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 b8910d6be9..92093bd21b 100644 --- a/e2e-tests/commands/insurance/check-export-contract-summary-list.js +++ b/e2e-tests/commands/insurance/check-export-contract-summary-list.js @@ -1,22 +1,25 @@ import { summaryList } from '../../pages/shared'; import getSummaryListField from './get-summary-list-field'; import { EXPECTED_SINGLE_LINE_STRING, FIELD_VALUES } from '../../constants'; -import FIELD_IDS from '../../constants/field-ids/insurance/export-contract'; +import { INSURANCE_FIELD_IDS } from '../../constants/field-ids/insurance'; import { EXPORT_CONTRACT_FIELDS as FIELDS } from '../../content-strings/fields/insurance/export-contract'; import formatCurrency from '../../helpers/format-currency'; 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 }, - USING_AGENT, - AGENT_DETAILS: { NAME, FULL_ADDRESS, COUNTRY_CODE }, - AGENT_SERVICE: { IS_CHARGING, SERVICE_DESCRIPTION }, - AGENT_CHARGES: { FIXED_SUM_AMOUNT, FIXED_SUM_CURRENCY_CODE, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE }, -} = FIELD_IDS; + CURRENCY: { CURRENCY_CODE }, + EXPORT_CONTRACT: { + 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 }, + USING_AGENT, + AGENT_DETAILS: { NAME, FULL_ADDRESS, COUNTRY_CODE }, + AGENT_SERVICE: { IS_CHARGING, SERVICE_DESCRIPTION }, + AGENT_CHARGES: { FIXED_SUM_AMOUNT, FIXED_SUM_CURRENCY_CODE, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE }, + }, +} = INSURANCE_FIELD_IDS; const { OPEN_TENDER } = FIELDS.HOW_WAS_THE_CONTRACT_AWARDED[AWARD_METHOD].OPTIONS; @@ -218,16 +221,22 @@ const checkExportContractSummaryList = { } }, [FIXED_SUM_CURRENCY_CODE]: ({ shouldRender = false }) => { - const fieldId = FIXED_SUM_CURRENCY_CODE; + /** + * NOTE: + * - The summary list uses the CURRENCY_CODE field ID. + * - The data uses the FIXED_SUM_CURRENCY_CODE field ID. + * The summary has to use the CURRENCY_CODE field ID to match the generic curency form field ID. + */ + const summaryListFieldId = CURRENCY_CODE; if (shouldRender) { - const { expectedKey, expectedChangeLinkText } = getSummaryListField(fieldId, FIELDS.AGENT_CHARGES); + const { expectedKey, expectedChangeLinkText } = getSummaryListField(summaryListFieldId, FIELDS.AGENT_CHARGES); - const expectedValue = application.EXPORT_CONTRACT.AGENT_CHARGES[fieldId]; + const expectedValue = application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_CURRENCY_CODE]; - cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue, expectedChangeLinkText); + cy.assertSummaryListRow(summaryList, summaryListFieldId, expectedKey, expectedValue, expectedChangeLinkText); } else { - cy.assertSummaryListRowDoesNotExist(summaryList, fieldId); + cy.assertSummaryListRowDoesNotExist(summaryList, summaryListFieldId); } }, [FIXED_SUM_AMOUNT]: ({ shouldRender = false, agentChargeFixedSumAmount }) => { diff --git a/e2e-tests/commands/insurance/complete-and-submit-alternative-currency-form.js b/e2e-tests/commands/insurance/complete-and-submit-alternative-currency-form.js index 94b5331088..ba93f77fb5 100644 --- a/e2e-tests/commands/insurance/complete-and-submit-alternative-currency-form.js +++ b/e2e-tests/commands/insurance/complete-and-submit-alternative-currency-form.js @@ -11,7 +11,7 @@ const { CURRENCY_CODE } = INSURANCE_FIELD_IDS.CURRENCY; * @param {String} isoCode: isoCode for radio selection. * @param {Boolean} alternativeCurrency: If alternative currency should be entered. */ -const completeAndSubmitAlternativeCurrencyForm = ({ isoCode, alternativeCurrency = true }) => { +const completeAndSubmitAlternativeCurrencyForm = ({ isoCode, alternativeCurrency = false }) => { if (isoCode) { radios(CURRENCY_CODE, isoCode).option.label().click(); cy.clickSubmitButton(); diff --git a/e2e-tests/fixtures/application.js b/e2e-tests/fixtures/application.js index ea84afc874..e630acb1a5 100644 --- a/e2e-tests/fixtures/application.js +++ b/e2e-tests/fixtures/application.js @@ -61,7 +61,7 @@ const { PRIVATE_MARKET: { ATTEMPTED, DECLINED_DESCRIPTION }, AGENT_DETAILS: { COUNTRY_CODE: AGENT_COUNTRY_CODE, FULL_ADDRESS: AGENT_FULL_ADDRESS, NAME: AGENT_NAME }, AGENT_SERVICE: { IS_CHARGING, SERVICE_DESCRIPTION }, - AGENT_CHARGES: { METHOD, PAYABLE_COUNTRY_CODE, FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE }, + AGENT_CHARGES: { METHOD, PAYABLE_COUNTRY_CODE, FIXED_SUM_AMOUNT, FIXED_SUM_CURRENCY_CODE, PERCENTAGE_CHARGE }, }, EXPORTER_BUSINESS: { ALTERNATIVE_TRADING_ADDRESS: { FULL_ADDRESS: EXPORTER_BUSINESS_FULL_ALT_TRADING_ADDRESS }, @@ -176,6 +176,7 @@ const application = { AGENT_CHARGES: { [PERCENTAGE_CHARGE]: '10', [FIXED_SUM_AMOUNT]: '1500', + [FIXED_SUM_CURRENCY_CODE]: GBP_CURRENCY_CODE, [METHOD]: AGENT_SERVICE_CHARGE.METHOD.FIXED_SUM, [PAYABLE_COUNTRY_CODE]: COUNTRY_APPLICATION_SUPPORT.ONLINE.NAME, }, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount-alternative-currency.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount-alternative-currency.spec.js deleted file mode 100644 index e4c60fa135..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount-alternative-currency.spec.js +++ /dev/null @@ -1,167 +0,0 @@ -import { summaryList } from '../../../../../../../../pages/shared'; -import FIELD_IDS from '../../../../../../../../constants/field-ids/insurance/export-contract'; -import { INSURANCE_ROUTES } from '../../../../../../../../constants/routes/insurance'; -import application from '../../../../../../../../fixtures/application'; -import { EUR_CURRENCY_CODE, NON_STANDARD_CURRENCY_CODE, SYMBOLS } from '../../../../../../../../fixtures/currencies'; -import formatCurrency from '../../../../../../../../helpers/format-currency'; - -const { - ROOT, - CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT }, - EXPORT_CONTRACT: { AGENT_CHARGES_CHECK_AND_CHANGE }, -} = INSURANCE_ROUTES; - -const { - AGENT_CHARGES: { FIXED_SUM_AMOUNT, PAYABLE_COUNTRY_CODE }, -} = FIELD_IDS; - -const fieldId = FIXED_SUM_AMOUNT; - -const baseUrl = Cypress.config('baseUrl'); - -context( - `Insurance - Change your answers - Export contract - Summary list - Agent charges - ${FIXED_SUM_AMOUNT} - As an exporter, I want to change my answers to an alternative currency`, - () => { - let referenceNumber; - let checkYourAnswersUrl; - - before(() => { - cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { - referenceNumber = refNumber; - - cy.completePrepareApplicationSinglePolicyType({ - referenceNumber, - isUsingAgent: true, - agentIsCharging: true, - agentChargeMethodFixedSum: true, - }); - - cy.clickTaskCheckAnswers(); - - // To get past previous "Check your answers" pages - cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 }); - - checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${EXPORT_CONTRACT}`; - - cy.assertUrl(checkYourAnswersUrl); - }); - }); - - beforeEach(() => { - cy.saveSession(); - - cy.navigateToUrl(checkYourAnswersUrl); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - describe(`changing ${PAYABLE_COUNTRY_CODE} to ${SYMBOLS.EUR}`, () => { - const currencyCode = EUR_CURRENCY_CODE; - - describe('when clicking the `change` link', () => { - it(`should redirect to ${AGENT_CHARGES_CHECK_AND_CHANGE}`, () => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(fieldId).changeLink().click(); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: AGENT_CHARGES_CHECK_AND_CHANGE, fieldId }); - }); - }); - - beforeEach(() => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(fieldId).changeLink().click(); - - cy.completeAndSubmitAlternativeCurrencyForm({ isoCode: EUR_CURRENCY_CODE }); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: AGENT_CHARGES_CHECK_AND_CHANGE }); - - // submit the AGENT_CHARGES form - cy.clickSubmitButton(); - }); - - it(`should redirect to ${AGENT_CHARGES_CHECK_AND_CHANGE} and then ${EXPORT_CONTRACT}`, () => { - cy.assertChangeAnswersPageUrl({ referenceNumber, route: EXPORT_CONTRACT }); - }); - - it(`should render the new answer for ${FIXED_SUM_AMOUNT} including ${SYMBOLS.EUR}`, () => { - const row = summaryList.field(FIXED_SUM_AMOUNT); - const expected = formatCurrency(application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_AMOUNT], currencyCode); - - cy.checkText(row.value(), expected); - }); - }); - - describe(`changing ${PAYABLE_COUNTRY_CODE} to an alternative currency`, () => { - const currencyCode = NON_STANDARD_CURRENCY_CODE; - - describe('when clicking the `change` link', () => { - it(`should redirect to ${AGENT_CHARGES_CHECK_AND_CHANGE}`, () => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(fieldId).changeLink().click(); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: AGENT_CHARGES_CHECK_AND_CHANGE, fieldId }); - }); - }); - - describe('form submission with a new answer', () => { - beforeEach(() => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(fieldId).changeLink().click(); - - cy.completeAndSubmitAlternativeCurrencyForm({ alternativeCurrency: true }); - - // submit AGENT_CHARGES form - cy.clickSubmitButton(); - }); - - it(`should redirect to ${AGENT_CHARGES_CHECK_AND_CHANGE} and then ${EXPORT_CONTRACT}`, () => { - cy.assertChangeAnswersPageUrl({ referenceNumber, route: EXPORT_CONTRACT }); - }); - - it(`should render the new answer for ${FIXED_SUM_AMOUNT}`, () => { - const row = summaryList.field(FIXED_SUM_AMOUNT); - const expected = formatCurrency(application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_AMOUNT], currencyCode); - - cy.checkText(row.value(), expected); - }); - }); - }); - - describe(`changing ${PAYABLE_COUNTRY_CODE} from an alternative currency to ${SYMBOLS.EUR}`, () => { - const currencyCode = EUR_CURRENCY_CODE; - - describe('form submission with a new answer', () => { - beforeEach(() => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(fieldId).changeLink().click(); - - cy.completeAndSubmitAlternativeCurrencyForm({ alternativeCurrency: true }); - - // submit AGENT_CHARGES form - cy.clickSubmitButton(); - - summaryList.field(fieldId).changeLink().click(); - - cy.completeAndSubmitAlternativeCurrencyForm({ isoCode: EUR_CURRENCY_CODE }); - - // submit AGENT_CHARGES form - cy.clickSubmitButton(); - }); - - it(`should render the new answer for ${FIXED_SUM_AMOUNT}`, () => { - const row = summaryList.field(FIXED_SUM_AMOUNT); - const expected = formatCurrency(application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_AMOUNT], currencyCode); - - cy.checkText(row.value(), expected); - }); - }); - }); - }, -); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount.spec.js index 0b7de6e444..56a4a6a0a9 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount.spec.js @@ -7,7 +7,7 @@ import application from '../../../../../../../../fixtures/application'; const { ROOT, CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT }, - EXPORT_CONTRACT: { AGENT_CHARGES_CHECK_AND_CHANGE }, + EXPORT_CONTRACT: { HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE }, } = INSURANCE_ROUTES; const { @@ -55,12 +55,12 @@ context(`Insurance - Change your answers - Export contract - Summary list - Agen }); describe('when clicking the `change` link', () => { - it(`should redirect to ${AGENT_CHARGES_CHECK_AND_CHANGE}`, () => { + it(`should redirect to ${HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE}`, () => { cy.navigateToUrl(url); summaryList.field(fieldId).changeLink().click(); - cy.assertChangeAnswersPageUrl({ referenceNumber, route: AGENT_CHARGES_CHECK_AND_CHANGE, fieldId }); + cy.assertChangeAnswersPageUrl({ referenceNumber, route: HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE, fieldId }); }); }); @@ -74,10 +74,7 @@ context(`Insurance - Change your answers - Export contract - Summary list - Agen it(`should redirect to ${EXPORT_CONTRACT}`, () => { summaryList.field(fieldId).changeLink().click(); - cy.completeAndSubmitAgentChargesForm({ - fixedSumMethod: true, - fixedSumAmount: newValueInput, - }); + cy.completeAndSubmitHowMuchTheAgentIsChargingForm({ fixedSumAmount: newValueInput }); cy.assertChangeAnswersPageUrl({ referenceNumber, route: EXPORT_CONTRACT, fieldId }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-to-percentage.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-to-percentage.spec.js deleted file mode 100644 index a553789ae6..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-to-percentage.spec.js +++ /dev/null @@ -1,87 +0,0 @@ -import { status, summaryList } from '../../../../../../../../pages/shared'; -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'; - -const { - ROOT, - CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT }, - EXPORT_CONTRACT: { AGENT_CHARGES_CHECK_AND_CHANGE }, -} = INSURANCE_ROUTES; - -const { - AGENT_CHARGES: { FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE }, -} = FIELD_IDS; - -const baseUrl = Cypress.config('baseUrl'); - -context('Insurance - Change your answers - Export contract - Summary list - Agent charges - Fixed sum to percentage', () => { - let referenceNumber; - let url; - - before(() => { - cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { - referenceNumber = refNumber; - - cy.completePrepareApplicationSinglePolicyType({ - referenceNumber, - isUsingAgent: true, - agentIsCharging: true, - agentChargeMethodFixedSum: true, - }); - - cy.clickTaskCheckAnswers(); - - // To get past previous "Check your answers" pages - cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 }); - - url = `${baseUrl}${ROOT}/${referenceNumber}${EXPORT_CONTRACT}`; - - cy.assertUrl(url); - }); - }); - - beforeEach(() => { - cy.saveSession(); - - cy.navigateToUrl(url); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - describe('when clicking the `change` link', () => { - it(`should redirect to ${AGENT_CHARGES_CHECK_AND_CHANGE}`, () => { - cy.navigateToUrl(url); - - summaryList.field(FIXED_SUM_AMOUNT).changeLink().click(); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: AGENT_CHARGES_CHECK_AND_CHANGE, fieldId: FIXED_SUM_AMOUNT }); - }); - }); - - describe('form submission with a new answer', () => { - beforeEach(() => { - cy.navigateToUrl(url); - }); - - it(`should redirect to ${EXPORT_CONTRACT}`, () => { - summaryList.field(FIXED_SUM_AMOUNT).changeLink().click(); - - cy.completeAndSubmitAgentChargesForm({ percentageMethod: true }); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: EXPORT_CONTRACT, fieldId: FIXED_SUM_AMOUNT }); - }); - - it(`should render only ${PERCENTAGE_CHARGE} and ${PAYABLE_COUNTRY_CODE} fields/values`, () => { - checkSummaryList[FIXED_SUM_AMOUNT]({ shouldRender: false }); - checkSummaryList[PERCENTAGE_CHARGE]({ shouldRender: true }); - checkSummaryList[PAYABLE_COUNTRY_CODE]({ shouldRender: true }); - }); - - it('should retain a `completed` status tag', () => { - cy.checkTaskStatusCompleted(status); - }); - }); -}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-payable-country.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-payable-country.spec.js index 77cba2113a..48978101a9 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-payable-country.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-payable-country.spec.js @@ -31,7 +31,7 @@ context(`Insurance - Change your answers - Export contract - Summary list - Agen referenceNumber, isUsingAgent: true, agentIsCharging: true, - agentChargeMethodFixedSum: true, + agentChargeMethodPercentage: true, }); cy.clickTaskCheckAnswers(); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-percentage-to-fixed-sum.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-percentage-to-fixed-sum.spec.js deleted file mode 100644 index c74b5ddd56..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-percentage-to-fixed-sum.spec.js +++ /dev/null @@ -1,89 +0,0 @@ -import { status, summaryList } from '../../../../../../../../pages/shared'; -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'; - -const { - ROOT, - CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT }, - EXPORT_CONTRACT: { AGENT_CHARGES_CHECK_AND_CHANGE }, -} = INSURANCE_ROUTES; - -const { - AGENT_CHARGES: { FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE }, -} = FIELD_IDS; - -const fieldId = PERCENTAGE_CHARGE; - -const baseUrl = Cypress.config('baseUrl'); - -context('Insurance - Change your answers - Export contract - Summary list - Percentage to Fixed sum', () => { - let referenceNumber; - let url; - - before(() => { - cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { - referenceNumber = refNumber; - - cy.completePrepareApplicationSinglePolicyType({ - referenceNumber, - isUsingAgent: true, - agentIsCharging: true, - agentChargeMethodPercentage: true, - }); - - cy.clickTaskCheckAnswers(); - - // To get past previous "Check your answers" pages - cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 }); - - url = `${baseUrl}${ROOT}/${referenceNumber}${EXPORT_CONTRACT}`; - - cy.assertUrl(url); - }); - }); - - beforeEach(() => { - cy.saveSession(); - - cy.navigateToUrl(url); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - describe('when clicking the `change` link', () => { - it(`should redirect to ${AGENT_CHARGES_CHECK_AND_CHANGE}`, () => { - cy.navigateToUrl(url); - - summaryList.field(fieldId).changeLink().click(); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: AGENT_CHARGES_CHECK_AND_CHANGE, fieldId }); - }); - }); - - describe('form submission with a new answer', () => { - beforeEach(() => { - cy.navigateToUrl(url); - }); - - it(`should redirect to ${EXPORT_CONTRACT}`, () => { - summaryList.field(fieldId).changeLink().click(); - - cy.completeAndSubmitAgentChargesForm({ fixedSumMethod: true }); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: EXPORT_CONTRACT, fieldId }); - }); - - it(`should render only ${FIXED_SUM_AMOUNT} and ${PAYABLE_COUNTRY_CODE} fields/values`, () => { - checkSummaryList[PERCENTAGE_CHARGE]({ shouldRender: false }); - checkSummaryList[FIXED_SUM_AMOUNT]({ shouldRender: true }); - checkSummaryList[PAYABLE_COUNTRY_CODE]({ shouldRender: true }); - }); - - it('should retain a `completed` status tag', () => { - cy.checkTaskStatusCompleted(status); - }); - }); -}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-no-to-yes.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-no-to-yes.spec.js index 0ee4605c8a..cf08470383 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-no-to-yes.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-no-to-yes.spec.js @@ -11,7 +11,7 @@ const { const { AGENT_SERVICE: { IS_CHARGING: FIELD_ID }, - AGENT_CHARGES: { PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE }, + AGENT_CHARGES: { FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE }, } = FIELD_IDS; const baseUrl = Cypress.config('baseUrl'); @@ -69,7 +69,7 @@ context('Insurance - Change your answers - Export contract - Summary list - Agen cy.navigateToUrl(url); }); - it(`should redirect to ${EXPORT_CONTRACT} after completing (now required) ${AGENT_CHARGES_CHECK_AND_CHANGE} fields`, () => { + it(`should redirect to ${AGENT_SERVICE_CHECK_AND_CHANGE} and then ${EXPORT_CONTRACT} after completing (now required) agent charges related forms`, () => { summaryList.field(FIELD_ID).changeLink().click(); cy.navigateToUrl(url); @@ -88,15 +88,17 @@ context('Insurance - Change your answers - Export contract - Summary list - Agen percentageMethod: false, }); + cy.completeAndSubmitAlternativeCurrencyForm({}); + + cy.completeAndSubmitHowMuchTheAgentIsChargingForm({}); + cy.assertChangeAnswersPageUrl({ referenceNumber, route: EXPORT_CONTRACT, fieldId: FIELD_ID }); }); it(`should render new ${FIELD_ID} answer and other agent charges fields`, () => { checkSummaryList[FIELD_ID]({ shouldRender: true, isYes: true }); - - // checkSummaryList[FIXED_SUM_AMOUNT]({ shouldRender: true }); - - checkSummaryList[PERCENTAGE_CHARGE]({ shouldRender: true }); + checkSummaryList[FIXED_SUM_AMOUNT]({ shouldRender: true }); + checkSummaryList[PERCENTAGE_CHARGE]({ shouldRender: false }); checkSummaryList[PAYABLE_COUNTRY_CODE]({ shouldRender: true }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-yes-to-no.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-yes-to-no.spec.js index f7fbfc7fe8..5cb5905ccc 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-yes-to-no.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-yes-to-no.spec.js @@ -1,19 +1,23 @@ -import { autoCompleteField, field, status, summaryList } from '../../../../../../../../pages/shared'; +import { autoCompleteField, field, status, summaryList, radios } from '../../../../../../../../pages/shared'; import { agentChargesPage } from '../../../../../../../../pages/insurance/export-contract'; -import FIELD_IDS from '../../../../../../../../constants/field-ids/insurance/export-contract'; +import { INSURANCE_FIELD_IDS } from '../../../../../../../../constants/field-ids/insurance'; import { INSURANCE_ROUTES } from '../../../../../../../../constants/routes/insurance'; import checkSummaryList from '../../../../../../../../commands/insurance/check-export-contract-summary-list'; +import { GBP } from '../../../../../../../../fixtures/currencies'; const { ROOT, CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT }, - EXPORT_CONTRACT: { AGENT_CHARGES, AGENT_SERVICE_CHECK_AND_CHANGE }, + EXPORT_CONTRACT: { AGENT_CHARGES, AGENT_SERVICE_CHECK_AND_CHANGE, HOW_MUCH_THE_AGENT_IS_CHARGING, AGENT_CHARGES_CURRENCY }, } = INSURANCE_ROUTES; const { - AGENT_SERVICE: { IS_CHARGING: FIELD_ID }, - AGENT_CHARGES: { FIXED_SUM, FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, METHOD, PAYABLE_COUNTRY_CODE, PERCENTAGE }, -} = FIELD_IDS; + CURRENCY: { CURRENCY_CODE }, + EXPORT_CONTRACT: { + AGENT_SERVICE: { IS_CHARGING: FIELD_ID }, + AGENT_CHARGES: { FIXED_SUM, FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, METHOD, PAYABLE_COUNTRY_CODE, PERCENTAGE }, + }, +} = INSURANCE_FIELD_IDS; const baseUrl = Cypress.config('baseUrl'); @@ -90,21 +94,35 @@ context('Insurance - Change your answers - Export contract - Summary list - Agen cy.checkTaskStatusCompleted(status); }); - describe(`when changing the answer again from no to yes and going back to ${AGENT_CHARGES}`, () => { - it('should have an empty values', () => { + describe(`when changing the answer again from no to yes and going back to ${AGENT_CHARGES}, ${AGENT_CHARGES_CURRENCY} and ${HOW_MUCH_THE_AGENT_IS_CHARGING}`, () => { + it('should have empty field values', () => { summaryList.field(FIELD_ID).changeLink().click(); cy.completeAndSubmitAgentServiceForm({ agentIsCharging: true, }); + // assert AGENT_CHARGES field values. cy.assertRadioOptionIsNotChecked(agentChargesPage[METHOD][FIXED_SUM].input()); cy.assertRadioOptionIsNotChecked(agentChargesPage[METHOD][PERCENTAGE].input()); - cy.checkValue(field(FIXED_SUM_AMOUNT), ''); - cy.checkValue(field(PERCENTAGE_CHARGE), ''); cy.checkValue(autoCompleteField(PAYABLE_COUNTRY_CODE), ''); + + cy.completeAndSubmitAgentChargesForm({ fixedSumMethod: true }); + + /** + * Assert AGENT_CHARGES_CURRENCY field values. + * GBP radio option should be checked by default. + */ + const { option } = radios(CURRENCY_CODE, GBP.isoCode); + + cy.assertRadioOptionIsChecked(option.input()); + + cy.completeAndSubmitAlternativeCurrencyForm({}); + + // assert HOW_MUCH_THE_AGENT_IS_CHARGING field values. + cy.checkValue(field(FIXED_SUM_AMOUNT), ''); }); }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-change-currency.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-change-currency.spec.js index 9136ef0775..57e6b41a30 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-change-currency.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-change-currency.spec.js @@ -4,7 +4,7 @@ import { assertCurrencyFormFields } from '../../../../../../shared-test-assertio const { ROOT, - EXPORT_CONTRACT: { AGENT_CHARGES }, + EXPORT_CONTRACT: { AGENT_CHARGES, HOW_MUCH_THE_AGENT_IS_CHARGING }, } = INSURANCE_ROUTES; const { @@ -30,30 +30,18 @@ context("Insurance - Export contract - Agent charges page - As an Exporter I wan }); }); - beforeEach(() => { - cy.saveSession(); - cy.navigateToUrl(url); - - cy.completeAgentChargesForm({ - fixedSumMethod: true, - fixedSumAmount: null, - payableCountry: null, - }); - }); - after(() => { cy.deleteApplication(referenceNumber); }); - describe('prefixes should be displayed based on the chosen currency', () => { - before(() => { + describe(`${HOW_MUCH_THE_AGENT_IS_CHARGING} prefixes should be displayed based on the chosen currency`, () => { + beforeEach(() => { cy.saveSession(); cy.navigateToUrl(url); cy.completeAndSubmitAgentChargesForm({ fixedSumMethod: true, - fixedSumAmount: null, - payableCountry: null, + percentageMethod: false, }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-fixed-sum-amount-as-decimal.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-fixed-sum-amount-as-decimal.spec.js index d9b66db40c..546513063b 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-fixed-sum-amount-as-decimal.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-fixed-sum-amount-as-decimal.spec.js @@ -3,7 +3,7 @@ import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance'; const { ROOT, - EXPORT_CONTRACT: { AGENT_CHARGES, CHECK_YOUR_ANSWERS }, + EXPORT_CONTRACT: { AGENT_CHARGES, AGENT_CHARGES_CURRENCY }, } = INSURANCE_ROUTES; const { @@ -15,7 +15,7 @@ const baseUrl = Cypress.config('baseUrl'); context('Insurance - Export contract - Agent charges page - Fixed sum amount as decimal', () => { let referenceNumber; let url; - let checkYourAnswersUrl; + let agentChargesCurrencyUrl; before(() => { cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { @@ -25,7 +25,7 @@ context('Insurance - Export contract - Agent charges page - Fixed sum amount as cy.completeAndSubmitExportContractForms({ formToStopAt: 'agentService', isUsingAgent: true, agentIsCharging: true }); url = `${baseUrl}${ROOT}/${referenceNumber}${AGENT_CHARGES}`; - checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; + agentChargesCurrencyUrl = `${baseUrl}${ROOT}/${referenceNumber}${AGENT_CHARGES_CURRENCY}`; }); }); @@ -45,16 +45,16 @@ context('Insurance - Export contract - Agent charges page - Fixed sum amount as describe(`when submitting with ${METHOD} as ${FIXED_SUM} as a decimal number`, () => { const fixedSumAmount = '100.54'; - it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => { + it(`should redirect to ${AGENT_CHARGES_CURRENCY}`, () => { cy.completeAndSubmitAgentChargesForm({ fixedSumMethod: true, fixedSumAmount }); - cy.assertUrl(checkYourAnswersUrl); + cy.assertUrl(agentChargesCurrencyUrl); }); - it('should update the `export contract` task status to `completed`', () => { + it('should retain the status of task `export contract` as `in progress`', () => { cy.navigateToAllSectionsUrl(referenceNumber); - cy.checkTaskExportContractStatusIsComplete(); + cy.checkTaskExportContractStatusIsInProgress(); }); describe('when going back to the page', () => { diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-fixed-sum-amount-with-comma.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-fixed-sum-amount-with-comma.spec.js index 59abbbe37e..b3749d0360 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-fixed-sum-amount-with-comma.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-fixed-sum-amount-with-comma.spec.js @@ -3,7 +3,7 @@ import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance'; const { ROOT, - EXPORT_CONTRACT: { AGENT_CHARGES, CHECK_YOUR_ANSWERS }, + EXPORT_CONTRACT: { AGENT_CHARGES, AGENT_CHARGES_CURRENCY }, } = INSURANCE_ROUTES; const { @@ -15,7 +15,7 @@ const baseUrl = Cypress.config('baseUrl'); context('Insurance - Export contract - Agent charges page - Fixed sum amount with a comma', () => { let referenceNumber; let url; - let checkYourAnswersUrl; + let agentChargesCurrencyUrl; before(() => { cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { @@ -25,7 +25,7 @@ context('Insurance - Export contract - Agent charges page - Fixed sum amount wit cy.completeAndSubmitExportContractForms({ formToStopAt: 'agentService', isUsingAgent: true, agentIsCharging: true }); url = `${baseUrl}${ROOT}/${referenceNumber}${AGENT_CHARGES}`; - checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; + agentChargesCurrencyUrl = `${baseUrl}${ROOT}/${referenceNumber}${AGENT_CHARGES_CURRENCY}`; }); }); @@ -46,16 +46,16 @@ context('Insurance - Export contract - Agent charges page - Fixed sum amount wit const fixedSumAmount = '1,000'; const amount = '1000'; - it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => { + it(`should redirect to ${AGENT_CHARGES_CURRENCY}`, () => { cy.completeAndSubmitAgentChargesForm({ fixedSumMethod: true, fixedSumAmount }); - cy.assertUrl(checkYourAnswersUrl); + cy.assertUrl(agentChargesCurrencyUrl); }); - it('should update the `export contract` task status to `completed`', () => { + it('should retain the status of task `export contract` as `in progress`', () => { cy.navigateToAllSectionsUrl(referenceNumber); - cy.checkTaskExportContractStatusIsComplete(); + cy.checkTaskExportContractStatusIsInProgress(); }); describe('when going back to the page', () => { diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/save-and-back-method-fixed-sum.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/save-and-back-method-fixed-sum.spec.js index 2550b49b43..e109b93746 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/save-and-back-method-fixed-sum.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/save-and-back-method-fixed-sum.spec.js @@ -68,7 +68,7 @@ context(`Insurance - Export contract - Agent charges - Save and go back - ${METH }); describe('when all fields are provided', () => { - it('should update the `export contract` task status to `completed`', () => { + it('should retain the status of task `export contract` as `in progress`', () => { cy.navigateToUrl(url); cy.completeAgentChargesForm({ fixedSumMethod: true }); @@ -77,7 +77,7 @@ context(`Insurance - Export contract - Agent charges - Save and go back - ${METH cy.navigateToAllSectionsUrl(referenceNumber); - cy.checkTaskExportContractStatusIsComplete(); + cy.checkTaskExportContractStatusIsInProgress(); }); describe('when going back to the page', () => { diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount-alternative-currency.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount-alternative-currency.spec.js deleted file mode 100644 index 09719f2702..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount-alternative-currency.spec.js +++ /dev/null @@ -1,158 +0,0 @@ -import { summaryList } from '../../../../../../../pages/shared'; -import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; -import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract'; -import application from '../../../../../../../fixtures/application'; -import { EUR_CURRENCY_CODE, NON_STANDARD_CURRENCY_CODE, SYMBOLS } from '../../../../../../../fixtures/currencies'; -import formatCurrency from '../../../../../../../helpers/format-currency'; - -const { - ROOT, - EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS, AGENT_CHARGES_CHANGE }, -} = INSURANCE_ROUTES; - -const { - AGENT_CHARGES: { FIXED_SUM_AMOUNT, PAYABLE_COUNTRY_CODE }, -} = FIELD_IDS; - -const fieldId = PAYABLE_COUNTRY_CODE; - -const baseUrl = Cypress.config('baseUrl'); - -context( - `Insurance - Export contract - Change your answers - Agent charges - ${FIXED_SUM_AMOUNT} - As an exporter, I want to change my answers to an alternative currency`, - () => { - let referenceNumber; - let checkYourAnswersUrl; - - before(() => { - cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { - referenceNumber = refNumber; - - cy.completeExportContractSection({ - isUsingAgent: true, - agentIsCharging: true, - agentChargeMethodFixedSum: true, - }); - - checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; - - cy.assertUrl(checkYourAnswersUrl); - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - describe(`changing ${PAYABLE_COUNTRY_CODE} to ${SYMBOLS.EUR}`, () => { - const currencyCode = EUR_CURRENCY_CODE; - - describe('when clicking the `change` link', () => { - it(`should redirect to ${AGENT_CHARGES_CHANGE}`, () => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(fieldId).changeLink().click(); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: AGENT_CHARGES_CHANGE, fieldId }); - }); - }); - - beforeEach(() => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(fieldId).changeLink().click(); - - cy.completeAndSubmitAlternativeCurrencyForm({ isoCode: EUR_CURRENCY_CODE }); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: AGENT_CHARGES_CHANGE }); - - // submit the AGENT_CHARGES form - cy.clickSubmitButton(); - }); - - it(`should redirect to ${AGENT_CHARGES_CHANGE} and then ${CHECK_YOUR_ANSWERS}`, () => { - cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS }); - }); - - it(`should render the new answer for ${FIXED_SUM_AMOUNT} including ${SYMBOLS.EUR}`, () => { - const row = summaryList.field(FIXED_SUM_AMOUNT); - const expected = formatCurrency(application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_AMOUNT], currencyCode); - - cy.checkText(row.value(), expected); - }); - }); - - describe(`changing ${PAYABLE_COUNTRY_CODE} to an alternative currency`, () => { - const currencyCode = NON_STANDARD_CURRENCY_CODE; - - describe('when clicking the `change` link', () => { - it(`should redirect to ${AGENT_CHARGES_CHANGE}`, () => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(fieldId).changeLink().click(); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: AGENT_CHARGES_CHANGE, fieldId }); - }); - }); - - describe('form submission with a new answer', () => { - beforeEach(() => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(fieldId).changeLink().click(); - - cy.completeAndSubmitAlternativeCurrencyForm({ alternativeCurrency: true }); - - // submit AGENT_CHARGES form - cy.clickSubmitButton(); - }); - - it(`should redirect to ${AGENT_CHARGES_CHANGE} and then ${CHECK_YOUR_ANSWERS}`, () => { - cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS }); - }); - - it(`should render the new answer for ${FIXED_SUM_AMOUNT}`, () => { - const row = summaryList.field(FIXED_SUM_AMOUNT); - const expected = formatCurrency(application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_AMOUNT], currencyCode); - - cy.checkText(row.value(), expected); - }); - }); - }); - - describe(`changing ${PAYABLE_COUNTRY_CODE} from an alternative currency to ${SYMBOLS.EUR}`, () => { - const currencyCode = EUR_CURRENCY_CODE; - - describe('form submission with a new answer', () => { - beforeEach(() => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(fieldId).changeLink().click(); - - cy.completeAndSubmitAlternativeCurrencyForm({ alternativeCurrency: true }); - - // submit AGENT_CHARGES form - cy.clickSubmitButton(); - - summaryList.field(fieldId).changeLink().click(); - - cy.completeAndSubmitAlternativeCurrencyForm({ isoCode: EUR_CURRENCY_CODE }); - - // submit AGENT_CHARGES form - cy.clickSubmitButton(); - }); - - it(`should render the new answer for ${FIXED_SUM_AMOUNT}`, () => { - const row = summaryList.field(FIXED_SUM_AMOUNT); - const expected = formatCurrency(application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_AMOUNT], currencyCode); - - cy.checkText(row.value(), expected); - }); - }); - }); - }, -); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount.spec.js index 6d0e73c736..6bdcdca3a4 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-amount.spec.js @@ -6,7 +6,7 @@ import application from '../../../../../../../fixtures/application'; const { ROOT, - EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS, AGENT_CHARGES_CHANGE }, + EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS, HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE }, } = INSURANCE_ROUTES; const { @@ -48,12 +48,12 @@ context( }); describe('when clicking the `change` link', () => { - it(`should redirect to ${AGENT_CHARGES_CHANGE}`, () => { + it(`should redirect to ${HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE}`, () => { cy.navigateToUrl(checkYourAnswersUrl); summaryList.field(fieldId).changeLink().click(); - cy.assertChangeAnswersPageUrl({ referenceNumber, route: AGENT_CHARGES_CHANGE, fieldId }); + cy.assertChangeAnswersPageUrl({ referenceNumber, route: HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE, fieldId }); }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-to-percentage.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-to-percentage.spec.js deleted file mode 100644 index 3d98bebcb2..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-fixed-sum-to-percentage.spec.js +++ /dev/null @@ -1,91 +0,0 @@ -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'; - -const { - ROOT, - EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS, AGENT_CHARGES_CHANGE }, -} = INSURANCE_ROUTES; - -const { - AGENT_CHARGES: { FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE }, -} = FIELD_IDS; - -const baseUrl = Cypress.config('baseUrl'); - -context( - 'Insurance - Export contract - Change your answers - Agent charges - Fixed sum to percentage - As an Exporter, I want to be able to review my input regarding the amount an agent is charging for helping me win my export contract, 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({ - isUsingAgent: true, - agentIsCharging: true, - agentChargeMethodFixedSum: true, - }); - - checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; - - cy.assertUrl(checkYourAnswersUrl); - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - describe(FIXED_SUM_AMOUNT, () => { - const fieldId = FIXED_SUM_AMOUNT; - - describe('when clicking the `change` link', () => { - it(`should redirect to ${AGENT_CHARGES_CHANGE}`, () => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(fieldId).changeLink().click(); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: AGENT_CHARGES_CHANGE, fieldId }); - }); - }); - - describe('form submission with a new answer', () => { - beforeEach(() => { - cy.navigateToUrl(checkYourAnswersUrl); - }); - - it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => { - summaryList.field(fieldId).changeLink().click(); - - cy.completeAndSubmitAgentChargesForm({ percentageMethod: true }); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS, fieldId }); - }); - - it(`should render only ${PERCENTAGE_CHARGE} and ${PAYABLE_COUNTRY_CODE} fields/values`, () => { - checkSummaryList[FIXED_SUM_AMOUNT]({ shouldRender: false }); - checkSummaryList[PERCENTAGE_CHARGE]({ shouldRender: true }); - checkSummaryList[PAYABLE_COUNTRY_CODE]({ shouldRender: true }); - }); - - describe(`when going back to ${AGENT_CHARGES_CHANGE}`, () => { - it('should have empty field `fixed sum` values', () => { - summaryList.field(PERCENTAGE_CHARGE).changeLink().click(); - - cy.assertAgentChargesFieldValues({ - percentageMethod: true, - }); - }); - }); - }); - }); - }, -); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-payable-country.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-payable-country.spec.js index 6c62d29ee6..d965b8946f 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-payable-country.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-payable-country.spec.js @@ -31,7 +31,7 @@ context( cy.completeExportContractSection({ isUsingAgent: true, agentIsCharging: true, - agentChargeMethodFixedSum: true, + agentChargeMethodPercentage: true, }); checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-percentage-to-fixed-sum.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-percentage-to-fixed-sum.spec.js deleted file mode 100644 index 6c780f820d..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-charges/change-your-answers-agent-charges-percentage-to-fixed-sum.spec.js +++ /dev/null @@ -1,91 +0,0 @@ -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'; - -const { - ROOT, - EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS, AGENT_CHARGES_CHANGE }, -} = INSURANCE_ROUTES; - -const { - AGENT_CHARGES: { FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE }, -} = FIELD_IDS; - -const baseUrl = Cypress.config('baseUrl'); - -context( - 'Insurance - Export contract - Change your answers - Agent charges - Percentage to Fixed sum - As an Exporter, I want to be able to review my input regarding the amount an agent is charging for helping me win my export contract, 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({ - isUsingAgent: true, - agentIsCharging: true, - agentChargeMethodPercentage: true, - }); - - checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; - - cy.assertUrl(checkYourAnswersUrl); - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - describe(PERCENTAGE_CHARGE, () => { - const fieldId = PERCENTAGE_CHARGE; - - describe('when clicking the `change` link', () => { - it(`should redirect to ${AGENT_CHARGES_CHANGE}`, () => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(fieldId).changeLink().click(); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: AGENT_CHARGES_CHANGE, fieldId }); - }); - }); - - describe('form submission with a new answer', () => { - beforeEach(() => { - cy.navigateToUrl(checkYourAnswersUrl); - }); - - it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => { - summaryList.field(fieldId).changeLink().click(); - - cy.completeAndSubmitAgentChargesForm({ fixedSumMethod: true }); - - cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS, fieldId }); - }); - - it(`should render only ${FIXED_SUM_AMOUNT} and ${PAYABLE_COUNTRY_CODE} fields/values`, () => { - checkSummaryList[PERCENTAGE_CHARGE]({ shouldRender: false }); - checkSummaryList[FIXED_SUM_AMOUNT]({ shouldRender: true }); - checkSummaryList[PAYABLE_COUNTRY_CODE]({ shouldRender: true }); - }); - - describe(`when going back to ${AGENT_CHARGES_CHANGE}`, () => { - it('should have empty field `fixed sum` values', () => { - summaryList.field(FIXED_SUM_AMOUNT).changeLink().click(); - - cy.assertAgentChargesFieldValues({ - fixedSumMethod: true, - }); - }); - }); - }); - }); - }, -); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-no-to-yes.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-no-to-yes.spec.js index b59a654fa6..4be92d312a 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-no-to-yes.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-no-to-yes.spec.js @@ -10,7 +10,7 @@ const { const { AGENT_SERVICE: { IS_CHARGING: FIELD_ID }, - AGENT_CHARGES: { PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE }, + AGENT_CHARGES: { FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE }, } = FIELD_IDS; const baseUrl = Cypress.config('baseUrl'); @@ -62,7 +62,7 @@ context( cy.navigateToUrl(checkYourAnswersUrl); }); - it(`should redirect to ${AGENT_CHARGES_CHANGE} and then ${CHECK_YOUR_ANSWERS} after completing (now required) ${AGENT_CHARGES_CHANGE} fields`, () => { + it(`should redirect to ${AGENT_SERVICE_CHANGE} and then ${CHECK_YOUR_ANSWERS} after completing (now required) agent charges related forms`, () => { summaryList.field(FIELD_ID).changeLink().click(); cy.completeAndSubmitAgentServiceForm({ @@ -77,15 +77,17 @@ context( percentageMethod: false, }); + cy.completeAndSubmitAlternativeCurrencyForm({}); + + cy.completeAndSubmitHowMuchTheAgentIsChargingForm({}); + cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS, fieldId: FIELD_ID }); }); it(`should render new ${FIELD_ID} answer and other agent charges fields`, () => { checkSummaryList[FIELD_ID]({ shouldRender: true, isYes: true }); - - // checkSummaryList[FIXED_SUM_AMOUNT]({ shouldRender: true }); - - checkSummaryList[PERCENTAGE_CHARGE]({ shouldRender: true }); + checkSummaryList[FIXED_SUM_AMOUNT]({ shouldRender: true }); + checkSummaryList[PERCENTAGE_CHARGE]({ shouldRender: false }); checkSummaryList[PAYABLE_COUNTRY_CODE]({ shouldRender: true }); }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-yes-to-no.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-yes-to-no.spec.js index cb9fcbba44..598996f93f 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-yes-to-no.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/change-your-answers/agent-service/change-your-answers-agent-service-charging-yes-to-no.spec.js @@ -1,18 +1,22 @@ -import { autoCompleteField, field, summaryList } from '../../../../../../../pages/shared'; +import { autoCompleteField, field, radios, summaryList } from '../../../../../../../pages/shared'; import { agentChargesPage } from '../../../../../../../pages/insurance/export-contract'; import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; -import FIELD_IDS from '../../../../../../../constants/field-ids/insurance/export-contract'; +import { INSURANCE_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance'; import checkSummaryList from '../../../../../../../commands/insurance/check-export-contract-summary-list'; +import { GBP } from '../../../../../../../fixtures/currencies'; const { ROOT, - EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS, AGENT_SERVICE_CHANGE, AGENT_CHARGES }, + EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS, AGENT_SERVICE_CHANGE, AGENT_CHARGES, AGENT_CHARGES_CURRENCY, HOW_MUCH_THE_AGENT_IS_CHARGING }, } = INSURANCE_ROUTES; const { - AGENT_SERVICE: { IS_CHARGING: FIELD_ID }, - AGENT_CHARGES: { FIXED_SUM, FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, METHOD, PAYABLE_COUNTRY_CODE, PERCENTAGE }, -} = FIELD_IDS; + CURRENCY: { CURRENCY_CODE }, + EXPORT_CONTRACT: { + AGENT_SERVICE: { IS_CHARGING: FIELD_ID }, + AGENT_CHARGES: { FIXED_SUM, FIXED_SUM_AMOUNT, PERCENTAGE_CHARGE, METHOD, PAYABLE_COUNTRY_CODE, PERCENTAGE }, + }, +} = INSURANCE_FIELD_IDS; const baseUrl = Cypress.config('baseUrl'); @@ -79,21 +83,35 @@ context( checkSummaryList[PAYABLE_COUNTRY_CODE]({ shouldRender: false }); }); - describe(`when changing the answer again from no to yes and going back to ${AGENT_CHARGES}`, () => { - it('should have an empty values', () => { + describe(`when changing the answer again from no to yes and going back to ${AGENT_CHARGES}, ${AGENT_CHARGES_CURRENCY} and ${HOW_MUCH_THE_AGENT_IS_CHARGING}`, () => { + it('should have empty field values', () => { summaryList.field(FIELD_ID).changeLink().click(); cy.completeAndSubmitAgentServiceForm({ agentIsCharging: true, }); + // assert AGENT_CHARGES field values. cy.assertRadioOptionIsNotChecked(agentChargesPage[METHOD][FIXED_SUM].input()); cy.assertRadioOptionIsNotChecked(agentChargesPage[METHOD][PERCENTAGE].input()); - cy.checkValue(field(FIXED_SUM_AMOUNT), ''); - cy.checkValue(field(PERCENTAGE_CHARGE), ''); cy.checkValue(autoCompleteField(PAYABLE_COUNTRY_CODE), ''); + + cy.completeAndSubmitAgentChargesForm({ fixedSumMethod: true }); + + /** + * Assert AGENT_CHARGES_CURRENCY field values. + * GBP radio option should be checked by default. + */ + const { option } = radios(CURRENCY_CODE, GBP.isoCode); + + cy.assertRadioOptionIsChecked(option.input()); + + cy.completeAndSubmitAlternativeCurrencyForm({}); + + // assert HOW_MUCH_THE_AGENT_IS_CHARGING field values. + cy.checkValue(field(FIXED_SUM_AMOUNT), ''); }); }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/currency-of-agent-charges/currency-of-agent-charges.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/currency-of-agent-charges/currency-of-agent-charges.spec.js index 71096192ca..a22fac7c42 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/currency-of-agent-charges/currency-of-agent-charges.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/currency-of-agent-charges/currency-of-agent-charges.spec.js @@ -81,7 +81,7 @@ context( const { rendering, formSubmission } = assertCurrencyFormFields({ gbpCurrencyCheckedByDefault: true, errors: CURRENCY_ERROR_MESSAGES, - expectedRedirectUrl: AGENT_CHARGES, + expectedRedirectUrl: HOW_MUCH_THE_AGENT_IS_CHARGING, }); rendering(); @@ -91,10 +91,18 @@ context( describe('form submission', () => { it(`should redirect to ${HOW_MUCH_THE_AGENT_IS_CHARGING}`, () => { + cy.navigateToUrl(url); + cy.completeAndSubmitAlternativeCurrencyForm({}); cy.assertUrl(howMuchAgentIsChargingUrl); }); + + it('should retain the status of task `export contract` as `in progress`', () => { + cy.navigateToAllSectionsUrl(referenceNumber); + + cy.checkTaskExportContractStatusIsInProgress(); + }); }); }, ); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/how-much-the-agent-is-charging/how-much-the-agent-is-charging.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/how-much-the-agent-is-charging/how-much-the-agent-is-charging.spec.js index 0d0066bc56..faaf3c80d9 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/how-much-the-agent-is-charging/how-much-the-agent-is-charging.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/how-much-the-agent-is-charging/how-much-the-agent-is-charging.spec.js @@ -87,6 +87,12 @@ context( cy.assertUrl(checkYourAnswersUrl); }); + it('should update the `export contract` task status to `completed`', () => { + cy.navigateToAllSectionsUrl(referenceNumber); + + cy.checkTaskExportContractStatusIsComplete(); + }); + describe('when going back to the page', () => { beforeEach(() => { cy.navigateToUrl(url); diff --git a/src/ui/server/controllers/insurance/export-contract/agent-charges/index.test.ts b/src/ui/server/controllers/insurance/export-contract/agent-charges/index.test.ts index 666185fc5e..b6c16ea2c8 100644 --- a/src/ui/server/controllers/insurance/export-contract/agent-charges/index.test.ts +++ b/src/ui/server/controllers/insurance/export-contract/agent-charges/index.test.ts @@ -1,5 +1,5 @@ import { pageVariables, FIELD_IDS, PAGE_CONTENT_STRINGS, TEMPLATE, get, post } from '.'; -import { TEMPLATES } from '../../../../constants'; +import { APPLICATION, TEMPLATES } from '../../../../constants'; import { PARTIALS as PARTIAL_TEMPLATES } from '../../../../constants/templates/partials'; import { INSURANCE_ROUTES } from '../../../../constants/routes/insurance'; import EXPORT_CONTRACT_FIELD_IDS from '../../../../constants/field-ids/insurance/export-contract'; @@ -28,17 +28,33 @@ import { referenceNumber, } from '../../../../test-mocks'; +const { + EXPORT_CONTRACT: { + AGENT_SERVICE_CHARGE: { + METHOD: { FIXED_SUM: METHOD_FIXED_SUM, PERCENTAGE: METHOD_PERCENTAGE }, + }, + }, +} = APPLICATION; + const { supportedCurrencies } = mockCurrenciesResponse; const { INSURANCE_ROOT, PROBLEM_WITH_SERVICE, - EXPORT_CONTRACT: { AGENT_CHARGES_CHECK_AND_CHANGE, AGENT_CHARGES_SAVE_AND_BACK, AGENT_CHARGES_CURRENCY }, + EXPORT_CONTRACT: { + AGENT_CHARGES_CHECK_AND_CHANGE, + AGENT_CHARGES_SAVE_AND_BACK, + AGENT_CHARGES_CURRENCY, + AGENT_CHARGES_CHANGE, + AGENT_CHARGES_CURRENCY_CHANGE, + AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE, + CHECK_YOUR_ANSWERS, + }, CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT: CHECK_AND_CHANGE_ROUTE }, } = INSURANCE_ROUTES; const { - AGENT_CHARGES: { METHOD, PAYABLE_COUNTRY_CODE, FIXED_SUM, FIXED_SUM_CURRENCY_CODE, PERCENTAGE, PERCENTAGE_CHARGE }, + AGENT_CHARGES: { METHOD, PAYABLE_COUNTRY_CODE, FIXED_SUM, FIXED_SUM_CURRENCY_CODE, FIXED_SUM_AMOUNT, PERCENTAGE, PERCENTAGE_CHARGE }, } = EXPORT_CONTRACT_FIELD_IDS; const { @@ -236,6 +252,17 @@ describe('controllers/insurance/export-contract/agent-charges', () => { [PAYABLE_COUNTRY_CODE]: mockExportContractAgentServiceCharge[PAYABLE_COUNTRY_CODE], }; + const validBodyFixedSumMethod = { + ...validBody, + [METHOD]: METHOD_FIXED_SUM, + }; + + const validBodyPercentageMethod = { + ...validBody, + [METHOD]: METHOD_PERCENTAGE, + [PERCENTAGE_CHARGE]: mockExportContractAgentServiceCharge[PERCENTAGE_CHARGE], + }; + beforeEach(() => { getCountriesSpy = jest.fn(() => Promise.resolve(mockCountries)); getCurrenciesSpy = jest.fn(() => Promise.resolve(mockCurrenciesResponse)); @@ -356,17 +383,81 @@ describe('controllers/insurance/export-contract/agent-charges', () => { expect(mapAndSave.exportContractAgentServiceCharge).toHaveBeenCalledWith(payload, res.locals.application); }); - it(`should redirect to ${AGENT_CHARGES_CURRENCY}`, async () => { - await post(req, res); + describe(`when ${METHOD} is ${METHOD_FIXED_SUM}`, () => { + it(`should redirect to ${AGENT_CHARGES_CURRENCY}`, async () => { + req.body = validBodyFixedSumMethod; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${AGENT_CHARGES_CURRENCY}`; + + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); + + describe(`when ${METHOD} is ${METHOD_PERCENTAGE}`, () => { + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, async () => { + req.body = validBodyPercentageMethod; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; + + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); + + describe(`when ${METHOD} is ${METHOD_FIXED_SUM}, no ${FIXED_SUM_AMOUNT} available and the url's last substring is 'change'`, () => { + it(`should redirect to ${AGENT_CHARGES_CURRENCY_CHANGE}`, async () => { + res.locals.application = mockApplication; + res.locals.application.exportContract.agent.service.charge.fixedSumAmount = ''; - const expected = `${INSURANCE_ROOT}/${referenceNumber}${AGENT_CHARGES_CURRENCY}`; + req.body = validBodyFixedSumMethod; - expect(res.redirect).toHaveBeenCalledWith(expected); + req.originalUrl = AGENT_CHARGES_CHANGE; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${AGENT_CHARGES_CURRENCY_CHANGE}`; + + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); + + describe(`when ${METHOD} is ${METHOD_PERCENTAGE} and the url's last substring is 'change'`, () => { + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, async () => { + req.body = validBodyPercentageMethod; + + req.originalUrl = AGENT_CHARGES_CHANGE; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; + + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); + + describe(`when ${METHOD} is ${METHOD_FIXED_SUM}, no ${FIXED_SUM_AMOUNT} available and the url's last substring is 'check-and-change'`, () => { + it(`should redirect to ${AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE}`, async () => { + res.locals.application = mockApplication; + res.locals.application.exportContract.agent.service.charge.fixedSumAmount = ''; + + req.body = validBodyFixedSumMethod; + + req.originalUrl = AGENT_CHARGES_CHECK_AND_CHANGE; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE}`; + + expect(res.redirect).toHaveBeenCalledWith(expected); + }); }); - describe("when the url's last substring is `check-and-change`", () => { + describe(`when ${METHOD} is ${METHOD_PERCENTAGE} and the url's last substring is 'check-and-change'`, () => { it(`should redirect to ${CHECK_AND_CHANGE_ROUTE}`, async () => { - req.body = validBody; + req.body = validBodyPercentageMethod; req.originalUrl = AGENT_CHARGES_CHECK_AND_CHANGE; diff --git a/src/ui/server/controllers/insurance/export-contract/agent-charges/index.ts b/src/ui/server/controllers/insurance/export-contract/agent-charges/index.ts index e19b599914..ea5e65b8bc 100644 --- a/src/ui/server/controllers/insurance/export-contract/agent-charges/index.ts +++ b/src/ui/server/controllers/insurance/export-contract/agent-charges/index.ts @@ -15,6 +15,7 @@ import constructPayload from '../../../../helpers/construct-payload'; import generateValidationErrors from './validation'; import { sanitiseData } from '../../../../helpers/sanitise-data'; import mapAndSave from '../map-and-save/export-contract-agent-service-charge'; +import isChangeRoute from '../../../../helpers/is-change-route'; import isCheckAndChangeRoute from '../../../../helpers/is-check-and-change-route'; import { Currency, Request, Response } from '../../../../../types'; @@ -25,12 +26,18 @@ const { const { INSURANCE_ROOT, PROBLEM_WITH_SERVICE, - EXPORT_CONTRACT: { AGENT_CHARGES_SAVE_AND_BACK, AGENT_CHARGES_CURRENCY, CHECK_YOUR_ANSWERS }, + EXPORT_CONTRACT: { + AGENT_CHARGES_SAVE_AND_BACK, + AGENT_CHARGES_CURRENCY, + AGENT_CHARGES_CURRENCY_CHANGE, + AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE, + CHECK_YOUR_ANSWERS, + }, CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT: CHECK_AND_CHANGE_ROUTE }, } = INSURANCE_ROUTES; const { - AGENT_CHARGES: { METHOD, PAYABLE_COUNTRY_CODE, FIXED_SUM, FIXED_SUM_CURRENCY_CODE, PERCENTAGE, PERCENTAGE_CHARGE }, + AGENT_CHARGES: { METHOD, PAYABLE_COUNTRY_CODE, FIXED_SUM, FIXED_SUM_AMOUNT, FIXED_SUM_CURRENCY_CODE, PERCENTAGE, PERCENTAGE_CHARGE }, } = EXPORT_CONTRACT_FIELD_IDS; const { @@ -190,17 +197,34 @@ export const post = async (req: Request, res: Response) => { return res.redirect(PROBLEM_WITH_SERVICE); } + const isFixedSumMethod = payload[METHOD] === AGENT_SERVICE_CHARGE.METHOD.FIXED_SUM; + const hasFixedSumAmount = agent.service.charge[FIXED_SUM_AMOUNT]; + + /** + * If the route is a "change" route, + * the agent charges are FIXED_SUM METHOD, + * and no FIXED_SUM_AMOUNT is available, + * redirect to AGENT_CHARGES_CURRENCY_CHANGE form. + */ + if (isChangeRoute(req.originalUrl) && isFixedSumMethod && !hasFixedSumAmount) { + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${AGENT_CHARGES_CURRENCY_CHANGE}`); + } + /** * If the route is a "check and change" route, - * redirect to CHECK_AND_CHANGE_ROUTE. - * Otherwise, redirect to CHECK_YOUR_ANSWERS. + * the agent charges are FIXED_SUM METHOD, + * and no FIXED_SUM_AMOUNT is available, + * redirect to AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE. + * Otherwise, redirect to CHECK_AND_CHANGE_ROUTE. */ if (isCheckAndChangeRoute(req.originalUrl)) { + if (isFixedSumMethod && !hasFixedSumAmount) { + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE}`); + } + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${CHECK_AND_CHANGE_ROUTE}`); } - const isFixedSumMethod = payload[METHOD] === AGENT_SERVICE_CHARGE.METHOD.FIXED_SUM; - /** * If the agent charges are FIXED_SUM METHOD, * redirect to AGENT_CHARGES_CURRENCY form. diff --git a/src/ui/server/controllers/insurance/export-contract/currency-of-agents-charge/index.test.ts b/src/ui/server/controllers/insurance/export-contract/currency-of-agents-charge/index.test.ts index eecc64599d..880ce833ea 100644 --- a/src/ui/server/controllers/insurance/export-contract/currency-of-agents-charge/index.test.ts +++ b/src/ui/server/controllers/insurance/export-contract/currency-of-agents-charge/index.test.ts @@ -26,13 +26,22 @@ import { const { INSURANCE_ROOT, PROBLEM_WITH_SERVICE, - EXPORT_CONTRACT: { AGENT_CHARGES_CURRENCY_SAVE_AND_BACK, HOW_MUCH_THE_AGENT_IS_CHARGING }, + EXPORT_CONTRACT: { + AGENT_CHARGES_CURRENCY_SAVE_AND_BACK, + AGENT_CHARGES_CURRENCY_CHANGE, + AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE, + HOW_MUCH_THE_AGENT_IS_CHARGING, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE, + CHECK_YOUR_ANSWERS, + }, + CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT: CHECK_AND_CHANGE_ROUTE }, } = INSURANCE_ROUTES; const { CURRENCY: { CURRENCY_CODE, ALTERNATIVE_CURRENCY_CODE }, EXPORT_CONTRACT: { - AGENT_CHARGES: { FIXED_SUM_CURRENCY_CODE }, + AGENT_CHARGES: { FIXED_SUM_CURRENCY_CODE, FIXED_SUM_AMOUNT }, }, } = INSURANCE_FIELD_IDS; @@ -257,6 +266,70 @@ describe('controllers/insurance/export-contract/currency-of-agents-charge', () = expect(mapAndSave.exportContractAgentServiceCharge).toHaveBeenCalledWith(payload, res.locals.application); }); + describe("when the url's last substring is 'change'", () => { + beforeEach(() => { + req.originalUrl = AGENT_CHARGES_CURRENCY_CHANGE; + }); + + describe(`when the application/agent data does NOT have a ${FIXED_SUM_AMOUNT} value`, () => { + it(`should redirect to ${HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE}`, async () => { + res.locals.application = mockApplication; + res.locals.application.exportContract.agent.service.charge.fixedSumAmount = ''; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE}`; + + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); + + describe(`when the application/agent data has a ${FIXED_SUM_AMOUNT} value`, () => { + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, async () => { + res.locals.application = mockApplication; + res.locals.application.exportContract.agent.service.charge.fixedSumAmount = '123'; + + 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'", () => { + beforeEach(() => { + req.originalUrl = AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE; + }); + + describe(`when the application/agent data does NOT have a ${FIXED_SUM_AMOUNT} value`, () => { + it(`should redirect to ${HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE}`, async () => { + res.locals.application = mockApplication; + res.locals.application.exportContract.agent.service.charge.fixedSumAmount = ''; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE}`; + + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); + + describe(`when the application/agent data has a ${FIXED_SUM_AMOUNT} value`, () => { + it(`should redirect to ${CHECK_AND_CHANGE_ROUTE}`, async () => { + res.locals.application = mockApplication; + res.locals.application.exportContract.agent.service.charge.fixedSumAmount = '123'; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${CHECK_AND_CHANGE_ROUTE}`; + + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); + }); + it(`should redirect to ${HOW_MUCH_THE_AGENT_IS_CHARGING}`, async () => { await post(req, res); diff --git a/src/ui/server/controllers/insurance/export-contract/currency-of-agents-charge/index.ts b/src/ui/server/controllers/insurance/export-contract/currency-of-agents-charge/index.ts index 5672ecfa56..8aea8e0f22 100644 --- a/src/ui/server/controllers/insurance/export-contract/currency-of-agents-charge/index.ts +++ b/src/ui/server/controllers/insurance/export-contract/currency-of-agents-charge/index.ts @@ -11,18 +11,27 @@ import mapRadioAndSelectOptions from '../../../../helpers/mappings/map-currencie import constructPayload from '../../../../helpers/construct-payload'; import generateValidationErrors from './validation'; import mapAndSave from '../map-and-save/export-contract-agent-service-charge'; +import isChangeRoute from '../../../../helpers/is-change-route'; +import isCheckAndChangeRoute from '../../../../helpers/is-check-and-change-route'; import { Request, Response } from '../../../../../types'; const { INSURANCE_ROOT, PROBLEM_WITH_SERVICE, - EXPORT_CONTRACT: { HOW_MUCH_THE_AGENT_IS_CHARGING, AGENT_CHARGES_CURRENCY_SAVE_AND_BACK }, + EXPORT_CONTRACT: { + HOW_MUCH_THE_AGENT_IS_CHARGING, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE, + AGENT_CHARGES_CURRENCY_SAVE_AND_BACK, + CHECK_YOUR_ANSWERS, + }, + CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT: CHECK_AND_CHANGE_ROUTE }, } = INSURANCE_ROUTES; const { CURRENCY: { CURRENCY_CODE, ALTERNATIVE_CURRENCY_CODE }, EXPORT_CONTRACT: { - AGENT_CHARGES: { FIXED_SUM_CURRENCY_CODE }, + AGENT_CHARGES: { FIXED_SUM_CURRENCY_CODE, FIXED_SUM_AMOUNT }, }, } = INSURANCE_FIELD_IDS; @@ -109,7 +118,10 @@ export const post = async (req: Request, res: Response) => { return res.redirect(PROBLEM_WITH_SERVICE); } - const { referenceNumber } = application; + const { + exportContract: { agent }, + referenceNumber, + } = application; const payload = constructPayload(req.body, FIELD_IDS); @@ -147,6 +159,39 @@ export const post = async (req: Request, res: Response) => { return res.redirect(PROBLEM_WITH_SERVICE); } + const hasFixedSumAmount = agent.service.charge[FIXED_SUM_AMOUNT]; + + if (isChangeRoute(req.originalUrl)) { + /** + * If the URL is a "change" route, + * and there is no FIXED_SUM_AMOUNT, + * redirect to HOW_MUCH_THE_AGENT_IS_CHARGING with /change in URL. + * This ensures that the next page can consume /change in the URL + * and therefore correctly redirect on submission. + */ + + if (!hasFixedSumAmount) { + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE}`); + } + + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`); + } + + if (isCheckAndChangeRoute(req.originalUrl)) { + /** + * If the URL is a "check and change" route, + * and there is no FIXED_SUM_AMOUNT, + * redirect to HOW_MUCH_THE_AGENT_IS_CHARGING with /check-and-change in URL. + * This ensures that the next page can consume /change in the URL + * and therefore correctly redirect on submission. + */ + if (!hasFixedSumAmount) { + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE}`); + } + + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${CHECK_AND_CHANGE_ROUTE}`); + } + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${HOW_MUCH_THE_AGENT_IS_CHARGING}`); } catch (error) { console.error('Error updating application - export contract - currency of agents charge %O', error); diff --git a/src/ui/server/controllers/insurance/export-contract/how-much-the-agent-is-charging/index.test.ts b/src/ui/server/controllers/insurance/export-contract/how-much-the-agent-is-charging/index.test.ts index a21ef655cc..76cf04ad8b 100644 --- a/src/ui/server/controllers/insurance/export-contract/how-much-the-agent-is-charging/index.test.ts +++ b/src/ui/server/controllers/insurance/export-contract/how-much-the-agent-is-charging/index.test.ts @@ -19,7 +19,8 @@ import { mockApplicationMultiplePolicy as mockApplication } from '../../../../te const { INSURANCE_ROOT, - EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS, HOW_MUCH_THE_AGENT_IS_CHARGING_SAVE_AND_BACK }, + EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS, HOW_MUCH_THE_AGENT_IS_CHARGING_SAVE_AND_BACK, HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE }, + CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT: CHECK_AND_CHANGE_ROUTE }, PROBLEM_WITH_SERVICE, } = INSURANCE_ROUTES; @@ -207,6 +208,18 @@ describe('controllers/insurance/export-contract/how-much-the-agent-is-charging', expect(mapAndSave.exportContractAgentServiceCharge).toHaveBeenCalledWith(payload, res.locals.application); }); + describe("when the url's last substring is 'check-and-change'", () => { + it(`should redirect to ${CHECK_AND_CHANGE_ROUTE}`, async () => { + req.originalUrl = HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${CHECK_AND_CHANGE_ROUTE}`; + + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, async () => { await post(req, res); diff --git a/src/ui/server/controllers/insurance/export-contract/how-much-the-agent-is-charging/index.ts b/src/ui/server/controllers/insurance/export-contract/how-much-the-agent-is-charging/index.ts index d84e1f2664..3b83cc4ffa 100644 --- a/src/ui/server/controllers/insurance/export-contract/how-much-the-agent-is-charging/index.ts +++ b/src/ui/server/controllers/insurance/export-contract/how-much-the-agent-is-charging/index.ts @@ -13,11 +13,13 @@ import constructPayload from '../../../../helpers/construct-payload'; import generateValidationErrors from './validation'; import { sanitiseData } from '../../../../helpers/sanitise-data'; import mapAndSave from '../map-and-save/export-contract-agent-service-charge'; +import isCheckAndChangeRoute from '../../../../helpers/is-check-and-change-route'; import { Currency, Request, Response } from '../../../../../types'; const { INSURANCE_ROOT, EXPORT_CONTRACT: { CHECK_YOUR_ANSWERS, HOW_MUCH_THE_AGENT_IS_CHARGING_SAVE_AND_BACK }, + CHECK_YOUR_ANSWERS: { EXPORT_CONTRACT: CHECK_AND_CHANGE_ROUTE }, PROBLEM_WITH_SERVICE, } = INSURANCE_ROUTES; @@ -179,6 +181,10 @@ export const post = async (req: Request, res: Response) => { return res.redirect(PROBLEM_WITH_SERVICE); } + if (isCheckAndChangeRoute(req.originalUrl)) { + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${CHECK_AND_CHANGE_ROUTE}`); + } + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`); } catch (error) { console.error('Error updating application - export contract - how much the agent is charging %O', error); diff --git a/src/ui/server/controllers/insurance/your-buyer/failed-to-pay-on-time/index.test.ts b/src/ui/server/controllers/insurance/your-buyer/failed-to-pay-on-time/index.test.ts index 41f472b377..63f9071bc9 100644 --- a/src/ui/server/controllers/insurance/your-buyer/failed-to-pay-on-time/index.test.ts +++ b/src/ui/server/controllers/insurance/your-buyer/failed-to-pay-on-time/index.test.ts @@ -165,7 +165,7 @@ describe('controllers/insurance/your-buyer/failed-to-pay-on-time', () => { expect(mapAndSave.buyerTradingHistory).toHaveBeenCalledWith(payload, mockApplication); }); - describe(`when the url's last substring is 'change'`, () => { + describe("when the url's last substring is 'change'", () => { it(`should redirect to ${CHECK_YOUR_ANSWERS}`, async () => { req.body = { [FIELD_ID]: 'false', @@ -181,7 +181,7 @@ describe('controllers/insurance/your-buyer/failed-to-pay-on-time', () => { }); }); - describe(`when the url's last substring is 'check-and-change'`, () => { + describe("when the url's last substring is 'check-and-change'", () => { it(`should redirect to ${CHECK_AND_CHANGE_ROUTE}`, async () => { req.body = { [FIELD_ID]: 'true', @@ -197,7 +197,7 @@ describe('controllers/insurance/your-buyer/failed-to-pay-on-time', () => { }); }); - describe(`when the totalContractValueOverThreshold=true`, () => { + describe(`when totalContractValueOverThreshold=true`, () => { it(`should redirect to ${CREDIT_INSURANCE_COVER}`, async () => { req.body = { [FIELD_ID]: 'false', diff --git a/src/ui/server/controllers/insurance/your-buyer/traded-with-buyer/index.test.ts b/src/ui/server/controllers/insurance/your-buyer/traded-with-buyer/index.test.ts index 75b47758cb..f4ca09740c 100644 --- a/src/ui/server/controllers/insurance/your-buyer/traded-with-buyer/index.test.ts +++ b/src/ui/server/controllers/insurance/your-buyer/traded-with-buyer/index.test.ts @@ -235,7 +235,7 @@ describe('controllers/insurance/your-buyer/traded-with-buyer', () => { }); }); - describe(`when the totalContractValueOverThreshold is true and ${TRADED_WITH_BUYER} is false`, () => { + describe(`when totalContractValueOverThreshold=true and ${TRADED_WITH_BUYER} is false`, () => { it(`should redirect to ${CREDIT_INSURANCE_COVER}`, async () => { req.body = { [TRADED_WITH_BUYER]: 'false', diff --git a/src/ui/server/helpers/summary-lists/export-contract/agent-fields/agent-charges/index.test.ts b/src/ui/server/helpers/summary-lists/export-contract/agent-fields/agent-charges/index.test.ts index 1854e6c23f..8414d764c7 100644 --- a/src/ui/server/helpers/summary-lists/export-contract/agent-fields/agent-charges/index.test.ts +++ b/src/ui/server/helpers/summary-lists/export-contract/agent-fields/agent-charges/index.test.ts @@ -27,6 +27,8 @@ const { AGENT_CHARGES_CHECK_AND_CHANGE, AGENT_SERVICE_CHANGE, AGENT_SERVICE_CHECK_AND_CHANGE, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE, } = EXPORT_CONTRACT_ROUTES; describe('server/helpers/summary-lists/export-contract/agent-fields/agent-charges', () => { @@ -106,7 +108,13 @@ describe('server/helpers/summary-lists/export-contract/agent-fields/agent-charge { field: getFieldById(FIELDS.AGENT_CHARGES, FIXED_SUM_AMOUNT), data: mockAnswers.charge, - href: generateChangeLink(AGENT_CHARGES_CHANGE, AGENT_CHARGES_CHECK_AND_CHANGE, `#${FIXED_SUM_AMOUNT}-label`, referenceNumber, checkAndChange), + href: generateChangeLink( + HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE, + `#${FIXED_SUM_AMOUNT}-label`, + referenceNumber, + checkAndChange, + ), renderChangeLink: true, }, formatCurrency(Number(fixedSumAnswer), mockAnswers.charge[FIXED_SUM_CURRENCY_CODE]), @@ -168,7 +176,13 @@ describe('server/helpers/summary-lists/export-contract/agent-fields/agent-charge { field: getFieldById(FIELDS.AGENT_CHARGES, FIXED_SUM_AMOUNT), data: mockAnswers.charge, - href: generateChangeLink(AGENT_CHARGES_CHANGE, AGENT_CHARGES_CHECK_AND_CHANGE, `#${FIXED_SUM_AMOUNT}-label`, referenceNumber, checkAndChange), + href: generateChangeLink( + HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE, + `#${FIXED_SUM_AMOUNT}-label`, + referenceNumber, + checkAndChange, + ), renderChangeLink: true, }, formatCurrency(Number(mockAnswers.charge[FIXED_SUM_AMOUNT]), mockAnswers.charge[FIXED_SUM_CURRENCY_CODE], 2), diff --git a/src/ui/server/helpers/summary-lists/export-contract/agent-fields/agent-charges/index.ts b/src/ui/server/helpers/summary-lists/export-contract/agent-fields/agent-charges/index.ts index 3f646556b2..711c862a01 100644 --- a/src/ui/server/helpers/summary-lists/export-contract/agent-fields/agent-charges/index.ts +++ b/src/ui/server/helpers/summary-lists/export-contract/agent-fields/agent-charges/index.ts @@ -26,6 +26,8 @@ const { AGENT_CHARGES_CHECK_AND_CHANGE, AGENT_SERVICE_CHANGE, AGENT_SERVICE_CHECK_AND_CHANGE, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE, } = EXPORT_CONTRACT_ROUTES; /** @@ -84,7 +86,13 @@ const agentChargesFields = (answers: ApplicationExportContractAgentService, refe { field: getFieldById(FIELDS.AGENT_CHARGES, FIXED_SUM_AMOUNT), data: answers.charge, - href: generateChangeLink(AGENT_CHARGES_CHANGE, AGENT_CHARGES_CHECK_AND_CHANGE, `#${FIXED_SUM_AMOUNT}-label`, referenceNumber, checkAndChange), + href: generateChangeLink( + HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE, + `#${FIXED_SUM_AMOUNT}-label`, + referenceNumber, + checkAndChange, + ), renderChangeLink: true, }, formatCurrency(Number(answer), answers.charge[FIXED_SUM_CURRENCY_CODE], decimalPlaces), 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 1ef5bbb207..896d0d1713 100644 --- a/src/ui/server/routes/insurance/export-contract/index.test.ts +++ b/src/ui/server/routes/insurance/export-contract/index.test.ts @@ -76,6 +76,8 @@ const { AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE, HOW_MUCH_THE_AGENT_IS_CHARGING, HOW_MUCH_THE_AGENT_IS_CHARGING_SAVE_AND_BACK, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE, CHECK_YOUR_ANSWERS, } = EXPORT_CONTRACT; @@ -89,8 +91,8 @@ describe('routes/insurance/export-contract', () => { }); it('should setup all routes', () => { - expect(get).toHaveBeenCalledTimes(33); - expect(post).toHaveBeenCalledTimes(43); + expect(get).toHaveBeenCalledTimes(35); + expect(post).toHaveBeenCalledTimes(45); expect(get).toHaveBeenCalledWith(`/:referenceNumber${ROOT}`, exportContractRootGet); @@ -176,6 +178,10 @@ describe('routes/insurance/export-contract', () => { expect(get).toHaveBeenCalledWith(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING}`, howMuchTheAgentIsChargingGet); expect(post).toHaveBeenCalledWith(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING}`, howMuchTheAgentIsChargingPost); expect(post).toHaveBeenCalledWith(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING_SAVE_AND_BACK}`, howMuchTheAgentIsChargingSaveAndBackPost); + expect(get).toHaveBeenCalledWith(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE}`, howMuchTheAgentIsChargingGet); + expect(post).toHaveBeenCalledWith(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE}`, howMuchTheAgentIsChargingPost); + expect(get).toHaveBeenCalledWith(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE}`, howMuchTheAgentIsChargingGet); + expect(post).toHaveBeenCalledWith(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE}`, howMuchTheAgentIsChargingPost); expect(get).toHaveBeenCalledWith(`/:referenceNumber${CHECK_YOUR_ANSWERS}`, checkYourAnswersGet); expect(post).toHaveBeenCalledWith(`/:referenceNumber${CHECK_YOUR_ANSWERS}`, checkYourAnswersPost); diff --git a/src/ui/server/routes/insurance/export-contract/index.ts b/src/ui/server/routes/insurance/export-contract/index.ts index 0d7e3f3675..35d3082a85 100644 --- a/src/ui/server/routes/insurance/export-contract/index.ts +++ b/src/ui/server/routes/insurance/export-contract/index.ts @@ -78,6 +78,8 @@ const { AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE, HOW_MUCH_THE_AGENT_IS_CHARGING, HOW_MUCH_THE_AGENT_IS_CHARGING_SAVE_AND_BACK, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE, + HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE, CHECK_YOUR_ANSWERS, } = EXPORT_CONTRACT; @@ -161,18 +163,19 @@ exportContractRoute.post(`/:referenceNumber${AGENT_CHARGES_CHECK_AND_CHANGE}`, a exportContractRoute.get(`/:referenceNumber${AGENT_CHARGES_CURRENCY}`, agentChargesCurrencyGet); exportContractRoute.post(`/:referenceNumber${AGENT_CHARGES_CURRENCY}`, agentChargesCurrencyPost); - exportContractRoute.post(`/:referenceNumber${AGENT_CHARGES_CURRENCY_SAVE_AND_BACK}`, agentChargesCurrencySaveAndBackPost); - exportContractRoute.get(`/:referenceNumber${AGENT_CHARGES_CURRENCY_CHANGE}`, agentChargesCurrencyGet); exportContractRoute.post(`/:referenceNumber${AGENT_CHARGES_CURRENCY_CHANGE}`, agentChargesCurrencyPost); - exportContractRoute.get(`/:referenceNumber${AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE}`, agentChargesCurrencyGet); exportContractRoute.post(`/:referenceNumber${AGENT_CHARGES_CURRENCY_CHECK_AND_CHANGE}`, agentChargesCurrencyPost); exportContractRoute.get(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING}`, howMuchTheAgentIsChargingGet); exportContractRoute.post(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING}`, howMuchTheAgentIsChargingPost); exportContractRoute.post(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING_SAVE_AND_BACK}`, howMuchTheAgentIsChargingSaveAndBackPost); +exportContractRoute.get(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE}`, howMuchTheAgentIsChargingGet); +exportContractRoute.post(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING_CHANGE}`, howMuchTheAgentIsChargingPost); +exportContractRoute.get(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE}`, howMuchTheAgentIsChargingGet); +exportContractRoute.post(`/:referenceNumber${HOW_MUCH_THE_AGENT_IS_CHARGING_CHECK_AND_CHANGE}`, howMuchTheAgentIsChargingPost); exportContractRoute.get(`/:referenceNumber${CHECK_YOUR_ANSWERS}`, checkYourAnswersGet); exportContractRoute.post(`/:referenceNumber${CHECK_YOUR_ANSWERS}`, checkYourAnswersPost); diff --git a/src/ui/server/routes/insurance/index.test.ts b/src/ui/server/routes/insurance/index.test.ts index b89933d63b..e0d0c59b29 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(216); - expect(post).toHaveBeenCalledTimes(226); + expect(get).toHaveBeenCalledTimes(218); + expect(post).toHaveBeenCalledTimes(228); expect(get).toHaveBeenCalledWith(INSURANCE_ROUTES.START, startGet);