Skip to content

Commit

Permalink
96358 Add well-defined attachment ID order for backend - form 10-10d (#…
Browse files Browse the repository at this point in the history
…33189)

* sorting attachments by attachmentId in transformer

* fix for out-of-order upload keys
  • Loading branch information
michaelclement authored Nov 27, 2024
1 parent 2217ab5 commit a0e8a0d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
17 changes: 17 additions & 0 deletions src/applications/ivc-champva/10-10D/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
12 changes: 4 additions & 8 deletions src/applications/ivc-champva/10-10D/config/submitTransformer.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: [
Expand Down

0 comments on commit a0e8a0d

Please sign in to comment.