import { Injectable } from '@angular/core'; import { CURRENCY_SERVICE_MOCK } from '@core/mocks/currency.service.mock'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import { ReferenceFieldAPI } from '@core/typings/api/reference-fields.typing'; import { ApplicationInfoForPDF } from '@core/typings/pdf.typing'; import { AdHocReportingUI } from '@core/typings/ui/ad-hoc-reporting.typing'; import { ReferenceFieldsUI } from '@core/typings/ui/reference-fields.typing'; import { FormAudience, FormDecisionTypes, FormDefinitionComponent } from '@features/configure-forms/form.typing'; import { KeyValue } from '@features/custom-data-tables/custom-data-tables.typing'; import { EMPLOYEE_SSO_TYPE_PREFIX } from '@features/formio/services/component-helper/component-helper.service'; import { InKindCategoryItemStat } from '@features/in-kind/in-kind.typing'; import { YcFile } from '@yourcause/common'; import { AfterEach, BeforeEach, Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularService } from '@yourcause/test-decorators/angular'; import { expect, spy } from 'chai'; import { ApplicationDownloadAnswerService } from './application-download-answer.service'; @Injectable({ providedIn: 'root' }) @DescribeAngularService(ApplicationDownloadAnswerService, { imports: [ GCMockModule ], providers: [ CURRENCY_SERVICE_MOCK ] }) export class ApplicationDownloadAnswerServiceSpec implements Spec { numberField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: 532, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Number', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Number, key: 'number', supportsMultiple: false, categoryId: 3, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; dateField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: ReferenceFieldAPI.ReferenceFieldAggregateType.Sum, referenceFieldId: 9959, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Date', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Date, key: '', supportsMultiple: false, categoryId: null, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: true, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; textField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: 9949, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Text field', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.TextField, key: 'text', supportsMultiple: false, categoryId: null, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; subsetFieldPercent: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: true, aggregateType: null, referenceFieldId: 8408, parentReferenceFieldId: null, formCount: 1, usedOnReports: true, createdBy: '', createDate: '', updateDate: '', updatedBy: '', customDataTableGuid: '', name: 'Subset field - percent', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Subset, key: 'subset', supportsMultiple: false, categoryId: 2, formAudience: FormAudience.MANAGER, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: ReferenceFieldAPI.DataSetCollectionType.Percent }; fileUpload: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: 145, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'File Upload', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.FileUpload, key: 'fileUpload', supportsMultiple: false, categoryId: 2, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; checkboxField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: 436, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Checkbox', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Checkbox, key: 'checkbox', supportsMultiple: false, categoryId: null, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; textAreaMulti: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: 754, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Text area', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.TextArea, key: 'textArea', supportsMultiple: true, categoryId: null, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: true, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; currencyField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: 1355, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: null, name: 'Currency', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Currency, key: 'currency', supportsMultiple: false, categoryId: 2, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; picklistField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: 424, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: 'cdt', name: 'Custom data table', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable, key: 'cdtField', supportsMultiple: true, categoryId: null, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; tableField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: 53232, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Table field', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Table, key: 'table', supportsMultiple: false, categoryId: null, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; maskedField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { customDataTableGuid: '', name: 'Text', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.TextField, key: 'textKey', supportsMultiple: false, categoryId: 0, formAudience: FormAudience.APPLICANT, referenceFieldId: 1, formCount: 1, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', aggregateType: null, updateDate: '', parentReferenceFieldId: null, isEncrypted: false, isMasked: true, tableAllowsImport: false, isSingleResponse: true, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; allReferenceFields: ReferenceFieldAPI.ReferenceFieldDisplayModel[] = [ this.textField, this.textAreaMulti, this.checkboxField, this.picklistField, this.numberField, this.currencyField, this.fileUpload, this.tableField, this.subsetFieldPercent, this.dateField, this.maskedField ]; inKindComputer: InKindCategoryItemStat = { inUse: true, identification: 'computer', name: 'Computer', units: 500, value: 1, unitsPaid: 200, unitsRemaining: 300, categoryId: null }; inKindPhone: InKindCategoryItemStat = { inUse: true, identification: 'phone', name: 'Phone', units: 500, value: 1, unitsPaid: 200, unitsRemaining: 300, categoryId: null }; application = { appId: 2353, specialHandling: { address1: '123 Main', city: 'North Charleston', state: 'SC', country: 'US', postalCode: '29406' }, designation: 'des', careOf: 'care of', amountRequested: 500, currencyRequestedAmountEquivalent: 600, currencyRequested: 'CAD', inKindItems: [{ count: 1, itemIdentification: this.inKindComputer.identification }, { count: 5, itemIdentification: this.inKindPhone.identification }], availableItemsForApplicant: [this.inKindComputer, this.inKindPhone], reportFieldResponse: { application: { id: 12, approvedDate: '10/15/2022' } as any, form: { applicationFormId: 543 } as any, referenceFields: [] } as AdHocReportingUI.ReportResponseRow, employeeInfo: { region: 'SC' } } as ApplicationInfoForPDF; refResponseMap: ReferenceFieldsUI.RefResponseMap = { [this.numberField.key]: 0, [this.checkboxField.key]: true, [this.textField.key]: 'text answer', [this.dateField.key]: '10/08/2022', [this.currencyField.key]: { amountEquivalent: 500, amountForControl: 400, amountInDefaultCurrency: 500, currency: 'CAD' }, [this.picklistField.key]: ['1'], [this.textAreaMulti.key]: ['one', 'two', 'three'], [this.tableField.key]: [{ rowId: 1, columns: [{ referenceFieldId: this.fileUpload.referenceFieldId, referenceFieldKey: this.fileUpload.key, value: [ new YcFile( 'file name', null, `https://yourcausegrantsqa.com/apply/download-file?applicationId=160574&applicationFormId=157406&fileId=${this.fileUpload.referenceFieldId}&fileName=Screen%20Shot%202021-07-15%20at%2010.09.05%20AM.png`, this.fileUpload.referenceFieldId ) ], dateValue: null, currencyValue: null, numericValue: null, file: null, files: [], applicationFormId: 1, applicationId: 2 }] }], [this.subsetFieldPercent.key]: [{ rowId: 1, columns: [{ value: 500 } as ReferenceFieldAPI.ApplicationRefFieldResponse, { value: null } as ReferenceFieldAPI.ApplicationRefFieldResponse, { value: 250 } as ReferenceFieldAPI.ApplicationRefFieldResponse] }] }; cdtOptions: KeyValue[] = [{ key: '1', sortOrder: 1, value: 'Steelers', parentKeys: [], parentKeysString: '', inUse: true }, { key: '2', sortOrder: 2, value: 'Cowboys', parentKeys: [], parentKeysString: '', inUse: true }]; @BeforeEach() async mock (service: ApplicationDownloadAnswerService) { service['referenceFieldService'].setAllReferenceFields(this.allReferenceFields); service['timezoneService'].setTimeZones(); const allItemsMap = { [this.inKindComputer.identification]: this.inKindComputer }; service['inKindService']['setAllItemsMapOnState'](allItemsMap); service['customDataTableService']['set']( 'customDataTableOptionsMap', { [this.picklistField.customDataTableGuid]: this.cdtOptions } ); service['referenceFieldService']['referenceFieldsResources']['getTableFields'] = async () => { return [{ referenceFieldId: this.fileUpload.referenceFieldId, referenceFieldName: 'File upload', label: '', isRequired: true, showInTable: true, columnOrder: 1, aggregateColumnReferenceFieldId: null }, { referenceFieldId: this.picklistField.referenceFieldId, referenceFieldName: 'Picklist', label: '', isRequired: true, showInTable: true, columnOrder: 1, aggregateColumnReferenceFieldId: null }]; }; service['referenceFieldService']['referenceFieldsResources']['getSubsetFields'] = async () => { return [{ referenceFieldId: this.textField.referenceFieldId, referenceFieldName: 'Text field', label: '', isRequired: true, showInTable: true, columnOrder: 1, aggregateColumnReferenceFieldId: null }, { referenceFieldId: this.numberField.referenceFieldId, referenceFieldName: 'Text', label: '', isRequired: true, showInTable: true, columnOrder: 1, aggregateColumnReferenceFieldId: null }]; }; await service['referenceFieldService'].setColumnsForTable(this.tableField.referenceFieldId); await service['referenceFieldService'].setDataPointsForSubset(this.subsetFieldPercent.referenceFieldId); } @AfterEach() restore () { spy.restore(); } @TestCase('should be able to get answer - ref default') getAnswerFromFromRefDefault (service: ApplicationDownloadAnswerService) { const component = { type: `referenceFields-${this.textField.key}` } as FormDefinitionComponent; spy.on(service, 'getTextFieldAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getTextFieldAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - ref text multi') getAnswerFromFromRefTextMulti (service: ApplicationDownloadAnswerService) { const component = { type: `referenceFields-${this.textAreaMulti.key}` } as FormDefinitionComponent; spy.on(service, 'getMultiTextFieldAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getMultiTextFieldAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - ref currency') getAnswerFromFromRefCurrency (service: ApplicationDownloadAnswerService) { const component = { type: `referenceFields-${this.currencyField.key}` } as FormDefinitionComponent; spy.on(service, 'getCurrencyFieldAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getCurrencyFieldAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - ref date') getAnswerFromFromRefDate (service: ApplicationDownloadAnswerService) { const component = { type: `referenceFields-${this.dateField.key}` } as FormDefinitionComponent; spy.on(service, 'getDateFieldAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getDateFieldAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - ref number') getAnswerFromFromRefNumber (service: ApplicationDownloadAnswerService) { const component = { type: `referenceFields-${this.numberField.key}`, prefix: '$', suffix: '%' } as FormDefinitionComponent; spy.on(service, 'getNumberFieldAnswer'); const answer = service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getNumberFieldAnswer']).to.have.been.called.once; const expected = `${component.prefix}${this.refResponseMap[this.numberField.key]}${component.suffix}`; expect(answer).to.be.equal(expected); } @TestCase('should be able to get answer - ref cdt') getAnswerFromFromRefCdt (service: ApplicationDownloadAnswerService) { const component = { type: `referenceFields-${this.picklistField.key}` } as FormDefinitionComponent; spy.on(service, 'getCustomDataTableAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getCustomDataTableAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - ref file') getAnswerFromFromRefFile (service: ApplicationDownloadAnswerService) { const component = { type: `referenceFields-${this.fileUpload.key}` } as FormDefinitionComponent; spy.on(service, 'getFileUploadAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getFileUploadAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - ref subset') getAnswerFromFromRefSubset (service: ApplicationDownloadAnswerService) { const component = { type: `referenceFields-${this.subsetFieldPercent.key}` } as FormDefinitionComponent; spy.on(service, 'getSubsetFieldAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getSubsetFieldAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - ref table') getAnswerFromFromRefTable (service: ApplicationDownloadAnswerService) { const component = { type: `referenceFields-${this.tableField.key}` } as FormDefinitionComponent; spy.on(service, 'getTableFieldAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getTableFieldAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - decision') getAnswerFromFromRefDecision (service: ApplicationDownloadAnswerService) { const component = { type: 'decision' } as FormDefinitionComponent; spy.on(service, 'getDecisionAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getDecisionAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - care of') getAnswerFromFromRefCareOf (service: ApplicationDownloadAnswerService) { const component = { type: 'careOf' } as FormDefinitionComponent; spy.on(service, 'getCareOfAnswer'); const answer = service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getCareOfAnswer']).to.have.been.called.once; expect(answer).to.be.equal(this.application.careOf); } @TestCase('should be able to get answer - special handling') getAnswerFromFromRefSpecialHandling (service: ApplicationDownloadAnswerService) { const component = { type: 'specialHandling' } as FormDefinitionComponent; spy.on(service['specialHandlingService'], 'getSpecialHandlingAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['specialHandlingService']['getSpecialHandlingAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - amount requested') getAnswerFromFromRefAmountRequested (service: ApplicationDownloadAnswerService) { const component = { type: 'amountRequested' } as FormDefinitionComponent; spy.on(service, 'getAmountRequestedAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getAmountRequestedAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - designation') getAnswerFromFromDesignation (service: ApplicationDownloadAnswerService) { const component = { type: 'designation' } as FormDefinitionComponent; spy.on(service, 'getDesignationAnswer'); const answer = service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getDesignationAnswer']).to.have.been.called.once; expect(answer).to.be.equal(this.application.designation); } @TestCase('should be able to get answer - recommended funding') getAnswerFromFromRecFunding (service: ApplicationDownloadAnswerService) { const component = { type: 'reviewerRecommendedFundingAmount' } as FormDefinitionComponent; spy.on(service, 'getRecommendedFundingAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getRecommendedFundingAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - in kind') getAnswerFromFromInKind (service: ApplicationDownloadAnswerService) { const component = { type: 'inKindItems' } as FormDefinitionComponent; spy.on(service, 'getInKindAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getInKindAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - report field') getAnswerFromFromReportField (service: ApplicationDownloadAnswerService) { const component = { type: 'reportField', reportFieldDataOptions: { reportFieldDisplay: 'approvedDate', reportFieldObject: 'application' } } as FormDefinitionComponent; spy.on(service, 'getReportFieldAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getReportFieldAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - sso field') getAnswerFromFromSsoField (service: ApplicationDownloadAnswerService) { const component = { type: `${EMPLOYEE_SSO_TYPE_PREFIX}-region` } as FormDefinitionComponent; spy.on(service, 'getSsoFieldAnswer'); service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, false, 600 ); expect(service['getSsoFieldAnswer']).to.have.been.called.once; } @TestCase('should be able to get answer - masked') getAnswerFromFromMaskedField (service: ApplicationDownloadAnswerService) { const component = { type: `referenceFields-${this.maskedField.key}` } as FormDefinitionComponent; const answer = service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, true, 600 ); expect(answer).to.be.equal(service['formMaskingService'].formFieldMask); } @TestCase('should be able to get text field answer') getTextFieldAnswer (service: ApplicationDownloadAnswerService) { const answer = service.getTextFieldAnswer( this.refResponseMap, this.textField.key ); expect(answer).to.be.equal(this.refResponseMap[this.textField.key]); } @TestCase('should be able to get multi field text answer') getMultiTextFieldAnswer (service: ApplicationDownloadAnswerService) { let answer = service.getMultiTextFieldAnswer( this.refResponseMap, this.textAreaMulti.key ); let expected = (this.refResponseMap[this.textAreaMulti.key] as string[]).join('
'); expect(answer).to.be.equal(expected); answer = service.getMultiTextFieldAnswer( { [this.textAreaMulti.key]: '1' }, this.textAreaMulti.key ); expected = '1'; expect(answer).to.be.equal(expected); } @TestCase('should be able to get answer from checkbox') getAnswerFormCheckbox (service: ApplicationDownloadAnswerService) { const component = { type: `referenceFields-${this.checkboxField.key}` } as FormDefinitionComponent; const answer = service.getAnswerFromForm( component, this.application, this.refResponseMap, FormDecisionTypes.Approve, true, 600 ); expect(answer).to.be.equal('True'); } @TestCase('should be able to get checkbox field answer') getCheckboxAnswer (service: ApplicationDownloadAnswerService) { let answer = service.getCheckboxAnswer( this.refResponseMap, this.checkboxField.key ); expect(answer).to.be.equal('True'); answer = service.getCheckboxAnswer( {}, this.checkboxField.key ); const noAnswer = !answer; expect(noAnswer).to.be.true; } @TestCase('should be able to get date field answer') getDateFieldAnswer (service: ApplicationDownloadAnswerService) { const answer = service.getDateFieldAnswer( this.refResponseMap, this.dateField.key ); expect(answer).to.be.equal('Oct 8, 2022'); } @TestCase('should be able to get currency field answer') getCurrencyFieldAnswer (service: ApplicationDownloadAnswerService) { const answer = service.getCurrencyFieldAnswer( this.refResponseMap, this.currencyField.key ); expect(answer).to.be.equal('$400'); } @TestCase('should be able to get number field answer') getNumberFieldAnswer (service: ApplicationDownloadAnswerService) { const answer = service.getNumberFieldAnswer( this.refResponseMap, this.numberField.key, true, 2 ); expect(answer).to.be.equal('0.00'); } @TestCase('should be able to get cdt answer - multi') getCustomDataTableAnswerMulti (service: ApplicationDownloadAnswerService) { const answer = service.getCustomDataTableAnswer( this.refResponseMap, this.picklistField.key, this.picklistField.customDataTableGuid, true ); expect(answer).to.be.equal('Steelers'); } @TestCase('should be able to get cdt answer') getCustomDataTableAnswer (service: ApplicationDownloadAnswerService) { const answer = service.getCustomDataTableAnswer( { [this.picklistField.key]: '2' }, this.picklistField.key, this.picklistField.customDataTableGuid, false ); expect(answer).to.be.equal('Cowboys'); } @TestCase('should be able to get file upload answer - no file') getFileUploadAnswerNoFile (service: ApplicationDownloadAnswerService) { const answer = service.getFileUploadAnswer( this.refResponseMap, this.fileUpload.key ); expect(answer).to.be.equal('No file uploaded'); } @TestCase('should be able to get file upload answer - with file') getFileUploadAnswer (service: ApplicationDownloadAnswerService) { const fileName = 'file name.png'; const answer = service.getFileUploadAnswer( { [this.fileUpload.key]: [new YcFile( fileName, new Blob(), 'url', 123 )] }, this.fileUpload.key ); expect(answer).to.be.equal(`See ${fileName}`); } @TestCase('should be able to get subset field answer - shown on pdf') getSubsetFieldAnswerShownOnPdf (service: ApplicationDownloadAnswerService) { const answer = service.getSubsetFieldAnswer( this.refResponseMap, this.subsetFieldPercent ); const columns = (answer as ReferenceFieldsUI.TableResponseRowForUiMapped[])[0].columns; const expectedCols = (this.refResponseMap[this.subsetFieldPercent.key] as ReferenceFieldsUI.TableResponseRowForUiMapped[])[0].columns; const expectedColsMapped = expectedCols.map((col) => col.value); const colsMapped = columns.map((col) => col.value); expect(colsMapped.sort()).to.deep.equal(expectedColsMapped.sort()); } @TestCase('should be able to get subset field answer - not on pdf') getSubsetFieldAnswerNotOnPdf (service: ApplicationDownloadAnswerService) { const dataPointsMap: Record = { [this.subsetFieldPercent.referenceFieldId]: [{ referenceFieldId: 1 } as ReferenceFieldsUI.DataPointForUI, { referenceFieldId: 2 } as ReferenceFieldsUI.DataPointForUI, { referenceFieldId: 3 } as ReferenceFieldsUI.DataPointForUI, { referenceFieldId: 4 } as ReferenceFieldsUI.DataPointForUI, { referenceFieldId: 5 } as ReferenceFieldsUI.DataPointForUI, { referenceFieldId: 6 } as ReferenceFieldsUI.DataPointForUI, { referenceFieldId: 7 } as ReferenceFieldsUI.DataPointForUI, { referenceFieldId: 8 } as ReferenceFieldsUI.DataPointForUI] }; service['referenceFieldService']['set']('dataPointsMap', dataPointsMap); const answer = service.getSubsetFieldAnswer( this.refResponseMap, this.subsetFieldPercent ); // Since there are so many columns, we export this as a csv instead of displaying in the PDF expect(answer).to.be.equal(`See ${this.subsetFieldPercent.name}.csv`); } @TestCase('should be able to get table field answers - shown on pdf') getTableFieldAnswerShownOnPdf (service: ApplicationDownloadAnswerService) { const answer = service.getTableFieldAnswer( this.refResponseMap, this.tableField ); const columns = (answer as ReferenceFieldsUI.TableResponseRowForUiMapped[])[0].columns; const expectedCols = (this.refResponseMap[this.tableField.key] as ReferenceFieldsUI.TableResponseRowForUiMapped[])[0].columns; const expectedColsMapped = expectedCols.map((col) => col.value); const colsMapped = columns.map((col) => col.value); expect(colsMapped.sort()).to.deep.equal(expectedColsMapped.sort()); } @TestCase('should be able to get table field answer - not on pdf') getTableFieldAnswerNotOnPdf (service: ApplicationDownloadAnswerService) { const tableColsMap: Record = { [this.tableField.referenceFieldId]: [{ referenceFieldId: 1 } as ReferenceFieldsUI.TableFieldForUi, { referenceFieldId: 2 } as ReferenceFieldsUI.TableFieldForUi, { referenceFieldId: 3 } as ReferenceFieldsUI.TableFieldForUi, { referenceFieldId: 4 } as ReferenceFieldsUI.TableFieldForUi, { referenceFieldId: 5 } as ReferenceFieldsUI.TableFieldForUi, { referenceFieldId: 6 } as ReferenceFieldsUI.TableFieldForUi, { referenceFieldId: 7 } as ReferenceFieldsUI.TableFieldForUi, { referenceFieldId: 8 } as ReferenceFieldsUI.TableFieldForUi] }; service['referenceFieldService']['set']('tableColumnsMap', tableColsMap); const answer = service.getTableFieldAnswer( this.refResponseMap, this.tableField ); // Since there are so many columns, we export this as a csv instead of displaying in the PDF expect(answer).to.be.equal(`See ${this.tableField.name}.csv`); } @TestCase('should be able to get amount requested answer') getAmountRequestedAnswer (service: ApplicationDownloadAnswerService) { spy.on(service['currencyService'], 'formatMoney'); service.getAmountRequestedAnswer(this.application); expect(service['currencyService'].formatMoney).to.have.been.called.once; } @TestCase('should be able to get recommended funding') getRecommendedFundingAnswer (service: ApplicationDownloadAnswerService) { spy.on(service['currencyService'], 'formatMoney'); service.getRecommendedFundingAnswer(500); expect(service['currencyService'].formatMoney).to.have.been.called.once; } @TestCase('should be able to get decision') getDecisionAnswer (service: ApplicationDownloadAnswerService) { const component = { recuseValue: 'Recuse', allowRecused: true, truthyValue: 'I approve it', falsyValue: 'No way' } as FormDefinitionComponent; let answer = service.getDecisionAnswer( FormDecisionTypes.Approve, component ); expect(answer).to.be.equal(component.truthyValue); answer = service.getDecisionAnswer( FormDecisionTypes.Decline, component ); expect(answer).to.be.equal(component.falsyValue); answer = service.getDecisionAnswer( FormDecisionTypes.Recused, component ); expect(answer).to.be.equal(component.recuseValue); } @TestCase('should be able to get in kind answer') getInKindAnswer (service: ApplicationDownloadAnswerService) { const answer = service.getInKindAnswer(this.application); const expectedAnswer = '1 Computer, 5 Phone'; expect(answer).to.be.equal(expectedAnswer); } @TestCase('should be able to get report field answer - no parse') getReportFieldAnswer (service: ApplicationDownloadAnswerService) { const component = { type: 'reportField', reportFieldDataOptions: { reportFieldDisplay: 'approvedDate', reportFieldObject: 'application' } } as FormDefinitionComponent; const answer = service.getReportFieldAnswer( this.application, component ); expect(answer).to.be.equal('Oct 15, 2022'); } @TestCase('should be able to get report field answer - with parse') getReportFieldAnswerWithParse (service: ApplicationDownloadAnswerService) { const component = { type: 'reportField', reportFieldDataOptions: JSON.stringify({ reportFieldDisplay: 'approvedDate', reportFieldObject: 'application' }) as any } as FormDefinitionComponent; const answer = service.getReportFieldAnswer( this.application, component ); expect(answer).to.be.equal('Oct 15, 2022'); } @TestCase('should be able to get sso field answer') getSsoFieldAnswer (service: ApplicationDownloadAnswerService) { const component = { type: `${EMPLOYEE_SSO_TYPE_PREFIX}-region` } as FormDefinitionComponent; const answer = service.getSsoFieldAnswer( this.application, component ); expect(answer).to.be.equal(this.application.employeeInfo.region); } }