From 40ea2f4a100567b21c321674904c80757fb11cb1 Mon Sep 17 00:00:00 2001 From: Tony Barnes Date: Tue, 6 Aug 2024 17:10:52 +0100 Subject: [PATCH] feat(EMS-3687): application submission - xlsx - how was contract awarded (#2907) * feat(EMS-3687): application submission - xlsx - how was contract awarded * feat(EMS-3687): add missing content string * chore(e2e): fix typo --- CHANGELOG.md | 1 - ...ract-was-awarded-from-other-method.spec.js | 2 +- ...ract-was-awarded-from-other-method.spec.js | 2 +- src/api/.keystone/config.js | 31 ++++- .../fields/insurance/export-contract/index.ts | 3 + .../map-export-contract/index.test.ts | 3 + .../map-export-contract/index.ts | 3 + .../index.test.ts | 110 ++++++++++++++++++ .../map-how-was-the-contract-awarded/index.ts | 43 +++++++ src/api/test-mocks/index.ts | 2 + src/api/types/application-types/index.ts | 1 + 11 files changed, 196 insertions(+), 5 deletions(-) create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/map-how-was-the-contract-awarded/index.test.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/map-how-was-the-contract-awarded/index.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 59bc539755..fe0e860aa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ ## [2.34.0](https://github.com/UK-Export-Finance/exip/compare/v2.33.0...v2.34.0) (2024-08-06) - ### Features * **EMS-3722-3723:** data migration - eligibility, export contract ([#2901](https://github.com/UK-Export-Finance/exip/issues/2901)) ([0c16bc1](https://github.com/UK-Export-Finance/exip/commit/0c16bc18b52bf1a6a0737a124d693203a8eba96a)) diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js index 9e735c477c..f15ffbf40b 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js @@ -60,7 +60,7 @@ context( beforeEach(() => { cy.navigateToUrl(url); - // select DIRECT_AWARD + // change to DIRECT_AWARD summaryList.field(FIELD_ID).changeLink().click(); cy.completeAndSubmitHowWasTheContractAwardedForm({ directAward: true }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js index f0df17e720..ac7252a596 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js @@ -47,7 +47,7 @@ context( beforeEach(() => { cy.navigateToUrl(checkYourAnswersUrl); - // select DIRECT_AWARD + // change to DIRECT_AWARD summaryList.field(FIELD_ID).changeLink().click(); cy.completeAndSubmitHowWasTheContractAwardedForm({ directAward: true }); diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index ffdfcad723..76e3f4d506 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -5786,6 +5786,9 @@ var EXPORT_CONTRACT_FIELDS = { VALUE: OTHER.DB_ID, TEXT: OTHER.VALUE } + }, + SUMMARY: { + TITLE: "How was the contract awarded" } } }, @@ -7344,8 +7347,31 @@ var mapBuyer = (application2) => { }; var map_buyer_default = mapBuyer; +// generate-xlsx/map-application-to-XLSX/map-export-contract/map-how-was-the-contract-awarded/index.ts +var { OTHER: OTHER2 } = EXPORT_CONTRACT_AWARD_METHOD; +var CONTENT_STRINGS8 = EXPORT_CONTRACT_FIELDS.HOW_WAS_THE_CONTRACT_AWARDED; +var { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD: AWARD_METHOD2, OTHER_AWARD_METHOD } +} = export_contract_default; +var mapHowWasTheContractAwarded = (exportContract) => { + const submittedMethodId = exportContract.awardMethodId; + let answer; + if (submittedMethodId === OTHER2.DB_ID) { + answer = exportContract[OTHER_AWARD_METHOD]; + } else { + const allMethods = Object.values(EXPORT_CONTRACT_AWARD_METHOD); + const method = allMethods.find((methodObj) => methodObj.DB_ID === submittedMethodId); + if (method) { + answer = method.VALUE; + } + } + const title = `${String(CONTENT_STRINGS8[AWARD_METHOD2].SUMMARY?.TITLE)}?`; + return xlsx_row_default(title, answer); +}; +var map_how_was_the_contract_awarded_default = mapHowWasTheContractAwarded; + // generate-xlsx/map-application-to-XLSX/map-export-contract/map-final-destination/index.ts -var CONTENT_STRINGS8 = EXPORT_CONTRACT_FIELDS.ABOUT_GOODS_OR_SERVICES; +var CONTENT_STRINGS9 = EXPORT_CONTRACT_FIELDS.ABOUT_GOODS_OR_SERVICES; var { FIELDS: FIELDS25 } = XLSX; var { ABOUT_GOODS_OR_SERVICES: { FINAL_DESTINATION: FINAL_DESTINATION2, FINAL_DESTINATION_KNOWN: FINAL_DESTINATION_KNOWN3 } @@ -7355,7 +7381,7 @@ var mapFinalDestination = (exportContract, countries) => { const mapped = [xlsx_row_default(String(FIELDS25.EXPORT_CONTRACT[FINAL_DESTINATION_KNOWN3]), map_yes_no_field_default({ answer: finalDestinationKnownAnswer }))]; if (finalDestinationKnownAnswer) { const country = get_country_by_iso_code_default(countries, exportContract[FINAL_DESTINATION2]); - mapped.push(xlsx_row_default(String(CONTENT_STRINGS8[FINAL_DESTINATION2].SUMMARY?.TITLE), country.name)); + mapped.push(xlsx_row_default(String(CONTENT_STRINGS9[FINAL_DESTINATION2].SUMMARY?.TITLE), country.name)); } return mapped; }; @@ -7457,6 +7483,7 @@ var mapExportContract = (application2, countries) => { const { agent, privateMarket } = exportContract; const mapped = [ xlsx_row_default(String(FIELDS30.EXPORT_CONTRACT[DESCRIPTION3]), exportContract[DESCRIPTION3]), + map_how_was_the_contract_awarded_default(exportContract), ...map_final_destination_default(exportContract, countries), xlsx_row_default(String(FIELDS30.EXPORT_CONTRACT[PAYMENT_TERMS_DESCRIPTION3]), exportContract[PAYMENT_TERMS_DESCRIPTION3]), ...map_private_market_default(privateMarket, totalContractValue), diff --git a/src/api/content-strings/fields/insurance/export-contract/index.ts b/src/api/content-strings/fields/insurance/export-contract/index.ts index 4131460cbb..160d69e91d 100644 --- a/src/api/content-strings/fields/insurance/export-contract/index.ts +++ b/src/api/content-strings/fields/insurance/export-contract/index.ts @@ -41,6 +41,9 @@ export const EXPORT_CONTRACT_FIELDS = { TEXT: OTHER.VALUE, }, }, + SUMMARY: { + TITLE: 'How was the contract awarded', + }, }, }, ABOUT_GOODS_OR_SERVICES: { diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/index.test.ts index 4a9ac282c6..6c4fa6e550 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/index.test.ts @@ -2,6 +2,7 @@ import mapExportContract from '.'; import FIELD_IDS from '../../../constants/field-ids/insurance/export-contract'; import { XLSX } from '../../../content-strings'; import xlsxRow from '../helpers/xlsx-row'; +import mapHowWasTheContractAwarded from './map-how-was-the-contract-awarded'; import mapFinalDestination from './map-final-destination'; import mapPrivateMarket from './map-private-market'; import mapAgent from './map-agent'; @@ -28,6 +29,8 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-export-contract', () => const expected = [ xlsxRow(String(FIELDS.EXPORT_CONTRACT[DESCRIPTION]), exportContract[DESCRIPTION]), + mapHowWasTheContractAwarded(exportContract), + ...mapFinalDestination(exportContract, mockCountries), xlsxRow(String(FIELDS.EXPORT_CONTRACT[PAYMENT_TERMS_DESCRIPTION]), exportContract[PAYMENT_TERMS_DESCRIPTION]), diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/index.ts index 92ff645426..a3e465af42 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/index.ts @@ -1,6 +1,7 @@ import FIELD_IDS from '../../../constants/field-ids/insurance/export-contract'; import { XLSX } from '../../../content-strings'; import xlsxRow from '../helpers/xlsx-row'; +import mapHowWasTheContractAwarded from './map-how-was-the-contract-awarded'; import mapFinalDestination from './map-final-destination'; import mapPrivateMarket from './map-private-market'; import mapAgent from './map-agent'; @@ -31,6 +32,8 @@ const mapExportContract = (application: Application, countries: Array) const mapped = [ xlsxRow(String(FIELDS.EXPORT_CONTRACT[DESCRIPTION]), exportContract[DESCRIPTION]), + mapHowWasTheContractAwarded(exportContract), + ...mapFinalDestination(exportContract, countries), xlsxRow(String(FIELDS.EXPORT_CONTRACT[PAYMENT_TERMS_DESCRIPTION]), exportContract[PAYMENT_TERMS_DESCRIPTION]), diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/map-how-was-the-contract-awarded/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/map-how-was-the-contract-awarded/index.test.ts new file mode 100644 index 0000000000..f6d63b6218 --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/map-how-was-the-contract-awarded/index.test.ts @@ -0,0 +1,110 @@ +import mapHowWasTheContractAwarded from '.'; +import { EXPORT_CONTRACT_AWARD_METHOD } from '../../../../constants'; +import FIELD_IDS from '../../../../constants/field-ids/insurance/export-contract'; +import { EXPORT_CONTRACT_FIELDS } from '../../../../content-strings/fields/insurance/export-contract'; +import xlsxRow from '../../helpers/xlsx-row'; +import { invalidId, mockApplication } from '../../../../test-mocks'; + +const { OPEN_TENDER, DIRECT_AWARD, COMPETITIVE_BIDDING, NEGOTIATED_CONTRACT, OTHER } = EXPORT_CONTRACT_AWARD_METHOD; + +const CONTENT_STRINGS = EXPORT_CONTRACT_FIELDS.HOW_WAS_THE_CONTRACT_AWARDED; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD, OTHER_AWARD_METHOD }, +} = FIELD_IDS; + +const { exportContract } = mockApplication; + +const expectedTitle = `${String(CONTENT_STRINGS[AWARD_METHOD].SUMMARY?.TITLE)}?`; + +describe('api/generate-xlsx/map-application-to-xlsx/map-export-contract/map-how-was-the-contract-awarded', () => { + describe(`when awardMethodId is ${OTHER.DB_ID}`, () => { + const mockExportContract = { + ...exportContract, + awardMethodId: OTHER.DB_ID, + }; + + it('should return a mapped field', () => { + const result = mapHowWasTheContractAwarded(mockExportContract); + + const expected = xlsxRow(expectedTitle, mockExportContract[OTHER_AWARD_METHOD]); + + expect(result).toEqual(expected); + }); + }); + + describe(`when awardMethodId is ${NEGOTIATED_CONTRACT.DB_ID}`, () => { + const mockExportContract = { + ...exportContract, + awardMethodId: NEGOTIATED_CONTRACT.DB_ID, + }; + + it('should return a mapped field', () => { + const result = mapHowWasTheContractAwarded(mockExportContract); + + const expected = xlsxRow(expectedTitle, NEGOTIATED_CONTRACT.VALUE); + + expect(result).toEqual(expected); + }); + }); + + describe(`when awardMethodId is ${OPEN_TENDER.DB_ID}`, () => { + const mockExportContract = { + ...exportContract, + awardMethodId: OPEN_TENDER.DB_ID, + }; + + it('should return a mapped field', () => { + const result = mapHowWasTheContractAwarded(mockExportContract); + + const expected = xlsxRow(expectedTitle, OPEN_TENDER.VALUE); + + expect(result).toEqual(expected); + }); + }); + + describe(`when awardMethodId is ${DIRECT_AWARD.DB_ID}`, () => { + const mockExportContract = { + ...exportContract, + awardMethodId: DIRECT_AWARD.DB_ID, + }; + + it('should return a mapped field', () => { + const result = mapHowWasTheContractAwarded(mockExportContract); + + const expected = xlsxRow(expectedTitle, DIRECT_AWARD.VALUE); + + expect(result).toEqual(expected); + }); + }); + + describe(`when awardMethodId is ${COMPETITIVE_BIDDING.DB_ID}`, () => { + const mockExportContract = { + ...exportContract, + awardMethodId: COMPETITIVE_BIDDING.DB_ID, + }; + + it('should return a mapped field', () => { + const result = mapHowWasTheContractAwarded(mockExportContract); + + const expected = xlsxRow(expectedTitle, COMPETITIVE_BIDDING.VALUE); + + expect(result).toEqual(expected); + }); + }); + + describe('when an award method is not recognised', () => { + const mockExportContract = { + ...exportContract, + awardMethodId: invalidId, + }; + + it('should return a mapped field with en empty answer', () => { + const result = mapHowWasTheContractAwarded(mockExportContract); + + const expected = xlsxRow(expectedTitle, ''); + + expect(result).toEqual(expected); + }); + }); +}); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/map-how-was-the-contract-awarded/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/map-how-was-the-contract-awarded/index.ts new file mode 100644 index 0000000000..2426baf548 --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-export-contract/map-how-was-the-contract-awarded/index.ts @@ -0,0 +1,43 @@ +import { EXPORT_CONTRACT_AWARD_METHOD } from '../../../../constants'; +import FIELD_IDS from '../../../../constants/field-ids/insurance/export-contract'; +import { EXPORT_CONTRACT_FIELDS } from '../../../../content-strings/fields/insurance/export-contract'; +import xlsxRow from '../../helpers/xlsx-row'; +import { ApplicationExportContract } from '../../../../types'; + +const { OTHER } = EXPORT_CONTRACT_AWARD_METHOD; + +const CONTENT_STRINGS = EXPORT_CONTRACT_FIELDS.HOW_WAS_THE_CONTRACT_AWARDED; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD, OTHER_AWARD_METHOD }, +} = FIELD_IDS; + +/** + * mapHowWasTheContractAwarded + * Map an application's export contract - AWARD_METHOD answers into an object for XLSX generation + * @param {ApplicationExportContract} application: Application export contract + * @returns {Object} xlsxRow + */ +const mapHowWasTheContractAwarded = (exportContract: ApplicationExportContract) => { + const submittedMethodId = exportContract.awardMethodId; + + let answer; + + if (submittedMethodId === OTHER.DB_ID) { + answer = exportContract[OTHER_AWARD_METHOD]; + } else { + const allMethods = Object.values(EXPORT_CONTRACT_AWARD_METHOD); + + const method = allMethods.find((methodObj) => methodObj.DB_ID === submittedMethodId); + + if (method) { + answer = method.VALUE; + } + } + + const title = `${String(CONTENT_STRINGS[AWARD_METHOD].SUMMARY?.TITLE)}?`; + + return xlsxRow(title, answer); +}; + +export default mapHowWasTheContractAwarded; diff --git a/src/api/test-mocks/index.ts b/src/api/test-mocks/index.ts index 75ba845f8a..c4f71c535a 100644 --- a/src/api/test-mocks/index.ts +++ b/src/api/test-mocks/index.ts @@ -20,6 +20,8 @@ const { const now = new Date(); +export const invalidId = 'invalid-id'; + export const mockAccount = { firstName: 'first', lastName: 'last', diff --git a/src/api/types/application-types/index.ts b/src/api/types/application-types/index.ts index 0caac31771..94c5f27b78 100644 --- a/src/api/types/application-types/index.ts +++ b/src/api/types/application-types/index.ts @@ -216,6 +216,7 @@ export interface ApplicationPrivateMarket extends Relationship { export interface ApplicationExportContract extends Relationship { agent: ApplicationExportContractAgent; + awardMethodId: string; id: string; finalDestinationKnown?: boolean; finalDestinationCountryCode?: string;