From f73873b1054bbbed50ac5dd81993aadfc1b41a1e Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Thu, 23 May 2024 16:59:48 +0100 Subject: [PATCH 01/29] feat(EMS-3345): no pdf - application submission - XLSX - exporter business --- .../insurance/complete-business-section.js | 4 +- ...pplication-section-multiple-policy-type.js | 3 + ...-application-section-single-policy-type.js | 3 + ...plete-sign-in-and-submit-an-application.js | 3 + ...fferent-trading-address-and-broker.spec.js | 30 +++ ...ype-with-different-trading-address.spec.js | 29 +++ ...nt-trading-name-address-and-broker.spec.js | 31 +++ ...different-trading-name-and-address.spec.js | 30 +++ ...-different-trading-name-and-broker.spec.js | 30 +++ ...y-type-with-different-trading-name.spec.js | 29 +++ ...fferent-trading-address-and-broker.spec.js | 27 +++ ...ype-with-different-trading-address.spec.js | 24 ++ ...nt-trading-name-address-and-broker.spec.js | 28 +++ ...different-trading-name-and-address.spec.js | 27 +++ ...-different-trading-name-and-broker.spec.js | 27 +++ ...y-type-with-different-trading-name.spec.js | 24 ++ ...lication-different-trading-address.spec.js | 21 -- src/api/.keystone/config.js | 182 +++++++++------ src/api/constants/XLSX-CONFIG/index.test.ts | 31 +-- src/api/constants/XLSX-CONFIG/index.ts | 80 +++++-- .../field-ids/insurance/business/index.ts | 5 +- src/api/content-strings/XLSX.ts | 14 +- .../map-application-to-XLSX/index.test.ts | 6 +- .../map-application-to-XLSX/index.ts | 6 +- .../index.test.ts | 2 +- .../map-exporter-business/index.ts | 144 ++++++++++++ .../map-address/index.test.ts | 0 .../map-address/index.ts | 0 .../map-exporter/index.ts | 122 ---------- .../index.api-error.test.ts | 211 ++++++++++++++++++ .../get-populated-application/index.test.ts | 165 +------------- .../get-populated-application/index.ts | 13 ++ src/api/types/application-types/index.ts | 13 +- src/api/types/xlsx-types/index.ts | 1 + 34 files changed, 942 insertions(+), 423 deletions(-) create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address-and-broker.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-address-and-broker.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-address.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-broker.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-address-and-broker.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-address.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-address-and-broker.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-and-address.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-and-broker.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name.spec.js delete mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/submit-an-application-different-trading-address.spec.js rename src/api/generate-xlsx/map-application-to-XLSX/{map-exporter => map-exporter-business}/index.test.ts (99%) create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts rename src/api/generate-xlsx/map-application-to-XLSX/{map-exporter => map-exporter-business}/map-address/index.test.ts (100%) rename src/api/generate-xlsx/map-application-to-XLSX/{map-exporter => map-exporter-business}/map-address/index.ts (100%) delete mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-exporter/index.ts create mode 100644 src/api/helpers/get-populated-application/index.api-error.test.ts diff --git a/e2e-tests/commands/insurance/complete-business-section.js b/e2e-tests/commands/insurance/complete-business-section.js index 0b3bb64bc3..61b66cec06 100644 --- a/e2e-tests/commands/insurance/complete-business-section.js +++ b/e2e-tests/commands/insurance/complete-business-section.js @@ -2,19 +2,21 @@ * completeBusinessSection * Complete the "business" section * @param {Boolean} viaTaskList: Start the "business" section from the task list. + * @param {Boolean} differentTradingName: Should submit "yes" to "have a different trading name" in the "company details" form. * @param {Boolean} differentTradingAddress: Should submit "yes" to "trade from a different address" in the "company details" form. * @param {Boolean} hasCreditControlProcess: Flag whether to submit "yes" or "no" radio input in the "credit control" form. * @param {Boolean} submitCheckYourAnswers: Click policy "check your answers" submit button */ const completeBusinessSection = ({ viaTaskList, + differentTradingName = false, differentTradingAddress = false, hasCreditControlProcess = false, submitCheckYourAnswers = false, }) => { cy.startYourBusinessSection({ viaTaskList }); - cy.completeAndSubmitCompanyDetails({ differentTradingAddress }); + cy.completeAndSubmitCompanyDetails({ differentTradingName, differentTradingAddress }); if (differentTradingAddress) { cy.completeAndSubmitAlternativeTradingAddressForm({}); diff --git a/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js b/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js index 3335ad5878..f5921c92eb 100644 --- a/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js +++ b/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js @@ -6,6 +6,7 @@ const { POLICY_TYPE } = APPLICATION; * completePrepareApplicationMultiplePolicyType * Runs through the full prepare your application journey for multiple policy type * @param {Object} Object with flags on how to complete specific parts of the application + * @param {Boolean} differentTradingName: Should submit "yes" to "have a different trading name" in the "company details" form. Defaults to false. * @param {Boolean} differentTradingAddress: Should submit "yes" to "trade from a different address" in the "company details" form. Defaults to false. * @param {Boolean} hasCreditControlProcess: Flag whether to submit "yes" or "no" radio input in the "credit control" form. Defaults to false. * @param {Boolean} hasConnectionToBuyer: Should submit "yes" to "have connection to buyer" radio. @@ -29,6 +30,7 @@ const { POLICY_TYPE } = APPLICATION; * @param {Boolean} submitCheckYourAnswers: Should click each section's "check your answers" submit button. */ const completePrepareApplicationMultiplePolicyType = ({ + differentTradingName = false, differentTradingAddress = false, hasCreditControlProcess = false, hasConnectionToBuyer = false, @@ -52,6 +54,7 @@ const completePrepareApplicationMultiplePolicyType = ({ submitCheckYourAnswers = true, }) => { cy.completeBusinessSection({ + differentTradingName, differentTradingAddress, hasCreditControlProcess, submitCheckYourAnswers, diff --git a/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js b/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js index a968c1a425..6f0c8378d1 100644 --- a/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js +++ b/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js @@ -6,6 +6,7 @@ const { POLICY_TYPE } = FIELD_VALUES; * completePrepareYourApplicationSectionSingle * Runs through the full prepare your application journey for a single policy type * @param {Object} Object with flags on how to complete specific parts of the application + * @param {Boolean} differentTradingName: Should submit "yes" to "have a different trading name" in the "company details" form. Defaults to false. * @param {Boolean} differentTradingAddress: Should submit "yes" to "trade from a different address" in the "company details" form. Defaults to false. * @param {Boolean} hasCreditControlProcess: Flag whether to submit "yes" or "no" radio input in the "credit control" form. Defaults to false. * @param {Boolean} hasConnectionToBuyer: Should submit "yes" to "have connection to buyer" radio. @@ -29,6 +30,7 @@ const { POLICY_TYPE } = FIELD_VALUES; * @param {Boolean} submitCheckYourAnswers: Should click each section's "check your answers" submit button. */ const completePrepareApplicationSinglePolicyType = ({ + differentTradingName = false, differentTradingAddress = false, hasCreditControlProcess = false, hasConnectionToBuyer, @@ -52,6 +54,7 @@ const completePrepareApplicationSinglePolicyType = ({ submitCheckYourAnswers = true, }) => { cy.completeBusinessSection({ + differentTradingName, differentTradingAddress, hasCreditControlProcess, submitCheckYourAnswers, diff --git a/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js b/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js index 32291eb839..dcf3066adc 100644 --- a/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js +++ b/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js @@ -27,6 +27,7 @@ import completeSignInAndGoToApplication from './account/complete-sign-in-and-go- * @return {String} Application reference number */ const completeSignInAndSubmitAnApplication = ({ + differentTradingName = false, differentTradingAddress = false, policyType = APPLICATION.POLICY_TYPE.SINGLE, exporterHasTradedWithBuyer, @@ -48,6 +49,7 @@ const completeSignInAndSubmitAnApplication = ({ completeSignInAndGoToApplication({ totalContractValueOverThreshold }).then(({ referenceNumber }) => { if (policyType === APPLICATION.POLICY_TYPE.MULTIPLE) { cy.completePrepareApplicationMultiplePolicyType({ + differentTradingName, differentTradingAddress, exporterHasTradedWithBuyer, policyValueOverMvpMaximum, @@ -66,6 +68,7 @@ const completeSignInAndSubmitAnApplication = ({ }); } else { cy.completePrepareApplicationSinglePolicyType({ + differentTradingName, differentTradingAddress, exporterHasTradedWithBuyer, policyValueOverMvpMaximum, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address-and-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address-and-broker.spec.js new file mode 100644 index 0000000000..b8c8946221 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address-and-broker.spec.js @@ -0,0 +1,30 @@ +import { APPLICATION } from '../../../../../../constants'; + +context( + 'Insurance - submit an application - Single policy type with a different trading address and broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + differentTradingAddress: true, + usingBroker: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address.spec.js new file mode 100644 index 0000000000..9ed4402eca --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address.spec.js @@ -0,0 +1,29 @@ +import { APPLICATION } from '../../../../../../constants'; + +context( + 'Insurance - submit an application - Multiple policy type, different trading address - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + differentTradingAddress: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-address-and-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-address-and-broker.spec.js new file mode 100644 index 0000000000..f203ed5fd1 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-address-and-broker.spec.js @@ -0,0 +1,31 @@ +import { APPLICATION } from '../../../../../../constants'; + +context( + 'Insurance - submit an application - Single policy type with a different trading name, address and broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + differentTradingName: true, + differentTradingAddress: true, + usingBroker: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-address.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-address.spec.js new file mode 100644 index 0000000000..f09bf99b73 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-address.spec.js @@ -0,0 +1,30 @@ +import { APPLICATION } from '../../../../../../constants'; + +context( + 'Insurance - submit an application - Multiple policy type, different trading name and address - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + differentTradingName: true, + differentTradingAddress: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-broker.spec.js new file mode 100644 index 0000000000..af5c89a9c0 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-broker.spec.js @@ -0,0 +1,30 @@ +import { APPLICATION } from '../../../../../../constants'; + +context( + 'Insurance - submit an application - Single policy type with a different trading name and broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + differentTradingName: true, + usingBroker: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name.spec.js new file mode 100644 index 0000000000..34ed61ac18 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name.spec.js @@ -0,0 +1,29 @@ +import { APPLICATION } from '../../../../../../constants'; + +context( + 'Insurance - submit an application - Multiple policy type, different trading name - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + differentTradingName: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-address-and-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-address-and-broker.spec.js new file mode 100644 index 0000000000..5ac9e7e440 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-address-and-broker.spec.js @@ -0,0 +1,27 @@ +context( + 'Insurance - submit an application - Single policy type with a different trading address and broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + differentTradingAddress: true, + usingBroker: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-address.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-address.spec.js new file mode 100644 index 0000000000..8c60b0240c --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-address.spec.js @@ -0,0 +1,24 @@ +context( + 'Insurance - submit an application - Single policy type, different trading address - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ differentTradingAddress: true }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-address-and-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-address-and-broker.spec.js new file mode 100644 index 0000000000..02e36dbd08 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-address-and-broker.spec.js @@ -0,0 +1,28 @@ +context( + 'Insurance - submit an application - Single policy type with a different trading name, address and broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + differentTradingName: true, + differentTradingAddress: true, + usingBroker: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-and-address.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-and-address.spec.js new file mode 100644 index 0000000000..31556e2ec3 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-and-address.spec.js @@ -0,0 +1,27 @@ +context( + 'Insurance - submit an application - Single policy type, different trading name and address - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + differentTradingName: true, + differentTradingAddress: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-and-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-and-broker.spec.js new file mode 100644 index 0000000000..586d78d4ad --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-and-broker.spec.js @@ -0,0 +1,27 @@ +context( + 'Insurance - submit an application - Single policy type with a different trading name and broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + differentTradingName: true, + usingBroker: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name.spec.js new file mode 100644 index 0000000000..c9e3c7b4df --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name.spec.js @@ -0,0 +1,24 @@ +context( + 'Insurance - submit an application - Single policy type, different trading name - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ differentTradingName: true }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/submit-an-application-different-trading-address.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/submit-an-application-different-trading-address.spec.js deleted file mode 100644 index 39e0052627..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/submit-an-application-different-trading-address.spec.js +++ /dev/null @@ -1,21 +0,0 @@ -context('Insurance - submit an application - Single policy type, with a different `trading address`', () => { - let referenceNumber; - - before(() => { - cy.completeSignInAndSubmitAnApplication({ differentTradingAddress: true }).then((refNumber) => { - referenceNumber = refNumber; - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - it('should successfully submit the application and redirect to `application submitted`', () => { - cy.assertApplicationSubmittedUrl(referenceNumber); - }); -}); diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 3e8365af75..c892e4709f 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -389,10 +389,13 @@ var EXPORTER_BUSINESS = { YOUR_BUSINESS: "yourBusiness", TRADING_ADDRESS: "hasDifferentTradingAddress", HAS_DIFFERENT_TRADING_NAME: "hasDifferentTradingName", + DIFFERENT_TRADING_NAME: "differentTradingName", WEBSITE: "companyWebsite", PHONE_NUMBER: "phoneNumber" }, - ALTERNATIVE_TRADING_ADDRESS: "alternativeTradingAddress", + ALTERNATIVE_TRADING_ADDRESS: { + FULL_ADDRESS: "fullAddress" + }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: "goodsOrServicesSupplied", YEARS_EXPORTING: "totalYearsExporting", @@ -793,21 +796,23 @@ var TITLE_INDEXES = () => ({ EXPORTER_CONTACT_DETAILS: 10, KEY_INFORMATION: 15, ELIGIBILITY: 21, - POLICY: 31, - EXPORTER_BUSINESS: 40, - BUYER: 58, - DECLARATIONS: 66 + EXPORTER_BUSINESS: 31, + POLICY: 48, + BUYER: 57, + DECLARATIONS: 65 }); var INDEXES = () => ({ TITLES: TITLE_INDEXES(), - COMPANY_ADDRESS: 34, - COMPANY_SIC_CODES: 37, - BROKER_ADDRESS: 45, - BUYER_ADDRESS: 50, - BUYER_CONTACT_DETAILS: 53 + COMPANY_ADDRESS: 33, + COMPANY_SIC_CODES: 44, + BUYER_ADDRESS: 64 }); var XLSX_ROW_INDEXES = (application2) => { - const { policy, broker } = application2; + const { + broker, + company: { hasDifferentTradingName, differentTradingAddress: { fullAddress: hasDifferentTradingAddress } }, + policy + } = application2; const policyType = policy[POLICY_TYPE2]; let isMultiplePolicy = false; if (isMultiplePolicyType(policyType)) { @@ -815,19 +820,37 @@ var XLSX_ROW_INDEXES = (application2) => { } const indexes = INDEXES(); if (isMultiplePolicy) { - indexes.TITLES.EXPORTER_BUSINESS += 1; indexes.TITLES.BUYER += 1; indexes.TITLES.DECLARATIONS += 1; - indexes.COMPANY_ADDRESS += 1; - indexes.COMPANY_SIC_CODES += 1; - indexes.BROKER_ADDRESS += 1; indexes.BUYER_ADDRESS += 1; indexes.BUYER_CONTACT_DETAILS += 1; } if (broker[USING_BROKER]) { + indexes.BROKER_ADDRESS = 48; + indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; indexes.TITLES.DECLARATIONS += 3; } + if (hasDifferentTradingName) { + indexes.COMPANY_SIC_CODES += 1; + indexes.BROKER_ADDRESS += 1; + indexes.BUYER_ADDRESS += 1; + indexes.TITLES.POLICY += 1; + indexes.TITLES.BUYER += 1; + indexes.TITLES.DECLARATIONS += 1; + } + if (hasDifferentTradingAddress) { + indexes.ALTERNATIVE_TRADING_ADDRESS = 36; + indexes.COMPANY_SIC_CODES += 1; + indexes.BROKER_ADDRESS += 1; + indexes.BUYER_ADDRESS += 1; + indexes.TITLES.POLICY += 1; + indexes.TITLES.BUYER += 1; + indexes.TITLES.DECLARATIONS += 1; + } + if (hasDifferentTradingName && hasDifferentTradingAddress) { + indexes.ALTERNATIVE_TRADING_ADDRESS = 37; + } return indexes; }; var XLSX_CONFIG = { @@ -4728,9 +4751,19 @@ var getPopulatedApplication = async (context, application2) => { const companyAddress = await context.db.CompanyAddress.findOne({ where: { id: company.registeredOfficeAddressId } }); + if (!companyAddress) { + throw new Error(generateErrorMessage("companyAddress", application2.id)); + } + const differentTradingAddress = await context.db.CompanyDifferentTradingAddress.findOne({ + where: { id: company.differentTradingAddressId } + }); + if (!differentTradingAddress) { + throw new Error(generateErrorMessage("differentTradingAddress", application2.id)); + } const populatedCompany = { ...company, - registeredOfficeAddress: companyAddress + registeredOfficeAddress: companyAddress, + differentTradingAddress }; const business = await context.db.Business.findOne({ where: { id: businessId } @@ -5451,10 +5484,12 @@ var { ACCOUNT: { FIRST_NAME, LAST_NAME }, ELIGIBILITY: { BUYER_COUNTRY: BUYER_COUNTRY2, COMPANIES_HOUSE_NUMBER: COMPANIES_HOUSE_NUMBER2, COVER_PERIOD: COVER_PERIOD2, HAS_END_BUYER: HAS_END_BUYER2, HAS_MINIMUM_UK_GOODS_OR_SERVICES: HAS_MINIMUM_UK_GOODS_OR_SERVICES2 }, EXPORTER_BUSINESS: { - COMPANIES_HOUSE: { COMPANY_NAME: EXPORTER_COMPANY_NAME, COMPANY_ADDRESS: EXPORTER_COMPANY_ADDRESS, COMPANY_SIC: EXPORTER_COMPANY_SIC }, - YOUR_COMPANY: { WEBSITE: WEBSITE2, PHONE_NUMBER: PHONE_NUMBER2 }, + COMPANIES_HOUSE: { COMPANY_ADDRESS: EXPORTER_COMPANY_ADDRESS, COMPANY_SIC: EXPORTER_COMPANY_SIC }, + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME: HAS_DIFFERENT_TRADING_NAME2, DIFFERENT_TRADING_NAME, PHONE_NUMBER: PHONE_NUMBER2, TRADING_ADDRESS: TRADING_ADDRESS2, WEBSITE: WEBSITE2 }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: GOODS_OR_SERVICES2, YEARS_EXPORTING: YEARS_EXPORTING2, EMPLOYEES_UK: EMPLOYEES_UK2 }, - TURNOVER: { ESTIMATED_ANNUAL_TURNOVER: ESTIMATED_ANNUAL_TURNOVER2 } + TURNOVER: { ESTIMATED_ANNUAL_TURNOVER: ESTIMATED_ANNUAL_TURNOVER2 }, + ALTERNATIVE_TRADING_ADDRESS: ALTERNATIVE_TRADING_ADDRESS2, + HAS_CREDIT_CONTROL: HAS_CREDIT_CONTROL2 }, POLICY: { CONTRACT_POLICY: { @@ -5493,13 +5528,17 @@ var XLSX = { [COVER_PERIOD2]: "Length of cover", [HAS_END_BUYER2]: "Is there an end buyer?", [HAS_MINIMUM_UK_GOODS_OR_SERVICES2]: "Is at least 20% of the contract value made up from UK goods or services", + [HAS_CREDIT_CONTROL2]: "Do you have a process for dealing with late payments", [CONTRACT_COMPLETION_DATE2]: "Date expected for contract to complete", - [EXPORTER_COMPANY_NAME]: "Exporter company name", [EXPORTER_COMPANY_ADDRESS]: "Exporter registered office address", [EXPORTER_COMPANY_SIC]: "Exporter standard industry classification (SIC) codes and nature of business", + [HAS_DIFFERENT_TRADING_NAME2]: "Different trading name?", + [DIFFERENT_TRADING_NAME]: "Alternative trading name", + [TRADING_ADDRESS2]: "Different trading address?", + [ALTERNATIVE_TRADING_ADDRESS2.FULL_ADDRESS]: "Alternative trading address", [MORE_THAN_250K.VALUE]: `Insured for more than ${format_currency_default(AMOUNT_250K, GBP_CURRENCY_CODE)}`, [WEBSITE2]: "Exporter Company website (optional)", - [PHONE_NUMBER2]: "Exporter telephone number (optional)", + [PHONE_NUMBER2]: "Exporter UK telephone number (optional)", [GOODS_OR_SERVICES2]: "Goods or services the business supplies", [YEARS_EXPORTING2]: "Exporter years exporting", [EMPLOYEES_UK2]: "Exporter UK Employees", @@ -5573,7 +5612,7 @@ var CONTENT_STRINGS = { }; var { EXPORTER_BUSINESS: { - COMPANIES_HOUSE: { COMPANY_NAME: EXPORTER_COMPANY_NAME2 } + COMPANIES_HOUSE: { COMPANY_NAME: EXPORTER_COMPANY_NAME } }, YOUR_BUYER: { COMPANY_OR_ORGANISATION: { COUNTRY: COUNTRY2, NAME: BUYER_COMPANY_NAME2 } @@ -5586,7 +5625,7 @@ var mapKeyInformation = (application2) => { const { policy } = application2; const mapped = [ xlsx_row_default(KEY_INFORMATION), - xlsx_row_default(FIELDS4[EXPORTER_COMPANY_NAME2], application2.company[EXPORTER_COMPANY_NAME2]), + xlsx_row_default(FIELDS4[EXPORTER_COMPANY_NAME], application2.company[EXPORTER_COMPANY_NAME]), xlsx_row_default(FIELDS4[COUNTRY2], application2.buyer[COUNTRY2].name), xlsx_row_default(FIELDS4[BUYER_COMPANY_NAME2], application2.buyer[BUYER_COMPANY_NAME2]), xlsx_row_default(String(CONTENT_STRINGS[POLICY_TYPE5].SUMMARY?.TITLE), policy[POLICY_TYPE5]) @@ -5688,7 +5727,7 @@ var map_policy_default = mapPolicy; var NEW_LINE = "\r\n"; var xlsx_new_line_default = NEW_LINE; -// generate-xlsx/map-application-to-XLSX/map-exporter/map-address/index.ts +// generate-xlsx/map-application-to-XLSX/map-exporter-business/map-address/index.ts var mapExporterAddress = (address) => { let addressString = ""; Object.keys(address).forEach((field) => { @@ -5712,7 +5751,8 @@ var mapYesNoField = (answer) => { }; var map_yes_no_field_default = mapYesNoField; -// generate-xlsx/map-application-to-XLSX/map-exporter/index.ts +// generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts +var { FIELDS: FIELDS5, SECTION_TITLES } = XLSX; var CONTENT_STRINGS3 = { ...FIELDS.COMPANY_DETAILS, ...FIELDS.NATURE_OF_YOUR_BUSINESS, @@ -5721,10 +5761,12 @@ var CONTENT_STRINGS3 = { }; var { EXPORTER_BUSINESS: { - COMPANIES_HOUSE: { COMPANY_NUMBER: COMPANY_NUMBER2, COMPANY_NAME: COMPANY_NAME3, COMPANY_ADDRESS: COMPANY_ADDRESS2, COMPANY_INCORPORATED: COMPANY_INCORPORATED2, COMPANY_SIC: COMPANY_SIC2, FINANCIAL_YEAR_END_DATE: FINANCIAL_YEAR_END_DATE2 }, - YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME: HAS_DIFFERENT_TRADING_NAME2, TRADING_ADDRESS: TRADING_ADDRESS2, WEBSITE: WEBSITE3, PHONE_NUMBER: PHONE_NUMBER3 }, + COMPANIES_HOUSE: { COMPANY_ADDRESS: COMPANY_ADDRESS2, COMPANY_INCORPORATED: COMPANY_INCORPORATED2, COMPANY_SIC: COMPANY_SIC2, FINANCIAL_YEAR_END_DATE: FINANCIAL_YEAR_END_DATE2 }, + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME: HAS_DIFFERENT_TRADING_NAME3, DIFFERENT_TRADING_NAME: DIFFERENT_TRADING_NAME2, PHONE_NUMBER: PHONE_NUMBER3, TRADING_ADDRESS: TRADING_ADDRESS3, WEBSITE: WEBSITE3 }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: GOODS_OR_SERVICES3, YEARS_EXPORTING: YEARS_EXPORTING3, EMPLOYEES_UK: EMPLOYEES_UK3 }, - TURNOVER: { ESTIMATED_ANNUAL_TURNOVER: ESTIMATED_ANNUAL_TURNOVER3, PERCENTAGE_TURNOVER: PERCENTAGE_TURNOVER2 } + TURNOVER: { ESTIMATED_ANNUAL_TURNOVER: ESTIMATED_ANNUAL_TURNOVER3, PERCENTAGE_TURNOVER: PERCENTAGE_TURNOVER2 }, + ALTERNATIVE_TRADING_ADDRESS: ALTERNATIVE_TRADING_ADDRESS3, + HAS_CREDIT_CONTROL: HAS_CREDIT_CONTROL3 }, POLICY: { USING_BROKER: USING_BROKER4, @@ -5741,48 +5783,62 @@ var mapSicCodes2 = (sicCodes) => { }; var mapBroker = (application2) => { const { broker } = application2; - let mapped = [xlsx_row_default(XLSX.FIELDS[USING_BROKER4], map_yes_no_field_default(broker[USING_BROKER4]))]; + let mapped = [xlsx_row_default(FIELDS5[USING_BROKER4], map_yes_no_field_default(broker[USING_BROKER4]))]; if (broker[USING_BROKER4]) { mapped = [ ...mapped, - xlsx_row_default(XLSX.FIELDS[BROKER_NAME2], broker[BROKER_NAME2]), - xlsx_row_default(XLSX.FIELDS[FULL_ADDRESS2], broker[FULL_ADDRESS2]), - xlsx_row_default(XLSX.FIELDS[EMAIL7], broker[EMAIL7]) + xlsx_row_default(FIELDS5[BROKER_NAME2], broker[BROKER_NAME2]), + xlsx_row_default(FIELDS5[FULL_ADDRESS2], broker[FULL_ADDRESS2]), + xlsx_row_default(FIELDS5[EMAIL7], broker[EMAIL7]) ]; } return mapped; }; -var mapExporter = (application2) => { - const { company, companySicCodes, business } = application2; +var mapExporterBusiness = (application2) => { + const { business, company, companySicCodes } = application2; + const { differentTradingAddress } = company; let financialYearEndDate = "No data from Companies House"; if (company[FINANCIAL_YEAR_END_DATE2]) { financialYearEndDate = format_date_default(company[FINANCIAL_YEAR_END_DATE2], "d MMMM"); } - const mapped = [ - xlsx_row_default(XLSX.SECTION_TITLES.EXPORTER_BUSINESS, ""), - // company fields - xlsx_row_default(CONTENT_STRINGS3[COMPANY_NUMBER2].SUMMARY?.TITLE, company[COMPANY_NUMBER2]), - xlsx_row_default(XLSX.FIELDS[COMPANY_NAME3], company[COMPANY_NAME3]), + const hasDifferentTradingName = company[HAS_DIFFERENT_TRADING_NAME3]; + const hasDifferentTradingAddress = differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS3.FULL_ADDRESS]; + let mapped = [ + xlsx_row_default(SECTION_TITLES.EXPORTER_BUSINESS, ""), xlsx_row_default(CONTENT_STRINGS3[COMPANY_INCORPORATED2].SUMMARY?.TITLE, format_date_default(company[COMPANY_INCORPORATED2], "dd-MMM-yy")), - xlsx_row_default(XLSX.FIELDS[COMPANY_ADDRESS2], map_address_default(company[COMPANY_ADDRESS2])), - xlsx_row_default(CONTENT_STRINGS3[HAS_DIFFERENT_TRADING_NAME2].SUMMARY?.TITLE, map_yes_no_field_default(company[HAS_DIFFERENT_TRADING_NAME2])), - xlsx_row_default(CONTENT_STRINGS3[TRADING_ADDRESS2].SUMMARY?.TITLE, map_yes_no_field_default(company[TRADING_ADDRESS2])), - xlsx_row_default(XLSX.FIELDS[COMPANY_SIC2], mapSicCodes2(companySicCodes)), - xlsx_row_default(CONTENT_STRINGS3[FINANCIAL_YEAR_END_DATE2].SUMMARY?.TITLE, financialYearEndDate), - xlsx_row_default(XLSX.FIELDS[WEBSITE3], company[WEBSITE3]), - xlsx_row_default(XLSX.FIELDS[PHONE_NUMBER3], company[PHONE_NUMBER3]), - // business fields - xlsx_row_default(XLSX.FIELDS[GOODS_OR_SERVICES3], business[GOODS_OR_SERVICES3]), - xlsx_row_default(XLSX.FIELDS[YEARS_EXPORTING3], business[YEARS_EXPORTING3]), - xlsx_row_default(XLSX.FIELDS[EMPLOYEES_UK3], business[EMPLOYEES_UK3]), - xlsx_row_default(XLSX.FIELDS[ESTIMATED_ANNUAL_TURNOVER3], format_currency_default2(business[ESTIMATED_ANNUAL_TURNOVER3], GBP_CURRENCY_CODE)), + xlsx_row_default(FIELDS5[COMPANY_ADDRESS2], map_address_default(company[COMPANY_ADDRESS2])), + xlsx_row_default(FIELDS5[HAS_DIFFERENT_TRADING_NAME3], map_yes_no_field_default(company[HAS_DIFFERENT_TRADING_NAME3])) + ]; + if (hasDifferentTradingName) { + mapped.push( + xlsx_row_default(FIELDS5[DIFFERENT_TRADING_NAME2], company[DIFFERENT_TRADING_NAME2]) + ); + } + mapped.push( + xlsx_row_default(FIELDS5[TRADING_ADDRESS3], map_yes_no_field_default(company[TRADING_ADDRESS3])) + ); + if (hasDifferentTradingAddress) { + mapped.push( + xlsx_row_default(FIELDS5[ALTERNATIVE_TRADING_ADDRESS3.FULL_ADDRESS], differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS3.FULL_ADDRESS]) + ); + } + mapped = [ + ...mapped, + xlsx_row_default(FIELDS5[WEBSITE3], company[WEBSITE3]), + xlsx_row_default(FIELDS5[PHONE_NUMBER3], company[PHONE_NUMBER3]), + xlsx_row_default(FIELDS5[GOODS_OR_SERVICES3], business[GOODS_OR_SERVICES3]), + xlsx_row_default(FIELDS5[YEARS_EXPORTING3], business[YEARS_EXPORTING3]), + xlsx_row_default(FIELDS5[EMPLOYEES_UK3], business[EMPLOYEES_UK3]), + xlsx_row_default(FIELDS5[ESTIMATED_ANNUAL_TURNOVER3], format_currency_default2(business[ESTIMATED_ANNUAL_TURNOVER3], GBP_CURRENCY_CODE)), xlsx_row_default(CONTENT_STRINGS3[PERCENTAGE_TURNOVER2].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER2]}%`), - // broker fields + xlsx_row_default(FIELDS5[HAS_CREDIT_CONTROL3], map_yes_no_field_default(business[HAS_CREDIT_CONTROL3])), + xlsx_row_default(FIELDS5[COMPANY_SIC2], mapSicCodes2(companySicCodes)), + xlsx_row_default(CONTENT_STRINGS3[FINANCIAL_YEAR_END_DATE2].SUMMARY?.TITLE, financialYearEndDate), ...mapBroker(application2) ]; return mapped; }; -var map_exporter_default = mapExporter; +var map_exporter_business_default = mapExporterBusiness; // generate-xlsx/map-application-to-XLSX/map-buyer/index.ts var CONTENT_STRINGS4 = { @@ -5811,7 +5867,7 @@ var map_buyer_default = mapBuyer; // generate-xlsx/map-application-to-XLSX/map-eligibility/index.ts var { MORE_THAN_250K: MORE_THAN_250K2 } = TOTAL_CONTRACT_VALUE; -var { FIELDS: FIELDS5, SECTION_TITLES } = XLSX; +var { FIELDS: FIELDS6, SECTION_TITLES: SECTION_TITLES2 } = XLSX; var { ELIGIBILITY: { BUYER_COUNTRY: BUYER_COUNTRY3, @@ -5828,15 +5884,15 @@ var { var mapEligibility = (application2) => { const { company, eligibility } = application2; const mapped = [ - xlsx_row_default(SECTION_TITLES.ELIGIBILITY, ""), + xlsx_row_default(SECTION_TITLES2.ELIGIBILITY, ""), xlsx_row_default(FIELDS_ELIGIBILITY[VALID_EXPORTER_LOCATION2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[VALID_EXPORTER_LOCATION2])), xlsx_row_default(FIELDS_ELIGIBILITY[HAS_COMPANIES_HOUSE_NUMBER2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[HAS_COMPANIES_HOUSE_NUMBER2])), - xlsx_row_default(FIELDS5[COMPANIES_HOUSE_NUMBER3], company[COMPANIES_HOUSE_NUMBER3]), - xlsx_row_default(FIELDS5[BUYER_COUNTRY3], eligibility[BUYER_COUNTRY3].name), - xlsx_row_default(FIELDS5[MORE_THAN_250K2.VALUE], map_yes_no_field_default(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID)), - xlsx_row_default(FIELDS5[COVER_PERIOD3], eligibility[COVER_PERIOD_ELIGIBILITY].value), - xlsx_row_default(FIELDS5[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3])), - xlsx_row_default(FIELDS5[HAS_END_BUYER3], map_yes_no_field_default(eligibility[HAS_END_BUYER3])) + xlsx_row_default(FIELDS6[COMPANIES_HOUSE_NUMBER3], company[COMPANIES_HOUSE_NUMBER3]), + xlsx_row_default(FIELDS6[BUYER_COUNTRY3], eligibility[BUYER_COUNTRY3].name), + xlsx_row_default(FIELDS6[MORE_THAN_250K2.VALUE], map_yes_no_field_default(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID)), + xlsx_row_default(FIELDS6[COVER_PERIOD3], eligibility[COVER_PERIOD_ELIGIBILITY].value), + xlsx_row_default(FIELDS6[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3])), + xlsx_row_default(FIELDS6[HAS_END_BUYER3], map_yes_no_field_default(eligibility[HAS_END_BUYER3])) ]; return mapped; }; @@ -5889,9 +5945,9 @@ var mapApplicationToXLSX = (application2) => { xlsx_row_seperator_default, ...map_eligibility_default(application2), xlsx_row_seperator_default, - ...map_policy_default(application2), + ...map_exporter_business_default(application2), xlsx_row_seperator_default, - ...map_exporter_default(application2), + ...map_policy_default(application2), xlsx_row_seperator_default, ...map_buyer_default(application2), xlsx_row_seperator_default, diff --git a/src/api/constants/XLSX-CONFIG/index.test.ts b/src/api/constants/XLSX-CONFIG/index.test.ts index b6d767af11..b22847fc68 100644 --- a/src/api/constants/XLSX-CONFIG/index.test.ts +++ b/src/api/constants/XLSX-CONFIG/index.test.ts @@ -16,8 +16,8 @@ describe('api/constants/XLSX-CONFIG', () => { EXPORTER_CONTACT_DETAILS: 10, KEY_INFORMATION: 15, ELIGIBILITY: 21, - POLICY: 31, - EXPORTER_BUSINESS: 40, + EXPORTER_BUSINESS: 31, + POLICY: 49, BUYER: 58, DECLARATIONS: 66, }; @@ -30,11 +30,9 @@ describe('api/constants/XLSX-CONFIG', () => { it('should return default indexes', () => { const expected = { TITLES: TITLE_INDEXES(), - COMPANY_ADDRESS: 34, - COMPANY_SIC_CODES: 37, - BROKER_ADDRESS: 45, - BUYER_ADDRESS: 50, - BUYER_CONTACT_DETAILS: 53, + COMPANY_ADDRESS: 35, + COMPANY_SIC_CODES: 38, + BUYER_ADDRESS: 60, }; expect(INDEXES()).toEqual(expected); @@ -92,8 +90,10 @@ describe('api/constants/XLSX-CONFIG', () => { const expected = { ...defaultIndexes, + BROKER_ADDRESS: 49, TITLES: { ...defaultTitleIndexes, + POLICY: defaultTitleIndexes.POLICY + 3, BUYER: defaultTitleIndexes.BUYER + 3, DECLARATIONS: defaultTitleIndexes.DECLARATIONS + 3, }, @@ -142,14 +142,11 @@ describe('api/constants/XLSX-CONFIG', () => { const expected = { ...defaultIndexes, - COMPANY_ADDRESS: defaultIndexes.COMPANY_ADDRESS + 1, - COMPANY_SIC_CODES: defaultIndexes.COMPANY_SIC_CODES + 1, - BROKER_ADDRESS: defaultIndexes.BROKER_ADDRESS + 1, - BUYER_ADDRESS: defaultIndexes.BUYER_ADDRESS + 1, - BUYER_CONTACT_DETAILS: defaultIndexes.BUYER_CONTACT_DETAILS + 1, + BUYER_ADDRESS: 1, + BUYER_CONTACT_DETAILS: 1, TITLES: { ...defaultTitleIndexes, - EXPORTER_BUSINESS: defaultTitleIndexes.EXPORTER_BUSINESS + 1, + POLICY: defaultTitleIndexes.POLICY + 3, BUYER: defaultTitleIndexes.BUYER + 4, DECLARATIONS: defaultTitleIndexes.DECLARATIONS + 4, }, @@ -173,14 +170,10 @@ describe('api/constants/XLSX-CONFIG', () => { const expected = { ...defaultIndexes, - COMPANY_ADDRESS: defaultIndexes.COMPANY_ADDRESS + 1, - COMPANY_SIC_CODES: defaultIndexes.COMPANY_SIC_CODES + 1, - BROKER_ADDRESS: defaultIndexes.BROKER_ADDRESS + 1, - BUYER_ADDRESS: defaultIndexes.BUYER_ADDRESS + 1, - BUYER_CONTACT_DETAILS: defaultIndexes.BUYER_CONTACT_DETAILS + 1, + BUYER_ADDRESS: 1, + BUYER_CONTACT_DETAILS: 1, TITLES: { ...defaultTitleIndexes, - EXPORTER_BUSINESS: defaultTitleIndexes.EXPORTER_BUSINESS + 1, BUYER: defaultTitleIndexes.BUYER + 1, DECLARATIONS: defaultTitleIndexes.DECLARATIONS + 1, }, diff --git a/src/api/constants/XLSX-CONFIG/index.ts b/src/api/constants/XLSX-CONFIG/index.ts index 7211a7d168..39048faf4a 100644 --- a/src/api/constants/XLSX-CONFIG/index.ts +++ b/src/api/constants/XLSX-CONFIG/index.ts @@ -12,30 +12,30 @@ const { * All XLSX title indexes. * @returns {Object} */ -export const TITLE_INDEXES = () => ({ - HEADER: 1, - EXPORTER_CONTACT_DETAILS: 10, - KEY_INFORMATION: 15, - ELIGIBILITY: 21, - POLICY: 31, - EXPORTER_BUSINESS: 40, - BUYER: 58, - DECLARATIONS: 66, -}) as XLSXTitleRowIndexes; +export const TITLE_INDEXES = () => + ({ + HEADER: 1, + EXPORTER_CONTACT_DETAILS: 10, + KEY_INFORMATION: 15, + ELIGIBILITY: 21, + EXPORTER_BUSINESS: 31, + POLICY: 48, + BUYER: 57, + DECLARATIONS: 65, + }) as XLSXTitleRowIndexes; /** * INDEXES * All XLSX indexes. * @returns {Object} */ -export const INDEXES = () => ({ - TITLES: TITLE_INDEXES(), - COMPANY_ADDRESS: 34, - COMPANY_SIC_CODES: 37, - BROKER_ADDRESS: 45, - BUYER_ADDRESS: 50, - BUYER_CONTACT_DETAILS: 53, -}) as XLSXRowIndexes; +export const INDEXES = () => + ({ + TITLES: TITLE_INDEXES(), + COMPANY_ADDRESS: 33, + COMPANY_SIC_CODES: 44, + BUYER_ADDRESS: 64, + }) as XLSXRowIndexes; /** * XLSX_ROW_INDEXES @@ -46,7 +46,14 @@ export const INDEXES = () => ({ * @returns {Object} */ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { - const { policy, broker } = application; + const { + broker, + company: { + hasDifferentTradingName, + differentTradingAddress: { fullAddress: hasDifferentTradingAddress }, + }, + policy, + } = application; const policyType = policy[POLICY_TYPE]; @@ -59,22 +66,47 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { const indexes = INDEXES(); if (isMultiplePolicy) { - indexes.TITLES.EXPORTER_BUSINESS += 1; indexes.TITLES.BUYER += 1; indexes.TITLES.DECLARATIONS += 1; - - indexes.COMPANY_ADDRESS += 1; - indexes.COMPANY_SIC_CODES += 1; - indexes.BROKER_ADDRESS += 1; indexes.BUYER_ADDRESS += 1; indexes.BUYER_CONTACT_DETAILS += 1; } if (broker[USING_BROKER]) { + indexes.BROKER_ADDRESS = 48; + indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; indexes.TITLES.DECLARATIONS += 3; } + if (hasDifferentTradingName) { + indexes.COMPANY_SIC_CODES += 1; + + indexes.BROKER_ADDRESS += 1; + indexes.BUYER_ADDRESS += 1; + + indexes.TITLES.POLICY += 1; + indexes.TITLES.BUYER += 1; + indexes.TITLES.DECLARATIONS += 1; + } + + if (hasDifferentTradingAddress) { + indexes.ALTERNATIVE_TRADING_ADDRESS = 36; + + indexes.COMPANY_SIC_CODES += 1; + + indexes.BROKER_ADDRESS += 1; + indexes.BUYER_ADDRESS += 1; + + indexes.TITLES.POLICY += 1; + indexes.TITLES.BUYER += 1; + indexes.TITLES.DECLARATIONS += 1; + } + + if (hasDifferentTradingName && hasDifferentTradingAddress) { + indexes.ALTERNATIVE_TRADING_ADDRESS = 37; + } + return indexes; }; diff --git a/src/api/constants/field-ids/insurance/business/index.ts b/src/api/constants/field-ids/insurance/business/index.ts index 39c02d89a9..44eb0d29d7 100644 --- a/src/api/constants/field-ids/insurance/business/index.ts +++ b/src/api/constants/field-ids/insurance/business/index.ts @@ -22,10 +22,13 @@ const EXPORTER_BUSINESS = { YOUR_BUSINESS: 'yourBusiness', TRADING_ADDRESS: 'hasDifferentTradingAddress', HAS_DIFFERENT_TRADING_NAME: 'hasDifferentTradingName', + DIFFERENT_TRADING_NAME: 'differentTradingName', WEBSITE: 'companyWebsite', PHONE_NUMBER: 'phoneNumber', }, - ALTERNATIVE_TRADING_ADDRESS: 'alternativeTradingAddress', + ALTERNATIVE_TRADING_ADDRESS: { + FULL_ADDRESS: 'fullAddress', + }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: 'goodsOrServicesSupplied', YEARS_EXPORTING: 'totalYearsExporting', diff --git a/src/api/content-strings/XLSX.ts b/src/api/content-strings/XLSX.ts index 9e1eb0c9b4..17aa725e29 100644 --- a/src/api/content-strings/XLSX.ts +++ b/src/api/content-strings/XLSX.ts @@ -9,10 +9,12 @@ const { ACCOUNT: { FIRST_NAME, LAST_NAME }, ELIGIBILITY: { BUYER_COUNTRY, COMPANIES_HOUSE_NUMBER, COVER_PERIOD, HAS_END_BUYER, HAS_MINIMUM_UK_GOODS_OR_SERVICES }, EXPORTER_BUSINESS: { - COMPANIES_HOUSE: { COMPANY_NAME: EXPORTER_COMPANY_NAME, COMPANY_ADDRESS: EXPORTER_COMPANY_ADDRESS, COMPANY_SIC: EXPORTER_COMPANY_SIC }, - YOUR_COMPANY: { WEBSITE, PHONE_NUMBER }, + COMPANIES_HOUSE: { COMPANY_ADDRESS: EXPORTER_COMPANY_ADDRESS, COMPANY_SIC: EXPORTER_COMPANY_SIC }, + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, DIFFERENT_TRADING_NAME, PHONE_NUMBER, TRADING_ADDRESS, WEBSITE }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, TURNOVER: { ESTIMATED_ANNUAL_TURNOVER }, + ALTERNATIVE_TRADING_ADDRESS, + HAS_CREDIT_CONTROL, }, POLICY: { CONTRACT_POLICY: { @@ -59,13 +61,17 @@ export const XLSX = { [COVER_PERIOD]: 'Length of cover', [HAS_END_BUYER]: 'Is there an end buyer?', [HAS_MINIMUM_UK_GOODS_OR_SERVICES]: 'Is at least 20% of the contract value made up from UK goods or services', + [HAS_CREDIT_CONTROL]: 'Do you have a process for dealing with late payments', [CONTRACT_COMPLETION_DATE]: 'Date expected for contract to complete', - [EXPORTER_COMPANY_NAME]: 'Exporter company name', [EXPORTER_COMPANY_ADDRESS]: 'Exporter registered office address', [EXPORTER_COMPANY_SIC]: 'Exporter standard industry classification (SIC) codes and nature of business', + [HAS_DIFFERENT_TRADING_NAME]: 'Different trading name?', + [DIFFERENT_TRADING_NAME]: 'Alternative trading name', + [TRADING_ADDRESS]: 'Different trading address?', + [ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS]: 'Alternative trading address', [MORE_THAN_250K.VALUE]: `Insured for more than ${formatCurrency(AMOUNT_250K, GBP_CURRENCY_CODE)}`, [WEBSITE]: 'Exporter Company website (optional)', - [PHONE_NUMBER]: 'Exporter telephone number (optional)', + [PHONE_NUMBER]: 'Exporter UK telephone number (optional)', [GOODS_OR_SERVICES]: 'Goods or services the business supplies', [YEARS_EXPORTING]: 'Exporter years exporting', [EMPLOYEES_UK]: 'Exporter UK Employees', diff --git a/src/api/generate-xlsx/map-application-to-XLSX/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/index.test.ts index 94d293252e..577d13ef2a 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/index.test.ts @@ -4,7 +4,7 @@ import mapKeyInformation from './map-introduction'; import mapExporterContactDetails from './map-exporter-contact-details'; import mapSecondaryKeyInformation from './map-key-information'; import mapPolicy from './map-policy'; -import mapExporter from './map-exporter'; +import mapExporterBusiness from './map-exporter-business'; import mapBuyer from './map-buyer'; import mapEligibility from './map-eligibility'; import mapDeclarations from './map-declarations'; @@ -38,11 +38,11 @@ describe('api/generate-xlsx/map-application-to-xlsx/index', () => { ROW_SEPERATOR, - ...mapPolicy(submittedApplication), + ...mapExporterBusiness(submittedApplication), ROW_SEPERATOR, - ...mapExporter(submittedApplication), + ...mapPolicy(submittedApplication), ROW_SEPERATOR, diff --git a/src/api/generate-xlsx/map-application-to-XLSX/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/index.ts index 7be149cefe..0b995c206c 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/index.ts @@ -3,7 +3,7 @@ import mapIntroduction from './map-introduction'; import mapExporterContactDetails from './map-exporter-contact-details'; import mapKeyInformation from './map-key-information'; import mapPolicy from './map-policy'; -import mapExporter from './map-exporter'; +import mapExporterBusiness from './map-exporter-business'; import mapBuyer from './map-buyer'; import mapEligibility from './map-eligibility'; import mapDeclarations from './map-declarations'; @@ -34,11 +34,11 @@ const mapApplicationToXLSX = (application: Application) => { ROW_SEPERATOR, - ...mapPolicy(application), + ...mapExporterBusiness(application), ROW_SEPERATOR, - ...mapExporter(application), + ...mapPolicy(application), ROW_SEPERATOR, diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts similarity index 99% rename from src/api/generate-xlsx/map-application-to-XLSX/map-exporter/index.test.ts rename to src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts index 6f1a31d929..f8f2d32f48 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts @@ -62,7 +62,7 @@ const expectedMapExporterArray = (company, companySicCodes, business, financialY ...mapBroker(mockApplication), ]; -describe('api/generate-xlsx/map-application-to-xlsx/map-exporter', () => { +describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business', () => { describe('mapSicCodes', () => { it('should return a string of SIC codes', () => { const sicCodes = mockApplication.companySicCodes; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts new file mode 100644 index 0000000000..2daffa15b4 --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts @@ -0,0 +1,144 @@ +import INSURANCE_FIELD_IDS from '../../../constants/field-ids/insurance'; +import { XLSX } from '../../../content-strings'; +import { FIELDS as YOUR_BUSINESS_FIELDS } from '../../../content-strings/fields/insurance/your-business'; +import { GBP_CURRENCY_CODE } from '../../../constants'; +import xlsxRow from '../helpers/xlsx-row'; +import mapExporterAddress from './map-address'; +import formatDate from '../../../helpers/format-date'; +import formatCurrency from '../helpers/format-currency'; +import mapYesNoField from '../helpers/map-yes-no-field'; +import NEW_LINE from '../helpers/xlsx-new-line'; +import { Application, ApplicationCompanySicCode } from '../../../types'; + +const { FIELDS, SECTION_TITLES } = XLSX; + +const CONTENT_STRINGS = { + ...YOUR_BUSINESS_FIELDS.COMPANY_DETAILS, + ...YOUR_BUSINESS_FIELDS.NATURE_OF_YOUR_BUSINESS, + ...YOUR_BUSINESS_FIELDS.TURNOVER, + ...YOUR_BUSINESS_FIELDS.BROKER, +}; + +const { + EXPORTER_BUSINESS: { + COMPANIES_HOUSE: { COMPANY_ADDRESS, COMPANY_INCORPORATED, COMPANY_SIC, FINANCIAL_YEAR_END_DATE }, + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, DIFFERENT_TRADING_NAME, PHONE_NUMBER, TRADING_ADDRESS, WEBSITE }, + NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, + TURNOVER: { ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER }, + ALTERNATIVE_TRADING_ADDRESS, + HAS_CREDIT_CONTROL, + }, + POLICY: { + USING_BROKER, + BROKER_DETAILS: { NAME: BROKER_NAME, EMAIL, FULL_ADDRESS }, + }, +} = INSURANCE_FIELD_IDS; + +/** + * mapSicCodes + * Map an application's array of company SIC codes into a single string + * @param {Array} Application company SIC codes + * @returns {String} String of company SIC codes for XLSX generation + */ +export const mapSicCodes = (sicCodes: Array) => { + let mapped = ''; + + sicCodes.forEach((sicCodeObj) => { + const { sicCode, industrySectorName } = sicCodeObj; + + mapped += `${sicCode} - ${industrySectorName}${NEW_LINE}`; + }); + + return mapped; +}; + +/** + * mapBroker + * Map an application's broker fields into an array of objects for XLSX generation + * @param {Application} + * @returns {Array} Array of objects for XLSX generation + */ +export const mapBroker = (application: Application) => { + const { broker } = application; + + let mapped = [xlsxRow(FIELDS[USING_BROKER], mapYesNoField(broker[USING_BROKER]))]; + + if (broker[USING_BROKER]) { + mapped = [ + ...mapped, + xlsxRow(FIELDS[BROKER_NAME], broker[BROKER_NAME]), + xlsxRow(FIELDS[FULL_ADDRESS], broker[FULL_ADDRESS]), + xlsxRow(FIELDS[EMAIL], broker[EMAIL]), + ]; + } + + return mapped; +}; + +/** + * mapExporterBusiness + * Map an application's exporter business fields into an array of objects for XLSX generation + * @param {Application} + * @returns {Array} Array of objects for XLSX generation + */ +const mapExporterBusiness = (application: Application) => { + const { business, company, companySicCodes } = application; + const { differentTradingAddress } = company; + + /** + * financial year end date should only be populated if it exists. + * Otherwise, return default text. + */ + let financialYearEndDate = 'No data from Companies House'; + + if (company[FINANCIAL_YEAR_END_DATE]) { + financialYearEndDate = formatDate(company[FINANCIAL_YEAR_END_DATE], 'd MMMM'); + } + + // TODO: documentation + const hasDifferentTradingName = company[HAS_DIFFERENT_TRADING_NAME]; + + const hasDifferentTradingAddress = differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS]; + + let mapped = [ + xlsxRow(SECTION_TITLES.EXPORTER_BUSINESS, ''), + xlsxRow(CONTENT_STRINGS[COMPANY_INCORPORATED].SUMMARY?.TITLE, formatDate(company[COMPANY_INCORPORATED], 'dd-MMM-yy')), + xlsxRow(FIELDS[COMPANY_ADDRESS], mapExporterAddress(company[COMPANY_ADDRESS])), + xlsxRow(FIELDS[HAS_DIFFERENT_TRADING_NAME], mapYesNoField(company[HAS_DIFFERENT_TRADING_NAME])), + ]; + + if (hasDifferentTradingName) { + mapped.push(xlsxRow(FIELDS[DIFFERENT_TRADING_NAME], company[DIFFERENT_TRADING_NAME])); + } + + mapped.push(xlsxRow(FIELDS[TRADING_ADDRESS], mapYesNoField(company[TRADING_ADDRESS]))); + + if (hasDifferentTradingAddress) { + mapped.push(xlsxRow(FIELDS[ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS], differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS])); + } + + mapped = [ + ...mapped, + + xlsxRow(FIELDS[WEBSITE], company[WEBSITE]), + xlsxRow(FIELDS[PHONE_NUMBER], company[PHONE_NUMBER]), + + xlsxRow(FIELDS[GOODS_OR_SERVICES], business[GOODS_OR_SERVICES]), + xlsxRow(FIELDS[YEARS_EXPORTING], business[YEARS_EXPORTING]), + xlsxRow(FIELDS[EMPLOYEES_UK], business[EMPLOYEES_UK]), + xlsxRow(FIELDS[ESTIMATED_ANNUAL_TURNOVER], formatCurrency(business[ESTIMATED_ANNUAL_TURNOVER], GBP_CURRENCY_CODE)), + xlsxRow(CONTENT_STRINGS[PERCENTAGE_TURNOVER].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER]}%`), + + xlsxRow(FIELDS[HAS_CREDIT_CONTROL], mapYesNoField(business[HAS_CREDIT_CONTROL])), + + xlsxRow(FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), + + xlsxRow(CONTENT_STRINGS[FINANCIAL_YEAR_END_DATE].SUMMARY?.TITLE, financialYearEndDate), + + ...mapBroker(application), + ]; + + return mapped; +}; + +export default mapExporterBusiness; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter/map-address/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-address/index.test.ts similarity index 100% rename from src/api/generate-xlsx/map-application-to-XLSX/map-exporter/map-address/index.test.ts rename to src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-address/index.test.ts diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter/map-address/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-address/index.ts similarity index 100% rename from src/api/generate-xlsx/map-application-to-XLSX/map-exporter/map-address/index.ts rename to src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-address/index.ts diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter/index.ts deleted file mode 100644 index 8bcaa3d6f2..0000000000 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter/index.ts +++ /dev/null @@ -1,122 +0,0 @@ -import INSURANCE_FIELD_IDS from '../../../constants/field-ids/insurance'; -import { XLSX } from '../../../content-strings'; -import { FIELDS } from '../../../content-strings/fields/insurance/your-business'; -import { GBP_CURRENCY_CODE } from '../../../constants'; -import xlsxRow from '../helpers/xlsx-row'; -import mapExporterAddress from './map-address'; -import formatDate from '../../../helpers/format-date'; -import formatCurrency from '../helpers/format-currency'; -import mapYesNoField from '../helpers/map-yes-no-field'; -import NEW_LINE from '../helpers/xlsx-new-line'; -import { Application, ApplicationCompanySicCode } from '../../../types'; - -const CONTENT_STRINGS = { - ...FIELDS.COMPANY_DETAILS, - ...FIELDS.NATURE_OF_YOUR_BUSINESS, - ...FIELDS.TURNOVER, - ...FIELDS.BROKER, -}; - -const { - EXPORTER_BUSINESS: { - COMPANIES_HOUSE: { COMPANY_NUMBER, COMPANY_NAME, COMPANY_ADDRESS, COMPANY_INCORPORATED, COMPANY_SIC, FINANCIAL_YEAR_END_DATE }, - YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, TRADING_ADDRESS, WEBSITE, PHONE_NUMBER }, - NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, - TURNOVER: { ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER }, - }, - POLICY: { - USING_BROKER, - BROKER_DETAILS: { NAME: BROKER_NAME, EMAIL, FULL_ADDRESS }, - }, -} = INSURANCE_FIELD_IDS; - -/** - * mapSicCodes - * Map an application's array of company SIC codes into a single string - * @param {Array} Application company SIC codes - * @returns {String} String of company SIC codes for XLSX generation - */ -export const mapSicCodes = (sicCodes: Array) => { - let mapped = ''; - - sicCodes.forEach((sicCodeObj) => { - const { sicCode, industrySectorName } = sicCodeObj; - - mapped += `${sicCode} - ${industrySectorName}${NEW_LINE}`; - }); - - return mapped; -}; - -/** - * mapBroker - * Map an application's broker fields into an array of objects for XLSX generation - * @param {Application} - * @returns {Array} Array of objects for XLSX generation - */ -export const mapBroker = (application: Application) => { - const { broker } = application; - - let mapped = [xlsxRow(XLSX.FIELDS[USING_BROKER], mapYesNoField(broker[USING_BROKER]))]; - - if (broker[USING_BROKER]) { - mapped = [ - ...mapped, - xlsxRow(XLSX.FIELDS[BROKER_NAME], broker[BROKER_NAME]), - xlsxRow(XLSX.FIELDS[FULL_ADDRESS], broker[FULL_ADDRESS]), - xlsxRow(XLSX.FIELDS[EMAIL], broker[EMAIL]), - ]; - } - - return mapped; -}; - -/** - * mapExporter - * Map an application's exporter fields into an array of objects for XLSX generation - * @param {Application} - * @returns {Array} Array of objects for XLSX generation - */ -const mapExporter = (application: Application) => { - const { company, companySicCodes, business } = application; - let financialYearEndDate = 'No data from Companies House'; - - // financial year end date should only be populated if it exists - if (company[FINANCIAL_YEAR_END_DATE]) { - financialYearEndDate = formatDate(company[FINANCIAL_YEAR_END_DATE], 'd MMMM'); - } - - const mapped = [ - xlsxRow(XLSX.SECTION_TITLES.EXPORTER_BUSINESS, ''), - - // company fields - xlsxRow(CONTENT_STRINGS[COMPANY_NUMBER].SUMMARY?.TITLE, company[COMPANY_NUMBER]), - xlsxRow(XLSX.FIELDS[COMPANY_NAME], company[COMPANY_NAME]), - xlsxRow(CONTENT_STRINGS[COMPANY_INCORPORATED].SUMMARY?.TITLE, formatDate(company[COMPANY_INCORPORATED], 'dd-MMM-yy')), - - xlsxRow(XLSX.FIELDS[COMPANY_ADDRESS], mapExporterAddress(company[COMPANY_ADDRESS])), - - xlsxRow(CONTENT_STRINGS[HAS_DIFFERENT_TRADING_NAME].SUMMARY?.TITLE, mapYesNoField(company[HAS_DIFFERENT_TRADING_NAME])), - xlsxRow(CONTENT_STRINGS[TRADING_ADDRESS].SUMMARY?.TITLE, mapYesNoField(company[TRADING_ADDRESS])), - - xlsxRow(XLSX.FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), - - xlsxRow(CONTENT_STRINGS[FINANCIAL_YEAR_END_DATE].SUMMARY?.TITLE, financialYearEndDate), - xlsxRow(XLSX.FIELDS[WEBSITE], company[WEBSITE]), - xlsxRow(XLSX.FIELDS[PHONE_NUMBER], company[PHONE_NUMBER]), - - // business fields - xlsxRow(XLSX.FIELDS[GOODS_OR_SERVICES], business[GOODS_OR_SERVICES]), - xlsxRow(XLSX.FIELDS[YEARS_EXPORTING], business[YEARS_EXPORTING]), - xlsxRow(XLSX.FIELDS[EMPLOYEES_UK], business[EMPLOYEES_UK]), - xlsxRow(XLSX.FIELDS[ESTIMATED_ANNUAL_TURNOVER], formatCurrency(business[ESTIMATED_ANNUAL_TURNOVER], GBP_CURRENCY_CODE)), - xlsxRow(CONTENT_STRINGS[PERCENTAGE_TURNOVER].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER]}%`), - - // broker fields - ...mapBroker(application), - ]; - - return mapped; -}; - -export default mapExporter; diff --git a/src/api/helpers/get-populated-application/index.api-error.test.ts b/src/api/helpers/get-populated-application/index.api-error.test.ts new file mode 100644 index 0000000000..3eb5e65cdc --- /dev/null +++ b/src/api/helpers/get-populated-application/index.api-error.test.ts @@ -0,0 +1,211 @@ +import { Application as KeystoneApplication } from '.keystone/types'; // eslint-disable-line +import getPopulatedApplication, { generateErrorMessage } from '.'; +import { createFullApplication, getKeystoneContext } from '../../test-helpers'; +import { Application, Context } from '../../types'; + +describe('api/helpers/get-populated-application - error handling', () => { + let context: Context; + let applicationIds: KeystoneApplication; + let application: Application; + + beforeAll(async () => { + context = getKeystoneContext(); + }); + + beforeEach(async () => { + application = await createFullApplication(context); + + applicationIds = { + companyId: application.company.id, + businessId: application.business.id, + brokerId: application.broker.id, + buyerId: application.buyer.id, + declarationId: application.declaration.id, + eligibilityId: application.eligibility.id, + exportContractId: application.exportContract.id, + id: application.id, + ownerId: application.owner.id, + policyId: application.policy.id, + policyContactId: application.policyContact.id, + nominatedLossPayeeId: application.nominatedLossPayee.id, + sectionReviewId: application.sectionReview.id, + }; + }); + + it('should throw an error when eligibility does not exist', async () => { + const invalidId = applicationIds.policyId; + + try { + await getPopulatedApplication(context, { ...applicationIds, eligibilityId: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('eligibility', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when exporter does not exist', async () => { + const invalidId = applicationIds.policyId; + + try { + await getPopulatedApplication(context, { ...applicationIds, accountId: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('exporter', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when buyerCountry does not exist', async () => { + const invalidId = applicationIds.policyId; + + try { + await getPopulatedApplication(context, { ...applicationIds, buyerCountryId: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('buyerCountry', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when nominatedLossPayee does not exist', async () => { + const invalidId = applicationIds.nominatedLossPayeeId; + + try { + await getPopulatedApplication(context, { ...applicationIds, nominatedLossPayeeId: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('nominatedLossPayee', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when policy does not exist', async () => { + const invalidId = applicationIds.id; + + try { + await getPopulatedApplication(context, { ...applicationIds, policyId: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('policy', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when policyContact does not exist', async () => { + const invalidId = applicationIds.id; + + try { + await getPopulatedApplication(context, { ...applicationIds, policyContactId: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('policyContact', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when companyAddress does not exist', async () => { + const invalidId = applicationIds.id; + + try { + await getPopulatedApplication(context, { ...applicationIds, companyAddressId: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('companyAddress', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when differentTradingAddress does not exist', async () => { + const invalidId = applicationIds.id; + + try { + await getPopulatedApplication(context, { + ...applicationIds, + company: { + ...applicationIds.company, + differentTradingAddressId: invalidId, + }, + }); + } catch (err) { + const expected = new Error(generateErrorMessage('differentTradingAddress', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when company does not exist', async () => { + const invalidId = applicationIds.id; + + try { + await getPopulatedApplication(context, { ...applicationIds, companyId: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('company', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when companySicCode does not exist', async () => { + try { + await getPopulatedApplication(context, { ...applicationIds, companyId: application.company.id }); + } catch (err) { + const expected = new Error(generateErrorMessage('companySicCode', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when business does not exist', async () => { + const invalidId = applicationIds.id; + + try { + await getPopulatedApplication(context, { ...applicationIds, businessId: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('business', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when broker does not exist', async () => { + const invalidId = applicationIds.id; + + try { + await getPopulatedApplication(context, { ...applicationIds, brokerId: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('broker', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when buyer does not exist', async () => { + const invalidId = applicationIds.id; + + try { + await getPopulatedApplication(context, { ...applicationIds, buyerId: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('buyer', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when buyer country does not exist', async () => { + const invalidId = applicationIds.id; + + try { + await getPopulatedApplication(context, { ...applicationIds, buyer: { countryId: invalidId } }); + } catch (err) { + const expected = new Error(generateErrorMessage('buyer', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when declaration does not exist', async () => { + const invalidId = applicationIds.id; + + try { + await getPopulatedApplication(context, { ...applicationIds, declarationId: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('declaration', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when sectionReview does not exist', async () => { + const invalidId = applicationIds.id; + + await expect(getPopulatedApplication(context, { ...applicationIds, sectionReviewId: invalidId })).rejects.toThrow( + new Error(generateErrorMessage('sectionReview', applicationIds.id)), + ); + }); +}); diff --git a/src/api/helpers/get-populated-application/index.test.ts b/src/api/helpers/get-populated-application/index.test.ts index b8f3225886..140313b32b 100644 --- a/src/api/helpers/get-populated-application/index.test.ts +++ b/src/api/helpers/get-populated-application/index.test.ts @@ -1,5 +1,5 @@ import { Application as KeystoneApplication } from '.keystone/types'; // eslint-disable-line -import getPopulatedApplication, { generateErrorMessage } from '.'; +import getPopulatedApplication from '.'; import { createFullApplication, getKeystoneContext } from '../../test-helpers'; import getCountryByField from '../get-country-by-field'; import mockCountries from '../../test-mocks/mock-countries'; @@ -44,8 +44,6 @@ describe('api/helpers/get-populated-application', () => { it('should return an application with associated data', async () => { const result = await getPopulatedApplication(context, applicationIds); - expect(result.company.id).toEqual(application.company.id); - expect(result.companySicCodes[0].companyId).toEqual(application.company.id); expect(result.business.id).toEqual(application.business.id); expect(result.broker.id).toEqual(application.broker.id); expect(result.buyer.id).toEqual(application.buyer.id); @@ -70,13 +68,17 @@ describe('api/helpers/get-populated-application', () => { expect(result.buyer.country?.isoCode).toEqual(expectedCountry.isoCode); }); - it('should return an application with populated buyer country', async () => { + it('should return an application with populated company', async () => { const result = await getPopulatedApplication(context, applicationIds); - const [expectedCountry] = mockCountries; + expect(result.company.id).toEqual(application.company.id); + expect(result.companySicCodes[0].companyId).toEqual(application.company.id); - expect(result.buyer.country?.name).toEqual(expectedCountry.name); - expect(result.buyer.country?.isoCode).toEqual(expectedCountry.isoCode); + expect(result.company.id).toEqual(application.company.id); + expect(result.company.registeredOfficeAddress).toEqual(application.company.registeredOfficeAddress); + + expect(result.company.differentTradingAddress.id).toEqual(application.company.differentTradingAddress.id); + expect(result.company.differentTradingAddress.fullAddress).toEqual(''); }); it('should return an application with populated nominatedLossPayee', async () => { @@ -135,153 +137,4 @@ describe('api/helpers/get-populated-application', () => { expect(result.sectionReview.id).toEqual(applicationIds.sectionReviewId); }); - - it('should throw an error when eligibility does not exist', async () => { - const invalidId = applicationIds.policyId; - - try { - await getPopulatedApplication(context, { ...applicationIds, eligibilityId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('eligibility', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when exporter does not exist', async () => { - const invalidId = applicationIds.policyId; - - try { - await getPopulatedApplication(context, { ...applicationIds, accountId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('exporter', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when buyerCountry does not exist', async () => { - const invalidId = applicationIds.policyId; - - try { - await getPopulatedApplication(context, { ...applicationIds, buyerCountryId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('buyerCountry', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when nominatedLossPayee does not exist', async () => { - const invalidId = applicationIds.nominatedLossPayeeId; - - try { - await getPopulatedApplication(context, { ...applicationIds, nominatedLossPayeeId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('nominatedLossPayee', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when policy does not exist', async () => { - const invalidId = applicationIds.id; - - try { - await getPopulatedApplication(context, { ...applicationIds, policyId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('policy', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when policyContact does not exist', async () => { - const invalidId = applicationIds.id; - - try { - await getPopulatedApplication(context, { ...applicationIds, policyContactId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('policyContact', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when company does not exist', async () => { - const invalidId = applicationIds.id; - - try { - await getPopulatedApplication(context, { ...applicationIds, companyId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('company', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when companySicCode does not exist', async () => { - try { - await getPopulatedApplication(context, { ...applicationIds, companyId: application.company.id }); - } catch (err) { - const expected = new Error(generateErrorMessage('companySicCode', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when business does not exist', async () => { - const invalidId = applicationIds.id; - - try { - await getPopulatedApplication(context, { ...applicationIds, businessId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('business', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when broker does not exist', async () => { - const invalidId = applicationIds.id; - - try { - await getPopulatedApplication(context, { ...applicationIds, brokerId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('broker', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when buyer does not exist', async () => { - const invalidId = applicationIds.id; - - try { - await getPopulatedApplication(context, { ...applicationIds, buyerId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('buyer', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when buyer country does not exist', async () => { - const invalidId = applicationIds.id; - - try { - await getPopulatedApplication(context, { ...applicationIds, buyer: { countryId: invalidId } }); - } catch (err) { - const expected = new Error(generateErrorMessage('buyer', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when declaration does not exist', async () => { - const invalidId = applicationIds.id; - - try { - await getPopulatedApplication(context, { ...applicationIds, declarationId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('declaration', applicationIds.id)); - expect(err).toEqual(expected); - } - }); - - it('should throw an error when sectionReview does not exist', async () => { - const invalidId = applicationIds.id; - - await expect(getPopulatedApplication(context, { ...applicationIds, sectionReviewId: invalidId })).rejects.toThrow( - new Error(generateErrorMessage('sectionReview', applicationIds.id)), - ); - }); }); diff --git a/src/api/helpers/get-populated-application/index.ts b/src/api/helpers/get-populated-application/index.ts index 73d1c6d5ec..1c5f47f10a 100644 --- a/src/api/helpers/get-populated-application/index.ts +++ b/src/api/helpers/get-populated-application/index.ts @@ -115,9 +115,22 @@ const getPopulatedApplication = async (context: Context, application: KeystoneAp where: { id: company.registeredOfficeAddressId }, }); + if (!companyAddress) { + throw new Error(generateErrorMessage('companyAddress', application.id)); + } + + const differentTradingAddress = await context.db.CompanyDifferentTradingAddress.findOne({ + where: { id: company.differentTradingAddressId }, + }); + + if (!differentTradingAddress) { + throw new Error(generateErrorMessage('differentTradingAddress', application.id)); + } + const populatedCompany = { ...company, registeredOfficeAddress: companyAddress, + differentTradingAddress, }; const business = await context.db.Business.findOne({ diff --git a/src/api/types/application-types/index.ts b/src/api/types/application-types/index.ts index 8da2eb31ca..a11591cc86 100644 --- a/src/api/types/application-types/index.ts +++ b/src/api/types/application-types/index.ts @@ -45,14 +45,21 @@ export interface ApplicationCompanyAddressCore { premises?: string; } +export interface ApplicationCompanyDifferentTradingAddress extends Relationship { + fullAddress: string; +} + export interface ApplicationCompanyCore { companyName: string; companyNumber: string; dateOfCreation: Date; - sicCodes: Array; + differentTradingAddress: ApplicationCompanyDifferentTradingAddress; industrySectorNames: Array; financialYearEndDate: Date; + hasDifferentTradingName?: boolean; + hasDifferentTradingAddress?: boolean; registeredOfficeAddress: ApplicationCompanyAddressCore; + sicCodes: Array; } export interface ApplicationCompany extends ApplicationCompanyCore { @@ -202,10 +209,6 @@ export interface ApplicationJointlyInsuredParty extends Relationship { country: Country; } -export interface ApplicationCompanyDifferentTradingAddress extends Relationship { - fullAddress: string; -} - export interface Application { id: string; referenceNumber: number; diff --git a/src/api/types/xlsx-types/index.ts b/src/api/types/xlsx-types/index.ts index d50f57854e..4c85b54a65 100644 --- a/src/api/types/xlsx-types/index.ts +++ b/src/api/types/xlsx-types/index.ts @@ -11,6 +11,7 @@ export interface XLSXTitleRowIndexes { export interface XLSXRowIndexes { TITLES: XLSXTitleRowIndexes; + ALTERNATIVE_TRADING_ADDRESS?: number; COMPANY_ADDRESS: number; COMPANY_SIC_CODES: number; BROKER_ADDRESS: number; From 9c303fccc43b543023b1ce30340cb0bbb9447f02 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Fri, 24 May 2024 09:50:36 +0100 Subject: [PATCH 02/29] feat(EMS-3345): fix linting issue --- .../assertions/assert-copy-with-currency-name.js | 7 ++++++- .../fields/insurance/business/index.js | 15 +++++++++++++-- .../your-business/turnover/turnover-page.spec.js | 7 ++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/e2e-tests/commands/shared-commands/assertions/assert-copy-with-currency-name.js b/e2e-tests/commands/shared-commands/assertions/assert-copy-with-currency-name.js index c604b3493c..bca74211f8 100644 --- a/e2e-tests/commands/shared-commands/assertions/assert-copy-with-currency-name.js +++ b/e2e-tests/commands/shared-commands/assertions/assert-copy-with-currency-name.js @@ -7,7 +7,12 @@ * @param {Function} selector: Cypress selector * @param {Boolean} withQuestionMark: Add a question mark to the expected text. */ -const assertCopyWithCurrencyName = ({ pageTitle, currencyName, selector, withQuestionMark = false }) => { +const assertCopyWithCurrencyName = ({ + pageTitle, + currencyName, + selector, + withQuestionMark = false, +}) => { let expected = `${pageTitle} ${currencyName}`; if (withQuestionMark) { diff --git a/e2e-tests/content-strings/fields/insurance/business/index.js b/e2e-tests/content-strings/fields/insurance/business/index.js index 563ff7d2b9..173ccad5d0 100644 --- a/e2e-tests/content-strings/fields/insurance/business/index.js +++ b/e2e-tests/content-strings/fields/insurance/business/index.js @@ -5,7 +5,13 @@ import { FORM_TITLES } from '../../../form-titles'; const { EXPORTER_BUSINESS: { - YOUR_COMPANY: { TRADING_ADDRESS, HAS_DIFFERENT_TRADING_NAME, DIFFERENT_TRADING_NAME, PHONE_NUMBER, WEBSITE }, + YOUR_COMPANY: { + TRADING_ADDRESS, + HAS_DIFFERENT_TRADING_NAME, + DIFFERENT_TRADING_NAME, + PHONE_NUMBER, + WEBSITE, + }, ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, TURNOVER: { FINANCIAL_YEAR_END_DATE, ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER }, @@ -15,7 +21,12 @@ const { } = INSURANCE_FIELD_IDS; const { - YOUR_BUSINESS: { COMPANY_DETAILS, NATURE_OF_BUSINESS, TURNOVER, CREDIT_CONTROL }, + YOUR_BUSINESS: { + COMPANY_DETAILS, + NATURE_OF_BUSINESS, + TURNOVER, + CREDIT_CONTROL, + }, } = FORM_TITLES; export const EXPORTER_BUSINESS_FIELDS = { diff --git a/e2e-tests/insurance/cypress/e2e/journeys/your-business/turnover/turnover-page.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/your-business/turnover/turnover-page.spec.js index ab00f1fe75..279cf19520 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/your-business/turnover/turnover-page.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/your-business/turnover/turnover-page.spec.js @@ -17,7 +17,12 @@ const { const { ROOT, - EXPORTER_BUSINESS: { TURNOVER_ROOT, TURNOVER_ALTERNATIVE_CURRENCY, NATURE_OF_BUSINESS_ROOT, CREDIT_CONTROL }, + EXPORTER_BUSINESS: { + TURNOVER_ROOT, + TURNOVER_ALTERNATIVE_CURRENCY, + NATURE_OF_BUSINESS_ROOT, + CREDIT_CONTROL, + }, } = INSURANCE_ROUTES; const financialYearEnd = { From ada64f02e96ee7f4a66096667e51eca6dd2102c2 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Fri, 24 May 2024 14:57:19 +0100 Subject: [PATCH 03/29] feat(EMS-3345): no pdf - application submission - XLSX - exporter business - code/test improvements --- src/api/.keystone/config.js | 69 +++++---- .../XLSX-CONFIG/INDEXES/index.test.ts | 64 +++++++++ .../constants/XLSX-CONFIG/INDEXES/index.ts | 55 ++++++++ ...roker-or-different-trading-details.test.ts | 43 ++++++ ...ple-contract-policy-using-a-broker.test.ts | 132 ++++++++++++++++++ ...roker-or-different-trading-details.test.ts | 34 +++++ ...gle-contract-policy-using-a-broker.test.ts | 124 ++++++++++++++++ src/api/constants/XLSX-CONFIG/index.test.ts | 100 +------------ src/api/constants/XLSX-CONFIG/index.ts | 69 ++------- .../map-exporter-business/index.test.ts | 51 ++++--- .../map-exporter-business/index.ts | 3 + src/api/package.json | 2 +- src/api/test-mocks/index.ts | 3 +- src/api/test-mocks/mock-application.ts | 11 +- src/api/test-mocks/mock-company.ts | 44 +++++- src/ui/server/test-mocks/mock-application.ts | 10 +- 16 files changed, 585 insertions(+), 229 deletions(-) create mode 100644 src/api/constants/XLSX-CONFIG/INDEXES/index.test.ts create mode 100644 src/api/constants/XLSX-CONFIG/INDEXES/index.ts create mode 100644 src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-or-different-trading-details.test.ts create mode 100644 src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts create mode 100644 src/api/constants/XLSX-CONFIG/index-single-contract-policy-no-broker-or-different-trading-details.test.ts create mode 100644 src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index c892e4709f..f48e0a2ff6 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -782,15 +782,7 @@ var TOTAL_CONTRACT_VALUE = { AMOUNT_250K: 25e4 }; -// helpers/policy-type/index.ts -var isSinglePolicyType = (policyType) => policyType === FIELD_VALUES.POLICY_TYPE.SINGLE; -var isMultiplePolicyType = (policyType) => policyType === FIELD_VALUES.POLICY_TYPE.MULTIPLE; - -// constants/XLSX-CONFIG/index.ts -var { - TYPE_OF_POLICY: { POLICY_TYPE: POLICY_TYPE2 }, - USING_BROKER -} = POLICY; +// constants/XLSX-CONFIG/INDEXES/index.ts var TITLE_INDEXES = () => ({ HEADER: 1, EXPORTER_CONTACT_DETAILS: 10, @@ -807,46 +799,55 @@ var INDEXES = () => ({ COMPANY_SIC_CODES: 44, BUYER_ADDRESS: 64 }); +var incrementIndexes = (indexes) => { + const modified = indexes; + modified.COMPANY_SIC_CODES += 1; + modified.BROKER_ADDRESS += 1; + modified.BUYER_ADDRESS += 1; + modified.TITLES.POLICY += 1; + modified.TITLES.BUYER += 1; + modified.TITLES.DECLARATIONS += 1; + return modified; +}; + +// helpers/policy-type/index.ts +var isSinglePolicyType = (policyType) => policyType === FIELD_VALUES.POLICY_TYPE.SINGLE; +var isMultiplePolicyType = (policyType) => policyType === FIELD_VALUES.POLICY_TYPE.MULTIPLE; + +// constants/XLSX-CONFIG/index.ts +var { + TYPE_OF_POLICY: { POLICY_TYPE: POLICY_TYPE2 }, + USING_BROKER +} = POLICY; var XLSX_ROW_INDEXES = (application2) => { const { broker, - company: { hasDifferentTradingName, differentTradingAddress: { fullAddress: hasDifferentTradingAddress } }, + company: { + differentTradingAddress: { fullAddress: hasDifferentTradingAddress }, + hasDifferentTradingName + }, policy } = application2; const policyType = policy[POLICY_TYPE2]; - let isMultiplePolicy = false; + let indexes = INDEXES(); if (isMultiplePolicyType(policyType)) { - isMultiplePolicy = true; - } - const indexes = INDEXES(); - if (isMultiplePolicy) { indexes.TITLES.BUYER += 1; indexes.TITLES.DECLARATIONS += 1; indexes.BUYER_ADDRESS += 1; indexes.BUYER_CONTACT_DETAILS += 1; } if (broker[USING_BROKER]) { - indexes.BROKER_ADDRESS = 48; indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; indexes.TITLES.DECLARATIONS += 3; + indexes.BROKER_ADDRESS = 48; } if (hasDifferentTradingName) { - indexes.COMPANY_SIC_CODES += 1; - indexes.BROKER_ADDRESS += 1; - indexes.BUYER_ADDRESS += 1; - indexes.TITLES.POLICY += 1; - indexes.TITLES.BUYER += 1; - indexes.TITLES.DECLARATIONS += 1; + indexes = incrementIndexes(indexes); } if (hasDifferentTradingAddress) { indexes.ALTERNATIVE_TRADING_ADDRESS = 36; - indexes.COMPANY_SIC_CODES += 1; - indexes.BROKER_ADDRESS += 1; - indexes.BUYER_ADDRESS += 1; - indexes.TITLES.POLICY += 1; - indexes.TITLES.BUYER += 1; - indexes.TITLES.DECLARATIONS += 1; + indexes = incrementIndexes(indexes); } if (hasDifferentTradingName && hasDifferentTradingAddress) { indexes.ALTERNATIVE_TRADING_ADDRESS = 37; @@ -5810,17 +5811,11 @@ var mapExporterBusiness = (application2) => { xlsx_row_default(FIELDS5[HAS_DIFFERENT_TRADING_NAME3], map_yes_no_field_default(company[HAS_DIFFERENT_TRADING_NAME3])) ]; if (hasDifferentTradingName) { - mapped.push( - xlsx_row_default(FIELDS5[DIFFERENT_TRADING_NAME2], company[DIFFERENT_TRADING_NAME2]) - ); + mapped.push(xlsx_row_default(FIELDS5[DIFFERENT_TRADING_NAME2], company[DIFFERENT_TRADING_NAME2])); } - mapped.push( - xlsx_row_default(FIELDS5[TRADING_ADDRESS3], map_yes_no_field_default(company[TRADING_ADDRESS3])) - ); + mapped.push(xlsx_row_default(FIELDS5[TRADING_ADDRESS3], map_yes_no_field_default(company[TRADING_ADDRESS3]))); if (hasDifferentTradingAddress) { - mapped.push( - xlsx_row_default(FIELDS5[ALTERNATIVE_TRADING_ADDRESS3.FULL_ADDRESS], differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS3.FULL_ADDRESS]) - ); + mapped.push(xlsx_row_default(FIELDS5[ALTERNATIVE_TRADING_ADDRESS3.FULL_ADDRESS], differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS3.FULL_ADDRESS])); } mapped = [ ...mapped, diff --git a/src/api/constants/XLSX-CONFIG/INDEXES/index.test.ts b/src/api/constants/XLSX-CONFIG/INDEXES/index.test.ts new file mode 100644 index 0000000000..f2d8e632f1 --- /dev/null +++ b/src/api/constants/XLSX-CONFIG/INDEXES/index.test.ts @@ -0,0 +1,64 @@ +import { TITLE_INDEXES, INDEXES, incrementIndexes } from '.'; +import { XLSXRowIndexes } from '../../../types'; + +describe('api/constants/XLSX-CONFIG/INDEXES', () => { + describe('TITLE_INDEXES', () => { + it('should return default title indexes', () => { + const expected = { + HEADER: 1, + EXPORTER_CONTACT_DETAILS: 10, + KEY_INFORMATION: 15, + ELIGIBILITY: 21, + EXPORTER_BUSINESS: 31, + POLICY: 48, + BUYER: 57, + DECLARATIONS: 65, + }; + + expect(TITLE_INDEXES()).toEqual(expected); + }); + }); + + describe('INDEXES', () => { + it('should return default indexes', () => { + const expected = { + TITLES: TITLE_INDEXES(), + COMPANY_ADDRESS: 33, + COMPANY_SIC_CODES: 44, + BUYER_ADDRESS: 64, + }; + + expect(INDEXES()).toEqual(expected); + }); + }); + + describe('incrementIndexes', () => { + it('should return incremented indexes', () => { + const mockIndexes = { + COMPANY_SIC_CODES: 1, + BROKER_ADDRESS: 2, + BUYER_ADDRESS: 3, + TITLES: { + POLICY: 4, + BUYER: 5, + DECLARATIONS: 6, + }, + } as XLSXRowIndexes; + + const result = incrementIndexes(mockIndexes); + + const expected = { + COMPANY_SIC_CODES: 2, + BROKER_ADDRESS: 3, + BUYER_ADDRESS: 4, + TITLES: { + POLICY: 5, + BUYER: 6, + DECLARATIONS: 7, + }, + }; + + expect(result).toEqual(expected); + }); + }); +}); diff --git a/src/api/constants/XLSX-CONFIG/INDEXES/index.ts b/src/api/constants/XLSX-CONFIG/INDEXES/index.ts new file mode 100644 index 0000000000..40216f32de --- /dev/null +++ b/src/api/constants/XLSX-CONFIG/INDEXES/index.ts @@ -0,0 +1,55 @@ +import { XLSXTitleRowIndexes, XLSXRowIndexes } from '../../../types'; + +/** + * TITLE_INDEXES + * All XLSX title indexes. + * @returns {Object} + */ +export const TITLE_INDEXES = () => + ({ + HEADER: 1, + EXPORTER_CONTACT_DETAILS: 10, + KEY_INFORMATION: 15, + ELIGIBILITY: 21, + EXPORTER_BUSINESS: 31, + POLICY: 48, + BUYER: 57, + DECLARATIONS: 65, + }) as XLSXTitleRowIndexes; + +/** + * INDEXES + * All XLSX indexes. + * @returns {Object} + */ +export const INDEXES = () => + ({ + TITLES: TITLE_INDEXES(), + COMPANY_ADDRESS: 33, + COMPANY_SIC_CODES: 44, + BUYER_ADDRESS: 64, + }) as XLSXRowIndexes; + +/** + * incrementIndexes + * Increment some specific indexes. + * Depending on the application, some additional fields could be submitted, + * and additional XLSX rows will be rendered. + * Therefore, we need to increment any affected XLSX row indexes. + * @param {XLSXRowIndexes} indexes + * @returns {XLSXRowIndexes} Modified indexes + */ +export const incrementIndexes = (indexes: XLSXRowIndexes) => { + const modified = indexes; + + modified.COMPANY_SIC_CODES += 1; + + modified.BROKER_ADDRESS += 1; + modified.BUYER_ADDRESS += 1; + + modified.TITLES.POLICY += 1; + modified.TITLES.BUYER += 1; + modified.TITLES.DECLARATIONS += 1; + + return modified; +}; diff --git a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-or-different-trading-details.test.ts b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-or-different-trading-details.test.ts new file mode 100644 index 0000000000..4fa3692717 --- /dev/null +++ b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-or-different-trading-details.test.ts @@ -0,0 +1,43 @@ +import { XLSX_ROW_INDEXES } from '.'; +import { INDEXES } from './INDEXES'; +import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; +import { APPLICATION } from '../application'; +import { mockApplication, mockCompanyScenarios } from '../../test-mocks'; + +const { + TYPE_OF_POLICY: { POLICY_TYPE }, +} = POLICY_FIELD_IDS; + +const application = { + ...mockApplication, + policy: { + ...mockApplication.policy, + [POLICY_TYPE]: APPLICATION.POLICY_TYPE.MULTIPLE, + }, + broker: { + ...mockApplication.broker, + isUsingBroker: false, + }, + company: mockCompanyScenarios.noDifferentTradingNameOrAddress, +}; + +describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.MULTIPLE} - not using a broker, no different trading details`, () => { + it('should return default multiple contract policy row indexes', () => { + const result = XLSX_ROW_INDEXES(application); + + const indexes = INDEXES(); + + const expected = { + ...indexes, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1, + BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, + TITLES: { + ...indexes.TITLES, + BUYER: indexes.TITLES.BUYER + 1, + DECLARATIONS: indexes.TITLES.DECLARATIONS + 1, + }, + }; + + expect(result).toEqual(expected); + }); +}); diff --git a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts new file mode 100644 index 0000000000..1b7c49cd8f --- /dev/null +++ b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts @@ -0,0 +1,132 @@ +import { XLSX_ROW_INDEXES } from '.'; +import { incrementIndexes, INDEXES } from './INDEXES'; +import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; +import { APPLICATION } from '../application'; +import { mockApplication, mockCompanyScenarios } from '../../test-mocks'; + +const { + TYPE_OF_POLICY: { POLICY_TYPE }, + USING_BROKER, +} = POLICY_FIELD_IDS; + +const application = { + ...mockApplication, + policy: { + ...mockApplication.policy, + [POLICY_TYPE]: APPLICATION.POLICY_TYPE.MULTIPLE, + }, + broker: { + ...mockApplication.broker, + isUsingBroker: true, + }, +}; + +describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.MULTIPLE} - using a broker`, () => { + describe('with no different trading name, no different trading adddress', () => { + it('should return the correct row indexes', () => { + const result = XLSX_ROW_INDEXES(application); + + const indexes = INDEXES(); + + const expected = { + ...indexes, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1, + BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, + BROKER_ADDRESS: 48, + TITLES: { + ...indexes.TITLES, + POLICY: indexes.TITLES.POLICY + 3, + BUYER: indexes.TITLES.BUYER + 4, + DECLARATIONS: indexes.TITLES.DECLARATIONS + 4, + }, + }; + + expect(result).toEqual(expected); + }); + }); + + describe('with different trading name, no different trading adddress', () => { + it('should return the correct row indexes', () => { + application.company = mockCompanyScenarios.differentTradingNameNoAddress; + + const result = XLSX_ROW_INDEXES(application); + + const indexes = INDEXES(); + const incremented = incrementIndexes(indexes); + + const expected = { + ...incremented, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1, + BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, + BROKER_ADDRESS: 49, + TITLES: { + ...incremented.TITLES, + POLICY: incremented.TITLES.POLICY + 3, + BUYER: incremented.TITLES.BUYER + 4, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 4, + }, + }; + + expect(result).toEqual(expected); + }); + }); + + describe('with different trading adddress, no different trading name', () => { + it('should return the correct row indexes', () => { + application.broker = { + ...application.broker, + [USING_BROKER]: true, + }; + application.company = mockCompanyScenarios.differentTradingAddressNoName; + + const result = XLSX_ROW_INDEXES(application); + + const indexes = INDEXES(); + const incremented = incrementIndexes(indexes); + + const expected = { + ...incremented, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1, + BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, + BROKER_ADDRESS: 49, + ALTERNATIVE_TRADING_ADDRESS: 36, + TITLES: { + ...incremented.TITLES, + POLICY: incremented.TITLES.POLICY + 3, + BUYER: incremented.TITLES.BUYER + 4, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 4, + }, + }; + + expect(result).toEqual(expected); + }); + }); + + describe('with different trading adddress and different trading name', () => { + it('should return the correct row indexes', () => { + application.company = mockCompanyScenarios.differentTradingAddressAndName; + + const result = XLSX_ROW_INDEXES(application); + + const indexes = INDEXES(); + const incremented = incrementIndexes(indexes); + const secondIncrement = incrementIndexes(incremented); + + const expected = { + ...secondIncrement, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1, + BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, + BROKER_ADDRESS: 50, + ALTERNATIVE_TRADING_ADDRESS: 37, + TITLES: { + ...secondIncrement.TITLES, + POLICY: incremented.TITLES.POLICY + 3, + BUYER: incremented.TITLES.BUYER + 4, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 4, + }, + }; + + expect(result).toEqual(expected); + }); + }); +}); diff --git a/src/api/constants/XLSX-CONFIG/index-single-contract-policy-no-broker-or-different-trading-details.test.ts b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-no-broker-or-different-trading-details.test.ts new file mode 100644 index 0000000000..d3bb4a2049 --- /dev/null +++ b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-no-broker-or-different-trading-details.test.ts @@ -0,0 +1,34 @@ +import { XLSX_ROW_INDEXES } from '.'; +import { INDEXES } from './INDEXES'; +import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; +import { APPLICATION } from '../application'; +import { mockApplication, mockCompanyScenarios } from '../../test-mocks'; + +const { + TYPE_OF_POLICY: { POLICY_TYPE }, +} = POLICY_FIELD_IDS; + +const application = { + ...mockApplication, + policy: { + ...mockApplication.policy, + [POLICY_TYPE]: APPLICATION.POLICY_TYPE.SINGLE, + }, + broker: { + ...mockApplication.broker, + isUsingBroker: false, + }, + company: mockCompanyScenarios.noDifferentTradingNameOrAddress, +}; + +describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.SINGLE} - not using a broker, no different trading details`, () => { + it('should return default row indexes', () => { + const result = XLSX_ROW_INDEXES(application); + + const indexes = INDEXES(); + + const expected = indexes; + + expect(result).toEqual(expected); + }); +}); diff --git a/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts new file mode 100644 index 0000000000..3717214cc0 --- /dev/null +++ b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts @@ -0,0 +1,124 @@ +import { XLSX_ROW_INDEXES } from '.'; +import { incrementIndexes, INDEXES } from './INDEXES'; +import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; +import { APPLICATION } from '../application'; +import { mockApplication, mockCompanyScenarios } from '../../test-mocks'; + +const { + TYPE_OF_POLICY: { POLICY_TYPE }, + USING_BROKER, +} = POLICY_FIELD_IDS; + +const application = { + ...mockApplication, + policy: { + ...mockApplication.policy, + [POLICY_TYPE]: APPLICATION.POLICY_TYPE.SINGLE, + }, + broker: { + ...mockApplication.broker, + isUsingBroker: true, + }, +}; + +describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.SINGLE} - using a broker`, () => { + describe('with no different trading name, no different trading adddress', () => { + it('should return the correct row indexes', () => { + const result = XLSX_ROW_INDEXES(application); + + const indexes = INDEXES(); + + const expected = { + ...indexes, + BROKER_ADDRESS: 48, + TITLES: { + ...indexes.TITLES, + POLICY: indexes.TITLES.POLICY + 3, + BUYER: indexes.TITLES.BUYER + 3, + DECLARATIONS: indexes.TITLES.DECLARATIONS + 3, + }, + }; + + expect(result).toEqual(expected); + }); + }); + + describe('with different trading name, no different trading adddress', () => { + it('should return the correct row indexes', () => { + application.company = mockCompanyScenarios.differentTradingNameNoAddress; + + const result = XLSX_ROW_INDEXES(application); + + const indexes = INDEXES(); + const incremented = incrementIndexes(indexes); + + const expected = { + ...incremented, + BROKER_ADDRESS: 49, + TITLES: { + ...incremented.TITLES, + POLICY: incremented.TITLES.POLICY + 3, + BUYER: incremented.TITLES.BUYER + 3, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 3, + }, + }; + + expect(result).toEqual(expected); + }); + }); + + describe('with different trading adddress, no different trading name', () => { + it('should return the correct row indexes', () => { + application.broker = { + ...application.broker, + [USING_BROKER]: true, + }; + application.company = mockCompanyScenarios.differentTradingAddressNoName; + + const result = XLSX_ROW_INDEXES(application); + + const indexes = INDEXES(); + const incremented = incrementIndexes(indexes); + + const expected = { + ...incremented, + BROKER_ADDRESS: 49, + ALTERNATIVE_TRADING_ADDRESS: 36, + TITLES: { + ...incremented.TITLES, + POLICY: incremented.TITLES.POLICY + 3, + BUYER: incremented.TITLES.BUYER + 3, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 3, + }, + }; + + expect(result).toEqual(expected); + }); + }); + + describe('with different trading adddress and different trading name', () => { + it('should return the correct row indexes', () => { + application.company = mockCompanyScenarios.differentTradingAddressAndName; + + const result = XLSX_ROW_INDEXES(application); + + const indexes = INDEXES(); + const incremented = incrementIndexes(indexes); + const secondIncrement = incrementIndexes(incremented); + + const expected = { + ...secondIncrement, + BROKER_ADDRESS: 50, + ALTERNATIVE_TRADING_ADDRESS: 37, + TITLES: { + ...secondIncrement.TITLES, + POLICY: incremented.TITLES.POLICY + 3, + BUYER: incremented.TITLES.BUYER + 3, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 3, + }, + }; + + expect(result).toEqual(expected); + }); + }); +}); diff --git a/src/api/constants/XLSX-CONFIG/index.test.ts b/src/api/constants/XLSX-CONFIG/index.test.ts index b22847fc68..8f5e49b9cf 100644 --- a/src/api/constants/XLSX-CONFIG/index.test.ts +++ b/src/api/constants/XLSX-CONFIG/index.test.ts @@ -1,4 +1,5 @@ -import { TITLE_INDEXES, INDEXES, XLSX_CONFIG, XLSX_ROW_INDEXES } from '.'; +import { XLSX_CONFIG, XLSX_ROW_INDEXES } from '.'; +import { INDEXES, TITLE_INDEXES } from './INDEXES'; import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; import { APPLICATION } from '../application'; import { mockApplication } from '../../test-mocks'; @@ -9,36 +10,6 @@ const { } = POLICY_FIELD_IDS; describe('api/constants/XLSX-CONFIG', () => { - describe('TITLE_INDEXES', () => { - it('should return default title indexes', () => { - const expected = { - HEADER: 1, - EXPORTER_CONTACT_DETAILS: 10, - KEY_INFORMATION: 15, - ELIGIBILITY: 21, - EXPORTER_BUSINESS: 31, - POLICY: 49, - BUYER: 58, - DECLARATIONS: 66, - }; - - expect(TITLE_INDEXES()).toEqual(expected); - }); - }); - - describe('INDEXES', () => { - it('should return default indexes', () => { - const expected = { - TITLES: TITLE_INDEXES(), - COMPANY_ADDRESS: 35, - COMPANY_SIC_CODES: 38, - BUYER_ADDRESS: 60, - }; - - expect(INDEXES()).toEqual(expected); - }); - }); - describe('XLSX_CONFIG', () => { it('should return a config for XLSX', () => { const result = XLSX_CONFIG; @@ -90,7 +61,7 @@ describe('api/constants/XLSX-CONFIG', () => { const expected = { ...defaultIndexes, - BROKER_ADDRESS: 49, + BROKER_ADDRESS: 48, TITLES: { ...defaultTitleIndexes, POLICY: defaultTitleIndexes.POLICY + 3, @@ -118,70 +89,5 @@ describe('api/constants/XLSX-CONFIG', () => { }); }); }); - - describe(APPLICATION.POLICY_TYPE.MULTIPLE, () => { - const application = { - ...mockApplication, - policy: { - ...mockApplication.policy, - [POLICY_TYPE]: APPLICATION.POLICY_TYPE.MULTIPLE, - }, - }; - - describe('when using a broker', () => { - it('should return correct row indexes', () => { - application.broker = { - ...mockApplication.buyer, - [USING_BROKER]: true, - }; - - const result = XLSX_ROW_INDEXES(application); - - const defaultIndexes = INDEXES(); - const defaultTitleIndexes = TITLE_INDEXES(); - - const expected = { - ...defaultIndexes, - BUYER_ADDRESS: 1, - BUYER_CONTACT_DETAILS: 1, - TITLES: { - ...defaultTitleIndexes, - POLICY: defaultTitleIndexes.POLICY + 3, - BUYER: defaultTitleIndexes.BUYER + 4, - DECLARATIONS: defaultTitleIndexes.DECLARATIONS + 4, - }, - }; - - expect(result).toEqual(expected); - }); - }); - - describe('when NOT using a broker', () => { - it('should return correct row indexes', () => { - application.broker = { - ...mockApplication.buyer, - [USING_BROKER]: false, - }; - - const result = XLSX_ROW_INDEXES(application); - - const defaultIndexes = INDEXES(); - const defaultTitleIndexes = TITLE_INDEXES(); - - const expected = { - ...defaultIndexes, - BUYER_ADDRESS: 1, - BUYER_CONTACT_DETAILS: 1, - TITLES: { - ...defaultTitleIndexes, - BUYER: defaultTitleIndexes.BUYER + 1, - DECLARATIONS: defaultTitleIndexes.DECLARATIONS + 1, - }, - }; - - expect(result).toEqual(expected); - }); - }); - }); }); }); diff --git a/src/api/constants/XLSX-CONFIG/index.ts b/src/api/constants/XLSX-CONFIG/index.ts index 39048faf4a..de93c5e300 100644 --- a/src/api/constants/XLSX-CONFIG/index.ts +++ b/src/api/constants/XLSX-CONFIG/index.ts @@ -1,42 +1,13 @@ +import { INDEXES, incrementIndexes } from './INDEXES'; import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; import { isMultiplePolicyType } from '../../helpers/policy-type'; -import { Application, XLSXTitleRowIndexes, XLSXRowIndexes } from '../../types'; +import { Application, XLSXRowIndexes } from '../../types'; const { TYPE_OF_POLICY: { POLICY_TYPE }, USING_BROKER, } = POLICY_FIELD_IDS; -/** - * TITLE_INDEXES - * All XLSX title indexes. - * @returns {Object} - */ -export const TITLE_INDEXES = () => - ({ - HEADER: 1, - EXPORTER_CONTACT_DETAILS: 10, - KEY_INFORMATION: 15, - ELIGIBILITY: 21, - EXPORTER_BUSINESS: 31, - POLICY: 48, - BUYER: 57, - DECLARATIONS: 65, - }) as XLSXTitleRowIndexes; - -/** - * INDEXES - * All XLSX indexes. - * @returns {Object} - */ -export const INDEXES = () => - ({ - TITLES: TITLE_INDEXES(), - COMPANY_ADDRESS: 33, - COMPANY_SIC_CODES: 44, - BUYER_ADDRESS: 64, - }) as XLSXRowIndexes; - /** * XLSX_ROW_INDEXES * Generate row indexes for XLSX. @@ -45,62 +16,48 @@ export const INDEXES = () => * - If "using a broker" is true - the XLSX's “About your business“ section has 3 additional rows. * @returns {Object} */ + +// TODO +// TODO +// TODO: update documentation export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { const { broker, company: { - hasDifferentTradingName, differentTradingAddress: { fullAddress: hasDifferentTradingAddress }, + hasDifferentTradingName, }, policy, } = application; const policyType = policy[POLICY_TYPE]; - let isMultiplePolicy = false; + let indexes = INDEXES(); if (isMultiplePolicyType(policyType)) { - isMultiplePolicy = true; - } - - const indexes = INDEXES(); - - if (isMultiplePolicy) { indexes.TITLES.BUYER += 1; indexes.TITLES.DECLARATIONS += 1; + indexes.BUYER_ADDRESS += 1; indexes.BUYER_CONTACT_DETAILS += 1; } if (broker[USING_BROKER]) { - indexes.BROKER_ADDRESS = 48; indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; indexes.TITLES.DECLARATIONS += 3; + + indexes.BROKER_ADDRESS = 48; } if (hasDifferentTradingName) { - indexes.COMPANY_SIC_CODES += 1; - - indexes.BROKER_ADDRESS += 1; - indexes.BUYER_ADDRESS += 1; - - indexes.TITLES.POLICY += 1; - indexes.TITLES.BUYER += 1; - indexes.TITLES.DECLARATIONS += 1; + indexes = incrementIndexes(indexes); } if (hasDifferentTradingAddress) { indexes.ALTERNATIVE_TRADING_ADDRESS = 36; - indexes.COMPANY_SIC_CODES += 1; - - indexes.BROKER_ADDRESS += 1; - indexes.BUYER_ADDRESS += 1; - - indexes.TITLES.POLICY += 1; - indexes.TITLES.BUYER += 1; - indexes.TITLES.DECLARATIONS += 1; + indexes = incrementIndexes(indexes); } if (hasDifferentTradingName && hasDifferentTradingAddress) { diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts index f8f2d32f48..308181fd15 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts @@ -1,7 +1,7 @@ import mapExporter, { mapSicCodes, mapBroker } from '.'; import INSURANCE_FIELD_IDS from '../../../constants/field-ids/insurance'; import { XLSX } from '../../../content-strings'; -import { FIELDS } from '../../../content-strings/fields/insurance/your-business'; +import { FIELDS as YOUR_BUSINESS_FIELDS } from '../../../content-strings/fields/insurance/your-business'; import { GBP_CURRENCY_CODE } from '../../../constants'; import xlsxRow from '../helpers/xlsx-row'; import mapExporterAddress from './map-address'; @@ -11,20 +11,23 @@ import NEW_LINE from '../helpers/xlsx-new-line'; import { mockApplication } from '../../../test-mocks'; import mapYesNoField from '../helpers/map-yes-no-field'; +const { FIELDS, SECTION_TITLES } = XLSX; + const CONTENT_STRINGS = { - ...FIELDS.COMPANY_DETAILS, - ...FIELDS.NATURE_OF_YOUR_BUSINESS, - ...FIELDS.TURNOVER, - ...FIELDS.BROKER, - ...FIELDS.BROKER_DETAILS, + ...YOUR_BUSINESS_FIELDS.COMPANY_DETAILS, + ...YOUR_BUSINESS_FIELDS.NATURE_OF_YOUR_BUSINESS, + ...YOUR_BUSINESS_FIELDS.TURNOVER, + ...YOUR_BUSINESS_FIELDS.BROKER, + ...YOUR_BUSINESS_FIELDS.BROKER_DETAILS, }; const { EXPORTER_BUSINESS: { - COMPANIES_HOUSE: { COMPANY_NUMBER, COMPANY_NAME, COMPANY_ADDRESS, COMPANY_INCORPORATED, COMPANY_SIC, FINANCIAL_YEAR_END_DATE }, - YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, TRADING_ADDRESS, WEBSITE, PHONE_NUMBER }, + COMPANIES_HOUSE: { COMPANY_ADDRESS, COMPANY_INCORPORATED, COMPANY_SIC, FINANCIAL_YEAR_END_DATE }, + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, PHONE_NUMBER, TRADING_ADDRESS, WEBSITE }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, TURNOVER: { ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER }, + HAS_CREDIT_CONTROL, }, POLICY: { USING_BROKER, @@ -33,32 +36,28 @@ const { } = INSURANCE_FIELD_IDS; const expectedMapExporterArray = (company, companySicCodes, business, financialYearEndDateValue) => [ - xlsxRow(XLSX.SECTION_TITLES.EXPORTER_BUSINESS, ''), + xlsxRow(SECTION_TITLES.EXPORTER_BUSINESS, ''), - // company fields - xlsxRow(CONTENT_STRINGS[COMPANY_NUMBER].SUMMARY?.TITLE, company[COMPANY_NUMBER]), - xlsxRow(XLSX.FIELDS[COMPANY_NAME], company[COMPANY_NAME]), xlsxRow(CONTENT_STRINGS[COMPANY_INCORPORATED].SUMMARY?.TITLE, formatDate(company[COMPANY_INCORPORATED], 'dd-MMM-yy')), + xlsxRow(FIELDS[COMPANY_ADDRESS], mapExporterAddress(company[COMPANY_ADDRESS])), + xlsxRow(FIELDS[HAS_DIFFERENT_TRADING_NAME], mapYesNoField(company[HAS_DIFFERENT_TRADING_NAME])), + xlsxRow(FIELDS[TRADING_ADDRESS], mapYesNoField(company[TRADING_ADDRESS])), + + xlsxRow(FIELDS[WEBSITE], company[WEBSITE]), + xlsxRow(FIELDS[PHONE_NUMBER], company[PHONE_NUMBER]), - xlsxRow(XLSX.FIELDS[COMPANY_ADDRESS], mapExporterAddress(company[COMPANY_ADDRESS])), + xlsxRow(FIELDS[GOODS_OR_SERVICES], business[GOODS_OR_SERVICES]), + xlsxRow(FIELDS[YEARS_EXPORTING], business[YEARS_EXPORTING]), + xlsxRow(FIELDS[EMPLOYEES_UK], business[EMPLOYEES_UK]), + xlsxRow(FIELDS[ESTIMATED_ANNUAL_TURNOVER], formatCurrency(business[ESTIMATED_ANNUAL_TURNOVER], GBP_CURRENCY_CODE)), + xlsxRow(CONTENT_STRINGS[PERCENTAGE_TURNOVER].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER]}%`), - xlsxRow(CONTENT_STRINGS[HAS_DIFFERENT_TRADING_NAME].SUMMARY?.TITLE, mapYesNoField(company[HAS_DIFFERENT_TRADING_NAME])), - xlsxRow(CONTENT_STRINGS[TRADING_ADDRESS].SUMMARY?.TITLE, mapYesNoField(company[TRADING_ADDRESS])), + xlsxRow(FIELDS[HAS_CREDIT_CONTROL], mapYesNoField(business[HAS_CREDIT_CONTROL])), - xlsxRow(XLSX.FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), + xlsxRow(FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), xlsxRow(CONTENT_STRINGS[FINANCIAL_YEAR_END_DATE].SUMMARY?.TITLE, financialYearEndDateValue), - xlsxRow(XLSX.FIELDS[WEBSITE], company[WEBSITE]), - xlsxRow(XLSX.FIELDS[PHONE_NUMBER], company[PHONE_NUMBER]), - - // business fields - xlsxRow(XLSX.FIELDS[GOODS_OR_SERVICES], business[GOODS_OR_SERVICES]), - xlsxRow(XLSX.FIELDS[YEARS_EXPORTING], business[YEARS_EXPORTING]), - xlsxRow(XLSX.FIELDS[EMPLOYEES_UK], business[EMPLOYEES_UK]), - xlsxRow(XLSX.FIELDS[ESTIMATED_ANNUAL_TURNOVER], formatCurrency(business[ESTIMATED_ANNUAL_TURNOVER], GBP_CURRENCY_CODE)), - xlsxRow(CONTENT_STRINGS[PERCENTAGE_TURNOVER].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER]}%`), - // broker fields ...mapBroker(mockApplication), ]; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts index 2daffa15b4..82e0ac9f6a 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts @@ -89,6 +89,8 @@ const mapExporterBusiness = (application: Application) => { * financial year end date should only be populated if it exists. * Otherwise, return default text. */ + + // TODO: constant let financialYearEndDate = 'No data from Companies House'; if (company[FINANCIAL_YEAR_END_DATE]) { @@ -96,6 +98,7 @@ const mapExporterBusiness = (application: Application) => { } // TODO: documentation + // TODO: unit tests const hasDifferentTradingName = company[HAS_DIFFERENT_TRADING_NAME]; const hasDifferentTradingAddress = differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS]; diff --git a/src/api/package.json b/src/api/package.json index 110aa7b79f..3a8c14cd2c 100644 --- a/src/api/package.json +++ b/src/api/package.json @@ -19,7 +19,7 @@ "lint": "eslint ./", "lint:fix": "eslint ./ --fix", "start": "keystone start --no-ui", - "test": "jest --runInBand --verbose --silent --coverage --config=jest.config.js" + "test": "jest --runInBand --verbose --coverage --config=jest.config.js" }, "dependencies": { "@babel/core": "^7.24.5", diff --git a/src/api/test-mocks/index.ts b/src/api/test-mocks/index.ts index b1eb6b0bb7..c04efa433b 100644 --- a/src/api/test-mocks/index.ts +++ b/src/api/test-mocks/index.ts @@ -4,7 +4,7 @@ import encryptPassword from '../helpers/encrypt-password'; import application from './mock-application'; import cisCountries from './mock-CIS-countries'; import currencies from './mock-currencies'; -import company from './mock-company'; +import company, { companyScenarios } from './mock-company'; import companySicCode from './mock-company-sic-code'; import nominatedLossPayee from './mock-nominated-loss-payee'; import { Account } from '../types'; @@ -48,6 +48,7 @@ export const mockCisCountries = cisCountries; export const mockCompany = company; export const mockCompanySicCode = companySicCode; +export const mockCompanyScenarios = companyScenarios; export const mockNominatedLossPayee = nominatedLossPayee; diff --git a/src/api/test-mocks/mock-application.ts b/src/api/test-mocks/mock-application.ts index 8a645b0b74..3cd950c691 100644 --- a/src/api/test-mocks/mock-application.ts +++ b/src/api/test-mocks/mock-application.ts @@ -59,10 +59,11 @@ export const mockAccount = { }; export const mockCompany = { - id: 'clcyyopn40148m8noyar9wxrn', + id: 'claydon40148m8boyar9waen', companyName: 'Test Name', companyNumber: '0123456', companyWebsite: '', + differentTradingAddress: {}, hasDifferentTradingName: false, hasDifferentTradingAddress: false, dateOfCreation: '2014-04-10T00:00:00.000Z', @@ -73,7 +74,7 @@ export const mockCompany = { }, ], registeredOfficeAddress: { - id: 'clcyyopna0158m8noaglyy94t', + id: 'claydona0158m8noaglyy94t', addressLine1: 'Line 1', addressLine2: 'Line 2', careOf: '', @@ -107,12 +108,12 @@ export const mockBusiness = { }; export const mockBroker = { - id: 'clcyyopna0158m8noaglyy9gg', + id: 'claydona0158m8noaglyy9gg', ...broker, }; export const mockApplicationBuyer = { - id: 'clcyyopna0158m8noaglyy9aa', + id: 'claydona0158m8noaglyy9aa', ...buyer, }; @@ -195,7 +196,7 @@ const mockApplication = { companySicCodes: [mockCompanySicCode, mockCompanySicCode], companyAddress: mockCompany.registeredOfficeAddress, business: { - id: 'clcyyopna0158m8noaglyy9gg', + id: 'claydona0158m8noaglyy9gg', ...mockBusiness, }, broker: mockBroker, diff --git a/src/api/test-mocks/mock-company.ts b/src/api/test-mocks/mock-company.ts index bda5efe89f..1ad7e38457 100644 --- a/src/api/test-mocks/mock-company.ts +++ b/src/api/test-mocks/mock-company.ts @@ -1,4 +1,6 @@ -import { ApplicationCompanyCore } from '../types'; +import { ApplicationCompany, ApplicationCompanyCore } from '../types'; + +const mockId = 'claydon40148m8boyar9waen'; const mockCompany = { companyName: 'Mock company', @@ -17,6 +19,46 @@ const mockCompany = { financialYearEndDate: new Date(), sicCodes: ['68201'], industrySectorNames: [], + differentTradingAddress: {}, } as ApplicationCompanyCore; +const mockCompanyDifferentTradingAddress = { + ...mockCompany, + differentTradingAddress: { + id: mockId, + fullAddress: 'Mock address', + }, +}; + +const mockCompanyNoDifferentTradingAddress = { + ...mockCompany, + differentTradingAddress: { + id: mockId, + fullAddress: '', + }, +}; + +export const companyScenarios = { + differentTradingAddressAndName: { + ...mockCompany, + ...mockCompanyDifferentTradingAddress, + hasDifferentTradingName: true, + } as ApplicationCompany, + differentTradingAddressNoName: { + ...mockCompany, + ...mockCompanyDifferentTradingAddress, + hasDifferentTradingName: false, + } as ApplicationCompany, + differentTradingNameNoAddress: { + ...mockCompany, + hasDifferentTradingName: true, + ...mockCompanyNoDifferentTradingAddress, + } as ApplicationCompany, + noDifferentTradingNameOrAddress: { + ...mockCompany, + hasDifferentTradingName: false, + ...mockCompanyNoDifferentTradingAddress, + } as ApplicationCompany, +}; + export default mockCompany; diff --git a/src/ui/server/test-mocks/mock-application.ts b/src/ui/server/test-mocks/mock-application.ts index ee1e0b1db0..aa1303ae81 100644 --- a/src/ui/server/test-mocks/mock-application.ts +++ b/src/ui/server/test-mocks/mock-application.ts @@ -108,7 +108,7 @@ export const mockCompanyDifferentTradingAddress = { }; export const mockCompany = { - id: 'clcyyopn40148m8noyar9wxrn', + id: 'claydon40148m8boyar9waen', ...companyMock, hasDifferentTradingName: false, hasDifferentTradingAddress: false, @@ -122,7 +122,7 @@ export const mockCompany = { ], differentTradingAddress: mockCompanyDifferentTradingAddress, registeredOfficeAddress: { - id: 'clcyyopna0158m8noaglyy94t', + id: 'claydona0158m8noaglyy94t', addressLine1: 'Line 1', addressLine2: 'Line 2', careOf: '', @@ -137,7 +137,7 @@ export const mockCompany = { }; export const mockBusiness = { - id: 'clcyyopna0158m8noaglyy9gg', + id: 'claydona0158m8noaglyy9gg', goodsOrServicesSupplied: 'ABC', totalYearsExporting: '20', totalEmployeesUK: '400', @@ -148,7 +148,7 @@ export const mockBusiness = { }; export const mockBroker = { - id: 'clcyyopna0158m8noaglyy9gg', + id: 'claydona0158m8noaglyy9gg', ...broker, }; @@ -157,7 +157,7 @@ export const mockApplicationBuyer = { }; export const mockNominatedLossPayee = { - id: 'clcyyopna0158m8noaglyy9gh', + id: 'claydona0158m8noaglyy9gh', ...nominatedLossPayee, }; From dd1ad5d31dee2b7d6a45be6fe211c89331b8e71b Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Fri, 24 May 2024 16:01:37 +0100 Subject: [PATCH 04/29] feat(EMS-3345): fix linting issues --- .../assertions/assert-copy-with-currency-name.js | 7 ++++++- .../journeys/your-business/turnover/turnover-page.spec.js | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/e2e-tests/commands/shared-commands/assertions/assert-copy-with-currency-name.js b/e2e-tests/commands/shared-commands/assertions/assert-copy-with-currency-name.js index 8f0e7d961c..302b038654 100644 --- a/e2e-tests/commands/shared-commands/assertions/assert-copy-with-currency-name.js +++ b/e2e-tests/commands/shared-commands/assertions/assert-copy-with-currency-name.js @@ -7,7 +7,12 @@ * @param {Function} selector: Cypress selector * @param {Boolean} withQuestionMark: Add a question mark to the expected text. */ -const assertCopyWithCurrencyName = ({ expectedCopy, currencyName, selector, withQuestionMark = false }) => { +const assertCopyWithCurrencyName = ({ + expectedCopy, + currencyName, + selector, + withQuestionMark = false, +}) => { let expected = `${expectedCopy} ${currencyName}`; if (withQuestionMark) { diff --git a/e2e-tests/insurance/cypress/e2e/journeys/your-business/turnover/turnover-page.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/your-business/turnover/turnover-page.spec.js index 45cf701cc2..dbb4e9addc 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/your-business/turnover/turnover-page.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/your-business/turnover/turnover-page.spec.js @@ -17,7 +17,12 @@ const { const { ROOT, - EXPORTER_BUSINESS: { TURNOVER_ROOT, TURNOVER_ALTERNATIVE_CURRENCY, NATURE_OF_BUSINESS_ROOT, CREDIT_CONTROL }, + EXPORTER_BUSINESS: { + TURNOVER_ROOT, + TURNOVER_ALTERNATIVE_CURRENCY, + NATURE_OF_BUSINESS_ROOT, + CREDIT_CONTROL, + }, } = INSURANCE_ROUTES; const financialYearEnd = { From 505e6d87e0b88f5e126222470a8b2aa5572f0648 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Fri, 24 May 2024 16:02:27 +0100 Subject: [PATCH 05/29] feat(EMS-3345): revert package.json change --- src/api/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/package.json b/src/api/package.json index 3a8c14cd2c..110aa7b79f 100644 --- a/src/api/package.json +++ b/src/api/package.json @@ -19,7 +19,7 @@ "lint": "eslint ./", "lint:fix": "eslint ./ --fix", "start": "keystone start --no-ui", - "test": "jest --runInBand --verbose --coverage --config=jest.config.js" + "test": "jest --runInBand --verbose --silent --coverage --config=jest.config.js" }, "dependencies": { "@babel/core": "^7.24.5", From ca152f21995f8e45d6769d126a8be49dabe79308 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Fri, 24 May 2024 16:08:19 +0100 Subject: [PATCH 06/29] feat(EMS-3345): fix/update unit tests --- src/api/test-mocks/mock-company.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api/test-mocks/mock-company.ts b/src/api/test-mocks/mock-company.ts index 1ad7e38457..a81c6e1b5a 100644 --- a/src/api/test-mocks/mock-company.ts +++ b/src/api/test-mocks/mock-company.ts @@ -19,7 +19,6 @@ const mockCompany = { financialYearEndDate: new Date(), sicCodes: ['68201'], industrySectorNames: [], - differentTradingAddress: {}, } as ApplicationCompanyCore; const mockCompanyDifferentTradingAddress = { From da41e7412a5bb7f2fe3978911b185e6d76fac00a Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Fri, 24 May 2024 16:18:44 +0100 Subject: [PATCH 07/29] feat(EMS-3345): address todo comment --- src/api/.keystone/config.js | 6 +++--- src/api/constants/XLSX-CONFIG/index.ts | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index f48e0a2ff6..cc2da8afbe 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -842,13 +842,13 @@ var XLSX_ROW_INDEXES = (application2) => { indexes.TITLES.DECLARATIONS += 3; indexes.BROKER_ADDRESS = 48; } - if (hasDifferentTradingName) { - indexes = incrementIndexes(indexes); - } if (hasDifferentTradingAddress) { indexes.ALTERNATIVE_TRADING_ADDRESS = 36; indexes = incrementIndexes(indexes); } + if (hasDifferentTradingName) { + indexes = incrementIndexes(indexes); + } if (hasDifferentTradingName && hasDifferentTradingAddress) { indexes.ALTERNATIVE_TRADING_ADDRESS = 37; } diff --git a/src/api/constants/XLSX-CONFIG/index.ts b/src/api/constants/XLSX-CONFIG/index.ts index de93c5e300..3c0d503f60 100644 --- a/src/api/constants/XLSX-CONFIG/index.ts +++ b/src/api/constants/XLSX-CONFIG/index.ts @@ -11,15 +11,15 @@ const { /** * XLSX_ROW_INDEXES * Generate row indexes for XLSX. - * Depending on the submitted application data, the rows can be different: - * - If the policy type is multiple - the XLSX's "Policy” section has 1 additional row. - * - If "using a broker" is true - the XLSX's “About your business“ section has 3 additional rows. - * @returns {Object} + * Depending on the submitted application data, the rows can be different. + * - If the policy type is multiple, the XLSX has 1 additional row. + * - If "using a broker" is true, the XLSX has 3 additional rows. + * - If "has different trading address" is true, the XLSX has 1 additional row. + * - If "has different trading name" is true, the XLSX has 1 additional row. + * - If "has different trading name/address" the ALTERNATIVE_TRADING_ADDRESS row needs to change. + * @returns {XLSXRowIndexes} */ -// TODO -// TODO -// TODO: update documentation export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { const { broker, @@ -50,16 +50,16 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { indexes.BROKER_ADDRESS = 48; } - if (hasDifferentTradingName) { - indexes = incrementIndexes(indexes); - } - if (hasDifferentTradingAddress) { indexes.ALTERNATIVE_TRADING_ADDRESS = 36; indexes = incrementIndexes(indexes); } + if (hasDifferentTradingName) { + indexes = incrementIndexes(indexes); + } + if (hasDifferentTradingName && hasDifferentTradingAddress) { indexes.ALTERNATIVE_TRADING_ADDRESS = 37; } From 3061cdfd221cc7fbc58592e7d3132c4784f42483 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Fri, 24 May 2024 17:19:49 +0100 Subject: [PATCH 08/29] feat(EMS-3345): no pdf - application submission - XLSX - exporter company sic/date ordering --- .../field-ids/insurance/business/index.js | 1 + src/api/.keystone/config.js | 28 +++++++++---------- .../XLSX-CONFIG/INDEXES/index.test.ts | 26 ++++++++--------- .../constants/XLSX-CONFIG/INDEXES/index.ts | 6 ++-- ...roker-or-different-trading-details.test.ts | 1 - ...ple-contract-policy-using-a-broker.test.ts | 12 ++++---- ...gle-contract-policy-using-a-broker.test.ts | 8 ++++-- src/api/constants/XLSX-CONFIG/index.test.ts | 1 + src/api/constants/XLSX-CONFIG/index.ts | 6 ++-- .../field-ids/insurance/business/index.ts | 1 + src/api/content-strings/XLSX.ts | 4 +-- .../map-exporter-business/index.test.ts | 8 +++--- .../map-exporter-business/index.ts | 8 ++---- .../field-ids/insurance/business/index.ts | 1 + 14 files changed, 56 insertions(+), 55 deletions(-) diff --git a/e2e-tests/constants/field-ids/insurance/business/index.js b/e2e-tests/constants/field-ids/insurance/business/index.js index 821ff06cc7..8ed302c02a 100644 --- a/e2e-tests/constants/field-ids/insurance/business/index.js +++ b/e2e-tests/constants/field-ids/insurance/business/index.js @@ -10,6 +10,7 @@ export const EXPORTER_BUSINESS = { }, ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS: 'fullAddress', + FULL_ADDRESS_DOT_NOTATION: 'alternativeTrading.fullAddress', }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: 'goodsOrServicesSupplied', diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 05110d647e..39af7d4a8f 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -394,7 +394,8 @@ var EXPORTER_BUSINESS = { PHONE_NUMBER: "phoneNumber" }, ALTERNATIVE_TRADING_ADDRESS: { - FULL_ADDRESS: "fullAddress" + FULL_ADDRESS: "fullAddress", + FULL_ADDRESS_DOT_NOTATION: "alternativeTrading.fullAddress" }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: "goodsOrServicesSupplied", @@ -797,12 +798,11 @@ var TITLE_INDEXES = () => ({ var INDEXES = () => ({ TITLES: TITLE_INDEXES(), COMPANY_ADDRESS: 33, - COMPANY_SIC_CODES: 44, - BUYER_ADDRESS: 64 + COMPANY_SIC_CODES: 34, + BUYER_ADDRESS: 59 }); var incrementIndexes = (indexes) => { const modified = indexes; - modified.COMPANY_SIC_CODES += 1; modified.BROKER_ADDRESS += 1; modified.BUYER_ADDRESS += 1; modified.TITLES.POLICY += 1; @@ -834,24 +834,24 @@ var XLSX_ROW_INDEXES = (application2) => { if (isMultiplePolicyType(policyType)) { indexes.TITLES.BUYER += 1; indexes.TITLES.DECLARATIONS += 1; - indexes.BUYER_ADDRESS += 1; indexes.BUYER_CONTACT_DETAILS += 1; } if (broker[USING_BROKER]) { indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; indexes.TITLES.DECLARATIONS += 3; + indexes.BUYER_ADDRESS += 3; indexes.BROKER_ADDRESS = 48; } if (hasDifferentTradingAddress) { - indexes.ALTERNATIVE_TRADING_ADDRESS = 36; + indexes.ALTERNATIVE_TRADING_ADDRESS = 37; indexes = incrementIndexes(indexes); } if (hasDifferentTradingName) { indexes = incrementIndexes(indexes); } if (hasDifferentTradingName && hasDifferentTradingAddress) { - indexes.ALTERNATIVE_TRADING_ADDRESS = 37; + indexes.ALTERNATIVE_TRADING_ADDRESS = 38; } return indexes; }; @@ -5559,7 +5559,7 @@ var { YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME: HAS_DIFFERENT_TRADING_NAME2, DIFFERENT_TRADING_NAME, PHONE_NUMBER: PHONE_NUMBER2, TRADING_ADDRESS: TRADING_ADDRESS2, WEBSITE: WEBSITE2 }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: GOODS_OR_SERVICES2, YEARS_EXPORTING: YEARS_EXPORTING2, EMPLOYEES_UK: EMPLOYEES_UK2 }, TURNOVER: { ESTIMATED_ANNUAL_TURNOVER: ESTIMATED_ANNUAL_TURNOVER2 }, - ALTERNATIVE_TRADING_ADDRESS: ALTERNATIVE_TRADING_ADDRESS2, + ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS_DOT_NOTATION }, HAS_CREDIT_CONTROL: HAS_CREDIT_CONTROL2 }, POLICY: { @@ -5606,7 +5606,7 @@ var XLSX = { [HAS_DIFFERENT_TRADING_NAME2]: "Different trading name?", [DIFFERENT_TRADING_NAME]: "Alternative trading name", [TRADING_ADDRESS2]: "Different trading address?", - [ALTERNATIVE_TRADING_ADDRESS2.FULL_ADDRESS]: "Alternative trading address", + [FULL_ADDRESS_DOT_NOTATION]: "Alternative trading address", [MORE_THAN_250K.VALUE]: `Insured for more than ${format_currency_default(AMOUNT_250K, GBP_CURRENCY_CODE)}`, [WEBSITE2]: "Exporter Company website (optional)", [PHONE_NUMBER2]: "Exporter UK telephone number (optional)", @@ -5836,7 +5836,7 @@ var { YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME: HAS_DIFFERENT_TRADING_NAME3, DIFFERENT_TRADING_NAME: DIFFERENT_TRADING_NAME2, PHONE_NUMBER: PHONE_NUMBER3, TRADING_ADDRESS: TRADING_ADDRESS3, WEBSITE: WEBSITE3 }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: GOODS_OR_SERVICES3, YEARS_EXPORTING: YEARS_EXPORTING3, EMPLOYEES_UK: EMPLOYEES_UK3 }, TURNOVER: { ESTIMATED_ANNUAL_TURNOVER: ESTIMATED_ANNUAL_TURNOVER3, PERCENTAGE_TURNOVER: PERCENTAGE_TURNOVER2 }, - ALTERNATIVE_TRADING_ADDRESS: ALTERNATIVE_TRADING_ADDRESS3, + ALTERNATIVE_TRADING_ADDRESS: ALTERNATIVE_TRADING_ADDRESS2, HAS_CREDIT_CONTROL: HAS_CREDIT_CONTROL3 }, POLICY: { @@ -5873,11 +5873,12 @@ var mapExporterBusiness = (application2) => { financialYearEndDate = format_date_default(company[FINANCIAL_YEAR_END_DATE2], "d MMMM"); } const hasDifferentTradingName = company[HAS_DIFFERENT_TRADING_NAME3]; - const hasDifferentTradingAddress = differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS3.FULL_ADDRESS]; + const hasDifferentTradingAddress = differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS2.FULL_ADDRESS]; let mapped = [ xlsx_row_default(SECTION_TITLES.EXPORTER_BUSINESS, ""), xlsx_row_default(CONTENT_STRINGS3[COMPANY_INCORPORATED2].SUMMARY?.TITLE, format_date_default(company[COMPANY_INCORPORATED2], "dd-MMM-yy")), xlsx_row_default(FIELDS5[COMPANY_ADDRESS2], map_address_default(company[COMPANY_ADDRESS2])), + xlsx_row_default(FIELDS5[COMPANY_SIC2], mapSicCodes2(companySicCodes)), xlsx_row_default(FIELDS5[HAS_DIFFERENT_TRADING_NAME3], map_yes_no_field_default(company[HAS_DIFFERENT_TRADING_NAME3])) ]; if (hasDifferentTradingName) { @@ -5885,7 +5886,7 @@ var mapExporterBusiness = (application2) => { } mapped.push(xlsx_row_default(FIELDS5[TRADING_ADDRESS3], map_yes_no_field_default(company[TRADING_ADDRESS3]))); if (hasDifferentTradingAddress) { - mapped.push(xlsx_row_default(FIELDS5[ALTERNATIVE_TRADING_ADDRESS3.FULL_ADDRESS], differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS3.FULL_ADDRESS])); + mapped.push(xlsx_row_default(FIELDS5[ALTERNATIVE_TRADING_ADDRESS2.FULL_ADDRESS_DOT_NOTATION], differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS2.FULL_ADDRESS])); } mapped = [ ...mapped, @@ -5894,11 +5895,10 @@ var mapExporterBusiness = (application2) => { xlsx_row_default(FIELDS5[GOODS_OR_SERVICES3], business[GOODS_OR_SERVICES3]), xlsx_row_default(FIELDS5[YEARS_EXPORTING3], business[YEARS_EXPORTING3]), xlsx_row_default(FIELDS5[EMPLOYEES_UK3], business[EMPLOYEES_UK3]), + xlsx_row_default(CONTENT_STRINGS3[FINANCIAL_YEAR_END_DATE2].SUMMARY?.TITLE, financialYearEndDate), xlsx_row_default(FIELDS5[ESTIMATED_ANNUAL_TURNOVER3], format_currency_default2(business[ESTIMATED_ANNUAL_TURNOVER3], GBP_CURRENCY_CODE)), xlsx_row_default(CONTENT_STRINGS3[PERCENTAGE_TURNOVER2].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER2]}%`), xlsx_row_default(FIELDS5[HAS_CREDIT_CONTROL3], map_yes_no_field_default(business[HAS_CREDIT_CONTROL3])), - xlsx_row_default(FIELDS5[COMPANY_SIC2], mapSicCodes2(companySicCodes)), - xlsx_row_default(CONTENT_STRINGS3[FINANCIAL_YEAR_END_DATE2].SUMMARY?.TITLE, financialYearEndDate), ...mapBroker(application2) ]; return mapped; diff --git a/src/api/constants/XLSX-CONFIG/INDEXES/index.test.ts b/src/api/constants/XLSX-CONFIG/INDEXES/index.test.ts index f2d8e632f1..155fc07c2b 100644 --- a/src/api/constants/XLSX-CONFIG/INDEXES/index.test.ts +++ b/src/api/constants/XLSX-CONFIG/INDEXES/index.test.ts @@ -24,8 +24,8 @@ describe('api/constants/XLSX-CONFIG/INDEXES', () => { const expected = { TITLES: TITLE_INDEXES(), COMPANY_ADDRESS: 33, - COMPANY_SIC_CODES: 44, - BUYER_ADDRESS: 64, + COMPANY_SIC_CODES: 34, + BUYER_ADDRESS: 59, }; expect(INDEXES()).toEqual(expected); @@ -35,26 +35,24 @@ describe('api/constants/XLSX-CONFIG/INDEXES', () => { describe('incrementIndexes', () => { it('should return incremented indexes', () => { const mockIndexes = { - COMPANY_SIC_CODES: 1, - BROKER_ADDRESS: 2, - BUYER_ADDRESS: 3, + BROKER_ADDRESS: 1, + BUYER_ADDRESS: 2, TITLES: { - POLICY: 4, - BUYER: 5, - DECLARATIONS: 6, + POLICY: 3, + BUYER: 4, + DECLARATIONS: 5, }, } as XLSXRowIndexes; const result = incrementIndexes(mockIndexes); const expected = { - COMPANY_SIC_CODES: 2, - BROKER_ADDRESS: 3, - BUYER_ADDRESS: 4, + BROKER_ADDRESS: 2, + BUYER_ADDRESS: 3, TITLES: { - POLICY: 5, - BUYER: 6, - DECLARATIONS: 7, + POLICY: 4, + BUYER: 5, + DECLARATIONS: 6, }, }; diff --git a/src/api/constants/XLSX-CONFIG/INDEXES/index.ts b/src/api/constants/XLSX-CONFIG/INDEXES/index.ts index 40216f32de..479e4b3355 100644 --- a/src/api/constants/XLSX-CONFIG/INDEXES/index.ts +++ b/src/api/constants/XLSX-CONFIG/INDEXES/index.ts @@ -26,8 +26,8 @@ export const INDEXES = () => ({ TITLES: TITLE_INDEXES(), COMPANY_ADDRESS: 33, - COMPANY_SIC_CODES: 44, - BUYER_ADDRESS: 64, + COMPANY_SIC_CODES: 34, + BUYER_ADDRESS: 59, }) as XLSXRowIndexes; /** @@ -42,8 +42,6 @@ export const INDEXES = () => export const incrementIndexes = (indexes: XLSXRowIndexes) => { const modified = indexes; - modified.COMPANY_SIC_CODES += 1; - modified.BROKER_ADDRESS += 1; modified.BUYER_ADDRESS += 1; diff --git a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-or-different-trading-details.test.ts b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-or-different-trading-details.test.ts index 4fa3692717..46d203a298 100644 --- a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-or-different-trading-details.test.ts +++ b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-or-different-trading-details.test.ts @@ -29,7 +29,6 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...indexes, - BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1, BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, TITLES: { ...indexes.TITLES, diff --git a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts index 1b7c49cd8f..3b091c3399 100644 --- a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts +++ b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts @@ -30,7 +30,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...indexes, - BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 3, BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, BROKER_ADDRESS: 48, TITLES: { @@ -56,7 +56,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...incremented, - BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 3, BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, BROKER_ADDRESS: 49, TITLES: { @@ -86,10 +86,10 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...incremented, - BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 3, BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, BROKER_ADDRESS: 49, - ALTERNATIVE_TRADING_ADDRESS: 36, + ALTERNATIVE_TRADING_ADDRESS: 37, TITLES: { ...incremented.TITLES, POLICY: incremented.TITLES.POLICY + 3, @@ -114,10 +114,10 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...secondIncrement, - BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 3, BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, BROKER_ADDRESS: 50, - ALTERNATIVE_TRADING_ADDRESS: 37, + ALTERNATIVE_TRADING_ADDRESS: 38, TITLES: { ...secondIncrement.TITLES, POLICY: incremented.TITLES.POLICY + 3, diff --git a/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts index 3717214cc0..4474b80e16 100644 --- a/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts +++ b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts @@ -31,6 +31,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...indexes, BROKER_ADDRESS: 48, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 3, TITLES: { ...indexes.TITLES, POLICY: indexes.TITLES.POLICY + 3, @@ -55,6 +56,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...incremented, BROKER_ADDRESS: 49, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 3, TITLES: { ...incremented.TITLES, POLICY: incremented.TITLES.POLICY + 3, @@ -83,7 +85,8 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...incremented, BROKER_ADDRESS: 49, - ALTERNATIVE_TRADING_ADDRESS: 36, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 3, + ALTERNATIVE_TRADING_ADDRESS: 37, TITLES: { ...incremented.TITLES, POLICY: incremented.TITLES.POLICY + 3, @@ -109,7 +112,8 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...secondIncrement, BROKER_ADDRESS: 50, - ALTERNATIVE_TRADING_ADDRESS: 37, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 3, + ALTERNATIVE_TRADING_ADDRESS: 38, TITLES: { ...secondIncrement.TITLES, POLICY: incremented.TITLES.POLICY + 3, diff --git a/src/api/constants/XLSX-CONFIG/index.test.ts b/src/api/constants/XLSX-CONFIG/index.test.ts index 8f5e49b9cf..908f3b7deb 100644 --- a/src/api/constants/XLSX-CONFIG/index.test.ts +++ b/src/api/constants/XLSX-CONFIG/index.test.ts @@ -62,6 +62,7 @@ describe('api/constants/XLSX-CONFIG', () => { const expected = { ...defaultIndexes, BROKER_ADDRESS: 48, + BUYER_ADDRESS: defaultIndexes.BUYER_ADDRESS + 3, TITLES: { ...defaultTitleIndexes, POLICY: defaultTitleIndexes.POLICY + 3, diff --git a/src/api/constants/XLSX-CONFIG/index.ts b/src/api/constants/XLSX-CONFIG/index.ts index 3c0d503f60..62539edfde 100644 --- a/src/api/constants/XLSX-CONFIG/index.ts +++ b/src/api/constants/XLSX-CONFIG/index.ts @@ -38,7 +38,6 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { indexes.TITLES.BUYER += 1; indexes.TITLES.DECLARATIONS += 1; - indexes.BUYER_ADDRESS += 1; indexes.BUYER_CONTACT_DETAILS += 1; } @@ -46,12 +45,13 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; indexes.TITLES.DECLARATIONS += 3; + indexes.BUYER_ADDRESS += 3; indexes.BROKER_ADDRESS = 48; } if (hasDifferentTradingAddress) { - indexes.ALTERNATIVE_TRADING_ADDRESS = 36; + indexes.ALTERNATIVE_TRADING_ADDRESS = 37; indexes = incrementIndexes(indexes); } @@ -61,7 +61,7 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { } if (hasDifferentTradingName && hasDifferentTradingAddress) { - indexes.ALTERNATIVE_TRADING_ADDRESS = 37; + indexes.ALTERNATIVE_TRADING_ADDRESS = 38; } return indexes; diff --git a/src/api/constants/field-ids/insurance/business/index.ts b/src/api/constants/field-ids/insurance/business/index.ts index 44eb0d29d7..4a2c5ff74e 100644 --- a/src/api/constants/field-ids/insurance/business/index.ts +++ b/src/api/constants/field-ids/insurance/business/index.ts @@ -28,6 +28,7 @@ const EXPORTER_BUSINESS = { }, ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS: 'fullAddress', + FULL_ADDRESS_DOT_NOTATION: 'alternativeTrading.fullAddress', }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: 'goodsOrServicesSupplied', diff --git a/src/api/content-strings/XLSX.ts b/src/api/content-strings/XLSX.ts index 17aa725e29..13dfae07bd 100644 --- a/src/api/content-strings/XLSX.ts +++ b/src/api/content-strings/XLSX.ts @@ -13,7 +13,7 @@ const { YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, DIFFERENT_TRADING_NAME, PHONE_NUMBER, TRADING_ADDRESS, WEBSITE }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, TURNOVER: { ESTIMATED_ANNUAL_TURNOVER }, - ALTERNATIVE_TRADING_ADDRESS, + ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS_DOT_NOTATION }, HAS_CREDIT_CONTROL, }, POLICY: { @@ -68,7 +68,7 @@ export const XLSX = { [HAS_DIFFERENT_TRADING_NAME]: 'Different trading name?', [DIFFERENT_TRADING_NAME]: 'Alternative trading name', [TRADING_ADDRESS]: 'Different trading address?', - [ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS]: 'Alternative trading address', + [FULL_ADDRESS_DOT_NOTATION]: 'Alternative trading address', [MORE_THAN_250K.VALUE]: `Insured for more than ${formatCurrency(AMOUNT_250K, GBP_CURRENCY_CODE)}`, [WEBSITE]: 'Exporter Company website (optional)', [PHONE_NUMBER]: 'Exporter UK telephone number (optional)', diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts index 308181fd15..b3142a67ed 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts @@ -27,6 +27,7 @@ const { YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, PHONE_NUMBER, TRADING_ADDRESS, WEBSITE }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, TURNOVER: { ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER }, + // ALTERNATIVE_TRADING_ADDRESS: { ALTERNATIVE_TRADING_FULL_ADDRESS }, HAS_CREDIT_CONTROL, }, POLICY: { @@ -40,6 +41,8 @@ const expectedMapExporterArray = (company, companySicCodes, business, financialY xlsxRow(CONTENT_STRINGS[COMPANY_INCORPORATED].SUMMARY?.TITLE, formatDate(company[COMPANY_INCORPORATED], 'dd-MMM-yy')), xlsxRow(FIELDS[COMPANY_ADDRESS], mapExporterAddress(company[COMPANY_ADDRESS])), + xlsxRow(FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), + xlsxRow(FIELDS[HAS_DIFFERENT_TRADING_NAME], mapYesNoField(company[HAS_DIFFERENT_TRADING_NAME])), xlsxRow(FIELDS[TRADING_ADDRESS], mapYesNoField(company[TRADING_ADDRESS])), @@ -49,15 +52,12 @@ const expectedMapExporterArray = (company, companySicCodes, business, financialY xlsxRow(FIELDS[GOODS_OR_SERVICES], business[GOODS_OR_SERVICES]), xlsxRow(FIELDS[YEARS_EXPORTING], business[YEARS_EXPORTING]), xlsxRow(FIELDS[EMPLOYEES_UK], business[EMPLOYEES_UK]), + xlsxRow(CONTENT_STRINGS[FINANCIAL_YEAR_END_DATE].SUMMARY?.TITLE, financialYearEndDateValue), xlsxRow(FIELDS[ESTIMATED_ANNUAL_TURNOVER], formatCurrency(business[ESTIMATED_ANNUAL_TURNOVER], GBP_CURRENCY_CODE)), xlsxRow(CONTENT_STRINGS[PERCENTAGE_TURNOVER].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER]}%`), xlsxRow(FIELDS[HAS_CREDIT_CONTROL], mapYesNoField(business[HAS_CREDIT_CONTROL])), - xlsxRow(FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), - - xlsxRow(CONTENT_STRINGS[FINANCIAL_YEAR_END_DATE].SUMMARY?.TITLE, financialYearEndDateValue), - ...mapBroker(mockApplication), ]; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts index 82e0ac9f6a..1d35d96d80 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts @@ -107,6 +107,7 @@ const mapExporterBusiness = (application: Application) => { xlsxRow(SECTION_TITLES.EXPORTER_BUSINESS, ''), xlsxRow(CONTENT_STRINGS[COMPANY_INCORPORATED].SUMMARY?.TITLE, formatDate(company[COMPANY_INCORPORATED], 'dd-MMM-yy')), xlsxRow(FIELDS[COMPANY_ADDRESS], mapExporterAddress(company[COMPANY_ADDRESS])), + xlsxRow(FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), xlsxRow(FIELDS[HAS_DIFFERENT_TRADING_NAME], mapYesNoField(company[HAS_DIFFERENT_TRADING_NAME])), ]; @@ -117,7 +118,7 @@ const mapExporterBusiness = (application: Application) => { mapped.push(xlsxRow(FIELDS[TRADING_ADDRESS], mapYesNoField(company[TRADING_ADDRESS]))); if (hasDifferentTradingAddress) { - mapped.push(xlsxRow(FIELDS[ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS], differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS])); + mapped.push(xlsxRow(FIELDS[ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS_DOT_NOTATION], differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS])); } mapped = [ @@ -129,15 +130,12 @@ const mapExporterBusiness = (application: Application) => { xlsxRow(FIELDS[GOODS_OR_SERVICES], business[GOODS_OR_SERVICES]), xlsxRow(FIELDS[YEARS_EXPORTING], business[YEARS_EXPORTING]), xlsxRow(FIELDS[EMPLOYEES_UK], business[EMPLOYEES_UK]), + xlsxRow(CONTENT_STRINGS[FINANCIAL_YEAR_END_DATE].SUMMARY?.TITLE, financialYearEndDate), xlsxRow(FIELDS[ESTIMATED_ANNUAL_TURNOVER], formatCurrency(business[ESTIMATED_ANNUAL_TURNOVER], GBP_CURRENCY_CODE)), xlsxRow(CONTENT_STRINGS[PERCENTAGE_TURNOVER].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER]}%`), xlsxRow(FIELDS[HAS_CREDIT_CONTROL], mapYesNoField(business[HAS_CREDIT_CONTROL])), - xlsxRow(FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), - - xlsxRow(CONTENT_STRINGS[FINANCIAL_YEAR_END_DATE].SUMMARY?.TITLE, financialYearEndDate), - ...mapBroker(application), ]; diff --git a/src/ui/server/constants/field-ids/insurance/business/index.ts b/src/ui/server/constants/field-ids/insurance/business/index.ts index 63c94996fe..774cfdd3e9 100644 --- a/src/ui/server/constants/field-ids/insurance/business/index.ts +++ b/src/ui/server/constants/field-ids/insurance/business/index.ts @@ -12,6 +12,7 @@ const EXPORTER_BUSINESS = { }, ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS: 'fullAddress', + FULL_ADDRESS_DOT_NOTATION: 'alternativeTrading.fullAddress', }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: 'goodsOrServicesSupplied', From 8871b843e06a99d22cfdcdc345b5819583892b56 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Tue, 28 May 2024 10:30:27 +0100 Subject: [PATCH 09/29] feat(EMS-3345): no pdf - application submission - XLSX - code/test improvements --- src/api/.keystone/config.js | 149 +++++++++--------- src/api/content-strings/XLSX.ts | 1 + src/api/content-strings/default.ts | 1 + .../map-exporter-business/index.test.ts | 113 +++---------- .../map-exporter-business/index.ts | 72 ++------- .../map-broker/index.test.ts | 52 ++++++ .../map-exporter-business/map-broker/index.ts | 37 +++++ .../index.test.ts | 2 +- .../index.ts | 0 .../map-sic-codes/index.test.ts | 21 +++ .../map-sic-codes/index.ts | 22 +++ 11 files changed, 250 insertions(+), 220 deletions(-) create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.test.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts rename src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/{map-address => map-exporter-address}/index.test.ts (97%) rename src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/{map-address => map-exporter-address}/index.ts (100%) create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.test.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.ts diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 39af7d4a8f..0401e8cbd2 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -5546,7 +5546,8 @@ var TIME_SUBMITTED = { // content-strings/default.ts var DEFAULT = { - EMPTY: "-" + EMPTY: "-", + NO_FINANCIAL_YEAR_END_DATE: "No data from Companies House" }; // content-strings/XLSX.ts @@ -5621,7 +5622,8 @@ var XLSX = { [COUNTRY]: "Buyer location", [BUYER_COMPANY_NAME]: "Buyer company name", [BUYER_REGISTRATION_NUMBER]: "Buyer registration number (optional)", - [BUYER_CONTACT_DETAILS]: "Buyer contact details" + [BUYER_CONTACT_DETAILS]: "Buyer contact details", + NO_FINANCIAL_YEAR_END_DATE: "No data from Companies House" } }; @@ -5794,22 +5796,6 @@ var mapPolicy = (application2) => { }; var map_policy_default = mapPolicy; -// generate-xlsx/map-application-to-XLSX/helpers/xlsx-new-line/index.ts -var NEW_LINE = "\r\n"; -var xlsx_new_line_default = NEW_LINE; - -// generate-xlsx/map-application-to-XLSX/map-exporter-business/map-address/index.ts -var mapExporterAddress = (address) => { - let addressString = ""; - Object.keys(address).forEach((field) => { - if (address[field] && field !== "id" && field !== "__typename") { - addressString += `${address[field]}${xlsx_new_line_default}`; - } - }); - return addressString; -}; -var map_address_default = mapExporterAddress; - // generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.ts var mapYesNoField = (answer) => { if (answer === false) { @@ -5822,36 +5808,12 @@ var mapYesNoField = (answer) => { }; var map_yes_no_field_default = mapYesNoField; -// generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts -var { FIELDS: FIELDS5, SECTION_TITLES } = XLSX; -var CONTENT_STRINGS3 = { - ...FIELDS.COMPANY_DETAILS, - ...FIELDS.NATURE_OF_YOUR_BUSINESS, - ...FIELDS.TURNOVER, - ...FIELDS.BROKER -}; +// generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts +var { FIELDS: FIELDS5 } = XLSX; var { - EXPORTER_BUSINESS: { - COMPANIES_HOUSE: { COMPANY_ADDRESS: COMPANY_ADDRESS2, COMPANY_INCORPORATED: COMPANY_INCORPORATED2, COMPANY_SIC: COMPANY_SIC2, FINANCIAL_YEAR_END_DATE: FINANCIAL_YEAR_END_DATE2 }, - YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME: HAS_DIFFERENT_TRADING_NAME3, DIFFERENT_TRADING_NAME: DIFFERENT_TRADING_NAME2, PHONE_NUMBER: PHONE_NUMBER3, TRADING_ADDRESS: TRADING_ADDRESS3, WEBSITE: WEBSITE3 }, - NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: GOODS_OR_SERVICES3, YEARS_EXPORTING: YEARS_EXPORTING3, EMPLOYEES_UK: EMPLOYEES_UK3 }, - TURNOVER: { ESTIMATED_ANNUAL_TURNOVER: ESTIMATED_ANNUAL_TURNOVER3, PERCENTAGE_TURNOVER: PERCENTAGE_TURNOVER2 }, - ALTERNATIVE_TRADING_ADDRESS: ALTERNATIVE_TRADING_ADDRESS2, - HAS_CREDIT_CONTROL: HAS_CREDIT_CONTROL3 - }, - POLICY: { - USING_BROKER: USING_BROKER4, - BROKER_DETAILS: { NAME: BROKER_NAME2, EMAIL: EMAIL7, FULL_ADDRESS: FULL_ADDRESS2 } - } -} = insurance_default; -var mapSicCodes2 = (sicCodes) => { - let mapped = ""; - sicCodes.forEach((sicCodeObj) => { - const { sicCode, industrySectorName } = sicCodeObj; - mapped += `${sicCode} - ${industrySectorName}${xlsx_new_line_default}`; - }); - return mapped; -}; + USING_BROKER: USING_BROKER4, + BROKER_DETAILS: { NAME: BROKER_NAME2, EMAIL: EMAIL7, FULL_ADDRESS: FULL_ADDRESS2 } +} = POLICY; var mapBroker = (application2) => { const { broker } = application2; let mapped = [xlsx_row_default(FIELDS5[USING_BROKER4], map_yes_no_field_default(broker[USING_BROKER4]))]; @@ -5865,10 +5827,55 @@ var mapBroker = (application2) => { } return mapped; }; +var map_broker_default = mapBroker; + +// generate-xlsx/map-application-to-XLSX/helpers/xlsx-new-line/index.ts +var NEW_LINE = "\r\n"; +var xlsx_new_line_default = NEW_LINE; + +// generate-xlsx/map-application-to-XLSX/map-exporter-business/map-exporter-address/index.ts +var mapExporterAddress = (address) => { + let addressString = ""; + Object.keys(address).forEach((field) => { + if (address[field] && field !== "id" && field !== "__typename") { + addressString += `${address[field]}${xlsx_new_line_default}`; + } + }); + return addressString; +}; +var map_exporter_address_default = mapExporterAddress; + +// generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.ts +var mapSicCodes2 = (sicCodes) => { + let mapped = ""; + sicCodes.forEach((sicCodeObj) => { + const { sicCode, industrySectorName } = sicCodeObj; + mapped += `${sicCode} - ${industrySectorName}${xlsx_new_line_default}`; + }); + return mapped; +}; +var map_sic_codes_default2 = mapSicCodes2; + +// generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts +var { FIELDS: FIELDS6, SECTION_TITLES } = XLSX; +var CONTENT_STRINGS3 = { + ...FIELDS.COMPANY_DETAILS, + ...FIELDS.NATURE_OF_YOUR_BUSINESS, + ...FIELDS.TURNOVER, + ...FIELDS.BROKER +}; +var { + COMPANIES_HOUSE: { COMPANY_ADDRESS: COMPANY_ADDRESS2, COMPANY_INCORPORATED: COMPANY_INCORPORATED2, COMPANY_SIC: COMPANY_SIC2, FINANCIAL_YEAR_END_DATE: FINANCIAL_YEAR_END_DATE2 }, + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME: HAS_DIFFERENT_TRADING_NAME3, DIFFERENT_TRADING_NAME: DIFFERENT_TRADING_NAME2, PHONE_NUMBER: PHONE_NUMBER3, TRADING_ADDRESS: TRADING_ADDRESS3, WEBSITE: WEBSITE3 }, + NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: GOODS_OR_SERVICES3, YEARS_EXPORTING: YEARS_EXPORTING3, EMPLOYEES_UK: EMPLOYEES_UK3 }, + TURNOVER: { ESTIMATED_ANNUAL_TURNOVER: ESTIMATED_ANNUAL_TURNOVER3, PERCENTAGE_TURNOVER: PERCENTAGE_TURNOVER2 }, + ALTERNATIVE_TRADING_ADDRESS: ALTERNATIVE_TRADING_ADDRESS2, + HAS_CREDIT_CONTROL: HAS_CREDIT_CONTROL3 +} = business_default; var mapExporterBusiness = (application2) => { const { business, company, companySicCodes } = application2; const { differentTradingAddress } = company; - let financialYearEndDate = "No data from Companies House"; + let financialYearEndDate = FIELDS6.NO_FINANCIAL_YEAR_END_DATE; if (company[FINANCIAL_YEAR_END_DATE2]) { financialYearEndDate = format_date_default(company[FINANCIAL_YEAR_END_DATE2], "d MMMM"); } @@ -5877,29 +5884,29 @@ var mapExporterBusiness = (application2) => { let mapped = [ xlsx_row_default(SECTION_TITLES.EXPORTER_BUSINESS, ""), xlsx_row_default(CONTENT_STRINGS3[COMPANY_INCORPORATED2].SUMMARY?.TITLE, format_date_default(company[COMPANY_INCORPORATED2], "dd-MMM-yy")), - xlsx_row_default(FIELDS5[COMPANY_ADDRESS2], map_address_default(company[COMPANY_ADDRESS2])), - xlsx_row_default(FIELDS5[COMPANY_SIC2], mapSicCodes2(companySicCodes)), - xlsx_row_default(FIELDS5[HAS_DIFFERENT_TRADING_NAME3], map_yes_no_field_default(company[HAS_DIFFERENT_TRADING_NAME3])) + xlsx_row_default(FIELDS6[COMPANY_ADDRESS2], map_exporter_address_default(company[COMPANY_ADDRESS2])), + xlsx_row_default(FIELDS6[COMPANY_SIC2], map_sic_codes_default2(companySicCodes)), + xlsx_row_default(FIELDS6[HAS_DIFFERENT_TRADING_NAME3], map_yes_no_field_default(company[HAS_DIFFERENT_TRADING_NAME3])) ]; if (hasDifferentTradingName) { - mapped.push(xlsx_row_default(FIELDS5[DIFFERENT_TRADING_NAME2], company[DIFFERENT_TRADING_NAME2])); + mapped.push(xlsx_row_default(FIELDS6[DIFFERENT_TRADING_NAME2], company[DIFFERENT_TRADING_NAME2])); } - mapped.push(xlsx_row_default(FIELDS5[TRADING_ADDRESS3], map_yes_no_field_default(company[TRADING_ADDRESS3]))); + mapped.push(xlsx_row_default(FIELDS6[TRADING_ADDRESS3], map_yes_no_field_default(company[TRADING_ADDRESS3]))); if (hasDifferentTradingAddress) { - mapped.push(xlsx_row_default(FIELDS5[ALTERNATIVE_TRADING_ADDRESS2.FULL_ADDRESS_DOT_NOTATION], differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS2.FULL_ADDRESS])); + mapped.push(xlsx_row_default(FIELDS6[ALTERNATIVE_TRADING_ADDRESS2.FULL_ADDRESS_DOT_NOTATION], differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS2.FULL_ADDRESS])); } mapped = [ ...mapped, - xlsx_row_default(FIELDS5[WEBSITE3], company[WEBSITE3]), - xlsx_row_default(FIELDS5[PHONE_NUMBER3], company[PHONE_NUMBER3]), - xlsx_row_default(FIELDS5[GOODS_OR_SERVICES3], business[GOODS_OR_SERVICES3]), - xlsx_row_default(FIELDS5[YEARS_EXPORTING3], business[YEARS_EXPORTING3]), - xlsx_row_default(FIELDS5[EMPLOYEES_UK3], business[EMPLOYEES_UK3]), + xlsx_row_default(FIELDS6[WEBSITE3], company[WEBSITE3]), + xlsx_row_default(FIELDS6[PHONE_NUMBER3], company[PHONE_NUMBER3]), + xlsx_row_default(FIELDS6[GOODS_OR_SERVICES3], business[GOODS_OR_SERVICES3]), + xlsx_row_default(FIELDS6[YEARS_EXPORTING3], business[YEARS_EXPORTING3]), + xlsx_row_default(FIELDS6[EMPLOYEES_UK3], business[EMPLOYEES_UK3]), xlsx_row_default(CONTENT_STRINGS3[FINANCIAL_YEAR_END_DATE2].SUMMARY?.TITLE, financialYearEndDate), - xlsx_row_default(FIELDS5[ESTIMATED_ANNUAL_TURNOVER3], format_currency_default2(business[ESTIMATED_ANNUAL_TURNOVER3], GBP_CURRENCY_CODE)), + xlsx_row_default(FIELDS6[ESTIMATED_ANNUAL_TURNOVER3], format_currency_default2(business[ESTIMATED_ANNUAL_TURNOVER3], GBP_CURRENCY_CODE)), xlsx_row_default(CONTENT_STRINGS3[PERCENTAGE_TURNOVER2].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER2]}%`), - xlsx_row_default(FIELDS5[HAS_CREDIT_CONTROL3], map_yes_no_field_default(business[HAS_CREDIT_CONTROL3])), - ...mapBroker(application2) + xlsx_row_default(FIELDS6[HAS_CREDIT_CONTROL3], map_yes_no_field_default(business[HAS_CREDIT_CONTROL3])), + ...map_broker_default(application2) ]; return mapped; }; @@ -5932,7 +5939,7 @@ var map_buyer_default = mapBuyer; // generate-xlsx/map-application-to-XLSX/map-eligibility/index.ts var { MORE_THAN_250K: MORE_THAN_250K2 } = TOTAL_CONTRACT_VALUE; -var { FIELDS: FIELDS6, SECTION_TITLES: SECTION_TITLES2 } = XLSX; +var { FIELDS: FIELDS7, SECTION_TITLES: SECTION_TITLES2 } = XLSX; var { ELIGIBILITY: { BUYER_COUNTRY: BUYER_COUNTRY3, @@ -5952,12 +5959,12 @@ var mapEligibility = (application2) => { xlsx_row_default(SECTION_TITLES2.ELIGIBILITY, ""), xlsx_row_default(FIELDS_ELIGIBILITY[VALID_EXPORTER_LOCATION2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[VALID_EXPORTER_LOCATION2])), xlsx_row_default(FIELDS_ELIGIBILITY[HAS_COMPANIES_HOUSE_NUMBER2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[HAS_COMPANIES_HOUSE_NUMBER2])), - xlsx_row_default(FIELDS6[COMPANIES_HOUSE_NUMBER3], company[COMPANIES_HOUSE_NUMBER3]), - xlsx_row_default(FIELDS6[BUYER_COUNTRY3], eligibility[BUYER_COUNTRY3].name), - xlsx_row_default(FIELDS6[MORE_THAN_250K2.VALUE], map_yes_no_field_default(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID)), - xlsx_row_default(FIELDS6[COVER_PERIOD3], eligibility[COVER_PERIOD_ELIGIBILITY].value), - xlsx_row_default(FIELDS6[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3])), - xlsx_row_default(FIELDS6[HAS_END_BUYER3], map_yes_no_field_default(eligibility[HAS_END_BUYER3])) + xlsx_row_default(FIELDS7[COMPANIES_HOUSE_NUMBER3], company[COMPANIES_HOUSE_NUMBER3]), + xlsx_row_default(FIELDS7[BUYER_COUNTRY3], eligibility[BUYER_COUNTRY3].name), + xlsx_row_default(FIELDS7[MORE_THAN_250K2.VALUE], map_yes_no_field_default(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID)), + xlsx_row_default(FIELDS7[COVER_PERIOD3], eligibility[COVER_PERIOD_ELIGIBILITY].value), + xlsx_row_default(FIELDS7[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3])), + xlsx_row_default(FIELDS7[HAS_END_BUYER3], map_yes_no_field_default(eligibility[HAS_END_BUYER3])) ]; return mapped; }; @@ -7140,7 +7147,7 @@ var mapAddress = (address) => ({ town: address.DPA.POST_TOWN, postalCode: address.DPA.POSTCODE }); -var map_address_default2 = mapAddress; +var map_address_default = mapAddress; // helpers/map-and-filter-address/index.ts var mapAndFilterAddress = (houseNameOrNumber, ordnanceSurveyResponse) => { @@ -7152,7 +7159,7 @@ var mapAndFilterAddress = (houseNameOrNumber, ordnanceSurveyResponse) => { } const mappedFilteredAddresses = []; filtered.forEach((address) => { - mappedFilteredAddresses.push(map_address_default2(address)); + mappedFilteredAddresses.push(map_address_default(address)); }); return mappedFilteredAddresses; }; diff --git a/src/api/content-strings/XLSX.ts b/src/api/content-strings/XLSX.ts index 13dfae07bd..47be3c973d 100644 --- a/src/api/content-strings/XLSX.ts +++ b/src/api/content-strings/XLSX.ts @@ -84,6 +84,7 @@ export const XLSX = { [BUYER_COMPANY_NAME]: 'Buyer company name', [BUYER_REGISTRATION_NUMBER]: 'Buyer registration number (optional)', [BUYER_CONTACT_DETAILS]: 'Buyer contact details', + NO_FINANCIAL_YEAR_END_DATE: 'No data from Companies House', }, }; diff --git a/src/api/content-strings/default.ts b/src/api/content-strings/default.ts index e26d6b2190..16d32ee2a9 100644 --- a/src/api/content-strings/default.ts +++ b/src/api/content-strings/default.ts @@ -1,3 +1,4 @@ export const DEFAULT = { EMPTY: '-', + NO_FINANCIAL_YEAR_END_DATE: 'No data from Companies House', }; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts index b3142a67ed..7074174454 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts @@ -1,13 +1,14 @@ -import mapExporter, { mapSicCodes, mapBroker } from '.'; -import INSURANCE_FIELD_IDS from '../../../constants/field-ids/insurance'; +import mapExporterBusiness from '.'; +import FIELD_IDS from '../../../constants/field-ids/insurance/business'; import { XLSX } from '../../../content-strings'; import { FIELDS as YOUR_BUSINESS_FIELDS } from '../../../content-strings/fields/insurance/your-business'; import { GBP_CURRENCY_CODE } from '../../../constants'; import xlsxRow from '../helpers/xlsx-row'; -import mapExporterAddress from './map-address'; +import mapBroker from './map-broker'; +import mapExporterAddress from './map-exporter-address'; +import mapSicCodes from './map-sic-codes'; import formatDate from '../../../helpers/format-date'; import formatCurrency from '../helpers/format-currency'; -import NEW_LINE from '../helpers/xlsx-new-line'; import { mockApplication } from '../../../test-mocks'; import mapYesNoField from '../helpers/map-yes-no-field'; @@ -22,19 +23,12 @@ const CONTENT_STRINGS = { }; const { - EXPORTER_BUSINESS: { - COMPANIES_HOUSE: { COMPANY_ADDRESS, COMPANY_INCORPORATED, COMPANY_SIC, FINANCIAL_YEAR_END_DATE }, - YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, PHONE_NUMBER, TRADING_ADDRESS, WEBSITE }, - NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, - TURNOVER: { ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER }, - // ALTERNATIVE_TRADING_ADDRESS: { ALTERNATIVE_TRADING_FULL_ADDRESS }, - HAS_CREDIT_CONTROL, - }, - POLICY: { - USING_BROKER, - BROKER_DETAILS: { NAME: BROKER_NAME, EMAIL, FULL_ADDRESS }, - }, -} = INSURANCE_FIELD_IDS; + COMPANIES_HOUSE: { COMPANY_ADDRESS, COMPANY_INCORPORATED, COMPANY_SIC, FINANCIAL_YEAR_END_DATE }, + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, PHONE_NUMBER, TRADING_ADDRESS, WEBSITE }, + NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, + TURNOVER: { ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER }, + HAS_CREDIT_CONTROL, +} = FIELD_IDS; const expectedMapExporterArray = (company, companySicCodes, business, financialYearEndDateValue) => [ xlsxRow(SECTION_TITLES.EXPORTER_BUSINESS, ''), @@ -62,92 +56,33 @@ const expectedMapExporterArray = (company, companySicCodes, business, financialY ]; describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business', () => { - describe('mapSicCodes', () => { - it('should return a string of SIC codes', () => { - const sicCodes = mockApplication.companySicCodes; + it('should return an array of mapped exporter fields', () => { + const result = mapExporterBusiness(mockApplication); - const result = mapSicCodes(sicCodes); + const { company, companySicCodes, business } = mockApplication; - const [first, last] = sicCodes; + const financialYearEndDate = formatDate(company[FINANCIAL_YEAR_END_DATE], 'd MMMM'); - const expectedFirst = `${first.sicCode} - ${first.industrySectorName}${NEW_LINE}`; + const expected = expectedMapExporterArray(company, companySicCodes, business, financialYearEndDate); - const expectedLast = `${last.sicCode} - ${last.industrySectorName}${NEW_LINE}`; - - const expected = `${expectedFirst}${expectedLast}`; - - expect(result).toEqual(expected); - }); + expect(result).toEqual(expected); }); - describe('mapBroker', () => { - describe(`when ${USING_BROKER} is true`, () => { - it('should return an array of mapped exporter fields', () => { - const result = mapBroker(mockApplication); - - const { broker } = mockApplication; - - const expected = [ - xlsxRow(XLSX.FIELDS[USING_BROKER], mapYesNoField(broker[USING_BROKER])), - xlsxRow(XLSX.FIELDS[BROKER_NAME], broker[BROKER_NAME]), - xlsxRow(XLSX.FIELDS[FULL_ADDRESS], broker[FULL_ADDRESS]), - xlsxRow(XLSX.FIELDS[EMAIL], broker[EMAIL]), - ]; - - expect(result).toEqual(expected); - }); - }); - - describe(`when ${USING_BROKER} is false`, () => { - it('should return an array of mapped exporter fields', () => { - const mockApplicationNoBroker = { - ...mockApplication, - broker: { - ...mockApplication.broker, - [USING_BROKER]: false, - }, - }; - - const result = mapBroker(mockApplicationNoBroker); - - const { broker } = mockApplicationNoBroker; + describe('when financial year end date does not exist', () => { + it('should return an array of mapped exporter fields with financialYearEndDate as an empty string', () => { + const noFinancialYearEndDateApplication = mockApplication; - const expected = [xlsxRow(XLSX.FIELDS[USING_BROKER], mapYesNoField(broker[USING_BROKER]))]; + noFinancialYearEndDateApplication.company[FINANCIAL_YEAR_END_DATE] = null; - expect(result).toEqual(expected); - }); - }); - }); - - describe('mapExporter', () => { - it('should return an array of mapped exporter fields', () => { - const result = mapExporter(mockApplication); + const result = mapExporterBusiness(noFinancialYearEndDateApplication); - const { company, companySicCodes, business } = mockApplication; + const { company, companySicCodes, business } = noFinancialYearEndDateApplication; - const financialYearEndDate = formatDate(company[FINANCIAL_YEAR_END_DATE], 'd MMMM'); + const financialYearEndDate = FIELDS.NO_FINANCIAL_YEAR_END_DATE; const expected = expectedMapExporterArray(company, companySicCodes, business, financialYearEndDate); expect(result).toEqual(expected); }); - - describe('when financial year end date does not exist', () => { - it('should return an array of mapped exporter fields with financialYearEndDate as an empty string', () => { - const noFinancialYearEndDateApplication = mockApplication; - - noFinancialYearEndDateApplication.company[FINANCIAL_YEAR_END_DATE] = null; - - const result = mapExporter(noFinancialYearEndDateApplication); - - const { company, companySicCodes, business } = noFinancialYearEndDateApplication; - - const financialYearEndDate = 'No data from Companies House'; - - const expected = expectedMapExporterArray(company, companySicCodes, business, financialYearEndDate); - - expect(result).toEqual(expected); - }); - }); }); }); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts index 1d35d96d80..df10253509 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts @@ -1,14 +1,15 @@ -import INSURANCE_FIELD_IDS from '../../../constants/field-ids/insurance'; +import FIELD_IDS from '../../../constants/field-ids/insurance/business'; import { XLSX } from '../../../content-strings'; import { FIELDS as YOUR_BUSINESS_FIELDS } from '../../../content-strings/fields/insurance/your-business'; import { GBP_CURRENCY_CODE } from '../../../constants'; import xlsxRow from '../helpers/xlsx-row'; -import mapExporterAddress from './map-address'; +import mapBroker from './map-broker'; +import mapExporterAddress from './map-exporter-address'; +import mapSicCodes from './map-sic-codes'; import formatDate from '../../../helpers/format-date'; import formatCurrency from '../helpers/format-currency'; import mapYesNoField from '../helpers/map-yes-no-field'; -import NEW_LINE from '../helpers/xlsx-new-line'; -import { Application, ApplicationCompanySicCode } from '../../../types'; +import { Application } from '../../../types'; const { FIELDS, SECTION_TITLES } = XLSX; @@ -20,60 +21,13 @@ const CONTENT_STRINGS = { }; const { - EXPORTER_BUSINESS: { - COMPANIES_HOUSE: { COMPANY_ADDRESS, COMPANY_INCORPORATED, COMPANY_SIC, FINANCIAL_YEAR_END_DATE }, - YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, DIFFERENT_TRADING_NAME, PHONE_NUMBER, TRADING_ADDRESS, WEBSITE }, - NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, - TURNOVER: { ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER }, - ALTERNATIVE_TRADING_ADDRESS, - HAS_CREDIT_CONTROL, - }, - POLICY: { - USING_BROKER, - BROKER_DETAILS: { NAME: BROKER_NAME, EMAIL, FULL_ADDRESS }, - }, -} = INSURANCE_FIELD_IDS; - -/** - * mapSicCodes - * Map an application's array of company SIC codes into a single string - * @param {Array} Application company SIC codes - * @returns {String} String of company SIC codes for XLSX generation - */ -export const mapSicCodes = (sicCodes: Array) => { - let mapped = ''; - - sicCodes.forEach((sicCodeObj) => { - const { sicCode, industrySectorName } = sicCodeObj; - - mapped += `${sicCode} - ${industrySectorName}${NEW_LINE}`; - }); - - return mapped; -}; - -/** - * mapBroker - * Map an application's broker fields into an array of objects for XLSX generation - * @param {Application} - * @returns {Array} Array of objects for XLSX generation - */ -export const mapBroker = (application: Application) => { - const { broker } = application; - - let mapped = [xlsxRow(FIELDS[USING_BROKER], mapYesNoField(broker[USING_BROKER]))]; - - if (broker[USING_BROKER]) { - mapped = [ - ...mapped, - xlsxRow(FIELDS[BROKER_NAME], broker[BROKER_NAME]), - xlsxRow(FIELDS[FULL_ADDRESS], broker[FULL_ADDRESS]), - xlsxRow(FIELDS[EMAIL], broker[EMAIL]), - ]; - } - - return mapped; -}; + COMPANIES_HOUSE: { COMPANY_ADDRESS, COMPANY_INCORPORATED, COMPANY_SIC, FINANCIAL_YEAR_END_DATE }, + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, DIFFERENT_TRADING_NAME, PHONE_NUMBER, TRADING_ADDRESS, WEBSITE }, + NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, + TURNOVER: { ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER }, + ALTERNATIVE_TRADING_ADDRESS, + HAS_CREDIT_CONTROL, +} = FIELD_IDS; /** * mapExporterBusiness @@ -91,7 +45,7 @@ const mapExporterBusiness = (application: Application) => { */ // TODO: constant - let financialYearEndDate = 'No data from Companies House'; + let financialYearEndDate = FIELDS.NO_FINANCIAL_YEAR_END_DATE; if (company[FINANCIAL_YEAR_END_DATE]) { financialYearEndDate = formatDate(company[FINANCIAL_YEAR_END_DATE], 'd MMMM'); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.test.ts new file mode 100644 index 0000000000..713cc47386 --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.test.ts @@ -0,0 +1,52 @@ +import mapBroker from '.'; +import { POLICY as FIELD_IDS } from '../../../../constants/field-ids/insurance/policy'; +import { XLSX } from '../../../../content-strings'; +import xlsxRow from '../../helpers/xlsx-row'; +import mapYesNoField from '../../helpers/map-yes-no-field'; +import { mockApplication } from '../../../../test-mocks'; + +const { FIELDS } = XLSX; + +const { + USING_BROKER, + BROKER_DETAILS: { NAME: BROKER_NAME, EMAIL, FULL_ADDRESS }, +} = FIELD_IDS; + +describe('api/generate-xlsx/map-application-to-xlsx/map-broker', () => { + describe(`when ${USING_BROKER} is true`, () => { + it('should return an array of mapped exporter fields', () => { + const result = mapBroker(mockApplication); + + const { broker } = mockApplication; + + const expected = [ + xlsxRow(FIELDS[USING_BROKER], mapYesNoField(broker[USING_BROKER])), + xlsxRow(FIELDS[BROKER_NAME], broker[BROKER_NAME]), + xlsxRow(FIELDS[FULL_ADDRESS], broker[FULL_ADDRESS]), + xlsxRow(FIELDS[EMAIL], broker[EMAIL]), + ]; + + expect(result).toEqual(expected); + }); + }); + + describe(`when ${USING_BROKER} is false`, () => { + it('should return an array of mapped exporter fields', () => { + const mockApplicationNoBroker = { + ...mockApplication, + broker: { + ...mockApplication.broker, + [USING_BROKER]: false, + }, + }; + + const result = mapBroker(mockApplicationNoBroker); + + const { broker } = mockApplicationNoBroker; + + const expected = [xlsxRow(FIELDS[USING_BROKER], mapYesNoField(broker[USING_BROKER]))]; + + expect(result).toEqual(expected); + }); + }); +}); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts new file mode 100644 index 0000000000..3deba7f4a8 --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts @@ -0,0 +1,37 @@ +import { POLICY as FIELD_IDS } from '../../../../constants/field-ids/insurance/policy'; +import { XLSX } from '../../../../content-strings'; +import xlsxRow from '../../helpers/xlsx-row'; +import mapYesNoField from '../../helpers/map-yes-no-field'; +import { Application } from '../../../../types'; + +const { FIELDS } = XLSX; + +const { + USING_BROKER, + BROKER_DETAILS: { NAME: BROKER_NAME, EMAIL, FULL_ADDRESS }, +} = FIELD_IDS; + +/** + * mapBroker + * Map an application's broker fields into an array of objects for XLSX generation + * @param {Application} + * @returns {Array} Array of objects for XLSX generation + */ +const mapBroker = (application: Application) => { + const { broker } = application; + + let mapped = [xlsxRow(FIELDS[USING_BROKER], mapYesNoField(broker[USING_BROKER]))]; + + if (broker[USING_BROKER]) { + mapped = [ + ...mapped, + xlsxRow(FIELDS[BROKER_NAME], broker[BROKER_NAME]), + xlsxRow(FIELDS[FULL_ADDRESS], broker[FULL_ADDRESS]), + xlsxRow(FIELDS[EMAIL], broker[EMAIL]), + ]; + } + + return mapped; +}; + +export default mapBroker; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-address/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-exporter-address/index.test.ts similarity index 97% rename from src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-address/index.test.ts rename to src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-exporter-address/index.test.ts index 1c6f6b2817..81623e89bf 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-address/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-exporter-address/index.test.ts @@ -10,7 +10,7 @@ const { }, } = FIELD_IDS; -describe('api/generate-xlsx/map-application-to-xlsx/map-exporter/map-address', () => { +describe('api/generate-xlsx/map-application-to-xlsx/map-exporter/map-exporter-address', () => { it('should return a string from address fields', () => { const address = mockCompany[COMPANY_ADDRESS]; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-address/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-exporter-address/index.ts similarity index 100% rename from src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-address/index.ts rename to src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-exporter-address/index.ts diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.test.ts new file mode 100644 index 0000000000..50294f50b7 --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.test.ts @@ -0,0 +1,21 @@ +import mapSicCodes from '.'; +import NEW_LINE from '../../helpers/xlsx-new-line'; +import { mockApplication } from '../../../../test-mocks'; + +describe('api/generate-xlsx/map-application-to-xlsx/map-sic-codes', () => { + it('should return a string of SIC codes', () => { + const sicCodes = mockApplication.companySicCodes; + + const result = mapSicCodes(sicCodes); + + const [first, last] = sicCodes; + + const expectedFirst = `${first.sicCode} - ${first.industrySectorName}${NEW_LINE}`; + + const expectedLast = `${last.sicCode} - ${last.industrySectorName}${NEW_LINE}`; + + const expected = `${expectedFirst}${expectedLast}`; + + expect(result).toEqual(expected); + }); +}); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.ts new file mode 100644 index 0000000000..655759b7bc --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.ts @@ -0,0 +1,22 @@ +import NEW_LINE from '../../helpers/xlsx-new-line'; +import { ApplicationCompanySicCode } from '../../../../types'; + +/** + * mapSicCodes + * Map an application's array of company SIC codes into a single string + * @param {Array} Application company SIC codes + * @returns {String} String of company SIC codes for XLSX generation + */ +const mapSicCodes = (sicCodes: Array) => { + let mapped = ''; + + sicCodes.forEach((sicCodeObj) => { + const { sicCode, industrySectorName } = sicCodeObj; + + mapped += `${sicCode} - ${industrySectorName}${NEW_LINE}`; + }); + + return mapped; +}; + +export default mapSicCodes; From 344e4965ccd1ca48e9baf586d6bf70e4dab99b46 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Tue, 28 May 2024 13:25:09 +0100 Subject: [PATCH 10/29] feat(EMS-3345): no pdf - application submission - XLSX - code improvements --- src/api/.keystone/config.js | 113 +++++++++++------- src/api/content-strings/default.ts | 1 - src/api/emails/application/index.ts | 6 +- src/api/generate-xlsx/index.ts | 28 +++-- .../map-exporter-business/index.test.ts | 68 ++++------- .../map-exporter-business/index.ts | 48 ++------ .../map-broker/index.test.ts | 6 +- .../map-exporter-business/map-broker/index.ts | 4 +- .../index.test.ts | 49 ++++++++ .../map-different-trading-address/index.ts | 28 +++++ .../map-different-trading-name/index.test.ts | 54 +++++++++ .../map-different-trading-name/index.ts | 24 ++++ .../map-exporter-address/index.test.ts | 3 +- .../map-financial-year-end-date/index.test.ts | 45 +++++++ .../map-financial-year-end-date/index.ts | 27 +++++ .../map-sic-codes/index.test.ts | 2 +- 16 files changed, 366 insertions(+), 140 deletions(-) create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-address/index.test.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-address/index.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-name/index.test.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-name/index.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-financial-year-end-date/index.test.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-financial-year-end-date/index.ts diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 0401e8cbd2..e6c5b731c1 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -5546,8 +5546,7 @@ var TIME_SUBMITTED = { // content-strings/default.ts var DEFAULT = { - EMPTY: "-", - NO_FINANCIAL_YEAR_END_DATE: "No data from Companies House" + EMPTY: "-" }; // content-strings/XLSX.ts @@ -5809,11 +5808,11 @@ var mapYesNoField = (answer) => { var map_yes_no_field_default = mapYesNoField; // generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts -var { FIELDS: FIELDS5 } = XLSX; var { USING_BROKER: USING_BROKER4, BROKER_DETAILS: { NAME: BROKER_NAME2, EMAIL: EMAIL7, FULL_ADDRESS: FULL_ADDRESS2 } } = POLICY; +var { FIELDS: FIELDS5 } = XLSX; var mapBroker = (application2) => { const { broker } = application2; let mapped = [xlsx_row_default(FIELDS5[USING_BROKER4], map_yes_no_field_default(broker[USING_BROKER4]))]; @@ -5829,6 +5828,32 @@ var mapBroker = (application2) => { }; var map_broker_default = mapBroker; +// generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-name/index.ts +var { + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME: HAS_DIFFERENT_TRADING_NAME3, DIFFERENT_TRADING_NAME: DIFFERENT_TRADING_NAME2 } +} = business_default; +var { FIELDS: FIELDS6 } = XLSX; +var mapDifferentTradingName = (company) => { + if (company[HAS_DIFFERENT_TRADING_NAME3]) { + return xlsx_row_default(FIELDS6[DIFFERENT_TRADING_NAME2], company[DIFFERENT_TRADING_NAME2]); + } +}; +var map_different_trading_name_default = mapDifferentTradingName; + +// generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-address/index.ts +var { + ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS: FULL_ADDRESS3, FULL_ADDRESS_DOT_NOTATION: FULL_ADDRESS_DOT_NOTATION2 } +} = business_default; +var { FIELDS: FIELDS7 } = XLSX; +var mapDifferentTradingAddress = (company) => { + const { differentTradingAddress } = company; + const differentTradingAddressValue = differentTradingAddress[FULL_ADDRESS3]; + if (differentTradingAddressValue) { + return xlsx_row_default(FIELDS7[FULL_ADDRESS_DOT_NOTATION2], differentTradingAddressValue); + } +}; +var map_different_trading_address_default = mapDifferentTradingAddress; + // generate-xlsx/map-application-to-XLSX/helpers/xlsx-new-line/index.ts var NEW_LINE = "\r\n"; var xlsx_new_line_default = NEW_LINE; @@ -5845,6 +5870,19 @@ var mapExporterAddress = (address) => { }; var map_exporter_address_default = mapExporterAddress; +// generate-xlsx/map-application-to-XLSX/map-exporter-business/map-financial-year-end-date/index.ts +var { + COMPANIES_HOUSE: { FINANCIAL_YEAR_END_DATE: FINANCIAL_YEAR_END_DATE2 } +} = business_default; +var { FIELDS: FIELDS8 } = XLSX; +var mapFinancialYearEndDate = (company) => { + if (company[FINANCIAL_YEAR_END_DATE2]) { + return format_date_default(company[FINANCIAL_YEAR_END_DATE2], "d MMMM"); + } + return FIELDS8.NO_FINANCIAL_YEAR_END_DATE; +}; +var map_financial_year_end_date_default = mapFinancialYearEndDate; + // generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.ts var mapSicCodes2 = (sicCodes) => { let mapped = ""; @@ -5857,7 +5895,7 @@ var mapSicCodes2 = (sicCodes) => { var map_sic_codes_default2 = mapSicCodes2; // generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts -var { FIELDS: FIELDS6, SECTION_TITLES } = XLSX; +var { FIELDS: FIELDS9, SECTION_TITLES } = XLSX; var CONTENT_STRINGS3 = { ...FIELDS.COMPANY_DETAILS, ...FIELDS.NATURE_OF_YOUR_BUSINESS, @@ -5865,47 +5903,32 @@ var CONTENT_STRINGS3 = { ...FIELDS.BROKER }; var { - COMPANIES_HOUSE: { COMPANY_ADDRESS: COMPANY_ADDRESS2, COMPANY_INCORPORATED: COMPANY_INCORPORATED2, COMPANY_SIC: COMPANY_SIC2, FINANCIAL_YEAR_END_DATE: FINANCIAL_YEAR_END_DATE2 }, - YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME: HAS_DIFFERENT_TRADING_NAME3, DIFFERENT_TRADING_NAME: DIFFERENT_TRADING_NAME2, PHONE_NUMBER: PHONE_NUMBER3, TRADING_ADDRESS: TRADING_ADDRESS3, WEBSITE: WEBSITE3 }, + COMPANIES_HOUSE: { COMPANY_ADDRESS: COMPANY_ADDRESS2, COMPANY_INCORPORATED: COMPANY_INCORPORATED2, COMPANY_SIC: COMPANY_SIC2, FINANCIAL_YEAR_END_DATE: FINANCIAL_YEAR_END_DATE3 }, + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME: HAS_DIFFERENT_TRADING_NAME4, TRADING_ADDRESS: TRADING_ADDRESS3, PHONE_NUMBER: PHONE_NUMBER3, WEBSITE: WEBSITE3 }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES: GOODS_OR_SERVICES3, YEARS_EXPORTING: YEARS_EXPORTING3, EMPLOYEES_UK: EMPLOYEES_UK3 }, TURNOVER: { ESTIMATED_ANNUAL_TURNOVER: ESTIMATED_ANNUAL_TURNOVER3, PERCENTAGE_TURNOVER: PERCENTAGE_TURNOVER2 }, - ALTERNATIVE_TRADING_ADDRESS: ALTERNATIVE_TRADING_ADDRESS2, HAS_CREDIT_CONTROL: HAS_CREDIT_CONTROL3 } = business_default; var mapExporterBusiness = (application2) => { const { business, company, companySicCodes } = application2; - const { differentTradingAddress } = company; - let financialYearEndDate = FIELDS6.NO_FINANCIAL_YEAR_END_DATE; - if (company[FINANCIAL_YEAR_END_DATE2]) { - financialYearEndDate = format_date_default(company[FINANCIAL_YEAR_END_DATE2], "d MMMM"); - } - const hasDifferentTradingName = company[HAS_DIFFERENT_TRADING_NAME3]; - const hasDifferentTradingAddress = differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS2.FULL_ADDRESS]; - let mapped = [ + const mapped = [ xlsx_row_default(SECTION_TITLES.EXPORTER_BUSINESS, ""), xlsx_row_default(CONTENT_STRINGS3[COMPANY_INCORPORATED2].SUMMARY?.TITLE, format_date_default(company[COMPANY_INCORPORATED2], "dd-MMM-yy")), - xlsx_row_default(FIELDS6[COMPANY_ADDRESS2], map_exporter_address_default(company[COMPANY_ADDRESS2])), - xlsx_row_default(FIELDS6[COMPANY_SIC2], map_sic_codes_default2(companySicCodes)), - xlsx_row_default(FIELDS6[HAS_DIFFERENT_TRADING_NAME3], map_yes_no_field_default(company[HAS_DIFFERENT_TRADING_NAME3])) - ]; - if (hasDifferentTradingName) { - mapped.push(xlsx_row_default(FIELDS6[DIFFERENT_TRADING_NAME2], company[DIFFERENT_TRADING_NAME2])); - } - mapped.push(xlsx_row_default(FIELDS6[TRADING_ADDRESS3], map_yes_no_field_default(company[TRADING_ADDRESS3]))); - if (hasDifferentTradingAddress) { - mapped.push(xlsx_row_default(FIELDS6[ALTERNATIVE_TRADING_ADDRESS2.FULL_ADDRESS_DOT_NOTATION], differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS2.FULL_ADDRESS])); - } - mapped = [ - ...mapped, - xlsx_row_default(FIELDS6[WEBSITE3], company[WEBSITE3]), - xlsx_row_default(FIELDS6[PHONE_NUMBER3], company[PHONE_NUMBER3]), - xlsx_row_default(FIELDS6[GOODS_OR_SERVICES3], business[GOODS_OR_SERVICES3]), - xlsx_row_default(FIELDS6[YEARS_EXPORTING3], business[YEARS_EXPORTING3]), - xlsx_row_default(FIELDS6[EMPLOYEES_UK3], business[EMPLOYEES_UK3]), - xlsx_row_default(CONTENT_STRINGS3[FINANCIAL_YEAR_END_DATE2].SUMMARY?.TITLE, financialYearEndDate), - xlsx_row_default(FIELDS6[ESTIMATED_ANNUAL_TURNOVER3], format_currency_default2(business[ESTIMATED_ANNUAL_TURNOVER3], GBP_CURRENCY_CODE)), + xlsx_row_default(FIELDS9[COMPANY_ADDRESS2], map_exporter_address_default(company[COMPANY_ADDRESS2])), + xlsx_row_default(FIELDS9[COMPANY_SIC2], map_sic_codes_default2(companySicCodes)), + xlsx_row_default(FIELDS9[HAS_DIFFERENT_TRADING_NAME4], map_yes_no_field_default(company[HAS_DIFFERENT_TRADING_NAME4])), + map_different_trading_name_default(company), + xlsx_row_default(FIELDS9[TRADING_ADDRESS3], map_yes_no_field_default(company[TRADING_ADDRESS3])), + map_different_trading_address_default(company), + xlsx_row_default(FIELDS9[WEBSITE3], company[WEBSITE3]), + xlsx_row_default(FIELDS9[PHONE_NUMBER3], company[PHONE_NUMBER3]), + xlsx_row_default(FIELDS9[GOODS_OR_SERVICES3], business[GOODS_OR_SERVICES3]), + xlsx_row_default(FIELDS9[YEARS_EXPORTING3], business[YEARS_EXPORTING3]), + xlsx_row_default(FIELDS9[EMPLOYEES_UK3], business[EMPLOYEES_UK3]), + xlsx_row_default(CONTENT_STRINGS3[FINANCIAL_YEAR_END_DATE3].SUMMARY?.TITLE, map_financial_year_end_date_default(company)), + xlsx_row_default(FIELDS9[ESTIMATED_ANNUAL_TURNOVER3], format_currency_default2(business[ESTIMATED_ANNUAL_TURNOVER3], GBP_CURRENCY_CODE)), xlsx_row_default(CONTENT_STRINGS3[PERCENTAGE_TURNOVER2].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER2]}%`), - xlsx_row_default(FIELDS6[HAS_CREDIT_CONTROL3], map_yes_no_field_default(business[HAS_CREDIT_CONTROL3])), + xlsx_row_default(FIELDS9[HAS_CREDIT_CONTROL3], map_yes_no_field_default(business[HAS_CREDIT_CONTROL3])), ...map_broker_default(application2) ]; return mapped; @@ -5939,7 +5962,7 @@ var map_buyer_default = mapBuyer; // generate-xlsx/map-application-to-XLSX/map-eligibility/index.ts var { MORE_THAN_250K: MORE_THAN_250K2 } = TOTAL_CONTRACT_VALUE; -var { FIELDS: FIELDS7, SECTION_TITLES: SECTION_TITLES2 } = XLSX; +var { FIELDS: FIELDS10, SECTION_TITLES: SECTION_TITLES2 } = XLSX; var { ELIGIBILITY: { BUYER_COUNTRY: BUYER_COUNTRY3, @@ -5959,12 +5982,12 @@ var mapEligibility = (application2) => { xlsx_row_default(SECTION_TITLES2.ELIGIBILITY, ""), xlsx_row_default(FIELDS_ELIGIBILITY[VALID_EXPORTER_LOCATION2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[VALID_EXPORTER_LOCATION2])), xlsx_row_default(FIELDS_ELIGIBILITY[HAS_COMPANIES_HOUSE_NUMBER2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[HAS_COMPANIES_HOUSE_NUMBER2])), - xlsx_row_default(FIELDS7[COMPANIES_HOUSE_NUMBER3], company[COMPANIES_HOUSE_NUMBER3]), - xlsx_row_default(FIELDS7[BUYER_COUNTRY3], eligibility[BUYER_COUNTRY3].name), - xlsx_row_default(FIELDS7[MORE_THAN_250K2.VALUE], map_yes_no_field_default(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID)), - xlsx_row_default(FIELDS7[COVER_PERIOD3], eligibility[COVER_PERIOD_ELIGIBILITY].value), - xlsx_row_default(FIELDS7[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3])), - xlsx_row_default(FIELDS7[HAS_END_BUYER3], map_yes_no_field_default(eligibility[HAS_END_BUYER3])) + xlsx_row_default(FIELDS10[COMPANIES_HOUSE_NUMBER3], company[COMPANIES_HOUSE_NUMBER3]), + xlsx_row_default(FIELDS10[BUYER_COUNTRY3], eligibility[BUYER_COUNTRY3].name), + xlsx_row_default(FIELDS10[MORE_THAN_250K2.VALUE], map_yes_no_field_default(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID)), + xlsx_row_default(FIELDS10[COVER_PERIOD3], eligibility[COVER_PERIOD_ELIGIBILITY].value), + xlsx_row_default(FIELDS10[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3])), + xlsx_row_default(FIELDS10[HAS_END_BUYER3], map_yes_no_field_default(eligibility[HAS_END_BUYER3])) ]; return mapped; }; @@ -6094,7 +6117,9 @@ var XLSX2 = (application2) => { worksheet.columns = header_columns_default; console.info("Generating XLSX file - adding rows to worksheet"); xlsxData.forEach((row) => { - worksheet.addRow(row); + if (row) { + worksheet.addRow(row); + } }); console.info("Generating XLSX file - adding custom styles to worksheet"); worksheet = styled_columns_default(application2, worksheet); diff --git a/src/api/content-strings/default.ts b/src/api/content-strings/default.ts index 16d32ee2a9..e26d6b2190 100644 --- a/src/api/content-strings/default.ts +++ b/src/api/content-strings/default.ts @@ -1,4 +1,3 @@ export const DEFAULT = { EMPTY: '-', - NO_FINANCIAL_YEAR_END_DATE: 'No data from Companies House', }; diff --git a/src/api/emails/application/index.ts b/src/api/emails/application/index.ts index 2b27cafacc..3ec532342f 100644 --- a/src/api/emails/application/index.ts +++ b/src/api/emails/application/index.ts @@ -50,8 +50,10 @@ const application = { const response = await callNotify(templateId, emailAddress, variables, fileBuffer); - // NOTE: no need to handle an error from fs.unlink here, - // if it errors, it will go into the catch handler below. + /** + * NOTE: no need to handle an error from fs.unlink here. + * If this errors, it will go into the catch handler below. + */ await fileSystem.unlink(filePath); return response; diff --git a/src/api/generate-xlsx/index.ts b/src/api/generate-xlsx/index.ts index b872c49d94..f388e25aad 100644 --- a/src/api/generate-xlsx/index.ts +++ b/src/api/generate-xlsx/index.ts @@ -23,32 +23,46 @@ const XLSX = (application: Application): Promise => { const xlsxData = mapApplicationToXLSX(application); - // Create a new workbook + // create a new workbook console.info('Generating XLSX file - creating a new workbook'); const workbook = new ExcelJS.Workbook(); - // Add a worksheet to the workbook + // add a worksheet to the workbook console.info('Generating XLSX file - adding worksheet to workbook'); let worksheet = workbook.addWorksheet(refNumber); - // Add header columns to the worksheet + // add header columns to the worksheet worksheet.columns = HEADER_COLUMNS; - // Add each row to the worksheet + // add each row to the worksheet console.info('Generating XLSX file - adding rows to worksheet'); xlsxData.forEach((row) => { - worksheet.addRow(row); + /** + * NOTE: some rows are undefined. + * Therefore, only add rows that have data. + */ + if (row) { + worksheet.addRow(row); + } }); - // Add custom styles to each column in the worksheet + /** + * Add custom styles to each column in the worksheet. + * This introduces e.g: + * - larger rows for address and SIC codes. + * - bold heading rows. + */ console.info('Generating XLSX file - adding custom styles to worksheet'); worksheet = styledColumns(application, worksheet); - // Write the file and return the file path + /** + * Write the file, + * return the file path + */ console.info('Generating XLSX file - writing file'); workbook.xlsx.writeFile(filePath).then(() => resolve(filePath)); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts index 7074174454..45ea17b23c 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts @@ -5,15 +5,16 @@ import { FIELDS as YOUR_BUSINESS_FIELDS } from '../../../content-strings/fields/ import { GBP_CURRENCY_CODE } from '../../../constants'; import xlsxRow from '../helpers/xlsx-row'; import mapBroker from './map-broker'; +import mapDifferentTradingName from './map-different-trading-name'; +import mapDifferentTradingAddress from './map-different-trading-address'; import mapExporterAddress from './map-exporter-address'; +import mapFinancialYearEndDate from './map-financial-year-end-date'; import mapSicCodes from './map-sic-codes'; import formatDate from '../../../helpers/format-date'; import formatCurrency from '../helpers/format-currency'; import { mockApplication } from '../../../test-mocks'; import mapYesNoField from '../helpers/map-yes-no-field'; -const { FIELDS, SECTION_TITLES } = XLSX; - const CONTENT_STRINGS = { ...YOUR_BUSINESS_FIELDS.COMPANY_DETAILS, ...YOUR_BUSINESS_FIELDS.NATURE_OF_YOUR_BUSINESS, @@ -24,36 +25,13 @@ const CONTENT_STRINGS = { const { COMPANIES_HOUSE: { COMPANY_ADDRESS, COMPANY_INCORPORATED, COMPANY_SIC, FINANCIAL_YEAR_END_DATE }, - YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, PHONE_NUMBER, TRADING_ADDRESS, WEBSITE }, + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, TRADING_ADDRESS, PHONE_NUMBER, WEBSITE }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, TURNOVER: { ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER }, HAS_CREDIT_CONTROL, } = FIELD_IDS; -const expectedMapExporterArray = (company, companySicCodes, business, financialYearEndDateValue) => [ - xlsxRow(SECTION_TITLES.EXPORTER_BUSINESS, ''), - - xlsxRow(CONTENT_STRINGS[COMPANY_INCORPORATED].SUMMARY?.TITLE, formatDate(company[COMPANY_INCORPORATED], 'dd-MMM-yy')), - xlsxRow(FIELDS[COMPANY_ADDRESS], mapExporterAddress(company[COMPANY_ADDRESS])), - xlsxRow(FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), - - xlsxRow(FIELDS[HAS_DIFFERENT_TRADING_NAME], mapYesNoField(company[HAS_DIFFERENT_TRADING_NAME])), - xlsxRow(FIELDS[TRADING_ADDRESS], mapYesNoField(company[TRADING_ADDRESS])), - - xlsxRow(FIELDS[WEBSITE], company[WEBSITE]), - xlsxRow(FIELDS[PHONE_NUMBER], company[PHONE_NUMBER]), - - xlsxRow(FIELDS[GOODS_OR_SERVICES], business[GOODS_OR_SERVICES]), - xlsxRow(FIELDS[YEARS_EXPORTING], business[YEARS_EXPORTING]), - xlsxRow(FIELDS[EMPLOYEES_UK], business[EMPLOYEES_UK]), - xlsxRow(CONTENT_STRINGS[FINANCIAL_YEAR_END_DATE].SUMMARY?.TITLE, financialYearEndDateValue), - xlsxRow(FIELDS[ESTIMATED_ANNUAL_TURNOVER], formatCurrency(business[ESTIMATED_ANNUAL_TURNOVER], GBP_CURRENCY_CODE)), - xlsxRow(CONTENT_STRINGS[PERCENTAGE_TURNOVER].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER]}%`), - - xlsxRow(FIELDS[HAS_CREDIT_CONTROL], mapYesNoField(business[HAS_CREDIT_CONTROL])), - - ...mapBroker(mockApplication), -]; +const { FIELDS, SECTION_TITLES } = XLSX; describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business', () => { it('should return an array of mapped exporter fields', () => { @@ -61,28 +39,34 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business', () = const { company, companySicCodes, business } = mockApplication; - const financialYearEndDate = formatDate(company[FINANCIAL_YEAR_END_DATE], 'd MMMM'); - - const expected = expectedMapExporterArray(company, companySicCodes, business, financialYearEndDate); + const expected = [ + xlsxRow(SECTION_TITLES.EXPORTER_BUSINESS, ''), - expect(result).toEqual(expected); - }); + xlsxRow(CONTENT_STRINGS[COMPANY_INCORPORATED].SUMMARY?.TITLE, formatDate(company[COMPANY_INCORPORATED], 'dd-MMM-yy')), + xlsxRow(FIELDS[COMPANY_ADDRESS], mapExporterAddress(company[COMPANY_ADDRESS])), + xlsxRow(FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), - describe('when financial year end date does not exist', () => { - it('should return an array of mapped exporter fields with financialYearEndDate as an empty string', () => { - const noFinancialYearEndDateApplication = mockApplication; + xlsxRow(FIELDS[HAS_DIFFERENT_TRADING_NAME], mapYesNoField(company[HAS_DIFFERENT_TRADING_NAME])), + mapDifferentTradingName(company), - noFinancialYearEndDateApplication.company[FINANCIAL_YEAR_END_DATE] = null; + xlsxRow(FIELDS[TRADING_ADDRESS], mapYesNoField(company[TRADING_ADDRESS])), + mapDifferentTradingAddress(company), - const result = mapExporterBusiness(noFinancialYearEndDateApplication); + xlsxRow(FIELDS[WEBSITE], company[WEBSITE]), + xlsxRow(FIELDS[PHONE_NUMBER], company[PHONE_NUMBER]), - const { company, companySicCodes, business } = noFinancialYearEndDateApplication; + xlsxRow(FIELDS[GOODS_OR_SERVICES], business[GOODS_OR_SERVICES]), + xlsxRow(FIELDS[YEARS_EXPORTING], business[YEARS_EXPORTING]), + xlsxRow(FIELDS[EMPLOYEES_UK], business[EMPLOYEES_UK]), + xlsxRow(CONTENT_STRINGS[FINANCIAL_YEAR_END_DATE].SUMMARY?.TITLE, mapFinancialYearEndDate(company)), + xlsxRow(FIELDS[ESTIMATED_ANNUAL_TURNOVER], formatCurrency(business[ESTIMATED_ANNUAL_TURNOVER], GBP_CURRENCY_CODE)), + xlsxRow(CONTENT_STRINGS[PERCENTAGE_TURNOVER].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER]}%`), - const financialYearEndDate = FIELDS.NO_FINANCIAL_YEAR_END_DATE; + xlsxRow(FIELDS[HAS_CREDIT_CONTROL], mapYesNoField(business[HAS_CREDIT_CONTROL])), - const expected = expectedMapExporterArray(company, companySicCodes, business, financialYearEndDate); + ...mapBroker(mockApplication), + ]; - expect(result).toEqual(expected); - }); + expect(result).toEqual(expected); }); }); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts index df10253509..5e3b647110 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts @@ -4,7 +4,10 @@ import { FIELDS as YOUR_BUSINESS_FIELDS } from '../../../content-strings/fields/ import { GBP_CURRENCY_CODE } from '../../../constants'; import xlsxRow from '../helpers/xlsx-row'; import mapBroker from './map-broker'; +import mapDifferentTradingName from './map-different-trading-name'; +import mapDifferentTradingAddress from './map-different-trading-address'; import mapExporterAddress from './map-exporter-address'; +import mapFinancialYearEndDate from './map-financial-year-end-date'; import mapSicCodes from './map-sic-codes'; import formatDate from '../../../helpers/format-date'; import formatCurrency from '../helpers/format-currency'; @@ -22,10 +25,9 @@ const CONTENT_STRINGS = { const { COMPANIES_HOUSE: { COMPANY_ADDRESS, COMPANY_INCORPORATED, COMPANY_SIC, FINANCIAL_YEAR_END_DATE }, - YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, DIFFERENT_TRADING_NAME, PHONE_NUMBER, TRADING_ADDRESS, WEBSITE }, + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, TRADING_ADDRESS, PHONE_NUMBER, WEBSITE }, NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, TURNOVER: { ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER }, - ALTERNATIVE_TRADING_ADDRESS, HAS_CREDIT_CONTROL, } = FIELD_IDS; @@ -33,50 +35,22 @@ const { * mapExporterBusiness * Map an application's exporter business fields into an array of objects for XLSX generation * @param {Application} - * @returns {Array} Array of objects for XLSX generation + * @returns {Array} Array of objects for XLSX generation */ const mapExporterBusiness = (application: Application) => { const { business, company, companySicCodes } = application; - const { differentTradingAddress } = company; - /** - * financial year end date should only be populated if it exists. - * Otherwise, return default text. - */ - - // TODO: constant - let financialYearEndDate = FIELDS.NO_FINANCIAL_YEAR_END_DATE; - - if (company[FINANCIAL_YEAR_END_DATE]) { - financialYearEndDate = formatDate(company[FINANCIAL_YEAR_END_DATE], 'd MMMM'); - } - - // TODO: documentation - // TODO: unit tests - const hasDifferentTradingName = company[HAS_DIFFERENT_TRADING_NAME]; - - const hasDifferentTradingAddress = differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS]; - - let mapped = [ + const mapped = [ xlsxRow(SECTION_TITLES.EXPORTER_BUSINESS, ''), xlsxRow(CONTENT_STRINGS[COMPANY_INCORPORATED].SUMMARY?.TITLE, formatDate(company[COMPANY_INCORPORATED], 'dd-MMM-yy')), xlsxRow(FIELDS[COMPANY_ADDRESS], mapExporterAddress(company[COMPANY_ADDRESS])), xlsxRow(FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), - xlsxRow(FIELDS[HAS_DIFFERENT_TRADING_NAME], mapYesNoField(company[HAS_DIFFERENT_TRADING_NAME])), - ]; - - if (hasDifferentTradingName) { - mapped.push(xlsxRow(FIELDS[DIFFERENT_TRADING_NAME], company[DIFFERENT_TRADING_NAME])); - } - mapped.push(xlsxRow(FIELDS[TRADING_ADDRESS], mapYesNoField(company[TRADING_ADDRESS]))); - - if (hasDifferentTradingAddress) { - mapped.push(xlsxRow(FIELDS[ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS_DOT_NOTATION], differentTradingAddress[ALTERNATIVE_TRADING_ADDRESS.FULL_ADDRESS])); - } + xlsxRow(FIELDS[HAS_DIFFERENT_TRADING_NAME], mapYesNoField(company[HAS_DIFFERENT_TRADING_NAME])), + mapDifferentTradingName(company), - mapped = [ - ...mapped, + xlsxRow(FIELDS[TRADING_ADDRESS], mapYesNoField(company[TRADING_ADDRESS])), + mapDifferentTradingAddress(company), xlsxRow(FIELDS[WEBSITE], company[WEBSITE]), xlsxRow(FIELDS[PHONE_NUMBER], company[PHONE_NUMBER]), @@ -84,7 +58,7 @@ const mapExporterBusiness = (application: Application) => { xlsxRow(FIELDS[GOODS_OR_SERVICES], business[GOODS_OR_SERVICES]), xlsxRow(FIELDS[YEARS_EXPORTING], business[YEARS_EXPORTING]), xlsxRow(FIELDS[EMPLOYEES_UK], business[EMPLOYEES_UK]), - xlsxRow(CONTENT_STRINGS[FINANCIAL_YEAR_END_DATE].SUMMARY?.TITLE, financialYearEndDate), + xlsxRow(CONTENT_STRINGS[FINANCIAL_YEAR_END_DATE].SUMMARY?.TITLE, mapFinancialYearEndDate(company)), xlsxRow(FIELDS[ESTIMATED_ANNUAL_TURNOVER], formatCurrency(business[ESTIMATED_ANNUAL_TURNOVER], GBP_CURRENCY_CODE)), xlsxRow(CONTENT_STRINGS[PERCENTAGE_TURNOVER].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER]}%`), diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.test.ts index 713cc47386..902c9912af 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.test.ts @@ -5,14 +5,14 @@ import xlsxRow from '../../helpers/xlsx-row'; import mapYesNoField from '../../helpers/map-yes-no-field'; import { mockApplication } from '../../../../test-mocks'; -const { FIELDS } = XLSX; - const { USING_BROKER, BROKER_DETAILS: { NAME: BROKER_NAME, EMAIL, FULL_ADDRESS }, } = FIELD_IDS; -describe('api/generate-xlsx/map-application-to-xlsx/map-broker', () => { +const { FIELDS } = XLSX; + +describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business/map-broker', () => { describe(`when ${USING_BROKER} is true`, () => { it('should return an array of mapped exporter fields', () => { const result = mapBroker(mockApplication); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts index 3deba7f4a8..9d03e28e60 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts @@ -4,13 +4,13 @@ import xlsxRow from '../../helpers/xlsx-row'; import mapYesNoField from '../../helpers/map-yes-no-field'; import { Application } from '../../../../types'; -const { FIELDS } = XLSX; - const { USING_BROKER, BROKER_DETAILS: { NAME: BROKER_NAME, EMAIL, FULL_ADDRESS }, } = FIELD_IDS; +const { FIELDS } = XLSX; + /** * mapBroker * Map an application's broker fields into an array of objects for XLSX generation diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-address/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-address/index.test.ts new file mode 100644 index 0000000000..e9f6f713a2 --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-address/index.test.ts @@ -0,0 +1,49 @@ +import mapDifferentTradingAddress from '.'; +import { XLSX } from '../../../../content-strings'; +import FIELD_IDS from '../../../../constants/field-ids/insurance/business'; +import xlsxRow from '../../helpers/xlsx-row'; +import mockApplication from '../../../../test-mocks/mock-application'; + +const { + ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS, FULL_ADDRESS_DOT_NOTATION }, +} = FIELD_IDS; + +const { FIELDS } = XLSX; + +describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business/map-different-trading-address', () => { + describe('when a company has a different trading address', () => { + it('should return an xlsxRow', () => { + const differentTradingAddressValue = 'Mock full address'; + + const mockCompany = { + ...mockApplication.company, + differentTradingAddress: { + ...mockApplication.company.differentTradingAddress, + [FULL_ADDRESS]: differentTradingAddressValue, + }, + }; + + const result = mapDifferentTradingAddress(mockCompany); + + const expected = xlsxRow(FIELDS[FULL_ADDRESS_DOT_NOTATION], differentTradingAddressValue); + + expect(result).toEqual(expected); + }); + }); + + describe('when a company does NOT have a different trading address', () => { + it('should not return anything', () => { + const mockCompany = { + ...mockApplication.company, + differentTradingAddress: { + ...mockApplication.company.differentTradingAddress, + [FULL_ADDRESS]: null, + }, + }; + + const result = mapDifferentTradingAddress(mockCompany); + + expect(result).toBeUndefined(); + }); + }); +}); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-address/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-address/index.ts new file mode 100644 index 0000000000..2160fa7daf --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-address/index.ts @@ -0,0 +1,28 @@ +import FIELD_IDS from '../../../../constants/field-ids/insurance/business'; +import { XLSX } from '../../../../content-strings'; +import xlsxRow from '../../helpers/xlsx-row'; +import { ApplicationCompany } from '../../../../types'; + +const { + ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS, FULL_ADDRESS_DOT_NOTATION }, +} = FIELD_IDS; + +const { FIELDS } = XLSX; + +/** + * mapDifferentTradingAddress + * Generate an XLSX row if a company has a "different trading address" value. + * @param {ApplicationCompany} company: Application company + * @returns {Object | undefined} xlsxRow + */ +const mapDifferentTradingAddress = (company: ApplicationCompany) => { + const { differentTradingAddress } = company; + + const differentTradingAddressValue = differentTradingAddress[FULL_ADDRESS]; + + if (differentTradingAddressValue) { + return xlsxRow(FIELDS[FULL_ADDRESS_DOT_NOTATION], differentTradingAddressValue); + } +}; + +export default mapDifferentTradingAddress; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-name/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-name/index.test.ts new file mode 100644 index 0000000000..e3478e410c --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-name/index.test.ts @@ -0,0 +1,54 @@ +import mapDifferentTradingName from '.'; +import { XLSX } from '../../../../content-strings'; +import FIELD_IDS from '../../../../constants/field-ids/insurance/business'; +import xlsxRow from '../../helpers/xlsx-row'; +import mockApplication from '../../../../test-mocks/mock-application'; + +const { FIELDS } = XLSX; + +const { + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, DIFFERENT_TRADING_NAME }, +} = FIELD_IDS; + +describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business/map-different-trading-name', () => { + describe(`when a company has a ${HAS_DIFFERENT_TRADING_NAME} value of true`, () => { + it('should return an xlsxRow', () => { + const mockCompany = { + ...mockApplication.company, + [HAS_DIFFERENT_TRADING_NAME]: true, + }; + + const result = mapDifferentTradingName(mockCompany); + + const expected = xlsxRow(FIELDS[DIFFERENT_TRADING_NAME], mockCompany[DIFFERENT_TRADING_NAME]); + + expect(result).toEqual(expected); + }); + }); + + describe(`when a company has a ${HAS_DIFFERENT_TRADING_NAME} value of false`, () => { + it('should not return anything', () => { + const mockCompany = { + ...mockApplication.company, + [HAS_DIFFERENT_TRADING_NAME]: false, + }; + + const result = mapDifferentTradingName(mockCompany); + + expect(result).toBeUndefined(); + }); + }); + + describe(`when a company has a ${HAS_DIFFERENT_TRADING_NAME} value of undefined`, () => { + it('should not return anything', () => { + const mockCompany = { + ...mockApplication.company, + [HAS_DIFFERENT_TRADING_NAME]: undefined, + }; + + const result = mapDifferentTradingName(mockCompany); + + expect(result).toBeUndefined(); + }); + }); +}); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-name/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-name/index.ts new file mode 100644 index 0000000000..917987b9f7 --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-name/index.ts @@ -0,0 +1,24 @@ +import FIELD_IDS from '../../../../constants/field-ids/insurance/business'; +import { XLSX } from '../../../../content-strings'; +import xlsxRow from '../../helpers/xlsx-row'; +import { ApplicationCompany } from '../../../../types'; + +const { + YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME, DIFFERENT_TRADING_NAME }, +} = FIELD_IDS; + +const { FIELDS } = XLSX; + +/** + * mapDifferentTradingName + * Generate an XLSX row if a company has a "different trading name" value. + * @param {ApplicationCompany} company: Application company + * @returns {Object | undefined} xlsxRow + */ +const mapDifferentTradingName = (company: ApplicationCompany) => { + if (company[HAS_DIFFERENT_TRADING_NAME]) { + return xlsxRow(FIELDS[DIFFERENT_TRADING_NAME], company[DIFFERENT_TRADING_NAME]); + } +}; + +export default mapDifferentTradingName; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-exporter-address/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-exporter-address/index.test.ts index 81623e89bf..40e47b3cd5 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-exporter-address/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-exporter-address/index.test.ts @@ -10,7 +10,7 @@ const { }, } = FIELD_IDS; -describe('api/generate-xlsx/map-application-to-xlsx/map-exporter/map-exporter-address', () => { +describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business/map-exporter-address', () => { it('should return a string from address fields', () => { const address = mockCompany[COMPANY_ADDRESS]; @@ -23,6 +23,7 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-exporter/map-exporter-ad const postalCode = `${address[POSTAL_CODE]}${NEW_LINE}`; const expected = `${line1}${line2}${locality}${region}${postalCode}`; + expect(result).toEqual(expected); }); }); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-financial-year-end-date/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-financial-year-end-date/index.test.ts new file mode 100644 index 0000000000..b2b87b922f --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-financial-year-end-date/index.test.ts @@ -0,0 +1,45 @@ +import mapFinancialYearEndDate from '.'; +import FIELD_IDS from '../../../../constants/field-ids/insurance/business'; +import { XLSX } from '../../../../content-strings'; +import formatDate from '../../../../helpers/format-date'; +import { mockApplication } from '../../../../test-mocks'; + +const { + COMPANIES_HOUSE: { FINANCIAL_YEAR_END_DATE }, +} = FIELD_IDS; + +const { FIELDS } = XLSX; + +describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business/map-financial-year-end-date', () => { + describe(`when a company has a ${FINANCIAL_YEAR_END_DATE}`, () => { + it('should return a formatted date', () => { + const now = new Date(); + + const mockCompany = { + ...mockApplication.company, + [FINANCIAL_YEAR_END_DATE]: now, + }; + + const result = mapFinancialYearEndDate(mockCompany); + + const expected = formatDate(mockCompany[FINANCIAL_YEAR_END_DATE], 'd MMMM'); + + expect(result).toEqual(expected); + }); + }); + + describe(`when a company does NOT have a ${FINANCIAL_YEAR_END_DATE}`, () => { + it(`should return ${FIELDS.NO_FINANCIAL_YEAR_END_DATE}`, () => { + const mockCompany = { + ...mockApplication.company, + [FINANCIAL_YEAR_END_DATE]: null, + }; + + const result = mapFinancialYearEndDate(mockCompany); + + const expected = FIELDS.NO_FINANCIAL_YEAR_END_DATE; + + expect(result).toEqual(expected); + }); + }); +}); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-financial-year-end-date/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-financial-year-end-date/index.ts new file mode 100644 index 0000000000..04dec55f53 --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-financial-year-end-date/index.ts @@ -0,0 +1,27 @@ +import FIELD_IDS from '../../../../constants/field-ids/insurance/business'; +import { XLSX } from '../../../../content-strings'; +import formatDate from '../../../../helpers/format-date'; +import { ApplicationCompany } from '../../../../types'; + +const { + COMPANIES_HOUSE: { FINANCIAL_YEAR_END_DATE }, +} = FIELD_IDS; + +const { FIELDS } = XLSX; + +/** + * mapFinancialYearEndDate + * financial year end date should only be populated if it exists. + * Otherwise, return default text. + * @param {ApplicationCompany} company: Application company + * @returns {String} + */ +const mapFinancialYearEndDate = (company: ApplicationCompany) => { + if (company[FINANCIAL_YEAR_END_DATE]) { + return formatDate(company[FINANCIAL_YEAR_END_DATE], 'd MMMM'); + } + + return FIELDS.NO_FINANCIAL_YEAR_END_DATE; +}; + +export default mapFinancialYearEndDate; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.test.ts index 50294f50b7..df7b660190 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-sic-codes/index.test.ts @@ -2,7 +2,7 @@ import mapSicCodes from '.'; import NEW_LINE from '../../helpers/xlsx-new-line'; import { mockApplication } from '../../../../test-mocks'; -describe('api/generate-xlsx/map-application-to-xlsx/map-sic-codes', () => { +describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business/map-sic-codes', () => { it('should return a string of SIC codes', () => { const sicCodes = mockApplication.companySicCodes; From 5ab21eb25fa69f11b22afb14e9bcaa3d88d202f5 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Tue, 28 May 2024 15:08:35 +0100 Subject: [PATCH 11/29] feat(EMS-3345): no pdf - application submission - XLSX - improve e2e coverage --- ...plete-sign-in-and-submit-an-application.js | 20 +++++++++--- ...-policy-type-fully-populated-buyer.spec.js | 31 +++++++++++++++++++ ...-policy-type-fully-populated-buyer.spec.js | 28 +++++++++++++++++ 3 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-fully-populated-buyer.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-fully-populated-buyer.spec.js diff --git a/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js b/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js index dcf3066adc..9e720c6ade 100644 --- a/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js +++ b/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js @@ -23,7 +23,10 @@ import completeSignInAndGoToApplication from './account/complete-sign-in-and-go- * - isUsingAgent: Should submit "yes" to "using an agent" form. * - agentIsCharging: Should submit "yes" to "agent is charging" in the "agent details" form. * - agentChargeMethodFixedSum: Agent charge method is "fixed sum" - * - agentChargeMethodPercentage: Agent charge method is "percentage" + * - hasConnectionToBuyer: Should submit "yes" to "have connection to buyer" radio. + * - fullyPopulatedBuyerTradingHistory: Submit all possible optional "buyer trading history" form fields. + * - hasHadCreditInsuranceCover: Submit "yes" to if export "has held credit insurance cover on the buyer in the past". + * - exporterHasBuyerFinancialAccounts: Should submit "yes" to the "have buyer financial accounts" form. * @return {String} Application reference number */ const completeSignInAndSubmitAnApplication = ({ @@ -44,7 +47,10 @@ const completeSignInAndSubmitAnApplication = ({ agentIsCharging = false, agentChargeMethodFixedSum = false, agentChargeMethodPercentage = false, - agentChargeMethod, + hasConnectionToBuyer = false, + fullyPopulatedBuyerTradingHistory = false, + hasHadCreditInsuranceCover = false, + exporterHasBuyerFinancialAccounts = false, }) => { completeSignInAndGoToApplication({ totalContractValueOverThreshold }).then(({ referenceNumber }) => { if (policyType === APPLICATION.POLICY_TYPE.MULTIPLE) { @@ -64,7 +70,10 @@ const completeSignInAndSubmitAnApplication = ({ agentIsCharging, agentChargeMethodFixedSum, agentChargeMethodPercentage, - agentChargeMethod, + hasConnectionToBuyer, + fullyPopulatedBuyerTradingHistory, + hasHadCreditInsuranceCover, + exporterHasBuyerFinancialAccounts, }); } else { cy.completePrepareApplicationSinglePolicyType({ @@ -82,7 +91,10 @@ const completeSignInAndSubmitAnApplication = ({ isUsingAgent, agentChargeMethodFixedSum, agentChargeMethodPercentage, - agentChargeMethod, + hasConnectionToBuyer, + fullyPopulatedBuyerTradingHistory, + hasHadCreditInsuranceCover, + exporterHasBuyerFinancialAccounts, }); } cy.completeAndSubmitCheckYourAnswers(); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-fully-populated-buyer.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-fully-populated-buyer.spec.js new file mode 100644 index 0000000000..304e2dc848 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-fully-populated-buyer.spec.js @@ -0,0 +1,31 @@ +import { APPLICATION } from '../../../../../../constants'; + +context('Insurance - submit an application - Multiple policy type, fully populated buyer', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + hasConnectionToBuyer: true, + exporterHasTradedWithBuyer: true, + fullyPopulatedBuyerTradingHistory: true, + hasHadCreditInsuranceCover: true, + exporterHasBuyerFinancialAccounts: true, + totalContractValueOverThreshold: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-fully-populated-buyer.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-fully-populated-buyer.spec.js new file mode 100644 index 0000000000..0f68e13046 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-fully-populated-buyer.spec.js @@ -0,0 +1,28 @@ +context('Insurance - submit an application - Single policy type, fully populated buyer', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + hasConnectionToBuyer: true, + exporterHasTradedWithBuyer: true, + fullyPopulatedBuyerTradingHistory: true, + hasHadCreditInsuranceCover: true, + exporterHasBuyerFinancialAccounts: true, + totalContractValueOverThreshold: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); From d89c6f8435d4c2a1dca23b764f4d4d9ebbd409d9 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Wed, 29 May 2024 15:36:25 +0100 Subject: [PATCH 12/29] feat(EMS-3344): no pdf - application submission - XLSX - your buyer --- .../insurance/complete-buyer-section.js | 8 +- ...pplication-section-multiple-policy-type.js | 6 + ...-application-section-single-policy-type.js | 6 + ...plete-sign-in-and-submit-an-application.js | 8 + e2e-tests/fixtures/application.js | 65 +--- ...policy-type-buyer-fully-populated.spec.js} | 3 +- ...e-connection-and-traded-with-buyer.spec.js | 25 ++ ...-policy-type-connection-with-buyer.spec.js | 23 ++ ...ing-payments-failed-to-pay-on-time.spec.js | 25 ++ ...payments-not-failed-to-pay-on-time.spec.js | 25 ++ ...ing-payments-failed-to-pay-on-time.spec.js | 25 ++ ...payments-not-failed-to-pay-on-time.spec.js | 25 ++ src/api/.keystone/config.js | 361 ++++++++++++++++-- .../constants/XLSX-CONFIG/INDEXES/index.ts | 2 +- src/api/constants/XLSX-CONFIG/index.ts | 30 +- .../constants/field-ids/insurance/index.ts | 4 + .../field-ids/insurance/your-buyer/index.ts | 7 + src/api/constants/index.ts | 1 + src/api/constants/validation.ts | 41 ++ src/api/content-strings/XLSX.ts | 20 +- .../fields/insurance/your-buyer/index.ts | 111 +++++- src/api/content-strings/form-titles.ts | 27 ++ src/api/emails/application/index.ts | 2 +- .../helpers/map-yes-no-field/index.ts | 8 +- .../map-buyer/index.ts | 70 +++- .../get-populated-application/index.test.ts | 24 +- .../get-populated-application/index.ts | 18 + src/api/types/application-types/index.ts | 12 +- src/ui/server/test-mocks/mock-buyer.ts | 4 +- 29 files changed, 869 insertions(+), 117 deletions(-) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{submit-an-application-single-policy-type-fully-populated-buyer.spec.js => buyer-conditions/submit-an-application-single-policy-type-buyer-fully-populated.spec.js} (91%) create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-and-traded-with-buyer.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-with-buyer.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-failed-to-pay-on-time.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-not-failed-to-pay-on-time.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-failed-to-pay-on-time.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-not-failed-to-pay-on-time.spec.js create mode 100644 src/api/constants/validation.ts create mode 100644 src/api/content-strings/form-titles.ts diff --git a/e2e-tests/commands/insurance/complete-buyer-section.js b/e2e-tests/commands/insurance/complete-buyer-section.js index e033aed577..6af0fcaab9 100644 --- a/e2e-tests/commands/insurance/complete-buyer-section.js +++ b/e2e-tests/commands/insurance/complete-buyer-section.js @@ -4,6 +4,8 @@ * @param {Boolean} viaTaskList: Start the "buyer" section from the task list. * @param {Boolean} hasConnectionToBuyer: Should submit "yes" to "have connection to buyer" radio. Defaults to "no". * @param {Boolean} exporterHasTradedWithBuyer: Submit "yes" to "have traded with buyer before" in the "working with buyer" form. + * @param {Boolean} outstandingPayments: Exporter has outstanding payments with the buyer + * @param {Boolean} failedToPay: Buyer has failed to pay the exporter on the time * @param {Boolean} fullyPopulatedBuyerTradingHistory: Submit all possible optional "buyer trading history" form fields. * @param {Boolean} hasHadCreditInsuranceCover: Submit "yes" to if export "has held credit insurance cover on the buyer in the past" * @param {Boolean} exporterHasBuyerFinancialAccounts: Submit "yes" to "have traded with buyer before" in the "working with buyer" form. @@ -14,6 +16,8 @@ const completeBuyerSection = ({ viaTaskList = true, hasConnectionToBuyer = false, exporterHasTradedWithBuyer = false, + outstandingPayments = false, + failedToPay = false, fullyPopulatedBuyerTradingHistory = false, hasHadCreditInsuranceCover = false, exporterHasBuyerFinancialAccounts = false, @@ -28,8 +32,8 @@ const completeBuyerSection = ({ if (exporterHasTradedWithBuyer) { cy.completeAndSubmitTradingHistoryWithBuyerForm({ - outstandingPayments: fullyPopulatedBuyerTradingHistory, - failedToPay: fullyPopulatedBuyerTradingHistory, + outstandingPayments: outstandingPayments || fullyPopulatedBuyerTradingHistory, + failedToPay: failedToPay || fullyPopulatedBuyerTradingHistory, }); } diff --git a/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js b/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js index f5921c92eb..7c607a5126 100644 --- a/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js +++ b/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js @@ -11,6 +11,8 @@ const { POLICY_TYPE } = APPLICATION; * @param {Boolean} hasCreditControlProcess: Flag whether to submit "yes" or "no" radio input in the "credit control" form. Defaults to false. * @param {Boolean} hasConnectionToBuyer: Should submit "yes" to "have connection to buyer" radio. * @param {Boolean} exporterHasTradedWithBuyer: Should submit "yes" to "have traded with buyer before" in the "working with buyer" form. + * @param {Boolean} buyerOutstandingPayments: Exporter has outstanding payments with the buyer + * @param {Boolean} buyerFailedToPayOnTime: Buyer has failed to pay the exporter on the time * @param {Boolean} fullyPopulatedBuyerTradingHistory: Submit all possible optional "buyer trading history" form fields. * @param {Boolean} hasHadCreditInsuranceCover: Submit "yes" to if export "has held credit insurance cover on the buyer in the past". * @param {Boolean} exporterHasBuyerFinancialAccounts: Should submit "yes" to the "have buyer financial accounts" form. @@ -35,6 +37,8 @@ const completePrepareApplicationMultiplePolicyType = ({ hasCreditControlProcess = false, hasConnectionToBuyer = false, exporterHasTradedWithBuyer = false, + buyerOutstandingPayments = false, + buyerFailedToPayOnTime = false, fullyPopulatedBuyerTradingHistory = false, hasHadCreditInsuranceCover = false, exporterHasBuyerFinancialAccounts = false, @@ -63,6 +67,8 @@ const completePrepareApplicationMultiplePolicyType = ({ cy.completeBuyerSection({ hasConnectionToBuyer, exporterHasTradedWithBuyer, + outstandingPayments: buyerOutstandingPayments, + failedToPay: buyerFailedToPayOnTime, fullyPopulatedBuyerTradingHistory, hasHadCreditInsuranceCover, exporterHasBuyerFinancialAccounts, diff --git a/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js b/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js index 6f0c8378d1..a6f6f1a946 100644 --- a/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js +++ b/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js @@ -11,6 +11,8 @@ const { POLICY_TYPE } = FIELD_VALUES; * @param {Boolean} hasCreditControlProcess: Flag whether to submit "yes" or "no" radio input in the "credit control" form. Defaults to false. * @param {Boolean} hasConnectionToBuyer: Should submit "yes" to "have connection to buyer" radio. * @param {Boolean} exporterHasTradedWithBuyer: Should submit "yes" to "have traded with buyer before" in the "working with buyer" form. + * @param {Boolean} buyerOutstandingPayments: Exporter has outstanding payments with the buyer + * @param {Boolean} buyerFailedToPayOnTime: Buyer has failed to pay the exporter on the time * @param {Boolean} fullyPopulatedBuyerTradingHistory: Submit all possible optional "buyer trading history" form fields. * @param {Boolean} hasHadCreditInsuranceCover: Submit "yes" to if export "has held credit insurance cover on the buyer in the past". * @param {Boolean} exporterHasBuyerFinancialAccounts: Should submit "yes" to the "have buyer financial accounts" form. @@ -35,6 +37,8 @@ const completePrepareApplicationSinglePolicyType = ({ hasCreditControlProcess = false, hasConnectionToBuyer, exporterHasTradedWithBuyer, + buyerOutstandingPayments = false, + buyerFailedToPayOnTime = false, fullyPopulatedBuyerTradingHistory, hasHadCreditInsuranceCover, exporterHasBuyerFinancialAccounts, @@ -63,6 +67,8 @@ const completePrepareApplicationSinglePolicyType = ({ cy.completeBuyerSection({ hasConnectionToBuyer, exporterHasTradedWithBuyer, + outstandingPayments: buyerOutstandingPayments, + failedToPay: buyerFailedToPayOnTime, fullyPopulatedBuyerTradingHistory, hasHadCreditInsuranceCover, exporterHasBuyerFinancialAccounts, diff --git a/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js b/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js index 9e720c6ade..704ce30b18 100644 --- a/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js +++ b/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js @@ -24,6 +24,8 @@ import completeSignInAndGoToApplication from './account/complete-sign-in-and-go- * - agentIsCharging: Should submit "yes" to "agent is charging" in the "agent details" form. * - agentChargeMethodFixedSum: Agent charge method is "fixed sum" * - hasConnectionToBuyer: Should submit "yes" to "have connection to buyer" radio. + * - buyerOutstandingPayments: Exporter has outstanding payments with the buyer + * - buyerFailedToPayOnTime: Buyer has failed to pay the exporter on the time * - fullyPopulatedBuyerTradingHistory: Submit all possible optional "buyer trading history" form fields. * - hasHadCreditInsuranceCover: Submit "yes" to if export "has held credit insurance cover on the buyer in the past". * - exporterHasBuyerFinancialAccounts: Should submit "yes" to the "have buyer financial accounts" form. @@ -48,6 +50,8 @@ const completeSignInAndSubmitAnApplication = ({ agentChargeMethodFixedSum = false, agentChargeMethodPercentage = false, hasConnectionToBuyer = false, + buyerOutstandingPayments = false, + buyerFailedToPayOnTime = false, fullyPopulatedBuyerTradingHistory = false, hasHadCreditInsuranceCover = false, exporterHasBuyerFinancialAccounts = false, @@ -71,6 +75,8 @@ const completeSignInAndSubmitAnApplication = ({ agentChargeMethodFixedSum, agentChargeMethodPercentage, hasConnectionToBuyer, + buyerOutstandingPayments, + buyerFailedToPayOnTime, fullyPopulatedBuyerTradingHistory, hasHadCreditInsuranceCover, exporterHasBuyerFinancialAccounts, @@ -92,6 +98,8 @@ const completeSignInAndSubmitAnApplication = ({ agentChargeMethodFixedSum, agentChargeMethodPercentage, hasConnectionToBuyer, + buyerOutstandingPayments, + buyerFailedToPayOnTime, fullyPopulatedBuyerTradingHistory, hasHadCreditInsuranceCover, exporterHasBuyerFinancialAccounts, diff --git a/e2e-tests/fixtures/application.js b/e2e-tests/fixtures/application.js index 992bb3f7aa..04b2b7b3cd 100644 --- a/e2e-tests/fixtures/application.js +++ b/e2e-tests/fixtures/application.js @@ -16,17 +16,11 @@ import mockCompanies from './companies'; import { mockIban0 } from './ibans'; import { mockSortCode0 } from './sort-codes'; -const { - AGENT_SERVICE_CHARGE, -} = APPLICATION.EXPORT_CONTRACT; +const { AGENT_SERVICE_CHARGE } = APPLICATION.EXPORT_CONTRACT; const { INSURANCE: { - ACCOUNT: { - FIRST_NAME: ACCOUNT_FIRST_NAME, - LAST_NAME: ACCOUNT_LAST_NAME, - EMAIL: ACCOUNT_EMAIL, - }, + ACCOUNT: { FIRST_NAME: ACCOUNT_FIRST_NAME, LAST_NAME: ACCOUNT_LAST_NAME, EMAIL: ACCOUNT_EMAIL }, ELIGIBILITY: { COVER_PERIOD_ID, HAS_COMPANIES_HOUSE_NUMBER, @@ -51,17 +45,11 @@ const { CREDIT_PERIOD_WITH_BUYER, REQUESTED_JOINTLY_INSURED_PARTY: { COMPANY_NAME, COMPANY_NUMBER, COUNTRY_CODE }, USING_BROKER, - BROKER_DETAILS: { - NAME, - EMAIL, - FULL_ADDRESS: BROKER_FULL_ADDRESS, - }, + BROKER_DETAILS: { NAME, EMAIL, FULL_ADDRESS: BROKER_FULL_ADDRESS }, LOSS_PAYEE_FINANCIAL_UK: { ACCOUNT_NUMBER, SORT_CODE }, LOSS_PAYEE_FINANCIAL_INTERNATIONAL: { BIC_SWIFT_CODE, IBAN }, FINANCIAL_ADDRESS, - LOSS_PAYEE_DETAILS: { - NAME: LOSS_PAYEE_NAME, - }, + LOSS_PAYEE_DETAILS: { NAME: LOSS_PAYEE_NAME }, }, EXPORT_CONTRACT: { ABOUT_GOODS_OR_SERVICES: { DESCRIPTION, FINAL_DESTINATION }, @@ -69,36 +57,17 @@ const { PRIVATE_MARKET: { ATTEMPTED, DECLINED_DESCRIPTION }, AGENT_DETAILS: { COUNTRY_CODE: AGENT_COUNTRY_CODE, FULL_ADDRESS: AGENT_FULL_ADDRESS, NAME: AGENT_NAME }, AGENT_SERVICE: { IS_CHARGING, SERVICE_DESCRIPTION }, - AGENT_CHARGES: { - METHOD, PAYABLE_COUNTRY_CODE, FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, - }, + AGENT_CHARGES: { METHOD, PAYABLE_COUNTRY_CODE, FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE }, }, EXPORTER_BUSINESS: { - ALTERNATIVE_TRADING_ADDRESS: { - FULL_ADDRESS: EXPORTER_BUSINESS_FULL_ALT_TRADING_ADDRESS, - }, - NATURE_OF_YOUR_BUSINESS: { - GOODS_OR_SERVICES, - YEARS_EXPORTING, - EMPLOYEES_UK, - }, - TURNOVER: { - ESTIMATED_ANNUAL_TURNOVER, - PERCENTAGE_TURNOVER, - }, + ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS: EXPORTER_BUSINESS_FULL_ALT_TRADING_ADDRESS }, + NATURE_OF_YOUR_BUSINESS: { GOODS_OR_SERVICES, YEARS_EXPORTING, EMPLOYEES_UK }, + TURNOVER: { ESTIMATED_ANNUAL_TURNOVER, PERCENTAGE_TURNOVER }, HAS_CREDIT_CONTROL, - YOUR_COMPANY: { - DIFFERENT_TRADING_NAME, - }, + YOUR_COMPANY: { DIFFERENT_TRADING_NAME }, }, YOUR_BUYER: { - COMPANY_OR_ORGANISATION: { - ADDRESS, - COUNTRY, - NAME: COMPANY_OR_ORGANISATION_NAME, - REGISTRATION_NUMBER, - WEBSITE, - }, + COMPANY_OR_ORGANISATION: { ADDRESS, COUNTRY, NAME: COMPANY_OR_ORGANISATION_NAME, REGISTRATION_NUMBER, WEBSITE }, CONNECTION_WITH_BUYER, CONNECTION_WITH_BUYER_DESCRIPTION, TRADED_WITH_BUYER, @@ -108,9 +77,7 @@ const { TOTAL_AMOUNT_OVERDUE, HAS_BUYER_FINANCIAL_ACCOUNTS, }, - CURRENCY: { - CURRENCY_CODE, - }, + CURRENCY: { CURRENCY_CODE }, }, } = FIELD_IDS; @@ -125,8 +92,8 @@ const date = new Date(); * move on the following year. * Note: JS months range (0 - 11) */ -export const startDate = new Date(date.setMonth((date.getMonth() + 3))); // Add 3 months -export const endDate = new Date(date.setMonth((date.getMonth() + 6))); // Add 6 months +export const startDate = new Date(date.setMonth(date.getMonth() + 3)); // Add 3 months +export const endDate = new Date(date.setMonth(date.getMonth() + 6)); // Add 6 months const application = { ELIGIBILITY: { @@ -146,12 +113,12 @@ const application = { POLICY: { [REQUESTED_START_DATE]: { day: '1', - month: (startDate.getMonth() + 1), + month: startDate.getMonth() + 1, year: startDate.getFullYear(), }, [CONTRACT_COMPLETION_DATE]: { day: '1', - month: (endDate.getMonth() + 1), + month: endDate.getMonth() + 1, year: endDate.getFullYear(), }, [TOTAL_CONTRACT_VALUE]: '10000', @@ -227,7 +194,7 @@ const application = { [CONNECTION_WITH_BUYER]: FIELD_VALUES.NO, [TRADED_WITH_BUYER]: FIELD_VALUES.NO, [HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]: FIELD_VALUES.NO, - [CONNECTION_WITH_BUYER_DESCRIPTION]: 'test description', + [CONNECTION_WITH_BUYER_DESCRIPTION]: 'Mock connection with buyer description', [PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]: 'Mock cover with buyer', [TOTAL_OUTSTANDING_PAYMENTS]: '1000', [TOTAL_AMOUNT_OVERDUE]: '2000', diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-fully-populated-buyer.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-fully-populated.spec.js similarity index 91% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-fully-populated-buyer.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-fully-populated.spec.js index 0f68e13046..a9214a03d4 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-fully-populated-buyer.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-fully-populated.spec.js @@ -5,7 +5,8 @@ context('Insurance - submit an application - Single policy type, fully populated cy.completeSignInAndSubmitAnApplication({ hasConnectionToBuyer: true, exporterHasTradedWithBuyer: true, - fullyPopulatedBuyerTradingHistory: true, + buyerOutstandingPayments: true, + buyerFailedToPayOnTime: true, hasHadCreditInsuranceCover: true, exporterHasBuyerFinancialAccounts: true, totalContractValueOverThreshold: true, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-and-traded-with-buyer.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-and-traded-with-buyer.spec.js new file mode 100644 index 0000000000..1e64d2128e --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-and-traded-with-buyer.spec.js @@ -0,0 +1,25 @@ +context('Insurance - submit an application - Single policy type, exporter has connection with buyer, has traded with buyer before', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + hasConnectionToBuyer: true, + exporterHasTradedWithBuyer: true, + fullyPopulatedBuyerTradingHistory: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-with-buyer.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-with-buyer.spec.js new file mode 100644 index 0000000000..3f50a84ed5 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-with-buyer.spec.js @@ -0,0 +1,23 @@ +context('Insurance - submit an application - Single policy type, exporter has connection with buyer', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + hasConnectionToBuyer: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-failed-to-pay-on-time.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-failed-to-pay-on-time.spec.js new file mode 100644 index 0000000000..aee3ff618b --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-failed-to-pay-on-time.spec.js @@ -0,0 +1,25 @@ +context('Insurance - submit an application - Single policy type, exporter has traded with buyer, no outstanding payments, failed to pay on time', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + exporterHasTradedWithBuyer: true, + buyerOutstandingPayments: false, + buyerFailedToPayOnTime: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-not-failed-to-pay-on-time.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-not-failed-to-pay-on-time.spec.js new file mode 100644 index 0000000000..9be1bc3c4d --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-not-failed-to-pay-on-time.spec.js @@ -0,0 +1,25 @@ +context('Insurance - submit an application - Single policy type, exporter has traded with buyer, no outstanding payments, not failed to pay on time', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + exporterHasTradedWithBuyer: true, + buyerOutstandingPayments: false, + buyerFailedToPayOnTime: false, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-failed-to-pay-on-time.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-failed-to-pay-on-time.spec.js new file mode 100644 index 0000000000..1f71e82147 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-failed-to-pay-on-time.spec.js @@ -0,0 +1,25 @@ +context('Insurance - submit an application - Single policy type, exporter has traded with buyer, has outstanding payments, has failed to pay on time', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + exporterHasTradedWithBuyer: true, + buyerOutstandingPayments: true, + buyerFailedToPayOnTime: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-not-failed-to-pay-on-time.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-not-failed-to-pay-on-time.spec.js new file mode 100644 index 0000000000..00703b646c --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-not-failed-to-pay-on-time.spec.js @@ -0,0 +1,25 @@ +context('Insurance - submit an application - Single policy type, exporter has traded with buyer, has outstanding payments, not failed to pay on time', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + exporterHasTradedWithBuyer: true, + buyerOutstandingPayments: true, + buyerFailedToPayOnTime: false, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index e6c5b731c1..ccf18835e9 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -463,7 +463,14 @@ var YOUR_BUYER = { }, CONNECTION_WITH_BUYER: "exporterIsConnectedWithBuyer", CONNECTION_WITH_BUYER_DESCRIPTION: "connectionWithBuyerDescription", - TRADED_WITH_BUYER: "exporterHasTradedWithBuyer" + TRADED_WITH_BUYER: "exporterHasTradedWithBuyer", + OUTSTANDING_PAYMENTS: "outstandingPayments", + TOTAL_OUTSTANDING_PAYMENTS: "totalOutstandingPayments", + TOTAL_AMOUNT_OVERDUE: "totalOverduePayments", + FAILED_PAYMENTS: "failedPayments", + HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: "exporterHasPreviousCreditInsuranceWithBuyer", + PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: "previousCreditInsuranceWithBuyerDescription", + HAS_BUYER_FINANCIAL_ACCOUNTS: "exporterHasBuyerFinancialAccounts" }; var your_buyer_default = YOUR_BUYER; @@ -504,6 +511,10 @@ var INSURANCE_FIELD_IDS = { HAS_REVIEWED_ELIGIBILITY: "hasReviewedEligibility" }, ...shared_default2, + CURRENCY: { + CURRENCY_CODE: "currencyCode", + ALTERNATIVE_CURRENCY_CODE: "alternativeCurrencyCode" + }, SUBMISSION_DEADLINE: "submissionDeadline", ACCOUNT: account_default, POLICY: policy_default, @@ -793,7 +804,7 @@ var TITLE_INDEXES = () => ({ EXPORTER_BUSINESS: 31, POLICY: 48, BUYER: 57, - DECLARATIONS: 65 + DECLARATIONS: 67 }); var INDEXES = () => ({ TITLES: TITLE_INDEXES(), @@ -823,6 +834,16 @@ var { var XLSX_ROW_INDEXES = (application2) => { const { broker, + buyer: { + buyerTradingHistory: { + exporterHasTradedWithBuyer, + outstandingPayments: buyerHasOutstandingPayments + }, + relationship: { + exporterIsConnectedWithBuyer, + exporterHasPreviousCreditInsuranceWithBuyer + } + }, company: { differentTradingAddress: { fullAddress: hasDifferentTradingAddress }, hasDifferentTradingName @@ -839,7 +860,7 @@ var XLSX_ROW_INDEXES = (application2) => { if (broker[USING_BROKER]) { indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; - indexes.TITLES.DECLARATIONS += 3; + indexes.TITLES.DECLARATIONS += 6; indexes.BUYER_ADDRESS += 3; indexes.BROKER_ADDRESS = 48; } @@ -853,6 +874,18 @@ var XLSX_ROW_INDEXES = (application2) => { if (hasDifferentTradingName && hasDifferentTradingAddress) { indexes.ALTERNATIVE_TRADING_ADDRESS = 38; } + if (exporterIsConnectedWithBuyer) { + indexes.TITLES.DECLARATIONS += 1; + } + if (exporterHasTradedWithBuyer) { + indexes.TITLES.DECLARATIONS += 2; + if (buyerHasOutstandingPayments) { + indexes.TITLES.DECLARATIONS += 2; + } + } + if (exporterHasPreviousCreditInsuranceWithBuyer) { + indexes.TITLES.DECLARATIONS += 1; + } return indexes; }; var XLSX_CONFIG = { @@ -874,6 +907,40 @@ var XLSX_CONFIG = { } }; +// constants/validation.ts +var MAXIMUM_CHARACTERS = { + ABOUT_GOODS_OR_SERVICES_DESCRIPTION: 1e3, + ACCOUNT_NUMBER: 8, + AGENT_NAME: 800, + AGENT_SERVICE_DESCRIPTION: 1e3, + BIC_SWIFT_CODE: 11, + BROKER_NAME: 800, + BUSINESS: { + GOODS_OR_SERVICES_DESCRIPTION: 1e3 + }, + BUYER: { + COMPANY_OR_ORGANISATION: 200, + REGISTRATION_NUMBER: 200, + PREVIOUS_CREDIT_INSURANCE_COVER: 1e3 + }, + COMPANY_DIFFERENT_TRADING_NAME: 200, + CONNECTION_WITH_BUYER_DESCRIPTION: 1e3, + CREDIT_PERIOD_WITH_BUYER: 1e3, + DECLINED_BY_PRIVATE_MARKET_DESCRIPTION: 1e3, + EMAIL: 300, + FEEDBACK: { + IMPROVEMENT: 1200, + OTHER_COMMENTS: 1200 + }, + FULL_ADDRESS: 500, + IBAN: 34, + LOSS_PAYEE_NAME: 200, + PAYMENT_TERMS_DESCRIPTION: 1e3, + PERCENTAGE: 100, + POLICY_CONTACT_NAME: 400, + SORT_CODE: 6 +}; + // constants/index.ts import_dotenv.default.config(); var GBP_CURRENCY_CODE = "GBP"; @@ -2946,7 +3013,6 @@ var application = { if (file) { const fileBuffer = Buffer.from(file); const response = await callNotify(templateId, emailAddress, variables, fileBuffer); - await file_system_default.unlink(filePath); return response; } throw new Error("Sending application submitted email to underwriting team - invalid file / file not found"); @@ -4854,6 +4920,18 @@ var getPopulatedApplication = async (context, application2) => { if (!buyer) { throw new Error(generateErrorMessage("buyer", application2.id)); } + const buyerRelationship = await context.db.BuyerRelationship.findOne({ + where: { id: buyer.relationshipId } + }); + if (!buyerRelationship) { + throw new Error(generateErrorMessage("buyerRelationship", application2.id)); + } + const buyerTradingHistory = await context.db.BuyerTradingHistory.findOne({ + where: { id: buyer.buyerTradingHistoryId } + }); + if (!buyerTradingHistory) { + throw new Error(generateErrorMessage("buyerTradingHistory", application2.id)); + } const nominatedLossPayee = await context.query.NominatedLossPayee.findOne({ where: { id: nominatedLossPayeeId }, query: "id financialUk { id accountNumber sortCode bankAddress vector { accountNumberVector sortCodeVector } } financialInternational { id iban bicSwiftCode bankAddress vector { bicSwiftCodeVector ibanVector } } isAppointed isLocatedInUk isLocatedInternationally name" @@ -4876,7 +4954,9 @@ var getPopulatedApplication = async (context, application2) => { }; const populatedBuyer = { ...buyer, - country: buyerCountry + country: buyerCountry, + relationship: buyerRelationship, + buyerTradingHistory }; const declaration = await context.db.Declaration.findOne({ where: { id: declarationId } @@ -5485,44 +5565,176 @@ var FIELDS = { } }; +// content-strings/form-titles.ts +var FORM_TITLES = { + YOUR_BUSINESS: { + COMPANY_DETAILS: "Company details", + NATURE_OF_BUSINESS: "Nature of your business", + TURNOVER: "Turnover", + CREDIT_CONTROL: "Credit control" + }, + YOUR_BUYER: { + COMPANY_DETAILS: "Company details", + CONNECTION_TO_BUYER: "Connection to the buyer", + TRADING_HISTORY: "Trading history", + CREDIT_INSURANCE_HISTORY: "Credit insurance history", + FINANCIAL_ACCOUNTS: "Financial accounts" + }, + POLICY: { + CONTRACT_POLICY: "Requested insurance policy", + NAME_ON_POLICY: "Named person on the policy", + BROKER: "Broker", + OTHER_COMPANY: "Other company to be insured", + LOSS_PAYEE: "Loss payee" + }, + EXPORT_CONTRACT: { + ABOUT_THE_EXPORT: "About the export", + PRIVATE_MARKET: "Private insurance market", + AGENT: "Agent" + } +}; + // content-strings/fields/insurance/your-buyer/index.ts var { - YOUR_BUYER: { COMPANY_OR_ORGANISATION, CONNECTION_WITH_BUYER, TRADED_WITH_BUYER } -} = insurance_default; + YOUR_BUYER: { + COMPANY_OR_ORGANISATION, + CONNECTION_WITH_BUYER, + TRADED_WITH_BUYER, + CONNECTION_WITH_BUYER_DESCRIPTION, + OUTSTANDING_PAYMENTS, + FAILED_PAYMENTS, + HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, + PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, + TOTAL_OUTSTANDING_PAYMENTS, + TOTAL_AMOUNT_OVERDUE, + HAS_BUYER_FINANCIAL_ACCOUNTS + }, + CURRENCY: { CURRENCY_CODE } +} = FIELD_IDS.INSURANCE; +var { + YOUR_BUYER: { + COMPANY_DETAILS, + TRADING_HISTORY, + CONNECTION_TO_BUYER, + CREDIT_INSURANCE_HISTORY, + FINANCIAL_ACCOUNTS + } +} = FORM_TITLES; var YOUR_BUYER_FIELDS = { COMPANY_OR_ORGANISATION: { [COMPANY_OR_ORGANISATION.NAME]: { + LABEL: "Buyer's company or organisation name", SUMMARY: { - TITLE: "Company or organisation name" + TITLE: "Company or organisation name", + FORM_TITLE: COMPANY_DETAILS } }, [COMPANY_OR_ORGANISATION.ADDRESS]: { + LABEL: "Company address", SUMMARY: { - TITLE: "Buyer address" - } + TITLE: "Buyer address", + FORM_TITLE: COMPANY_DETAILS + }, + MAXIMUM: MAXIMUM_CHARACTERS.FULL_ADDRESS }, [COMPANY_OR_ORGANISATION.COUNTRY]: { - LABEL: "Country" + LABEL: "Buyer country", + SUMMARY: { + TITLE: "Buyer country" + } }, [COMPANY_OR_ORGANISATION.REGISTRATION_NUMBER]: { + LABEL: "Company registration number (optional)", SUMMARY: { - TITLE: "Registration number (optional)" - } + TITLE: "Registration number (optional)", + FORM_TITLE: COMPANY_DETAILS + }, + MAXIMUM: MAXIMUM_CHARACTERS.BUYER.REGISTRATION_NUMBER }, [COMPANY_OR_ORGANISATION.WEBSITE]: { + LABEL: "Enter their website (optional)", SUMMARY: { - TITLE: "Buyer website (optional)" + TITLE: "Buyer website (optional)", + FORM_TITLE: COMPANY_DETAILS } } }, [CONNECTION_WITH_BUYER]: { + LABEL: "Are you connected with the buyer in any way?", + HINT: "For example, someone in your company is a shareholder or director of the buyer's company.", + SUMMARY: { + TITLE: "Connected with the buyer", + FORM_TITLE: CONNECTION_TO_BUYER + } + }, + [CONNECTION_WITH_BUYER_DESCRIPTION]: { + LABEL: "Describe the connection with the buyer", + MAXIMUM: MAXIMUM_CHARACTERS.CONNECTION_WITH_BUYER_DESCRIPTION, SUMMARY: { - TITLE: "Connected with the buyer in any way?" + TITLE: "Details of connection", + FORM_TITLE: CONNECTION_TO_BUYER } }, [TRADED_WITH_BUYER]: { + LABEL: "Have you traded with this buyer before?", + HINT: "If yes, we will request a copy of your trading history once the application has been submitted.", + SUMMARY: { + TITLE: "Trading history", + FORM_TITLE: TRADING_HISTORY + } + }, + [OUTSTANDING_PAYMENTS]: { + LABEL: "Do you currently have any outstanding or overdue payments from the buyer?", SUMMARY: { - TITLE: "Have you traded with this buyer before?" + TITLE: "Outstanding or overdue payments", + FORM_TITLE: TRADING_HISTORY + } + }, + [FAILED_PAYMENTS]: { + LABEL: "Has the buyer ever failed to pay you on time?", + SUMMARY: { + TITLE: "Buyer failed to pay on time?", + FORM_TITLE: TRADING_HISTORY + } + }, + [CURRENCY_CODE]: { + LEGEND: "What currency are the outstanding or overdue payments in?" + }, + [HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]: { + LABEL: "Have you in the past held credit insurance cover on the buyer?", + SUMMARY: { + TITLE: "Credit insurance previously held for the buyer", + FORM_TITLE: CREDIT_INSURANCE_HISTORY + } + }, + [PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]: { + LABEL: "Tell us about the credit insurance cover you had on the buyer", + HINT: "Include the name of the insurer(s) and the credit limit.", + SUMMARY: { + TITLE: "Details of credit insurance", + FORM_TITLE: CREDIT_INSURANCE_HISTORY + }, + MAXIMUM: MAXIMUM_CHARACTERS.BUYER.PREVIOUS_CREDIT_INSURANCE_COVER + }, + [TOTAL_OUTSTANDING_PAYMENTS]: { + HEADING: "Tell us about the outstanding or overdue payments", + LABEL: "Total outstanding, including overdue", + SUMMARY: { + TITLE: "Total outstanding including overdue", + FORM_TITLE: TRADING_HISTORY + } + }, + [TOTAL_AMOUNT_OVERDUE]: { + LABEL: "Amount overdue", + SUMMARY: { + TITLE: "Amount overdue", + FORM_TITLE: TRADING_HISTORY + } + }, + [HAS_BUYER_FINANCIAL_ACCOUNTS]: { + SUMMARY: { + TITLE: "Financial accounts relating to the buyer", + FORM_TITLE: FINANCIAL_ACCOUNTS } } }; @@ -5570,7 +5782,17 @@ var { BROKER_DETAILS: { NAME: BROKER_NAME, EMAIL: BROKER_EMAIL, FULL_ADDRESS: BROKER_ADDRESS } }, YOUR_BUYER: { - COMPANY_OR_ORGANISATION: { COUNTRY, NAME: BUYER_COMPANY_NAME, REGISTRATION_NUMBER: BUYER_REGISTRATION_NUMBER, FIRST_NAME: BUYER_CONTACT_DETAILS } + COMPANY_OR_ORGANISATION: { COUNTRY, NAME: BUYER_COMPANY_NAME, REGISTRATION_NUMBER: BUYER_REGISTRATION_NUMBER, FIRST_NAME: BUYER_CONTACT_DETAILS }, + CONNECTION_WITH_BUYER: CONNECTION_WITH_BUYER2, + CONNECTION_WITH_BUYER_DESCRIPTION: CONNECTION_WITH_BUYER_DESCRIPTION2, + FAILED_PAYMENTS: FAILED_PAYMENTS2, + HAS_BUYER_FINANCIAL_ACCOUNTS: HAS_BUYER_FINANCIAL_ACCOUNTS2, + HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER2, + OUTSTANDING_PAYMENTS: OUTSTANDING_PAYMENTS2, + PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER2, + TOTAL_AMOUNT_OVERDUE: TOTAL_AMOUNT_OVERDUE2, + TOTAL_OUTSTANDING_PAYMENTS: TOTAL_OUTSTANDING_PAYMENTS2, + TRADED_WITH_BUYER: TRADED_WITH_BUYER2 } } = insurance_default; var XLSX = { @@ -5619,9 +5841,18 @@ var XLSX = { [BROKER_ADDRESS]: "Broker address", [BROKER_EMAIL]: "Broker email address", [COUNTRY]: "Buyer location", - [BUYER_COMPANY_NAME]: "Buyer company name", + [BUYER_COMPANY_NAME]: "Buyer company name or organisation", [BUYER_REGISTRATION_NUMBER]: "Buyer registration number (optional)", [BUYER_CONTACT_DETAILS]: "Buyer contact details", + [CONNECTION_WITH_BUYER2]: "Is the exporter connected with the buyer in any way?", + [CONNECTION_WITH_BUYER_DESCRIPTION2]: "Describe connection to the buyer", + [TRADED_WITH_BUYER2]: "Has the exporter traded with this buyer before?", + [FAILED_PAYMENTS2]: "Has the buyer ever failed to pay the exporter on time", + [HAS_BUYER_FINANCIAL_ACCOUNTS2]: "Does the exporter hold any financial accounts in relation to the buyer?", + [HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER2]: "If the exporter has in past held credit insurance cover on the buyer", + [OUTSTANDING_PAYMENTS2]: "Does the exporter currently have any outstanding or overdue payments from the buyer", + [PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER2]: "Exporter explaining the credit insurance cover they had on the buyer", + [TOTAL_OUTSTANDING_PAYMENTS2]: "Total outstanding payments", NO_FINANCIAL_YEAR_END_DATE: "No data from Companies House" } }; @@ -5796,13 +6027,16 @@ var mapPolicy = (application2) => { var map_policy_default = mapPolicy; // generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.ts -var mapYesNoField = (answer) => { +var mapYesNoField = (answer, defaultValue) => { if (answer === false) { return "No"; } if (answer === true) { return "Yes"; } + if (defaultValue) { + return defaultValue; + } return DEFAULT.EMPTY; }; var map_yes_no_field_default = mapYesNoField; @@ -5941,20 +6175,73 @@ var CONTENT_STRINGS4 = { ...YOUR_BUYER_FIELDS }; var { - COMPANY_OR_ORGANISATION: { NAME: NAME2, ADDRESS, COUNTRY: COUNTRY3, REGISTRATION_NUMBER, WEBSITE: WEBSITE4 }, - CONNECTION_WITH_BUYER: CONNECTION_WITH_BUYER2, - TRADED_WITH_BUYER: TRADED_WITH_BUYER2 -} = your_buyer_default; + CURRENCY: { CURRENCY_CODE: CURRENCY_CODE2 }, + YOUR_BUYER: { + COMPANY_OR_ORGANISATION: { NAME: NAME2, ADDRESS, COUNTRY: COUNTRY3, REGISTRATION_NUMBER, WEBSITE: WEBSITE4 }, + CONNECTION_WITH_BUYER: CONNECTION_WITH_BUYER3, + CONNECTION_WITH_BUYER_DESCRIPTION: CONNECTION_WITH_BUYER_DESCRIPTION3, + FAILED_PAYMENTS: FAILED_PAYMENTS3, + HAS_BUYER_FINANCIAL_ACCOUNTS: HAS_BUYER_FINANCIAL_ACCOUNTS3, + HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3, + OUTSTANDING_PAYMENTS: OUTSTANDING_PAYMENTS3, + PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3, + TRADED_WITH_BUYER: TRADED_WITH_BUYER3, + TOTAL_OUTSTANDING_PAYMENTS: TOTAL_OUTSTANDING_PAYMENTS3, + TOTAL_AMOUNT_OVERDUE: TOTAL_AMOUNT_OVERDUE3 + } +} = insurance_default; +var { SECTION_TITLES: SECTION_TITLES2, FIELDS: FIELDS10 } = XLSX; var mapBuyer = (application2) => { const { buyer } = application2; - const mapped = [ - xlsx_row_default(XLSX.SECTION_TITLES.BUYER, ""), - xlsx_row_default(XLSX.FIELDS[NAME2], buyer[NAME2]), + console.log(">>>>>>>> buyer ", buyer); + const { buyerTradingHistory, relationship: relationship2 } = buyer; + let mapped = [ + xlsx_row_default(SECTION_TITLES2.BUYER, ""), + xlsx_row_default(FIELDS10[NAME2], buyer[NAME2]), xlsx_row_default(String(CONTENT_STRINGS4[ADDRESS].SUMMARY?.TITLE), `${buyer[ADDRESS]} ${xlsx_new_line_default}${buyer[COUNTRY3].name}`), - xlsx_row_default(XLSX.FIELDS[REGISTRATION_NUMBER], buyer[REGISTRATION_NUMBER]), + xlsx_row_default(FIELDS10[REGISTRATION_NUMBER], buyer[REGISTRATION_NUMBER]), xlsx_row_default(String(CONTENT_STRINGS4[WEBSITE4].SUMMARY?.TITLE), buyer[WEBSITE4]), - xlsx_row_default(String(CONTENT_STRINGS4[CONNECTION_WITH_BUYER2].SUMMARY?.TITLE), map_yes_no_field_default(buyer[CONNECTION_WITH_BUYER2])), - xlsx_row_default(String(CONTENT_STRINGS4[TRADED_WITH_BUYER2].SUMMARY?.TITLE), map_yes_no_field_default(buyer[TRADED_WITH_BUYER2])) + xlsx_row_default(String(FIELDS10[CONNECTION_WITH_BUYER3]), map_yes_no_field_default(relationship2[CONNECTION_WITH_BUYER3])) + ]; + if (relationship2[CONNECTION_WITH_BUYER3]) { + mapped.push( + xlsx_row_default(String(FIELDS10[CONNECTION_WITH_BUYER_DESCRIPTION3]), relationship2[CONNECTION_WITH_BUYER_DESCRIPTION3]) + ); + } + mapped = [ + ...mapped, + xlsx_row_default(String(FIELDS10[TRADED_WITH_BUYER3]), map_yes_no_field_default(buyerTradingHistory[TRADED_WITH_BUYER3])) + ]; + if (buyerTradingHistory[TRADED_WITH_BUYER3]) { + mapped.push( + xlsx_row_default(String(FIELDS10[OUTSTANDING_PAYMENTS3]), map_yes_no_field_default(buyerTradingHistory[OUTSTANDING_PAYMENTS3])) + ); + if (buyerTradingHistory[OUTSTANDING_PAYMENTS3]) { + const totalOutstandingPaymentsValue = format_currency_default2(buyerTradingHistory[TOTAL_OUTSTANDING_PAYMENTS3], buyerTradingHistory[CURRENCY_CODE2]); + mapped.push( + xlsx_row_default(String(FIELDS10[TOTAL_OUTSTANDING_PAYMENTS3]), totalOutstandingPaymentsValue) + ); + const totalAmountOverdueValue = format_currency_default2(buyerTradingHistory[TOTAL_AMOUNT_OVERDUE3], buyerTradingHistory[CURRENCY_CODE2]); + mapped.push( + xlsx_row_default(String(CONTENT_STRINGS4[TOTAL_AMOUNT_OVERDUE3].SUMMARY?.TITLE), totalAmountOverdueValue) + ); + } + mapped.push( + xlsx_row_default(String(FIELDS10[FAILED_PAYMENTS3]), map_yes_no_field_default(buyerTradingHistory[FAILED_PAYMENTS3])) + ); + } + mapped = [ + ...mapped, + xlsx_row_default(String(FIELDS10[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3]), map_yes_no_field_default(relationship2[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3], "No")) + ]; + if (relationship2[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3]) { + mapped.push( + xlsx_row_default(String(FIELDS10[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3]), relationship2[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3]) + ); + } + mapped = [ + ...mapped, + xlsx_row_default(String(FIELDS10[HAS_BUYER_FINANCIAL_ACCOUNTS3]), map_yes_no_field_default(relationship2[HAS_BUYER_FINANCIAL_ACCOUNTS3])) ]; return mapped; }; @@ -5962,7 +6249,7 @@ var map_buyer_default = mapBuyer; // generate-xlsx/map-application-to-XLSX/map-eligibility/index.ts var { MORE_THAN_250K: MORE_THAN_250K2 } = TOTAL_CONTRACT_VALUE; -var { FIELDS: FIELDS10, SECTION_TITLES: SECTION_TITLES2 } = XLSX; +var { FIELDS: FIELDS11, SECTION_TITLES: SECTION_TITLES3 } = XLSX; var { ELIGIBILITY: { BUYER_COUNTRY: BUYER_COUNTRY3, @@ -5979,15 +6266,15 @@ var { var mapEligibility = (application2) => { const { company, eligibility } = application2; const mapped = [ - xlsx_row_default(SECTION_TITLES2.ELIGIBILITY, ""), + xlsx_row_default(SECTION_TITLES3.ELIGIBILITY, ""), xlsx_row_default(FIELDS_ELIGIBILITY[VALID_EXPORTER_LOCATION2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[VALID_EXPORTER_LOCATION2])), xlsx_row_default(FIELDS_ELIGIBILITY[HAS_COMPANIES_HOUSE_NUMBER2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[HAS_COMPANIES_HOUSE_NUMBER2])), - xlsx_row_default(FIELDS10[COMPANIES_HOUSE_NUMBER3], company[COMPANIES_HOUSE_NUMBER3]), - xlsx_row_default(FIELDS10[BUYER_COUNTRY3], eligibility[BUYER_COUNTRY3].name), - xlsx_row_default(FIELDS10[MORE_THAN_250K2.VALUE], map_yes_no_field_default(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID)), - xlsx_row_default(FIELDS10[COVER_PERIOD3], eligibility[COVER_PERIOD_ELIGIBILITY].value), - xlsx_row_default(FIELDS10[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3])), - xlsx_row_default(FIELDS10[HAS_END_BUYER3], map_yes_no_field_default(eligibility[HAS_END_BUYER3])) + xlsx_row_default(FIELDS11[COMPANIES_HOUSE_NUMBER3], company[COMPANIES_HOUSE_NUMBER3]), + xlsx_row_default(FIELDS11[BUYER_COUNTRY3], eligibility[BUYER_COUNTRY3].name), + xlsx_row_default(FIELDS11[MORE_THAN_250K2.VALUE], map_yes_no_field_default(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID)), + xlsx_row_default(FIELDS11[COVER_PERIOD3], eligibility[COVER_PERIOD_ELIGIBILITY].value), + xlsx_row_default(FIELDS11[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3])), + xlsx_row_default(FIELDS11[HAS_END_BUYER3], map_yes_no_field_default(eligibility[HAS_END_BUYER3])) ]; return mapped; }; diff --git a/src/api/constants/XLSX-CONFIG/INDEXES/index.ts b/src/api/constants/XLSX-CONFIG/INDEXES/index.ts index 479e4b3355..b04b619717 100644 --- a/src/api/constants/XLSX-CONFIG/INDEXES/index.ts +++ b/src/api/constants/XLSX-CONFIG/INDEXES/index.ts @@ -14,7 +14,7 @@ export const TITLE_INDEXES = () => EXPORTER_BUSINESS: 31, POLICY: 48, BUYER: 57, - DECLARATIONS: 65, + DECLARATIONS: 67, }) as XLSXTitleRowIndexes; /** diff --git a/src/api/constants/XLSX-CONFIG/index.ts b/src/api/constants/XLSX-CONFIG/index.ts index 62539edfde..cdc3439d4c 100644 --- a/src/api/constants/XLSX-CONFIG/index.ts +++ b/src/api/constants/XLSX-CONFIG/index.ts @@ -20,9 +20,19 @@ const { * @returns {XLSXRowIndexes} */ +// TODO - updates +// - 3 extra fields regardless +// - if connected with buyer, +1 row +// - if traded with buyer, +4 rows +// - if has previous credit insurance cover with buyer, +1 row + export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { const { broker, + buyer: { + buyerTradingHistory: { exporterHasTradedWithBuyer, outstandingPayments: buyerHasOutstandingPayments }, + relationship: { exporterIsConnectedWithBuyer, exporterHasPreviousCreditInsuranceWithBuyer }, + }, company: { differentTradingAddress: { fullAddress: hasDifferentTradingAddress }, hasDifferentTradingName, @@ -44,7 +54,7 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { if (broker[USING_BROKER]) { indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; - indexes.TITLES.DECLARATIONS += 3; + indexes.TITLES.DECLARATIONS += 6; indexes.BUYER_ADDRESS += 3; indexes.BROKER_ADDRESS = 48; @@ -53,6 +63,8 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { if (hasDifferentTradingAddress) { indexes.ALTERNATIVE_TRADING_ADDRESS = 37; + // TODO: after other sections are complete, rename incrementIndexes? + // incrementIndexes is only applicable to certain fields/sections. indexes = incrementIndexes(indexes); } @@ -64,6 +76,22 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { indexes.ALTERNATIVE_TRADING_ADDRESS = 38; } + if (exporterIsConnectedWithBuyer) { + indexes.TITLES.DECLARATIONS += 1; + } + + if (exporterHasTradedWithBuyer) { + indexes.TITLES.DECLARATIONS += 2; + + if (buyerHasOutstandingPayments) { + indexes.TITLES.DECLARATIONS += 2; + } + } + + if (exporterHasPreviousCreditInsuranceWithBuyer) { + indexes.TITLES.DECLARATIONS += 1; + } + return indexes; }; diff --git a/src/api/constants/field-ids/insurance/index.ts b/src/api/constants/field-ids/insurance/index.ts index 9a486fb315..841f0dfce1 100644 --- a/src/api/constants/field-ids/insurance/index.ts +++ b/src/api/constants/field-ids/insurance/index.ts @@ -23,6 +23,10 @@ const INSURANCE_FIELD_IDS = { HAS_REVIEWED_ELIGIBILITY: 'hasReviewedEligibility', }, ...SHARED_FIELD_IDS, + CURRENCY: { + CURRENCY_CODE: 'currencyCode', + ALTERNATIVE_CURRENCY_CODE: 'alternativeCurrencyCode', + }, SUBMISSION_DEADLINE: 'submissionDeadline', ACCOUNT, POLICY, diff --git a/src/api/constants/field-ids/insurance/your-buyer/index.ts b/src/api/constants/field-ids/insurance/your-buyer/index.ts index f141f27ad5..4b62f6da94 100644 --- a/src/api/constants/field-ids/insurance/your-buyer/index.ts +++ b/src/api/constants/field-ids/insurance/your-buyer/index.ts @@ -9,6 +9,13 @@ const YOUR_BUYER = { CONNECTION_WITH_BUYER: 'exporterIsConnectedWithBuyer', CONNECTION_WITH_BUYER_DESCRIPTION: 'connectionWithBuyerDescription', TRADED_WITH_BUYER: 'exporterHasTradedWithBuyer', + OUTSTANDING_PAYMENTS: 'outstandingPayments', + TOTAL_OUTSTANDING_PAYMENTS: 'totalOutstandingPayments', + TOTAL_AMOUNT_OVERDUE: 'totalOverduePayments', + FAILED_PAYMENTS: 'failedPayments', + HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: 'exporterHasPreviousCreditInsuranceWithBuyer', + PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: 'previousCreditInsuranceWithBuyerDescription', + HAS_BUYER_FINANCIAL_ACCOUNTS: 'exporterHasBuyerFinancialAccounts', }; export default YOUR_BUYER; diff --git a/src/api/constants/index.ts b/src/api/constants/index.ts index 991b52f8f0..70f919d842 100644 --- a/src/api/constants/index.ts +++ b/src/api/constants/index.ts @@ -12,6 +12,7 @@ export * from './field-values'; export * from './supported-currencies'; export * from './total-contract-value'; export * from './XLSX-CONFIG'; +export * from './validation'; dotenv.config(); diff --git a/src/api/constants/validation.ts b/src/api/constants/validation.ts new file mode 100644 index 0000000000..3ad7fa15eb --- /dev/null +++ b/src/api/constants/validation.ts @@ -0,0 +1,41 @@ +export const MINIMUM_CHARACTERS = { + ZERO: 0, + ONE: 1, + SORT_CODE: 6, + ACCOUNT_NUMBER: 6, + BIC_SWIFT_CODE: 8, + IBAN: 16, +}; + +export const MAXIMUM_CHARACTERS = { + ABOUT_GOODS_OR_SERVICES_DESCRIPTION: 1000, + ACCOUNT_NUMBER: 8, + AGENT_NAME: 800, + AGENT_SERVICE_DESCRIPTION: 1000, + BIC_SWIFT_CODE: 11, + BROKER_NAME: 800, + BUSINESS: { + GOODS_OR_SERVICES_DESCRIPTION: 1000, + }, + BUYER: { + COMPANY_OR_ORGANISATION: 200, + REGISTRATION_NUMBER: 200, + PREVIOUS_CREDIT_INSURANCE_COVER: 1000, + }, + COMPANY_DIFFERENT_TRADING_NAME: 200, + CONNECTION_WITH_BUYER_DESCRIPTION: 1000, + CREDIT_PERIOD_WITH_BUYER: 1000, + DECLINED_BY_PRIVATE_MARKET_DESCRIPTION: 1000, + EMAIL: 300, + FEEDBACK: { + IMPROVEMENT: 1200, + OTHER_COMMENTS: 1200, + }, + FULL_ADDRESS: 500, + IBAN: 34, + LOSS_PAYEE_NAME: 200, + PAYMENT_TERMS_DESCRIPTION: 1000, + PERCENTAGE: 100, + POLICY_CONTACT_NAME: 400, + SORT_CODE: 6, +}; diff --git a/src/api/content-strings/XLSX.ts b/src/api/content-strings/XLSX.ts index 47be3c973d..9fc45cf535 100644 --- a/src/api/content-strings/XLSX.ts +++ b/src/api/content-strings/XLSX.ts @@ -25,6 +25,15 @@ const { }, YOUR_BUYER: { COMPANY_OR_ORGANISATION: { COUNTRY, NAME: BUYER_COMPANY_NAME, REGISTRATION_NUMBER: BUYER_REGISTRATION_NUMBER, FIRST_NAME: BUYER_CONTACT_DETAILS }, + CONNECTION_WITH_BUYER, + CONNECTION_WITH_BUYER_DESCRIPTION, + FAILED_PAYMENTS, + HAS_BUYER_FINANCIAL_ACCOUNTS, + HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, + OUTSTANDING_PAYMENTS, + PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, + TOTAL_OUTSTANDING_PAYMENTS, + TRADED_WITH_BUYER, }, } = INSURANCE_FIELD_IDS; @@ -81,9 +90,18 @@ export const XLSX = { [BROKER_ADDRESS]: 'Broker address', [BROKER_EMAIL]: 'Broker email address', [COUNTRY]: 'Buyer location', - [BUYER_COMPANY_NAME]: 'Buyer company name', + [BUYER_COMPANY_NAME]: 'Buyer company name or organisation', [BUYER_REGISTRATION_NUMBER]: 'Buyer registration number (optional)', [BUYER_CONTACT_DETAILS]: 'Buyer contact details', + [CONNECTION_WITH_BUYER]: 'Is the exporter connected with the buyer in any way?', + [CONNECTION_WITH_BUYER_DESCRIPTION]: 'Describe connection to the buyer', + [TRADED_WITH_BUYER]: 'Has the exporter traded with this buyer before?', + [FAILED_PAYMENTS]: 'Has the buyer ever failed to pay the exporter on time', + [HAS_BUYER_FINANCIAL_ACCOUNTS]: 'Does the exporter hold any financial accounts in relation to the buyer?', + [HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]: 'If the exporter has in past held credit insurance cover on the buyer', + [OUTSTANDING_PAYMENTS]: 'Does the exporter currently have any outstanding or overdue payments from the buyer', + [PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]: 'Exporter explaining the credit insurance cover they had on the buyer', + [TOTAL_OUTSTANDING_PAYMENTS]: 'Total outstanding payments', NO_FINANCIAL_YEAR_END_DATE: 'No data from Companies House', }, }; diff --git a/src/api/content-strings/fields/insurance/your-buyer/index.ts b/src/api/content-strings/fields/insurance/your-buyer/index.ts index a64a565fd6..6a1bd750e3 100644 --- a/src/api/content-strings/fields/insurance/your-buyer/index.ts +++ b/src/api/content-strings/fields/insurance/your-buyer/index.ts @@ -1,43 +1,142 @@ -import FIELD_IDS from '../../../../constants/field-ids/insurance'; +import { FIELD_IDS, MAXIMUM_CHARACTERS } from '../../../../constants'; +import { FORM_TITLES } from '../../../form-titles'; const { - YOUR_BUYER: { COMPANY_OR_ORGANISATION, CONNECTION_WITH_BUYER, TRADED_WITH_BUYER }, -} = FIELD_IDS; + YOUR_BUYER: { + COMPANY_OR_ORGANISATION, + CONNECTION_WITH_BUYER, + TRADED_WITH_BUYER, + CONNECTION_WITH_BUYER_DESCRIPTION, + OUTSTANDING_PAYMENTS, + FAILED_PAYMENTS, + HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, + PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, + TOTAL_OUTSTANDING_PAYMENTS, + TOTAL_AMOUNT_OVERDUE, + HAS_BUYER_FINANCIAL_ACCOUNTS, + }, + CURRENCY: { CURRENCY_CODE }, +} = FIELD_IDS.INSURANCE; + +const { + YOUR_BUYER: { COMPANY_DETAILS, TRADING_HISTORY, CONNECTION_TO_BUYER, CREDIT_INSURANCE_HISTORY, FINANCIAL_ACCOUNTS }, +} = FORM_TITLES; export const YOUR_BUYER_FIELDS = { COMPANY_OR_ORGANISATION: { [COMPANY_OR_ORGANISATION.NAME]: { + LABEL: "Buyer's company or organisation name", SUMMARY: { TITLE: 'Company or organisation name', + FORM_TITLE: COMPANY_DETAILS, }, }, [COMPANY_OR_ORGANISATION.ADDRESS]: { + LABEL: 'Company address', SUMMARY: { TITLE: 'Buyer address', + FORM_TITLE: COMPANY_DETAILS, }, + MAXIMUM: MAXIMUM_CHARACTERS.FULL_ADDRESS, }, [COMPANY_OR_ORGANISATION.COUNTRY]: { - LABEL: 'Country', + LABEL: 'Buyer country', + SUMMARY: { + TITLE: 'Buyer country', + }, }, [COMPANY_OR_ORGANISATION.REGISTRATION_NUMBER]: { + LABEL: 'Company registration number (optional)', SUMMARY: { TITLE: 'Registration number (optional)', + FORM_TITLE: COMPANY_DETAILS, }, + MAXIMUM: MAXIMUM_CHARACTERS.BUYER.REGISTRATION_NUMBER, }, [COMPANY_OR_ORGANISATION.WEBSITE]: { + LABEL: 'Enter their website (optional)', SUMMARY: { TITLE: 'Buyer website (optional)', + FORM_TITLE: COMPANY_DETAILS, }, }, }, [CONNECTION_WITH_BUYER]: { + LABEL: 'Are you connected with the buyer in any way?', + HINT: "For example, someone in your company is a shareholder or director of the buyer's company.", + SUMMARY: { + TITLE: 'Connected with the buyer', + FORM_TITLE: CONNECTION_TO_BUYER, + }, + }, + [CONNECTION_WITH_BUYER_DESCRIPTION]: { + LABEL: 'Describe the connection with the buyer', + MAXIMUM: MAXIMUM_CHARACTERS.CONNECTION_WITH_BUYER_DESCRIPTION, SUMMARY: { - TITLE: 'Connected with the buyer in any way?', + TITLE: 'Details of connection', + FORM_TITLE: CONNECTION_TO_BUYER, }, }, [TRADED_WITH_BUYER]: { + LABEL: 'Have you traded with this buyer before?', + HINT: 'If yes, we will request a copy of your trading history once the application has been submitted.', + SUMMARY: { + TITLE: 'Trading history', + FORM_TITLE: TRADING_HISTORY, + }, + }, + [OUTSTANDING_PAYMENTS]: { + LABEL: 'Do you currently have any outstanding or overdue payments from the buyer?', + SUMMARY: { + TITLE: 'Outstanding or overdue payments', + FORM_TITLE: TRADING_HISTORY, + }, + }, + [FAILED_PAYMENTS]: { + LABEL: 'Has the buyer ever failed to pay you on time?', + SUMMARY: { + TITLE: 'Buyer failed to pay on time?', + FORM_TITLE: TRADING_HISTORY, + }, + }, + [CURRENCY_CODE]: { + LEGEND: 'What currency are the outstanding or overdue payments in?', + }, + [HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]: { + LABEL: 'Have you in the past held credit insurance cover on the buyer?', + SUMMARY: { + TITLE: 'Credit insurance previously held for the buyer', + FORM_TITLE: CREDIT_INSURANCE_HISTORY, + }, + }, + [PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]: { + LABEL: 'Tell us about the credit insurance cover you had on the buyer', + HINT: 'Include the name of the insurer(s) and the credit limit.', + SUMMARY: { + TITLE: 'Details of credit insurance', + FORM_TITLE: CREDIT_INSURANCE_HISTORY, + }, + MAXIMUM: MAXIMUM_CHARACTERS.BUYER.PREVIOUS_CREDIT_INSURANCE_COVER, + }, + [TOTAL_OUTSTANDING_PAYMENTS]: { + HEADING: 'Tell us about the outstanding or overdue payments', + LABEL: 'Total outstanding, including overdue', + SUMMARY: { + TITLE: 'Total outstanding including overdue', + FORM_TITLE: TRADING_HISTORY, + }, + }, + [TOTAL_AMOUNT_OVERDUE]: { + LABEL: 'Amount overdue', + SUMMARY: { + TITLE: 'Amount overdue', + FORM_TITLE: TRADING_HISTORY, + }, + }, + [HAS_BUYER_FINANCIAL_ACCOUNTS]: { SUMMARY: { - TITLE: 'Have you traded with this buyer before?', + TITLE: 'Financial accounts relating to the buyer', + FORM_TITLE: FINANCIAL_ACCOUNTS, }, }, }; diff --git a/src/api/content-strings/form-titles.ts b/src/api/content-strings/form-titles.ts new file mode 100644 index 0000000000..72a8338475 --- /dev/null +++ b/src/api/content-strings/form-titles.ts @@ -0,0 +1,27 @@ +export const FORM_TITLES = { + YOUR_BUSINESS: { + COMPANY_DETAILS: 'Company details', + NATURE_OF_BUSINESS: 'Nature of your business', + TURNOVER: 'Turnover', + CREDIT_CONTROL: 'Credit control', + }, + YOUR_BUYER: { + COMPANY_DETAILS: 'Company details', + CONNECTION_TO_BUYER: 'Connection to the buyer', + TRADING_HISTORY: 'Trading history', + CREDIT_INSURANCE_HISTORY: 'Credit insurance history', + FINANCIAL_ACCOUNTS: 'Financial accounts', + }, + POLICY: { + CONTRACT_POLICY: 'Requested insurance policy', + NAME_ON_POLICY: 'Named person on the policy', + BROKER: 'Broker', + OTHER_COMPANY: 'Other company to be insured', + LOSS_PAYEE: 'Loss payee', + }, + EXPORT_CONTRACT: { + ABOUT_THE_EXPORT: 'About the export', + PRIVATE_MARKET: 'Private insurance market', + AGENT: 'Agent', + }, +}; diff --git a/src/api/emails/application/index.ts b/src/api/emails/application/index.ts index 3ec532342f..cb4bb7a584 100644 --- a/src/api/emails/application/index.ts +++ b/src/api/emails/application/index.ts @@ -54,7 +54,7 @@ const application = { * NOTE: no need to handle an error from fs.unlink here. * If this errors, it will go into the catch handler below. */ - await fileSystem.unlink(filePath); + // await fileSystem.unlink(filePath); return response; } diff --git a/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.ts index 3ed251f407..729ccbaceb 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.ts @@ -1,12 +1,14 @@ import { DEFAULT } from '../../../../content-strings'; +// TODO: object structured +// TODO: yes/no values as content strings. /** * mapYesNoField * Map a "true" or "false" field to Yes/No * @param {Boolean} answer * @returns {String} "Yes/No" or DEFAULT.EMPTY */ -const mapYesNoField = (answer?: boolean) => { +const mapYesNoField = (answer?: boolean, defaultValue?: string) => { if (answer === false) { return 'No'; } @@ -15,6 +17,10 @@ const mapYesNoField = (answer?: boolean) => { return 'Yes'; } + if (defaultValue) { + return defaultValue; + } + return DEFAULT.EMPTY; }; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts index 72c9284c16..fa186943ad 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts @@ -1,9 +1,10 @@ -import FIELD_IDS from '../../../constants/field-ids/insurance/your-buyer'; +import INSURANCE_FIELD_IDS from '../../../constants/field-ids/insurance'; import { XLSX } from '../../../content-strings'; import { YOUR_BUYER_FIELDS } from '../../../content-strings/fields/insurance/your-buyer'; import xlsxRow from '../helpers/xlsx-row'; import NEW_LINE from '../helpers/xlsx-new-line'; import mapYesNoField from '../helpers/map-yes-no-field'; +import formatCurrency from '../helpers/format-currency'; import { Application } from '../../../types'; const CONTENT_STRINGS = { @@ -12,10 +13,23 @@ const CONTENT_STRINGS = { }; const { - COMPANY_OR_ORGANISATION: { NAME, ADDRESS, COUNTRY, REGISTRATION_NUMBER, WEBSITE }, - CONNECTION_WITH_BUYER, - TRADED_WITH_BUYER, -} = FIELD_IDS; + CURRENCY: { CURRENCY_CODE }, + YOUR_BUYER: { + COMPANY_OR_ORGANISATION: { NAME, ADDRESS, COUNTRY, REGISTRATION_NUMBER, WEBSITE }, + CONNECTION_WITH_BUYER, + CONNECTION_WITH_BUYER_DESCRIPTION, + FAILED_PAYMENTS, + HAS_BUYER_FINANCIAL_ACCOUNTS, + HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, + OUTSTANDING_PAYMENTS, + PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, + TRADED_WITH_BUYER, + TOTAL_OUTSTANDING_PAYMENTS, + TOTAL_AMOUNT_OVERDUE, + }, +} = INSURANCE_FIELD_IDS; + +const { SECTION_TITLES, FIELDS } = XLSX; /** * mapBuyer @@ -26,16 +40,50 @@ const { const mapBuyer = (application: Application) => { const { buyer } = application; - const mapped = [ - xlsxRow(XLSX.SECTION_TITLES.BUYER, ''), - xlsxRow(XLSX.FIELDS[NAME], buyer[NAME]), + const { buyerTradingHistory, relationship } = buyer; + + let mapped = [ + xlsxRow(SECTION_TITLES.BUYER, ''), + xlsxRow(FIELDS[NAME], buyer[NAME]), xlsxRow(String(CONTENT_STRINGS[ADDRESS].SUMMARY?.TITLE), `${buyer[ADDRESS]} ${NEW_LINE}${buyer[COUNTRY].name}`), - xlsxRow(XLSX.FIELDS[REGISTRATION_NUMBER], buyer[REGISTRATION_NUMBER]), + xlsxRow(FIELDS[REGISTRATION_NUMBER], buyer[REGISTRATION_NUMBER]), xlsxRow(String(CONTENT_STRINGS[WEBSITE].SUMMARY?.TITLE), buyer[WEBSITE]), - xlsxRow(String(CONTENT_STRINGS[CONNECTION_WITH_BUYER].SUMMARY?.TITLE), mapYesNoField(buyer[CONNECTION_WITH_BUYER])), - xlsxRow(String(CONTENT_STRINGS[TRADED_WITH_BUYER].SUMMARY?.TITLE), mapYesNoField(buyer[TRADED_WITH_BUYER])), + xlsxRow(String(FIELDS[CONNECTION_WITH_BUYER]), mapYesNoField(relationship[CONNECTION_WITH_BUYER])), + ]; + + if (relationship[CONNECTION_WITH_BUYER]) { + mapped.push(xlsxRow(String(FIELDS[CONNECTION_WITH_BUYER_DESCRIPTION]), relationship[CONNECTION_WITH_BUYER_DESCRIPTION])); + } + + mapped = [...mapped, xlsxRow(String(FIELDS[TRADED_WITH_BUYER]), mapYesNoField(buyerTradingHistory[TRADED_WITH_BUYER]))]; + + if (buyerTradingHistory[TRADED_WITH_BUYER]) { + mapped.push(xlsxRow(String(FIELDS[OUTSTANDING_PAYMENTS]), mapYesNoField(buyerTradingHistory[OUTSTANDING_PAYMENTS]))); + + if (buyerTradingHistory[OUTSTANDING_PAYMENTS]) { + const totalOutstandingPaymentsValue = formatCurrency(buyerTradingHistory[TOTAL_OUTSTANDING_PAYMENTS], buyerTradingHistory[CURRENCY_CODE]); + + mapped.push(xlsxRow(String(FIELDS[TOTAL_OUTSTANDING_PAYMENTS]), totalOutstandingPaymentsValue)); + + const totalAmountOverdueValue = formatCurrency(buyerTradingHistory[TOTAL_AMOUNT_OVERDUE], buyerTradingHistory[CURRENCY_CODE]); + + mapped.push(xlsxRow(String(CONTENT_STRINGS[TOTAL_AMOUNT_OVERDUE].SUMMARY?.TITLE), totalAmountOverdueValue)); + } + + mapped.push(xlsxRow(String(FIELDS[FAILED_PAYMENTS]), mapYesNoField(buyerTradingHistory[FAILED_PAYMENTS]))); + } + + mapped = [ + ...mapped, + xlsxRow(String(FIELDS[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]), mapYesNoField(relationship[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER], 'No')), ]; + if (relationship[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]) { + mapped.push(xlsxRow(String(FIELDS[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]), relationship[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER])); + } + + mapped = [...mapped, xlsxRow(String(FIELDS[HAS_BUYER_FINANCIAL_ACCOUNTS]), mapYesNoField(relationship[HAS_BUYER_FINANCIAL_ACCOUNTS]))]; + return mapped; }; diff --git a/src/api/helpers/get-populated-application/index.test.ts b/src/api/helpers/get-populated-application/index.test.ts index 140313b32b..e78781d6a9 100644 --- a/src/api/helpers/get-populated-application/index.test.ts +++ b/src/api/helpers/get-populated-application/index.test.ts @@ -46,7 +46,7 @@ describe('api/helpers/get-populated-application', () => { expect(result.business.id).toEqual(application.business.id); expect(result.broker.id).toEqual(application.broker.id); - expect(result.buyer.id).toEqual(application.buyer.id); + // expect(result.buyer.id).toEqual(application.buyer.id); expect(result.declaration.id).toEqual(application.declaration.id); expect(result.eligibility.id).toEqual(application.eligibility.id); expect(result.eligibility.coverPeriod.id).toEqual(application.eligibility.coverPeriodId); @@ -59,13 +59,33 @@ describe('api/helpers/get-populated-application', () => { expect(result.sectionReview.id).toEqual(application.sectionReview.id); }); - it('should return an application with populated buyer country', async () => { + // it('should return an application with populated buyer country', async () => { + // const result = await getPopulatedApplication(context, applicationIds); + + // const [expectedCountry] = mockCountries; + + // expect(result.buyer.country?.name).toEqual(expectedCountry.name); + // expect(result.buyer.country?.isoCode).toEqual(expectedCountry.isoCode); + // }); + + // TODO: + // it('should return an application with populated eligibility', async () => { + + // TODO: improve test coverage. + it('should return an application with populated buyer', async () => { const result = await getPopulatedApplication(context, applicationIds); const [expectedCountry] = mockCountries; + expect(result.buyer.id).toEqual(application.buyer.id); expect(result.buyer.country?.name).toEqual(expectedCountry.name); expect(result.buyer.country?.isoCode).toEqual(expectedCountry.isoCode); + + // expect(result.buyer.relationship.id).toEqual(application.buyer.relationship.buyer.id); + expect(result.buyer.exporterIsConnectedWithBuyer).toBeNull(); + + expect(result.buyer.buyerTradingHistory.id).toEqual(application.buyer.buyerTradingHistory.id); + expect(result.buyer.buyerTradingHistory.outstandingPayments).toBeNull(); }); it('should return an application with populated company', async () => { diff --git a/src/api/helpers/get-populated-application/index.ts b/src/api/helpers/get-populated-application/index.ts index 1c5f47f10a..751e6e894e 100644 --- a/src/api/helpers/get-populated-application/index.ts +++ b/src/api/helpers/get-populated-application/index.ts @@ -157,6 +157,22 @@ const getPopulatedApplication = async (context: Context, application: KeystoneAp throw new Error(generateErrorMessage('buyer', application.id)); } + const buyerRelationship = await context.db.BuyerRelationship.findOne({ + where: { id: buyer.relationshipId }, + }); + + if (!buyerRelationship) { + throw new Error(generateErrorMessage('buyerRelationship', application.id)); + } + + const buyerTradingHistory = await context.db.BuyerTradingHistory.findOne({ + where: { id: buyer.buyerTradingHistoryId }, + }); + + if (!buyerTradingHistory) { + throw new Error(generateErrorMessage('buyerTradingHistory', application.id)); + } + const nominatedLossPayee = await context.query.NominatedLossPayee.findOne({ where: { id: nominatedLossPayeeId }, query: @@ -186,6 +202,8 @@ const getPopulatedApplication = async (context: Context, application: KeystoneAp const populatedBuyer = { ...buyer, country: buyerCountry, + relationship: buyerRelationship, + buyerTradingHistory, }; const declaration = await context.db.Declaration.findOne({ diff --git a/src/api/types/application-types/index.ts b/src/api/types/application-types/index.ts index ec3d16b37d..4f2e866248 100644 --- a/src/api/types/application-types/index.ts +++ b/src/api/types/application-types/index.ts @@ -16,7 +16,15 @@ export interface BuyerTradingHistory extends Relationship { currencyCode?: string; exporterHasTradedWithBuyer?: boolean; failedPayments?: boolean; - outstandingPayment?: boolean; + outstandingPayments?: boolean; +} + +export interface ApplicationBuyerRelationship extends Relationship { + exporterIsConnectedWithBuyer?: boolean; + connectionWithBuyerDescription?: string; + exporterHasPreviousCreditInsuranceWithBuyer?: boolean; + exporterHasBuyerFinancialAccounts?: boolean; + previousCreditInsuranceWithBuyerDescription?: string; } export interface ApplicationBuyer extends Relationship { @@ -30,8 +38,8 @@ export interface ApplicationBuyer extends Relationship { contactPosition?: string; contactEmail?: string; canContactBuyer?: boolean; - exporterIsConnectedWithBuyer?: boolean; buyerTradingHistory: BuyerTradingHistory; + relationship: ApplicationBuyerRelationship; } export interface ApplicationCompanyAddressCore { diff --git a/src/ui/server/test-mocks/mock-buyer.ts b/src/ui/server/test-mocks/mock-buyer.ts index 084189ed1e..9aa4e426f1 100644 --- a/src/ui/server/test-mocks/mock-buyer.ts +++ b/src/ui/server/test-mocks/mock-buyer.ts @@ -5,7 +5,7 @@ dotenv.config(); export const mockConnectionWithBuyer = { exporterIsConnectedWithBuyer: true, - connectionWithBuyerDescription: 'test description', + connectionWithBuyerDescription: 'Mock connection with buyer description', }; export const mockBuyerTradingHistory = { @@ -23,7 +23,7 @@ export const mockBuyerRelationship = { ...mockConnectionWithBuyer, exporterHasPreviousCreditInsuranceWithBuyer: true, exporterHasBuyerFinancialAccounts: true, - previousCreditInsuranceWithBuyerDescription: 'mock credit insurance buyer', + previousCreditInsuranceWithBuyerDescription: 'mock credit insurance with buyer description', }; export const mockBuyerContact = { From c605d2448031f5bfe6ae32b9dd8fe11eee832c64 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Wed, 29 May 2024 16:39:45 +0100 Subject: [PATCH 13/29] feat(EMS-3344): no pdf - application submission - XLSX - improve e2e test coverage --- ...policy-type-buyer-fully-populated.spec.js} | 5 ++-- ...e-connection-and-traded-with-buyer.spec.js | 28 +++++++++++++++++++ ...-policy-type-connection-with-buyer.spec.js | 26 +++++++++++++++++ ...ing-payments-failed-to-pay-on-time.spec.js | 28 +++++++++++++++++++ ...payments-not-failed-to-pay-on-time.spec.js | 28 +++++++++++++++++++ ...ing-payments-failed-to-pay-on-time.spec.js | 28 +++++++++++++++++++ ...payments-not-failed-to-pay-on-time.spec.js | 28 +++++++++++++++++++ 7 files changed, 169 insertions(+), 2 deletions(-) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/{submit-an-application-multiple-policy-type-fully-populated-buyer.spec.js => buyer-conditions/submit-an-application-single-policy-type-buyer-fully-populated.spec.js} (85%) create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-and-traded-with-buyer.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-with-buyer.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-failed-to-pay-on-time.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-not-failed-to-pay-on-time.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-failed-to-pay-on-time.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-not-failed-to-pay-on-time.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-fully-populated-buyer.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-fully-populated.spec.js similarity index 85% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-fully-populated-buyer.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-fully-populated.spec.js index 304e2dc848..75d357e113 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-fully-populated-buyer.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-fully-populated.spec.js @@ -1,4 +1,4 @@ -import { APPLICATION } from '../../../../../../constants'; +import { APPLICATION } from '../../../../../../../constants'; context('Insurance - submit an application - Multiple policy type, fully populated buyer', () => { let referenceNumber; @@ -8,7 +8,8 @@ context('Insurance - submit an application - Multiple policy type, fully populat policyType: APPLICATION.POLICY_TYPE.MULTIPLE, hasConnectionToBuyer: true, exporterHasTradedWithBuyer: true, - fullyPopulatedBuyerTradingHistory: true, + buyerOutstandingPayments: true, + buyerFailedToPayOnTime: true, hasHadCreditInsuranceCover: true, exporterHasBuyerFinancialAccounts: true, totalContractValueOverThreshold: true, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-and-traded-with-buyer.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-and-traded-with-buyer.spec.js new file mode 100644 index 0000000000..2f2cb27942 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-and-traded-with-buyer.spec.js @@ -0,0 +1,28 @@ +import { APPLICATION } from '../../../../../../../constants'; + +context('Insurance - submit an application - Multiple policy type, exporter has connection with buyer, has traded with buyer before', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + hasConnectionToBuyer: true, + exporterHasTradedWithBuyer: true, + fullyPopulatedBuyerTradingHistory: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-with-buyer.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-with-buyer.spec.js new file mode 100644 index 0000000000..ec0b16f18e --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-with-buyer.spec.js @@ -0,0 +1,26 @@ +import { APPLICATION } from '../../../../../../../constants'; + +context('Insurance - submit an application - Multiple policy type, exporter has connection with buyer', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + hasConnectionToBuyer: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-failed-to-pay-on-time.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-failed-to-pay-on-time.spec.js new file mode 100644 index 0000000000..483324a135 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-failed-to-pay-on-time.spec.js @@ -0,0 +1,28 @@ +import { APPLICATION } from '../../../../../../../../constants'; + +context('Insurance - submit an application - Multiple policy type, exporter has traded with buyer, no outstanding payments, failed to pay on time', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + exporterHasTradedWithBuyer: true, + buyerOutstandingPayments: false, + buyerFailedToPayOnTime: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-not-failed-to-pay-on-time.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-not-failed-to-pay-on-time.spec.js new file mode 100644 index 0000000000..cd0269adc8 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/no-outstanding-payments-not-failed-to-pay-on-time.spec.js @@ -0,0 +1,28 @@ +import { APPLICATION } from '../../../../../../../../constants'; + +context('Insurance - submit an application - Multiple policy type, exporter has traded with buyer, no outstanding payments, not failed to pay on time', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + exporterHasTradedWithBuyer: true, + buyerOutstandingPayments: false, + buyerFailedToPayOnTime: false, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-failed-to-pay-on-time.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-failed-to-pay-on-time.spec.js new file mode 100644 index 0000000000..887741fbb3 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-failed-to-pay-on-time.spec.js @@ -0,0 +1,28 @@ +import { APPLICATION } from '../../../../../../../../constants'; + +context('Insurance - submit an application - Multiple policy type, exporter has traded with buyer, has outstanding payments, has failed to pay on time', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + exporterHasTradedWithBuyer: true, + buyerOutstandingPayments: true, + buyerFailedToPayOnTime: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-not-failed-to-pay-on-time.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-not-failed-to-pay-on-time.spec.js new file mode 100644 index 0000000000..56cb126c52 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-not-failed-to-pay-on-time.spec.js @@ -0,0 +1,28 @@ +import { APPLICATION } from '../../../../../../../../constants'; + +context('Insurance - submit an application - Multiple policy type, exporter has traded with buyer, has outstanding payments, not failed to pay on time', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + exporterHasTradedWithBuyer: true, + buyerOutstandingPayments: true, + buyerFailedToPayOnTime: false, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); From 35c545c8e4c2780fea8ed9a95240a28caf319974 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Thu, 30 May 2024 10:46:05 +0100 Subject: [PATCH 14/29] feat(EMS-3344): no pdf - application submission - XLSX - unit tests --- src/api/.keystone/config.js | 289 ++++++------------ .../map-buyer/index.test.ts | 32 +- .../map-buyer/index.ts | 63 ++-- .../map-buyer-trading-history/index.test.ts | 60 ++++ .../map-buyer-trading-history/index.ts | 34 +++ .../map-connection-with-buyer/index.test.ts | 52 ++++ .../map-connection-with-buyer/index.ts | 22 ++ .../map-outstanding-payments/index.test.ts | 65 ++++ .../map-outstanding-payments/index.ts | 39 +++ .../index.test.ts | 52 ++++ .../map-previous-cover-with-buyer/index.ts | 22 ++ src/api/test-mocks/mock-buyer.ts | 38 ++- 12 files changed, 513 insertions(+), 255 deletions(-) create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.test.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.test.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-outstanding-payments/index.test.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-outstanding-payments/index.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-previous-cover-with-buyer/index.test.ts create mode 100644 src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-previous-cover-with-buyer/index.ts diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 7a18752efb..6fcc65651d 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -804,11 +804,7 @@ var TITLE_INDEXES = () => ({ EXPORTER_BUSINESS: 31, POLICY: 48, BUYER: 57, -<<<<<<< HEAD DECLARATIONS: 67 -======= - DECLARATIONS: 65 ->>>>>>> main-application-no-pdf }); var INDEXES = () => ({ TITLES: TITLE_INDEXES(), @@ -838,19 +834,10 @@ var { var XLSX_ROW_INDEXES = (application2) => { const { broker, -<<<<<<< HEAD buyer: { - buyerTradingHistory: { - exporterHasTradedWithBuyer, - outstandingPayments: buyerHasOutstandingPayments - }, - relationship: { - exporterIsConnectedWithBuyer, - exporterHasPreviousCreditInsuranceWithBuyer - } + buyerTradingHistory: { exporterHasTradedWithBuyer, outstandingPayments: buyerHasOutstandingPayments }, + relationship: { exporterIsConnectedWithBuyer, exporterHasPreviousCreditInsuranceWithBuyer } }, -======= ->>>>>>> main-application-no-pdf company: { differentTradingAddress: { fullAddress: hasDifferentTradingAddress }, hasDifferentTradingName @@ -867,11 +854,7 @@ var XLSX_ROW_INDEXES = (application2) => { if (broker[USING_BROKER]) { indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; -<<<<<<< HEAD indexes.TITLES.DECLARATIONS += 6; -======= - indexes.TITLES.DECLARATIONS += 3; ->>>>>>> main-application-no-pdf indexes.BUYER_ADDRESS += 3; indexes.BROKER_ADDRESS = 48; } @@ -884,7 +867,6 @@ var XLSX_ROW_INDEXES = (application2) => { } if (hasDifferentTradingName && hasDifferentTradingAddress) { indexes.ALTERNATIVE_TRADING_ADDRESS = 38; -<<<<<<< HEAD } if (exporterIsConnectedWithBuyer) { indexes.TITLES.DECLARATIONS += 1; @@ -897,8 +879,6 @@ var XLSX_ROW_INDEXES = (application2) => { } if (exporterHasPreviousCreditInsuranceWithBuyer) { indexes.TITLES.DECLARATIONS += 1; -======= ->>>>>>> main-application-no-pdf } return indexes; }; @@ -5626,13 +5606,7 @@ var { CURRENCY: { CURRENCY_CODE } } = FIELD_IDS.INSURANCE; var { - YOUR_BUYER: { - COMPANY_DETAILS, - TRADING_HISTORY, - CONNECTION_TO_BUYER, - CREDIT_INSURANCE_HISTORY, - FINANCIAL_ACCOUNTS - } + YOUR_BUYER: { COMPANY_DETAILS, TRADING_HISTORY, CONNECTION_TO_BUYER, CREDIT_INSURANCE_HISTORY, FINANCIAL_ACCOUNTS } } = FORM_TITLES; var YOUR_BUYER_FIELDS = { COMPANY_OR_ORGANISATION: { @@ -5804,7 +5778,6 @@ var { HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER2, OUTSTANDING_PAYMENTS: OUTSTANDING_PAYMENTS2, PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER2, - TOTAL_AMOUNT_OVERDUE: TOTAL_AMOUNT_OVERDUE2, TOTAL_OUTSTANDING_PAYMENTS: TOTAL_OUTSTANDING_PAYMENTS2, TRADED_WITH_BUYER: TRADED_WITH_BUYER2 } @@ -5858,7 +5831,6 @@ var XLSX = { [BUYER_COMPANY_NAME]: "Buyer company name or organisation", [BUYER_REGISTRATION_NUMBER]: "Buyer registration number (optional)", [BUYER_CONTACT_DETAILS]: "Buyer contact details", -<<<<<<< HEAD [CONNECTION_WITH_BUYER2]: "Is the exporter connected with the buyer in any way?", [CONNECTION_WITH_BUYER_DESCRIPTION2]: "Describe connection to the buyer", [TRADED_WITH_BUYER2]: "Has the exporter traded with this buyer before?", @@ -5868,8 +5840,6 @@ var XLSX = { [OUTSTANDING_PAYMENTS2]: "Does the exporter currently have any outstanding or overdue payments from the buyer", [PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER2]: "Exporter explaining the credit insurance cover they had on the buyer", [TOTAL_OUTSTANDING_PAYMENTS2]: "Total outstanding payments", -======= ->>>>>>> main-application-no-pdf NO_FINANCIAL_YEAR_END_DATE: "No data from Companies House" } }; @@ -6044,29 +6014,21 @@ var mapPolicy = (application2) => { var map_policy_default = mapPolicy; // generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.ts -<<<<<<< HEAD var mapYesNoField = (answer, defaultValue) => { -======= -var mapYesNoField = (answer) => { ->>>>>>> main-application-no-pdf if (answer === false) { return "No"; } if (answer === true) { return "Yes"; } -<<<<<<< HEAD if (defaultValue) { return defaultValue; } -======= ->>>>>>> main-application-no-pdf return DEFAULT.EMPTY; }; var map_yes_no_field_default = mapYesNoField; // generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts -<<<<<<< HEAD var { USING_BROKER: USING_BROKER4, BROKER_DETAILS: { NAME: BROKER_NAME2, EMAIL: EMAIL7, FULL_ADDRESS: FULL_ADDRESS2 } @@ -6138,79 +6100,6 @@ var mapFinancialYearEndDate = (company) => { if (company[FINANCIAL_YEAR_END_DATE2]) { return format_date_default(company[FINANCIAL_YEAR_END_DATE2], "d MMMM"); } -======= -var { - USING_BROKER: USING_BROKER4, - BROKER_DETAILS: { NAME: BROKER_NAME2, EMAIL: EMAIL7, FULL_ADDRESS: FULL_ADDRESS2 } -} = POLICY; -var { FIELDS: FIELDS5 } = XLSX; -var mapBroker = (application2) => { - const { broker } = application2; - let mapped = [xlsx_row_default(FIELDS5[USING_BROKER4], map_yes_no_field_default(broker[USING_BROKER4]))]; - if (broker[USING_BROKER4]) { - mapped = [ - ...mapped, - xlsx_row_default(FIELDS5[BROKER_NAME2], broker[BROKER_NAME2]), - xlsx_row_default(FIELDS5[FULL_ADDRESS2], broker[FULL_ADDRESS2]), - xlsx_row_default(FIELDS5[EMAIL7], broker[EMAIL7]) - ]; - } - return mapped; -}; -var map_broker_default = mapBroker; - -// generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-name/index.ts -var { - YOUR_COMPANY: { HAS_DIFFERENT_TRADING_NAME: HAS_DIFFERENT_TRADING_NAME3, DIFFERENT_TRADING_NAME: DIFFERENT_TRADING_NAME2 } -} = business_default; -var { FIELDS: FIELDS6 } = XLSX; -var mapDifferentTradingName = (company) => { - if (company[HAS_DIFFERENT_TRADING_NAME3]) { - return xlsx_row_default(FIELDS6[DIFFERENT_TRADING_NAME2], company[DIFFERENT_TRADING_NAME2]); - } -}; -var map_different_trading_name_default = mapDifferentTradingName; - -// generate-xlsx/map-application-to-XLSX/map-exporter-business/map-different-trading-address/index.ts -var { - ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS: FULL_ADDRESS3, FULL_ADDRESS_DOT_NOTATION: FULL_ADDRESS_DOT_NOTATION2 } -} = business_default; -var { FIELDS: FIELDS7 } = XLSX; -var mapDifferentTradingAddress = (company) => { - const { differentTradingAddress } = company; - const differentTradingAddressValue = differentTradingAddress[FULL_ADDRESS3]; - if (differentTradingAddressValue) { - return xlsx_row_default(FIELDS7[FULL_ADDRESS_DOT_NOTATION2], differentTradingAddressValue); - } -}; -var map_different_trading_address_default = mapDifferentTradingAddress; - -// generate-xlsx/map-application-to-XLSX/helpers/xlsx-new-line/index.ts -var NEW_LINE = "\r\n"; -var xlsx_new_line_default = NEW_LINE; - -// generate-xlsx/map-application-to-XLSX/map-exporter-business/map-exporter-address/index.ts -var mapExporterAddress = (address) => { - let addressString = ""; - Object.keys(address).forEach((field) => { - if (address[field] && field !== "id" && field !== "__typename") { - addressString += `${address[field]}${xlsx_new_line_default}`; - } - }); - return addressString; -}; -var map_exporter_address_default = mapExporterAddress; - -// generate-xlsx/map-application-to-XLSX/map-exporter-business/map-financial-year-end-date/index.ts -var { - COMPANIES_HOUSE: { FINANCIAL_YEAR_END_DATE: FINANCIAL_YEAR_END_DATE2 } -} = business_default; -var { FIELDS: FIELDS8 } = XLSX; -var mapFinancialYearEndDate = (company) => { - if (company[FINANCIAL_YEAR_END_DATE2]) { - return format_date_default(company[FINANCIAL_YEAR_END_DATE2], "d MMMM"); - } ->>>>>>> main-application-no-pdf return FIELDS8.NO_FINANCIAL_YEAR_END_DATE; }; var map_financial_year_end_date_default = mapFinancialYearEndDate; @@ -6267,79 +6156,103 @@ var mapExporterBusiness = (application2) => { }; var map_exporter_business_default = mapExporterBusiness; -// generate-xlsx/map-application-to-XLSX/map-buyer/index.ts -var CONTENT_STRINGS4 = { - ...YOUR_BUYER_FIELDS.COMPANY_OR_ORGANISATION, - ...YOUR_BUYER_FIELDS +// generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.ts +var { + CONNECTION_WITH_BUYER: CONNECTION_WITH_BUYER3, + CONNECTION_WITH_BUYER_DESCRIPTION: CONNECTION_WITH_BUYER_DESCRIPTION3 +} = your_buyer_default; +var { FIELDS: FIELDS10 } = XLSX; +var mapConnectionWithBuyer = (relationship2) => { + if (relationship2[CONNECTION_WITH_BUYER3]) { + return xlsx_row_default(String(FIELDS10[CONNECTION_WITH_BUYER_DESCRIPTION3]), relationship2[CONNECTION_WITH_BUYER_DESCRIPTION3]); + } }; +var map_connection_with_buyer_default = mapConnectionWithBuyer; + +// generate-xlsx/map-application-to-XLSX/map-buyer/map-outstanding-payments/index.ts var { CURRENCY: { CURRENCY_CODE: CURRENCY_CODE2 }, YOUR_BUYER: { - COMPANY_OR_ORGANISATION: { NAME: NAME2, ADDRESS, COUNTRY: COUNTRY3, REGISTRATION_NUMBER, WEBSITE: WEBSITE4 }, - CONNECTION_WITH_BUYER: CONNECTION_WITH_BUYER3, - CONNECTION_WITH_BUYER_DESCRIPTION: CONNECTION_WITH_BUYER_DESCRIPTION3, - FAILED_PAYMENTS: FAILED_PAYMENTS3, - HAS_BUYER_FINANCIAL_ACCOUNTS: HAS_BUYER_FINANCIAL_ACCOUNTS3, - HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3, OUTSTANDING_PAYMENTS: OUTSTANDING_PAYMENTS3, - PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3, - TRADED_WITH_BUYER: TRADED_WITH_BUYER3, TOTAL_OUTSTANDING_PAYMENTS: TOTAL_OUTSTANDING_PAYMENTS3, - TOTAL_AMOUNT_OVERDUE: TOTAL_AMOUNT_OVERDUE3 + TOTAL_AMOUNT_OVERDUE: TOTAL_AMOUNT_OVERDUE2 } } = insurance_default; -var { SECTION_TITLES: SECTION_TITLES2, FIELDS: FIELDS10 } = XLSX; +var { FIELDS: FIELDS11 } = XLSX; +var mapOutstandingPayments = (tradingHistory) => { + if (tradingHistory[OUTSTANDING_PAYMENTS3]) { + const values = { + totalOutstanding: format_currency_default(tradingHistory[TOTAL_OUTSTANDING_PAYMENTS3], tradingHistory[CURRENCY_CODE2]), + totalAmountOverdue: format_currency_default(tradingHistory[TOTAL_AMOUNT_OVERDUE2], tradingHistory[CURRENCY_CODE2]) + }; + const mapped = [ + xlsx_row_default(String(FIELDS11[TOTAL_OUTSTANDING_PAYMENTS3]), values.totalOutstanding), + xlsx_row_default(String(YOUR_BUYER_FIELDS[TOTAL_AMOUNT_OVERDUE2].SUMMARY?.TITLE), values.totalAmountOverdue) + ]; + return mapped; + } + return []; +}; +var map_outstanding_payments_default = mapOutstandingPayments; + +// generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.ts +var { FAILED_PAYMENTS: FAILED_PAYMENTS3, OUTSTANDING_PAYMENTS: OUTSTANDING_PAYMENTS4, TRADED_WITH_BUYER: TRADED_WITH_BUYER3 } = your_buyer_default; +var { FIELDS: FIELDS12 } = XLSX; +var mapBuyerTradingHistory = (tradingHistory) => { + if (tradingHistory[TRADED_WITH_BUYER3]) { + const mapped = [ + xlsx_row_default(String(FIELDS12[OUTSTANDING_PAYMENTS4]), map_yes_no_field_default(tradingHistory[OUTSTANDING_PAYMENTS4])), + ...map_outstanding_payments_default(tradingHistory), + xlsx_row_default(String(FIELDS12[FAILED_PAYMENTS3]), map_yes_no_field_default(tradingHistory[FAILED_PAYMENTS3])) + ]; + return mapped; + } + return []; +}; +var map_buyer_trading_history_default = mapBuyerTradingHistory; + +// generate-xlsx/map-application-to-XLSX/map-buyer/map-previous-cover-with-buyer/index.ts +var { + HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3, + PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3 +} = your_buyer_default; +var { FIELDS: FIELDS13 } = XLSX; +var mapPreviousCoverWithBuyer = (relationship2) => { + if (relationship2[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3]) { + return xlsx_row_default(String(FIELDS13[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3]), relationship2[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3]); + } +}; +var map_previous_cover_with_buyer_default = mapPreviousCoverWithBuyer; + +// generate-xlsx/map-application-to-XLSX/map-buyer/index.ts +var CONTENT_STRINGS4 = { + ...YOUR_BUYER_FIELDS.COMPANY_OR_ORGANISATION, + ...YOUR_BUYER_FIELDS +}; +var { + COMPANY_OR_ORGANISATION: { NAME: NAME2, ADDRESS, COUNTRY: COUNTRY3, REGISTRATION_NUMBER, WEBSITE: WEBSITE4 }, + CONNECTION_WITH_BUYER: CONNECTION_WITH_BUYER4, + HAS_BUYER_FINANCIAL_ACCOUNTS: HAS_BUYER_FINANCIAL_ACCOUNTS3, + HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER4, + TRADED_WITH_BUYER: TRADED_WITH_BUYER4 +} = your_buyer_default; +var { SECTION_TITLES: SECTION_TITLES2, FIELDS: FIELDS14 } = XLSX; var mapBuyer = (application2) => { const { buyer } = application2; - console.log(">>>>>>>> buyer ", buyer); const { buyerTradingHistory, relationship: relationship2 } = buyer; - let mapped = [ + const mapped = [ xlsx_row_default(SECTION_TITLES2.BUYER, ""), - xlsx_row_default(FIELDS10[NAME2], buyer[NAME2]), + xlsx_row_default(FIELDS14[NAME2], buyer[NAME2]), xlsx_row_default(String(CONTENT_STRINGS4[ADDRESS].SUMMARY?.TITLE), `${buyer[ADDRESS]} ${xlsx_new_line_default}${buyer[COUNTRY3].name}`), - xlsx_row_default(FIELDS10[REGISTRATION_NUMBER], buyer[REGISTRATION_NUMBER]), + xlsx_row_default(FIELDS14[REGISTRATION_NUMBER], buyer[REGISTRATION_NUMBER]), xlsx_row_default(String(CONTENT_STRINGS4[WEBSITE4].SUMMARY?.TITLE), buyer[WEBSITE4]), - xlsx_row_default(String(FIELDS10[CONNECTION_WITH_BUYER3]), map_yes_no_field_default(relationship2[CONNECTION_WITH_BUYER3])) - ]; - if (relationship2[CONNECTION_WITH_BUYER3]) { - mapped.push( - xlsx_row_default(String(FIELDS10[CONNECTION_WITH_BUYER_DESCRIPTION3]), relationship2[CONNECTION_WITH_BUYER_DESCRIPTION3]) - ); - } - mapped = [ - ...mapped, - xlsx_row_default(String(FIELDS10[TRADED_WITH_BUYER3]), map_yes_no_field_default(buyerTradingHistory[TRADED_WITH_BUYER3])) - ]; - if (buyerTradingHistory[TRADED_WITH_BUYER3]) { - mapped.push( - xlsx_row_default(String(FIELDS10[OUTSTANDING_PAYMENTS3]), map_yes_no_field_default(buyerTradingHistory[OUTSTANDING_PAYMENTS3])) - ); - if (buyerTradingHistory[OUTSTANDING_PAYMENTS3]) { - const totalOutstandingPaymentsValue = format_currency_default2(buyerTradingHistory[TOTAL_OUTSTANDING_PAYMENTS3], buyerTradingHistory[CURRENCY_CODE2]); - mapped.push( - xlsx_row_default(String(FIELDS10[TOTAL_OUTSTANDING_PAYMENTS3]), totalOutstandingPaymentsValue) - ); - const totalAmountOverdueValue = format_currency_default2(buyerTradingHistory[TOTAL_AMOUNT_OVERDUE3], buyerTradingHistory[CURRENCY_CODE2]); - mapped.push( - xlsx_row_default(String(CONTENT_STRINGS4[TOTAL_AMOUNT_OVERDUE3].SUMMARY?.TITLE), totalAmountOverdueValue) - ); - } - mapped.push( - xlsx_row_default(String(FIELDS10[FAILED_PAYMENTS3]), map_yes_no_field_default(buyerTradingHistory[FAILED_PAYMENTS3])) - ); - } - mapped = [ - ...mapped, - xlsx_row_default(String(FIELDS10[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3]), map_yes_no_field_default(relationship2[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3], "No")) - ]; - if (relationship2[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3]) { - mapped.push( - xlsx_row_default(String(FIELDS10[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3]), relationship2[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3]) - ); - } - mapped = [ - ...mapped, - xlsx_row_default(String(FIELDS10[HAS_BUYER_FINANCIAL_ACCOUNTS3]), map_yes_no_field_default(relationship2[HAS_BUYER_FINANCIAL_ACCOUNTS3])) + xlsx_row_default(String(FIELDS14[CONNECTION_WITH_BUYER4]), map_yes_no_field_default(relationship2[CONNECTION_WITH_BUYER4])), + map_connection_with_buyer_default(relationship2), + xlsx_row_default(String(FIELDS14[TRADED_WITH_BUYER4]), map_yes_no_field_default(buyerTradingHistory[TRADED_WITH_BUYER4])), + ...map_buyer_trading_history_default(buyerTradingHistory), + xlsx_row_default(String(FIELDS14[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER4]), map_yes_no_field_default(relationship2[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER4], "No")), + map_previous_cover_with_buyer_default(relationship2), + xlsx_row_default(String(FIELDS14[HAS_BUYER_FINANCIAL_ACCOUNTS3]), map_yes_no_field_default(relationship2[HAS_BUYER_FINANCIAL_ACCOUNTS3])) ]; return mapped; }; @@ -6347,11 +6260,7 @@ var map_buyer_default = mapBuyer; // generate-xlsx/map-application-to-XLSX/map-eligibility/index.ts var { MORE_THAN_250K: MORE_THAN_250K2 } = TOTAL_CONTRACT_VALUE; -<<<<<<< HEAD -var { FIELDS: FIELDS11, SECTION_TITLES: SECTION_TITLES3 } = XLSX; -======= -var { FIELDS: FIELDS10, SECTION_TITLES: SECTION_TITLES2 } = XLSX; ->>>>>>> main-application-no-pdf +var { FIELDS: FIELDS15, SECTION_TITLES: SECTION_TITLES3 } = XLSX; var { ELIGIBILITY: { BUYER_COUNTRY: BUYER_COUNTRY3, @@ -6368,27 +6277,15 @@ var { var mapEligibility = (application2) => { const { company, eligibility } = application2; const mapped = [ -<<<<<<< HEAD xlsx_row_default(SECTION_TITLES3.ELIGIBILITY, ""), xlsx_row_default(FIELDS_ELIGIBILITY[VALID_EXPORTER_LOCATION2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[VALID_EXPORTER_LOCATION2])), xlsx_row_default(FIELDS_ELIGIBILITY[HAS_COMPANIES_HOUSE_NUMBER2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[HAS_COMPANIES_HOUSE_NUMBER2])), - xlsx_row_default(FIELDS11[COMPANIES_HOUSE_NUMBER3], company[COMPANIES_HOUSE_NUMBER3]), - xlsx_row_default(FIELDS11[BUYER_COUNTRY3], eligibility[BUYER_COUNTRY3].name), - xlsx_row_default(FIELDS11[MORE_THAN_250K2.VALUE], map_yes_no_field_default(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID)), - xlsx_row_default(FIELDS11[COVER_PERIOD3], eligibility[COVER_PERIOD_ELIGIBILITY].value), - xlsx_row_default(FIELDS11[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3])), - xlsx_row_default(FIELDS11[HAS_END_BUYER3], map_yes_no_field_default(eligibility[HAS_END_BUYER3])) -======= - xlsx_row_default(SECTION_TITLES2.ELIGIBILITY, ""), - xlsx_row_default(FIELDS_ELIGIBILITY[VALID_EXPORTER_LOCATION2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[VALID_EXPORTER_LOCATION2])), - xlsx_row_default(FIELDS_ELIGIBILITY[HAS_COMPANIES_HOUSE_NUMBER2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[HAS_COMPANIES_HOUSE_NUMBER2])), - xlsx_row_default(FIELDS10[COMPANIES_HOUSE_NUMBER3], company[COMPANIES_HOUSE_NUMBER3]), - xlsx_row_default(FIELDS10[BUYER_COUNTRY3], eligibility[BUYER_COUNTRY3].name), - xlsx_row_default(FIELDS10[MORE_THAN_250K2.VALUE], map_yes_no_field_default(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID)), - xlsx_row_default(FIELDS10[COVER_PERIOD3], eligibility[COVER_PERIOD_ELIGIBILITY].value), - xlsx_row_default(FIELDS10[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3])), - xlsx_row_default(FIELDS10[HAS_END_BUYER3], map_yes_no_field_default(eligibility[HAS_END_BUYER3])) ->>>>>>> main-application-no-pdf + xlsx_row_default(FIELDS15[COMPANIES_HOUSE_NUMBER3], company[COMPANIES_HOUSE_NUMBER3]), + xlsx_row_default(FIELDS15[BUYER_COUNTRY3], eligibility[BUYER_COUNTRY3].name), + xlsx_row_default(FIELDS15[MORE_THAN_250K2.VALUE], map_yes_no_field_default(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID)), + xlsx_row_default(FIELDS15[COVER_PERIOD3], eligibility[COVER_PERIOD_ELIGIBILITY].value), + xlsx_row_default(FIELDS15[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3])), + xlsx_row_default(FIELDS15[HAS_END_BUYER3], map_yes_no_field_default(eligibility[HAS_END_BUYER3])) ]; return mapped; }; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.test.ts index e9c83a0c75..2b6117058d 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.test.ts @@ -5,6 +5,9 @@ import { YOUR_BUYER_FIELDS } from '../../../content-strings/fields/insurance/you import NEW_LINE from '../helpers/xlsx-new-line'; import xlsxRow from '../helpers/xlsx-row'; import mapYesNoField from '../helpers/map-yes-no-field'; +import mapConnectionWithBuyer from './map-connection-with-buyer'; +import mapBuyerTradingHistory from './map-buyer-trading-history'; +import mapPreviousCoverWithBuyer from './map-previous-cover-with-buyer'; import { mockApplication } from '../../../test-mocks'; const CONTENT_STRINGS = { @@ -15,23 +18,42 @@ const CONTENT_STRINGS = { const { COMPANY_OR_ORGANISATION: { NAME, ADDRESS, COUNTRY, REGISTRATION_NUMBER, WEBSITE }, CONNECTION_WITH_BUYER, + HAS_BUYER_FINANCIAL_ACCOUNTS, + HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, TRADED_WITH_BUYER, } = FIELD_IDS; +const { SECTION_TITLES, FIELDS } = XLSX; + describe('api/generate-xlsx/map-application-to-xlsx/map-buyer', () => { it('should return an array of mapped buyer fields', () => { const result = mapBuyer(mockApplication); const { buyer } = mockApplication; + const { buyerTradingHistory, relationship } = buyer; const expected = [ - xlsxRow(XLSX.SECTION_TITLES.BUYER, ''), - xlsxRow(XLSX.FIELDS[NAME], buyer[NAME]), + xlsxRow(SECTION_TITLES.BUYER, ''), + xlsxRow(FIELDS[NAME], buyer[NAME]), xlsxRow(String(CONTENT_STRINGS[ADDRESS].SUMMARY?.TITLE), `${buyer[ADDRESS]} ${NEW_LINE}${buyer[COUNTRY].name}`), - xlsxRow(XLSX.FIELDS[REGISTRATION_NUMBER], buyer[REGISTRATION_NUMBER]), + xlsxRow(FIELDS[REGISTRATION_NUMBER], buyer[REGISTRATION_NUMBER]), xlsxRow(String(CONTENT_STRINGS[WEBSITE].SUMMARY?.TITLE), buyer[WEBSITE]), - xlsxRow(String(CONTENT_STRINGS[CONNECTION_WITH_BUYER].SUMMARY?.TITLE), mapYesNoField(buyer[CONNECTION_WITH_BUYER])), - xlsxRow(String(CONTENT_STRINGS[TRADED_WITH_BUYER].SUMMARY?.TITLE), mapYesNoField(buyer[TRADED_WITH_BUYER])), + xlsxRow(String(FIELDS[CONNECTION_WITH_BUYER]), mapYesNoField(relationship[CONNECTION_WITH_BUYER])), + + mapConnectionWithBuyer(relationship), + + xlsxRow(String(FIELDS[TRADED_WITH_BUYER]), mapYesNoField(buyerTradingHistory[TRADED_WITH_BUYER])), + + ...mapBuyerTradingHistory(buyerTradingHistory), + + xlsxRow( + String(FIELDS[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]), + mapYesNoField(relationship[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER], 'No'), + ), + + mapPreviousCoverWithBuyer(relationship), + + xlsxRow(String(FIELDS[HAS_BUYER_FINANCIAL_ACCOUNTS]), mapYesNoField(relationship[HAS_BUYER_FINANCIAL_ACCOUNTS])), ]; expect(result).toEqual(expected); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts index fa186943ad..9f836b75ca 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts @@ -1,10 +1,12 @@ -import INSURANCE_FIELD_IDS from '../../../constants/field-ids/insurance'; +import FIELD_IDS from '../../../constants/field-ids/insurance/your-buyer'; import { XLSX } from '../../../content-strings'; import { YOUR_BUYER_FIELDS } from '../../../content-strings/fields/insurance/your-buyer'; import xlsxRow from '../helpers/xlsx-row'; import NEW_LINE from '../helpers/xlsx-new-line'; import mapYesNoField from '../helpers/map-yes-no-field'; -import formatCurrency from '../helpers/format-currency'; +import mapConnectionWithBuyer from './map-connection-with-buyer'; +import mapBuyerTradingHistory from './map-buyer-trading-history'; +import mapPreviousCoverWithBuyer from './map-previous-cover-with-buyer'; import { Application } from '../../../types'; const CONTENT_STRINGS = { @@ -13,21 +15,12 @@ const CONTENT_STRINGS = { }; const { - CURRENCY: { CURRENCY_CODE }, - YOUR_BUYER: { - COMPANY_OR_ORGANISATION: { NAME, ADDRESS, COUNTRY, REGISTRATION_NUMBER, WEBSITE }, - CONNECTION_WITH_BUYER, - CONNECTION_WITH_BUYER_DESCRIPTION, - FAILED_PAYMENTS, - HAS_BUYER_FINANCIAL_ACCOUNTS, - HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, - OUTSTANDING_PAYMENTS, - PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, - TRADED_WITH_BUYER, - TOTAL_OUTSTANDING_PAYMENTS, - TOTAL_AMOUNT_OVERDUE, - }, -} = INSURANCE_FIELD_IDS; + COMPANY_OR_ORGANISATION: { NAME, ADDRESS, COUNTRY, REGISTRATION_NUMBER, WEBSITE }, + CONNECTION_WITH_BUYER, + HAS_BUYER_FINANCIAL_ACCOUNTS, + HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, + TRADED_WITH_BUYER, +} = FIELD_IDS; const { SECTION_TITLES, FIELDS } = XLSX; @@ -39,50 +32,28 @@ const { SECTION_TITLES, FIELDS } = XLSX; */ const mapBuyer = (application: Application) => { const { buyer } = application; - const { buyerTradingHistory, relationship } = buyer; - let mapped = [ + const mapped = [ xlsxRow(SECTION_TITLES.BUYER, ''), xlsxRow(FIELDS[NAME], buyer[NAME]), xlsxRow(String(CONTENT_STRINGS[ADDRESS].SUMMARY?.TITLE), `${buyer[ADDRESS]} ${NEW_LINE}${buyer[COUNTRY].name}`), xlsxRow(FIELDS[REGISTRATION_NUMBER], buyer[REGISTRATION_NUMBER]), xlsxRow(String(CONTENT_STRINGS[WEBSITE].SUMMARY?.TITLE), buyer[WEBSITE]), xlsxRow(String(FIELDS[CONNECTION_WITH_BUYER]), mapYesNoField(relationship[CONNECTION_WITH_BUYER])), - ]; - - if (relationship[CONNECTION_WITH_BUYER]) { - mapped.push(xlsxRow(String(FIELDS[CONNECTION_WITH_BUYER_DESCRIPTION]), relationship[CONNECTION_WITH_BUYER_DESCRIPTION])); - } - - mapped = [...mapped, xlsxRow(String(FIELDS[TRADED_WITH_BUYER]), mapYesNoField(buyerTradingHistory[TRADED_WITH_BUYER]))]; - - if (buyerTradingHistory[TRADED_WITH_BUYER]) { - mapped.push(xlsxRow(String(FIELDS[OUTSTANDING_PAYMENTS]), mapYesNoField(buyerTradingHistory[OUTSTANDING_PAYMENTS]))); - if (buyerTradingHistory[OUTSTANDING_PAYMENTS]) { - const totalOutstandingPaymentsValue = formatCurrency(buyerTradingHistory[TOTAL_OUTSTANDING_PAYMENTS], buyerTradingHistory[CURRENCY_CODE]); + mapConnectionWithBuyer(relationship), - mapped.push(xlsxRow(String(FIELDS[TOTAL_OUTSTANDING_PAYMENTS]), totalOutstandingPaymentsValue)); + xlsxRow(String(FIELDS[TRADED_WITH_BUYER]), mapYesNoField(buyerTradingHistory[TRADED_WITH_BUYER])), - const totalAmountOverdueValue = formatCurrency(buyerTradingHistory[TOTAL_AMOUNT_OVERDUE], buyerTradingHistory[CURRENCY_CODE]); + ...mapBuyerTradingHistory(buyerTradingHistory), - mapped.push(xlsxRow(String(CONTENT_STRINGS[TOTAL_AMOUNT_OVERDUE].SUMMARY?.TITLE), totalAmountOverdueValue)); - } - - mapped.push(xlsxRow(String(FIELDS[FAILED_PAYMENTS]), mapYesNoField(buyerTradingHistory[FAILED_PAYMENTS]))); - } - - mapped = [ - ...mapped, xlsxRow(String(FIELDS[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]), mapYesNoField(relationship[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER], 'No')), - ]; - if (relationship[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]) { - mapped.push(xlsxRow(String(FIELDS[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]), relationship[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER])); - } + mapPreviousCoverWithBuyer(relationship), - mapped = [...mapped, xlsxRow(String(FIELDS[HAS_BUYER_FINANCIAL_ACCOUNTS]), mapYesNoField(relationship[HAS_BUYER_FINANCIAL_ACCOUNTS]))]; + xlsxRow(String(FIELDS[HAS_BUYER_FINANCIAL_ACCOUNTS]), mapYesNoField(relationship[HAS_BUYER_FINANCIAL_ACCOUNTS])), + ]; return mapped; }; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.test.ts new file mode 100644 index 0000000000..dd5addbf15 --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.test.ts @@ -0,0 +1,60 @@ +import mapBuyerTradingHistory from '.'; +import FIELD_IDS from '../../../../constants/field-ids/insurance/your-buyer'; +import { XLSX } from '../../../../content-strings'; +import xlsxRow from '../../helpers/xlsx-row'; +import mapYesNoField from '../../helpers/map-yes-no-field'; +import mapOutstandingPayments from '../map-outstanding-payments'; +import { mockBuyerTradingHistory } from '../../../../test-mocks/mock-buyer'; + +const { FAILED_PAYMENTS, OUTSTANDING_PAYMENTS, TRADED_WITH_BUYER } = FIELD_IDS; + +const { FIELDS } = XLSX; + +describe('api/generate-xlsx/map-application-to-xlsx/map-buyer-trading-history', () => { + describe(`when buyer trading history has a ${TRADED_WITH_BUYER} value of true`, () => { + it('should return mapped trading history data', () => { + const mockTradingHistory = { + ...mockBuyerTradingHistory, + [TRADED_WITH_BUYER]: true, + }; + + const result = mapBuyerTradingHistory(mockTradingHistory); + + const expected = [ + xlsxRow(String(FIELDS[OUTSTANDING_PAYMENTS]), mapYesNoField(mockTradingHistory[OUTSTANDING_PAYMENTS])), + + ...mapOutstandingPayments(mockTradingHistory), + + xlsxRow(String(FIELDS[FAILED_PAYMENTS]), mapYesNoField(mockTradingHistory[FAILED_PAYMENTS])), + ]; + + expect(result).toEqual(expected); + }); + }); + + describe(`when buyer trading history has a ${TRADED_WITH_BUYER} value of false`, () => { + it('should return an empty array', () => { + const mockTradingHistory = { + ...mockBuyerTradingHistory, + [TRADED_WITH_BUYER]: false, + }; + + const result = mapBuyerTradingHistory(mockTradingHistory); + + expect(result).toEqual([]); + }); + }); + + describe(`when buyer trading history has a ${TRADED_WITH_BUYER} value of undefined`, () => { + it('should return an empty array', () => { + const mockTradingHistory = { + ...mockBuyerTradingHistory, + [TRADED_WITH_BUYER]: undefined, + }; + + const result = mapBuyerTradingHistory(mockTradingHistory); + + expect(result).toEqual([]); + }); + }); +}); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.ts new file mode 100644 index 0000000000..d48fd11f6d --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.ts @@ -0,0 +1,34 @@ +import FIELD_IDS from '../../../../constants/field-ids/insurance/your-buyer'; +import { XLSX } from '../../../../content-strings'; +import xlsxRow from '../../helpers/xlsx-row'; +import mapYesNoField from '../../helpers/map-yes-no-field'; +import mapOutstandingPayments from '../map-outstanding-payments'; +import { BuyerTradingHistory } from '../../../../types'; + +const { FAILED_PAYMENTS, OUTSTANDING_PAYMENTS, TRADED_WITH_BUYER } = FIELD_IDS; + +const { FIELDS } = XLSX; + +/** + * mapBuyerTradingHistory + * Map an application's "buyer trading history" fields into an array of objects for XLSX generation + * @param {BuyerTradingHistory} tradingHistory: Buyer trading history + * @returns {Array} Array of objects for XLSX generation + */ +const mapBuyerTradingHistory = (tradingHistory: BuyerTradingHistory) => { + if (tradingHistory[TRADED_WITH_BUYER]) { + const mapped = [ + xlsxRow(String(FIELDS[OUTSTANDING_PAYMENTS]), mapYesNoField(tradingHistory[OUTSTANDING_PAYMENTS])), + + ...mapOutstandingPayments(tradingHistory), + + xlsxRow(String(FIELDS[FAILED_PAYMENTS]), mapYesNoField(tradingHistory[FAILED_PAYMENTS])), + ]; + + return mapped; + } + + return []; +}; + +export default mapBuyerTradingHistory; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.test.ts new file mode 100644 index 0000000000..4ed7b395f3 --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.test.ts @@ -0,0 +1,52 @@ +import mapConnectionWithBuyer from '.'; +import FIELD_IDS from '../../../../constants/field-ids/insurance/your-buyer'; +import { XLSX } from '../../../../content-strings'; +import xlsxRow from '../../helpers/xlsx-row'; +import { mockBuyerRelationship } from '../../../../test-mocks/mock-buyer'; + +const { CONNECTION_WITH_BUYER, CONNECTION_WITH_BUYER_DESCRIPTION } = FIELD_IDS; + +const { FIELDS } = XLSX; + +describe('api/generate-xlsx/map-application-to-xlsx/map-connection-with-buyer', () => { + describe(`when buyer relationship has a ${CONNECTION_WITH_BUYER} value of true`, () => { + it('should return an xlsxRow', () => { + const mockRelationship = { + ...mockBuyerRelationship, + [CONNECTION_WITH_BUYER]: true, + }; + + const result = mapConnectionWithBuyer(mockRelationship); + + const expected = xlsxRow(String(FIELDS[CONNECTION_WITH_BUYER_DESCRIPTION]), mockRelationship[CONNECTION_WITH_BUYER_DESCRIPTION]); + + expect(result).toEqual(expected); + }); + }); + + describe(`when buyer relationship has a ${CONNECTION_WITH_BUYER} value of false`, () => { + it('should not return anything', () => { + const mockRelationship = { + ...mockBuyerRelationship, + [CONNECTION_WITH_BUYER]: false, + }; + + const result = mapConnectionWithBuyer(mockRelationship); + + expect(result).toBeUndefined(); + }); + }); + + describe(`when buyer relationship has a ${CONNECTION_WITH_BUYER} value of undefined`, () => { + it('should not return anything', () => { + const mockRelationship = { + ...mockBuyerRelationship, + [CONNECTION_WITH_BUYER]: undefined, + }; + + const result = mapConnectionWithBuyer(mockRelationship); + + expect(result).toBeUndefined(); + }); + }); +}); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.ts new file mode 100644 index 0000000000..33a33215bd --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.ts @@ -0,0 +1,22 @@ +import FIELD_IDS from '../../../../constants/field-ids/insurance/your-buyer'; +import { XLSX } from '../../../../content-strings'; +import xlsxRow from '../../helpers/xlsx-row'; +import { ApplicationBuyerRelationship } from '../../../../types'; + +const { CONNECTION_WITH_BUYER, CONNECTION_WITH_BUYER_DESCRIPTION } = FIELD_IDS; + +const { FIELDS } = XLSX; + +/** + * mapPreviousCoverWithBuyer + * Generate an XLSX row if an exporter has a connection with the buyer. + * @param {ApplicationBuyerRelationship} relationship: Application buyer relationship + * @returns {Object | undefined} xlsxRow + */ +const mapConnectionWithBuyer = (relationship: ApplicationBuyerRelationship) => { + if (relationship[CONNECTION_WITH_BUYER]) { + return xlsxRow(String(FIELDS[CONNECTION_WITH_BUYER_DESCRIPTION]), relationship[CONNECTION_WITH_BUYER_DESCRIPTION]); + } +}; + +export default mapConnectionWithBuyer; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-outstanding-payments/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-outstanding-payments/index.test.ts new file mode 100644 index 0000000000..cb703f01c9 --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-outstanding-payments/index.test.ts @@ -0,0 +1,65 @@ +import mapOutstandingPayments from '.'; +import INSURANCE_FIELD_IDS from '../../../../constants/field-ids/insurance'; +import { XLSX } from '../../../../content-strings'; +import { YOUR_BUYER_FIELDS as CONTENT_STRINGS } from '../../../../content-strings/fields/insurance/your-buyer'; +import formatCurrency from '../../../../helpers/format-currency'; +import xlsxRow from '../../helpers/xlsx-row'; +import { mockBuyerTradingHistory } from '../../../../test-mocks/mock-buyer'; + +const { + CURRENCY: { CURRENCY_CODE }, + YOUR_BUYER: { OUTSTANDING_PAYMENTS, TOTAL_OUTSTANDING_PAYMENTS, TOTAL_AMOUNT_OVERDUE }, +} = INSURANCE_FIELD_IDS; + +const { FIELDS } = XLSX; + +describe('api/generate-xlsx/map-application-to-xlsx/map-outstanding-payments', () => { + describe(`when buyer trading history has an ${OUTSTANDING_PAYMENTS} value of true`, () => { + it('should return mapped trading history data', () => { + const mockTradingHistory = { + ...mockBuyerTradingHistory, + [OUTSTANDING_PAYMENTS]: true, + }; + + const result = mapOutstandingPayments(mockTradingHistory); + + const expectedValues = { + totalOutstanding: formatCurrency(mockTradingHistory[TOTAL_OUTSTANDING_PAYMENTS], mockTradingHistory[CURRENCY_CODE]), + totalAmountOverdue: formatCurrency(mockTradingHistory[TOTAL_AMOUNT_OVERDUE], mockTradingHistory[CURRENCY_CODE]), + }; + + const expected = [ + xlsxRow(String(FIELDS[TOTAL_OUTSTANDING_PAYMENTS]), expectedValues.totalOutstanding), + xlsxRow(String(CONTENT_STRINGS[TOTAL_AMOUNT_OVERDUE].SUMMARY?.TITLE), expectedValues.totalAmountOverdue), + ]; + + expect(result).toEqual(expected); + }); + }); + + describe(`when buyer trading history has an ${OUTSTANDING_PAYMENTS} value of false`, () => { + it('should return an empty array', () => { + const mockTradingHistory = { + ...mockBuyerTradingHistory, + [OUTSTANDING_PAYMENTS]: false, + }; + + const result = mapOutstandingPayments(mockTradingHistory); + + expect(result).toEqual([]); + }); + }); + + describe(`when buyer trading history has an ${OUTSTANDING_PAYMENTS} value of undefined`, () => { + it('should return an empty array', () => { + const mockTradingHistory = { + ...mockBuyerTradingHistory, + [OUTSTANDING_PAYMENTS]: undefined, + }; + + const result = mapOutstandingPayments(mockTradingHistory); + + expect(result).toEqual([]); + }); + }); +}); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-outstanding-payments/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-outstanding-payments/index.ts new file mode 100644 index 0000000000..041fd65b4c --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-outstanding-payments/index.ts @@ -0,0 +1,39 @@ +import INSURANCE_FIELD_IDS from '../../../../constants/field-ids/insurance'; +import { XLSX } from '../../../../content-strings'; +import { YOUR_BUYER_FIELDS as CONTENT_STRINGS } from '../../../../content-strings/fields/insurance/your-buyer'; +import formatCurrency from '../../../../helpers/format-currency'; +import xlsxRow from '../../helpers/xlsx-row'; +import { BuyerTradingHistory } from '../../../../types'; + +const { + CURRENCY: { CURRENCY_CODE }, + YOUR_BUYER: { OUTSTANDING_PAYMENTS, TOTAL_OUTSTANDING_PAYMENTS, TOTAL_AMOUNT_OVERDUE }, +} = INSURANCE_FIELD_IDS; + +const { FIELDS } = XLSX; + +/** + * mapOutstandingPayments + * Map an application's "outstanding buyer payments" fields into an array of objects for XLSX generation + * @param {BuyerTradingHistory} tradingHistory: Buyer trading history + * @returns {Array} Array of objects for XLSX generation + */ +const mapOutstandingPayments = (tradingHistory: BuyerTradingHistory) => { + if (tradingHistory[OUTSTANDING_PAYMENTS]) { + const values = { + totalOutstanding: formatCurrency(tradingHistory[TOTAL_OUTSTANDING_PAYMENTS], tradingHistory[CURRENCY_CODE]), + totalAmountOverdue: formatCurrency(tradingHistory[TOTAL_AMOUNT_OVERDUE], tradingHistory[CURRENCY_CODE]), + }; + + const mapped = [ + xlsxRow(String(FIELDS[TOTAL_OUTSTANDING_PAYMENTS]), values.totalOutstanding), + xlsxRow(String(CONTENT_STRINGS[TOTAL_AMOUNT_OVERDUE].SUMMARY?.TITLE), values.totalAmountOverdue), + ]; + + return mapped; + } + + return []; +}; + +export default mapOutstandingPayments; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-previous-cover-with-buyer/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-previous-cover-with-buyer/index.test.ts new file mode 100644 index 0000000000..5c13dba98f --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-previous-cover-with-buyer/index.test.ts @@ -0,0 +1,52 @@ +import mapPreviousCoverWithBuyer from '.'; +import FIELD_IDS from '../../../../constants/field-ids/insurance/your-buyer'; +import { XLSX } from '../../../../content-strings'; +import xlsxRow from '../../helpers/xlsx-row'; +import { mockBuyerRelationship } from '../../../../test-mocks/mock-buyer'; + +const { HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER } = FIELD_IDS; + +const { FIELDS } = XLSX; + +describe('api/generate-xlsx/map-application-to-xlsx/map-previous-cover-with-buyer', () => { + describe(`when buyer relationship has a ${HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER} value of true`, () => { + it('should return an xlsxRow', () => { + const mockRelationship = { + ...mockBuyerRelationship, + [HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]: true, + }; + + const result = mapPreviousCoverWithBuyer(mockRelationship); + + const expected = xlsxRow(String(FIELDS[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]), mockRelationship[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]); + + expect(result).toEqual(expected); + }); + }); + + describe(`when buyer relationship has a ${HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER} value of false`, () => { + it('should not return anything', () => { + const mockRelationship = { + ...mockBuyerRelationship, + [HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]: false, + }; + + const result = mapPreviousCoverWithBuyer(mockRelationship); + + expect(result).toBeUndefined(); + }); + }); + + describe(`when buyer relationship has a ${HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER} value of undefined`, () => { + it('should not return anything', () => { + const mockRelationship = { + ...mockBuyerRelationship, + [HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]: undefined, + }; + + const result = mapPreviousCoverWithBuyer(mockRelationship); + + expect(result).toBeUndefined(); + }); + }); +}); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-previous-cover-with-buyer/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-previous-cover-with-buyer/index.ts new file mode 100644 index 0000000000..1a723ae56f --- /dev/null +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-previous-cover-with-buyer/index.ts @@ -0,0 +1,22 @@ +import FIELD_IDS from '../../../../constants/field-ids/insurance/your-buyer'; +import { XLSX } from '../../../../content-strings'; +import xlsxRow from '../../helpers/xlsx-row'; +import { ApplicationBuyerRelationship } from '../../../../types'; + +const { HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER, PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER } = FIELD_IDS; + +const { FIELDS } = XLSX; + +/** + * mapPreviousCoverWithBuyer + * Generate an XLSX row if an exporter has "previous cover" with the buyer. + * @param {ApplicationBuyerRelationship} relationship: Application buyer relationship + * @returns {Object | undefined} xlsxRow + */ +const mapPreviousCoverWithBuyer = (relationship: ApplicationBuyerRelationship) => { + if (relationship[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]) { + return xlsxRow(String(FIELDS[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]), relationship[PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]); + } +}; + +export default mapPreviousCoverWithBuyer; diff --git a/src/api/test-mocks/mock-buyer.ts b/src/api/test-mocks/mock-buyer.ts index f1cb7e0f0c..3130ee5817 100644 --- a/src/api/test-mocks/mock-buyer.ts +++ b/src/api/test-mocks/mock-buyer.ts @@ -1,24 +1,46 @@ import dotenv from 'dotenv'; +import { GBP } from './mock-currencies'; dotenv.config(); +export const mockBuyerRelationship = { + id: 'clav8by1g0000kgoq5a2afr1b', + exporterIsConnectedWithBuyer: true, + connectionWithBuyerDescription: 'Mock connection with buyer description', + exporterHasPreviousCreditInsuranceWithBuyer: true, + exporterHasBuyerFinancialAccounts: true, + previousCreditInsuranceWithBuyerDescription: 'Mock previous credit insurance description', +}; + +export const mockBuyerTradingHistory = { + id: 'clav8by1g0000kgoq5a2afr1c', + currencyCode: GBP.isoCode, + outstandingPayments: true, + failedPayments: true, + exporterHasTradedWithBuyer: true, + totalOutstandingPayments: 100, + totalOverduePayments: 200, +}; + const mockBuyer = { - companyOrOrganisationName: 'Test name', address: 'Test address', + buyerTradingHistory: mockBuyerTradingHistory, + companyOrOrganisationName: 'Test name', + canContactBuyer: true, + contactFirstName: 'Bob', + contactLastName: 'Smith', + contactPosition: 'CEO', + contactEmail: process.env.GOV_NOTIFY_EMAIL_RECIPIENT_1, country: { id: 'clav8by1g0000kgoq5a2afr1a', isoCode: 'GBR', name: 'United Kingdom', }, - registrationNumber: '1234', - website: 'www.gov.uk', - contactFirstName: 'Bob', - contactLastName: 'Smith', - contactPosition: 'CEO', - contactEmail: process.env.GOV_NOTIFY_EMAIL_RECIPIENT_1, - canContactBuyer: true, exporterIsConnectedWithBuyer: true, exporterHasTradedWithBuyer: true, + registrationNumber: '1234', + relationship: mockBuyerRelationship, + website: 'www.gov.uk', }; export default mockBuyer; From aeb23191478ce0968f91f02c935833e02492280b Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Thu, 30 May 2024 10:55:25 +0100 Subject: [PATCH 15/29] feat(EMS-3344): revert commented code, address todo comments --- src/api/.keystone/config.js | 17 ++++------------- src/api/constants/XLSX-CONFIG/index.ts | 19 +++++++------------ src/api/emails/application/index.ts | 2 +- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 6fcc65651d..678efeadd4 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -3007,6 +3007,7 @@ var application = { if (file) { const fileBuffer = Buffer.from(file); const response = await callNotify(templateId, emailAddress, variables, fileBuffer); + await file_system_default.unlink(filePath); return response; } throw new Error("Sending application submitted email to underwriting team - invalid file / file not found"); @@ -6157,10 +6158,7 @@ var mapExporterBusiness = (application2) => { var map_exporter_business_default = mapExporterBusiness; // generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.ts -var { - CONNECTION_WITH_BUYER: CONNECTION_WITH_BUYER3, - CONNECTION_WITH_BUYER_DESCRIPTION: CONNECTION_WITH_BUYER_DESCRIPTION3 -} = your_buyer_default; +var { CONNECTION_WITH_BUYER: CONNECTION_WITH_BUYER3, CONNECTION_WITH_BUYER_DESCRIPTION: CONNECTION_WITH_BUYER_DESCRIPTION3 } = your_buyer_default; var { FIELDS: FIELDS10 } = XLSX; var mapConnectionWithBuyer = (relationship2) => { if (relationship2[CONNECTION_WITH_BUYER3]) { @@ -6172,11 +6170,7 @@ var map_connection_with_buyer_default = mapConnectionWithBuyer; // generate-xlsx/map-application-to-XLSX/map-buyer/map-outstanding-payments/index.ts var { CURRENCY: { CURRENCY_CODE: CURRENCY_CODE2 }, - YOUR_BUYER: { - OUTSTANDING_PAYMENTS: OUTSTANDING_PAYMENTS3, - TOTAL_OUTSTANDING_PAYMENTS: TOTAL_OUTSTANDING_PAYMENTS3, - TOTAL_AMOUNT_OVERDUE: TOTAL_AMOUNT_OVERDUE2 - } + YOUR_BUYER: { OUTSTANDING_PAYMENTS: OUTSTANDING_PAYMENTS3, TOTAL_OUTSTANDING_PAYMENTS: TOTAL_OUTSTANDING_PAYMENTS3, TOTAL_AMOUNT_OVERDUE: TOTAL_AMOUNT_OVERDUE2 } } = insurance_default; var { FIELDS: FIELDS11 } = XLSX; var mapOutstandingPayments = (tradingHistory) => { @@ -6212,10 +6206,7 @@ var mapBuyerTradingHistory = (tradingHistory) => { var map_buyer_trading_history_default = mapBuyerTradingHistory; // generate-xlsx/map-application-to-XLSX/map-buyer/map-previous-cover-with-buyer/index.ts -var { - HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3, - PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3 -} = your_buyer_default; +var { HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3, PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER: PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3 } = your_buyer_default; var { FIELDS: FIELDS13 } = XLSX; var mapPreviousCoverWithBuyer = (relationship2) => { if (relationship2[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER3]) { diff --git a/src/api/constants/XLSX-CONFIG/index.ts b/src/api/constants/XLSX-CONFIG/index.ts index cdc3439d4c..bec2b0a6fe 100644 --- a/src/api/constants/XLSX-CONFIG/index.ts +++ b/src/api/constants/XLSX-CONFIG/index.ts @@ -14,18 +14,15 @@ const { * Depending on the submitted application data, the rows can be different. * - If the policy type is multiple, the XLSX has 1 additional row. * - If "using a broker" is true, the XLSX has 3 additional rows. - * - If "has different trading address" is true, the XLSX has 1 additional row. - * - If "has different trading name" is true, the XLSX has 1 additional row. - * - If "has different trading name/address" the ALTERNATIVE_TRADING_ADDRESS row needs to change. + * - If "exporter business section - has different trading address" is true, the XLSX has 1 additional row. + * - If "exporter business section - has different trading name" is true, the XLSX has 1 additional row. + * - If "exporter business section - has different trading name/address" the ALTERNATIVE_TRADING_ADDRESS row needs to change. + * - If "buyer section - is connected with buyer" is true, the XLSX has 1 additional row. + * - If "buyer section - traded with buyer before" is true, the XLSX has 4 additional rows. + * - If "buyer section - traded with buyer before" is true and "buyer has outstanding payments" is true, the XLSX has 2 additional rows. + * - If "buyer section - has previous credit insurance cover with buyer" is true, the XLSX has 1 additional row. * @returns {XLSXRowIndexes} */ - -// TODO - updates -// - 3 extra fields regardless -// - if connected with buyer, +1 row -// - if traded with buyer, +4 rows -// - if has previous credit insurance cover with buyer, +1 row - export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { const { broker, @@ -63,8 +60,6 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { if (hasDifferentTradingAddress) { indexes.ALTERNATIVE_TRADING_ADDRESS = 37; - // TODO: after other sections are complete, rename incrementIndexes? - // incrementIndexes is only applicable to certain fields/sections. indexes = incrementIndexes(indexes); } diff --git a/src/api/emails/application/index.ts b/src/api/emails/application/index.ts index cb4bb7a584..3ec532342f 100644 --- a/src/api/emails/application/index.ts +++ b/src/api/emails/application/index.ts @@ -54,7 +54,7 @@ const application = { * NOTE: no need to handle an error from fs.unlink here. * If this errors, it will go into the catch handler below. */ - // await fileSystem.unlink(filePath); + await fileSystem.unlink(filePath); return response; } From 29a30c2b3c667319054cc9eeef118247b1b4445e Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Thu, 30 May 2024 14:53:03 +0100 Subject: [PATCH 16/29] feat(EMS-3344): no pdf - application submission - XLSX - improve test coverage --- .../insurance/assert-currency-form-fields.js | 35 +++------- ...te-and-submit-alternative-currency-form.js | 12 +--- .../insurance/complete-buyer-section.js | 10 +++ .../complete-multiple-contract-policy-form.js | 14 ++-- ...pplication-section-multiple-policy-type.js | 3 + ...-application-section-single-policy-type.js | 3 + ...plete-sign-in-and-submit-an-application.js | 4 ++ .../complete-single-contract-policy-form.js | 10 +-- ...ve-currency-radio-and-complete-currency.js | 13 ++++ ...tive-currency-radio-and-submit-currency.js | 13 ++++ .../complete-alternative-currency-field.js | 18 +++++ .../commands/shared-commands/form/index.js | 5 ++ ...policy-type-buyer-fully-populated.spec.js} | 0 ...y-type-buyer-no-financial-accounts.spec.js | 26 ++++++++ ...-connection-and-traded-with-buyer.spec.js} | 0 ...policy-type-connection-with-buyer.spec.js} | 0 ...ding-payments-alternative-currency.spec.js | 29 ++++++++ ...y-type-buyer-no-financial-accounts.spec.js | 23 +++++++ ...ding-payments-alternative-currency.spec.js | 26 ++++++++ .../currency-form-fields/assertions.js | 36 ++++------ src/api/.keystone/config.js | 4 +- .../XLSX-CONFIG/INDEXES/index.test.ts | 2 +- ...e-contract-policy-buyer-conditions.test.ts | 41 ++++++++++++ ...ions-or-different-trading-details.test.ts} | 14 ++-- ...ple-contract-policy-using-a-broker.test.ts | 24 +++---- ...e-contract-policy-buyer-conditions.test.ts | 38 +++++++++++ ...ions-or-different-trading-details.test.ts} | 13 ++-- ...gle-contract-policy-using-a-broker.test.ts | 16 ++--- src/api/constants/XLSX-CONFIG/index.test.ts | 66 +------------------ src/api/constants/XLSX-CONFIG/index.ts | 3 +- src/api/emails/application/index.ts | 2 +- src/api/test-mocks/index.ts | 27 ++++++-- 32 files changed, 342 insertions(+), 188 deletions(-) create mode 100644 e2e-tests/commands/shared-commands/form/click-alternative-currency-radio-and-complete-currency.js create mode 100644 e2e-tests/commands/shared-commands/form/click-alternative-currency-radio-and-submit-currency.js create mode 100644 e2e-tests/commands/shared-commands/form/complete-alternative-currency-field.js rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/{submit-an-application-single-policy-type-buyer-fully-populated.spec.js => submit-an-application-multiple-policy-type-buyer-fully-populated.spec.js} (100%) create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-buyer-no-financial-accounts.spec.js rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/{submit-an-application-single-policy-type-connection-and-traded-with-buyer.spec.js => submit-an-application-multiple-policy-type-connection-and-traded-with-buyer.spec.js} (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/{submit-an-application-single-policy-type-connection-with-buyer.spec.js => submit-an-application-multiple-policy-type-connection-with-buyer.spec.js} (100%) create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-alternative-currency.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-no-financial-accounts.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-alternative-currency.spec.js create mode 100644 src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-buyer-conditions.test.ts rename src/api/constants/XLSX-CONFIG/{index-multiple-contract-policy-no-broker-or-different-trading-details.test.ts => index-multiple-contract-policy-no-broker-buyer-conditions-or-different-trading-details.test.ts} (71%) create mode 100644 src/api/constants/XLSX-CONFIG/index-single-contract-policy-buyer-conditions.test.ts rename src/api/constants/XLSX-CONFIG/{index-single-contract-policy-no-broker-or-different-trading-details.test.ts => index-single-contract-policy-no-broker-buyer-conditions-or-different-trading-details.test.ts} (64%) diff --git a/e2e-tests/commands/insurance/assert-currency-form-fields.js b/e2e-tests/commands/insurance/assert-currency-form-fields.js index a1ff26ab95..22aab682d1 100644 --- a/e2e-tests/commands/insurance/assert-currency-form-fields.js +++ b/e2e-tests/commands/insurance/assert-currency-form-fields.js @@ -1,18 +1,13 @@ import { INSURANCE_FIELD_IDS } from '../../constants/field-ids/insurance'; import { field as fieldSelector, radios, autoCompleteField } from '../../pages/shared'; -import { - EUR, - GBP, - JPY, - USD, - NON_STANDARD_CURRENCY_CODE, - NON_STANDARD_CURRENCY_NAME, -} from '../../fixtures/currencies'; +import { EUR, GBP, JPY, USD, NON_STANDARD_CURRENCY_CODE, NON_STANDARD_CURRENCY_NAME } from '../../fixtures/currencies'; import { checkAutocompleteInput } from '../../shared-test-assertions'; import { DZA } from '../../fixtures/countries'; import partials from '../../partials'; -const { CURRENCY: { CURRENCY_CODE, ALTERNATIVE_CURRENCY_CODE } } = INSURANCE_FIELD_IDS; +const { + CURRENCY: { CURRENCY_CODE, ALTERNATIVE_CURRENCY_CODE }, +} = INSURANCE_FIELD_IDS; /** * returns field for currency/alternative currency @@ -107,8 +102,7 @@ const assertCurrencyFormFields = ({ checkAutocompleteInput.rendersMultipleResults(autoCompleteField(alternativeCurrencyFieldId), 'Be'); const expectedValue = `${NON_STANDARD_CURRENCY_NAME} (${NON_STANDARD_CURRENCY_CODE})`; - checkAutocompleteInput - .allowsUserToRemoveCountryAndSearchAgain(alternativeCurrencyFieldId, DZA.NAME, NON_STANDARD_CURRENCY_NAME, expectedValue); + checkAutocompleteInput.allowsUserToRemoveCountryAndSearchAgain(alternativeCurrencyFieldId, DZA.NAME, NON_STANDARD_CURRENCY_NAME, expectedValue); }, rendersAlternativeCurrencyValidationError: ({ errorIndex = 0 }) => { cy.clickAlternativeCurrencyRadioOption(); @@ -119,15 +113,9 @@ const assertCurrencyFormFields = ({ cy.assertRadioOptionIsChecked(option.input()); - cy.checkText( - partials.errorSummaryListItems().eq(errorIndex), - errors[alternativeCurrencyFieldId].IS_EMPTY, - ); + cy.checkText(partials.errorSummaryListItems().eq(errorIndex), errors[alternativeCurrencyFieldId].IS_EMPTY); - cy.checkText( - fieldSelector(alternativeCurrencyFieldId).errorMessage(), - `Error: ${errors[alternativeCurrencyFieldId].IS_EMPTY}`, - ); + cy.checkText(fieldSelector(alternativeCurrencyFieldId).errorMessage(), `Error: ${errors[alternativeCurrencyFieldId].IS_EMPTY}`); }, submitRadioAndAssertUrl: ({ currency, url, completeNonCurrencyFields }) => { if (completeNonCurrencyFields) { @@ -156,12 +144,9 @@ const assertCurrencyFormFields = ({ cy.assertRadioOptionIsChecked(option.input()); }, submitAlternativeCurrencyAndAssertUrl: (url) => { - cy.clickAlternativeCurrencyRadioOption(); - - // search for currency - cy.autocompleteKeyboardInput(alternativeCurrencyFieldId, NON_STANDARD_CURRENCY_NAME); - - cy.clickSubmitButton(); + cy.clickAlternativeCurrencyRadioAndSubmitCurrency({ + fieldId: alternativeCurrencyFieldId, + }); cy.url().should('include', url); }, diff --git a/e2e-tests/commands/insurance/complete-and-submit-alternative-currency-form.js b/e2e-tests/commands/insurance/complete-and-submit-alternative-currency-form.js index 83fe2bcee0..432a7a8eb5 100644 --- a/e2e-tests/commands/insurance/complete-and-submit-alternative-currency-form.js +++ b/e2e-tests/commands/insurance/complete-and-submit-alternative-currency-form.js @@ -1,8 +1,7 @@ -import { NON_STANDARD_CURRENCY_CODE } from '../../fixtures/currencies'; import { radios } from '../../pages/shared'; import { INSURANCE_FIELD_IDS } from '../../constants/field-ids/insurance'; -const { CURRENCY_CODE, ALTERNATIVE_CURRENCY_CODE } = INSURANCE_FIELD_IDS.CURRENCY; +const { CURRENCY_CODE } = INSURANCE_FIELD_IDS.CURRENCY; /** * completeAndSubmitAlternativeCurrencyForm @@ -23,14 +22,7 @@ const completeAndSubmitAlternativeCurrencyForm = ({ isoCode, alternativeCurrency if (alternativeCurrency) { cy.clickProvideAlternativeCurrencyLink(); - /** - * clicks alternativeCurrency radio option - * enters alternative currency into input - * submits form - */ - cy.clickAlternativeCurrencyRadioOption(); - cy.autocompleteKeyboardInput(ALTERNATIVE_CURRENCY_CODE, NON_STANDARD_CURRENCY_CODE); - cy.clickSubmitButton(); + cy.clickAlternativeCurrencyRadioAndSubmitCurrency({}); } }; diff --git a/e2e-tests/commands/insurance/complete-buyer-section.js b/e2e-tests/commands/insurance/complete-buyer-section.js index 6af0fcaab9..fdad46c324 100644 --- a/e2e-tests/commands/insurance/complete-buyer-section.js +++ b/e2e-tests/commands/insurance/complete-buyer-section.js @@ -2,6 +2,7 @@ * completeBuyerSection * Complete the "Buyer" section * @param {Boolean} viaTaskList: Start the "buyer" section from the task list. + * @param {Boolean} alternativeCurrency: Should submit an "alternative currency". Defaults to false. * @param {Boolean} hasConnectionToBuyer: Should submit "yes" to "have connection to buyer" radio. Defaults to "no". * @param {Boolean} exporterHasTradedWithBuyer: Submit "yes" to "have traded with buyer before" in the "working with buyer" form. * @param {Boolean} outstandingPayments: Exporter has outstanding payments with the buyer @@ -14,6 +15,7 @@ */ const completeBuyerSection = ({ viaTaskList = true, + alternativeCurrency = false, hasConnectionToBuyer = false, exporterHasTradedWithBuyer = false, outstandingPayments = false, @@ -31,6 +33,14 @@ const completeBuyerSection = ({ cy.completeAndSubmitTradedWithBuyerForm({ exporterHasTradedWithBuyer }); if (exporterHasTradedWithBuyer) { + cy.clickYesRadioInput(); + + if (alternativeCurrency) { + cy.clickProvideAlternativeCurrencyLink(); + + cy.clickAlternativeCurrencyRadioAndSubmitCurrency({}); + } + cy.completeAndSubmitTradingHistoryWithBuyerForm({ outstandingPayments: outstandingPayments || fullyPopulatedBuyerTradingHistory, failedToPay: failedToPay || fullyPopulatedBuyerTradingHistory, diff --git a/e2e-tests/commands/insurance/complete-multiple-contract-policy-form.js b/e2e-tests/commands/insurance/complete-multiple-contract-policy-form.js index d95828cdf3..2955ca8ce4 100644 --- a/e2e-tests/commands/insurance/complete-multiple-contract-policy-form.js +++ b/e2e-tests/commands/insurance/complete-multiple-contract-policy-form.js @@ -3,7 +3,7 @@ import { radios, field } from '../../pages/shared'; import application from '../../fixtures/application'; const { - CURRENCY: { CURRENCY_CODE, ALTERNATIVE_CURRENCY_CODE }, + CURRENCY: { CURRENCY_CODE }, POLICY: { CONTRACT_POLICY: { REQUESTED_START_DATE, @@ -20,11 +20,7 @@ const { * @param {Boolean} alternativeCurrency: Select the "alternative currency" option * @param {Boolean} chooseCurrency: Whether to choose a currency or not */ -const completeMultipleContractPolicyForm = ({ - isoCode = application.POLICY[POLICY_CURRENCY_CODE], - alternativeCurrency = false, - chooseCurrency = true, -}) => { +const completeMultipleContractPolicyForm = ({ isoCode = application.POLICY[POLICY_CURRENCY_CODE], alternativeCurrency = false, chooseCurrency = true }) => { cy.keyboardInput(field(REQUESTED_START_DATE).dayInput(), application.POLICY[REQUESTED_START_DATE].day); cy.keyboardInput(field(REQUESTED_START_DATE).monthInput(), application.POLICY[REQUESTED_START_DATE].month); cy.keyboardInput(field(REQUESTED_START_DATE).yearInput(), application.POLICY[REQUESTED_START_DATE].year); @@ -33,9 +29,9 @@ const completeMultipleContractPolicyForm = ({ if (chooseCurrency) { if (alternativeCurrency) { - cy.clickAlternativeCurrencyRadioOption(); - - cy.autocompleteKeyboardInput(ALTERNATIVE_CURRENCY_CODE, isoCode); + cy.clickAlternativeCurrencyRadioAndCompleteCurrency({ + currency: isoCode, + }); } else { radios(CURRENCY_CODE, isoCode).option.label().click(); } diff --git a/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js b/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js index 7c607a5126..cbed85b390 100644 --- a/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js +++ b/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js @@ -6,6 +6,7 @@ const { POLICY_TYPE } = APPLICATION; * completePrepareApplicationMultiplePolicyType * Runs through the full prepare your application journey for multiple policy type * @param {Object} Object with flags on how to complete specific parts of the application + * @param {Boolean} alternativeBuyerCurrency: Should submit an "alternative currency" in the buyer section. Defaults to false. * @param {Boolean} differentTradingName: Should submit "yes" to "have a different trading name" in the "company details" form. Defaults to false. * @param {Boolean} differentTradingAddress: Should submit "yes" to "trade from a different address" in the "company details" form. Defaults to false. * @param {Boolean} hasCreditControlProcess: Flag whether to submit "yes" or "no" radio input in the "credit control" form. Defaults to false. @@ -32,6 +33,7 @@ const { POLICY_TYPE } = APPLICATION; * @param {Boolean} submitCheckYourAnswers: Should click each section's "check your answers" submit button. */ const completePrepareApplicationMultiplePolicyType = ({ + alternativeBuyerCurrency = false, differentTradingName = false, differentTradingAddress = false, hasCreditControlProcess = false, @@ -65,6 +67,7 @@ const completePrepareApplicationMultiplePolicyType = ({ }); cy.completeBuyerSection({ + alternativeBuyerCurrency, hasConnectionToBuyer, exporterHasTradedWithBuyer, outstandingPayments: buyerOutstandingPayments, diff --git a/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js b/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js index a6f6f1a946..0fa74a467b 100644 --- a/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js +++ b/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js @@ -6,6 +6,7 @@ const { POLICY_TYPE } = FIELD_VALUES; * completePrepareYourApplicationSectionSingle * Runs through the full prepare your application journey for a single policy type * @param {Object} Object with flags on how to complete specific parts of the application + * @param {Boolean} alternativeBuyerCurrency: Should submit an "alternative currency" in the buyer section. Defaults to false. * @param {Boolean} differentTradingName: Should submit "yes" to "have a different trading name" in the "company details" form. Defaults to false. * @param {Boolean} differentTradingAddress: Should submit "yes" to "trade from a different address" in the "company details" form. Defaults to false. * @param {Boolean} hasCreditControlProcess: Flag whether to submit "yes" or "no" radio input in the "credit control" form. Defaults to false. @@ -32,6 +33,7 @@ const { POLICY_TYPE } = FIELD_VALUES; * @param {Boolean} submitCheckYourAnswers: Should click each section's "check your answers" submit button. */ const completePrepareApplicationSinglePolicyType = ({ + alternativeBuyerCurrency = false, differentTradingName = false, differentTradingAddress = false, hasCreditControlProcess = false, @@ -65,6 +67,7 @@ const completePrepareApplicationSinglePolicyType = ({ }); cy.completeBuyerSection({ + alternativeCurrency: alternativeBuyerCurrency, hasConnectionToBuyer, exporterHasTradedWithBuyer, outstandingPayments: buyerOutstandingPayments, diff --git a/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js b/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js index 704ce30b18..80ee9f5735 100644 --- a/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js +++ b/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js @@ -8,6 +8,7 @@ import completeSignInAndGoToApplication from './account/complete-sign-in-and-go- * 3) Complete and submit all declarations forms * 4) Get and return the application reference number from the URL for consumption in the tests * @param {Object} Object with flags on how to complete specific parts of the application + * - alternativeBuyerCurrency: Should submit an "alternative currency" in the buyer section. Defaults to false. * - differentTradingAddress: Should submit "yes" to "trade from a different address" in the "your business - company details" form. Defaults to false. * - policyType: Type of policy. Defaults to "single" * - exporterHasTradedWithBuyer: Should submit "yes" to "have traded with buyer before" in the "working with buyer" form. Defaults to "yes". @@ -32,6 +33,7 @@ import completeSignInAndGoToApplication from './account/complete-sign-in-and-go- * @return {String} Application reference number */ const completeSignInAndSubmitAnApplication = ({ + alternativeBuyerCurrency = false, differentTradingName = false, differentTradingAddress = false, policyType = APPLICATION.POLICY_TYPE.SINGLE, @@ -59,6 +61,7 @@ const completeSignInAndSubmitAnApplication = ({ completeSignInAndGoToApplication({ totalContractValueOverThreshold }).then(({ referenceNumber }) => { if (policyType === APPLICATION.POLICY_TYPE.MULTIPLE) { cy.completePrepareApplicationMultiplePolicyType({ + alternativeBuyerCurrency, differentTradingName, differentTradingAddress, exporterHasTradedWithBuyer, @@ -83,6 +86,7 @@ const completeSignInAndSubmitAnApplication = ({ }); } else { cy.completePrepareApplicationSinglePolicyType({ + alternativeBuyerCurrency, differentTradingName, differentTradingAddress, exporterHasTradedWithBuyer, diff --git a/e2e-tests/commands/insurance/complete-single-contract-policy-form.js b/e2e-tests/commands/insurance/complete-single-contract-policy-form.js index 3b4a2eccd5..43b0f6f813 100644 --- a/e2e-tests/commands/insurance/complete-single-contract-policy-form.js +++ b/e2e-tests/commands/insurance/complete-single-contract-policy-form.js @@ -3,7 +3,7 @@ import { radios, field } from '../../pages/shared'; import application from '../../fixtures/application'; const { - CURRENCY: { CURRENCY_CODE, ALTERNATIVE_CURRENCY_CODE }, + CURRENCY: { CURRENCY_CODE }, POLICY: { CONTRACT_POLICY: { REQUESTED_START_DATE, @@ -20,11 +20,7 @@ const { * @param {Boolean} alternativeCurrency: Select the "alternative currency" option * @param {Boolean} chooseCurrency: Whether to choose a currency or not */ -const completeSingleContractPolicyForm = ({ - isoCode = application.POLICY[POLICY_CURRENCY_CODE], - alternativeCurrency = false, - chooseCurrency = true, -}) => { +const completeSingleContractPolicyForm = ({ isoCode = application.POLICY[POLICY_CURRENCY_CODE], alternativeCurrency = false, chooseCurrency = true }) => { cy.keyboardInput(field(REQUESTED_START_DATE).dayInput(), application.POLICY[REQUESTED_START_DATE].day); cy.keyboardInput(field(REQUESTED_START_DATE).monthInput(), application.POLICY[REQUESTED_START_DATE].month); cy.keyboardInput(field(REQUESTED_START_DATE).yearInput(), application.POLICY[REQUESTED_START_DATE].year); @@ -37,7 +33,7 @@ const completeSingleContractPolicyForm = ({ if (alternativeCurrency) { cy.clickAlternativeCurrencyRadioOption(); - cy.autocompleteKeyboardInput(ALTERNATIVE_CURRENCY_CODE, isoCode); + cy.completeAlternativeCurrencyField({ currency: isoCode }); } else { radios(CURRENCY_CODE, isoCode).option.label().click(); } diff --git a/e2e-tests/commands/shared-commands/form/click-alternative-currency-radio-and-complete-currency.js b/e2e-tests/commands/shared-commands/form/click-alternative-currency-radio-and-complete-currency.js new file mode 100644 index 0000000000..d3ece9eeae --- /dev/null +++ b/e2e-tests/commands/shared-commands/form/click-alternative-currency-radio-and-complete-currency.js @@ -0,0 +1,13 @@ +/** + * clickAlternativeCurrencyRadioAndCompleteCurrency + * Click an "alternative currency" radio and complete the "currency" field. + * @param {String} fieldId: Field ID + * @param {String} currency: Currency + */ +const clickAlternativeCurrencyRadioAndCompleteCurrency = ({ fieldId, currency }) => { + cy.clickAlternativeCurrencyRadioOption(); + + cy.completeAlternativeCurrencyField({ fieldId, currency }); +}; + +export default clickAlternativeCurrencyRadioAndCompleteCurrency; diff --git a/e2e-tests/commands/shared-commands/form/click-alternative-currency-radio-and-submit-currency.js b/e2e-tests/commands/shared-commands/form/click-alternative-currency-radio-and-submit-currency.js new file mode 100644 index 0000000000..0194e31186 --- /dev/null +++ b/e2e-tests/commands/shared-commands/form/click-alternative-currency-radio-and-submit-currency.js @@ -0,0 +1,13 @@ +/** + * clickAlternativeCurrencyRadioAndSubmitCurrency + * Complete and submit an "alternative currency" field + * @param {String} fieldId: Field ID + * @param {String} currency: Currency + */ +const clickAlternativeCurrencyRadioAndSubmitCurrency = ({ fieldId, currency }) => { + cy.clickAlternativeCurrencyRadioAndCompleteCurrency({ fieldId, currency }); + + cy.clickSubmitButton(); +}; + +export default clickAlternativeCurrencyRadioAndSubmitCurrency; diff --git a/e2e-tests/commands/shared-commands/form/complete-alternative-currency-field.js b/e2e-tests/commands/shared-commands/form/complete-alternative-currency-field.js new file mode 100644 index 0000000000..fa9be4094c --- /dev/null +++ b/e2e-tests/commands/shared-commands/form/complete-alternative-currency-field.js @@ -0,0 +1,18 @@ +import { INSURANCE_FIELD_IDS } from '../../../constants/field-ids/insurance'; +import { NON_STANDARD_CURRENCY_NAME } from '../../../fixtures/currencies'; + +const { + CURRENCY: { ALTERNATIVE_CURRENCY_CODE }, +} = INSURANCE_FIELD_IDS; + +/** + * completeAlternativeCurrencyField + * Complete an "alternative currency" field + * @param {String} fieldId: Field ID. Defaults to ALTERNATIVE_CURRENCY_CODE + * @param {String} currency: Currency. Defaults to NON_STANDARD_CURRENCY_NAME + */ +const completeAlternativeCurrencyField = ({ fieldId = ALTERNATIVE_CURRENCY_CODE, currency = NON_STANDARD_CURRENCY_NAME }) => { + cy.autocompleteKeyboardInput(fieldId, currency); +}; + +export default completeAlternativeCurrencyField; diff --git a/e2e-tests/commands/shared-commands/form/index.js b/e2e-tests/commands/shared-commands/form/index.js index 41f4fd9a62..e7887f3af3 100644 --- a/e2e-tests/commands/shared-commands/form/index.js +++ b/e2e-tests/commands/shared-commands/form/index.js @@ -1,6 +1,11 @@ Cypress.Commands.add('changeAnswerField', require('./change-answer-field')); Cypress.Commands.add('changeAnswerSelectField', require('./change-answer-select-field')); Cypress.Commands.add('changeAnswerRadioField', require('./change-answer-radio-field')); + +Cypress.Commands.add('completeAlternativeCurrencyField', require('./complete-alternative-currency-field')); +Cypress.Commands.add('clickAlternativeCurrencyRadioAndCompleteCurrency', require('./click-alternative-currency-radio-and-complete-currency')); +Cypress.Commands.add('clickAlternativeCurrencyRadioAndSubmitCurrency', require('./click-alternative-currency-radio-and-submit-currency')); + Cypress.Commands.add('clickSubmitButton', require('./click-submit-button')); Cypress.Commands.add('clickSubmitButtonMultipleTimes', require('./click-submit-button-multiple-times')); Cypress.Commands.add('clickSaveAndBackButton', require('./click-save-and-back-button')); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-fully-populated.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-buyer-fully-populated.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-fully-populated.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-buyer-fully-populated.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-buyer-no-financial-accounts.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-buyer-no-financial-accounts.spec.js new file mode 100644 index 0000000000..780ace3ee6 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-buyer-no-financial-accounts.spec.js @@ -0,0 +1,26 @@ +import { APPLICATION } from '../../../../../../../constants'; + +context('Insurance - submit an application - Multiple policy type, fully populated buyer', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + exporterHasBuyerFinancialAccounts: false, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-and-traded-with-buyer.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-connection-and-traded-with-buyer.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-and-traded-with-buyer.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-connection-and-traded-with-buyer.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-with-buyer.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-connection-with-buyer.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-single-policy-type-connection-with-buyer.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-connection-with-buyer.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-alternative-currency.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-alternative-currency.spec.js new file mode 100644 index 0000000000..2be67cea87 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-alternative-currency.spec.js @@ -0,0 +1,29 @@ +import { APPLICATION } from '../../../../../../../../constants'; + +context('Insurance - submit an application - Multiple policy type, exporter has traded with buyer, has outstanding payments, alternative currency', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + alternativeBuyerCurrency: true, + exporterHasTradedWithBuyer: true, + buyerOutstandingPayments: true, + buyerFailedToPayOnTime: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-no-financial-accounts.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-no-financial-accounts.spec.js new file mode 100644 index 0000000000..b37cbf19ba --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-no-financial-accounts.spec.js @@ -0,0 +1,23 @@ +context('Insurance - submit an application - Single policy type, fully populated buyer', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + exporterHasBuyerFinancialAccounts: false, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-alternative-currency.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-alternative-currency.spec.js new file mode 100644 index 0000000000..dc04a1f464 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-alternative-currency.spec.js @@ -0,0 +1,26 @@ +context('Insurance - submit an application - Single policy type, exporter has traded with buyer, has outstanding payments, alternative currency', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + alternativeBuyerCurrency: true, + exporterHasTradedWithBuyer: true, + buyerOutstandingPayments: true, + buyerFailedToPayOnTime: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); +}); diff --git a/e2e-tests/shared-test-assertions/currency-form-fields/assertions.js b/e2e-tests/shared-test-assertions/currency-form-fields/assertions.js index 1f71d8d14a..ff6cb691f0 100644 --- a/e2e-tests/shared-test-assertions/currency-form-fields/assertions.js +++ b/e2e-tests/shared-test-assertions/currency-form-fields/assertions.js @@ -1,18 +1,13 @@ import { INSURANCE_FIELD_IDS } from '../../constants/field-ids/insurance'; import { field as fieldSelector, radios, autoCompleteField } from '../../pages/shared'; -import { - EUR, - GBP, - JPY, - USD, - NON_STANDARD_CURRENCY_CODE, - NON_STANDARD_CURRENCY_NAME, -} from '../../fixtures/currencies'; +import { EUR, GBP, JPY, USD, NON_STANDARD_CURRENCY_CODE, NON_STANDARD_CURRENCY_NAME } from '../../fixtures/currencies'; import { checkAutocompleteInput } from '../autocomplete-assertions'; import { DZA } from '../../fixtures/countries'; import partials from '../../partials'; -const { CURRENCY: { CURRENCY_CODE, ALTERNATIVE_CURRENCY_CODE } } = INSURANCE_FIELD_IDS; +const { + CURRENCY: { CURRENCY_CODE, ALTERNATIVE_CURRENCY_CODE }, +} = INSURANCE_FIELD_IDS; /** * returns field for currency/alternative currency @@ -110,23 +105,16 @@ const assertCurrencyFormFields = ({ checkAutocompleteInput.rendersMultipleResults(autoCompleteField(alternativeCurrencyFieldId), 'Be'); const expectedValue = `${NON_STANDARD_CURRENCY_NAME} (${NON_STANDARD_CURRENCY_CODE})`; - checkAutocompleteInput - .allowsUserToRemoveCountryAndSearchAgain(alternativeCurrencyFieldId, DZA.NAME, NON_STANDARD_CURRENCY_NAME, expectedValue); + checkAutocompleteInput.allowsUserToRemoveCountryAndSearchAgain(alternativeCurrencyFieldId, DZA.NAME, NON_STANDARD_CURRENCY_NAME, expectedValue); }, rendersAlternativeCurrencyValidationError: ({ errorIndex = 0 }) => { cy.clickAlternativeCurrencyRadioOption(); cy.clickSubmitButton(); - cy.checkText( - partials.errorSummaryListItems().eq(errorIndex), - errors[alternativeCurrencyFieldId].IS_EMPTY, - ); + cy.checkText(partials.errorSummaryListItems().eq(errorIndex), errors[alternativeCurrencyFieldId].IS_EMPTY); - cy.checkText( - fieldSelector(alternativeCurrencyFieldId).errorMessage(), - `Error: ${errors[alternativeCurrencyFieldId].IS_EMPTY}`, - ); + cy.checkText(fieldSelector(alternativeCurrencyFieldId).errorMessage(), `Error: ${errors[alternativeCurrencyFieldId].IS_EMPTY}`); }, submitRadioAndAssertUrl: ({ currency, url, completeNonCurrencyFields }) => { if (completeNonCurrencyFields) { @@ -155,12 +143,10 @@ const assertCurrencyFormFields = ({ cy.assertRadioOptionIsChecked(option.input()); }, submitAlternativeCurrencyAndAssertUrl: (url) => { - cy.clickAlternativeCurrencyRadioOption(); - - // search for currency - cy.autocompleteKeyboardInput(alternativeCurrencyFieldId, NON_STANDARD_CURRENCY_NAME); - - cy.clickSubmitButton(); + cy.clickAlternativeCurrencyRadioAndSubmitCurrency({ + fieldId: alternativeCurrencyFieldId, + currency: NON_STANDARD_CURRENCY_NAME, + }); cy.url().should('include', url); }, diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 678efeadd4..26e9e5aa1e 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -849,14 +849,15 @@ var XLSX_ROW_INDEXES = (application2) => { if (isMultiplePolicyType(policyType)) { indexes.TITLES.BUYER += 1; indexes.TITLES.DECLARATIONS += 1; + indexes.BUYER_ADDRESS += 1; indexes.BUYER_CONTACT_DETAILS += 1; } if (broker[USING_BROKER]) { indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; indexes.TITLES.DECLARATIONS += 6; - indexes.BUYER_ADDRESS += 3; indexes.BROKER_ADDRESS = 48; + indexes.BUYER_ADDRESS += 3; } if (hasDifferentTradingAddress) { indexes.ALTERNATIVE_TRADING_ADDRESS = 37; @@ -3007,7 +3008,6 @@ var application = { if (file) { const fileBuffer = Buffer.from(file); const response = await callNotify(templateId, emailAddress, variables, fileBuffer); - await file_system_default.unlink(filePath); return response; } throw new Error("Sending application submitted email to underwriting team - invalid file / file not found"); diff --git a/src/api/constants/XLSX-CONFIG/INDEXES/index.test.ts b/src/api/constants/XLSX-CONFIG/INDEXES/index.test.ts index 155fc07c2b..edfb685064 100644 --- a/src/api/constants/XLSX-CONFIG/INDEXES/index.test.ts +++ b/src/api/constants/XLSX-CONFIG/INDEXES/index.test.ts @@ -12,7 +12,7 @@ describe('api/constants/XLSX-CONFIG/INDEXES', () => { EXPORTER_BUSINESS: 31, POLICY: 48, BUYER: 57, - DECLARATIONS: 65, + DECLARATIONS: 67, }; expect(TITLE_INDEXES()).toEqual(expected); diff --git a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-buyer-conditions.test.ts b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-buyer-conditions.test.ts new file mode 100644 index 0000000000..9f205ad95a --- /dev/null +++ b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-buyer-conditions.test.ts @@ -0,0 +1,41 @@ +import { XLSX_ROW_INDEXES } from '.'; +import { INDEXES } from './INDEXES'; +import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; +import { APPLICATION } from '../application'; +import { mockApplicationMinimalBrokerBuyerAndCompany, mockApplication } from '../../test-mocks'; + +const { + TYPE_OF_POLICY: { POLICY_TYPE }, +} = POLICY_FIELD_IDS; + +const application = { + ...mockApplicationMinimalBrokerBuyerAndCompany, + policy: { + ...mockApplicationMinimalBrokerBuyerAndCompany, + [POLICY_TYPE]: APPLICATION.POLICY_TYPE.MULTIPLE, + }, + buyer: mockApplication.buyer, +}; + +describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.MULTIPLE} - all buyer conditions`, () => { + describe('with all possible buyer conditions (connected and traded with buyer, outstanding payments, previous credit insurance)', () => { + it('should return the correct row indexes', () => { + const result = XLSX_ROW_INDEXES(application); + + const indexes = INDEXES(); + + const expected = { + ...indexes, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1, + BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, + TITLES: { + ...indexes.TITLES, + BUYER: indexes.TITLES.BUYER + 1, + DECLARATIONS: indexes.TITLES.DECLARATIONS + 7, + }, + }; + + expect(result).toEqual(expected); + }); + }); +}); diff --git a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-or-different-trading-details.test.ts b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-buyer-conditions-or-different-trading-details.test.ts similarity index 71% rename from src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-or-different-trading-details.test.ts rename to src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-buyer-conditions-or-different-trading-details.test.ts index 46d203a298..8a8cc24246 100644 --- a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-or-different-trading-details.test.ts +++ b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-no-broker-buyer-conditions-or-different-trading-details.test.ts @@ -2,26 +2,21 @@ import { XLSX_ROW_INDEXES } from '.'; import { INDEXES } from './INDEXES'; import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; import { APPLICATION } from '../application'; -import { mockApplication, mockCompanyScenarios } from '../../test-mocks'; +import { mockApplicationMinimalBrokerBuyerAndCompany } from '../../test-mocks'; const { TYPE_OF_POLICY: { POLICY_TYPE }, } = POLICY_FIELD_IDS; const application = { - ...mockApplication, + ...mockApplicationMinimalBrokerBuyerAndCompany, policy: { - ...mockApplication.policy, + ...mockApplicationMinimalBrokerBuyerAndCompany.policy, [POLICY_TYPE]: APPLICATION.POLICY_TYPE.MULTIPLE, }, - broker: { - ...mockApplication.broker, - isUsingBroker: false, - }, - company: mockCompanyScenarios.noDifferentTradingNameOrAddress, }; -describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.MULTIPLE} - not using a broker, no different trading details`, () => { +describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.MULTIPLE} - not using a broker, no buyer conditions, no different trading details`, () => { it('should return default multiple contract policy row indexes', () => { const result = XLSX_ROW_INDEXES(application); @@ -29,6 +24,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...indexes, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1, BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, TITLES: { ...indexes.TITLES, diff --git a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts index 3b091c3399..1df6c30a08 100644 --- a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts +++ b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts @@ -2,7 +2,7 @@ import { XLSX_ROW_INDEXES } from '.'; import { incrementIndexes, INDEXES } from './INDEXES'; import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; import { APPLICATION } from '../application'; -import { mockApplication, mockCompanyScenarios } from '../../test-mocks'; +import { mockApplicationMinimalBrokerBuyerAndCompany, mockCompanyScenarios } from '../../test-mocks'; const { TYPE_OF_POLICY: { POLICY_TYPE }, @@ -10,13 +10,13 @@ const { } = POLICY_FIELD_IDS; const application = { - ...mockApplication, + ...mockApplicationMinimalBrokerBuyerAndCompany, policy: { - ...mockApplication.policy, + ...mockApplicationMinimalBrokerBuyerAndCompany.policy, [POLICY_TYPE]: APPLICATION.POLICY_TYPE.MULTIPLE, }, broker: { - ...mockApplication.broker, + ...mockApplicationMinimalBrokerBuyerAndCompany.broker, isUsingBroker: true, }, }; @@ -30,14 +30,14 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...indexes, - BUYER_ADDRESS: indexes.BUYER_ADDRESS + 3, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 4, BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, BROKER_ADDRESS: 48, TITLES: { ...indexes.TITLES, POLICY: indexes.TITLES.POLICY + 3, BUYER: indexes.TITLES.BUYER + 4, - DECLARATIONS: indexes.TITLES.DECLARATIONS + 4, + DECLARATIONS: indexes.TITLES.DECLARATIONS + 7, }, }; @@ -56,14 +56,14 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...incremented, - BUYER_ADDRESS: indexes.BUYER_ADDRESS + 3, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 4, BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, BROKER_ADDRESS: 49, TITLES: { ...incremented.TITLES, POLICY: incremented.TITLES.POLICY + 3, BUYER: incremented.TITLES.BUYER + 4, - DECLARATIONS: incremented.TITLES.DECLARATIONS + 4, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 7, }, }; @@ -86,7 +86,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...incremented, - BUYER_ADDRESS: indexes.BUYER_ADDRESS + 3, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 4, BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, BROKER_ADDRESS: 49, ALTERNATIVE_TRADING_ADDRESS: 37, @@ -94,7 +94,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...incremented.TITLES, POLICY: incremented.TITLES.POLICY + 3, BUYER: incremented.TITLES.BUYER + 4, - DECLARATIONS: incremented.TITLES.DECLARATIONS + 4, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 7, }, }; @@ -114,7 +114,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY const expected = { ...secondIncrement, - BUYER_ADDRESS: indexes.BUYER_ADDRESS + 3, + BUYER_ADDRESS: indexes.BUYER_ADDRESS + 4, BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1, BROKER_ADDRESS: 50, ALTERNATIVE_TRADING_ADDRESS: 38, @@ -122,7 +122,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...secondIncrement.TITLES, POLICY: incremented.TITLES.POLICY + 3, BUYER: incremented.TITLES.BUYER + 4, - DECLARATIONS: incremented.TITLES.DECLARATIONS + 4, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 7, }, }; diff --git a/src/api/constants/XLSX-CONFIG/index-single-contract-policy-buyer-conditions.test.ts b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-buyer-conditions.test.ts new file mode 100644 index 0000000000..334c177149 --- /dev/null +++ b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-buyer-conditions.test.ts @@ -0,0 +1,38 @@ +import { XLSX_ROW_INDEXES } from '.'; +import { INDEXES } from './INDEXES'; +import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; +import { APPLICATION } from '../application'; +import { mockApplicationMinimalBrokerBuyerAndCompany, mockApplication } from '../../test-mocks'; + +const { + TYPE_OF_POLICY: { POLICY_TYPE }, +} = POLICY_FIELD_IDS; + +const application = { + ...mockApplicationMinimalBrokerBuyerAndCompany, + policy: { + ...mockApplicationMinimalBrokerBuyerAndCompany, + [POLICY_TYPE]: APPLICATION.POLICY_TYPE.SINGLE, + }, + buyer: mockApplication.buyer, +}; + +describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.SINGLE} - all buyer conditions`, () => { + describe('with all possible buyer conditions (connected and traded with buyer, outstanding payments, previous credit insurance)', () => { + it('should return the correct row indexes', () => { + const result = XLSX_ROW_INDEXES(application); + + const indexes = INDEXES(); + + const expected = { + ...indexes, + TITLES: { + ...indexes.TITLES, + DECLARATIONS: indexes.TITLES.DECLARATIONS + 6, + }, + }; + + expect(result).toEqual(expected); + }); + }); +}); diff --git a/src/api/constants/XLSX-CONFIG/index-single-contract-policy-no-broker-or-different-trading-details.test.ts b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-no-broker-buyer-conditions-or-different-trading-details.test.ts similarity index 64% rename from src/api/constants/XLSX-CONFIG/index-single-contract-policy-no-broker-or-different-trading-details.test.ts rename to src/api/constants/XLSX-CONFIG/index-single-contract-policy-no-broker-buyer-conditions-or-different-trading-details.test.ts index d3bb4a2049..4559ef6a90 100644 --- a/src/api/constants/XLSX-CONFIG/index-single-contract-policy-no-broker-or-different-trading-details.test.ts +++ b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-no-broker-buyer-conditions-or-different-trading-details.test.ts @@ -2,26 +2,21 @@ import { XLSX_ROW_INDEXES } from '.'; import { INDEXES } from './INDEXES'; import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; import { APPLICATION } from '../application'; -import { mockApplication, mockCompanyScenarios } from '../../test-mocks'; +import { mockApplicationMinimalBrokerBuyerAndCompany } from '../../test-mocks'; const { TYPE_OF_POLICY: { POLICY_TYPE }, } = POLICY_FIELD_IDS; const application = { - ...mockApplication, + ...mockApplicationMinimalBrokerBuyerAndCompany, policy: { - ...mockApplication.policy, + ...mockApplicationMinimalBrokerBuyerAndCompany.policy, [POLICY_TYPE]: APPLICATION.POLICY_TYPE.SINGLE, }, - broker: { - ...mockApplication.broker, - isUsingBroker: false, - }, - company: mockCompanyScenarios.noDifferentTradingNameOrAddress, }; -describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.SINGLE} - not using a broker, no different trading details`, () => { +describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.SINGLE} - not using a broker, no broker conditions, no different trading details`, () => { it('should return default row indexes', () => { const result = XLSX_ROW_INDEXES(application); diff --git a/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts index 4474b80e16..ec7cfc6236 100644 --- a/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts +++ b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts @@ -2,7 +2,7 @@ import { XLSX_ROW_INDEXES } from '.'; import { incrementIndexes, INDEXES } from './INDEXES'; import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; import { APPLICATION } from '../application'; -import { mockApplication, mockCompanyScenarios } from '../../test-mocks'; +import { mockApplicationMinimalBrokerBuyerAndCompany, mockCompanyScenarios } from '../../test-mocks'; const { TYPE_OF_POLICY: { POLICY_TYPE }, @@ -10,13 +10,13 @@ const { } = POLICY_FIELD_IDS; const application = { - ...mockApplication, + ...mockApplicationMinimalBrokerBuyerAndCompany, policy: { - ...mockApplication.policy, + ...mockApplicationMinimalBrokerBuyerAndCompany, [POLICY_TYPE]: APPLICATION.POLICY_TYPE.SINGLE, }, broker: { - ...mockApplication.broker, + ...mockApplicationMinimalBrokerBuyerAndCompany, isUsingBroker: true, }, }; @@ -36,7 +36,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...indexes.TITLES, POLICY: indexes.TITLES.POLICY + 3, BUYER: indexes.TITLES.BUYER + 3, - DECLARATIONS: indexes.TITLES.DECLARATIONS + 3, + DECLARATIONS: indexes.TITLES.DECLARATIONS + 6, }, }; @@ -61,7 +61,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...incremented.TITLES, POLICY: incremented.TITLES.POLICY + 3, BUYER: incremented.TITLES.BUYER + 3, - DECLARATIONS: incremented.TITLES.DECLARATIONS + 3, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 6, }, }; @@ -91,7 +91,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...incremented.TITLES, POLICY: incremented.TITLES.POLICY + 3, BUYER: incremented.TITLES.BUYER + 3, - DECLARATIONS: incremented.TITLES.DECLARATIONS + 3, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 6, }, }; @@ -118,7 +118,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...secondIncrement.TITLES, POLICY: incremented.TITLES.POLICY + 3, BUYER: incremented.TITLES.BUYER + 3, - DECLARATIONS: incremented.TITLES.DECLARATIONS + 3, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 6, }, }; diff --git a/src/api/constants/XLSX-CONFIG/index.test.ts b/src/api/constants/XLSX-CONFIG/index.test.ts index 908f3b7deb..899f3a32ee 100644 --- a/src/api/constants/XLSX-CONFIG/index.test.ts +++ b/src/api/constants/XLSX-CONFIG/index.test.ts @@ -1,13 +1,4 @@ -import { XLSX_CONFIG, XLSX_ROW_INDEXES } from '.'; -import { INDEXES, TITLE_INDEXES } from './INDEXES'; -import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy'; -import { APPLICATION } from '../application'; -import { mockApplication } from '../../test-mocks'; - -const { - TYPE_OF_POLICY: { POLICY_TYPE }, - USING_BROKER, -} = POLICY_FIELD_IDS; +import { XLSX_CONFIG } from '.'; describe('api/constants/XLSX-CONFIG', () => { describe('XLSX_CONFIG', () => { @@ -36,59 +27,4 @@ describe('api/constants/XLSX-CONFIG', () => { expect(result).toEqual(expected); }); }); - - describe('XLSX_ROW_INDEXES', () => { - describe(APPLICATION.POLICY_TYPE.SINGLE, () => { - const application = { - ...mockApplication, - policy: { - ...mockApplication.policy, - [POLICY_TYPE]: APPLICATION.POLICY_TYPE.SINGLE, - }, - }; - - describe('when using a broker', () => { - it('should return correct row indexes', () => { - application.broker = { - ...mockApplication.buyer, - [USING_BROKER]: true, - }; - - const result = XLSX_ROW_INDEXES(application); - - const defaultIndexes = INDEXES(); - const defaultTitleIndexes = TITLE_INDEXES(); - - const expected = { - ...defaultIndexes, - BROKER_ADDRESS: 48, - BUYER_ADDRESS: defaultIndexes.BUYER_ADDRESS + 3, - TITLES: { - ...defaultTitleIndexes, - POLICY: defaultTitleIndexes.POLICY + 3, - BUYER: defaultTitleIndexes.BUYER + 3, - DECLARATIONS: defaultTitleIndexes.DECLARATIONS + 3, - }, - }; - - expect(result).toEqual(expected); - }); - }); - - describe('when NOT using a broker', () => { - it('should return default row indexes', () => { - application.broker = { - ...mockApplication.buyer, - [USING_BROKER]: false, - }; - - const result = XLSX_ROW_INDEXES(application); - - const expected = INDEXES(); - - expect(result).toEqual(expected); - }); - }); - }); - }); }); diff --git a/src/api/constants/XLSX-CONFIG/index.ts b/src/api/constants/XLSX-CONFIG/index.ts index bec2b0a6fe..1c9bd7d22c 100644 --- a/src/api/constants/XLSX-CONFIG/index.ts +++ b/src/api/constants/XLSX-CONFIG/index.ts @@ -45,6 +45,7 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { indexes.TITLES.BUYER += 1; indexes.TITLES.DECLARATIONS += 1; + indexes.BUYER_ADDRESS += 1; indexes.BUYER_CONTACT_DETAILS += 1; } @@ -52,9 +53,9 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; indexes.TITLES.DECLARATIONS += 6; - indexes.BUYER_ADDRESS += 3; indexes.BROKER_ADDRESS = 48; + indexes.BUYER_ADDRESS += 3; } if (hasDifferentTradingAddress) { diff --git a/src/api/emails/application/index.ts b/src/api/emails/application/index.ts index 3ec532342f..cb4bb7a584 100644 --- a/src/api/emails/application/index.ts +++ b/src/api/emails/application/index.ts @@ -54,7 +54,7 @@ const application = { * NOTE: no need to handle an error from fs.unlink here. * If this errors, it will go into the catch handler below. */ - await fileSystem.unlink(filePath); + // await fileSystem.unlink(filePath); return response; } diff --git a/src/api/test-mocks/index.ts b/src/api/test-mocks/index.ts index c04efa433b..d52b99c4a7 100644 --- a/src/api/test-mocks/index.ts +++ b/src/api/test-mocks/index.ts @@ -2,6 +2,7 @@ import { Request, Response } from 'express'; import { ACCOUNT, FIELD_IDS } from '../constants'; import encryptPassword from '../helpers/encrypt-password'; import application from './mock-application'; +import buyer from './mock-buyer'; import cisCountries from './mock-CIS-countries'; import currencies from './mock-currencies'; import company, { companyScenarios } from './mock-company'; @@ -44,6 +45,24 @@ export const mockIV = 'SVheFWN4nT+2pac4'; export const mockApplication = application; +export const mockApplicationMinimalBrokerBuyerAndCompany = { + ...application, + broker: { + ...mockApplication.broker, + isUsingBroker: false, + }, + buyer: { + ...mockApplication.buyer, + buyerTradingHistory: { + id: buyer.buyerTradingHistory.id, + }, + relationship: { + id: buyer.relationship.id, + }, + }, + company: companyScenarios.noDifferentTradingNameOrAddress, +}; + export const mockCisCountries = cisCountries; export const mockCompany = company; @@ -52,10 +71,10 @@ export const mockCompanyScenarios = companyScenarios; export const mockNominatedLossPayee = nominatedLossPayee; -export const mockBuyer = { - companyOrOrganisationName: 'Mock buyer', - exporterIsConnectedWithBuyer: true, -}; +export const mockBuyer = buyer; + +export const mockBuyerTradingHistory = buyer.buyerTradingHistory; +export const mockBuyerRelationship = buyer.relationship; export const mockLossPayeeFinancialDetailsUk = { accountNumber: '12345678', From 6896560a454277d0cd4df7d40ebc616d736c977a Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Thu, 30 May 2024 15:06:04 +0100 Subject: [PATCH 17/29] chore(helpers): transform api mapYesNoField helper to have object structured params --- src/api/.keystone/config.js | 51 +++++++++++-------- .../helpers/map-agreed-field/index.test.ts | 8 +-- .../helpers/map-yes-no-field/index.test.ts | 29 +++++++---- .../helpers/map-yes-no-field/index.ts | 15 +++--- .../map-buyer/index.test.ts | 12 +++-- .../map-buyer/index.ts | 15 ++++-- .../map-buyer-trading-history/index.test.ts | 4 +- .../map-buyer-trading-history/index.ts | 4 +- .../map-declarations/index.test.ts | 4 +- .../map-declarations/index.ts | 4 +- .../map-eligibility/index.test.ts | 10 ++-- .../map-eligibility/index.ts | 11 ++-- .../map-exporter-business/index.test.ts | 6 +-- .../map-exporter-business/index.ts | 6 +-- .../map-broker/index.test.ts | 4 +- .../map-exporter-business/map-broker/index.ts | 2 +- src/api/types/helpers/index.ts | 4 ++ src/api/types/index.ts | 1 + 18 files changed, 112 insertions(+), 78 deletions(-) create mode 100644 src/api/types/helpers/index.ts diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 26e9e5aa1e..f3596128a2 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -6015,12 +6015,13 @@ var mapPolicy = (application2) => { var map_policy_default = mapPolicy; // generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.ts -var mapYesNoField = (answer, defaultValue) => { +var { YES, NO } = FIELD_VALUES; +var mapYesNoField = ({ answer, defaultValue }) => { if (answer === false) { - return "No"; + return NO; } if (answer === true) { - return "Yes"; + return YES; } if (defaultValue) { return defaultValue; @@ -6037,7 +6038,7 @@ var { var { FIELDS: FIELDS5 } = XLSX; var mapBroker = (application2) => { const { broker } = application2; - let mapped = [xlsx_row_default(FIELDS5[USING_BROKER4], map_yes_no_field_default(broker[USING_BROKER4]))]; + let mapped = [xlsx_row_default(FIELDS5[USING_BROKER4], map_yes_no_field_default({ answer: broker[USING_BROKER4] }))]; if (broker[USING_BROKER4]) { mapped = [ ...mapped, @@ -6138,9 +6139,9 @@ var mapExporterBusiness = (application2) => { xlsx_row_default(CONTENT_STRINGS3[COMPANY_INCORPORATED2].SUMMARY?.TITLE, format_date_default(company[COMPANY_INCORPORATED2], "dd-MMM-yy")), xlsx_row_default(FIELDS9[COMPANY_ADDRESS2], map_exporter_address_default(company[COMPANY_ADDRESS2])), xlsx_row_default(FIELDS9[COMPANY_SIC2], map_sic_codes_default2(companySicCodes)), - xlsx_row_default(FIELDS9[HAS_DIFFERENT_TRADING_NAME4], map_yes_no_field_default(company[HAS_DIFFERENT_TRADING_NAME4])), + xlsx_row_default(FIELDS9[HAS_DIFFERENT_TRADING_NAME4], map_yes_no_field_default({ answer: company[HAS_DIFFERENT_TRADING_NAME4] })), map_different_trading_name_default(company), - xlsx_row_default(FIELDS9[TRADING_ADDRESS3], map_yes_no_field_default(company[TRADING_ADDRESS3])), + xlsx_row_default(FIELDS9[TRADING_ADDRESS3], map_yes_no_field_default({ answer: company[TRADING_ADDRESS3] })), map_different_trading_address_default(company), xlsx_row_default(FIELDS9[WEBSITE3], company[WEBSITE3]), xlsx_row_default(FIELDS9[PHONE_NUMBER3], company[PHONE_NUMBER3]), @@ -6150,7 +6151,7 @@ var mapExporterBusiness = (application2) => { xlsx_row_default(CONTENT_STRINGS3[FINANCIAL_YEAR_END_DATE3].SUMMARY?.TITLE, map_financial_year_end_date_default(company)), xlsx_row_default(FIELDS9[ESTIMATED_ANNUAL_TURNOVER3], format_currency_default2(business[ESTIMATED_ANNUAL_TURNOVER3], GBP_CURRENCY_CODE)), xlsx_row_default(CONTENT_STRINGS3[PERCENTAGE_TURNOVER2].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER2]}%`), - xlsx_row_default(FIELDS9[HAS_CREDIT_CONTROL3], map_yes_no_field_default(business[HAS_CREDIT_CONTROL3])), + xlsx_row_default(FIELDS9[HAS_CREDIT_CONTROL3], map_yes_no_field_default({ answer: business[HAS_CREDIT_CONTROL3] })), ...map_broker_default(application2) ]; return mapped; @@ -6195,9 +6196,9 @@ var { FIELDS: FIELDS12 } = XLSX; var mapBuyerTradingHistory = (tradingHistory) => { if (tradingHistory[TRADED_WITH_BUYER3]) { const mapped = [ - xlsx_row_default(String(FIELDS12[OUTSTANDING_PAYMENTS4]), map_yes_no_field_default(tradingHistory[OUTSTANDING_PAYMENTS4])), + xlsx_row_default(String(FIELDS12[OUTSTANDING_PAYMENTS4]), map_yes_no_field_default({ answer: tradingHistory[OUTSTANDING_PAYMENTS4] })), ...map_outstanding_payments_default(tradingHistory), - xlsx_row_default(String(FIELDS12[FAILED_PAYMENTS3]), map_yes_no_field_default(tradingHistory[FAILED_PAYMENTS3])) + xlsx_row_default(String(FIELDS12[FAILED_PAYMENTS3]), map_yes_no_field_default({ answer: tradingHistory[FAILED_PAYMENTS3] })) ]; return mapped; } @@ -6237,13 +6238,19 @@ var mapBuyer = (application2) => { xlsx_row_default(String(CONTENT_STRINGS4[ADDRESS].SUMMARY?.TITLE), `${buyer[ADDRESS]} ${xlsx_new_line_default}${buyer[COUNTRY3].name}`), xlsx_row_default(FIELDS14[REGISTRATION_NUMBER], buyer[REGISTRATION_NUMBER]), xlsx_row_default(String(CONTENT_STRINGS4[WEBSITE4].SUMMARY?.TITLE), buyer[WEBSITE4]), - xlsx_row_default(String(FIELDS14[CONNECTION_WITH_BUYER4]), map_yes_no_field_default(relationship2[CONNECTION_WITH_BUYER4])), + xlsx_row_default(String(FIELDS14[CONNECTION_WITH_BUYER4]), map_yes_no_field_default({ answer: relationship2[CONNECTION_WITH_BUYER4] })), map_connection_with_buyer_default(relationship2), - xlsx_row_default(String(FIELDS14[TRADED_WITH_BUYER4]), map_yes_no_field_default(buyerTradingHistory[TRADED_WITH_BUYER4])), + xlsx_row_default(String(FIELDS14[TRADED_WITH_BUYER4]), map_yes_no_field_default({ answer: buyerTradingHistory[TRADED_WITH_BUYER4] })), ...map_buyer_trading_history_default(buyerTradingHistory), - xlsx_row_default(String(FIELDS14[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER4]), map_yes_no_field_default(relationship2[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER4], "No")), + xlsx_row_default( + String(FIELDS14[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER4]), + map_yes_no_field_default({ + answer: relationship2[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER4], + defaultValue: FIELD_VALUES.NO + }) + ), map_previous_cover_with_buyer_default(relationship2), - xlsx_row_default(String(FIELDS14[HAS_BUYER_FINANCIAL_ACCOUNTS3]), map_yes_no_field_default(relationship2[HAS_BUYER_FINANCIAL_ACCOUNTS3])) + xlsx_row_default(String(FIELDS14[HAS_BUYER_FINANCIAL_ACCOUNTS3]), map_yes_no_field_default({ answer: relationship2[HAS_BUYER_FINANCIAL_ACCOUNTS3] })) ]; return mapped; }; @@ -6269,14 +6276,14 @@ var mapEligibility = (application2) => { const { company, eligibility } = application2; const mapped = [ xlsx_row_default(SECTION_TITLES3.ELIGIBILITY, ""), - xlsx_row_default(FIELDS_ELIGIBILITY[VALID_EXPORTER_LOCATION2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[VALID_EXPORTER_LOCATION2])), - xlsx_row_default(FIELDS_ELIGIBILITY[HAS_COMPANIES_HOUSE_NUMBER2].SUMMARY?.TITLE, map_yes_no_field_default(eligibility[HAS_COMPANIES_HOUSE_NUMBER2])), + xlsx_row_default(FIELDS_ELIGIBILITY[VALID_EXPORTER_LOCATION2].SUMMARY?.TITLE, map_yes_no_field_default({ answer: eligibility[VALID_EXPORTER_LOCATION2] })), + xlsx_row_default(FIELDS_ELIGIBILITY[HAS_COMPANIES_HOUSE_NUMBER2].SUMMARY?.TITLE, map_yes_no_field_default({ answer: eligibility[HAS_COMPANIES_HOUSE_NUMBER2] })), xlsx_row_default(FIELDS15[COMPANIES_HOUSE_NUMBER3], company[COMPANIES_HOUSE_NUMBER3]), xlsx_row_default(FIELDS15[BUYER_COUNTRY3], eligibility[BUYER_COUNTRY3].name), - xlsx_row_default(FIELDS15[MORE_THAN_250K2.VALUE], map_yes_no_field_default(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID)), + xlsx_row_default(FIELDS15[MORE_THAN_250K2.VALUE], map_yes_no_field_default({ answer: eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID2].valueId === MORE_THAN_250K2.DB_ID })), xlsx_row_default(FIELDS15[COVER_PERIOD3], eligibility[COVER_PERIOD_ELIGIBILITY].value), - xlsx_row_default(FIELDS15[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3])), - xlsx_row_default(FIELDS15[HAS_END_BUYER3], map_yes_no_field_default(eligibility[HAS_END_BUYER3])) + xlsx_row_default(FIELDS15[HAS_MINIMUM_UK_GOODS_OR_SERVICES3], map_yes_no_field_default({ answer: eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES3] })), + xlsx_row_default(FIELDS15[HAS_END_BUYER3], map_yes_no_field_default({ answer: eligibility[HAS_END_BUYER3] })) ]; return mapped; }; @@ -6308,8 +6315,8 @@ var mapDeclarations = (application2) => { xlsx_row_default(XLSX.SECTION_TITLES.DECLARATIONS, ""), xlsx_row_default(DECLARATIONS_FIELDS[AGREE_CONFIDENTIALITY2].SUMMARY.TITLE, map_agreed_field_default(declaration[AGREE_CONFIDENTIALITY2])), xlsx_row_default(DECLARATIONS_FIELDS[AGREE_ANTI_BRIBERY2].SUMMARY.TITLE, map_agreed_field_default(declaration[AGREE_ANTI_BRIBERY2])), - xlsx_row_default(DECLARATIONS_FIELDS[HAS_ANTI_BRIBERY_CODE_OF_CONDUCT2].SUMMARY.TITLE, map_yes_no_field_default(declaration[HAS_ANTI_BRIBERY_CODE_OF_CONDUCT2])), - xlsx_row_default(DECLARATIONS_FIELDS[WILL_EXPORT_WITH_CODE_OF_CONDUCT2].SUMMARY.TITLE, map_yes_no_field_default(declaration[WILL_EXPORT_WITH_CODE_OF_CONDUCT2])), + xlsx_row_default(DECLARATIONS_FIELDS[HAS_ANTI_BRIBERY_CODE_OF_CONDUCT2].SUMMARY.TITLE, map_yes_no_field_default({ answer: declaration[HAS_ANTI_BRIBERY_CODE_OF_CONDUCT2] })), + xlsx_row_default(DECLARATIONS_FIELDS[WILL_EXPORT_WITH_CODE_OF_CONDUCT2].SUMMARY.TITLE, map_yes_no_field_default({ answer: declaration[WILL_EXPORT_WITH_CODE_OF_CONDUCT2] })), xlsx_row_default(DECLARATIONS_FIELDS[AGREE_HOW_YOUR_DATA_WILL_BE_USED2].SUMMARY.TITLE, map_agreed_field_default(declaration[AGREE_HOW_YOUR_DATA_WILL_BE_USED2])), xlsx_row_default(DECLARATIONS_FIELDS[AGREE_CONFIRMATION_ACKNOWLEDGEMENTS2].SUMMARY.TITLE, map_agreed_field_default(declaration[AGREE_CONFIRMATION_ACKNOWLEDGEMENTS2])) ]; @@ -6939,12 +6946,12 @@ var cannot_get_a_quote_default = cannotGetAQuote; // helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online/index.ts var { CIS: { - SHORT_TERM_COVER_AVAILABLE: { YES, ILC, CILC, REFER, UNLISTED } + SHORT_TERM_COVER_AVAILABLE: { YES: YES2, ILC, CILC, REFER, UNLISTED } } } = EXTERNAL_API_DEFINITIONS; var canApplyForInsuranceOnline = (originalShortTermCover, riskCategory) => { switch (originalShortTermCover) { - case (riskCategory && YES): + case (riskCategory && YES2): return true; case (riskCategory && ILC): return true; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-agreed-field/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-agreed-field/index.test.ts index 727b375d69..537401a23e 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-agreed-field/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-agreed-field/index.test.ts @@ -1,4 +1,4 @@ -import mapYesNoField from '.'; +import mapAgreedField from '.'; import { DEFAULT, XLSX } from '../../../../content-strings'; describe('api/generate-xlsx/map-application-to-xlsx/helpers/map-agreed-field', () => { @@ -6,7 +6,7 @@ describe('api/generate-xlsx/map-application-to-xlsx/helpers/map-agreed-field', ( const value = true; it(`should return "${XLSX.AGREED}"`, () => { - const response = mapYesNoField(value); + const response = mapAgreedField(value); expect(response).toEqual(XLSX.AGREED); }); @@ -16,7 +16,7 @@ describe('api/generate-xlsx/map-application-to-xlsx/helpers/map-agreed-field', ( const value = false; it(`should return "${DEFAULT.EMPTY}"`, () => { - const response = mapYesNoField(value); + const response = mapAgreedField(value); expect(response).toEqual(DEFAULT.EMPTY); }); @@ -24,7 +24,7 @@ describe('api/generate-xlsx/map-application-to-xlsx/helpers/map-agreed-field', ( describe('when value is undefined', () => { it(`should return "${DEFAULT.EMPTY}"`, () => { - const response = mapYesNoField(); + const response = mapAgreedField(); expect(response).toEqual(DEFAULT.EMPTY); }); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.test.ts index 3b55b0083a..ff210ca6af 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.test.ts @@ -1,30 +1,39 @@ import mapYesNoField from '.'; +import { FIELD_VALUES } from '../../../../constants'; import { DEFAULT } from '../../../../content-strings'; +const { YES, NO } = FIELD_VALUES; + describe('api/generate-xlsx/map-application-to-xlsx/helpers/map-yes-no-field', () => { describe('when value is true', () => { - const value = true; - - it('should return "Yes"', () => { - const response = mapYesNoField(value); + it(`should return "${YES}"`, () => { + const response = mapYesNoField({ answer: true }); - expect(response).toEqual('Yes'); + expect(response).toEqual(YES); }); }); describe('when value is "false"', () => { - const value = false; + it(`should return "${NO}"`, () => { + const response = mapYesNoField({ answer: true }); + + expect(response).toEqual(NO); + }); + }); + + describe('when value is undefined and a default value is passed', () => { + it('should return the default value', () => { + const mockDefaultValue = 'Mock default value'; - it('should return "No"', () => { - const response = mapYesNoField(value); + const response = mapYesNoField({ defaultValue: mockDefaultValue }); - expect(response).toEqual('No'); + expect(response).toEqual(mockDefaultValue); }); }); describe('when value is "undefined"', () => { it(`should return ${DEFAULT.EMPTY}`, () => { - const response = mapYesNoField(); + const response = mapYesNoField({}); expect(response).toEqual(DEFAULT.EMPTY); }); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.ts index 729ccbaceb..b53f44d356 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.ts @@ -1,20 +1,23 @@ +import { FIELD_VALUES } from '../../../../constants'; import { DEFAULT } from '../../../../content-strings'; +import { MapYesNoFieldParams } from '../../../../types'; + +const { YES, NO } = FIELD_VALUES; -// TODO: object structured -// TODO: yes/no values as content strings. /** * mapYesNoField * Map a "true" or "false" field to Yes/No - * @param {Boolean} answer + * @param {Boolean} answer: The boolean answer to map into a yes/no string. + * @param {String} defaultValue: Custom default value. * @returns {String} "Yes/No" or DEFAULT.EMPTY */ -const mapYesNoField = (answer?: boolean, defaultValue?: string) => { +const mapYesNoField = ({ answer, defaultValue }: MapYesNoFieldParams): string => { if (answer === false) { - return 'No'; + return NO; } if (answer === true) { - return 'Yes'; + return YES; } if (defaultValue) { diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.test.ts index 2b6117058d..6f5e6dc446 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.test.ts @@ -1,4 +1,5 @@ import mapBuyer from '.'; +import { FIELD_VALUES } from '../../../constants'; import FIELD_IDS from '../../../constants/field-ids/insurance/your-buyer'; import { XLSX } from '../../../content-strings'; import { YOUR_BUYER_FIELDS } from '../../../content-strings/fields/insurance/your-buyer'; @@ -38,22 +39,25 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-buyer', () => { xlsxRow(String(CONTENT_STRINGS[ADDRESS].SUMMARY?.TITLE), `${buyer[ADDRESS]} ${NEW_LINE}${buyer[COUNTRY].name}`), xlsxRow(FIELDS[REGISTRATION_NUMBER], buyer[REGISTRATION_NUMBER]), xlsxRow(String(CONTENT_STRINGS[WEBSITE].SUMMARY?.TITLE), buyer[WEBSITE]), - xlsxRow(String(FIELDS[CONNECTION_WITH_BUYER]), mapYesNoField(relationship[CONNECTION_WITH_BUYER])), + xlsxRow(String(FIELDS[CONNECTION_WITH_BUYER]), mapYesNoField({ answer: relationship[CONNECTION_WITH_BUYER] })), mapConnectionWithBuyer(relationship), - xlsxRow(String(FIELDS[TRADED_WITH_BUYER]), mapYesNoField(buyerTradingHistory[TRADED_WITH_BUYER])), + xlsxRow(String(FIELDS[TRADED_WITH_BUYER]), mapYesNoField({ answer: buyerTradingHistory[TRADED_WITH_BUYER] })), ...mapBuyerTradingHistory(buyerTradingHistory), xlsxRow( String(FIELDS[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]), - mapYesNoField(relationship[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER], 'No'), + mapYesNoField({ + answer: relationship[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER], + defaultValue: FIELD_VALUES.NO, + }), ), mapPreviousCoverWithBuyer(relationship), - xlsxRow(String(FIELDS[HAS_BUYER_FINANCIAL_ACCOUNTS]), mapYesNoField(relationship[HAS_BUYER_FINANCIAL_ACCOUNTS])), + xlsxRow(String(FIELDS[HAS_BUYER_FINANCIAL_ACCOUNTS]), mapYesNoField({ answer: relationship[HAS_BUYER_FINANCIAL_ACCOUNTS] })), ]; expect(result).toEqual(expected); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts index 9f836b75ca..3866ccbc25 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts @@ -1,3 +1,4 @@ +import { FIELD_VALUES } from '../../../constants'; import FIELD_IDS from '../../../constants/field-ids/insurance/your-buyer'; import { XLSX } from '../../../content-strings'; import { YOUR_BUYER_FIELDS } from '../../../content-strings/fields/insurance/your-buyer'; @@ -40,19 +41,25 @@ const mapBuyer = (application: Application) => { xlsxRow(String(CONTENT_STRINGS[ADDRESS].SUMMARY?.TITLE), `${buyer[ADDRESS]} ${NEW_LINE}${buyer[COUNTRY].name}`), xlsxRow(FIELDS[REGISTRATION_NUMBER], buyer[REGISTRATION_NUMBER]), xlsxRow(String(CONTENT_STRINGS[WEBSITE].SUMMARY?.TITLE), buyer[WEBSITE]), - xlsxRow(String(FIELDS[CONNECTION_WITH_BUYER]), mapYesNoField(relationship[CONNECTION_WITH_BUYER])), + xlsxRow(String(FIELDS[CONNECTION_WITH_BUYER]), mapYesNoField({ answer: relationship[CONNECTION_WITH_BUYER] })), mapConnectionWithBuyer(relationship), - xlsxRow(String(FIELDS[TRADED_WITH_BUYER]), mapYesNoField(buyerTradingHistory[TRADED_WITH_BUYER])), + xlsxRow(String(FIELDS[TRADED_WITH_BUYER]), mapYesNoField({ answer: buyerTradingHistory[TRADED_WITH_BUYER] })), ...mapBuyerTradingHistory(buyerTradingHistory), - xlsxRow(String(FIELDS[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]), mapYesNoField(relationship[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER], 'No')), + xlsxRow( + String(FIELDS[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]), + mapYesNoField({ + answer: relationship[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER], + defaultValue: FIELD_VALUES.NO, + }), + ), mapPreviousCoverWithBuyer(relationship), - xlsxRow(String(FIELDS[HAS_BUYER_FINANCIAL_ACCOUNTS]), mapYesNoField(relationship[HAS_BUYER_FINANCIAL_ACCOUNTS])), + xlsxRow(String(FIELDS[HAS_BUYER_FINANCIAL_ACCOUNTS]), mapYesNoField({ answer: relationship[HAS_BUYER_FINANCIAL_ACCOUNTS] })), ]; return mapped; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.test.ts index dd5addbf15..f52cf25108 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.test.ts @@ -21,11 +21,11 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-buyer-trading-history', const result = mapBuyerTradingHistory(mockTradingHistory); const expected = [ - xlsxRow(String(FIELDS[OUTSTANDING_PAYMENTS]), mapYesNoField(mockTradingHistory[OUTSTANDING_PAYMENTS])), + xlsxRow(String(FIELDS[OUTSTANDING_PAYMENTS]), mapYesNoField({ answer: mockTradingHistory[OUTSTANDING_PAYMENTS] })), ...mapOutstandingPayments(mockTradingHistory), - xlsxRow(String(FIELDS[FAILED_PAYMENTS]), mapYesNoField(mockTradingHistory[FAILED_PAYMENTS])), + xlsxRow(String(FIELDS[FAILED_PAYMENTS]), mapYesNoField({ answer: mockTradingHistory[FAILED_PAYMENTS] })), ]; expect(result).toEqual(expected); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.ts index d48fd11f6d..dede1c3782 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-buyer-trading-history/index.ts @@ -18,11 +18,11 @@ const { FIELDS } = XLSX; const mapBuyerTradingHistory = (tradingHistory: BuyerTradingHistory) => { if (tradingHistory[TRADED_WITH_BUYER]) { const mapped = [ - xlsxRow(String(FIELDS[OUTSTANDING_PAYMENTS]), mapYesNoField(tradingHistory[OUTSTANDING_PAYMENTS])), + xlsxRow(String(FIELDS[OUTSTANDING_PAYMENTS]), mapYesNoField({ answer: tradingHistory[OUTSTANDING_PAYMENTS] })), ...mapOutstandingPayments(tradingHistory), - xlsxRow(String(FIELDS[FAILED_PAYMENTS]), mapYesNoField(tradingHistory[FAILED_PAYMENTS])), + xlsxRow(String(FIELDS[FAILED_PAYMENTS]), mapYesNoField({ answer: tradingHistory[FAILED_PAYMENTS] })), ]; return mapped; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-declarations/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-declarations/index.test.ts index a4bae2f2e0..0f298ccbfd 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-declarations/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-declarations/index.test.ts @@ -28,8 +28,8 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-declarations', () => { xlsxRow(XLSX.SECTION_TITLES.DECLARATIONS, ''), xlsxRow(CONTENT_STRINGS[AGREE_CONFIDENTIALITY].SUMMARY.TITLE, mapAgreedField(declaration[AGREE_CONFIDENTIALITY])), xlsxRow(CONTENT_STRINGS[AGREE_ANTI_BRIBERY].SUMMARY.TITLE, mapAgreedField(declaration[AGREE_ANTI_BRIBERY])), - xlsxRow(CONTENT_STRINGS[HAS_ANTI_BRIBERY_CODE_OF_CONDUCT].SUMMARY.TITLE, mapYesNoField(declaration[HAS_ANTI_BRIBERY_CODE_OF_CONDUCT])), - xlsxRow(CONTENT_STRINGS[WILL_EXPORT_WITH_CODE_OF_CONDUCT].SUMMARY.TITLE, mapYesNoField(declaration[WILL_EXPORT_WITH_CODE_OF_CONDUCT])), + xlsxRow(CONTENT_STRINGS[HAS_ANTI_BRIBERY_CODE_OF_CONDUCT].SUMMARY.TITLE, mapYesNoField({ answer: declaration[HAS_ANTI_BRIBERY_CODE_OF_CONDUCT] })), + xlsxRow(CONTENT_STRINGS[WILL_EXPORT_WITH_CODE_OF_CONDUCT].SUMMARY.TITLE, mapYesNoField({ answer: declaration[WILL_EXPORT_WITH_CODE_OF_CONDUCT] })), xlsxRow(CONTENT_STRINGS[AGREE_HOW_YOUR_DATA_WILL_BE_USED].SUMMARY.TITLE, mapAgreedField(declaration[AGREE_HOW_YOUR_DATA_WILL_BE_USED])), xlsxRow(CONTENT_STRINGS[AGREE_CONFIRMATION_ACKNOWLEDGEMENTS].SUMMARY.TITLE, mapAgreedField(declaration[AGREE_CONFIRMATION_ACKNOWLEDGEMENTS])), ]; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-declarations/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-declarations/index.ts index 19ebe37918..4798771106 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-declarations/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-declarations/index.ts @@ -30,8 +30,8 @@ const mapDeclarations = (application: Application) => { xlsxRow(XLSX.SECTION_TITLES.DECLARATIONS, ''), xlsxRow(CONTENT_STRINGS[AGREE_CONFIDENTIALITY].SUMMARY.TITLE, mapAgreedField(declaration[AGREE_CONFIDENTIALITY])), xlsxRow(CONTENT_STRINGS[AGREE_ANTI_BRIBERY].SUMMARY.TITLE, mapAgreedField(declaration[AGREE_ANTI_BRIBERY])), - xlsxRow(CONTENT_STRINGS[HAS_ANTI_BRIBERY_CODE_OF_CONDUCT].SUMMARY.TITLE, mapYesNoField(declaration[HAS_ANTI_BRIBERY_CODE_OF_CONDUCT])), - xlsxRow(CONTENT_STRINGS[WILL_EXPORT_WITH_CODE_OF_CONDUCT].SUMMARY.TITLE, mapYesNoField(declaration[WILL_EXPORT_WITH_CODE_OF_CONDUCT])), + xlsxRow(CONTENT_STRINGS[HAS_ANTI_BRIBERY_CODE_OF_CONDUCT].SUMMARY.TITLE, mapYesNoField({ answer: declaration[HAS_ANTI_BRIBERY_CODE_OF_CONDUCT] })), + xlsxRow(CONTENT_STRINGS[WILL_EXPORT_WITH_CODE_OF_CONDUCT].SUMMARY.TITLE, mapYesNoField({ answer: declaration[WILL_EXPORT_WITH_CODE_OF_CONDUCT] })), xlsxRow(CONTENT_STRINGS[AGREE_HOW_YOUR_DATA_WILL_BE_USED].SUMMARY.TITLE, mapAgreedField(declaration[AGREE_HOW_YOUR_DATA_WILL_BE_USED])), xlsxRow(CONTENT_STRINGS[AGREE_CONFIRMATION_ACKNOWLEDGEMENTS].SUMMARY.TITLE, mapAgreedField(declaration[AGREE_CONFIRMATION_ACKNOWLEDGEMENTS])), ]; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-eligibility/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-eligibility/index.test.ts index d4b716816b..1333a2d3a7 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-eligibility/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-eligibility/index.test.ts @@ -33,19 +33,19 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-eligibility', () => { const expected = [ xlsxRow(SECTION_TITLES.ELIGIBILITY, ''), - xlsxRow(CONTENT_STRINGS[VALID_EXPORTER_LOCATION].SUMMARY?.TITLE, mapYesNoField(eligibility[VALID_EXPORTER_LOCATION])), + xlsxRow(CONTENT_STRINGS[VALID_EXPORTER_LOCATION].SUMMARY?.TITLE, mapYesNoField({ answer: eligibility[VALID_EXPORTER_LOCATION] })), - xlsxRow(CONTENT_STRINGS[HAS_COMPANIES_HOUSE_NUMBER].SUMMARY?.TITLE, mapYesNoField(eligibility[HAS_COMPANIES_HOUSE_NUMBER])), + xlsxRow(CONTENT_STRINGS[HAS_COMPANIES_HOUSE_NUMBER].SUMMARY?.TITLE, mapYesNoField({ answer: eligibility[HAS_COMPANIES_HOUSE_NUMBER] })), xlsxRow(FIELDS[COMPANIES_HOUSE_NUMBER], company[COMPANIES_HOUSE_NUMBER]), xlsxRow(FIELDS[BUYER_COUNTRY], eligibility[BUYER_COUNTRY].name), - xlsxRow(FIELDS[MORE_THAN_250K.VALUE], mapYesNoField(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID].valueId === MORE_THAN_250K.DB_ID)), + xlsxRow(FIELDS[MORE_THAN_250K.VALUE], mapYesNoField({ answer: eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID].valueId === MORE_THAN_250K.DB_ID })), xlsxRow(FIELDS[COVER_PERIOD], eligibility[COVER_PERIOD_ELIGIBILITY].value), - xlsxRow(FIELDS[HAS_MINIMUM_UK_GOODS_OR_SERVICES], mapYesNoField(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES])), - xlsxRow(FIELDS[HAS_END_BUYER], mapYesNoField(eligibility[HAS_END_BUYER])), + xlsxRow(FIELDS[HAS_MINIMUM_UK_GOODS_OR_SERVICES], mapYesNoField({ answer: eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES] })), + xlsxRow(FIELDS[HAS_END_BUYER], mapYesNoField({ answer: eligibility[HAS_END_BUYER] })), ]; expect(result).toEqual(expected); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-eligibility/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-eligibility/index.ts index 9d2d3ec21f..44633b1afd 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-eligibility/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-eligibility/index.ts @@ -1,4 +1,3 @@ - import { TOTAL_CONTRACT_VALUE } from '../../../constants/total-contract-value'; import { XLSX } from '../../../content-strings'; import INSURANCE_FIELD_IDS from '../../../constants/field-ids/insurance'; @@ -36,19 +35,19 @@ const mapEligibility = (application: Application) => { const mapped = [ xlsxRow(SECTION_TITLES.ELIGIBILITY, ''), - xlsxRow(CONTENT_STRINGS[VALID_EXPORTER_LOCATION].SUMMARY?.TITLE, mapYesNoField(eligibility[VALID_EXPORTER_LOCATION])), + xlsxRow(CONTENT_STRINGS[VALID_EXPORTER_LOCATION].SUMMARY?.TITLE, mapYesNoField({ answer: eligibility[VALID_EXPORTER_LOCATION] })), - xlsxRow(CONTENT_STRINGS[HAS_COMPANIES_HOUSE_NUMBER].SUMMARY?.TITLE, mapYesNoField(eligibility[HAS_COMPANIES_HOUSE_NUMBER])), + xlsxRow(CONTENT_STRINGS[HAS_COMPANIES_HOUSE_NUMBER].SUMMARY?.TITLE, mapYesNoField({ answer: eligibility[HAS_COMPANIES_HOUSE_NUMBER] })), xlsxRow(FIELDS[COMPANIES_HOUSE_NUMBER], company[COMPANIES_HOUSE_NUMBER]), xlsxRow(FIELDS[BUYER_COUNTRY], eligibility[BUYER_COUNTRY].name), - xlsxRow(FIELDS[MORE_THAN_250K.VALUE], mapYesNoField(eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID].valueId === MORE_THAN_250K.DB_ID)), + xlsxRow(FIELDS[MORE_THAN_250K.VALUE], mapYesNoField({ answer: eligibility[TOTAL_CONTRACT_VALUE_FIELD_ID].valueId === MORE_THAN_250K.DB_ID })), xlsxRow(FIELDS[COVER_PERIOD], eligibility[COVER_PERIOD_ELIGIBILITY].value), - xlsxRow(FIELDS[HAS_MINIMUM_UK_GOODS_OR_SERVICES], mapYesNoField(eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES])), - xlsxRow(FIELDS[HAS_END_BUYER], mapYesNoField(eligibility[HAS_END_BUYER])), + xlsxRow(FIELDS[HAS_MINIMUM_UK_GOODS_OR_SERVICES], mapYesNoField({ answer: eligibility[HAS_MINIMUM_UK_GOODS_OR_SERVICES] })), + xlsxRow(FIELDS[HAS_END_BUYER], mapYesNoField({ answer: eligibility[HAS_END_BUYER] })), ]; return mapped; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts index 45ea17b23c..63487a6e93 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.test.ts @@ -46,10 +46,10 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business', () = xlsxRow(FIELDS[COMPANY_ADDRESS], mapExporterAddress(company[COMPANY_ADDRESS])), xlsxRow(FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), - xlsxRow(FIELDS[HAS_DIFFERENT_TRADING_NAME], mapYesNoField(company[HAS_DIFFERENT_TRADING_NAME])), + xlsxRow(FIELDS[HAS_DIFFERENT_TRADING_NAME], mapYesNoField({ answer: company[HAS_DIFFERENT_TRADING_NAME] })), mapDifferentTradingName(company), - xlsxRow(FIELDS[TRADING_ADDRESS], mapYesNoField(company[TRADING_ADDRESS])), + xlsxRow(FIELDS[TRADING_ADDRESS], mapYesNoField({ answer: company[TRADING_ADDRESS] })), mapDifferentTradingAddress(company), xlsxRow(FIELDS[WEBSITE], company[WEBSITE]), @@ -62,7 +62,7 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business', () = xlsxRow(FIELDS[ESTIMATED_ANNUAL_TURNOVER], formatCurrency(business[ESTIMATED_ANNUAL_TURNOVER], GBP_CURRENCY_CODE)), xlsxRow(CONTENT_STRINGS[PERCENTAGE_TURNOVER].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER]}%`), - xlsxRow(FIELDS[HAS_CREDIT_CONTROL], mapYesNoField(business[HAS_CREDIT_CONTROL])), + xlsxRow(FIELDS[HAS_CREDIT_CONTROL], mapYesNoField({ answer: business[HAS_CREDIT_CONTROL] })), ...mapBroker(mockApplication), ]; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts index 5e3b647110..e9ee347d97 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/index.ts @@ -46,10 +46,10 @@ const mapExporterBusiness = (application: Application) => { xlsxRow(FIELDS[COMPANY_ADDRESS], mapExporterAddress(company[COMPANY_ADDRESS])), xlsxRow(FIELDS[COMPANY_SIC], mapSicCodes(companySicCodes)), - xlsxRow(FIELDS[HAS_DIFFERENT_TRADING_NAME], mapYesNoField(company[HAS_DIFFERENT_TRADING_NAME])), + xlsxRow(FIELDS[HAS_DIFFERENT_TRADING_NAME], mapYesNoField({ answer: company[HAS_DIFFERENT_TRADING_NAME] })), mapDifferentTradingName(company), - xlsxRow(FIELDS[TRADING_ADDRESS], mapYesNoField(company[TRADING_ADDRESS])), + xlsxRow(FIELDS[TRADING_ADDRESS], mapYesNoField({ answer: company[TRADING_ADDRESS] })), mapDifferentTradingAddress(company), xlsxRow(FIELDS[WEBSITE], company[WEBSITE]), @@ -62,7 +62,7 @@ const mapExporterBusiness = (application: Application) => { xlsxRow(FIELDS[ESTIMATED_ANNUAL_TURNOVER], formatCurrency(business[ESTIMATED_ANNUAL_TURNOVER], GBP_CURRENCY_CODE)), xlsxRow(CONTENT_STRINGS[PERCENTAGE_TURNOVER].SUMMARY?.TITLE, `${business[PERCENTAGE_TURNOVER]}%`), - xlsxRow(FIELDS[HAS_CREDIT_CONTROL], mapYesNoField(business[HAS_CREDIT_CONTROL])), + xlsxRow(FIELDS[HAS_CREDIT_CONTROL], mapYesNoField({ answer: business[HAS_CREDIT_CONTROL] })), ...mapBroker(application), ]; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.test.ts index 902c9912af..2919212ffe 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.test.ts @@ -20,7 +20,7 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business/map-br const { broker } = mockApplication; const expected = [ - xlsxRow(FIELDS[USING_BROKER], mapYesNoField(broker[USING_BROKER])), + xlsxRow(FIELDS[USING_BROKER], mapYesNoField({ answer: broker[USING_BROKER] })), xlsxRow(FIELDS[BROKER_NAME], broker[BROKER_NAME]), xlsxRow(FIELDS[FULL_ADDRESS], broker[FULL_ADDRESS]), xlsxRow(FIELDS[EMAIL], broker[EMAIL]), @@ -44,7 +44,7 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-exporter-business/map-br const { broker } = mockApplicationNoBroker; - const expected = [xlsxRow(FIELDS[USING_BROKER], mapYesNoField(broker[USING_BROKER]))]; + const expected = [xlsxRow(FIELDS[USING_BROKER], mapYesNoField({ answer: broker[USING_BROKER] }))]; expect(result).toEqual(expected); }); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts index 9d03e28e60..22eec76a55 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-exporter-business/map-broker/index.ts @@ -20,7 +20,7 @@ const { FIELDS } = XLSX; const mapBroker = (application: Application) => { const { broker } = application; - let mapped = [xlsxRow(FIELDS[USING_BROKER], mapYesNoField(broker[USING_BROKER]))]; + let mapped = [xlsxRow(FIELDS[USING_BROKER], mapYesNoField({ answer: broker[USING_BROKER] }))]; if (broker[USING_BROKER]) { mapped = [ diff --git a/src/api/types/helpers/index.ts b/src/api/types/helpers/index.ts new file mode 100644 index 0000000000..6b069b1200 --- /dev/null +++ b/src/api/types/helpers/index.ts @@ -0,0 +1,4 @@ +export interface MapYesNoFieldParams { + answer?: boolean; + defaultValue?: string; +} diff --git a/src/api/types/index.ts b/src/api/types/index.ts index 38cf736e11..f1831c6b89 100644 --- a/src/api/types/index.ts +++ b/src/api/types/index.ts @@ -12,6 +12,7 @@ export * from './email'; export * from './encryption'; export * from './feedback'; export * from './generic'; +export * from './helpers'; export * from './ordnance-survey'; export * from './relationship'; export * from './test-helpers'; From ab29744f1e670f5815bec0a08e92bbfc1bb2aff9 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Thu, 30 May 2024 15:09:07 +0100 Subject: [PATCH 18/29] chore(tests): fix linting issues --- .../insurance/assert-currency-form-fields.js | 9 ++++++++- e2e-tests/fixtures/application.js | 15 +++++++++++++-- .../currency-form-fields/assertions.js | 9 ++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/e2e-tests/commands/insurance/assert-currency-form-fields.js b/e2e-tests/commands/insurance/assert-currency-form-fields.js index 22aab682d1..14262db035 100644 --- a/e2e-tests/commands/insurance/assert-currency-form-fields.js +++ b/e2e-tests/commands/insurance/assert-currency-form-fields.js @@ -1,6 +1,13 @@ import { INSURANCE_FIELD_IDS } from '../../constants/field-ids/insurance'; import { field as fieldSelector, radios, autoCompleteField } from '../../pages/shared'; -import { EUR, GBP, JPY, USD, NON_STANDARD_CURRENCY_CODE, NON_STANDARD_CURRENCY_NAME } from '../../fixtures/currencies'; +import { + EUR, + GBP, + JPY, + USD, + NON_STANDARD_CURRENCY_CODE, + NON_STANDARD_CURRENCY_NAME, +} from '../../fixtures/currencies'; import { checkAutocompleteInput } from '../../shared-test-assertions'; import { DZA } from '../../fixtures/countries'; import partials from '../../partials'; diff --git a/e2e-tests/fixtures/application.js b/e2e-tests/fixtures/application.js index 04b2b7b3cd..ff71a4ce4b 100644 --- a/e2e-tests/fixtures/application.js +++ b/e2e-tests/fixtures/application.js @@ -57,7 +57,12 @@ const { PRIVATE_MARKET: { ATTEMPTED, DECLINED_DESCRIPTION }, AGENT_DETAILS: { COUNTRY_CODE: AGENT_COUNTRY_CODE, FULL_ADDRESS: AGENT_FULL_ADDRESS, NAME: AGENT_NAME }, AGENT_SERVICE: { IS_CHARGING, SERVICE_DESCRIPTION }, - AGENT_CHARGES: { METHOD, PAYABLE_COUNTRY_CODE, FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE }, + AGENT_CHARGES: { + METHOD, + PAYABLE_COUNTRY_CODE, + FIXED_SUM_AMOUNT, + PERCENTAGE_CHARGE, + }, }, EXPORTER_BUSINESS: { ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS: EXPORTER_BUSINESS_FULL_ALT_TRADING_ADDRESS }, @@ -67,7 +72,13 @@ const { YOUR_COMPANY: { DIFFERENT_TRADING_NAME }, }, YOUR_BUYER: { - COMPANY_OR_ORGANISATION: { ADDRESS, COUNTRY, NAME: COMPANY_OR_ORGANISATION_NAME, REGISTRATION_NUMBER, WEBSITE }, + COMPANY_OR_ORGANISATION: { + ADDRESS, + COUNTRY, + NAME: COMPANY_OR_ORGANISATION_NAME, + REGISTRATION_NUMBER, + WEBSITE, + }, CONNECTION_WITH_BUYER, CONNECTION_WITH_BUYER_DESCRIPTION, TRADED_WITH_BUYER, diff --git a/e2e-tests/shared-test-assertions/currency-form-fields/assertions.js b/e2e-tests/shared-test-assertions/currency-form-fields/assertions.js index ff6cb691f0..dad7b02ad7 100644 --- a/e2e-tests/shared-test-assertions/currency-form-fields/assertions.js +++ b/e2e-tests/shared-test-assertions/currency-form-fields/assertions.js @@ -1,6 +1,13 @@ import { INSURANCE_FIELD_IDS } from '../../constants/field-ids/insurance'; import { field as fieldSelector, radios, autoCompleteField } from '../../pages/shared'; -import { EUR, GBP, JPY, USD, NON_STANDARD_CURRENCY_CODE, NON_STANDARD_CURRENCY_NAME } from '../../fixtures/currencies'; +import { + EUR, + GBP, + JPY, + USD, + NON_STANDARD_CURRENCY_CODE, + NON_STANDARD_CURRENCY_NAME, +} from '../../fixtures/currencies'; import { checkAutocompleteInput } from '../autocomplete-assertions'; import { DZA } from '../../fixtures/countries'; import partials from '../../partials'; From 29c8c7fdb50a110e243af646e8ee647a5d310db6 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Thu, 30 May 2024 15:57:53 +0100 Subject: [PATCH 19/29] feat(EMS-3344): address todo comments --- src/api/emails/application/index.ts | 2 +- .../index.api-error.test.ts | 22 ++++++++++++++++++ .../get-populated-application/index.test.ts | 23 ++++--------------- .../test-helpers/create-full-application.ts | 2 +- src/api/types/application-types/index.ts | 2 ++ 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/api/emails/application/index.ts b/src/api/emails/application/index.ts index cb4bb7a584..3ec532342f 100644 --- a/src/api/emails/application/index.ts +++ b/src/api/emails/application/index.ts @@ -54,7 +54,7 @@ const application = { * NOTE: no need to handle an error from fs.unlink here. * If this errors, it will go into the catch handler below. */ - // await fileSystem.unlink(filePath); + await fileSystem.unlink(filePath); return response; } diff --git a/src/api/helpers/get-populated-application/index.api-error.test.ts b/src/api/helpers/get-populated-application/index.api-error.test.ts index 3eb5e65cdc..4cac522eac 100644 --- a/src/api/helpers/get-populated-application/index.api-error.test.ts +++ b/src/api/helpers/get-populated-application/index.api-error.test.ts @@ -179,6 +179,28 @@ describe('api/helpers/get-populated-application - error handling', () => { } }); + it('should throw an error when buyerRelationship does not exist', async () => { + const invalidId = applicationIds.id; + + try { + await getPopulatedApplication(context, { ...applicationIds, buyerRelationship: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('buyerRelationship', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + + it('should throw an error when buyerTradingHistory does not exist', async () => { + const invalidId = applicationIds.id; + + try { + await getPopulatedApplication(context, { ...applicationIds, buyerTradingHistory: invalidId }); + } catch (err) { + const expected = new Error(generateErrorMessage('buyerTradingHistory', applicationIds.id)); + expect(err).toEqual(expected); + } + }); + it('should throw an error when buyer country does not exist', async () => { const invalidId = applicationIds.id; diff --git a/src/api/helpers/get-populated-application/index.test.ts b/src/api/helpers/get-populated-application/index.test.ts index e78781d6a9..577998f328 100644 --- a/src/api/helpers/get-populated-application/index.test.ts +++ b/src/api/helpers/get-populated-application/index.test.ts @@ -59,19 +59,6 @@ describe('api/helpers/get-populated-application', () => { expect(result.sectionReview.id).toEqual(application.sectionReview.id); }); - // it('should return an application with populated buyer country', async () => { - // const result = await getPopulatedApplication(context, applicationIds); - - // const [expectedCountry] = mockCountries; - - // expect(result.buyer.country?.name).toEqual(expectedCountry.name); - // expect(result.buyer.country?.isoCode).toEqual(expectedCountry.isoCode); - // }); - - // TODO: - // it('should return an application with populated eligibility', async () => { - - // TODO: improve test coverage. it('should return an application with populated buyer', async () => { const result = await getPopulatedApplication(context, applicationIds); @@ -81,11 +68,11 @@ describe('api/helpers/get-populated-application', () => { expect(result.buyer.country?.name).toEqual(expectedCountry.name); expect(result.buyer.country?.isoCode).toEqual(expectedCountry.isoCode); - // expect(result.buyer.relationship.id).toEqual(application.buyer.relationship.buyer.id); - expect(result.buyer.exporterIsConnectedWithBuyer).toBeNull(); - - expect(result.buyer.buyerTradingHistory.id).toEqual(application.buyer.buyerTradingHistory.id); - expect(result.buyer.buyerTradingHistory.outstandingPayments).toBeNull(); + expect(result.buyer.relationship.exporterIsConnectedWithBuyer).toBeNull(); + expect(result.buyer.relationship.connectionWithBuyerDescription).toEqual(''); + expect(result.buyer.relationship.exporterHasPreviousCreditInsuranceWithBuyer).toBeNull(); + expect(result.buyer.relationship.exporterHasBuyerFinancialAccounts).toBeNull(); + expect(result.buyer.relationship.previousCreditInsuranceWithBuyerDescription).toEqual(''); }); it('should return an application with populated company', async () => { diff --git a/src/api/test-helpers/create-full-application.ts b/src/api/test-helpers/create-full-application.ts index 4650ad9d1c..b61a50fa77 100644 --- a/src/api/test-helpers/create-full-application.ts +++ b/src/api/test-helpers/create-full-application.ts @@ -65,7 +65,7 @@ export const createFullApplication = async (context: Context, policyType?: strin // create a new application const application = (await context.query.Application.createOne({ query: - 'id referenceNumber updatedAt submissionCount policyContact { id } exportContract { id } owner { id } company { id } business { id } nominatedLossPayee { id } broker { id } declaration { id } sectionReview { id } buyer { id buyerTradingHistory { id } }', + 'id referenceNumber updatedAt submissionCount policyContact { id } exportContract { id } owner { id } company { id } business { id } nominatedLossPayee { id } broker { id } declaration { id } sectionReview { id } buyer { id buyerTradingHistory { id } relationship { id } }', data: { owner: { connect: { diff --git a/src/api/types/application-types/index.ts b/src/api/types/application-types/index.ts index 4f2e866248..82bead12a4 100644 --- a/src/api/types/application-types/index.ts +++ b/src/api/types/application-types/index.ts @@ -17,6 +17,8 @@ export interface BuyerTradingHistory extends Relationship { exporterHasTradedWithBuyer?: boolean; failedPayments?: boolean; outstandingPayments?: boolean; + totalOutstandingPayments?: number; + totalOverduePayments?: number; } export interface ApplicationBuyerRelationship extends Relationship { From e12f36966cddde0ebdcef7c1cfb68a1181905c07 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Thu, 30 May 2024 16:13:42 +0100 Subject: [PATCH 20/29] feat(EMS-3344): fix/update e2e test --- ...complete-prepare-application-section-multiple-policy-type.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js b/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js index cbed85b390..0712e45ae4 100644 --- a/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js +++ b/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js @@ -67,7 +67,7 @@ const completePrepareApplicationMultiplePolicyType = ({ }); cy.completeBuyerSection({ - alternativeBuyerCurrency, + alternativeCurrency: alternativeBuyerCurrency, hasConnectionToBuyer, exporterHasTradedWithBuyer, outstandingPayments: buyerOutstandingPayments, From 857524b2b2ff5f9dcefddb2b43690131dbee2f0b Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Thu, 30 May 2024 16:24:03 +0100 Subject: [PATCH 21/29] chore(tests): split up application submission e2e tests --- .github/workflows/test.yml | 23 ++++++------- ...fferent-trading-address-and-broker.spec.js | 2 +- ...ype-with-different-trading-address.spec.js | 2 +- ...nt-trading-name-address-and-broker.spec.js | 2 +- ...different-trading-name-and-address.spec.js | 2 +- ...-different-trading-name-and-broker.spec.js | 2 +- ...y-type-with-different-trading-name.spec.js | 2 +- ...over-and-using-an-agent-no-charges.spec.js | 2 +- ...ng-an-agent-with-charges-fixed-sum.spec.js | 33 +++++++++++++++++++ ...g-an-agent-with-charges-percentage.spec.js | 33 +++++++++++++++++++ ...ype-attempted-private-market-cover.spec.js | 2 +- ...e-policy-type-using-an-agent-cover.spec.js | 2 +- ...licy-type-loss-payee-international.spec.js | 2 +- ...multiple-policy-type-loss-payee-uk.spec.js | 2 +- ...multiple-policy-type-maximum-cover.spec.js | 29 ++++++++++++++++ ...n-multiple-policy-type-with-broker.spec.js | 29 ++++++++++++++++ ...ng-an-agent-with-charges-fixed-sum.spec.js | 30 ----------------- ...g-an-agent-with-charges-percentage.spec.js | 30 ----------------- ...multiple-policy-type-maximum-cover.spec.js | 26 --------------- ...n-multiple-policy-type-with-broker.spec.js | 26 --------------- ...fferent-trading-address-and-broker.spec.js | 0 ...ype-with-different-trading-address.spec.js | 0 ...nt-trading-name-address-and-broker.spec.js | 0 ...different-trading-name-and-address.spec.js | 0 ...-different-trading-name-and-broker.spec.js | 0 ...y-type-with-different-trading-name.spec.js | 0 ...over-and-using-an-agent-no-charges.spec.js | 0 ...ng-an-agent-with-charges-fixed-sum.spec.js | 0 ...g-an-agent-with-charges-percentage.spec.js | 0 ...ype-attempted-private-market-cover.spec.js | 0 ...e-policy-type-using-an-agent-cover.spec.js | 0 ...licy-type-loss-payee-international.spec.js | 0 ...n-single-policy-type-loss-payee-uk.spec.js | 0 ...n-single-policy-type-maximum-cover.spec.js | 26 +++++++++++++++ ...ion-single-policy-type-with-broker.spec.js | 24 ++++++++++++++ ...n-single-policy-type-maximum-cover.spec.js | 23 ------------- ...ion-single-policy-type-with-broker.spec.js | 21 ------------ 37 files changed, 197 insertions(+), 178 deletions(-) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/{ => business-conditions}/submit-an-application-multiple-policy-type-with-different-trading-address-and-broker.spec.js (93%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/{ => business-conditions}/submit-an-application-multiple-policy-type-with-different-trading-address.spec.js (93%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/{ => business-conditions}/submit-an-application-multiple-policy-type-with-different-trading-name-address-and-broker.spec.js (93%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/{ => business-conditions}/submit-an-application-multiple-policy-type-with-different-trading-name-and-address.spec.js (93%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/{ => business-conditions}/submit-an-application-multiple-policy-type-with-different-trading-name-and-broker.spec.js (93%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/{ => business-conditions}/submit-an-application-multiple-policy-type-with-different-trading-name.spec.js (92%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/{ => export-contract-conditions}/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-no-charges.spec.js (92%) create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/{ => export-contract-conditions}/submit-an-application-multiple-policy-type-attempted-private-market-cover.spec.js (91%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/{ => export-contract-conditions}/submit-an-application-multiple-policy-type-using-an-agent-cover.spec.js (90%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/{ => policy-conditions}/submit-an-application-multiple-policy-type-loss-payee-international.spec.js (91%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/{ => policy-conditions}/submit-an-application-multiple-policy-type-loss-payee-uk.spec.js (91%) create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-maximum-cover.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-with-broker.spec.js delete mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js delete mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js delete mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-maximum-cover.spec.js delete mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-broker.spec.js rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => business-conditions}/submit-an-application-single-policy-type-with-different-trading-address-and-broker.spec.js (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => business-conditions}/submit-an-application-single-policy-type-with-different-trading-address.spec.js (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => business-conditions}/submit-an-application-single-policy-type-with-different-trading-name-address-and-broker.spec.js (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => business-conditions}/submit-an-application-single-policy-type-with-different-trading-name-and-address.spec.js (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => business-conditions}/submit-an-application-single-policy-type-with-different-trading-name-and-broker.spec.js (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => business-conditions}/submit-an-application-single-policy-type-with-different-trading-name.spec.js (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => export-contract-conditions}/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-no-charges.spec.js (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => export-contract-conditions}/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => export-contract-conditions}/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => export-contract-conditions}/submit-an-application-single-policy-type-attempted-private-market-cover.spec.js (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => export-contract-conditions}/submit-an-application-single-policy-type-using-an-agent-cover.spec.js (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => policy-conditions}/submit-an-application-single-policy-type-loss-payee-international.spec.js (100%) rename e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/{ => policy-conditions}/submit-an-application-single-policy-type-loss-payee-uk.spec.js (100%) create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-maximum-cover.spec.js create mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-with-broker.spec.js delete mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-maximum-cover.spec.js delete mode 100644 e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-broker.spec.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8697487226..cdaeac97ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -192,17 +192,18 @@ jobs: matrix: spec: [ - "/*.spec.js", - "account/create/**/*.spec.js", - "account/manage/**/*.spec.js", - "account/password-reset/**/*.spec.js", - "account/reactivated/**/*.spec.js", - "account/sign-in/**/*.spec.js", - "account/sign-out/**/*.spec.js", - "account/suspended/**/*.spec.js", - "application-submission/*.spec.js", - "application-submission/multiple-policy-type/**/*.spec.js", - "application-submission/single-policy-type/**/*.spec.js", + "application-submission/multiple-policy-type/*.spec.js", + "application-submission/multiple-policy-type/business-conditions/*.spec.js", + "application-submission/multiple-policy-type/buyer-conditions/*.spec.js", + "application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/*.spec.js", + "application-submission/multiple-policy-type/export-contract-conditions/*.spec.js", + "application-submission/multiple-policy-type/policy-contract-conditions/*.spec.js", + "application-submission/single-policy-type/*.spec.js", + "application-submission/single-policy-type/business-conditions/*.spec.js", + "application-submission/single-policy-type/buyer-conditions/*.spec.js", + "application-submission/single-policy-type/buyer-conditions/traded-with-buyer/*.spec.js", + "application-submission/single-policy-type/export-contract-conditions/*.spec.js", + "application-submission/single-policy-type/policy-contract-conditions/*.spec.js", "cannot-skip-flow/**/*.spec.js", "check-your-answers/export-contract/*.spec.js", "check-your-answers/export-contract/change-your-answers/about-goods-or-services/*.spec.js", diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address-and-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-address-and-broker.spec.js similarity index 93% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address-and-broker.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-address-and-broker.spec.js index b8c8946221..6f9dcdb214 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address-and-broker.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-address-and-broker.spec.js @@ -1,4 +1,4 @@ -import { APPLICATION } from '../../../../../../constants'; +import { APPLICATION } from '../../../../../../../constants'; context( 'Insurance - submit an application - Single policy type with a different trading address and broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-address.spec.js similarity index 93% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-address.spec.js index 9ed4402eca..437cdfbc1a 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-address.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-address.spec.js @@ -1,4 +1,4 @@ -import { APPLICATION } from '../../../../../../constants'; +import { APPLICATION } from '../../../../../../../constants'; context( 'Insurance - submit an application - Multiple policy type, different trading address - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-address-and-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-name-address-and-broker.spec.js similarity index 93% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-address-and-broker.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-name-address-and-broker.spec.js index f203ed5fd1..388fc035ff 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-address-and-broker.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-name-address-and-broker.spec.js @@ -1,4 +1,4 @@ -import { APPLICATION } from '../../../../../../constants'; +import { APPLICATION } from '../../../../../../../constants'; context( 'Insurance - submit an application - Single policy type with a different trading name, address and broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-address.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-name-and-address.spec.js similarity index 93% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-address.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-name-and-address.spec.js index f09bf99b73..376a35e6f2 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-address.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-name-and-address.spec.js @@ -1,4 +1,4 @@ -import { APPLICATION } from '../../../../../../constants'; +import { APPLICATION } from '../../../../../../../constants'; context( 'Insurance - submit an application - Multiple policy type, different trading name and address - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-name-and-broker.spec.js similarity index 93% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-broker.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-name-and-broker.spec.js index af5c89a9c0..1953cf7dd8 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name-and-broker.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-name-and-broker.spec.js @@ -1,4 +1,4 @@ -import { APPLICATION } from '../../../../../../constants'; +import { APPLICATION } from '../../../../../../../constants'; context( 'Insurance - submit an application - Single policy type with a different trading name and broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-name.spec.js similarity index 92% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-name.spec.js index 34ed61ac18..e0f711b5d6 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-different-trading-name.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/business-conditions/submit-an-application-multiple-policy-type-with-different-trading-name.spec.js @@ -1,4 +1,4 @@ -import { APPLICATION } from '../../../../../../constants'; +import { APPLICATION } from '../../../../../../../constants'; context( 'Insurance - submit an application - Multiple policy type, different trading name - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-no-charges.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-no-charges.spec.js similarity index 92% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-no-charges.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-no-charges.spec.js index cee2b9bf57..188227bd3d 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-no-charges.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-no-charges.spec.js @@ -1,4 +1,4 @@ -import { APPLICATION } from '../../../../../../constants'; +import { APPLICATION } from '../../../../../../../constants'; context('Insurance - submit an application - Multiple policy type, attempted private market cover, using an agent, no agent charges', () => { let referenceNumber; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js new file mode 100644 index 0000000000..3cb38cecbe --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js @@ -0,0 +1,33 @@ +import { APPLICATION } from '../../../../../../../constants'; + +context( + 'Insurance - submit an application - Multiple policy type, attempted private market cover, using an agent, agent is charging - fixed sum method', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + totalContractValueOverThreshold: true, + attemptedPrivateMarketCover: true, + isUsingAgent: true, + agentIsCharging: true, + agentChargeMethodFixedSum: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js new file mode 100644 index 0000000000..118e6b1976 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js @@ -0,0 +1,33 @@ +import { APPLICATION } from '../../../../../../../constants'; + +context( + 'Insurance - submit an application - Multiple policy type, attempted private market cover, using an agent, agent is charging - percentage method', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + totalContractValueOverThreshold: true, + attemptedPrivateMarketCover: true, + isUsingAgent: true, + agentIsCharging: true, + agentChargeMethodPercentage: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover.spec.js similarity index 91% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover.spec.js index c6672b11b6..a19472505f 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-attempted-private-market-cover.spec.js @@ -1,4 +1,4 @@ -import { APPLICATION } from '../../../../../../constants'; +import { APPLICATION } from '../../../../../../../constants'; context('Insurance - submit an application - Multiple policy type, attempted private market cover', () => { let referenceNumber; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-using-an-agent-cover.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-using-an-agent-cover.spec.js similarity index 90% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-using-an-agent-cover.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-using-an-agent-cover.spec.js index e039182259..ddc68146e0 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-using-an-agent-cover.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-using-an-agent-cover.spec.js @@ -1,4 +1,4 @@ -import { APPLICATION } from '../../../../../../constants'; +import { APPLICATION } from '../../../../../../../constants'; context('Insurance - submit an application - Multiple policy type, using an agent', () => { let referenceNumber; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-loss-payee-international.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-loss-payee-international.spec.js similarity index 91% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-loss-payee-international.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-loss-payee-international.spec.js index 394844cfd1..11746dda61 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-loss-payee-international.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-loss-payee-international.spec.js @@ -1,4 +1,4 @@ -import { APPLICATION } from '../../../../../../constants'; +import { APPLICATION } from '../../../../../../../constants'; context('Insurance - submit an application - Multiple policy type, Loss payee - Financial details International ', () => { let referenceNumber; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-loss-payee-uk.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-loss-payee-uk.spec.js similarity index 91% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-loss-payee-uk.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-loss-payee-uk.spec.js index 22434ccbc1..2daa87bfea 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-loss-payee-uk.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-loss-payee-uk.spec.js @@ -1,4 +1,4 @@ -import { APPLICATION } from '../../../../../../constants'; +import { APPLICATION } from '../../../../../../../constants'; context('Insurance - submit an application - Single policy type, Loss payee - Financial details UK ', () => { let referenceNumber; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-maximum-cover.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-maximum-cover.spec.js new file mode 100644 index 0000000000..4122e87d47 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-maximum-cover.spec.js @@ -0,0 +1,29 @@ +import { APPLICATION } from '../../../../../../../constants'; + +context( + 'Insurance - submit an application - Multiple policy type, no broker - As an Exporter, I want to submit my completed credit insurance application with a value greater than 500000, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + policyValueOverMvpMaximum: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-with-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-with-broker.spec.js new file mode 100644 index 0000000000..c2978fe104 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-with-broker.spec.js @@ -0,0 +1,29 @@ +import { APPLICATION } from '../../../../../../../constants'; + +context( + 'Insurance - submit an application - Multiple policy type with a broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + usingBroker: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js deleted file mode 100644 index f93819b4e1..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js +++ /dev/null @@ -1,30 +0,0 @@ -import { APPLICATION } from '../../../../../../constants'; - -context('Insurance - submit an application - Multiple policy type, attempted private market cover, using an agent, agent is charging - fixed sum method', () => { - let referenceNumber; - - before(() => { - cy.completeSignInAndSubmitAnApplication({ - policyType: APPLICATION.POLICY_TYPE.MULTIPLE, - totalContractValueOverThreshold: true, - attemptedPrivateMarketCover: true, - isUsingAgent: true, - agentIsCharging: true, - agentChargeMethodFixedSum: true, - }).then((refNumber) => { - referenceNumber = refNumber; - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - it('should successfully submit the application and redirect to `application submitted`', () => { - cy.assertApplicationSubmittedUrl(referenceNumber); - }); -}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js deleted file mode 100644 index 2361f3f818..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js +++ /dev/null @@ -1,30 +0,0 @@ -import { APPLICATION } from '../../../../../../constants'; - -context('Insurance - submit an application - Multiple policy type, attempted private market cover, using an agent, agent is charging - percentage method', () => { - let referenceNumber; - - before(() => { - cy.completeSignInAndSubmitAnApplication({ - policyType: APPLICATION.POLICY_TYPE.MULTIPLE, - totalContractValueOverThreshold: true, - attemptedPrivateMarketCover: true, - isUsingAgent: true, - agentIsCharging: true, - agentChargeMethodPercentage: true, - }).then((refNumber) => { - referenceNumber = refNumber; - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - it('should successfully submit the application and redirect to `application submitted`', () => { - cy.assertApplicationSubmittedUrl(referenceNumber); - }); -}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-maximum-cover.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-maximum-cover.spec.js deleted file mode 100644 index 0f7a9185e0..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-maximum-cover.spec.js +++ /dev/null @@ -1,26 +0,0 @@ -import { APPLICATION } from '../../../../../../constants'; - -context('Insurance - submit an application - Multiple policy type, no broker - As an Exporter, I want to submit my completed credit insurance application with a value greater than 500000, So that UKEF can process and make a decision on my application', () => { - let referenceNumber; - - before(() => { - cy.completeSignInAndSubmitAnApplication({ - policyType: APPLICATION.POLICY_TYPE.MULTIPLE, - policyValueOverMvpMaximum: true, - }).then((refNumber) => { - referenceNumber = refNumber; - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - it('should successfully submit the application and redirect to `application submitted`', () => { - cy.assertApplicationSubmittedUrl(referenceNumber); - }); -}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-broker.spec.js deleted file mode 100644 index fd696cc027..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-with-broker.spec.js +++ /dev/null @@ -1,26 +0,0 @@ -import { APPLICATION } from '../../../../../../constants'; - -context('Insurance - submit an application - Multiple policy type with a broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', () => { - let referenceNumber; - - before(() => { - cy.completeSignInAndSubmitAnApplication({ - policyType: APPLICATION.POLICY_TYPE.MULTIPLE, - usingBroker: true, - }).then((refNumber) => { - referenceNumber = refNumber; - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - it('should successfully submit the application and redirect to `application submitted`', () => { - cy.assertApplicationSubmittedUrl(referenceNumber); - }); -}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-address-and-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/business-conditions/submit-an-application-single-policy-type-with-different-trading-address-and-broker.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-address-and-broker.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/business-conditions/submit-an-application-single-policy-type-with-different-trading-address-and-broker.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-address.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/business-conditions/submit-an-application-single-policy-type-with-different-trading-address.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-address.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/business-conditions/submit-an-application-single-policy-type-with-different-trading-address.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-address-and-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/business-conditions/submit-an-application-single-policy-type-with-different-trading-name-address-and-broker.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-address-and-broker.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/business-conditions/submit-an-application-single-policy-type-with-different-trading-name-address-and-broker.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-and-address.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/business-conditions/submit-an-application-single-policy-type-with-different-trading-name-and-address.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-and-address.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/business-conditions/submit-an-application-single-policy-type-with-different-trading-name-and-address.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-and-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/business-conditions/submit-an-application-single-policy-type-with-different-trading-name-and-broker.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name-and-broker.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/business-conditions/submit-an-application-single-policy-type-with-different-trading-name-and-broker.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/business-conditions/submit-an-application-single-policy-type-with-different-trading-name.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-different-trading-name.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/business-conditions/submit-an-application-single-policy-type-with-different-trading-name.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-no-charges.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-no-charges.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-no-charges.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-no-charges.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-fixed-sum.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-attempted-private-market-cover-and-using-an-agent-with-charges-percentage.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-attempted-private-market-cover.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-attempted-private-market-cover.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-attempted-private-market-cover.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-attempted-private-market-cover.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-using-an-agent-cover.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-using-an-agent-cover.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-using-an-agent-cover.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-using-an-agent-cover.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-loss-payee-international.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-loss-payee-international.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-loss-payee-international.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-loss-payee-international.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-loss-payee-uk.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-loss-payee-uk.spec.js similarity index 100% rename from e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-loss-payee-uk.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-loss-payee-uk.spec.js diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-maximum-cover.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-maximum-cover.spec.js new file mode 100644 index 0000000000..34498e674d --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-maximum-cover.spec.js @@ -0,0 +1,26 @@ +context( + 'Insurance - submit an application - Single policy type, no broker - As an Exporter, I want to submit my completed credit insurance application with a value greater than 500000, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyValueOverMvpMaximum: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-with-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-with-broker.spec.js new file mode 100644 index 0000000000..edd57e314e --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-with-broker.spec.js @@ -0,0 +1,24 @@ +context( + 'Insurance - submit an application - Single policy type with a broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ usingBroker: true }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-maximum-cover.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-maximum-cover.spec.js deleted file mode 100644 index 38efdb4c39..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-maximum-cover.spec.js +++ /dev/null @@ -1,23 +0,0 @@ -context('Insurance - submit an application - Single policy type, no broker - As an Exporter, I want to submit my completed credit insurance application with a value greater than 500000, So that UKEF can process and make a decision on my application', () => { - let referenceNumber; - - before(() => { - cy.completeSignInAndSubmitAnApplication({ - policyValueOverMvpMaximum: true, - }).then((refNumber) => { - referenceNumber = refNumber; - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - it('should successfully submit the application and redirect to `application submitted`', () => { - cy.assertApplicationSubmittedUrl(referenceNumber); - }); -}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-broker.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-broker.spec.js deleted file mode 100644 index 8c79634187..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-with-broker.spec.js +++ /dev/null @@ -1,21 +0,0 @@ -context('Insurance - submit an application - Single policy type with a broker - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', () => { - let referenceNumber; - - before(() => { - cy.completeSignInAndSubmitAnApplication({ usingBroker: true }).then((refNumber) => { - referenceNumber = refNumber; - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - it('should successfully submit the application and redirect to `application submitted`', () => { - cy.assertApplicationSubmittedUrl(referenceNumber); - }); -}); From 232cd0e4fe6255f9c0525a9d8edf7ad9b81dd63b Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Thu, 30 May 2024 16:24:16 +0100 Subject: [PATCH 22/29] chore(EMS-3344): remove commented code --- src/api/.keystone/config.js | 1 + src/api/helpers/get-populated-application/index.test.ts | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index f3596128a2..ddaeeeab8d 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -3008,6 +3008,7 @@ var application = { if (file) { const fileBuffer = Buffer.from(file); const response = await callNotify(templateId, emailAddress, variables, fileBuffer); + await file_system_default.unlink(filePath); return response; } throw new Error("Sending application submitted email to underwriting team - invalid file / file not found"); diff --git a/src/api/helpers/get-populated-application/index.test.ts b/src/api/helpers/get-populated-application/index.test.ts index 577998f328..688b715515 100644 --- a/src/api/helpers/get-populated-application/index.test.ts +++ b/src/api/helpers/get-populated-application/index.test.ts @@ -46,7 +46,6 @@ describe('api/helpers/get-populated-application', () => { expect(result.business.id).toEqual(application.business.id); expect(result.broker.id).toEqual(application.broker.id); - // expect(result.buyer.id).toEqual(application.buyer.id); expect(result.declaration.id).toEqual(application.declaration.id); expect(result.eligibility.id).toEqual(application.eligibility.id); expect(result.eligibility.coverPeriod.id).toEqual(application.eligibility.coverPeriodId); From 9e5b395c5260d6a8220a568faa5fd1dde8c3dc2d Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Thu, 30 May 2024 16:26:59 +0100 Subject: [PATCH 23/29] chore(tests): fix/revert some test.yml changes --- .github/workflows/test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cdaeac97ab..b08f1eec6f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -192,6 +192,14 @@ jobs: matrix: spec: [ + "/*.spec.js", + "account/create/**/*.spec.js", + "account/manage/**/*.spec.js", + "account/password-reset/**/*.spec.js", + "account/reactivated/**/*.spec.js", + "account/sign-in/**/*.spec.js", + "account/sign-out/**/*.spec.js", + "account/suspended/**/*.spec.js", "application-submission/multiple-policy-type/*.spec.js", "application-submission/multiple-policy-type/business-conditions/*.spec.js", "application-submission/multiple-policy-type/buyer-conditions/*.spec.js", From 7887528b8791e0b052ee6204700f25470967c21b Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Thu, 30 May 2024 16:50:13 +0100 Subject: [PATCH 24/29] feat(EMS-3344): fix typo --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b08f1eec6f..dc280a3252 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -205,13 +205,14 @@ jobs: "application-submission/multiple-policy-type/buyer-conditions/*.spec.js", "application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/*.spec.js", "application-submission/multiple-policy-type/export-contract-conditions/*.spec.js", - "application-submission/multiple-policy-type/policy-contract-conditions/*.spec.js", + "application-submission/multiple-policy-type/policy-conditions/*.spec.js", + "application-submission/single-policy-type/*.spec.js", "application-submission/single-policy-type/business-conditions/*.spec.js", "application-submission/single-policy-type/buyer-conditions/*.spec.js", "application-submission/single-policy-type/buyer-conditions/traded-with-buyer/*.spec.js", "application-submission/single-policy-type/export-contract-conditions/*.spec.js", - "application-submission/single-policy-type/policy-contract-conditions/*.spec.js", + "application-submission/single-policy-type/policy-conditions/*.spec.js", "cannot-skip-flow/**/*.spec.js", "check-your-answers/export-contract/*.spec.js", "check-your-answers/export-contract/change-your-answers/about-goods-or-services/*.spec.js", From 426d5976971f03cc3a81220066f0a43a9f282c8d Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Fri, 31 May 2024 10:03:41 +0100 Subject: [PATCH 25/29] feat(EMS-3344): fix typo --- .../helpers/map-yes-no-field/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.test.ts index ff210ca6af..822513624b 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/helpers/map-yes-no-field/index.test.ts @@ -15,7 +15,7 @@ describe('api/generate-xlsx/map-application-to-xlsx/helpers/map-yes-no-field', ( describe('when value is "false"', () => { it(`should return "${NO}"`, () => { - const response = mapYesNoField({ answer: true }); + const response = mapYesNoField({ answer: false }); expect(response).toEqual(NO); }); From 6a5d1e417ca8d1c60557a6433dc3d62d977936fb Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Sat, 1 Jun 2024 10:51:32 +0100 Subject: [PATCH 26/29] feat(EMS-3344): improve e2e test descriptions --- ...y-type-buyer-no-financial-accounts.spec.js | 2 +- ...ding-payments-alternative-currency.spec.js | 47 ++++++++++--------- ...multiple-policy-type-maximum-cover.spec.js | 2 +- ...y-type-buyer-no-financial-accounts.spec.js | 2 +- ...n-single-policy-type-maximum-cover.spec.js | 2 +- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-buyer-no-financial-accounts.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-buyer-no-financial-accounts.spec.js index 780ace3ee6..73c0d86e36 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-buyer-no-financial-accounts.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/submit-an-application-multiple-policy-type-buyer-no-financial-accounts.spec.js @@ -1,6 +1,6 @@ import { APPLICATION } from '../../../../../../../constants'; -context('Insurance - submit an application - Multiple policy type, fully populated buyer', () => { +context('Insurance - submit an application - Multiple policy type, fully populated buyer, no financial accounts', () => { let referenceNumber; before(() => { diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-alternative-currency.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-alternative-currency.spec.js index 2be67cea87..35435738b4 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-alternative-currency.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/buyer-conditions/traded-with-buyer/outstanding-payments-alternative-currency.spec.js @@ -1,29 +1,32 @@ import { APPLICATION } from '../../../../../../../../constants'; -context('Insurance - submit an application - Multiple policy type, exporter has traded with buyer, has outstanding payments, alternative currency', () => { - let referenceNumber; +context( + 'Insurance - submit an application - Multiple policy type, exporter has traded with buyer, has outstanding payments, failed to pay on time, alternative currency', + () => { + let referenceNumber; - before(() => { - cy.completeSignInAndSubmitAnApplication({ - policyType: APPLICATION.POLICY_TYPE.MULTIPLE, - alternativeBuyerCurrency: true, - exporterHasTradedWithBuyer: true, - buyerOutstandingPayments: true, - buyerFailedToPayOnTime: true, - }).then((refNumber) => { - referenceNumber = refNumber; + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + alternativeBuyerCurrency: true, + exporterHasTradedWithBuyer: true, + buyerOutstandingPayments: true, + buyerFailedToPayOnTime: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); }); - }); - beforeEach(() => { - cy.saveSession(); - }); + beforeEach(() => { + cy.saveSession(); + }); - after(() => { - cy.deleteApplication(referenceNumber); - }); + after(() => { + cy.deleteApplication(referenceNumber); + }); - it('should successfully submit the application and redirect to `application submitted`', () => { - cy.assertApplicationSubmittedUrl(referenceNumber); - }); -}); + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-maximum-cover.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-maximum-cover.spec.js index 4122e87d47..b318d8e1f4 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-maximum-cover.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-maximum-cover.spec.js @@ -1,7 +1,7 @@ import { APPLICATION } from '../../../../../../../constants'; context( - 'Insurance - submit an application - Multiple policy type, no broker - As an Exporter, I want to submit my completed credit insurance application with a value greater than 500000, So that UKEF can process and make a decision on my application', + 'Insurance - submit an application - Multiple policy type - As an Exporter, I want to submit my completed credit insurance application with a value greater than 500000, So that UKEF can process and make a decision on my application', () => { let referenceNumber; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-no-financial-accounts.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-no-financial-accounts.spec.js index b37cbf19ba..bd7acc1cb1 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-no-financial-accounts.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/buyer-conditions/submit-an-application-single-policy-type-buyer-no-financial-accounts.spec.js @@ -1,4 +1,4 @@ -context('Insurance - submit an application - Single policy type, fully populated buyer', () => { +context('Insurance - submit an application - Single policy type, fully populated buyer, no financial accounts', () => { let referenceNumber; before(() => { diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-maximum-cover.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-maximum-cover.spec.js index 34498e674d..9c102494cb 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-maximum-cover.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-maximum-cover.spec.js @@ -1,5 +1,5 @@ context( - 'Insurance - submit an application - Single policy type, no broker - As an Exporter, I want to submit my completed credit insurance application with a value greater than 500000, So that UKEF can process and make a decision on my application', + 'Insurance - submit an application - Single policy type - As an Exporter, I want to submit my completed credit insurance application with a value greater than 500000, So that UKEF can process and make a decision on my application', () => { let referenceNumber; From c12f98a31bcd4c8b8892205f684b6316a2f9dd8f Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Mon, 3 Jun 2024 10:05:08 +0100 Subject: [PATCH 27/29] chore(tests): fix failing date test --- src/ui/server/shared-validation/date/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/server/shared-validation/date/index.test.ts b/src/ui/server/shared-validation/date/index.test.ts index 2cb68e2e77..2a99a63fda 100644 --- a/src/ui/server/shared-validation/date/index.test.ts +++ b/src/ui/server/shared-validation/date/index.test.ts @@ -26,7 +26,7 @@ describe('shared-validation/date', () => { const month = date.getMonth() + 1; const year = date.getFullYear(); - const futureDate = new Date(date.setMonth(month + 6)); + const futureDate = new Date(date.setMonth(month)); const futureDateMonth = futureDate.getMonth(); const futureDateYear = futureDate.getFullYear(); const futureDateDay = getDaysInAMonth(futureDateMonth, futureDateYear); From 6b560a1d69b3aacf83d70d45011da5d372b26ff0 Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Mon, 3 Jun 2024 10:41:35 +0100 Subject: [PATCH 28/29] feat(EMS-3344): no pdf - application submission - XLSX - fix indexing issue --- src/api/.keystone/config.js | 2 +- .../index-multiple-contract-policy-using-a-broker.test.ts | 8 ++++---- .../index-single-contract-policy-using-a-broker.test.ts | 8 ++++---- src/api/constants/XLSX-CONFIG/index.ts | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index ddaeeeab8d..7e30295a73 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -855,7 +855,7 @@ var XLSX_ROW_INDEXES = (application2) => { if (broker[USING_BROKER]) { indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; - indexes.TITLES.DECLARATIONS += 6; + indexes.TITLES.DECLARATIONS += 3; indexes.BROKER_ADDRESS = 48; indexes.BUYER_ADDRESS += 3; } diff --git a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts index 1df6c30a08..f6cca39839 100644 --- a/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts +++ b/src/api/constants/XLSX-CONFIG/index-multiple-contract-policy-using-a-broker.test.ts @@ -37,7 +37,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...indexes.TITLES, POLICY: indexes.TITLES.POLICY + 3, BUYER: indexes.TITLES.BUYER + 4, - DECLARATIONS: indexes.TITLES.DECLARATIONS + 7, + DECLARATIONS: indexes.TITLES.DECLARATIONS + 4, }, }; @@ -63,7 +63,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...incremented.TITLES, POLICY: incremented.TITLES.POLICY + 3, BUYER: incremented.TITLES.BUYER + 4, - DECLARATIONS: incremented.TITLES.DECLARATIONS + 7, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 4, }, }; @@ -94,7 +94,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...incremented.TITLES, POLICY: incremented.TITLES.POLICY + 3, BUYER: incremented.TITLES.BUYER + 4, - DECLARATIONS: incremented.TITLES.DECLARATIONS + 7, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 4, }, }; @@ -122,7 +122,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...secondIncrement.TITLES, POLICY: incremented.TITLES.POLICY + 3, BUYER: incremented.TITLES.BUYER + 4, - DECLARATIONS: incremented.TITLES.DECLARATIONS + 7, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 4, }, }; diff --git a/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts index ec7cfc6236..1970c4c4e1 100644 --- a/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts +++ b/src/api/constants/XLSX-CONFIG/index-single-contract-policy-using-a-broker.test.ts @@ -36,7 +36,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...indexes.TITLES, POLICY: indexes.TITLES.POLICY + 3, BUYER: indexes.TITLES.BUYER + 3, - DECLARATIONS: indexes.TITLES.DECLARATIONS + 6, + DECLARATIONS: indexes.TITLES.DECLARATIONS + 3, }, }; @@ -61,7 +61,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...incremented.TITLES, POLICY: incremented.TITLES.POLICY + 3, BUYER: incremented.TITLES.BUYER + 3, - DECLARATIONS: incremented.TITLES.DECLARATIONS + 6, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 3, }, }; @@ -91,7 +91,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...incremented.TITLES, POLICY: incremented.TITLES.POLICY + 3, BUYER: incremented.TITLES.BUYER + 3, - DECLARATIONS: incremented.TITLES.DECLARATIONS + 6, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 3, }, }; @@ -118,7 +118,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY ...secondIncrement.TITLES, POLICY: incremented.TITLES.POLICY + 3, BUYER: incremented.TITLES.BUYER + 3, - DECLARATIONS: incremented.TITLES.DECLARATIONS + 6, + DECLARATIONS: incremented.TITLES.DECLARATIONS + 3, }, }; diff --git a/src/api/constants/XLSX-CONFIG/index.ts b/src/api/constants/XLSX-CONFIG/index.ts index 1c9bd7d22c..4a4518aa14 100644 --- a/src/api/constants/XLSX-CONFIG/index.ts +++ b/src/api/constants/XLSX-CONFIG/index.ts @@ -52,7 +52,7 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => { if (broker[USING_BROKER]) { indexes.TITLES.POLICY += 3; indexes.TITLES.BUYER += 3; - indexes.TITLES.DECLARATIONS += 6; + indexes.TITLES.DECLARATIONS += 3; indexes.BROKER_ADDRESS = 48; indexes.BUYER_ADDRESS += 3; From 43b7aeb2117e9406d0573d33a6d81a072d50bcae Mon Sep 17 00:00:00 2001 From: ttbarnes Date: Tue, 4 Jun 2024 09:58:25 +0100 Subject: [PATCH 29/29] feat(EMS-3344): unit test improvement --- .../map-connection-with-buyer/index.ts | 2 +- .../index.api-error.test.ts | 54 +++++++------------ 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.ts index 33a33215bd..2f6d0b1e7c 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-buyer/map-connection-with-buyer/index.ts @@ -8,7 +8,7 @@ const { CONNECTION_WITH_BUYER, CONNECTION_WITH_BUYER_DESCRIPTION } = FIELD_IDS; const { FIELDS } = XLSX; /** - * mapPreviousCoverWithBuyer + * mapConnectionWithBuyer * Generate an XLSX row if an exporter has a connection with the buyer. * @param {ApplicationBuyerRelationship} relationship: Application buyer relationship * @returns {Object | undefined} xlsxRow diff --git a/src/api/helpers/get-populated-application/index.api-error.test.ts b/src/api/helpers/get-populated-application/index.api-error.test.ts index 4cac522eac..49fc1b8ead 100644 --- a/src/api/helpers/get-populated-application/index.api-error.test.ts +++ b/src/api/helpers/get-populated-application/index.api-error.test.ts @@ -79,23 +79,17 @@ describe('api/helpers/get-populated-application - error handling', () => { it('should throw an error when policy does not exist', async () => { const invalidId = applicationIds.id; - try { - await getPopulatedApplication(context, { ...applicationIds, policyId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('policy', applicationIds.id)); - expect(err).toEqual(expected); - } + const expected = new Error(generateErrorMessage('policy', applicationIds.id)); + + await expect(getPopulatedApplication(context, { ...applicationIds, policyId: invalidId })).rejects.toThrow(expected); }); it('should throw an error when policyContact does not exist', async () => { const invalidId = applicationIds.id; - try { - await getPopulatedApplication(context, { ...applicationIds, policyContactId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('policyContact', applicationIds.id)); - expect(err).toEqual(expected); - } + const expected = new Error(generateErrorMessage('policyContact', applicationIds.id)); + + await expect(getPopulatedApplication(context, { ...applicationIds, policyContactId: invalidId })).rejects.toThrow(expected); }); it('should throw an error when companyAddress does not exist', async () => { @@ -129,12 +123,9 @@ describe('api/helpers/get-populated-application - error handling', () => { it('should throw an error when company does not exist', async () => { const invalidId = applicationIds.id; - try { - await getPopulatedApplication(context, { ...applicationIds, companyId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('company', applicationIds.id)); - expect(err).toEqual(expected); - } + const expected = new Error(generateErrorMessage('company', applicationIds.id)); + + await expect(getPopulatedApplication(context, { ...applicationIds, companyId: invalidId })).rejects.toThrow(expected); }); it('should throw an error when companySicCode does not exist', async () => { @@ -149,23 +140,17 @@ describe('api/helpers/get-populated-application - error handling', () => { it('should throw an error when business does not exist', async () => { const invalidId = applicationIds.id; - try { - await getPopulatedApplication(context, { ...applicationIds, businessId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('business', applicationIds.id)); - expect(err).toEqual(expected); - } + const expected = new Error(generateErrorMessage('business', applicationIds.id)); + + await expect(getPopulatedApplication(context, { ...applicationIds, businessId: invalidId })).rejects.toThrow(expected); }); it('should throw an error when broker does not exist', async () => { const invalidId = applicationIds.id; - try { - await getPopulatedApplication(context, { ...applicationIds, brokerId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('broker', applicationIds.id)); - expect(err).toEqual(expected); - } + const expected = new Error(generateErrorMessage('broker', applicationIds.id)); + + await expect(getPopulatedApplication(context, { ...applicationIds, brokerId: invalidId })).rejects.toThrow(expected); }); it('should throw an error when buyer does not exist', async () => { @@ -215,12 +200,9 @@ describe('api/helpers/get-populated-application - error handling', () => { it('should throw an error when declaration does not exist', async () => { const invalidId = applicationIds.id; - try { - await getPopulatedApplication(context, { ...applicationIds, declarationId: invalidId }); - } catch (err) { - const expected = new Error(generateErrorMessage('declaration', applicationIds.id)); - expect(err).toEqual(expected); - } + const expected = new Error(generateErrorMessage('declaration', applicationIds.id)); + + await expect(getPopulatedApplication(context, { ...applicationIds, declarationId: invalidId })).rejects.toThrow(expected); }); it('should throw an error when sectionReview does not exist', async () => {