diff --git a/CHANGELOG.md b/CHANGELOG.md index ab9c1e13a8..5272fe7dea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,9 @@ ## [2.30.0](https://github.com/UK-Export-Finance/exip/compare/v2.29.0...v2.30.0) (2024-08-02) - ### Features -* **EMS-3665:** export contract - how was contract awarded - data saving ([#2883](https://github.com/UK-Export-Finance/exip/issues/2883)) ([d91a5d9](https://github.com/UK-Export-Finance/exip/commit/d91a5d9b186209cc07311b6ed0eb53c3f8464287)) +- **EMS-3665:** export contract - how was contract awarded - data saving ([#2883](https://github.com/UK-Export-Finance/exip/issues/2883)) ([d91a5d9](https://github.com/UK-Export-Finance/exip/commit/d91a5d9b186209cc07311b6ed0eb53c3f8464287)) ## [2.29.0](https://github.com/UK-Export-Finance/exip/compare/v2.28.2...v2.29.0) (2024-08-01) diff --git a/e2e-tests/commands/insurance/complete-export-contract-section.js b/e2e-tests/commands/insurance/complete-export-contract-section.js index 88523cda10..81c8bcac7d 100644 --- a/e2e-tests/commands/insurance/complete-export-contract-section.js +++ b/e2e-tests/commands/insurance/complete-export-contract-section.js @@ -7,6 +7,7 @@ * @param {Boolean} agentChargeMethodPercentage: Agent charge method is "percentage" * @param {Boolean} alternativeCurrency: Should submit an "alternative currency". Defaults to false. * @param {Boolean} attemptedPrivateMarketCover: Has attempted to insure through the private market + * @param {Boolean} contractAwardedOtherMethod: "How was the contract awarded" method as "other" * @param {Boolean} finalDestinationKnown: "Final destination known" * @param {Boolean} isUsingAgent: Exporter is using an agent * @param {Boolean} submitCheckYourAnswers: Click export contract "check your answers" submit button @@ -20,6 +21,7 @@ const completeExportContractSection = ({ agentChargeMethodPercentage = false, alternativeCurrency = false, attemptedPrivateMarketCover = false, + contractAwardedOtherMethod = false, finalDestinationKnown, isUsingAgent = false, submitCheckYourAnswers = false, @@ -28,7 +30,7 @@ const completeExportContractSection = ({ }) => { cy.startInsuranceExportContractSection({ viaTaskList }); - cy.completeAndSubmitHowWasTheContractAwardedForm({}); + cy.completeAndSubmitHowWasTheContractAwardedForm({ otherMethod: contractAwardedOtherMethod }); cy.completeAndSubmitAboutGoodsOrServicesForm({ finalDestinationKnown }); cy.completeAndSubmitHowYouWillGetPaidForm({}); 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 4b4dcf1dd3..4e12eed423 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 @@ -17,6 +17,7 @@ const { POLICY_TYPE } = APPLICATION; * @param {Boolean} attemptedPrivateMarketCover: Should submit "yes" to "attempted to insure through the private market" 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} contractAwardedOtherMethod: "How was the contract awarded" method as "other" * @param {Boolean} differentPolicyContact: Should submit an application with a different policy contact to the owner. * @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. @@ -49,6 +50,7 @@ const completePrepareApplicationMultiplePolicyType = ({ attemptedPrivateMarketCover = false, buyerOutstandingPayments = false, buyerFailedToPayOnTime = false, + contractAwardedOtherMethod = false, differentPolicyContact = false, differentTradingName = false, differentTradingAddress = false, @@ -110,6 +112,7 @@ const completePrepareApplicationMultiplePolicyType = ({ agentChargeMethodPercentage, alternativeCurrency: alternativeCurrencyExportContract, attemptedPrivateMarketCover, + contractAwardedOtherMethod, finalDestinationKnown, isUsingAgent, 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 f305d29c81..b8f857aac8 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 @@ -17,6 +17,7 @@ const { POLICY_TYPE } = FIELD_VALUES; * @param {Boolean} attemptedPrivateMarketCover: Should submit "yes" to "attempted to insure through the private market" 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} contractAwardedOtherMethod: "How was the contract awarded" method as "other" * @param {Boolean} differentPolicyContact: Should submit an application with a different policy contact to the owner. * @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. @@ -38,36 +39,37 @@ const { POLICY_TYPE } = FIELD_VALUES; * @param {Boolean} usingBroker: Should submit "yes" or "no" to "using a broker". */ const completePrepareApplicationSinglePolicyType = ({ + agentChargeMethodFixedSum = false, + agentChargeFixedSumAmount, + agentChargeMethodPercentage = false, + agentIsCharging = false, alternativeCurrencyBuyer = false, alternativeCurrencyExportContract = false, alternativeCurrencyTurnover = false, alternativeCurrencyPolicy = false, + attemptedPrivateMarketCover = false, + buyerOutstandingPayments = false, + buyerFailedToPayOnTime = false, + contractAwardedOtherMethod = false, + differentPolicyContact = false, differentTradingName = false, differentTradingAddress = false, - hasCreditControlProcess = false, - hasConnectionToBuyer = false, + exporterHasBuyerFinancialAccounts = false, exporterHasTradedWithBuyer = false, - buyerOutstandingPayments = false, - buyerFailedToPayOnTime = false, + finalDestinationKnown = false, fullyPopulatedBuyerTradingHistory = false, + hasCreditControlProcess = false, + hasConnectionToBuyer = false, hasHadCreditInsuranceCoverWithBuyer = false, - exporterHasBuyerFinancialAccounts = false, - finalDestinationKnown = false, - usingBroker = false, - otherCompanyInvolved = false, isAppointingLossPayee = false, + isUsingAgent = false, lossPayeeIsLocatedInUK = false, - policyValueOverMvpMaximum = false, - differentPolicyContact = false, needPreCreditPeriod = false, + otherCompanyInvolved = false, + policyValueOverMvpMaximum = false, totalContractValueOverThreshold = false, - attemptedPrivateMarketCover = false, - isUsingAgent = false, - agentIsCharging = false, - agentChargeMethodFixedSum = false, - agentChargeFixedSumAmount, - agentChargeMethodPercentage = false, submitCheckYourAnswers = true, + usingBroker = false, }) => { cy.completeBusinessSection({ differentTradingName, @@ -110,6 +112,7 @@ const completePrepareApplicationSinglePolicyType = ({ agentChargeMethodPercentage, alternativeCurrency: alternativeCurrencyExportContract, attemptedPrivateMarketCover, + contractAwardedOtherMethod, finalDestinationKnown, isUsingAgent, 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 1372182e4a..a980c709a5 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 @@ -19,6 +19,7 @@ import completeSignInAndGoToApplication from './account/complete-sign-in-and-go- * @param {Boolean} buyerOutstandingPayments: Exporter has outstanding payments with the buyer. * @param {Boolean} buyerFailedToPayOnTime: Buyer has failed to pay the exporter on the time. * @param {String} companyNumber: Company number/Companies house number + * @param {Boolean} contractAwardedOtherMethod: "How was the contract awarded" method as "other" * @param {Boolean} createApplicationViaApi: Flag whether to create the application via API instead of going through the eligibility journey. * @param {Boolean} differentPolicyContact: Should submit an application with a different policy contact to the owner. * @param {Boolean} differentTradingName: Should submit "yes" to "have a different trading name" in the "company details" form. @@ -54,6 +55,7 @@ const completeSignInAndSubmitAnApplication = ({ buyerFailedToPayOnTime = false, createApplicationViaApi, companyNumber, + contractAwardedOtherMethod = false, differentPolicyContact = false, differentTradingName = false, differentTradingAddress = false, @@ -92,6 +94,7 @@ const completeSignInAndSubmitAnApplication = ({ alternativeCurrencyPolicy, buyerOutstandingPayments, buyerFailedToPayOnTime, + contractAwardedOtherMethod, differentPolicyContact, differentTradingName, differentTradingAddress, @@ -123,6 +126,7 @@ const completeSignInAndSubmitAnApplication = ({ attemptedPrivateMarketCover, buyerFailedToPayOnTime, buyerOutstandingPayments, + contractAwardedOtherMethod, differentPolicyContact, differentTradingName, differentTradingAddress, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-contract-awarded-other-method.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-contract-awarded-other-method.spec.js new file mode 100644 index 0000000000..03c4aa3c4f --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-contract-awarded-other-method.spec.js @@ -0,0 +1,30 @@ +import { APPLICATION } from '../../../../../../../constants'; + +context('Insurance - submit an application - Multiple policy type, contract awarded with `other` method', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + contractAwardedOtherMethod: true, + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + }).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); + }); + + it('should render in a `submitted` state in the dashboard', () => { + cy.assertDashboardApplicationSubmitted(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-export-contract-fully-populated.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-export-contract-fully-populated.spec.js index b16178ce94..2034a6924f 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-export-contract-fully-populated.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/export-contract-conditions/submit-an-application-multiple-policy-type-export-contract-fully-populated.spec.js @@ -8,6 +8,7 @@ context('Insurance - submit an application - Multiple policy type, fully populat agentIsCharging: true, agentChargeMethodFixedSum: true, attemptedPrivateMarketCover: true, + contractAwardedOtherMethod: true, isUsingAgent: true, finalDestinationKnown: true, policyType: APPLICATION.POLICY_TYPE.MULTIPLE, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-fully-populated.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-fully-populated.spec.js index 10043cd726..ce51d9f3ac 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-fully-populated.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/submit-an-application-multiple-policy-type-fully-populated.spec.js @@ -23,6 +23,7 @@ context( lossPayeeIsLocatedInUK: true, totalContractValueOverThreshold: true, attemptedPrivateMarketCover: true, + contractAwardedOtherMethod: true, isUsingAgent: true, agentIsCharging: true, agentChargeMethodFixedSum: true, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-contract-awarded-other-method.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-contract-awarded-other-method.spec.js new file mode 100644 index 0000000000..95b9bb57cb --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-contract-awarded-other-method.spec.js @@ -0,0 +1,25 @@ +context('Insurance - submit an application - Single policy type, contract awarded with `other` method', () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ contractAwardedOtherMethod: 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); + }); + + it('should render in a `submitted` state in the dashboard', () => { + cy.assertDashboardApplicationSubmitted(referenceNumber); + }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-export-contract-fully-populated.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-export-contract-fully-populated.spec.js index 236cdba5e4..06ad76bced 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-export-contract-fully-populated.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-export-contract-fully-populated.spec.js @@ -6,6 +6,7 @@ context('Insurance - submit an application - Single policy type, fully populated agentIsCharging: true, agentChargeMethodFixedSum: true, attemptedPrivateMarketCover: true, + contractAwardedOtherMethod: true, isUsingAgent: true, finalDestinationKnown: true, totalContractValueOverThreshold: true, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-using-an-agent-alternative-currency.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-alternative-currency.spec.js index bcfd13346f..a75fb55b72 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/export-contract-conditions/submit-an-application-single-policy-type-using-an-agent-alternative-currency.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-alternative-currency.spec.js @@ -1,4 +1,4 @@ -context('Insurance - submit an application - Single policy type, using an agent, fixed sum method, alternative currency', () => { +context('Insurance - submit an application - Single policy type, using an agent, fixed sum method, alternative currency', () => { let referenceNumber; before(() => { diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-fully-populated.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-fully-populated.spec.js index 6aab92b261..c228c8de6a 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-fully-populated.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/submit-an-application-single-policy-type-fully-populated.spec.js @@ -20,6 +20,7 @@ context( lossPayeeIsLocatedInUK: true, totalContractValueOverThreshold: true, attemptedPrivateMarketCover: true, + contractAwardedOtherMethod: true, isUsingAgent: true, agentIsCharging: true, agentChargeMethodFixedSum: true, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/about-goods-or-services/save-and-back.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/about-goods-or-services/save-and-back.spec.js index c3d3340d3d..b4ba252c3a 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/about-goods-or-services/save-and-back.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/about-goods-or-services/save-and-back.spec.js @@ -53,8 +53,8 @@ context('Insurance - Export contract - About goods or services page - Save and g cy.assertAllSectionsUrl(referenceNumber); }); - it('should retain the `export contract` task status as `not started`', () => { - cy.checkTaskExportContractStatusIsNotStartedYet(); + it('should retain the `export contract` task status as `in progress`', () => { + cy.checkTaskExportContractStatusIsInProgress(); }); }); @@ -71,7 +71,7 @@ context('Insurance - Export contract - About goods or services page - Save and g cy.assertAllSectionsUrl(referenceNumber); }); - it('should update the `export contract` task status to `in progress`', () => { + it('should retain the `export contract` task status as `in progress`', () => { cy.checkTaskExportContractStatusIsInProgress(); }); @@ -112,8 +112,8 @@ context('Insurance - Export contract - About goods or services page - Save and g cy.assertAllSectionsUrl(referenceNumber); }); - it('should update the `export contract` task status to `not started`', () => { - cy.checkTaskExportContractStatusIsNotStartedYet(); + it('should retain the `export contract` task status as `in progress`', () => { + cy.checkTaskExportContractStatusIsInProgress(); }); it(`should have no value in '${FIELD_ID}' when going back to the page`, () => { diff --git a/src/ui/server/controllers/insurance/all-sections/index.test.ts b/src/ui/server/controllers/insurance/all-sections/index.test.ts index 02d8b423fc..edf17148fb 100644 --- a/src/ui/server/controllers/insurance/all-sections/index.test.ts +++ b/src/ui/server/controllers/insurance/all-sections/index.test.ts @@ -60,6 +60,7 @@ describe('controllers/insurance/all-sections', () => { const { buyerTradingHistory, relationship } = buyer; const { exporterIsConnectedWithBuyer, exporterHasPreviousCreditInsuranceWithBuyer } = relationship; const { outstandingPayments, exporterHasTradedWithBuyer } = buyerTradingHistory; + const { awardMethod } = exportContract; const flatApplicationData = flattenApplicationData(mockApplication); @@ -83,6 +84,7 @@ describe('controllers/insurance/all-sections', () => { isUsingAgent, agentIsCharging, agentChargeMethod, + awardMethod?.id, ); const expectedTaskListData = generateTaskList(taskListStructure, flatApplicationData); diff --git a/src/ui/server/controllers/insurance/all-sections/index.ts b/src/ui/server/controllers/insurance/all-sections/index.ts index b34f8ad31e..15af878e66 100644 --- a/src/ui/server/controllers/insurance/all-sections/index.ts +++ b/src/ui/server/controllers/insurance/all-sections/index.ts @@ -53,6 +53,7 @@ export const get = (req: Request, res: Response) => { const { buyerTradingHistory, relationship } = buyer; const { exporterIsConnectedWithBuyer, exporterHasPreviousCreditInsuranceWithBuyer } = relationship; const { outstandingPayments, exporterHasTradedWithBuyer } = buyerTradingHistory; + const { awardMethod } = exportContract; const flatApplicationData = flattenApplicationData(application); @@ -76,6 +77,7 @@ export const get = (req: Request, res: Response) => { isUsingAgent, agentIsCharging, agentChargeMethod, + awardMethod?.id, ); const taskListData = generateTaskList(taskListStructure, flatApplicationData); diff --git a/src/ui/server/controllers/insurance/check-your-answers/export-contract/index.test.ts b/src/ui/server/controllers/insurance/check-your-answers/export-contract/index.test.ts index 1bb950f933..cea20c4d53 100644 --- a/src/ui/server/controllers/insurance/check-your-answers/export-contract/index.test.ts +++ b/src/ui/server/controllers/insurance/check-your-answers/export-contract/index.test.ts @@ -32,6 +32,7 @@ const { charge: { method: agentChargeMethod }, }, }, + awardMethod, } = exportContract; describe('controllers/insurance/check-your-answers/export-contract', () => { @@ -102,6 +103,7 @@ describe('controllers/insurance/check-your-answers/export-contract', () => { isUsingAgent, agentIsCharging, agentChargeMethod, + awardMethodId: awardMethod?.id, }); const status = sectionStatus(exportContractFields, mockApplication); diff --git a/src/ui/server/controllers/insurance/check-your-answers/export-contract/index.ts b/src/ui/server/controllers/insurance/check-your-answers/export-contract/index.ts index e0295d4406..d72eb91868 100644 --- a/src/ui/server/controllers/insurance/check-your-answers/export-contract/index.ts +++ b/src/ui/server/controllers/insurance/check-your-answers/export-contract/index.ts @@ -60,6 +60,7 @@ export const get = async (req: Request, res: Response) => { charge: { method: agentChargeMethod }, }, }, + awardMethod, } = exportContract; const checkAndChange = true; @@ -75,6 +76,7 @@ export const get = async (req: Request, res: Response) => { isUsingAgent, agentIsCharging, agentChargeMethod, + awardMethodId: awardMethod?.id, }); const status = sectionStatus(exportContractFields, application); diff --git a/src/ui/server/graphql/queries/application-by-reference-number.ts b/src/ui/server/graphql/queries/application-by-reference-number.ts index 8182661ffb..5788462ce9 100644 --- a/src/ui/server/graphql/queries/application-by-reference-number.ts +++ b/src/ui/server/graphql/queries/application-by-reference-number.ts @@ -94,6 +94,11 @@ const applicationByReferenceNumberQuery = gql` } exportContract { id + awardMethod { + id + value + } + otherAwardMethod goodsOrServicesDescription finalDestinationKnown finalDestinationCountryCode diff --git a/src/ui/server/helpers/can-access-submit-your-application-routes/index.ts b/src/ui/server/helpers/can-access-submit-your-application-routes/index.ts index f2236fa15e..0302eff9aa 100644 --- a/src/ui/server/helpers/can-access-submit-your-application-routes/index.ts +++ b/src/ui/server/helpers/can-access-submit-your-application-routes/index.ts @@ -9,7 +9,6 @@ import { Application } from '../../../types'; * Check if an application has submitted previous fields/sections required before accessing the "submit your application" group/sections/routes. * The "submit your application" group includes all routes for "check your answers" and "declarations". * @param {Application} - * @param {String} Current URL * @returns {Boolean} */ const canAccessSubmitYourApplicationRoutes = (application: Application) => { diff --git a/src/ui/server/helpers/flatten-application-data/index.test.ts b/src/ui/server/helpers/flatten-application-data/index.test.ts index 64c6aa7475..49c42b1524 100644 --- a/src/ui/server/helpers/flatten-application-data/index.test.ts +++ b/src/ui/server/helpers/flatten-application-data/index.test.ts @@ -164,6 +164,7 @@ describe('server/helpers/flatten-application-data', () => { ...contact, ...getTrueAndFalseAnswers(declaration), ...exportContract, + ...exportContract.awardMethod, ...getTrueAndFalseAnswers(exportContract), ...exportContract.privateMarket, ...getTrueAndFalseAnswers(exportContract.privateMarket), diff --git a/src/ui/server/helpers/flatten-application-data/index.ts b/src/ui/server/helpers/flatten-application-data/index.ts index 4067848c91..de439a7946 100644 --- a/src/ui/server/helpers/flatten-application-data/index.ts +++ b/src/ui/server/helpers/flatten-application-data/index.ts @@ -137,6 +137,7 @@ const flattenApplicationData = (application: Application): ApplicationFlat => { ...company, ...contact, ...exportContract, + ...exportContract.awardMethod, ...getTrueAndFalseAnswers(exportContract), ...exportContract.privateMarket, ...getTrueAndFalseAnswers(exportContract.privateMarket), diff --git a/src/ui/server/helpers/required-fields/export-contract/index.test.ts b/src/ui/server/helpers/required-fields/export-contract/index.test.ts index 099c92c0a6..b32053e29d 100644 --- a/src/ui/server/helpers/required-fields/export-contract/index.test.ts +++ b/src/ui/server/helpers/required-fields/export-contract/index.test.ts @@ -1,5 +1,5 @@ -import requiredFields, { getAboutGoodsOrServicesTasks, privateCoverTasks, agentServiceChargeTasks, agentTasks } from '.'; -import { FIELD_VALUES } from '../../../constants'; +import requiredFields, { getAboutGoodsOrServicesTasks, privateCoverTasks, agentServiceChargeTasks, agentTasks, awardMethodTasks } from '.'; +import { EXPORT_CONTRACT_AWARD_METHOD, FIELD_VALUES } from '../../../constants'; import FIELD_IDS from '../../../constants/field-ids/insurance/export-contract'; import { mockApplication } from '../../../test-mocks'; @@ -8,6 +8,7 @@ const { } = FIELD_VALUES; const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD, OTHER_AWARD_METHOD }, ABOUT_GOODS_OR_SERVICES, HOW_WILL_YOU_GET_PAID: { PAYMENT_TERMS_DESCRIPTION }, PRIVATE_MARKET: { ATTEMPTED, DECLINED_DESCRIPTION }, @@ -23,6 +24,7 @@ describe('server/helpers/required-fields/export-contract', () => { finalDestinationKnown, privateMarket: { attempted: attemptedPrivateMarketCover }, agent: { isUsingAgent }, + awardMethod: { id: awardMethodId }, }, totalContractValueOverThreshold, } = mockApplication; @@ -167,6 +169,28 @@ describe('server/helpers/required-fields/export-contract', () => { }); }); + describe('awardMethodTasks', () => { + describe(`when awardMethod is ${EXPORT_CONTRACT_AWARD_METHOD.OTHER.DB_ID}`, () => { + it('should return an array with required field IDs', () => { + const result = awardMethodTasks(EXPORT_CONTRACT_AWARD_METHOD.OTHER.DB_ID); + + const expected = [AWARD_METHOD, OTHER_AWARD_METHOD]; + + expect(result).toEqual(expected); + }); + }); + + describe(`when awardMethod is NOT ${EXPORT_CONTRACT_AWARD_METHOD.OTHER.DB_ID}`, () => { + it(`should return an array with ${AWARD_METHOD} field ID`, () => { + const result = awardMethodTasks(EXPORT_CONTRACT_AWARD_METHOD.COMPETITIVE_BIDDING.DB_ID); + + const expected = [AWARD_METHOD]; + + expect(result).toEqual(expected); + }); + }); + }); + describe('requiredFields', () => { it('should return array of required fields', () => { const result = requiredFields({ totalContractValueOverThreshold, finalDestinationKnown, attemptedPrivateMarketCover, isUsingAgent }); @@ -176,6 +200,7 @@ describe('server/helpers/required-fields/export-contract', () => { ...getAboutGoodsOrServicesTasks(finalDestinationKnown), ...privateCoverTasks({ totalContractValueOverThreshold, attemptedPrivateMarketCover }), ...agentTasks({ isUsingAgent }), + ...awardMethodTasks(awardMethodId), ]; expect(result).toEqual(expected); diff --git a/src/ui/server/helpers/required-fields/export-contract/index.ts b/src/ui/server/helpers/required-fields/export-contract/index.ts index 84aafa5d11..fdd76726ce 100644 --- a/src/ui/server/helpers/required-fields/export-contract/index.ts +++ b/src/ui/server/helpers/required-fields/export-contract/index.ts @@ -1,4 +1,4 @@ -import { FIELD_VALUES } from '../../../constants'; +import { EXPORT_CONTRACT_AWARD_METHOD, FIELD_VALUES } from '../../../constants'; import FIELD_IDS from '../../../constants/field-ids/insurance/export-contract'; const { @@ -6,6 +6,7 @@ const { } = FIELD_VALUES; const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD, OTHER_AWARD_METHOD }, ABOUT_GOODS_OR_SERVICES, HOW_WILL_YOU_GET_PAID: { PAYMENT_TERMS_DESCRIPTION }, PRIVATE_MARKET: { ATTEMPTED, DECLINED_DESCRIPTION }, @@ -35,6 +36,7 @@ interface RequiredFields { isUsingAgent?: boolean; agentIsCharging?: boolean; agentChargeMethod?: string; + awardMethodId?: string; } /** @@ -103,6 +105,19 @@ export const agentTasks = ({ isUsingAgent, agentIsCharging, agentChargeMethod }: return [USING_AGENT]; }; +/** + * awardMethodTasks + * @param {String} awardMethodId: Export contract award method ID + * @returns {Array} Array of tasks + */ +export const awardMethodTasks = (awardMethodId?: string): Array => { + if (awardMethodId === EXPORT_CONTRACT_AWARD_METHOD.OTHER.DB_ID) { + return [AWARD_METHOD, OTHER_AWARD_METHOD]; + } + + return [AWARD_METHOD]; +}; + /** * Required fields for the insurance - export contract section * * @param {Boolean} totalContractValueOverThreshold: If total contract value in eligibility should be over threshold. @@ -111,6 +126,7 @@ export const agentTasks = ({ isUsingAgent, agentIsCharging, agentChargeMethod }: * @param {Boolean} isUsingAgent: "Is using an agent to help win the export contract" flag * @param {Boolean} agentIsCharging: "Is the agent charging for their support in the export contract?" flag * @param {Boolean} agentChargeMethod: Agent charge method + * @param {String} awardMethodId: Export contract award method ID * @returns {Array} Required field IDs */ const requiredFields = ({ @@ -120,11 +136,13 @@ const requiredFields = ({ isUsingAgent, agentIsCharging, agentChargeMethod, + awardMethodId, }: RequiredFields): Array => [ PAYMENT_TERMS_DESCRIPTION, ...getAboutGoodsOrServicesTasks(finalDestinationKnown), ...privateCoverTasks({ totalContractValueOverThreshold, attemptedPrivateMarketCover }), ...agentTasks({ isUsingAgent, agentIsCharging, agentChargeMethod }), + ...awardMethodTasks(awardMethodId), ]; export default requiredFields; diff --git a/src/ui/server/helpers/required-fields/prepare-application/index.test.ts b/src/ui/server/helpers/required-fields/prepare-application/index.test.ts index dc456b885d..b58d3d2d43 100644 --- a/src/ui/server/helpers/required-fields/prepare-application/index.test.ts +++ b/src/ui/server/helpers/required-fields/prepare-application/index.test.ts @@ -10,6 +10,7 @@ import { mockApplication } from '../../../test-mocks'; const { EXPORT_CONTRACT: { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, ABOUT_GOODS_OR_SERVICES: { FINAL_DESTINATION_KNOWN }, PRIVATE_MARKET: { ATTEMPTED }, USING_AGENT, @@ -42,6 +43,7 @@ describe('server/helpers/required-fields/section-review', () => { totalContractValueOverThreshold, attemptedPrivateMarketCover: flatApplicationData[ATTEMPTED], isUsingAgent: flatApplicationData[USING_AGENT], + awardMethodId: flatApplicationData[AWARD_METHOD]?.id, }), ...requiredBusinessFields(flatApplicationData[HAS_DIFFERENT_TRADING_NAME]), ...requiredYourBuyerFields({ diff --git a/src/ui/server/helpers/required-fields/prepare-application/index.ts b/src/ui/server/helpers/required-fields/prepare-application/index.ts index 8e638a9bbb..3baf4593b3 100644 --- a/src/ui/server/helpers/required-fields/prepare-application/index.ts +++ b/src/ui/server/helpers/required-fields/prepare-application/index.ts @@ -8,6 +8,7 @@ import { ApplicationFlat } from '../../../../types'; const { EXPORT_CONTRACT: { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, ABOUT_GOODS_OR_SERVICES: { FINAL_DESTINATION_KNOWN }, PRIVATE_MARKET: { ATTEMPTED }, USING_AGENT, @@ -37,6 +38,7 @@ const requiredFields = (application: ApplicationFlat): Array => [ totalContractValueOverThreshold: application.totalContractValueOverThreshold, attemptedPrivateMarketCover: application[ATTEMPTED], isUsingAgent: application[USING_AGENT], + awardMethodId: application[AWARD_METHOD]?.id, }), ...requiredBusinessFields(application[HAS_DIFFERENT_TRADING_NAME]), ...requiredYourBuyerFields({ diff --git a/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.test.ts b/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.test.ts index 873422acfd..a14886e9b3 100644 --- a/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.test.ts +++ b/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.test.ts @@ -27,6 +27,7 @@ describe('server/helpers/task-list/generate-groups-and-tasks', () => { charge: { method: agentChargeMethod }, }, }, + awardMethod: { id: awardMethodId }, }, nominatedLossPayee: { isAppointed: isAppointingLossPayee, @@ -56,6 +57,10 @@ describe('server/helpers/task-list/generate-groups-and-tasks', () => { exporterHasPreviousCreditInsuranceWithBuyer, totalContractValueOverThreshold, attemptedPrivateMarketCover, + isUsingAgent, + agentIsCharging, + agentChargeMethod, + awardMethodId, ); const initialChecks = { @@ -87,6 +92,7 @@ describe('server/helpers/task-list/generate-groups-and-tasks', () => { isUsingAgent, agentIsCharging, agentChargeMethod, + awardMethodId, }), }; diff --git a/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.ts b/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.ts index b526eabff6..d98f18a406 100644 --- a/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.ts +++ b/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.ts @@ -27,7 +27,8 @@ const { INITIAL_CHECKS, PREPARE_APPLICATION, SUBMIT_APPLICATION } = TASKS.LIST; * @param {Boolean} attemptedPrivateMarketCover: "Attempted cover via the private market" flag * @param {Boolean} isUsingAgent: "Is using an agent to help win the export contract" flag * @param {Boolean} agentIsCharging: "Is the agent charging for their support in the export contract?" flag - * @param {Boolean} agentChargeMethod: Agent charge method + * @param {String} agentChargeMethod: Agent charge method + * @param {String} awardMethodId: Export contract award method ID * @returns {Array} Task list groups and tasks */ const generateGroupsAndTasks = ( @@ -50,6 +51,7 @@ const generateGroupsAndTasks = ( isUsingAgent?: boolean, agentIsCharging?: boolean, agentChargeMethod?: string, + awardMethodId?: string, ): TaskListData => { let groups = [ { @@ -85,6 +87,7 @@ const generateGroupsAndTasks = ( isUsingAgent, agentIsCharging, agentChargeMethod, + awardMethodId, }), }, ] as TaskListData; diff --git a/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.test.ts b/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.test.ts index d70b0aa97a..049cb45b95 100644 --- a/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.test.ts +++ b/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.test.ts @@ -39,6 +39,7 @@ describe('server/helpers/task-list/prepare-application', () => { charge: { method: agentChargeMethod }, }, }, + awardMethod: { id: awardMethodId }, }, nominatedLossPayee: { isAppointed: isAppointingLossPayee, @@ -79,6 +80,10 @@ describe('server/helpers/task-list/prepare-application', () => { hasPreviousCreditInsuranceWithBuyer: exporterHasPreviousCreditInsuranceWithBuyer, totalContractValueOverThreshold, attemptedPrivateMarketCover, + isUsingAgent, + agentIsCharging, + agentChargeMethod, + awardMethodId, }); const expectedDependencies = getAllTasksFieldsInAGroup(otherGroups[0]); @@ -131,6 +136,7 @@ describe('server/helpers/task-list/prepare-application', () => { isUsingAgent, agentIsCharging, agentChargeMethod, + awardMethodId, }), dependencies: expectedDependencies, }; diff --git a/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.ts b/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.ts index 6d49b73172..617db042ed 100644 --- a/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.ts +++ b/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.ts @@ -30,7 +30,8 @@ const { PREPARE_APPLICATION } = TASKS.LIST; * @param {Boolean} attemptedPrivateMarketCover: "Attempted cover via the private market" flag * @param {Boolean} isUsingAgent: "Is using an agent to help win the export contract" flag * @param {Boolean} agentIsCharging: "Is the agent charging for their support in the export contract?" flag - * @param {Boolean} agentChargeMethod: Agent charge method + * @param {String} agentChargeMethod: Agent charge method + * @param {String} awardMethodId: Export contract award method ID * @returns {Array} Prepare application tasks */ const createPrepareApplicationTasks = ({ @@ -53,6 +54,7 @@ const createPrepareApplicationTasks = ({ isUsingAgent, agentIsCharging, agentChargeMethod, + awardMethodId, }: CreatePrepareApplicationTasksParams): Array => { const initialChecksGroup = getGroupById(otherGroups, GROUP_IDS.INITIAL_CHECKS); @@ -108,6 +110,7 @@ const createPrepareApplicationTasks = ({ isUsingAgent, agentIsCharging, agentChargeMethod, + awardMethodId, }), dependencies, }; diff --git a/src/ui/server/middleware/insurance/application-status/index.ts b/src/ui/server/middleware/insurance/application-status/index.ts index 1be847f076..ae1f1ea330 100644 --- a/src/ui/server/middleware/insurance/application-status/index.ts +++ b/src/ui/server/middleware/insurance/application-status/index.ts @@ -53,6 +53,8 @@ export const applicationStatusMiddleware = async (req: Request, res: Response, n * do not allow the user to view/access these routes and redirect to COMPLETE_OTHER_SECTIONS. */ if (isSubmitYourApplicationRoute(url, referenceNumber) && !canAccessSubmitYourApplicationRoutes(application)) { + console.info(`'Submit application' route and incomplete section detected - redirecting to ${COMPLETE_OTHER_SECTIONS}`); + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${COMPLETE_OTHER_SECTIONS}`); } } diff --git a/src/ui/types/application.ts b/src/ui/types/application.ts index 55cf30de2a..2067ad7d97 100644 --- a/src/ui/types/application.ts +++ b/src/ui/types/application.ts @@ -72,6 +72,7 @@ interface ApplicationExportContract { finalDestinationKnown?: boolean; finalDestinationCountryCode?: string; goodsOrServicesDescription?: string; + otherAwardMethod?: string; paymentTermsDescription?: string; privateMarket: ApplicationPrivateMarket; } diff --git a/src/ui/types/task-list.ts b/src/ui/types/task-list.ts index 90be0f9c61..f972974b75 100644 --- a/src/ui/types/task-list.ts +++ b/src/ui/types/task-list.ts @@ -50,6 +50,7 @@ interface CreatePrepareApplicationTasksParams { isUsingAgent?: boolean; agentIsCharging?: boolean; agentChargeMethod?: string; + awardMethodId?: string; } export { CreatePrepareApplicationTasksParams, TaskListData, TaskListDataTask, TaskListDataGroup, TaskListGroup, TaskListTask, TaskList };