import { Injectable } from '@angular/core'; import { CURRENCY_SERVICE_MOCK } from '@core/mocks/currency.service.mock'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import { CyclesAPI } from '@core/typings/api/cycles.typing'; import { ReferenceFieldAPI } from '@core/typings/api/reference-fields.typing'; import { ApplicationByFormFromApi, ApplicationCycle, MyApplicationFromApi, MyApplicationsApi, SaveApplication, SubmitEligibility, VettingRequestStatusId } from '@core/typings/application.typing'; import { ClientBrandingFromApi } from '@core/typings/branding.typing'; import { ProcessingTypes } from '@core/typings/payment.typing'; import { ProgramApplicantType, ProgramDetailApi } from '@core/typings/program.typing'; import { ApplicationStatuses } from '@core/typings/status.typing'; import { ReferenceFieldsUI } from '@core/typings/ui/reference-fields.typing'; import { AttachmentType } from '@features/application-view/application-attachments/application-attachments.typing'; import { CommunicationVisibility } from '@features/communications/communications.typing'; import { FormAudience, FormStatuses, FormTypes, ProgramFormFromApi } from '@features/configure-forms/form.typing'; import { EmployeeSSOFieldsData } from '@features/employee-sso-fields/employee-sso-fields.typing'; import { RoutingAppForSave } from '@features/programs/program-automation/program-automation.typing'; import { AfterEach, BeforeEach, Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularService } from '@yourcause/test-decorators/angular'; import { expect, spy } from 'chai'; import moment from 'moment'; import { ApplicationApplicantService } from './application-applicant.service'; @Injectable({ providedIn: 'root' }) @DescribeAngularService(ApplicationApplicantService, { imports: [ GCMockModule ], providers: [ CURRENCY_SERVICE_MOCK ] }) export class ApplicationApplicantServiceSpec implements Spec { appId = 1; formId = 2; programId = 3; cycleId = 4; revisionId = 5; postalCode = '29406'; grantProgramCycle = { id: this.cycleId, name: 'Cycle name', startDate: '', endDate: '', grantProgramId: this.programId, isArchived: false, isClientProcessing: false, clientOrganizationsProcessingTypeId: ProcessingTypes.YourCause }; programForm: ProgramFormFromApi = { applicationFormId: 8, formId: this.formId, formRevisionId: this.revisionId, name: '', defaultLanguageId: '', description: '', formDefinition: [{ tabName: '', logic: null, components: [] }], formData: {}, isDraft: true, canEdit: true, revisionNotes: '', formType: FormTypes.REQUEST, applicationFormStatusId: FormStatuses.DraftSaved, requireSignature: false, signatureDescription: '' }; latestVettingStatus = VettingRequestStatusId.PENDING; applicationByForm: ApplicationByFormFromApi = { isApplicationDraft: true, organization: null, grantProgramId: this.programId, grantProgramName: '', grantProgramDescription: '', programApplicantType: ProgramApplicantType.INDIVIDUAL, startDate: '', endDate: '', active: true, imageUrl: '', clientName: '', clientLogoUrl: '', clientId: 4, form: this.programForm, programAllowCollaboration: true, programSendEmailsToCollaborators: true, amountRequested: 500, nominee: null, applicationStatusId: ApplicationStatuses.Hold, nominationApplicationId: null, paymentDesignation: '', specialHandlingName: '', specialHandlingAddress1: '', specialHandlingAddress2: '', specialHandlingCountry: '', specialHandlingCity: '', specialHandlingStateProvinceRegion: '', specialHandlingPostalCode: this.postalCode, specialHandlingNotes: '', specialHandlingFileUrl: null, specialHandlingReason: '', currencyRequestedAmountEquivalent: 500, currencyRequested: '', clientOrganizationsProcessingTypeId: ProcessingTypes.YourCause, inKindAmountRequested: 0, isArchived: true, isProgramArchived: true, inKindItems: [], cycle: this.grantProgramCycle, careOf: null, latestVettingRequestStatusForOrg: this.latestVettingStatus, invitationOrganizationId: null }; program: ProgramDetailApi = { hasDraftApplication: true, grantProgramId: this.programId, grantProgramName: '', grantProgramDescription: '', charityBucketId: '', charityBucketDescription: '', startDate: '', endDate: '', timezoneId: '', active: true, imageUrl: '', clientName: '', clientId: 4, clientLogoUrl: '', form: { applicationFormId: 1, formId: this.formId, formRevisionId: this.revisionId, name: 'Test', description: '', formData: null, isDraft: true, canEdit: true, revisionNotes: '', formType: FormTypes.REQUEST, applicationFormStatusId: null, defaultLanguageId: null, formDefinition: [{ logic: null, tabName: '', components: [] }], requireSignature: false, signatureDescription: '' }, programApplicantType: ProgramApplicantType.INDIVIDUAL, eligibilityForm: null, eligibilityPassMessage: '', eligibilityFailMessage: '', notifyNominators: true, allowAddOrg: true, logoUrl: '', nameLanguageTranslations: [], descriptionLanguageTranslations: [], isArchived: true, cycles: [], hideCycleDatesInApplicantPortal: true, inviteOnly: true }; grantProgramGuid = 'grantProgramGuid'; futureCycleId = 3; currentCycleId = 4; myApplications: MyApplicationFromApi[] = [{ clientLogoUrl: '', grantProgramId: this.programId, grantProgramGuid: this.grantProgramGuid, grantProgramName: '', grantProgramImageUrl: '', programAllowCollaboration: true, programSendEmailsToCollaborators: true, applicationId: this.appId, isDraft: true, organizationId: 4, organizationName: '', submissionDate: '', createdDate: '', status: null, applicationForms: [{ formId: this.formId, id: 2, formRevisionId: this.revisionId, name: 'Over due form', isDraft: true, submissionDate: null, status: FormStatuses.DraftSaved, statusUpdatedDate: '', updatedDate: '', dueDate: '03/01/2020' }, { formId: 134, id: 23523, formRevisionId: 567, name: 'Submitted form', isDraft: true, submissionDate: null, status: FormStatuses.Submitted, statusUpdatedDate: '', updatedDate: '', dueDate: '03/01/2020' }], applicantCount: 1, applicant: { id: 2, firstName: '', lastName: '', email: '', profileImageUrl: '' }, amountRequested: 500, nominee: null, nominatedBy: null, nominationApplicationId: null, grantProgramLogoUrl: '', currencyRequested: '', currencyRequestedAmountEquivalent: 500, clientId: 1, inKindAmountRequested: 0, inKindItems: [], clientName: '', files: [], mergeDocuments: [{ applicantCanView: true, canRemoveAttachment: true, documentVisibility: CommunicationVisibility.ALL_GRANT_MANAGERS, documentTemplateId: 12, documentTemplateName: 'test', attachmentId: 353, fileName: 'name', fileUploadId: 532, attachmentType: AttachmentType.EXTERNAL, uploadedDate: '', uploadedBy: null }], hasOpenCycle: true, isAwarded: true, isInvitationOnlyProgram: false, invitationId: null, isArchived: false, isProgramArchived: false, cycleId: this.currentCycleId }]; myApplicationsApi: MyApplicationsApi = { totalCount: 1, pageCount: 1, page: 1, pageSize: 5, data: this.myApplications }; textFieldId = 1; textAreaId = 2; refFieldsByRevision: ReferenceFieldAPI.ReferenceFieldDisplayModel[] = [{ isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.textFieldId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Text field', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.TextField, key: 'text', supportsMultiple: true, categoryId: 1, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, isStandardProductField: false, standardComponentIsPublished: false, subsetCollectionType: null }, { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.textAreaId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Text area', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.TextArea, key: 'textarea', supportsMultiple: false, categoryId: 1, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, isStandardProductField: false, standardComponentIsPublished: false, subsetCollectionType: null }]; appCycle: ApplicationCycle = { id: 1, startDate: '', endDate: '', grantProgramId: 1, isArchived: false, clientOrganizationsProcessingTypeId: null, isClientProcessing: true }; programCycles: CyclesAPI.BaseProgramCycle[] = [{ id: this.futureCycleId, name: 'Future Cycle', startDate: moment().add(2, 'month').format('ll'), endDate: moment().add(3, 'month').format('ll'), isClientProcessing: true }, { id: this.currentCycleId, name: 'Current Cycle', startDate: moment().subtract(1, 'month').format('ll'), endDate: moment().add(1, 'month').format('ll'), isClientProcessing: true }]; clientBranding: ClientBrandingFromApi = { logoUrl: '', brandPrimary: '#e9511f', brandSecondary: '#9aeb97', brandUtility: '#57f3d6', siteId: 1, clientColorSchemes: [] }; @BeforeEach() async prepare (service: ApplicationApplicantService) { service['applicationApplicantResources'].getApplicationByForm = async () => { return this.applicationByForm; }; service['applicationApplicantResources'].getApplications = async () => { return this.myApplicationsApi; }; service['employeeSSOFieldsService']['employeeSSOFieldsResources'].getEmployeeSSOFieldsForApp = async () => { return {} as EmployeeSSOFieldsData; }; service['applicationApplicantResources'].getClientBranding = async () => { return this.clientBranding as ClientBrandingFromApi; }; service['applicationApplicantResources'].deleteApplication = async () => {}; service['referenceFieldsService'].getReferenceFieldResponses = async () => { return {}; }; service['referenceFieldsService'].fetchFieldsByFormRevisionId = async () => { return this.refFieldsByRevision; }; service['programService']['programResources'].getProgramForApplicant = async () => { return this.program; }; service['clientSettingsService'].setAvailableApplicantCurrencies = async () => {}; service.setMyApplications(this.myApplications); service.setRevisionAlerts([]); } @AfterEach() restore () { spy.restore(); } @TestCase('should be able to get portal application - standard') async getPortalApplication (service: ApplicationApplicantService) { const response = await service.getPortalApplication( this.appId, this.formId, '' + this.programId, null, null, false ); expect(response.statusId).to.be.equal(ApplicationStatuses.Hold); expect(response.amountRequested).to.be.equal(500); expect(response.programId).to.be.equal(this.programId); } @TestCase('should be able to get portal application - copy') async getPortalApplicationCopy (service: ApplicationApplicantService) { spy.on(service['applicationApplicantResources'], 'getApplicationByForm', async () => { return this.applicationByForm; }); spy.on(service['programService']['programResources'], 'getProgramForApplicant', async () => { return this.program; }); spy.on(service, 'prepareReferenceFields', async () => {}); const copyId = 124; await service.getPortalApplication( null, this.formId, '' + this.programId, copyId, null, false ); expect(service['applicationApplicantResources']['getApplicationByForm']).to.have.been.called.once; expect(service['programService']['programResources']['getProgramForApplicant']).to.have.been.called.once; expect(service['prepareReferenceFields']).to.have.been.called.once; } @TestCase('should be able to get portal application - no app ID') async getPortalApplicationNoId (service: ApplicationApplicantService) { spy.on(service['nonprofitService'], 'getApplicantOrganizationFromOrgId', async () => { return { id: 325231, name: 'Organization name' }; }); spy.on(service, 'getApplicationByForm'); await service.getPortalApplication( null, this.formId, '' + this.programId, null, 23523, false ); expect(service['nonprofitService']['getApplicantOrganizationFromOrgId']).to.have.been.called.once; // Only call this when we have app ID expect(service['getApplicationByForm']).to.not.have.been.called; } @TestCase('should be able to get portal application - routing') async getPortalApplicationRouting (service: ApplicationApplicantService) { spy.on(service['programAutomationService']['programAutomationResources'], 'getRoutingInfoForApplicant', async () => { return { name: 'Ruleset A', description: '', ruleSetFailureMessage: '', fallbackGrantProgramGuid: '', isArchived: false, formId: this.formId, formRevisionId: 235, clientLogoUrl: '', clientId: 1, clientName: '', formDefinition: [] }; }); spy.on(service, 'prepareReferenceFields', async () => {}); const routingGuid = '2asdflasdf'; await service.getPortalApplication( null, this.formId, routingGuid, null, null, true ); expect(service['programAutomationService']['programAutomationResources']['getRoutingInfoForApplicant']).to.have.been.called.once; expect(service['prepareReferenceFields']).to.have.been.called.once; } @TestCase('should be able to get portal application - fail') async getPortalApplicationFail (service: ApplicationApplicantService) { spy.on(service['applicationApplicantResources'], 'getApplicationByForm', async () => { // eslint-disable-next-line no-throw-literal throw { error: {} }; }); spy.on(service['logger'], 'error'); await service.getPortalApplication( this.appId, this.formId, '' + this.programId, null, null, false ); expect(service['logger']['error']).to.have.been.called.once; } @TestCase('should be able to get eligibility form') getEligibilityForm (service: ApplicationApplicantService) { spy.on(service['formLogicService'], 'adaptFormForTabs'); service.getEligibilityForm( { ...this.program, eligibilityForm: { formType: FormTypes.ELIGIBILITY, formDefinition: [] } as ProgramFormFromApi }, { ...this.applicationByForm, form: { formType: FormTypes.ELIGIBILITY, formDefinition: [] } as ProgramFormFromApi } ); // Called twice - once for the program adapt and another for the application adapt expect(service['formLogicService']['adaptFormForTabs']).to.have.been.called.twice; } @TestCase('should be able to get eligibility form - app only') getEligibilityFormAppOnly (service: ApplicationApplicantService) { spy.on(service['formLogicService'], 'adaptFormForTabs'); service.getEligibilityForm( this.program, { ...this.applicationByForm, form: { formType: FormTypes.ELIGIBILITY, formDefinition: [] } as ProgramFormFromApi } ); // Called once for the application adapt expect(service['formLogicService']['adaptFormForTabs']).to.have.been.called.once; } @TestCase('should be able to remove app id from my apps') removeFromMyApplications (service: ApplicationApplicantService) { service.removeFromMyApplications(this.appId); expect(service.myApplications.length).to.be.equal(this.myApplications.length - 1); const noLongerHasApp = service.myApplications.every((app) => { return app.applicationId !== this.appId; }); expect(noLongerHasApp).to.be.true; } @TestCase('should be able to remove app id from my apps - revisions') removeFromMyApplicationsRevisions (service: ApplicationApplicantService) { const revisionAlert = { applicationId: 643 } as MyApplicationFromApi; service.setRevisionAlerts([revisionAlert]); service.removeFromMyApplications(revisionAlert.applicationId); expect(service.revisionAlerts.length).to.be.equal(0); const noLongerHasRevisionAlert = service.revisionAlerts.every((app) => { return app.applicationId !== revisionAlert.applicationId; }); expect(noLongerHasRevisionAlert).to.be.true; } @TestCase('should be able to get form past due alerts') async getFormPastDueAlerts (service: ApplicationApplicantService) { await service.getMyApplications(true); const formsPastdue = service.formsPastDue; expect(formsPastdue.length).to.be.equal(1); expect(formsPastdue[0].formId).to.be.equal(this.formId); } @TestCase('should be able to prepare reference fields for applicant') async prepareReferenceFields (service: ApplicationApplicantService) { await service.prepareReferenceFields( 1, null, null ); const refFieldsWereAdded = service['referenceFieldsService'].allReferenceFields .every((field) => { return field.referenceFieldId === this.textFieldId || field.referenceFieldId === this.textAreaId; }); expect(refFieldsWereAdded).to.be.true; } @TestCase('should be able to get cycle for apply page when app exists') getCycleForApplyPage (service: ApplicationApplicantService) { const cycle = service.getCycleForApplyPage( this.appCycle, 1, [] ); expect(cycle.id).to.be.equal(this.appCycle.id); } @TestCase('should be able to get cycle for apply page when app does not exist') getCycleForApplyPage2 (service: ApplicationApplicantService) { const cycle = service.getCycleForApplyPage( undefined, 1, this.programCycles ); expect(cycle.id).to.be.equal(cycle.id); } @TestCase('should be able to append translations to app') appendFormTranslationsToApp (service: ApplicationApplicantService) { const translations = { Name: 'Translated Name', Description: 'Translated Description' }; service.appendFormTranslationsToApp( this.applicationByForm, translations ); expect(this.applicationByForm.form.name).to.be.equal(translations.Name); expect(this.applicationByForm.form.description).to.be.equal( translations.Description ); } @TestCase('should be able to get client branding from an application') async getClientBranding (service: ApplicationApplicantService) { const response = await service.getPortalApplication( this.appId, this.formId, '' + this.programId, null, null, false ); expect(response.clientBranding).to.be.equal(this.clientBranding); } @TestCase('should be able to clear client branding') async clearClientBranding (service: ApplicationApplicantService) { await service.getClientBranding(1); service.clearClientBranding(); const branding = service['clientSettingsService'].clientBranding; branding; const isCleared = !branding; expect(isCleared).to.be.true; } @TestCase('should be able to get latest vetting request status') async getLatestVettingStatusForApplication (service: ApplicationApplicantService) { const latestStatus = await service.getLatestVettingStatusForApplication(1, 2); expect(latestStatus).to.be.equal(this.latestVettingStatus); } @TestCase('should be able to get application by form') async getApplicationByForm (service: ApplicationApplicantService) { spy.on(service['applicationApplicantResources'], 'getApplicationByForm', async () => { return this.applicationByForm; }); await service.getApplicationByForm(1, 2); expect(service['applicationApplicantResources']['getApplicationByForm']).to.have.been.called.once; } @TestCase('should be able to get application by form - fail') async getApplicationByFormFail (service: ApplicationApplicantService) { spy.on(service['applicationApplicantResources'], 'getApplicationByForm', async () => { // eslint-disable-next-line no-throw-literal throw { error: {} }; }); spy.on(service['logger'], 'error'); spy.on(service['notifier'], 'error'); await service.getApplicationByForm(1, 2); expect(service['logger']['error']).to.have.been.called.once; expect(service['notifier']['error']).to.have.been.called.once; } @TestCase('should be able to adapt my applications and get has nominations') adaptMyApplicationsHasNominations (service: ApplicationApplicantService) { const appsWithNominations = [{ ...this.myApplications[0], nominee: { email: 'test@email.com', firstName: 'Test', lastName: 'Name' }, createdDate: '01/02/2022' }, { ...this.myApplications[0], status: ApplicationStatuses.Hold, appId: 234 }, { ...this.myApplications[0], status: ApplicationStatuses.Hold, appId: 23423 }, { ...this.myApplications[0], status: ApplicationStatuses.AwaitingReview, createdDate: '01/02/2022', appId: 23435 }, { ...this.myApplications[0], status: ApplicationStatuses.Approved, createdDate: '01/04/2022', appId: 234354 }]; let response = service.adaptMyApplications(appsWithNominations); expect(response.hasNominations).to.be.true; response = service.adaptMyApplications(this.myApplications); expect(response.hasNominations).to.be.false; } @TestCase('should be able to adapt my applications and get revision alerts') adaptMyApplicationsHasRevisionAlerts (service: ApplicationApplicantService) { const appsWithRevisionAlerts = [ { ...this.myApplications[0], applicationForms: [{ formId: 2, id: 3, formRevisionId: 4, name: 'Form needs revision', isDraft: true, submissionDate: '', status: FormStatuses.RevisionRequested, statusUpdatedDate: '', updatedDate: '', dueDate: '' }, { formId: 353, id: 52, formRevisionId: 4745, name: 'Draft form', isDraft: true, submissionDate: '', status: null, statusUpdatedDate: '', updatedDate: '', dueDate: '' }] } ]; let response = service.adaptMyApplications(appsWithRevisionAlerts); let hasRevisionAlert = response.revisionAlerts[0].applicationId === this.appId; expect(hasRevisionAlert).to.be.true; response = service.adaptMyApplications(this.myApplications); hasRevisionAlert = response.revisionAlerts.length !== 0; expect(hasRevisionAlert).to.be.false; } @TestCase('should be able to adapt my applications and get form past due alerts') adaptMyApplicationsHasFormsPastDueAlerts (service: ApplicationApplicantService) { const appsWithFormsPastDue = [ { ...this.myApplications[0], applicationForms: [{ formId: 2, id: 3, formRevisionId: 4, name: 'Form overdue', isDraft: true, submissionDate: '', status: FormStatuses.DraftSaved, statusUpdatedDate: '', updatedDate: '', dueDate: '01/01/2021' }] } ]; let response = service.adaptMyApplications(appsWithFormsPastDue); let hasFormAlert = response.formsPastDue[0].applicationId === this.appId; expect(hasFormAlert).to.be.true; const appsWithNoFormsPastDue = [ { ...this.myApplications[0], applicationForms: [{ formId: 2, id: 3, formRevisionId: 4, name: 'Form not overdue', isDraft: true, submissionDate: '', status: FormStatuses.DraftSaved, statusUpdatedDate: '', updatedDate: '', dueDate: '' }] } ]; response = service.adaptMyApplications(appsWithNoFormsPastDue); hasFormAlert = response.formsPastDue.length !== 0; expect(hasFormAlert).to.be.false; } @TestCase('should be able to adapt my applications - organizationName and status') adaptApplicationsOrgNameAndStatus (service: ApplicationApplicantService) { const adapted = service.adaptMyApplications(this.myApplications); const foundApp = adapted.rows[0]; const hasAdaptedStatus = foundApp.status === ApplicationStatuses.Draft; const hasAdaptedOrgName = foundApp.organizationName === 'None'; expect(hasAdaptedStatus).to.be.true; expect(hasAdaptedOrgName).to.be.true; } @TestCase('delete app should reset my applications') async deletePortalApplication (service: ApplicationApplicantService) { spy.on(service['applicationApplicantResources'], 'deleteApplication'); spy.on(service['confirmAndTakeActionService'], 'genericConfirmAndTakeAction', async (fn) => { await fn(); return { passed: true, endpointResponse: null }; }); let resetMyApps = false; service['getMyApplications'] = async () => { resetMyApps = true; }; await service.handleDeleteApplication(1, false); expect(resetMyApps).to.be.true; expect(service['confirmAndTakeActionService']['genericConfirmAndTakeAction']).to.have.been.called.once; expect(service['applicationApplicantResources']['deleteApplication']).to.have.been.called.once; } @TestCase('cancel app should reset my applications') async cancelPortalApplication (service: ApplicationApplicantService) { let resetMyApps = false; service['getMyApplications'] = async () => { resetMyApps = true; }; await service.cancelApplication({ applicationId: this.appId, reason: null, comment: '', sendEmailToApplicants: true, customMessage: '', emailOptions: null }); expect(resetMyApps).to.be.true; } @TestCase('should be able to get draft apps for program') getDraftAppsForProgram (service: ApplicationApplicantService) { const draftApps = service.getDraftAppsForProgram( this.grantProgramGuid, this.programCycles ); const foundDraftApp = draftApps.some((app) => { return app.applicationId === this.appId; }); expect(foundDraftApp).to.be.true; } @TestCase('should be able to test for existing submitted apps') checkForExistingSubmittedApps (service: ApplicationApplicantService) { let hasExisting = service.checkForExistingSubmittedApps(this.programId); expect(hasExisting).to.be.false; const adaptedWithSubmittedApps = [{ ...this.myApplications[0], isDraft: false }]; service.setMyApplications(adaptedWithSubmittedApps); hasExisting = service.checkForExistingSubmittedApps(this.programId); expect(hasExisting).to.be.true; } @TestCase('should be able to set routing app for save') setRoutingAppForSave (service: ApplicationApplicantService) { const routingApp = { formId: 1 } as RoutingAppForSave; service.setRoutingAppForSave(routingApp); expect(service.routingAppForSave.formId).to.be.equal(routingApp.formId); } @TestCase('should be able to set routing app for save') clearRoutingAppForSave (service: ApplicationApplicantService) { service.clearRoutingAppForSave(); const isCleared = !service.routingAppForSave; expect(isCleared).to.be.true; } @TestCase('should be able to get has nominations') hasNominations (service: ApplicationApplicantService) { service['set']('hasNominations', true); expect(service.hasNominations).to.be.true; } @TestCase('should be able to save applicant routing responses to app') async saveApplicantRoutingResponsesToApp (service: ApplicationApplicantService) { const routingApp = { formId: 1, formRevisionId: 2, programId: 3 } as RoutingAppForSave; service.setRoutingAppForSave(routingApp); spy.on(service, 'saveApplication', async () => { return { applicationFormId: 1 }; }); spy.on(service['referenceFieldsService'], 'adaptFormioChangesForSave', () => { return {}; }); spy.on(service['applicationFormService'], 'handleSaveOfChangedFields', async () => {}); const saveAppPayload = { form: {} } as SaveApplication; await service.saveApplicantRoutingResponsesToApp(1, saveAppPayload); expect(service['referenceFieldsService']['adaptFormioChangesForSave']).to.have.been.called.once; expect(service['applicationFormService']['handleSaveOfChangedFields']).to.have.been.called.once; const isCleared = !service.routingAppForSave; expect(isCleared).to.be.true; } @TestCase('should be able to save application') async saveApplication (service: ApplicationApplicantService) { spy.on(service['applicationApplicantResources'], 'saveApplication', async () => {}); await service.saveApplication({} as SaveApplication); expect(service['applicationApplicantResources']['saveApplication']).to.have.been.called.once; } @TestCase('should be able to submit eligibility') async submitEligibility (service: ApplicationApplicantService) { spy.on(service['applicationApplicantResources'], 'submitEligibility', async () => {}); await service.submitEligibility({} as SubmitEligibility); expect(service['applicationApplicantResources']['submitEligibility']).to.have.been.called.once; } }