diff --git a/e2e-tests/commands/insurance/check-policy-summary-list.js b/e2e-tests/commands/insurance/check-policy-summary-list.js index 9c3010bfde..ecb5b238b5 100644 --- a/e2e-tests/commands/insurance/check-policy-summary-list.js +++ b/e2e-tests/commands/insurance/check-policy-summary-list.js @@ -28,6 +28,8 @@ const { NAME_ON_POLICY: { NAME, POSITION }, USING_BROKER, BROKER_DETAILS, + BROKER_ADDRESSES, + BROKER_MANUAL_ADDRESS, REQUESTED_JOINTLY_INSURED_PARTY: { REQUESTED, COMPANY_NAME, COMPANY_NUMBER, COUNTRY_CODE }, LOSS_PAYEE: { IS_APPOINTED: LOSS_PAYEE_IS_APPOINTED }, LOSS_PAYEE_DETAILS: { NAME: LOSS_PAYEE_NAME }, @@ -231,22 +233,30 @@ const checkPolicySummaryList = { cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue, expectedChangeLinkText); }, - // TODO: EMS-4011 - // [BROKER_DETAILS.FULL_ADDRESS]: () => { - // const fieldId = BROKER_DETAILS.FULL_ADDRESS; + [BROKER_ADDRESSES.SELECT_THE_ADDRESS]: () => { + const fieldId = BROKER_ADDRESSES.SELECT_THE_ADDRESS; - // const expectedKey = FIELDS.BROKER_DETAILS[fieldId].SUMMARY.TITLE; + const expectedKey = FIELDS.BROKER_ADDRESSES[fieldId].SUMMARY.TITLE; - // const row = summaryList.field(fieldId); + const row = summaryList.field(fieldId); - // cy.checkText(row.key(), expectedKey); + cy.checkText(row.key(), expectedKey); - // row.value().contains(EXPECTED_SINGLE_LINE_STRING); + row.value().contains(EXPECTED_SINGLE_LINE_STRING); - // const expectedLineBreaks = 3; + const expectedLineBreaks = 3; - // cy.assertLength(row.valueHtmlLineBreak(), expectedLineBreaks); - // }, + cy.assertLength(row.valueHtmlLineBreak(), expectedLineBreaks); + }, + [BROKER_MANUAL_ADDRESS.FULL_ADDRESS]: () => { + const fieldId = BROKER_MANUAL_ADDRESS.FULL_ADDRESS; + + const { expectedKey, expectedChangeLinkText } = getSummaryListField(fieldId, FIELDS.BROKER_MANUAL_ADDRESS); + + const expectedValue = application.BROKER[fieldId]; + + cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue, expectedChangeLinkText); + }, [BROKER_DETAILS.EMAIL]: () => { const fieldId = BROKER_DETAILS.NAME; diff --git a/e2e-tests/constants/routes/insurance/policy/broker.js b/e2e-tests/constants/routes/insurance/policy/broker.js index 38e8eb1860..edebb40d89 100644 --- a/e2e-tests/constants/routes/insurance/policy/broker.js +++ b/e2e-tests/constants/routes/insurance/policy/broker.js @@ -18,10 +18,14 @@ const BROKER_ROUTES = { BROKER_DETAILS_CHECK_AND_CHANGE: `${BROKER_DETAILS_ROOT}/check-and-change`, BROKER_ADDRESSES_ROOT, BROKER_ADDRESSES_SAVE_AND_BACK: `${BROKER_ADDRESSES_ROOT}/save-and-back`, + BROKER_ADDRESSES_CHANGE: `${BROKER_ADDRESSES_ROOT}/change`, + BROKER_ADDRESSES_CHECK_AND_CHANGE: `${BROKER_ADDRESSES_ROOT}/check-and-change`, BROKER_CONFIRM_ADDRESS_ROOT, BROKER_ZERO_ADDRESSES_ROOT, BROKER_MANUAL_ADDRESS_ROOT, BROKER_MANUAL_ADDRESS_SAVE_AND_BACK: `${BROKER_MANUAL_ADDRESS_ROOT}/save-and-back`, + BROKER_MANUAL_ADDRESS_CHANGE: `${BROKER_MANUAL_ADDRESS_ROOT}/change`, + BROKER_MANUAL_ADDRESS_CHECK_AND_CHANGE: `${BROKER_MANUAL_ADDRESS_ROOT}/check-and-change`, }; export default BROKER_ROUTES; diff --git a/e2e-tests/content-strings/fields/insurance/policy/index.js b/e2e-tests/content-strings/fields/insurance/policy/index.js index 539a2033aa..58938ed95b 100644 --- a/e2e-tests/content-strings/fields/insurance/policy/index.js +++ b/e2e-tests/content-strings/fields/insurance/policy/index.js @@ -286,6 +286,10 @@ export const POLICY_FIELDS = { BROKER_ADDRESSES: { [SELECT_THE_ADDRESS]: { LABEL: 'Select the address', + SUMMARY: { + TITLE: "Broker's address", + FORM_TITLE: POLICY_FORM_TITLES.BROKER, + }, }, }, BROKER_MANUAL_ADDRESS: { diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/policy/summary-list/multiple-policy/check-your-answers-policy-multiple-with-broker-summary-list.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/policy/summary-list/multiple-policy/check-your-answers-policy-multiple-with-broker-summary-list.spec.js index 382974b872..4b998d40f1 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/policy/summary-list/multiple-policy/check-your-answers-policy-multiple-with-broker-summary-list.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/policy/summary-list/multiple-policy/check-your-answers-policy-multiple-with-broker-summary-list.spec.js @@ -9,7 +9,8 @@ const { const { USING_BROKER, - BROKER_DETAILS: { NAME, EMAIL, FULL_ADDRESS }, + BROKER_DETAILS: { NAME, EMAIL }, + BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, } = POLICY_FIELD_IDS; const baseUrl = Cypress.config('baseUrl'); @@ -56,8 +57,7 @@ context('Insurance - Check your answers - Policy - Multiple contract policy - Wi checkSummaryList.BROKER[NAME]({}); }); - // TODO: EMS-4011 - it.skip(`should render a ${FULL_ADDRESS} summary list row`, () => { + it(`should render a ${FULL_ADDRESS} summary list row`, () => { checkSummaryList.BROKER[FULL_ADDRESS](); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/policy/summary-list/single-policy/check-your-answers-policy-single-with-broker-summary-list.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/policy/summary-list/single-policy/check-your-answers-policy-single-with-broker-summary-list.spec.js index 58141da486..4adbe7e6b8 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/policy/summary-list/single-policy/check-your-answers-policy-single-with-broker-summary-list.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/check-your-answers/policy/summary-list/single-policy/check-your-answers-policy-single-with-broker-summary-list.spec.js @@ -9,7 +9,8 @@ const { const { USING_BROKER, - BROKER_DETAILS: { NAME, EMAIL, FULL_ADDRESS }, + BROKER_DETAILS: { NAME, EMAIL }, + BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, } = POLICY_FIELD_IDS; const baseUrl = Cypress.config('baseUrl'); @@ -56,8 +57,7 @@ context('Insurance - Check your answers - Policy - Single contract policy - With checkSummaryList.BROKER[NAME]({}); }); - // TODO: EMS-3976 - it.skip(`should render a ${FULL_ADDRESS} summary list row`, () => { + it(`should render a ${FULL_ADDRESS} summary list row`, () => { checkSummaryList.BROKER[FULL_ADDRESS](); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/broker-manual-address-page.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/broker-manual-address-page.spec.js index e2558f5f8a..5de307161c 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/broker-manual-address-page.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/broker-manual-address-page.spec.js @@ -15,100 +15,100 @@ const { const { ROOT, - POLICY: { BROKER_MANUAL_ADDRESS_ROOT, LOSS_PAYEE_ROOT }, + POLICY: { BROKER_DETAILS_ROOT, BROKER_MANUAL_ADDRESS_ROOT, LOSS_PAYEE_ROOT }, } = INSURANCE_ROUTES; const { BROKER_MANUAL_ADDRESS: FIELD_STRINGS } = FIELDS; const baseUrl = Cypress.config('baseUrl'); -context('Insurance - Policy - Broker manual address page - As an exporter, ... TODO', () => { - let referenceNumber; - let url; - let lossPayeeUrl; +context( + "Insurance - Policy - Broker manual address page - As an exporter, I want to provide UKEF with my broker's details So that UKEF can communicate with the broker as needed whilst processing my application", + () => { + let referenceNumber; + let url; + let lossPayeeUrl; - before(() => { - cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { - referenceNumber = refNumber; + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; - // go to the page we want to test. - cy.completeAndSubmitPolicyForms({ stopSubmittingAfter: 'brokerDetails', usingBroker: true }); + // go to the page we want to test. + cy.completeAndSubmitPolicyForms({ stopSubmittingAfter: 'brokerDetails', usingBroker: true, isBasedInUk: false }); - url = `${baseUrl}${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`; - lossPayeeUrl = `${baseUrl}${ROOT}/${referenceNumber}${LOSS_PAYEE_ROOT}`; + url = `${baseUrl}${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`; + lossPayeeUrl = `${baseUrl}${ROOT}/${referenceNumber}${LOSS_PAYEE_ROOT}`; - // TODO: EMS-3973 - remove this - cy.navigateToUrl(url); - - cy.assertUrl(url); - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - it('renders core page elements', () => { - cy.corePageChecks({ - pageTitle: CONTENT_STRINGS.PAGE_TITLE, - currentHref: `${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`, - backLink: `${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}#`, + cy.assertUrl(url); + }); }); - }); - describe('page tests', () => { beforeEach(() => { - cy.navigateToUrl(url); + cy.saveSession(); }); - it('renders a heading caption', () => { - cy.checkText(headingCaption(), CONTENT_STRINGS.HEADING_CAPTION); + after(() => { + cy.deleteApplication(referenceNumber); }); - it('renders intro text', () => { - cy.checkIntroText(CONTENT_STRINGS.INTRO); + it('renders core page elements', () => { + cy.corePageChecks({ + pageTitle: CONTENT_STRINGS.PAGE_TITLE, + currentHref: `${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`, + backLink: `${ROOT}/${referenceNumber}${BROKER_DETAILS_ROOT}`, + }); }); - it('renders `broker name` text', () => { - cy.checkText(brokerManualAddressPage.brokerName(), application.BROKER[NAME]); - }); + describe('page tests', () => { + beforeEach(() => { + cy.navigateToUrl(url); + }); - it(`renders ${FIELD_ID} textarea`, () => { - const fieldId = FIELD_ID; - const fieldStrings = FIELD_STRINGS[fieldId]; + it('renders a heading caption', () => { + cy.checkText(headingCaption(), CONTENT_STRINGS.HEADING_CAPTION); + }); - cy.assertTextareaRendering({ - fieldId, - expectedLabel: fieldStrings.LABEL, - maximumCharacters: fieldStrings.MAXIMUM, + it('renders intro text', () => { + cy.checkIntroText(CONTENT_STRINGS.INTRO); }); - }); - }); - describe('form submission', () => { - beforeEach(() => { - cy.navigateToUrl(url); + it('renders `broker name` text', () => { + cy.checkText(brokerManualAddressPage.brokerName(), application.BROKER[NAME]); + }); + + it(`renders ${FIELD_ID} textarea`, () => { + const fieldId = FIELD_ID; + const fieldStrings = FIELD_STRINGS[fieldId]; + + cy.assertTextareaRendering({ + fieldId, + expectedLabel: fieldStrings.LABEL, + maximumCharacters: fieldStrings.MAXIMUM, + }); + }); }); - it(`should redirect to ${LOSS_PAYEE_ROOT} page`, () => { - cy.completeAndSubmitBrokerManualAddressForm({}); + describe('form submission', () => { + beforeEach(() => { + cy.navigateToUrl(url); + }); + + it(`should redirect to ${LOSS_PAYEE_ROOT} page`, () => { + cy.completeAndSubmitBrokerManualAddressForm({}); - cy.assertUrl(lossPayeeUrl); + cy.assertUrl(lossPayeeUrl); + }); }); - }); - describe('when going back to the page', () => { - it('should have the submitted value', () => { - cy.navigateToUrl(url); + describe('when going back to the page', () => { + it('should have the submitted value', () => { + cy.navigateToUrl(url); - cy.checkTextareaValue({ - fieldId: FIELD_ID, - expectedValue: application.BROKER[FIELD_ID], + cy.checkTextareaValue({ + fieldId: FIELD_ID, + expectedValue: application.BROKER[FIELD_ID], + }); }); }); - }); -}); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/save-and-back.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/save-and-back.spec.js index 6277a8028c..96a1485dcf 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/save-and-back.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/save-and-back.spec.js @@ -23,13 +23,10 @@ context('Insurance - Policy - Broker manual address page - Save and back', () => referenceNumber = refNumber; // go to the page we want to test. - cy.completeAndSubmitPolicyForms({ stopSubmittingAfter: 'brokerDetails', usingBroker: true }); + cy.completeAndSubmitPolicyForms({ stopSubmittingAfter: 'brokerDetails', usingBroker: true, isBasedInUk: false }); url = `${baseUrl}${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`; - // TODO: EMS-3973 - remove this - cy.navigateToUrl(url); - cy.assertUrl(url); }); }); @@ -76,8 +73,12 @@ context('Insurance - Policy - Broker manual address page - Save and back', () => }); it('should have the originally submitted answer selected when going back to the page after submission', () => { - // TODO: EMS-3973 - remove this, use cy.clickSubmitButtonMultipleTimes instead. - cy.navigateToUrl(url); + cy.navigateToAllSectionsUrl(referenceNumber); + + cy.startInsurancePolicySection({}); + + // go through 8 policy forms. + cy.clickSubmitButtonMultipleTimes({ count: 8 }); cy.checkTextareaValue({ fieldId: FIELD_ID, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/validation/broker-manual-address-validation.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/validation/broker-manual-address-validation.spec.js index 4de9ed6722..1192d9b93d 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/validation/broker-manual-address-validation.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/validation/broker-manual-address-validation.spec.js @@ -30,13 +30,10 @@ context('Insurance - Policy - Broker manual address page - validation', () => { referenceNumber = refNumber; // go to the page we want to test. - cy.completeAndSubmitPolicyForms({ stopSubmittingAfter: 'brokerDetails', usingBroker: true }); + cy.completeAndSubmitPolicyForms({ stopSubmittingAfter: 'brokerDetails', usingBroker: true, isBasedInUk: false }); url = `${baseUrl}${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`; - // TODO: EMS-3973 - remove this - cy.navigateToUrl(url); - cy.assertUrl(url); }); }); 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 a32f7303d1..a50ed65e7b 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 @@ -51,8 +51,7 @@ const assertFullyPopulatedExportContractSummaryListRows = ({ agentChargeMethodFi checkSummaryList[NAME]({ shouldRender: true }); }); - // TODO: EMS-4011 - it.skip(`should render a ${FULL_ADDRESS} summary list row`, () => { + it(`should render a ${FULL_ADDRESS} summary list row`, () => { checkSummaryList[FULL_ADDRESS]({ shouldRender: true }); }); diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index d9595c71f0..253d28cb31 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -6765,6 +6765,10 @@ var POLICY_FIELDS = { BROKER_ADDRESSES: { [SELECT_THE_ADDRESS]: { LABEL: 'Select the address', + SUMMARY: { + TITLE: "Broker's address", + FORM_TITLE: POLICY_FORM_TITLES.BROKER, + }, }, }, BROKER_MANUAL_ADDRESS: { diff --git a/src/api/content-strings/fields/insurance/policy/index.ts b/src/api/content-strings/fields/insurance/policy/index.ts index 02492c9536..281c5a318b 100644 --- a/src/api/content-strings/fields/insurance/policy/index.ts +++ b/src/api/content-strings/fields/insurance/policy/index.ts @@ -262,6 +262,10 @@ export const POLICY_FIELDS = { BROKER_ADDRESSES: { [SELECT_THE_ADDRESS]: { LABEL: 'Select the address', + SUMMARY: { + TITLE: "Broker's address", + FORM_TITLE: POLICY_FORM_TITLES.BROKER, + }, }, }, BROKER_MANUAL_ADDRESS: { diff --git a/src/ui/server/constants/routes/insurance/policy/broker.ts b/src/ui/server/constants/routes/insurance/policy/broker.ts index 38e8eb1860..edebb40d89 100644 --- a/src/ui/server/constants/routes/insurance/policy/broker.ts +++ b/src/ui/server/constants/routes/insurance/policy/broker.ts @@ -18,10 +18,14 @@ const BROKER_ROUTES = { BROKER_DETAILS_CHECK_AND_CHANGE: `${BROKER_DETAILS_ROOT}/check-and-change`, BROKER_ADDRESSES_ROOT, BROKER_ADDRESSES_SAVE_AND_BACK: `${BROKER_ADDRESSES_ROOT}/save-and-back`, + BROKER_ADDRESSES_CHANGE: `${BROKER_ADDRESSES_ROOT}/change`, + BROKER_ADDRESSES_CHECK_AND_CHANGE: `${BROKER_ADDRESSES_ROOT}/check-and-change`, BROKER_CONFIRM_ADDRESS_ROOT, BROKER_ZERO_ADDRESSES_ROOT, BROKER_MANUAL_ADDRESS_ROOT, BROKER_MANUAL_ADDRESS_SAVE_AND_BACK: `${BROKER_MANUAL_ADDRESS_ROOT}/save-and-back`, + BROKER_MANUAL_ADDRESS_CHANGE: `${BROKER_MANUAL_ADDRESS_ROOT}/change`, + BROKER_MANUAL_ADDRESS_CHECK_AND_CHANGE: `${BROKER_MANUAL_ADDRESS_ROOT}/check-and-change`, }; export default BROKER_ROUTES; diff --git a/src/ui/server/content-strings/fields/insurance/policy/index.ts b/src/ui/server/content-strings/fields/insurance/policy/index.ts index 34895c43e4..f0d5b7e72c 100644 --- a/src/ui/server/content-strings/fields/insurance/policy/index.ts +++ b/src/ui/server/content-strings/fields/insurance/policy/index.ts @@ -282,6 +282,10 @@ export const POLICY_FIELDS = { BROKER_ADDRESSES: { [SELECT_THE_ADDRESS]: { LABEL: 'Select the address', + SUMMARY: { + TITLE: "Broker's address", + FORM_TITLE: POLICY_FORM_TITLES.BROKER, + }, }, }, BROKER_MANUAL_ADDRESS: { diff --git a/src/ui/server/controllers/insurance/policy/broker-addresses/index.test.ts b/src/ui/server/controllers/insurance/policy/broker-addresses/index.test.ts index f85aa4776f..b7ceea8b70 100644 --- a/src/ui/server/controllers/insurance/policy/broker-addresses/index.test.ts +++ b/src/ui/server/controllers/insurance/policy/broker-addresses/index.test.ts @@ -24,7 +24,15 @@ const { const { INSURANCE_ROOT, PROBLEM_WITH_SERVICE, - POLICY: { BROKER_ADDRESSES_SAVE_AND_BACK, BROKER_DETAILS_ROOT, BROKER_ZERO_ADDRESSES_ROOT, BROKER_CONFIRM_ADDRESS_ROOT, BROKER_MANUAL_ADDRESS_ROOT }, + POLICY: { + BROKER_ADDRESSES_SAVE_AND_BACK, + BROKER_DETAILS_ROOT, + BROKER_ZERO_ADDRESSES_ROOT, + BROKER_CONFIRM_ADDRESS_ROOT, + BROKER_MANUAL_ADDRESS_ROOT, + BROKER_ADDRESSES_CHANGE, + CHECK_YOUR_ANSWERS, + }, } = INSURANCE_ROUTES; const { BROKER_ADDRESSES } = POLICY_FIELDS; @@ -397,6 +405,17 @@ describe('controllers/insurance/policy/broker-addresses', () => { expect(mapAndSave.broker).toHaveBeenCalledWith(chosenAddress, mockApplication); }); + describe("when the url's last substring is `change`", () => { + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, async () => { + req.originalUrl = BROKER_ADDRESSES_CHANGE; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); + describe('api error handling', () => { describe('when api.keystone.getOrdnanceSurveyAddresses throws an error', () => { beforeEach(() => { diff --git a/src/ui/server/controllers/insurance/policy/broker-addresses/index.ts b/src/ui/server/controllers/insurance/policy/broker-addresses/index.ts index fe44c5472c..66507b9815 100644 --- a/src/ui/server/controllers/insurance/policy/broker-addresses/index.ts +++ b/src/ui/server/controllers/insurance/policy/broker-addresses/index.ts @@ -12,6 +12,7 @@ import generateValidationErrors from '../../../../shared-validation/yes-no-radio import getOrdnanceSurveyAddressByIndex from '../../../../helpers/get-chosen-ordnance-survey-address/by-index'; import getOrdnanceSurveyAddressById from '../../../../helpers/get-chosen-ordnance-survey-address/by-id'; import mapAndSave from '../map-and-save/broker'; +import isChangeRoute from '../../../../helpers/is-change-route'; import { Request, Response } from '../../../../../types'; const { SELECT_THE_ADDRESS } = POLICY_FIELD_IDS.BROKER_ADDRESSES; @@ -19,7 +20,14 @@ const { SELECT_THE_ADDRESS } = POLICY_FIELD_IDS.BROKER_ADDRESSES; const { INSURANCE_ROOT, PROBLEM_WITH_SERVICE, - POLICY: { BROKER_ADDRESSES_SAVE_AND_BACK, BROKER_DETAILS_ROOT, BROKER_ZERO_ADDRESSES_ROOT, BROKER_CONFIRM_ADDRESS_ROOT, BROKER_MANUAL_ADDRESS_ROOT }, + POLICY: { + BROKER_ADDRESSES_SAVE_AND_BACK, + BROKER_DETAILS_ROOT, + BROKER_ZERO_ADDRESSES_ROOT, + BROKER_CONFIRM_ADDRESS_ROOT, + BROKER_MANUAL_ADDRESS_ROOT, + CHECK_YOUR_ANSWERS, + }, } = INSURANCE_ROUTES; const { BROKER_ADDRESSES } = POLICY_FIELDS; @@ -189,6 +197,10 @@ export const post = async (req: Request, res: Response) => { return res.redirect(PROBLEM_WITH_SERVICE); } + if (isChangeRoute(req.originalUrl)) { + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`); + } + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${BROKER_CONFIRM_ADDRESS_ROOT}`); } catch (error) { console.error('Error updating application - policy - broker addresses %o', error); diff --git a/src/ui/server/controllers/insurance/policy/broker-manual-address/index.test.ts b/src/ui/server/controllers/insurance/policy/broker-manual-address/index.test.ts index 8fe3a75513..9c8da76dc1 100644 --- a/src/ui/server/controllers/insurance/policy/broker-manual-address/index.test.ts +++ b/src/ui/server/controllers/insurance/policy/broker-manual-address/index.test.ts @@ -20,7 +20,7 @@ const { const { PROBLEM_WITH_SERVICE, INSURANCE_ROOT, - POLICY: { LOSS_PAYEE_ROOT, BROKER_MANUAL_ADDRESS_SAVE_AND_BACK }, + POLICY: { LOSS_PAYEE_ROOT, BROKER_MANUAL_ADDRESS_CHANGE, BROKER_MANUAL_ADDRESS_SAVE_AND_BACK, CHECK_YOUR_ANSWERS }, } = INSURANCE_ROUTES; const { broker } = mockApplication; @@ -143,6 +143,17 @@ describe('controllers/insurance/policy/broker-manual-address', () => { expect(mapAndSave.broker).toHaveBeenCalledWith(payload, mockApplication); }); + describe("when the url's last substring is `change`", () => { + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, async () => { + req.originalUrl = BROKER_MANUAL_ADDRESS_CHANGE; + + await post(req, res); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; + expect(res.redirect).toHaveBeenCalledWith(expected); + }); + }); + it(`should redirect to ${LOSS_PAYEE_ROOT}`, () => { const expected = `${INSURANCE_ROOT}/${referenceNumber}${LOSS_PAYEE_ROOT}`; diff --git a/src/ui/server/controllers/insurance/policy/broker-manual-address/index.ts b/src/ui/server/controllers/insurance/policy/broker-manual-address/index.ts index a610f0580d..3c14ac003b 100644 --- a/src/ui/server/controllers/insurance/policy/broker-manual-address/index.ts +++ b/src/ui/server/controllers/insurance/policy/broker-manual-address/index.ts @@ -9,6 +9,7 @@ import constructPayload from '../../../../helpers/construct-payload'; import { sanitiseData } from '../../../../helpers/sanitise-data'; import generateValidationErrors from './validation'; import mapAndSave from '../map-and-save/broker'; +import isChangeRoute from '../../../../helpers/is-change-route'; import { Request, Response } from '../../../../../types'; const { @@ -18,7 +19,7 @@ const { const { PROBLEM_WITH_SERVICE, INSURANCE_ROOT, - POLICY: { LOSS_PAYEE_ROOT, BROKER_MANUAL_ADDRESS_SAVE_AND_BACK }, + POLICY: { LOSS_PAYEE_ROOT, BROKER_MANUAL_ADDRESS_SAVE_AND_BACK, CHECK_YOUR_ANSWERS }, } = INSURANCE_ROUTES; export const FIELD_ID = FULL_ADDRESS; @@ -106,6 +107,10 @@ export const post = async (req: Request, res: Response) => { return res.redirect(PROBLEM_WITH_SERVICE); } + if (isChangeRoute(req.originalUrl)) { + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`); + } + return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${LOSS_PAYEE_ROOT}`); } catch (error) { console.error('Error updating application - policy - broker manual address %o', error); diff --git a/src/ui/server/helpers/summary-lists/policy/broker-fields/address-field/based-in-the-uk/index.test.ts b/src/ui/server/helpers/summary-lists/policy/broker-fields/address-field/based-in-the-uk/index.test.ts new file mode 100644 index 0000000000..3f575bbf31 --- /dev/null +++ b/src/ui/server/helpers/summary-lists/policy/broker-fields/address-field/based-in-the-uk/index.test.ts @@ -0,0 +1,107 @@ +import mapBrokerAddressBasedInTheUk from '.'; +import { POLICY as FIELD_IDS } from '../../../../../../constants/field-ids/insurance/policy'; +import { ApplicationBroker } from '../../../../../../../types'; +import { mockApplication } from '../../../../../../test-mocks'; + +const { + BROKER_DETAILS: { BUILDING_NUMBER_OR_NAME, ADDRESS_LINE_1, ADDRESS_LINE_2, TOWN, COUNTY, POSTCODE }, +} = FIELD_IDS; + +const { broker } = mockApplication; + +const { buildingNumberOrName, addressLine1, addressLine2, town, county, postcode } = broker; + +describe('server/helpers/summary-lists/policy/broker-fields/map-broker-address-field/based-in-the-uk', () => { + describe(`when a broker only has ${BUILDING_NUMBER_OR_NAME}, ${ADDRESS_LINE_1} and ${POSTCODE} generic fields`, () => { + it('should return a single string containing only said fields', () => { + const mockBroker: ApplicationBroker = { + ...broker, + [ADDRESS_LINE_2]: '', + [TOWN]: '', + [COUNTY]: '', + }; + + const result = mapBrokerAddressBasedInTheUk(mockBroker); + + const expected = `${buildingNumberOrName}\n${addressLine1}\n${postcode}`; + + expect(result).toEqual(expected); + }); + }); + + describe(`when a broker has generic fields and ${ADDRESS_LINE_2}`, () => { + it('should return a single string containing only said fields', () => { + const mockBroker: ApplicationBroker = { + ...broker, + [TOWN]: '', + [COUNTY]: '', + }; + + const result = mapBrokerAddressBasedInTheUk(mockBroker); + + const expected = `${buildingNumberOrName}\n${addressLine1}\n${addressLine2}\n${postcode}`; + + expect(result).toEqual(expected); + }); + }); + + describe(`when a broker has generic fields and ${TOWN}`, () => { + it('should return a single string containing only said fields', () => { + const mockBroker: ApplicationBroker = { + ...broker, + [ADDRESS_LINE_2]: '', + [COUNTY]: '', + }; + + const result = mapBrokerAddressBasedInTheUk(mockBroker); + + const expected = `${buildingNumberOrName}\n${addressLine1}\n${town}\n${postcode}`; + + expect(result).toEqual(expected); + }); + }); + + describe(`when a broker has generic fields and ${COUNTY}`, () => { + it('should return a single string containing only said fields', () => { + const mockBroker: ApplicationBroker = { + ...broker, + [ADDRESS_LINE_2]: '', + [TOWN]: '', + }; + + const result = mapBrokerAddressBasedInTheUk(mockBroker); + + const expected = `${buildingNumberOrName}\n${addressLine1}\n${county}\n${postcode}`; + + expect(result).toEqual(expected); + }); + }); + + describe('when a broker has all possible fields', () => { + it('should return a single string with all fields', () => { + const result = mapBrokerAddressBasedInTheUk(broker); + + const expected = `${buildingNumberOrName}\n${addressLine1}\n${addressLine2}\n${town}\n${county}\n${postcode}`; + + expect(result).toEqual(expected); + }); + }); + + describe('when all broker fields are empty string', () => { + it('should return a single string with all fields', () => { + const mockBroker: ApplicationBroker = { + ...broker, + [BUILDING_NUMBER_OR_NAME]: '', + [ADDRESS_LINE_1]: '', + [ADDRESS_LINE_2]: '', + [TOWN]: '', + [COUNTY]: '', + [POSTCODE]: '', + }; + + const result = mapBrokerAddressBasedInTheUk(mockBroker); + + expect(result).toEqual(''); + }); + }); +}); diff --git a/src/ui/server/helpers/summary-lists/policy/broker-fields/address-field/based-in-the-uk/index.ts b/src/ui/server/helpers/summary-lists/policy/broker-fields/address-field/based-in-the-uk/index.ts new file mode 100644 index 0000000000..2cb78d4c57 --- /dev/null +++ b/src/ui/server/helpers/summary-lists/policy/broker-fields/address-field/based-in-the-uk/index.ts @@ -0,0 +1,39 @@ +import { ApplicationBroker } from '../../../../../../../types'; + +/** + * mapBrokerAddressBasedInTheUk + * Map an application's broker "based in the UK" address fields into a string for summary list field value + * @param {ApplicationBroker} broker + * @returns {String} Broker UK address string + */ +const mapBrokerAddressBasedInTheUk = (broker: ApplicationBroker) => { + const { buildingNumberOrName, addressLine1, addressLine2, town, county, postcode } = broker; + + let addressString = ''; + + if (buildingNumberOrName) { + addressString += `${buildingNumberOrName}\n`; + } + + if (addressLine1) { + addressString += `${addressLine1}\n`; + } + + if (addressLine2) { + addressString += `${addressLine2}\n`; + } + + if (town) { + addressString += `${town}\n`; + } + + if (county) { + addressString += `${county}\n`; + } + + addressString += postcode; + + return addressString; +}; + +export default mapBrokerAddressBasedInTheUk; diff --git a/src/ui/server/helpers/summary-lists/policy/broker-fields/address-field/index.test.ts b/src/ui/server/helpers/summary-lists/policy/broker-fields/address-field/index.test.ts new file mode 100644 index 0000000000..11114c5b79 --- /dev/null +++ b/src/ui/server/helpers/summary-lists/policy/broker-fields/address-field/index.test.ts @@ -0,0 +1,73 @@ +import brokerAddressField from '.'; +import { POLICY as POLICY_FIELD_IDS } from '../../../../../constants/field-ids/insurance/policy'; +import { POLICY as POLICY_ROUTES } from '../../../../../constants/routes/insurance/policy'; +import { POLICY_FIELDS } from '../../../../../content-strings/fields/insurance'; +import mapBrokerAddressBasedInTheUk from './based-in-the-uk'; +import fieldGroupItem from '../../../generate-field-group-item'; +import getFieldById from '../../../../get-field-by-id'; +import generateChangeLink from '../../../../generate-change-link'; +import { mockBroker, referenceNumber } from '../../../../../test-mocks/mock-application'; + +const { + BROKER_DETAILS: { IS_BASED_IN_UK }, + BROKER_ADDRESSES: { SELECT_THE_ADDRESS }, + BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, +} = POLICY_FIELD_IDS; + +const { BROKER_ADDRESSES_CHANGE, BROKER_ADDRESSES_CHECK_AND_CHANGE, BROKER_MANUAL_ADDRESS_CHANGE, BROKER_MANUAL_ADDRESS_CHECK_AND_CHANGE } = POLICY_ROUTES; + +const checkAndChange = false; + +describe('server/helpers/summary-lists/policy/broker-fields/address-field', () => { + describe(`when ${IS_BASED_IN_UK} is true`, () => { + it('should return a UK address field', () => { + const mockAnswers = { + ...mockBroker, + [IS_BASED_IN_UK]: true, + }; + + const result = brokerAddressField(mockAnswers, referenceNumber, checkAndChange); + + const expected = fieldGroupItem( + { + field: getFieldById(POLICY_FIELDS.BROKER_ADDRESSES, SELECT_THE_ADDRESS), + data: mockAnswers, + href: generateChangeLink(BROKER_ADDRESSES_CHANGE, BROKER_ADDRESSES_CHECK_AND_CHANGE, `#${SELECT_THE_ADDRESS}-label`, referenceNumber, checkAndChange), + renderChangeLink: true, + }, + mapBrokerAddressBasedInTheUk(mockAnswers), + ); + + expect(result).toEqual(expected); + }); + }); + + describe(`when ${IS_BASED_IN_UK} is false`, () => { + it('should return a non-UK address field', () => { + const mockAnswers = { + ...mockBroker, + [IS_BASED_IN_UK]: false, + }; + + const result = brokerAddressField(mockAnswers, referenceNumber, checkAndChange); + + const expected = fieldGroupItem( + { + field: getFieldById(POLICY_FIELDS.BROKER_MANUAL_ADDRESS, FULL_ADDRESS), + data: mockAnswers, + href: generateChangeLink( + BROKER_MANUAL_ADDRESS_CHANGE, + BROKER_MANUAL_ADDRESS_CHECK_AND_CHANGE, + `#${FULL_ADDRESS}-label`, + referenceNumber, + checkAndChange, + ), + renderChangeLink: true, + }, + mockAnswers[FULL_ADDRESS], + ); + + expect(result).toEqual(expected); + }); + }); +}); diff --git a/src/ui/server/helpers/summary-lists/policy/broker-fields/address-field/index.ts b/src/ui/server/helpers/summary-lists/policy/broker-fields/address-field/index.ts new file mode 100644 index 0000000000..3384f87eb4 --- /dev/null +++ b/src/ui/server/helpers/summary-lists/policy/broker-fields/address-field/index.ts @@ -0,0 +1,65 @@ +import { POLICY as POLICY_FIELD_IDS } from '../../../../../constants/field-ids/insurance/policy'; +import { POLICY as POLICY_ROUTES } from '../../../../../constants/routes/insurance/policy'; +import { POLICY_FIELDS } from '../../../../../content-strings/fields/insurance'; +import mapBrokerAddressBasedInTheUk from './based-in-the-uk'; +import fieldGroupItem from '../../../generate-field-group-item'; +import getFieldById from '../../../../get-field-by-id'; +import generateChangeLink from '../../../../generate-change-link'; +import { ApplicationBroker } from '../../../../../../types'; + +const { + BROKER_DETAILS: { IS_BASED_IN_UK }, + BROKER_ADDRESSES: { SELECT_THE_ADDRESS }, + BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, +} = POLICY_FIELD_IDS; + +const { BROKER_ADDRESSES_CHANGE, BROKER_ADDRESSES_CHECK_AND_CHANGE, BROKER_MANUAL_ADDRESS_CHANGE, BROKER_MANUAL_ADDRESS_CHECK_AND_CHANGE } = POLICY_ROUTES; + +/** + * brokerAddressField + * If IS_BASED_IN_UK is true, populate and return UK address field (BROKER_ADDRESSES) + * If IS_BASED_IN_UK is false, populate and return a non-UK address field (BROKER_MANUAL_ADDRESS) + * @param {ApplicationBroker} answers: Broker answers + * @param {Number} referenceNumber: Application reference number + * @param {Boolean} checkAndChange: True if coming from check your answers section in submit application section + * @returns {SummaryListItemData} Broker address field + */ +const brokerAddressField = (answers: ApplicationBroker, referenceNumber: number, checkAndChange?: boolean) => { + let field; + let fieldValue; + let changeRoute; + let checkAndChangeRoute; + let href; + + if (answers[IS_BASED_IN_UK]) { + field = getFieldById(POLICY_FIELDS.BROKER_ADDRESSES, SELECT_THE_ADDRESS); + fieldValue = mapBrokerAddressBasedInTheUk(answers); + + changeRoute = BROKER_ADDRESSES_CHANGE; + checkAndChangeRoute = BROKER_ADDRESSES_CHECK_AND_CHANGE; + + href = generateChangeLink(changeRoute, checkAndChangeRoute, `#${SELECT_THE_ADDRESS}-label`, referenceNumber, checkAndChange); + } else { + field = getFieldById(POLICY_FIELDS.BROKER_MANUAL_ADDRESS, FULL_ADDRESS); + fieldValue = answers[FULL_ADDRESS]; + + changeRoute = BROKER_MANUAL_ADDRESS_CHANGE; + checkAndChangeRoute = BROKER_MANUAL_ADDRESS_CHECK_AND_CHANGE; + + href = generateChangeLink(changeRoute, checkAndChangeRoute, `#${FULL_ADDRESS}-label`, referenceNumber, checkAndChange); + } + + const groupItem = fieldGroupItem( + { + field, + data: answers, + href, + renderChangeLink: true, + }, + fieldValue, + ); + + return groupItem; +}; + +export default brokerAddressField; diff --git a/src/ui/server/helpers/summary-lists/policy/broker-fields/index.test.ts b/src/ui/server/helpers/summary-lists/policy/broker-fields/index.test.ts index 64d66a8397..f33858a385 100644 --- a/src/ui/server/helpers/summary-lists/policy/broker-fields/index.test.ts +++ b/src/ui/server/helpers/summary-lists/policy/broker-fields/index.test.ts @@ -1,14 +1,14 @@ import { generateBrokerFields, optionalBrokerFields } from '.'; -import { FORM_TITLES } from '../../../../content-strings/form-titles'; -import { POLICY_FIELDS } from '../../../../content-strings/fields/insurance'; import { POLICY as POLICY_FIELD_IDS } from '../../../../constants/field-ids/insurance/policy'; import ACCOUNT_FIELD_IDS from '../../../../constants/field-ids/insurance/account'; import { INSURANCE_ROUTES } from '../../../../constants/routes/insurance'; +import { FORM_TITLES } from '../../../../content-strings/form-titles'; +import { POLICY_FIELDS } from '../../../../content-strings/fields/insurance'; import fieldGroupItem from '../../generate-field-group-item'; import getFieldById from '../../../get-field-by-id'; import mapYesNoField from '../../../mappings/map-yes-no-field'; import generateChangeLink from '../../../generate-change-link'; -import replaceNewLineWithLineBreak from '../../../replace-new-line-with-line-break'; +import brokerAddressField from './address-field'; import { mockBroker, referenceNumber } from '../../../../test-mocks/mock-application'; const { @@ -18,7 +18,6 @@ const { const { USING_BROKER, BROKER_DETAILS: { NAME }, - BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, } = POLICY_FIELD_IDS; const { EMAIL } = ACCOUNT_FIELD_IDS; @@ -44,15 +43,7 @@ describe('server/helpers/summary-lists/policy/broker-fields', () => { href: generateChangeLink(BROKER_DETAILS_CHANGE, BROKER_DETAILS_CHECK_AND_CHANGE, `#${NAME}-label`, referenceNumber, checkAndChange), renderChangeLink: true, }), - fieldGroupItem( - { - field: getFieldById(POLICY_FIELDS.BROKER_DETAILS, FULL_ADDRESS), - data: mockBroker, - href: generateChangeLink(BROKER_DETAILS_CHANGE, BROKER_DETAILS_CHECK_AND_CHANGE, `#${FULL_ADDRESS}-label`, referenceNumber, checkAndChange), - renderChangeLink: true, - }, - replaceNewLineWithLineBreak(mockBroker[FULL_ADDRESS]), - ), + brokerAddressField(mockBroker, referenceNumber, checkAndChange), fieldGroupItem({ field: getFieldById(POLICY_FIELDS.BROKER_DETAILS, EMAIL), data: mockBroker, diff --git a/src/ui/server/helpers/summary-lists/policy/broker-fields/index.ts b/src/ui/server/helpers/summary-lists/policy/broker-fields/index.ts index 231d771463..62583a6157 100644 --- a/src/ui/server/helpers/summary-lists/policy/broker-fields/index.ts +++ b/src/ui/server/helpers/summary-lists/policy/broker-fields/index.ts @@ -1,13 +1,13 @@ -import { FORM_TITLES } from '../../../../content-strings/form-titles'; -import { POLICY_FIELDS } from '../../../../content-strings/fields/insurance'; import { POLICY as POLICY_FIELD_IDS } from '../../../../constants/field-ids/insurance/policy'; import ACCOUNT_FIELD_IDS from '../../../../constants/field-ids/insurance/account'; import { INSURANCE_ROUTES } from '../../../../constants/routes/insurance'; +import { FORM_TITLES } from '../../../../content-strings/form-titles'; +import { POLICY_FIELDS } from '../../../../content-strings/fields/insurance'; import fieldGroupItem from '../../generate-field-group-item'; import getFieldById from '../../../get-field-by-id'; import mapYesNoField from '../../../mappings/map-yes-no-field'; import generateChangeLink from '../../../generate-change-link'; -import replaceNewLineWithLineBreak from '../../../replace-new-line-with-line-break'; +import brokerAddressField from './address-field'; import { ApplicationBroker, SummaryListItemData } from '../../../../../types'; const { @@ -17,7 +17,6 @@ const { const { USING_BROKER, BROKER_DETAILS: { NAME }, - BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, } = POLICY_FIELD_IDS; const { EMAIL } = ACCOUNT_FIELD_IDS; @@ -28,11 +27,11 @@ const { /** * optionalBrokerFields - * If USING_BROKER is true, populates and return optional fields. + * If USING_BROKER is true, populate and return optional fields. * @param {ApplicationBroker} answers: Broker answers * @param {Number} referenceNumber: Application reference number * @param {Boolean} checkAndChange: True if coming from check your answers section in submit application section - * @returns {Array} Optional broker fields if yes is selected + * @returns {Array} Optional broker fields if USING_BROKER is true */ export const optionalBrokerFields = (answers: ApplicationBroker, referenceNumber: number, checkAndChange?: boolean) => { let fields = [] as Array; @@ -49,15 +48,7 @@ export const optionalBrokerFields = (answers: ApplicationBroker, referenceNumber href: generateChangeLink(BROKER_DETAILS_CHANGE, BROKER_DETAILS_CHECK_AND_CHANGE, `#${NAME}-label`, referenceNumber, checkAndChange), renderChangeLink: true, }), - fieldGroupItem( - { - field: getFieldById(POLICY_FIELDS.BROKER_DETAILS, FULL_ADDRESS), - data: answers, - href: generateChangeLink(BROKER_DETAILS_CHANGE, BROKER_DETAILS_CHECK_AND_CHANGE, `#${FULL_ADDRESS}-label`, referenceNumber, checkAndChange), - renderChangeLink: true, - }, - replaceNewLineWithLineBreak(answers[FULL_ADDRESS]), - ), + brokerAddressField(answers, referenceNumber, checkAndChange), fieldGroupItem({ field: getFieldById(POLICY_FIELDS.BROKER_DETAILS, EMAIL), data: answers, diff --git a/src/ui/server/helpers/summary-lists/policy/other-company-fields/index.ts b/src/ui/server/helpers/summary-lists/policy/other-company-fields/index.ts index 88b0cab640..5bb0d9d9e6 100644 --- a/src/ui/server/helpers/summary-lists/policy/other-company-fields/index.ts +++ b/src/ui/server/helpers/summary-lists/policy/other-company-fields/index.ts @@ -25,7 +25,7 @@ const { REQUESTED_JOINTLY_INSURED_PARTY } = POLICY_FIELDS; /** * optionalOtherCompanyFields - * if yes is selected for other company requested, populates and returns optional fields in an array + * if yes is selected for other company requested, populate and return optional fields in an array * @param {ApplicationJointlyInsuredParty} answers: Jointly insured party answers * @param {Number} referenceNumber: Application reference number * @param {Array} countries: Countries diff --git a/src/ui/server/routes/insurance/index.test.ts b/src/ui/server/routes/insurance/index.test.ts index cdbcdd8f06..819103b4be 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(222); - expect(post).toHaveBeenCalledTimes(232); + expect(get).toHaveBeenCalledTimes(226); + expect(post).toHaveBeenCalledTimes(236); expect(get).toHaveBeenCalledWith(INSURANCE_ROUTES.START, startGet); diff --git a/src/ui/server/routes/insurance/policy/broker/index.test.ts b/src/ui/server/routes/insurance/policy/broker/index.test.ts index 42561afab7..49c4a6a676 100644 --- a/src/ui/server/routes/insurance/policy/broker/index.test.ts +++ b/src/ui/server/routes/insurance/policy/broker/index.test.ts @@ -22,9 +22,13 @@ const { BROKER_DETAILS_CHECK_AND_CHANGE, BROKER_ADDRESSES_ROOT, BROKER_ADDRESSES_SAVE_AND_BACK, + BROKER_ADDRESSES_CHANGE, + BROKER_ADDRESSES_CHECK_AND_CHANGE, BROKER_CONFIRM_ADDRESS_ROOT, BROKER_ZERO_ADDRESSES_ROOT, BROKER_MANUAL_ADDRESS_ROOT, + BROKER_MANUAL_ADDRESS_CHANGE, + BROKER_MANUAL_ADDRESS_CHECK_AND_CHANGE, BROKER_MANUAL_ADDRESS_SAVE_AND_BACK, } = POLICY; @@ -38,8 +42,8 @@ describe('routes/insurance/policy/broker', () => { }); it('should setup all routes', () => { - expect(get).toHaveBeenCalledTimes(10); - expect(post).toHaveBeenCalledTimes(13); + expect(get).toHaveBeenCalledTimes(14); + expect(post).toHaveBeenCalledTimes(17); expect(get).toHaveBeenCalledWith(`/:referenceNumber${BROKER_ROOT}`, getBroker); expect(post).toHaveBeenCalledWith(`/:referenceNumber${BROKER_ROOT}`, postBroker); @@ -60,6 +64,10 @@ describe('routes/insurance/policy/broker', () => { expect(get).toHaveBeenCalledWith(`/:referenceNumber${BROKER_ADDRESSES_ROOT}`, getBrokerAddresses); expect(post).toHaveBeenCalledWith(`/:referenceNumber${BROKER_ADDRESSES_ROOT}`, postBrokerAddresses); expect(post).toHaveBeenCalledWith(`/:referenceNumber${BROKER_ADDRESSES_SAVE_AND_BACK}`, postBrokerAddressesSaveAndBack); + expect(get).toHaveBeenCalledWith(`/:referenceNumber${BROKER_ADDRESSES_CHANGE}`, getBrokerAddresses); + expect(post).toHaveBeenCalledWith(`/:referenceNumber${BROKER_ADDRESSES_CHANGE}`, postBrokerAddresses); + expect(get).toHaveBeenCalledWith(`/:referenceNumber${BROKER_ADDRESSES_CHECK_AND_CHANGE}`, getBrokerAddresses); + expect(post).toHaveBeenCalledWith(`/:referenceNumber${BROKER_ADDRESSES_CHECK_AND_CHANGE}`, postBrokerAddresses); expect(get).toHaveBeenCalledWith(`/:referenceNumber${BROKER_CONFIRM_ADDRESS_ROOT}`, getBrokerConfirmAddress); expect(post).toHaveBeenCalledWith(`/:referenceNumber${BROKER_CONFIRM_ADDRESS_ROOT}`, postBrokerConfirmAddress); @@ -69,5 +77,9 @@ describe('routes/insurance/policy/broker', () => { expect(get).toHaveBeenCalledWith(`/:referenceNumber${BROKER_MANUAL_ADDRESS_ROOT}`, getBrokerManualAddress); expect(post).toHaveBeenCalledWith(`/:referenceNumber${BROKER_MANUAL_ADDRESS_ROOT}`, postBrokerManualAddress); expect(post).toHaveBeenCalledWith(`/:referenceNumber${BROKER_MANUAL_ADDRESS_SAVE_AND_BACK}`, postBrokerManualAddressSaveAndBack); + expect(get).toHaveBeenCalledWith(`/:referenceNumber${BROKER_MANUAL_ADDRESS_CHANGE}`, getBrokerManualAddress); + expect(post).toHaveBeenCalledWith(`/:referenceNumber${BROKER_MANUAL_ADDRESS_CHANGE}`, postBrokerManualAddress); + expect(get).toHaveBeenCalledWith(`/:referenceNumber${BROKER_MANUAL_ADDRESS_CHECK_AND_CHANGE}`, getBrokerManualAddress); + expect(post).toHaveBeenCalledWith(`/:referenceNumber${BROKER_MANUAL_ADDRESS_CHECK_AND_CHANGE}`, postBrokerManualAddress); }); }); diff --git a/src/ui/server/routes/insurance/policy/broker/index.ts b/src/ui/server/routes/insurance/policy/broker/index.ts index d6a0900364..dfcd323889 100644 --- a/src/ui/server/routes/insurance/policy/broker/index.ts +++ b/src/ui/server/routes/insurance/policy/broker/index.ts @@ -22,9 +22,13 @@ const { BROKER_DETAILS_CHECK_AND_CHANGE, BROKER_ADDRESSES_ROOT, BROKER_ADDRESSES_SAVE_AND_BACK, + BROKER_ADDRESSES_CHANGE, + BROKER_ADDRESSES_CHECK_AND_CHANGE, BROKER_CONFIRM_ADDRESS_ROOT, BROKER_ZERO_ADDRESSES_ROOT, BROKER_MANUAL_ADDRESS_ROOT, + BROKER_MANUAL_ADDRESS_CHANGE, + BROKER_MANUAL_ADDRESS_CHECK_AND_CHANGE, BROKER_MANUAL_ADDRESS_SAVE_AND_BACK, } = POLICY; @@ -50,6 +54,10 @@ router.post(`/:referenceNumber${BROKER_DETAILS_CHECK_AND_CHANGE}`, postBrokerDet router.get(`/:referenceNumber${BROKER_ADDRESSES_ROOT}`, getBrokerAddresses); router.post(`/:referenceNumber${BROKER_ADDRESSES_ROOT}`, postBrokerAddresses); router.post(`/:referenceNumber${BROKER_ADDRESSES_SAVE_AND_BACK}`, postBrokerAddressesSaveAndBack); +router.get(`/:referenceNumber${BROKER_ADDRESSES_CHANGE}`, getBrokerAddresses); +router.post(`/:referenceNumber${BROKER_ADDRESSES_CHANGE}`, postBrokerAddresses); +router.get(`/:referenceNumber${BROKER_ADDRESSES_CHECK_AND_CHANGE}`, getBrokerAddresses); +router.post(`/:referenceNumber${BROKER_ADDRESSES_CHECK_AND_CHANGE}`, postBrokerAddresses); router.get(`/:referenceNumber${BROKER_CONFIRM_ADDRESS_ROOT}`, getBrokerConfirmAddress); router.post(`/:referenceNumber${BROKER_CONFIRM_ADDRESS_ROOT}`, postBrokerConfirmAddress); @@ -59,5 +67,9 @@ router.get(`/:referenceNumber${BROKER_ZERO_ADDRESSES_ROOT}`, getBrokerZeroAddres router.get(`/:referenceNumber${BROKER_MANUAL_ADDRESS_ROOT}`, getBrokerManualAddress); router.post(`/:referenceNumber${BROKER_MANUAL_ADDRESS_ROOT}`, postBrokerManualAddress); router.post(`/:referenceNumber${BROKER_MANUAL_ADDRESS_SAVE_AND_BACK}`, postBrokerManualAddressSaveAndBack); +router.get(`/:referenceNumber${BROKER_MANUAL_ADDRESS_CHANGE}`, getBrokerManualAddress); +router.post(`/:referenceNumber${BROKER_MANUAL_ADDRESS_CHANGE}`, postBrokerManualAddress); +router.get(`/:referenceNumber${BROKER_MANUAL_ADDRESS_CHECK_AND_CHANGE}`, getBrokerManualAddress); +router.post(`/:referenceNumber${BROKER_MANUAL_ADDRESS_CHECK_AND_CHANGE}`, postBrokerManualAddress); export default router; diff --git a/src/ui/server/test-mocks/mock-broker.ts b/src/ui/server/test-mocks/mock-broker.ts index 9d7b77a113..b70f9fffed 100644 --- a/src/ui/server/test-mocks/mock-broker.ts +++ b/src/ui/server/test-mocks/mock-broker.ts @@ -10,6 +10,10 @@ const mockBroker = { isBasedInUk: false, postcode: 'W1A 1AA', buildingNumberOrName: 'WOGAN HOUSE', + addressLine1: 'Mock broker address line 1', + addressLine2: 'Mock broker address line 2', + town: 'Mock broker town', + county: 'Mock broker county', }; export default mockBroker; diff --git a/src/ui/types/application.ts b/src/ui/types/application.ts index c56359e8e5..092eed82c7 100644 --- a/src/ui/types/application.ts +++ b/src/ui/types/application.ts @@ -131,6 +131,7 @@ interface ApplicationBroker { addressLine2?: string; buildingNumberOrName?: string; town?: string; + county?: string; postcode?: string; fullAddress?: string; email?: string;