diff --git a/src/applications/ivc-champva/10-10D/config/constants.js b/src/applications/ivc-champva/10-10D/config/constants.js index 6febf1de17f4..8c1ea16dc68a 100644 --- a/src/applications/ivc-champva/10-10D/config/constants.js +++ b/src/applications/ivc-champva/10-10D/config/constants.js @@ -51,5 +51,22 @@ export const OPTIONAL_FILES = { 'Proof of Legal Separation from Marriage Or Legal Union to Other', }; +// The backend needs this list so that it can properly match the attachmentId +// on a per applicant basis to the temporary cache files that have been uploaded +// See: https://github.com/department-of-veterans-affairs/va.gov-team/issues/96358 +export const FILE_UPLOAD_ORDER = [ + 'applicantBirthCertOrSocialSecCard', + 'applicantAdoptionPapers', + 'applicantStepMarriageCert', + 'applicantSchoolCert', + 'applicantHelplessCert', + 'applicantRemarriageCert', + 'applicantMedicarePartAPartBCard', + 'applicantMedicarePartDCard', + 'applicantMedicareIneligibleProof', + 'applicantOhiCard', + 'applicantOtherInsuranceCertification', +]; + export const ADDITIONAL_FILES_HINT = 'Depending on your response, you may need to submit additional documents with this application.'; diff --git a/src/applications/ivc-champva/10-10D/config/submitTransformer.js b/src/applications/ivc-champva/10-10D/config/submitTransformer.js index c1af3461484c..795663751ec4 100644 --- a/src/applications/ivc-champva/10-10D/config/submitTransformer.js +++ b/src/applications/ivc-champva/10-10D/config/submitTransformer.js @@ -1,5 +1,5 @@ import { transformForSubmit as formsSystemTransformForSubmit } from 'platform/forms-system/src/js/helpers'; -import { REQUIRED_FILES, OPTIONAL_FILES } from './constants'; +import { FILE_UPLOAD_ORDER } from './constants'; import { adjustYearString, concatStreets, @@ -53,13 +53,9 @@ function transformApplicants(applicants) { ), // Grab any file upload properties from this applicant and combine into a // supporting documents array: - applicantSupportingDocuments: Object.keys({ - ...REQUIRED_FILES, - ...OPTIONAL_FILES, - }) - .filter(k => k.includes('applicant')) // Ignore sponsor files - .map(f => app?.[f]) // Grab the upload obj from top-level in applicant - .filter(el => el), // Drop any undefineds/nulls + applicantSupportingDocuments: FILE_UPLOAD_ORDER.map( + property => app?.[property], + ).filter(el => el), // Drop any undefineds/nulls }; transformedApp = adjustYearString(transformedApp); transformedApp.applicantAddress = concatStreets( diff --git a/src/applications/ivc-champva/10-10D/tests/unit/components/File/MissingFileOverview.unit.spec.js b/src/applications/ivc-champva/10-10D/tests/unit/components/File/MissingFileOverview.unit.spec.js index 71817250ce17..1f6a8caf8985 100644 --- a/src/applications/ivc-champva/10-10D/tests/unit/components/File/MissingFileOverview.unit.spec.js +++ b/src/applications/ivc-champva/10-10D/tests/unit/components/File/MissingFileOverview.unit.spec.js @@ -4,7 +4,10 @@ import { Provider } from 'react-redux'; import { expect } from 'chai'; import SupportingDocumentsPage from '../../../../pages/SupportingDocumentsPage'; import { MissingFileConsentPage } from '../../../../pages/MissingFileConsentPage'; -import { REQUIRED_FILES } from '../../../../config/constants'; +import { + REQUIRED_FILES, + FILE_UPLOAD_ORDER, +} from '../../../../config/constants'; import { testComponentRender, getProps, @@ -14,10 +17,52 @@ import { checkFlags, } from '../../../../../shared/components/fileUploads/MissingFileOverview'; import MissingFileList from '../../../../../shared/components/fileUploads/MissingFileList'; +import { getAllPages } from '../../../../../shared/tests/helpers'; +import SupportingDocsVerification from '../../../../../shared/components/fileUploads/supportingDocsVerification'; import formConfig from '../../../../config/form'; import mockData from '../../../e2e/fixtures/data/test-data.json'; +describe('FILE_UPLOAD_ORDER constant', () => { + it('should match order of file upload fields present in formConfig', () => { + /* + NOTE: FILE_UPLOAD_ORDER must be manually updated if the order + of file uploads in `formConfig` ever changes. This test serves to + make sure that happens. The backend relies on this list to properly + map metadata to the tmp files generated when users upload docs. + */ + + const verifier = new SupportingDocsVerification([]); + // We want this `FILE_UPLOAD_ORDER` to match what we pull from formConfig. + // This helper produces a list like: + // ['applicantBirthCertOrSocialSecCard','applicantAdoptionPapers', ...] + const generatedArr = verifier + .getApplicantFileKeyNames(getAllPages(formConfig)) + .map(el => el.name); + + let orderIsSame = true; + generatedArr.forEach((el, idx) => { + if (FILE_UPLOAD_ORDER[idx] !== el) { + orderIsSame = false; + } + }); + + expect( + orderIsSame, + `Expected FILE_UPLOAD_ORDER array: + + ${FILE_UPLOAD_ORDER.join('\n\t')} + + to have same order as defined in formConfig: + + ${generatedArr.join('\n\t')} + + Please verify that FILE_UPLOAD_ORDER matches the order of file upload properties defined in formConfig. + `, + ).to.be.true; + }); +}); + describe('hasReq', () => { const data = { applicants: [