Skip to content

Commit

Permalink
fix(EMS-3633): data migration - xlsx - total contract value (#2934)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttbarnes authored Aug 12, 2024
1 parent d79c0d8 commit f0bfdba
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
20 changes: 12 additions & 8 deletions src/api/.keystone/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,13 @@ const {

const { company, eligibility } = mockApplication;

const genericExpectedRows = [
const expectedInitialRows = [
xlsxRow(CONTENT_STRINGS[VALID_EXPORTER_LOCATION].SUMMARY?.TITLE, mapYesNoField({ answer: eligibility[VALID_EXPORTER_LOCATION] })),

xlsxRow(CONTENT_STRINGS[HAS_COMPANIES_HOUSE_NUMBER].SUMMARY?.TITLE, mapYesNoField({ answer: eligibility[HAS_COMPANIES_HOUSE_NUMBER] })),
xlsxRow(String(FIELDS[COMPANIES_HOUSE_NUMBER]), company[COMPANIES_HOUSE_NUMBER]),

xlsxRow(String(FIELDS[BUYER_COUNTRY]), eligibility[BUYER_COUNTRY].name),

xlsxRow(String(FIELDS[MORE_THAN_250K.VALUE]), mapYesNoField({ answer: eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID].valueId === MORE_THAN_250K.DB_ID })),

xlsxRow(String(FIELDS[COVER_PERIOD]), eligibility[COVER_PERIOD_ELIGIBILITY].value),

xlsxRow(String(FIELDS[HAS_MINIMUM_UK_GOODS_OR_SERVICES]), mapYesNoField({ answer: eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES] })),
];

describe('api/generate-xlsx/map-application-to-xlsx/map-eligibility', () => {
Expand All @@ -54,10 +48,14 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-eligibility', () => {
});

const expected = [
...genericExpectedRows,
...expectedInitialRows,

xlsxRow(String(FIELDS[HAS_END_BUYER]), mapYesNoField({ answer: null })),
xlsxRow(String(FIELDS[MORE_THAN_250K.VALUE]), mapYesNoField({ answer: null })),

xlsxRow(String(FIELDS[COVER_PERIOD]), eligibility[COVER_PERIOD_ELIGIBILITY].value),
xlsxRow(String(FIELDS[HAS_MINIMUM_UK_GOODS_OR_SERVICES]), mapYesNoField({ answer: eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES] })),

xlsxRow(String(FIELDS[HAS_END_BUYER]), mapYesNoField({ answer: null })),
xlsxRow(String(FIELDS[IS_PARTY_TO_CONSORTIUM]), mapYesNoField({ answer: null })),
xlsxRow(String(FIELDS[IS_MEMBER_OF_A_GROUP]), mapYesNoField({ answer: null })),
];
Expand All @@ -74,7 +72,11 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-eligibility', () => {
});

const expected = [
...genericExpectedRows,
...expectedInitialRows,

xlsxRow(String(FIELDS[MORE_THAN_250K.VALUE]), mapYesNoField({ answer: eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID].valueId === MORE_THAN_250K.DB_ID })),
xlsxRow(String(FIELDS[COVER_PERIOD]), eligibility[COVER_PERIOD_ELIGIBILITY].value),
xlsxRow(String(FIELDS[HAS_MINIMUM_UK_GOODS_OR_SERVICES]), mapYesNoField({ answer: eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES] })),

xlsxRow(String(FIELDS[HAS_END_BUYER]), mapYesNoField({ answer: eligibility[HAS_END_BUYER] })),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ const {
/**
* mapEligibility
* Map an application's eligibility fields into an array of objects for XLSX generation
* If an application has been migrated from V1 to V2,
* the IS_PARTY_TO_CONSORTIUM, IS_MEMBER_OF_A_GROUP and HAS_END_BUYER fields should have NULL answers.
* If an application has been migrated from V1 to V2, the following fields/rows should have NULL answers:
* - MORE_THAN_250K
* - HAS_END_BUYER
* - IS_PARTY_TO_CONSORTIUM
* - IS_MEMBER_OF_A_GROUP
* This is because, V1 eligibility does not have these fields available and so, the user has not provided an answer.
* @param {Application}
* @returns {Array<object>} Array of objects for XLSX generation
Expand All @@ -45,8 +48,13 @@ const mapEligibility = (application: Application) => {
xlsxRow(String(FIELDS[COMPANIES_HOUSE_NUMBER]), company[COMPANIES_HOUSE_NUMBER]),

xlsxRow(String(FIELDS[BUYER_COUNTRY]), eligibility[BUYER_COUNTRY].name),
];

const totalContractValueAnswer = migratedV1toV2 ? null : eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID].valueId === MORE_THAN_250K.DB_ID;

xlsxRow(String(FIELDS[MORE_THAN_250K.VALUE]), mapYesNoField({ answer: eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID].valueId === MORE_THAN_250K.DB_ID })),
mapped = [
...mapped,
xlsxRow(String(FIELDS[MORE_THAN_250K.VALUE]), mapYesNoField({ answer: totalContractValueAnswer })),

xlsxRow(String(FIELDS[COVER_PERIOD]), eligibility[COVER_PERIOD_ELIGIBILITY].value),

Expand Down

0 comments on commit f0bfdba

Please sign in to comment.