diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index edbdad2121..554495e2f7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -229,6 +229,7 @@ jobs: 'check-your-answers/export-contract/change-your-answers/about-goods-or-services/*.spec.js', 'check-your-answers/export-contract/change-your-answers/agent/*.spec.js', 'check-your-answers/export-contract/change-your-answers/agent-charges/*.spec.js', + 'check-your-answers/export-contract/change-your-answers/how-the-contract-was-awarded/*.spec.js', 'check-your-answers/export-contract/change-your-answers/agent-service/*.spec.js', 'check-your-answers/export-contract/change-your-answers/how-will-you-get-paid/*.spec.js', 'check-your-answers/export-contract/change-your-answers/private-market/*.spec.js', @@ -285,6 +286,7 @@ jobs: 'export-contract/change-your-answers/agent/*.spec.js', 'export-contract/change-your-answers/agent-charges/*.spec.js', 'export-contract/change-your-answers/agent-service/*.spec.js', + 'export-contract/change-your-answers/how-the-contract-was-awarded/*.spec.js', 'export-contract/change-your-answers/how-will-you-get-paid/*.spec.js', 'export-contract/change-your-answers/private-market/*.spec.js', 'export-contract/check-your-answers/**/*.spec.js', diff --git a/CHANGELOG.md b/CHANGELOG.md index 94ab511c77..04e1d12217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,17 +2,15 @@ ## [2.32.0](https://github.com/UK-Export-Finance/exip/compare/v2.31.0...v2.32.0) (2024-08-05) - ### Features -* **EMS-3662:** export contract - how was contract awarded - save and back ([#2892](https://github.com/UK-Export-Finance/exip/issues/2892)) ([8003b9d](https://github.com/UK-Export-Finance/exip/commit/8003b9d66fda8fb75d26877c9fccb9e9c3e753c1)) +- **EMS-3662:** export contract - how was contract awarded - save and back ([#2892](https://github.com/UK-Export-Finance/exip/issues/2892)) ([8003b9d](https://github.com/UK-Export-Finance/exip/commit/8003b9d66fda8fb75d26877c9fccb9e9c3e753c1)) ## [2.31.0](https://github.com/UK-Export-Finance/exip/compare/v2.30.0...v2.31.0) (2024-08-05) - ### Features -* **EMS-3685:** added xlsx for 2 new eligibility fields ([#2884](https://github.com/UK-Export-Finance/exip/issues/2884)) ([3878733](https://github.com/UK-Export-Finance/exip/commit/3878733d3235e38fc20e02e5f0b8d43492990974)) +- **EMS-3685:** added xlsx for 2 new eligibility fields ([#2884](https://github.com/UK-Export-Finance/exip/issues/2884)) ([3878733](https://github.com/UK-Export-Finance/exip/commit/3878733d3235e38fc20e02e5f0b8d43492990974)) ## [2.30.0](https://github.com/UK-Export-Finance/exip/compare/v2.29.0...v2.30.0) (2024-08-02) diff --git a/e2e-tests/commands/insurance/check-export-contract-summary-list.js b/e2e-tests/commands/insurance/check-export-contract-summary-list.js index 25c06b55f9..39cbc2c576 100644 --- a/e2e-tests/commands/insurance/check-export-contract-summary-list.js +++ b/e2e-tests/commands/insurance/check-export-contract-summary-list.js @@ -8,6 +8,7 @@ import application from '../../fixtures/application'; import COUNTRIES from '../../fixtures/countries'; const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, ABOUT_GOODS_OR_SERVICES: { DESCRIPTION, FINAL_DESTINATION }, HOW_WILL_YOU_GET_PAID: { PAYMENT_TERMS_DESCRIPTION }, PRIVATE_MARKET: { ATTEMPTED, DECLINED_DESCRIPTION }, @@ -17,11 +18,20 @@ const { AGENT_CHARGES: { FIXED_SUM_AMOUNT, FIXED_SUM_CURRENCY_CODE, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE }, } = FIELD_IDS; +const { OPEN_TENDER } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS; + /** * checkExportContractSummaryList * "export contract" summary list assertions. */ const checkExportContractSummaryList = { + [AWARD_METHOD]: ({ expectedValue = OPEN_TENDER.TEXT }) => { + const fieldId = AWARD_METHOD; + + const { expectedKey, expectedChangeLinkText } = getSummaryListField(fieldId, FIELDS.HOW_WAS_THE_CONTRACT_AWARDED); + + cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue, expectedChangeLinkText); + }, [DESCRIPTION]: () => { const fieldId = DESCRIPTION; diff --git a/e2e-tests/commands/insurance/complete-export-contract-section.js b/e2e-tests/commands/insurance/complete-export-contract-section.js index 81c8bcac7d..d32aeb07ac 100644 --- a/e2e-tests/commands/insurance/complete-export-contract-section.js +++ b/e2e-tests/commands/insurance/complete-export-contract-section.js @@ -7,7 +7,11 @@ * @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} contractAwardedCompetitiveBidding: "How was the contract awarded" method as COMPETITIVE_BIDDING + * @param {Boolean} contractAwardedDirectAward: "How was the contract awarded" method as DIRECT_AWARD + * @param {Boolean} contractAwardedNegotiatedContract: "How was the contract awarded" method as NEGOTIATED_CONTRACT + * @param {Boolean} contractAwardedOpenTender: "How was the contract awarded" method as OPEN_TENDER + * @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 @@ -21,6 +25,10 @@ const completeExportContractSection = ({ agentChargeMethodPercentage = false, alternativeCurrency = false, attemptedPrivateMarketCover = false, + contractAwardedCompetitiveBidding = false, + contractAwardedDirectAward = false, + contractAwardedNegotiatedContract = false, + contractAwardedOpenTender = true, contractAwardedOtherMethod = false, finalDestinationKnown, isUsingAgent = false, @@ -30,7 +38,13 @@ const completeExportContractSection = ({ }) => { cy.startInsuranceExportContractSection({ viaTaskList }); - cy.completeAndSubmitHowWasTheContractAwardedForm({ otherMethod: contractAwardedOtherMethod }); + cy.completeAndSubmitHowWasTheContractAwardedForm({ + openTender: contractAwardedOpenTender, + negotiatedContract: contractAwardedNegotiatedContract, + directAward: contractAwardedDirectAward, + competitiveBidding: contractAwardedCompetitiveBidding, + 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 4e12eed423..defcc32ca6 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,7 +17,11 @@ 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} contractAwardedCompetitiveBidding: "How was the contract awarded" method as COMPETITIVE_BIDDING + * @param {Boolean} contractAwardedDirectAward: "How was the contract awarded" method as DIRECT_AWARD + * @param {Boolean} contractAwardedNegotiatedContract: "How was the contract awarded" method as NEGOTIATED_CONTRACT + * @param {Boolean} contractAwardedOpenTender: "How was the contract awarded" method as OPEN_TENDER + * @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. @@ -50,6 +54,10 @@ const completePrepareApplicationMultiplePolicyType = ({ attemptedPrivateMarketCover = false, buyerOutstandingPayments = false, buyerFailedToPayOnTime = false, + contractAwardedCompetitiveBidding = false, + contractAwardedDirectAward = false, + contractAwardedNegotiatedContract = false, + contractAwardedOpenTender = true, contractAwardedOtherMethod = false, differentPolicyContact = false, differentTradingName = false, @@ -112,6 +120,10 @@ const completePrepareApplicationMultiplePolicyType = ({ agentChargeMethodPercentage, alternativeCurrency: alternativeCurrencyExportContract, attemptedPrivateMarketCover, + contractAwardedCompetitiveBidding, + contractAwardedDirectAward, + contractAwardedNegotiatedContract, + contractAwardedOpenTender, contractAwardedOtherMethod, finalDestinationKnown, isUsingAgent, 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 b8f857aac8..48b187c7e2 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,7 +17,11 @@ 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} contractAwardedCompetitiveBidding: "How was the contract awarded" method as COMPETITIVE_BIDDING + * @param {Boolean} contractAwardedDirectAward: "How was the contract awarded" method as DIRECT_AWARD + * @param {Boolean} contractAwardedNegotiatedContract: "How was the contract awarded" method as NEGOTIATED_CONTRACT + * @param {Boolean} contractAwardedOpenTender: "How was the contract awarded" method as OPEN_TENDER + * @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. @@ -50,6 +54,10 @@ const completePrepareApplicationSinglePolicyType = ({ attemptedPrivateMarketCover = false, buyerOutstandingPayments = false, buyerFailedToPayOnTime = false, + contractAwardedCompetitiveBidding = false, + contractAwardedDirectAward = false, + contractAwardedNegotiatedContract = false, + contractAwardedOpenTender = true, contractAwardedOtherMethod = false, differentPolicyContact = false, differentTradingName = false, @@ -112,6 +120,10 @@ const completePrepareApplicationSinglePolicyType = ({ agentChargeMethodPercentage, alternativeCurrency: alternativeCurrencyExportContract, attemptedPrivateMarketCover, + contractAwardedOpenTender, + contractAwardedCompetitiveBidding, + contractAwardedDirectAward, + contractAwardedNegotiatedContract, contractAwardedOtherMethod, finalDestinationKnown, isUsingAgent, diff --git a/e2e-tests/content-strings/fields/insurance/export-contract/index.js b/e2e-tests/content-strings/fields/insurance/export-contract/index.js index 399ff7c72b..0d49c42273 100644 --- a/e2e-tests/content-strings/fields/insurance/export-contract/index.js +++ b/e2e-tests/content-strings/fields/insurance/export-contract/index.js @@ -51,6 +51,10 @@ export const EXPORT_CONTRACT_FIELDS = { TEXT: OTHER.VALUE, }, }, + SUMMARY: { + TITLE: 'How was the contract awarded', + FORM_TITLE: EXPORT_CONTRACT_FORM_TITLES.ABOUT_THE_EXPORT, + }, }, [OTHER_AWARD_METHOD]: { MAXIMUM: MAXIMUM_CHARACTERS.EXPORT_CONTRACT.OTHER_AWARD_METHOD, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js new file mode 100644 index 0000000000..9e735c477c --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js @@ -0,0 +1,79 @@ +import { summaryList, radios, field } from '../../../../../../../../pages/shared'; +import partials from '../../../../../../../../partials'; +import FIELD_IDS from '../../../../../../../../constants/field-ids/insurance/export-contract'; +import { INSURANCE_ROUTES } from '../../../../../../../../constants/routes/insurance'; +import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../../../../content-strings/fields/insurance/export-contract'; + +const { + ROOT, + CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT }, +} = INSURANCE_ROUTES; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD: FIELD_ID, OTHER_AWARD_METHOD }, +} = FIELD_IDS; + +const { DIRECT_AWARD, OTHER } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[FIELD_ID].OPTIONS; + +const baseUrl = Cypress.config('baseUrl'); + +const { taskList } = partials.insurancePartials; + +const task = taskList.submitApplication.tasks.checkAnswers; + +context( + `Insurance - Export contract - Change your answers - How the contract was awarded - Changing from ${OTHER.TEXT} to ${DIRECT_AWARD.TEXT} and back to ${OTHER.TEXT}`, + () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completePrepareApplicationSinglePolicyType({ + referenceNumber, + contractAwardedOtherMethod: true, + }); + + task.link().click(); + + // To get past previous "Check your answers" pages + cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 }); + + url = `${baseUrl}${ROOT}/${referenceNumber}${EXPORT_CONTRACT}`; + + cy.assertUrl(url); + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe(FIELD_ID, () => { + describe(`after changing the answer from ${OTHER.TEXT} to ${DIRECT_AWARD.TEXT} and back to ${OTHER.TEXT}`, () => { + beforeEach(() => { + cy.navigateToUrl(url); + + // select DIRECT_AWARD + summaryList.field(FIELD_ID).changeLink().click(); + cy.completeAndSubmitHowWasTheContractAwardedForm({ directAward: true }); + + // select OTHER + summaryList.field(FIELD_ID).changeLink().click(); + const selector = radios(OTHER.ID).option; + selector.label().click(); + }); + + it(`should have no value for ${OTHER_AWARD_METHOD} text input`, () => { + cy.checkValue(field(OTHER_AWARD_METHOD), ''); + }); + }); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded.spec.js new file mode 100644 index 0000000000..a3a2b1ce95 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded.spec.js @@ -0,0 +1,144 @@ +import { summaryList } from '../../../../../../../../pages/shared'; +import partials from '../../../../../../../../partials'; +import FIELD_IDS from '../../../../../../../../constants/field-ids/insurance/export-contract'; +import { INSURANCE_ROUTES } from '../../../../../../../../constants/routes/insurance'; +import checkSummaryList from '../../../../../../../../commands/insurance/check-export-contract-summary-list'; +import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../../../../content-strings/fields/insurance/export-contract'; +import application from '../../../../../../../../fixtures/application'; + +const { + ROOT, + CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT }, + EXPORT_CONTRACT: { HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE }, +} = INSURANCE_ROUTES; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD: FIELD_ID, OTHER_AWARD_METHOD }, +} = FIELD_IDS; + +const { DIRECT_AWARD, NEGOTIATED_CONTRACT, COMPETITIVE_BIDDING, OPEN_TENDER, OTHER } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[FIELD_ID].OPTIONS; + +const baseUrl = Cypress.config('baseUrl'); + +const { taskList } = partials.insurancePartials; + +const task = taskList.submitApplication.tasks.checkAnswers; + +context( + 'Insurance - Change your answers - How the contract was awarded - As an Exporter, I want to be able to review my input regarding how the contract was awarded, So that I can be assured I am providing UKEF with the right information', + () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completePrepareApplicationSinglePolicyType({ + referenceNumber, + }); + + task.link().click(); + + // To get past previous "Check your answers" pages + cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 }); + + url = `${baseUrl}${ROOT}/${referenceNumber}${EXPORT_CONTRACT}`; + + cy.assertUrl(url); + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe(FIELD_ID, () => { + describe('when clicking the `change` link', () => { + it(`should redirect to ${HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE}`, () => { + cy.navigateToUrl(url); + + summaryList.field(FIELD_ID).changeLink().click(); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE, fieldId: FIELD_ID }); + }); + }); + + describe(`after changing the answer from ${OPEN_TENDER.TEXT} to ${NEGOTIATED_CONTRACT.TEXT}`, () => { + beforeEach(() => { + cy.navigateToUrl(url); + }); + + it(`should redirect to ${EXPORT_CONTRACT}`, () => { + summaryList.field(FIELD_ID).changeLink().click(); + + cy.completeAndSubmitHowWasTheContractAwardedForm({ negotiatedContract: true }); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: EXPORT_CONTRACT, fieldId: FIELD_ID }); + }); + + it(`should render new ${FIELD_ID} answer and change link`, () => { + checkSummaryList[FIELD_ID]({ expectedValue: NEGOTIATED_CONTRACT.TEXT }); + }); + }); + + describe(`after changing the answer from ${NEGOTIATED_CONTRACT.TEXT} to ${DIRECT_AWARD.TEXT}`, () => { + beforeEach(() => { + cy.navigateToUrl(url); + }); + + it(`should redirect to ${EXPORT_CONTRACT}`, () => { + summaryList.field(FIELD_ID).changeLink().click(); + + cy.completeAndSubmitHowWasTheContractAwardedForm({ directAward: true }); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: EXPORT_CONTRACT, fieldId: FIELD_ID }); + }); + + it(`should render new ${FIELD_ID} answer and change link, with no other agent service charge fields`, () => { + checkSummaryList[FIELD_ID]({ expectedValue: DIRECT_AWARD.TEXT }); + }); + }); + + describe(`after changing the answer from ${DIRECT_AWARD.TEXT} to ${COMPETITIVE_BIDDING.TEXT}`, () => { + beforeEach(() => { + cy.navigateToUrl(url); + }); + + it(`should redirect to ${EXPORT_CONTRACT}`, () => { + summaryList.field(FIELD_ID).changeLink().click(); + + cy.completeAndSubmitHowWasTheContractAwardedForm({ competitiveBidding: true }); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: EXPORT_CONTRACT, fieldId: FIELD_ID }); + }); + + it(`should render new ${FIELD_ID} answer and change link`, () => { + checkSummaryList[FIELD_ID]({ expectedValue: COMPETITIVE_BIDDING.TEXT }); + }); + }); + + describe(`after changing the answer from ${COMPETITIVE_BIDDING.TEXT} to ${OTHER.TEXT}`, () => { + beforeEach(() => { + cy.navigateToUrl(url); + }); + + it(`should redirect to ${EXPORT_CONTRACT}`, () => { + summaryList.field(FIELD_ID).changeLink().click(); + + cy.completeAndSubmitHowWasTheContractAwardedForm({ otherMethod: true }); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: EXPORT_CONTRACT, fieldId: FIELD_ID }); + }); + + it(`should render new ${FIELD_ID} answer and change link`, () => { + checkSummaryList[FIELD_ID]({ expectedValue: application.EXPORT_CONTRACT[OTHER_AWARD_METHOD] }); + }); + }); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answer-summary-list-contract-awarded-competitive-bidding.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answer-summary-list-contract-awarded-competitive-bidding.spec.js new file mode 100644 index 0000000000..56455a28ba --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answer-summary-list-contract-awarded-competitive-bidding.spec.js @@ -0,0 +1,54 @@ +import partials from '../../../../../../../partials'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; +import { assertMinimalExportContractSummaryListRows } from '../../../../../../../shared-test-assertions'; +import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../../../content-strings/fields/insurance/export-contract'; +import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract'; + +const { + ROOT: INSURANCE_ROOT, + CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT }, +} = INSURANCE_ROUTES; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, +} = FIELD_IDS; + +const { COMPETITIVE_BIDDING } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS; + +const { taskList } = partials.insurancePartials; + +const task = taskList.submitApplication.tasks.checkAnswers; + +const baseUrl = Cypress.config('baseUrl'); + +context(`Insurance - Check your answers - Export contract - Summary list - Contract awarded with ${COMPETITIVE_BIDDING.TEXT}`, () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completePrepareApplicationSinglePolicyType({ referenceNumber, contractAwardedCompetitiveBidding: true }); + + task.link().click(); + + // To get past previous "Check your answers" pages + cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 }); + + url = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${EXPORT_CONTRACT}`; + }); + }); + + beforeEach(() => { + cy.saveSession(); + + cy.navigateToUrl(url); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + assertMinimalExportContractSummaryListRows({ awardMethodValue: COMPETITIVE_BIDDING.TEXT }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answer-summary-list-contract-awarded-direct-award.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answer-summary-list-contract-awarded-direct-award.spec.js new file mode 100644 index 0000000000..1c8eb6afdb --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answer-summary-list-contract-awarded-direct-award.spec.js @@ -0,0 +1,54 @@ +import partials from '../../../../../../../partials'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; +import { assertMinimalExportContractSummaryListRows } from '../../../../../../../shared-test-assertions'; +import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../../../content-strings/fields/insurance/export-contract'; +import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract'; + +const { + ROOT: INSURANCE_ROOT, + CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT }, +} = INSURANCE_ROUTES; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, +} = FIELD_IDS; + +const { DIRECT_AWARD } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS; + +const { taskList } = partials.insurancePartials; + +const task = taskList.submitApplication.tasks.checkAnswers; + +const baseUrl = Cypress.config('baseUrl'); + +context(`Insurance - Check your answers - Export contract - Summary list - Contract awarded with ${DIRECT_AWARD.TEXT}`, () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completePrepareApplicationSinglePolicyType({ referenceNumber, contractAwardedDirectAward: true }); + + task.link().click(); + + // To get past previous "Check your answers" pages + cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 }); + + url = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${EXPORT_CONTRACT}`; + }); + }); + + beforeEach(() => { + cy.saveSession(); + + cy.navigateToUrl(url); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + assertMinimalExportContractSummaryListRows({ awardMethodValue: DIRECT_AWARD.TEXT }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answer-summary-list-contract-awarded-negotiated-contract.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answer-summary-list-contract-awarded-negotiated-contract.spec.js new file mode 100644 index 0000000000..fd77f03fad --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answer-summary-list-contract-awarded-negotiated-contract.spec.js @@ -0,0 +1,54 @@ +import partials from '../../../../../../../partials'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; +import { assertMinimalExportContractSummaryListRows } from '../../../../../../../shared-test-assertions'; +import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../../../content-strings/fields/insurance/export-contract'; +import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract'; + +const { + ROOT: INSURANCE_ROOT, + CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT }, +} = INSURANCE_ROUTES; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, +} = FIELD_IDS; + +const { NEGOTIATED_CONTRACT } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS; + +const { taskList } = partials.insurancePartials; + +const task = taskList.submitApplication.tasks.checkAnswers; + +const baseUrl = Cypress.config('baseUrl'); + +context(`Insurance - Check your answers - Export contract - Summary list - Contract awarded with ${NEGOTIATED_CONTRACT.TEXT}`, () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completePrepareApplicationSinglePolicyType({ referenceNumber, contractAwardedNegotiatedContract: true }); + + task.link().click(); + + // To get past previous "Check your answers" pages + cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 }); + + url = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${EXPORT_CONTRACT}`; + }); + }); + + beforeEach(() => { + cy.saveSession(); + + cy.navigateToUrl(url); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + assertMinimalExportContractSummaryListRows({ awardMethodValue: NEGOTIATED_CONTRACT.TEXT }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-contract-awarded-other-method.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-contract-awarded-other-method.spec.js new file mode 100644 index 0000000000..46c8283c47 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-contract-awarded-other-method.spec.js @@ -0,0 +1,55 @@ +import partials from '../../../../../../../partials'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; +import { assertMinimalExportContractSummaryListRows } from '../../../../../../../shared-test-assertions'; +import application from '../../../../../../../fixtures/application'; +import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract'; +import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../../../content-strings/fields/insurance/export-contract'; + +const { + ROOT: INSURANCE_ROOT, + CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT }, +} = INSURANCE_ROUTES; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { OTHER_AWARD_METHOD, AWARD_METHOD }, +} = FIELD_IDS; + +const { OTHER } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS; + +const { taskList } = partials.insurancePartials; + +const task = taskList.submitApplication.tasks.checkAnswers; + +const baseUrl = Cypress.config('baseUrl'); + +context(`Insurance - Check your answers - Export contract - Summary list - Contract awarded with ${OTHER.TEXT}`, () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completePrepareApplicationSinglePolicyType({ referenceNumber, contractAwardedOtherMethod: true }); + + task.link().click(); + + // To get past previous "Check your answers" pages + cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 }); + + url = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${EXPORT_CONTRACT}`; + }); + }); + + beforeEach(() => { + cy.saveSession(); + + cy.navigateToUrl(url); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + assertMinimalExportContractSummaryListRows({ awardMethodValue: application.EXPORT_CONTRACT[OTHER_AWARD_METHOD] }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-fixed-sum-decimals-multiple-policy.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-fixed-sum-decimals-multiple-policy.spec.js index ca161ca1f2..3e404fcefc 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-fixed-sum-decimals-multiple-policy.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-fixed-sum-decimals-multiple-policy.spec.js @@ -14,7 +14,7 @@ const task = taskList.submitApplication.tasks.checkAnswers; const baseUrl = Cypress.config('baseUrl'); context( - 'Insurance - Change your answers - Export contract - Summary list - total contract value threshold, private insurance attempt, using an agent, agent is charging - fixed sum method with decimal places - multiple policy', + 'Insurance - Check your answers - Export contract - Summary list - total contract value threshold, private insurance attempt, using an agent, agent is charging - fixed sum method with decimal places - multiple policy', () => { let referenceNumber; let url; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-fixed-sum-decimals.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-fixed-sum-decimals.spec.js index 29201a420b..963ea225ae 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-fixed-sum-decimals.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-fixed-sum-decimals.spec.js @@ -14,7 +14,7 @@ const task = taskList.submitApplication.tasks.checkAnswers; const baseUrl = Cypress.config('baseUrl'); context( - 'Insurance - Change your answers - Export contract - Summary list - total contract value threshold, private insurance attempt, using an agent, agent is chraging - fixed sum method with decimal places', + 'Insurance - Check your answers - Export contract - Summary list - total contract value threshold, private insurance attempt, using an agent, agent is chraging - fixed sum method with decimal places', () => { let referenceNumber; let url; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-fixed-sum.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-fixed-sum.spec.js index 6a79d6693a..36bd4a3f86 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-fixed-sum.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-fixed-sum.spec.js @@ -14,7 +14,7 @@ const task = taskList.submitApplication.tasks.checkAnswers; const baseUrl = Cypress.config('baseUrl'); context( - 'Insurance - Change your answers - Export contract - Summary list - total contract value threshold, private insurance attempt, using an agent, agent is chraging - fixed sum method', + 'Insurance - Check your answers - Export contract - Summary list - total contract value threshold, private insurance attempt, using an agent, agent is chraging - fixed sum method', () => { let referenceNumber; let url; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-percentage.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-percentage.spec.js index 7ba0281766..d163671691 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-percentage.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-fully-populated-with-agent-charges-percentage.spec.js @@ -14,7 +14,7 @@ const task = taskList.submitApplication.tasks.checkAnswers; const baseUrl = Cypress.config('baseUrl'); context( - 'Insurance - Change your answers - Export contract - Summary list - total contract value threshold, private insurance attempt, using an agent, agent is chraging - percentage method', + 'Insurance - Check your answers - Export contract - Summary list - total contract value threshold, private insurance attempt, using an agent, agent is chraging - percentage method', () => { let referenceNumber; let url; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-minimal.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-minimal.spec.js index c59245c3c6..c03a06387d 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-minimal.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/summary-list/check-your-answers-summary-list-minimal.spec.js @@ -14,7 +14,7 @@ const task = taskList.submitApplication.tasks.checkAnswers; const baseUrl = Cypress.config('baseUrl'); context( - 'Insurance - Change your answers - Export contract - Summary list - As an exporter, I want to be able to review my input for the export contract again, So that I can do a final review of the information I previously input before submitting my application', + 'Insurance - Check your answers - Export contract - Summary list - As an exporter, I want to be able to review my input for the export contract again, So that I can do a final review of the information I previously input before submitting my application', () => { let referenceNumber; let url; @@ -44,6 +44,6 @@ context( cy.deleteApplication(referenceNumber); }); - assertMinimalExportContractSummaryListRows(); + assertMinimalExportContractSummaryListRows({}); }, ); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js new file mode 100644 index 0000000000..f0df17e720 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded-from-other-method.spec.js @@ -0,0 +1,66 @@ +import { summaryList, radios, field } from '../../../../../../../pages/shared'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; +import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract'; +import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../../../content-strings/fields/insurance/export-contract'; + +const { + ROOT, + EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS }, +} = INSURANCE_ROUTES; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD: FIELD_ID, OTHER_AWARD_METHOD }, +} = FIELD_IDS; + +const { DIRECT_AWARD, OTHER } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[FIELD_ID].OPTIONS; + +const baseUrl = Cypress.config('baseUrl'); + +context( + `Insurance - Export contract - Change your answers - How the contract was awarded - Changing from ${OTHER.TEXT} to ${DIRECT_AWARD.TEXT} and back to ${OTHER.TEXT}`, + () => { + let referenceNumber; + let checkYourAnswersUrl; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completeExportContractSection({ contractAwardedOtherMethod: true }); + + checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; + + cy.assertUrl(checkYourAnswersUrl); + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe(FIELD_ID, () => { + describe(`after changing the answer from ${OTHER.TEXT} to ${DIRECT_AWARD.TEXT} and back to ${OTHER.TEXT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + + // select DIRECT_AWARD + summaryList.field(FIELD_ID).changeLink().click(); + cy.completeAndSubmitHowWasTheContractAwardedForm({ directAward: true }); + + // select OTHER + summaryList.field(FIELD_ID).changeLink().click(); + const selector = radios(OTHER.ID).option; + selector.label().click(); + }); + + it(`should have no value for ${OTHER_AWARD_METHOD} text input`, () => { + cy.checkValue(field(OTHER_AWARD_METHOD), ''); + }); + }); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded.spec.js new file mode 100644 index 0000000000..f66117b628 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/how-the-contract-was-awarded/change-your-answers-how-the-contract-was-awarded.spec.js @@ -0,0 +1,131 @@ +import { summaryList } from '../../../../../../../pages/shared'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; +import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract'; +import checkSummaryList from '../../../../../../../commands/insurance/check-export-contract-summary-list'; +import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../../../content-strings/fields/insurance/export-contract'; +import application from '../../../../../../../fixtures/application'; + +const { + ROOT, + EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS, HOW_WAS_THE_CONTRACT_AWARDED_CHANGE }, +} = INSURANCE_ROUTES; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD: FIELD_ID, OTHER_AWARD_METHOD }, +} = FIELD_IDS; + +const { DIRECT_AWARD, NEGOTIATED_CONTRACT, COMPETITIVE_BIDDING, OPEN_TENDER, OTHER } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[FIELD_ID].OPTIONS; + +const baseUrl = Cypress.config('baseUrl'); + +context( + 'Insurance - Export contract - Change your answers - How the contract was awarded - As an Exporter, I want to be able to review my input regarding how the contract was awarded, So that I can be assured I am providing UKEF with the right information', + () => { + let referenceNumber; + let checkYourAnswersUrl; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completeExportContractSection({}); + + checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; + + cy.assertUrl(checkYourAnswersUrl); + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe(FIELD_ID, () => { + describe('when clicking the `change` link', () => { + it(`should redirect to ${HOW_WAS_THE_CONTRACT_AWARDED_CHANGE}`, () => { + cy.navigateToUrl(checkYourAnswersUrl); + + summaryList.field(FIELD_ID).changeLink().click(); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: HOW_WAS_THE_CONTRACT_AWARDED_CHANGE, fieldId: FIELD_ID }); + }); + }); + + describe(`after changing the answer from ${OPEN_TENDER.TEXT} to ${NEGOTIATED_CONTRACT.TEXT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + }); + + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => { + summaryList.field(FIELD_ID).changeLink().click(); + + cy.completeAndSubmitHowWasTheContractAwardedForm({ negotiatedContract: true }); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS, fieldId: FIELD_ID }); + }); + + it(`should render new ${FIELD_ID} answer and change link`, () => { + checkSummaryList[FIELD_ID]({ expectedValue: NEGOTIATED_CONTRACT.TEXT }); + }); + }); + + describe(`after changing the answer from ${NEGOTIATED_CONTRACT.TEXT} to ${DIRECT_AWARD.TEXT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + }); + + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => { + summaryList.field(FIELD_ID).changeLink().click(); + + cy.completeAndSubmitHowWasTheContractAwardedForm({ directAward: true }); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS, fieldId: FIELD_ID }); + }); + + it(`should render new ${FIELD_ID} answer and change link`, () => { + checkSummaryList[FIELD_ID]({ expectedValue: DIRECT_AWARD.TEXT }); + }); + }); + + describe(`after changing the answer from ${DIRECT_AWARD.TEXT} to ${COMPETITIVE_BIDDING.TEXT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + }); + + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => { + summaryList.field(FIELD_ID).changeLink().click(); + + cy.completeAndSubmitHowWasTheContractAwardedForm({ competitiveBidding: true }); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS, fieldId: FIELD_ID }); + }); + + it(`should render new ${FIELD_ID} answer and change link`, () => { + checkSummaryList[FIELD_ID]({ expectedValue: COMPETITIVE_BIDDING.TEXT }); + }); + }); + + describe(`after changing the answer from ${COMPETITIVE_BIDDING.TEXT} to ${OTHER.TEXT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + }); + + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => { + summaryList.field(FIELD_ID).changeLink().click(); + + cy.completeAndSubmitHowWasTheContractAwardedForm({ otherMethod: true }); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS, fieldId: FIELD_ID }); + }); + + it(`should render new ${FIELD_ID} answer and change link`, () => { + checkSummaryList[FIELD_ID]({ expectedValue: application.EXPORT_CONTRACT[OTHER_AWARD_METHOD] }); + }); + }); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answer-summary-list-contract-awarded-competitive-bidding.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answer-summary-list-contract-awarded-competitive-bidding.spec.js new file mode 100644 index 0000000000..2230f81c28 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answer-summary-list-contract-awarded-competitive-bidding.spec.js @@ -0,0 +1,41 @@ +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; +import { assertMinimalExportContractSummaryListRows } from '../../../../../../../shared-test-assertions'; +import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../../../content-strings/fields/insurance/export-contract'; +import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract'; + +const { ROOT, EXPORT_CONTRACT } = INSURANCE_ROUTES; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, +} = FIELD_IDS; + +const { COMPETITIVE_BIDDING } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS; + +const baseUrl = Cypress.config('baseUrl'); + +context(`Insurance - Export contract - Check your answers - Summary list - contract awarded with ${COMPETITIVE_BIDDING.TEXT}`, () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completeExportContractSection({ contractAwardedCompetitiveBidding: true }); + + url = `${baseUrl}${ROOT}/${referenceNumber}${EXPORT_CONTRACT.CHECK_YOUR_ANSWERS}`; + }); + }); + + beforeEach(() => { + cy.saveSession(); + + cy.navigateToUrl(url); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + assertMinimalExportContractSummaryListRows({ awardMethodValue: COMPETITIVE_BIDDING.TEXT }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answer-summary-list-contract-awarded-direct-award.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answer-summary-list-contract-awarded-direct-award.spec.js new file mode 100644 index 0000000000..726fbe1892 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answer-summary-list-contract-awarded-direct-award.spec.js @@ -0,0 +1,41 @@ +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; +import { assertMinimalExportContractSummaryListRows } from '../../../../../../../shared-test-assertions'; +import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../../../content-strings/fields/insurance/export-contract'; +import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract'; + +const { ROOT, EXPORT_CONTRACT } = INSURANCE_ROUTES; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, +} = FIELD_IDS; + +const { DIRECT_AWARD } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS; + +const baseUrl = Cypress.config('baseUrl'); + +context(`Insurance - Export contract - Check your answers - Summary list - contract awarded with ${DIRECT_AWARD.TEXT}`, () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completeExportContractSection({ contractAwardedDirectAward: true }); + + url = `${baseUrl}${ROOT}/${referenceNumber}${EXPORT_CONTRACT.CHECK_YOUR_ANSWERS}`; + }); + }); + + beforeEach(() => { + cy.saveSession(); + + cy.navigateToUrl(url); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + assertMinimalExportContractSummaryListRows({ awardMethodValue: DIRECT_AWARD.TEXT }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answer-summary-list-contract-awarded-negotiated-contract.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answer-summary-list-contract-awarded-negotiated-contract.spec.js new file mode 100644 index 0000000000..4ff2da5cc0 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answer-summary-list-contract-awarded-negotiated-contract.spec.js @@ -0,0 +1,41 @@ +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; +import { assertMinimalExportContractSummaryListRows } from '../../../../../../../shared-test-assertions'; +import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../../../../../content-strings/fields/insurance/export-contract'; +import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract'; + +const { ROOT, EXPORT_CONTRACT } = INSURANCE_ROUTES; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, +} = FIELD_IDS; + +const { NEGOTIATED_CONTRACT } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS; + +const baseUrl = Cypress.config('baseUrl'); + +context(`Insurance - Export contract - Check your answers - Summary list - contract awarded with ${NEGOTIATED_CONTRACT.TEXT}`, () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completeExportContractSection({ contractAwardedNegotiatedContract: true }); + + url = `${baseUrl}${ROOT}/${referenceNumber}${EXPORT_CONTRACT.CHECK_YOUR_ANSWERS}`; + }); + }); + + beforeEach(() => { + cy.saveSession(); + + cy.navigateToUrl(url); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + assertMinimalExportContractSummaryListRows({ awardMethodValue: NEGOTIATED_CONTRACT.TEXT }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answers-summary-list-contract-awarded-other-method.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answers-summary-list-contract-awarded-other-method.spec.js new file mode 100644 index 0000000000..d4c74ba894 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answers-summary-list-contract-awarded-other-method.spec.js @@ -0,0 +1,39 @@ +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; +import { assertMinimalExportContractSummaryListRows } from '../../../../../../../shared-test-assertions'; +import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract'; +import application from '../../../../../../../fixtures/application'; + +const { ROOT, EXPORT_CONTRACT } = INSURANCE_ROUTES; + +const { + HOW_WAS_THE_CONTRACT_AWARDED: { OTHER_AWARD_METHOD }, +} = FIELD_IDS; + +const baseUrl = Cypress.config('baseUrl'); + +context(`Insurance - Export contract - Check your answers - Summary list - contract awarded with ${OTHER_AWARD_METHOD}`, () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completeExportContractSection({ contractAwardedOtherMethod: true }); + + url = `${baseUrl}${ROOT}/${referenceNumber}${EXPORT_CONTRACT.CHECK_YOUR_ANSWERS}`; + }); + }); + + beforeEach(() => { + cy.saveSession(); + + cy.navigateToUrl(url); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + assertMinimalExportContractSummaryListRows({ awardMethodValue: application.EXPORT_CONTRACT[OTHER_AWARD_METHOD] }); +}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answers-summary-list-minimal.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answers-summary-list-minimal.spec.js index b3ff0de80f..02fab877c1 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answers-summary-list-minimal.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/check-your-answers/check-your-answers-summary-list/check-your-answers-summary-list-minimal.spec.js @@ -31,6 +31,6 @@ context( cy.deleteApplication(referenceNumber); }); - assertMinimalExportContractSummaryListRows(); + assertMinimalExportContractSummaryListRows({}); }, ); diff --git a/e2e-tests/shared-test-assertions/summary-lists/export-contract/fully-populated.js b/e2e-tests/shared-test-assertions/summary-lists/export-contract/fully-populated.js index a54ac66f7a..d9e129831d 100644 --- a/e2e-tests/shared-test-assertions/summary-lists/export-contract/fully-populated.js +++ b/e2e-tests/shared-test-assertions/summary-lists/export-contract/fully-populated.js @@ -21,7 +21,7 @@ const { * @param {Boolean} agentChargeMethodPercentage: Agent charge method is "percentage" */ const assertFullyPopulatedExportContractSummaryListRows = ({ agentChargeMethodFixedSum, agentChargeMethodPercentage, agentChargeFixedSumAmount }) => { - assertGenericExportContractSummaryListRows(); + assertGenericExportContractSummaryListRows({}); it(`should render a ${DESCRIPTION} summary list row`, () => { checkSummaryList[DESCRIPTION](); diff --git a/e2e-tests/shared-test-assertions/summary-lists/export-contract/generic.js b/e2e-tests/shared-test-assertions/summary-lists/export-contract/generic.js index 654a40ad94..fb425284cb 100644 --- a/e2e-tests/shared-test-assertions/summary-lists/export-contract/generic.js +++ b/e2e-tests/shared-test-assertions/summary-lists/export-contract/generic.js @@ -2,6 +2,7 @@ import FIELD_IDS from '../../../constants/field-ids/insurance/export-contract'; import checkSummaryList from '../../../commands/insurance/check-export-contract-summary-list'; const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, ABOUT_GOODS_OR_SERVICES: { DESCRIPTION }, HOW_WILL_YOU_GET_PAID: { PAYMENT_TERMS_DESCRIPTION }, } = FIELD_IDS; @@ -11,7 +12,11 @@ const { * Assert generic "export contract" summary list rows. * These rows should always be present in any "export contract" scenario */ -const assertGenericExportContractSummaryListRows = () => { +const assertGenericExportContractSummaryListRows = ({ awardMethodValue }) => { + it(`should render an ${AWARD_METHOD} summary list row`, () => { + checkSummaryList[AWARD_METHOD]({ expectedValue: awardMethodValue }); + }); + it(`should render a ${DESCRIPTION} summary list row`, () => { checkSummaryList[DESCRIPTION](); }); diff --git a/e2e-tests/shared-test-assertions/summary-lists/export-contract/minimal.js b/e2e-tests/shared-test-assertions/summary-lists/export-contract/minimal.js index 95bd277f15..5af0dd55f1 100644 --- a/e2e-tests/shared-test-assertions/summary-lists/export-contract/minimal.js +++ b/e2e-tests/shared-test-assertions/summary-lists/export-contract/minimal.js @@ -1,8 +1,10 @@ import assertGenericExportContractSummaryListRows from './generic'; import FIELD_IDS from '../../../constants/field-ids/insurance/export-contract'; import checkSummaryList from '../../../commands/insurance/check-export-contract-summary-list'; +import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../../content-strings/fields/insurance/export-contract'; const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, ABOUT_GOODS_OR_SERVICES: { DESCRIPTION, FINAL_DESTINATION }, HOW_WILL_YOU_GET_PAID: { PAYMENT_TERMS_DESCRIPTION }, PRIVATE_MARKET: { ATTEMPTED, DECLINED_DESCRIPTION }, @@ -12,13 +14,15 @@ const { AGENT_CHARGES: { FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE }, } = FIELD_IDS; +const { OPEN_TENDER } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS; + /** * assertMinimalExportContractSummaryListRows * Assert minimal "export contract" summary list rows. * These rows should either not render or have an answer of "no". */ -const assertMinimalExportContractSummaryListRows = () => { - assertGenericExportContractSummaryListRows(); +const assertMinimalExportContractSummaryListRows = ({ awardMethodValue = OPEN_TENDER.TEXT }) => { + assertGenericExportContractSummaryListRows({ awardMethodValue }); it(`should render a ${DESCRIPTION} summary list row`, () => { checkSummaryList[DESCRIPTION](); diff --git a/src/ui/server/content-strings/fields/insurance/export-contract/index.ts b/src/ui/server/content-strings/fields/insurance/export-contract/index.ts index e774ef314d..ac29b7bed9 100644 --- a/src/ui/server/content-strings/fields/insurance/export-contract/index.ts +++ b/src/ui/server/content-strings/fields/insurance/export-contract/index.ts @@ -51,6 +51,10 @@ export const EXPORT_CONTRACT_FIELDS = { TEXT: OTHER.VALUE, }, }, + SUMMARY: { + TITLE: 'How was the contract awarded', + FORM_TITLE: EXPORT_CONTRACT_FORM_TITLES.ABOUT_THE_EXPORT, + }, }, }, ABOUT_GOODS_OR_SERVICES: { diff --git a/src/ui/server/controllers/insurance/export-contract/how-was-the-contract-awarded/index.test.ts b/src/ui/server/controllers/insurance/export-contract/how-was-the-contract-awarded/index.test.ts index 3f14b73342..b982379f0f 100644 --- a/src/ui/server/controllers/insurance/export-contract/how-was-the-contract-awarded/index.test.ts +++ b/src/ui/server/controllers/insurance/export-contract/how-was-the-contract-awarded/index.test.ts @@ -16,7 +16,14 @@ import { mockReq, mockRes, mockExportContract, referenceNumber } from '../../../ const { INSURANCE_ROOT, - EXPORT_CONTRACT: { ABOUT_GOODS_OR_SERVICES, HOW_WAS_THE_CONTRACT_AWARDED_SAVE_AND_BACK: SAVE_AND_BACK }, + EXPORT_CONTRACT: { + ABOUT_GOODS_OR_SERVICES, + CHECK_YOUR_ANSWERS, + HOW_WAS_THE_CONTRACT_AWARDED_CHANGE, + HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE, + HOW_WAS_THE_CONTRACT_AWARDED_SAVE_AND_BACK: SAVE_AND_BACK, + }, + CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT: CHECK_AND_CHANGE_ROUTE }, PROBLEM_WITH_SERVICE, } = INSURANCE_ROUTES; @@ -180,6 +187,30 @@ describe('controllers/insurance/export-contract/how-was-the-contract-awarded', ( expect(res.redirect).toHaveBeenCalledWith(expected); }); + + describe("when the url's last substring is `change`", () => { + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, async () => { + req.originalUrl = HOW_WAS_THE_CONTRACT_AWARDED_CHANGE; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; + + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); + + describe("when the url's last substring is `check-and-change`", () => { + it(`should redirect to ${CHECK_AND_CHANGE_ROUTE}`, async () => { + req.originalUrl = HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${CHECK_AND_CHANGE_ROUTE}`; + + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); }); describe('when there is no application', () => { diff --git a/src/ui/server/controllers/insurance/export-contract/how-was-the-contract-awarded/index.ts b/src/ui/server/controllers/insurance/export-contract/how-was-the-contract-awarded/index.ts index aa6828d9c5..e40bcbc380 100644 --- a/src/ui/server/controllers/insurance/export-contract/how-was-the-contract-awarded/index.ts +++ b/src/ui/server/controllers/insurance/export-contract/how-was-the-contract-awarded/index.ts @@ -10,11 +10,15 @@ import constructPayload from '../../../../helpers/construct-payload'; import generateValidationErrors from './validation'; import { sanitiseData } from '../../../../helpers/sanitise-data'; import mapAndSave from '../map-and-save/export-contract'; +import isChangeRoute from '../../../../helpers/is-change-route'; +import isCheckAndChangeRoute from '../../../../helpers/is-check-and-change-route'; import { ObjectType, Request, Response } from '../../../../../types'; const { INSURANCE_ROOT, - EXPORT_CONTRACT: { ABOUT_GOODS_OR_SERVICES, HOW_WAS_THE_CONTRACT_AWARDED_SAVE_AND_BACK: SAVE_AND_BACK }, + EXPORT_CONTRACT: { ABOUT_GOODS_OR_SERVICES, CHECK_YOUR_ANSWERS, HOW_WAS_THE_CONTRACT_AWARDED_SAVE_AND_BACK: SAVE_AND_BACK }, + CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT: CHECK_AND_CHANGE_ROUTE }, + PROBLEM_WITH_SERVICE, } = INSURANCE_ROUTES; @@ -140,6 +144,22 @@ export const post = async (req: Request, res: Response) => { return res.redirect(PROBLEM_WITH_SERVICE); } + /** + * If the URL is a "change" route, + * redirect to CHECK_YOUR_ANSWERS. + */ + if (isChangeRoute(req.originalUrl)) { + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`); + } + + /** + * If the URL is a "check and change" route, + * redirect to CHECK_AND_CHANGE_ROUTE. + */ + if (isCheckAndChangeRoute(req.originalUrl)) { + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${CHECK_AND_CHANGE_ROUTE}`); + } + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${ABOUT_GOODS_OR_SERVICES}`); } catch (err) { console.error('Error updating application - export contract - how was the contract awarded %O', err); diff --git a/src/ui/server/controllers/insurance/export-contract/map-submitted-data/export-contract/index.test.ts b/src/ui/server/controllers/insurance/export-contract/map-submitted-data/export-contract/index.test.ts index f7ff3d04be..5cc5feec6a 100644 --- a/src/ui/server/controllers/insurance/export-contract/map-submitted-data/export-contract/index.test.ts +++ b/src/ui/server/controllers/insurance/export-contract/map-submitted-data/export-contract/index.test.ts @@ -1,17 +1,20 @@ import mapSubmittedData from '.'; import FIELD_IDS from '../../../../../constants/field-ids/insurance/export-contract'; import getCountryByIsoCode from '../../../../../helpers/get-country-by-iso-code'; +import { EXPORT_CONTRACT_AWARD_METHOD } from '../../../../../constants'; import { mockCountries, mockExportContract } from '../../../../../test-mocks'; import { RequestBody } from '../../../../../../types'; const { - HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD, OTHER_AWARD_METHOD }, ABOUT_GOODS_OR_SERVICES: { DESCRIPTION, FINAL_DESTINATION_KNOWN, FINAL_DESTINATION }, } = FIELD_IDS; const mockCountryIsoCode = mockCountries[0].isoCode; const mockAwardMethodId = mockExportContract.awardMethod.id; +const { DB_ID: OTHER_DB_ID } = EXPORT_CONTRACT_AWARD_METHOD.OTHER; + describe('controllers/insurance/export-contract/map-submitted-data/export-contract', () => { let mockFormBody: RequestBody; @@ -94,4 +97,52 @@ describe('controllers/insurance/export-contract/map-submitted-data/export-contra expect(result).toEqual(expected); }); }); + + describe(`when ${AWARD_METHOD} is not equal to ${OTHER_DB_ID}`, () => { + it(`should return the form body with an empty ${OTHER_AWARD_METHOD}`, () => { + const mockBody = { + ...mockFormBody, + [AWARD_METHOD]: mockAwardMethodId, + [OTHER_AWARD_METHOD]: 'test', + }; + + const result = mapSubmittedData(mockBody, mockCountries); + + const expected = { + ...mockFormBody, + [AWARD_METHOD]: { + connect: { + id: mockAwardMethodId, + }, + }, + [OTHER_AWARD_METHOD]: '', + }; + + expect(result).toEqual(expected); + }); + }); + + describe(`when ${AWARD_METHOD} is equal to ${OTHER_DB_ID}`, () => { + it(`should return the form body with ${OTHER_AWARD_METHOD} populated`, () => { + const mockBody = { + ...mockFormBody, + [AWARD_METHOD]: OTHER_DB_ID, + [OTHER_AWARD_METHOD]: mockExportContract.otherAwardMethod, + }; + + const result = mapSubmittedData(mockBody, mockCountries); + + const expected = { + ...mockFormBody, + [AWARD_METHOD]: { + connect: { + id: OTHER_DB_ID, + }, + }, + [OTHER_AWARD_METHOD]: mockBody[OTHER_AWARD_METHOD], + }; + + expect(result).toEqual(expected); + }); + }); }); diff --git a/src/ui/server/controllers/insurance/export-contract/map-submitted-data/export-contract/index.ts b/src/ui/server/controllers/insurance/export-contract/map-submitted-data/export-contract/index.ts index a941567d9c..ef09cf2160 100644 --- a/src/ui/server/controllers/insurance/export-contract/map-submitted-data/export-contract/index.ts +++ b/src/ui/server/controllers/insurance/export-contract/map-submitted-data/export-contract/index.ts @@ -2,13 +2,16 @@ import FIELD_IDS from '../../../../../constants/field-ids/insurance/export-contr import getCountryByIsoCode from '../../../../../helpers/get-country-by-iso-code'; import { objectHasProperty } from '../../../../../helpers/object'; import { isEmptyString } from '../../../../../helpers/string'; +import { EXPORT_CONTRACT_AWARD_METHOD } from '../../../../../constants'; import { Country, RequestBody } from '../../../../../../types'; const { - HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD }, + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD, OTHER_AWARD_METHOD }, ABOUT_GOODS_OR_SERVICES: { FINAL_DESTINATION, FINAL_DESTINATION_KNOWN }, } = FIELD_IDS; +const { DB_ID: OTHER_DB_ID } = EXPORT_CONTRACT_AWARD_METHOD.OTHER; + /** * mapSubmittedData * Map "export contract" related data for the following forms: @@ -60,6 +63,14 @@ const mapSubmittedData = (formBody: RequestBody, countries?: Array): ob populatedData[FINAL_DESTINATION] = ''; } + /** + * if AWARD_METHOD is not OTHER_AWARD_METHOD's database id and OTHER_AWARD_METHOD is populated, + * then set data for OTHER_AWARD_METHOD to an empty string. + */ + if (formBody[AWARD_METHOD]?.connect?.id !== OTHER_DB_ID && objectHasProperty(populatedData, OTHER_AWARD_METHOD)) { + populatedData[OTHER_AWARD_METHOD] = ''; + } + return populatedData; }; diff --git a/src/ui/server/helpers/summary-lists/export-contract/about-the-export-fields/index.test.ts b/src/ui/server/helpers/summary-lists/export-contract/about-the-export-fields/index.test.ts index fca408b6da..7b0ac52a8f 100644 --- a/src/ui/server/helpers/summary-lists/export-contract/about-the-export-fields/index.test.ts +++ b/src/ui/server/helpers/summary-lists/export-contract/about-the-export-fields/index.test.ts @@ -11,6 +11,7 @@ import replaceNewLineWithLineBreak from '../../../replace-new-line-with-line-bre import { mockApplication, mockCountries, referenceNumber } from '../../../../test-mocks'; const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD, OTHER_AWARD_METHOD }, ABOUT_GOODS_OR_SERVICES: { DESCRIPTION, FINAL_DESTINATION }, HOW_WILL_YOU_GET_PAID: { PAYMENT_TERMS_DESCRIPTION }, } = FIELD_IDS; @@ -19,6 +20,7 @@ const { EXPORT_CONTRACT: { ABOUT_THE_EXPORT: FORM_TITLE }, } = FORM_TITLES; +const { HOW_WAS_THE_CONTRACT_AWARDED_CHANGE, HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE } = EXPORT_CONTRACT_ROUTES; const { ABOUT_GOODS_OR_SERVICES_CHANGE, ABOUT_GOODS_OR_SERVICES_CHECK_AND_CHANGE } = EXPORT_CONTRACT_ROUTES; const { HOW_WILL_YOU_GET_PAID_CHANGE, HOW_WILL_YOU_GET_PAID_CHECK_AND_CHANGE } = EXPORT_CONTRACT_ROUTES; @@ -32,6 +34,21 @@ describe('server/helpers/summary-lists/export-contract/about-goods-or-services-f const expected = { title: FORM_TITLE, fields: [ + fieldGroupItem( + { + field: getFieldById(FIELDS.HOW_WAS_THE_CONTRACT_AWARDED, AWARD_METHOD), + data: mockAnswers, + href: generateChangeLink( + HOW_WAS_THE_CONTRACT_AWARDED_CHANGE, + HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE, + `#${AWARD_METHOD}-label`, + referenceNumber, + checkAndChange, + ), + renderChangeLink: true, + }, + mockAnswers[OTHER_AWARD_METHOD] ? mockAnswers[OTHER_AWARD_METHOD] : mockAnswers[AWARD_METHOD].value, + ), fieldGroupItem({ field: getFieldById(FIELDS.ABOUT_GOODS_OR_SERVICES, DESCRIPTION), data: mockAnswers, diff --git a/src/ui/server/helpers/summary-lists/export-contract/about-the-export-fields/index.ts b/src/ui/server/helpers/summary-lists/export-contract/about-the-export-fields/index.ts index 276360355e..221a7d7047 100644 --- a/src/ui/server/helpers/summary-lists/export-contract/about-the-export-fields/index.ts +++ b/src/ui/server/helpers/summary-lists/export-contract/about-the-export-fields/index.ts @@ -14,10 +14,12 @@ const { } = FORM_TITLES; const { + HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD, OTHER_AWARD_METHOD }, ABOUT_GOODS_OR_SERVICES: { DESCRIPTION, FINAL_DESTINATION }, HOW_WILL_YOU_GET_PAID: { PAYMENT_TERMS_DESCRIPTION }, } = FIELD_IDS; +const { HOW_WAS_THE_CONTRACT_AWARDED_CHANGE, HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE } = EXPORT_CONTRACT_ROUTES; const { ABOUT_GOODS_OR_SERVICES_CHANGE, ABOUT_GOODS_OR_SERVICES_CHECK_AND_CHANGE } = EXPORT_CONTRACT_ROUTES; const { HOW_WILL_YOU_GET_PAID_CHANGE, HOW_WILL_YOU_GET_PAID_CHECK_AND_CHANGE } = EXPORT_CONTRACT_ROUTES; @@ -32,6 +34,21 @@ const { HOW_WILL_YOU_GET_PAID_CHANGE, HOW_WILL_YOU_GET_PAID_CHECK_AND_CHANGE } = */ const generateAboutTheExportFields = (answers: ApplicationExportContract, referenceNumber: number, countries: Array, checkAndChange: boolean) => { const fields = [ + fieldGroupItem( + { + field: getFieldById(FIELDS.HOW_WAS_THE_CONTRACT_AWARDED, AWARD_METHOD), + data: answers, + href: generateChangeLink( + HOW_WAS_THE_CONTRACT_AWARDED_CHANGE, + HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE, + `#${AWARD_METHOD}-label`, + referenceNumber, + checkAndChange, + ), + renderChangeLink: true, + }, + answers[OTHER_AWARD_METHOD] ? answers[OTHER_AWARD_METHOD] : answers[AWARD_METHOD]?.value, + ), fieldGroupItem({ field: getFieldById(FIELDS.ABOUT_GOODS_OR_SERVICES, DESCRIPTION), data: answers, diff --git a/src/ui/server/routes/insurance/export-contract/index.test.ts b/src/ui/server/routes/insurance/export-contract/index.test.ts index 536015fba9..01f7a4e9f9 100644 --- a/src/ui/server/routes/insurance/export-contract/index.test.ts +++ b/src/ui/server/routes/insurance/export-contract/index.test.ts @@ -33,6 +33,8 @@ import { get as checkYourAnswersGet, post as checkYourAnswersPost } from '../../ const { ROOT, HOW_WAS_THE_CONTRACT_AWARDED, + HOW_WAS_THE_CONTRACT_AWARDED_CHANGE, + HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE, ABOUT_GOODS_OR_SERVICES, ABOUT_GOODS_OR_SERVICES_SAVE_AND_BACK, ABOUT_GOODS_OR_SERVICES_CHANGE, @@ -81,13 +83,17 @@ describe('routes/insurance/export-contract', () => { }); it('should setup all routes', () => { - expect(get).toHaveBeenCalledTimes(30); - expect(post).toHaveBeenCalledTimes(38); + expect(get).toHaveBeenCalledTimes(32); + expect(post).toHaveBeenCalledTimes(40); expect(get).toHaveBeenCalledWith(`/:referenceNumber${ROOT}`, exportContractRootGet); expect(get).toHaveBeenCalledWith(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED}`, howWasTheContractAwardedGet); expect(post).toHaveBeenCalledWith(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED}`, howWasTheContractAwardedPost); + expect(get).toHaveBeenCalledWith(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED_CHANGE}`, howWasTheContractAwardedGet); + expect(post).toHaveBeenCalledWith(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED_CHANGE}`, howWasTheContractAwardedPost); + expect(get).toHaveBeenCalledWith(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE}`, howWasTheContractAwardedGet); + expect(post).toHaveBeenCalledWith(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE}`, howWasTheContractAwardedPost); expect(get).toHaveBeenCalledWith(`/:referenceNumber${ABOUT_GOODS_OR_SERVICES}`, aboutGoodsOrServicesGet); expect(post).toHaveBeenCalledWith(`/:referenceNumber${ABOUT_GOODS_OR_SERVICES}`, aboutGoodsOrServicesPost); diff --git a/src/ui/server/routes/insurance/export-contract/index.ts b/src/ui/server/routes/insurance/export-contract/index.ts index 328c344aa5..dc6600feb7 100644 --- a/src/ui/server/routes/insurance/export-contract/index.ts +++ b/src/ui/server/routes/insurance/export-contract/index.ts @@ -34,6 +34,8 @@ import { get as checkYourAnswersGet, post as checkYourAnswersPost } from '../../ const { ROOT, HOW_WAS_THE_CONTRACT_AWARDED, + HOW_WAS_THE_CONTRACT_AWARDED_CHANGE, + HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE, HOW_WAS_THE_CONTRACT_AWARDED_SAVE_AND_BACK, ABOUT_GOODS_OR_SERVICES, ABOUT_GOODS_OR_SERVICES_SAVE_AND_BACK, @@ -80,6 +82,10 @@ exportContractRoute.get(`/:referenceNumber${ROOT}`, exportContractRootGet); exportContractRoute.get(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED}`, howWasTheContractAwardedGet); exportContractRoute.post(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED}`, howWasTheContractAwardedPost); +exportContractRoute.get(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED_CHANGE}`, howWasTheContractAwardedGet); +exportContractRoute.post(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED_CHANGE}`, howWasTheContractAwardedPost); +exportContractRoute.get(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE}`, howWasTheContractAwardedGet); +exportContractRoute.post(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED_CHECK_AND_CHANGE}`, howWasTheContractAwardedPost); exportContractRoute.post(`/:referenceNumber${HOW_WAS_THE_CONTRACT_AWARDED_SAVE_AND_BACK}`, howWasTheContractAwardedSaveAndBackPost); diff --git a/src/ui/server/routes/insurance/index.test.ts b/src/ui/server/routes/insurance/index.test.ts index 679701c48b..fc92cdd09f 100644 --- a/src/ui/server/routes/insurance/index.test.ts +++ b/src/ui/server/routes/insurance/index.test.ts @@ -21,8 +21,8 @@ describe('routes/insurance', () => { }); it('should setup all routes', () => { - expect(get).toHaveBeenCalledTimes(207); - expect(post).toHaveBeenCalledTimes(212); + expect(get).toHaveBeenCalledTimes(209); + expect(post).toHaveBeenCalledTimes(214); expect(get).toHaveBeenCalledWith(INSURANCE_ROUTES.START, startGet); diff --git a/src/ui/server/test-mocks/mock-application.ts b/src/ui/server/test-mocks/mock-application.ts index 98a0b5d839..90bcd84bd0 100644 --- a/src/ui/server/test-mocks/mock-application.ts +++ b/src/ui/server/test-mocks/mock-application.ts @@ -94,6 +94,7 @@ export const mockExportContract = { ...EXPORT_CONTRACT_AWARD_METHOD.COMPETITIVE_BIDDING, id: 'clldfm6pt000noqa6fs6cj5xo', }, + otherAwardMethod: 'Mock other award method', goodsOrServicesDescription: 'Mock description', finalDestinationKnown: false, finalDestinationCountryCode: mockCountries[0].isoCode,