diff --git a/e2e-tests/commands/insurance/complete-policy-section.js b/e2e-tests/commands/insurance/complete-policy-section.js index 5684d8129a..c20d22b8a5 100644 --- a/e2e-tests/commands/insurance/complete-policy-section.js +++ b/e2e-tests/commands/insurance/complete-policy-section.js @@ -15,6 +15,7 @@ const { POLICY_TYPE } = APPLICATION; * @param {Boolean} usingBroker: If "using broker" - defaults to false * @param {Boolean} brokerIsBasedInUk: Broker is based in the UK - defaults to false * @param {Boolean} multipleBrokerAddressesAvailable: Multiple broker addresses are available from Ordnance Survey + * @param {Boolean} provideBrokerAddressManually: Provide a broker address manually, instead of selecting a result from Ordnance Survey * @param {String} brokerBuildingNumberOrName: Broker building name or number * @param {String} brokerPostcode: Broker postcode * @param {Boolean} otherCompanyInvolved: Should submit "yes" to "another company to be insured". Defaults to false. @@ -33,6 +34,7 @@ const completePolicySection = ({ usingBroker = false, brokerIsBasedInUk = false, multipleBrokerAddressesAvailable = false, + provideBrokerAddressManually = false, brokerBuildingNumberOrName, brokerPostcode, otherCompanyInvolved = false, @@ -88,8 +90,14 @@ const completePolicySection = ({ cy.completeAndSubmitBrokerAddressesForm({}); } - // submit the "confirm broker address" form - cy.clickSubmitButton(); + if (provideBrokerAddressManually) { + cy.clickEnterAddressManuallyLink(); + + cy.completeAndSubmitBrokerManualAddressForm({}); + } else { + // submit the "confirm broker address" form + cy.clickSubmitButton(); + } } else { cy.completeAndSubmitBrokerManualAddressForm({}); } diff --git a/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js b/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js index 4f8a150fb5..9003291d64 100644 --- a/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js +++ b/e2e-tests/commands/insurance/complete-prepare-application-section-multiple-policy-type.js @@ -45,6 +45,7 @@ const { POLICY_TYPE } = APPLICATION; * @param {String} brokerBuildingNumberOrName: Broker building name or number. * @param {String} brokerPostcode: Broker postcode. * @param {Boolean} multipleBrokerAddressesAvailable: Multiple broker addresses are available from Ordnance Survey. + * @param {Boolean} provideBrokerAddressManually: Provide a broker address manually, instead of selecting a result from Ordnance Survey */ const completePrepareApplicationMultiplePolicyType = ({ agentChargeMethodFixedSum = false, @@ -86,6 +87,7 @@ const completePrepareApplicationMultiplePolicyType = ({ brokerBuildingNumberOrName, brokerPostcode, multipleBrokerAddressesAvailable, + provideBrokerAddressManually, }) => { cy.completeBusinessSection({ differentTradingName, @@ -118,6 +120,7 @@ const completePrepareApplicationMultiplePolicyType = ({ brokerBuildingNumberOrName, brokerPostcode, multipleBrokerAddressesAvailable, + provideBrokerAddressManually, otherCompanyInvolved, needPreCreditPeriod, isAppointingLossPayee, diff --git a/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js b/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js index 4164ab370a..15fd5ad631 100644 --- a/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js +++ b/e2e-tests/commands/insurance/complete-prepare-application-section-single-policy-type.js @@ -45,6 +45,7 @@ const { POLICY_TYPE } = FIELD_VALUES; * @param {String} brokerBuildingNumberOrName: Broker building name or number. * @param {String} brokerPostcode: Broker postcode. * @param {Boolean} multipleBrokerAddressesAvailable: Multiple broker addresses are available from Ordnance Survey. + * @param {Boolean} provideBrokerAddressManually: Provide a broker address manually, instead of selecting a result from Ordnance Survey */ const completePrepareApplicationSinglePolicyType = ({ agentChargeMethodFixedSum = false, @@ -86,6 +87,7 @@ const completePrepareApplicationSinglePolicyType = ({ brokerBuildingNumberOrName, brokerPostcode, multipleBrokerAddressesAvailable, + provideBrokerAddressManually, }) => { cy.completeBusinessSection({ differentTradingName, @@ -118,6 +120,7 @@ const completePrepareApplicationSinglePolicyType = ({ brokerBuildingNumberOrName, brokerPostcode, multipleBrokerAddressesAvailable, + provideBrokerAddressManually, otherCompanyInvolved, needPreCreditPeriod, isAppointingLossPayee, diff --git a/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js b/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js index 71b161a6ca..002193aec8 100644 --- a/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js +++ b/e2e-tests/commands/insurance/complete-sign-in-and-submit-an-application.js @@ -44,6 +44,7 @@ import completeSignInAndGoToApplication from './account/complete-sign-in-and-go- * @param {String} brokerBuildingNumberOrName: Broker building name or number. * @param {String} brokerPostcode: Broker postcode. * @param {Boolean} multipleBrokerAddressesAvailable: Multiple broker addresses are available from Ordnance Survey. + * @param {Boolean} provideBrokerAddressManually: Provide a broker address manually, instead of selecting a result from Ordnance Survey * @return {String} Application reference number */ const completeSignInAndSubmitAnApplication = ({ @@ -84,6 +85,7 @@ const completeSignInAndSubmitAnApplication = ({ brokerBuildingNumberOrName, brokerPostcode, multipleBrokerAddressesAvailable, + provideBrokerAddressManually, }) => { completeSignInAndGoToApplication({ companyNumber, @@ -125,6 +127,7 @@ const completeSignInAndSubmitAnApplication = ({ brokerBuildingNumberOrName, brokerPostcode, multipleBrokerAddressesAvailable, + provideBrokerAddressManually, }); } else { cy.completePrepareApplicationSinglePolicyType({ @@ -161,6 +164,7 @@ const completeSignInAndSubmitAnApplication = ({ brokerBuildingNumberOrName, brokerPostcode, multipleBrokerAddressesAvailable, + provideBrokerAddressManually, }); } cy.completeAndSubmitCheckYourAnswers(); diff --git a/e2e-tests/commands/insurance/policy/complete-and-submit-policy-forms.js b/e2e-tests/commands/insurance/policy/complete-and-submit-policy-forms.js index 98565d11b6..4634341516 100644 --- a/e2e-tests/commands/insurance/policy/complete-and-submit-policy-forms.js +++ b/e2e-tests/commands/insurance/policy/complete-and-submit-policy-forms.js @@ -68,7 +68,7 @@ const completeAndSubmitPolicyForms = ({ steps.push({ name: 'brokerConfirmAddress', action: () => cy.clickSubmitButton() }); } else { - cy.completeAndSubmitBrokerManualAddressForm({}); + steps.push({ name: 'brokerManualAddress', action: () => cy.completeAndSubmitBrokerManualAddressForm({}) }); } } diff --git a/e2e-tests/commands/shared-commands/assertions/assert-enter-address-manually-link.js b/e2e-tests/commands/shared-commands/assertions/assert-enter-address-manually-link.js index dad66ed644..e0cc8f551e 100644 --- a/e2e-tests/commands/shared-commands/assertions/assert-enter-address-manually-link.js +++ b/e2e-tests/commands/shared-commands/assertions/assert-enter-address-manually-link.js @@ -13,13 +13,14 @@ const baseUrl = Cypress.config('baseUrl'); * assertEnterAddressManuallyLink * Check the "enter address manually" link and redirection * @param {Number} referenceNumber: Application reference number + * @param {Number} expectedText: Expected link text */ -const assertEnterAddressManuallyLink = ({ referenceNumber }) => { +const assertEnterAddressManuallyLink = ({ referenceNumber, expectedText = LINKS.ENTER_ADDRESS_MANUALLY }) => { const expectedRoute = `${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`; - cy.checkLink(enterAddressManuallyLink(), expectedRoute, LINKS.ENTER_ADDRESS_MANUALLY); + cy.checkLink(enterAddressManuallyLink(), expectedRoute, expectedText); - enterAddressManuallyLink().click(); + cy.clickEnterAddressManuallyLink(); const expectedUrl = `${baseUrl}${expectedRoute}`; diff --git a/e2e-tests/commands/shared-commands/click-events/click-enter-address-manually-link.js b/e2e-tests/commands/shared-commands/click-events/click-enter-address-manually-link.js new file mode 100644 index 0000000000..22c04a43d2 --- /dev/null +++ b/e2e-tests/commands/shared-commands/click-events/click-enter-address-manually-link.js @@ -0,0 +1,11 @@ +import { enterAddressManuallyLink } from '../../../partials/insurance'; + +/** + * clickEnterAddressManuallyLink + * Click the "enter manually" link in the "zero addresses" page. + */ +const clickEnterAddressManuallyLink = () => { + enterAddressManuallyLink().click(); +}; + +export default clickEnterAddressManuallyLink; diff --git a/e2e-tests/commands/shared-commands/click-events/click-zero-addresses-enter-manually-link.js b/e2e-tests/commands/shared-commands/click-events/click-zero-addresses-enter-manually-link.js deleted file mode 100644 index a066a9d306..0000000000 --- a/e2e-tests/commands/shared-commands/click-events/click-zero-addresses-enter-manually-link.js +++ /dev/null @@ -1,11 +0,0 @@ -import { brokerZeroAddressesPage } from '../../../pages/insurance/policy'; - -/** - * clickZeroAddressesEnterManuallyLink - * Click the "enter manually" link in the "zero addresses" page. - */ -const clickZeroAddressesEnterManuallyLink = () => { - brokerZeroAddressesPage.outro.enterManuallyLink().click(); -}; - -export default clickZeroAddressesEnterManuallyLink; diff --git a/e2e-tests/commands/shared-commands/click-events/index.js b/e2e-tests/commands/shared-commands/click-events/index.js index d8275bd1a3..c6fc8806cb 100644 --- a/e2e-tests/commands/shared-commands/click-events/index.js +++ b/e2e-tests/commands/shared-commands/click-events/index.js @@ -10,7 +10,7 @@ Cypress.Commands.add('clickYesRadioInput', require('./click-yes-radio-input')); Cypress.Commands.add('clickAlternativeCurrencyRadioOption', require('./click-alternative-currency-radio-option')); -Cypress.Commands.add('clickZeroAddressesEntryManuallyLink', require('./click-zero-addresses-enter-manually-link')); +Cypress.Commands.add('clickEnterAddressManuallyLink', require('./click-enter-address-manually-link')); Cypress.Commands.add('clickFooterAccessibilityStatementLink', require('./click-footer-accessibility-statement-link')); Cypress.Commands.add('clickFooterCookiesLink', require('./click-footer-cookies-link')); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-with-broker-based-in-uk-manual-address.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-with-broker-based-in-uk-manual-address.spec.js new file mode 100644 index 0000000000..23bda2b13e --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/multiple-policy-type/policy-conditions/submit-an-application-multiple-policy-type-with-broker-based-in-uk-manual-address.spec.js @@ -0,0 +1,37 @@ +import { APPLICATION, BUILDING_NAMES, VALID_POSTCODES } from '../../../../../../../constants'; + +context( + 'Insurance - submit an application - Multiple policy type with a broker - Based in UK - Manual address - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + policyType: APPLICATION.POLICY_TYPE.MULTIPLE, + usingBroker: true, + brokerIsBasedInUk: true, + brokerPostcode: VALID_POSTCODES.WITH_SPACE, + brokerBuildingNumberOrName: BUILDING_NAMES.TREASURY, + provideBrokerAddressManually: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + + it('should render the application in a `submitted` state in the dashboard', () => { + cy.assertDashboardApplicationSubmitted(referenceNumber); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-with-broker-based-in-uk-manual-address.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-with-broker-based-in-uk-manual-address.spec.js new file mode 100644 index 0000000000..4955d60418 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/application-submission/single-policy-type/policy-conditions/submit-an-application-single-policy-type-with-broker-based-in-uk-manual-address.spec.js @@ -0,0 +1,36 @@ +import { BUILDING_NAMES, VALID_POSTCODES } from '../../../../../../../constants'; + +context( + 'Insurance - submit an application - Single policy type with a broker - Based in UK - Manual address - As an Exporter, I want to submit my completed credit insurance application, So that UKEF can process and make a decision on my application', + () => { + let referenceNumber; + + before(() => { + cy.completeSignInAndSubmitAnApplication({ + usingBroker: true, + brokerIsBasedInUk: true, + brokerPostcode: VALID_POSTCODES.WITH_SPACE, + brokerBuildingNumberOrName: BUILDING_NAMES.TREASURY, + provideBrokerAddressManually: true, + }).then((refNumber) => { + referenceNumber = refNumber; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + it('should successfully submit the application and redirect to `application submitted`', () => { + cy.assertApplicationSubmittedUrl(referenceNumber); + }); + + it('should render the application in a `submitted` state in the dashboard', () => { + cy.assertDashboardApplicationSubmitted(referenceNumber); + }); + }, +); 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 6275f189cc..cd38bf45ed 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,7 +15,7 @@ const { const { ROOT, - POLICY: { BROKER_MANUAL_ADDRESS_ROOT, BROKER_ZERO_ADDRESSES_ROOT, LOSS_PAYEE_ROOT }, + POLICY: { BROKER_DETAILS_ROOT, BROKER_MANUAL_ADDRESS_ROOT, LOSS_PAYEE_ROOT }, } = INSURANCE_ROUTES; const { BROKER_MANUAL_ADDRESS: FIELD_STRINGS } = FIELDS; @@ -37,12 +37,10 @@ context( cy.completeAndSubmitPolicyForms({ stopSubmittingAfter: 'brokerDetails', usingBroker: true, - isBasedInUk: true, + isBasedInUk: false, buildingNumberOrName: '123456789', }); - cy.clickZeroAddressesEntryManuallyLink(); - url = `${baseUrl}${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`; lossPayeeUrl = `${baseUrl}${ROOT}/${referenceNumber}${LOSS_PAYEE_ROOT}`; @@ -62,7 +60,7 @@ context( cy.corePageChecks({ pageTitle: CONTENT_STRINGS.PAGE_TITLE, currentHref: `${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`, - backLink: `${ROOT}/${referenceNumber}${BROKER_ZERO_ADDRESSES_ROOT}`, + backLink: `${ROOT}/${referenceNumber}${BROKER_DETAILS_ROOT}`, }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/save-and-back-based-in-uk.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/save-and-back-based-in-uk.spec.js new file mode 100644 index 0000000000..7afb3cf3ba --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/save-and-back-based-in-uk.spec.js @@ -0,0 +1,83 @@ +import { field } from '../../../../../../pages/shared'; +import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance'; +import { POLICY as POLICY_FIELD_IDS } from '../../../../../../constants/field-ids/insurance/policy'; +import application from '../../../../../../fixtures/application'; + +const { + BROKER_MANUAL_ADDRESS: { FULL_ADDRESS: FIELD_ID }, +} = POLICY_FIELD_IDS; + +const { + ROOT, + POLICY: { BROKER_MANUAL_ADDRESS_ROOT }, +} = INSURANCE_ROUTES; + +const baseUrl = Cypress.config('baseUrl'); + +context('Insurance - Policy - Broker manual address page - Based in UK - Save and back', () => { + let referenceNumber; + let url; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + // go to the page we want to test. + cy.completeAndSubmitPolicyForms({ + stopSubmittingAfter: 'brokerDetails', + usingBroker: true, + isBasedInUk: true, + buildingNumberOrName: '123456789', + }); + + cy.clickEnterAddressManuallyLink(); + + url = `${baseUrl}${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`; + + cy.assertUrl(url); + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe('when submitting an empty form via `save and go back` button', () => { + beforeEach(() => { + cy.navigateToUrl(url); + + cy.clickSaveAndBackButton(); + }); + + it('should redirect to `all sections`', () => { + cy.assertAllSectionsUrl(referenceNumber); + }); + + it('should retain the `insurance policy` task status as `in progress`', () => { + cy.checkTaskPolicyStatusIsInProgress(); + }); + }); + + describe('when submitting an answer and submitting the form via `save and go back` button', () => { + beforeEach(() => { + cy.navigateToUrl(url); + + // submit the form via 'save and go back' button + cy.keyboardInput(field(FIELD_ID).textarea(), application.BROKER[FIELD_ID]); + + cy.clickSaveAndBackButton(); + }); + + it('should redirect to `all sections`', () => { + cy.assertAllSectionsUrl(referenceNumber); + }); + + it('should retain the `insurance policy` task status as `in progress`', () => { + cy.checkTaskPolicyStatusIsInProgress(); + }); + }); +}); 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-not-based-in-uk.spec.js similarity index 91% rename from e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/save-and-back.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/policy/broker-manual-address/save-and-back-not-based-in-uk.spec.js index ad8d52bff4..73b91c90f7 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-not-based-in-uk.spec.js @@ -14,7 +14,7 @@ const { const baseUrl = Cypress.config('baseUrl'); -context('Insurance - Policy - Broker manual address page - Save and back', () => { +context('Insurance - Policy - Broker manual address page - Not based in UK - Save and back', () => { let referenceNumber; let url; @@ -26,12 +26,10 @@ context('Insurance - Policy - Broker manual address page - Save and back', () => cy.completeAndSubmitPolicyForms({ stopSubmittingAfter: 'brokerDetails', usingBroker: true, - isBasedInUk: true, + isBasedInUk: false, buildingNumberOrName: '123456789', }); - cy.clickZeroAddressesEntryManuallyLink(); - url = `${baseUrl}${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`; cy.assertUrl(url); @@ -68,6 +66,7 @@ context('Insurance - Policy - Broker manual address page - Save and back', () => // submit the form via 'save and go back' button cy.keyboardInput(field(FIELD_ID).textarea(), application.BROKER[FIELD_ID]); + cy.clickSaveAndBackButton(); }); @@ -87,9 +86,6 @@ context('Insurance - Policy - Broker manual address page - Save and back', () => // go through 8 policy forms. cy.clickSubmitButtonMultipleTimes({ count: 8 }); - // go to the "enter manually" page. - cy.clickZeroAddressesEntryManuallyLink(); - cy.checkTextareaValue({ fieldId: FIELD_ID, expectedValue: application.BROKER[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 02767bd5ca..f33b575ab4 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 @@ -33,12 +33,10 @@ context('Insurance - Policy - Broker manual address page - validation', () => { cy.completeAndSubmitPolicyForms({ stopSubmittingAfter: 'brokerDetails', usingBroker: true, - isBasedInUk: true, + isBasedInUk: false, buildingNumberOrName: '123456789', }); - cy.clickZeroAddressesEntryManuallyLink(); - url = `${baseUrl}${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`; cy.assertUrl(url); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-zero-addresses/broker-zero-addresses-page.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-zero-addresses/broker-zero-addresses-page.spec.js index 9decc166a5..d9df38e8ed 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-zero-addresses/broker-zero-addresses-page.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/broker-zero-addresses/broker-zero-addresses-page.spec.js @@ -10,7 +10,7 @@ const CONTENT_STRINGS = PAGES.INSURANCE.POLICY.BROKER_ZERO_ADDRESSES; const { ROOT, - POLICY: { BROKER_DETAILS_ROOT, BROKER_MANUAL_ADDRESS_ROOT, BROKER_ZERO_ADDRESSES_ROOT }, + POLICY: { BROKER_DETAILS_ROOT, BROKER_ZERO_ADDRESSES_ROOT }, } = INSURANCE_ROUTES; const { @@ -92,9 +92,10 @@ context( }); it('renders outro `enter manually` link', () => { - const expectedHref = `${ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`; - - cy.checkLink(outro.enterManuallyLink(), expectedHref, CONTENT_STRINGS.OUTRO.ENTER_MANUALLY); + cy.assertEnterAddressManuallyLink({ + referenceNumber, + expectedText: CONTENT_STRINGS.OUTRO.ENTER_MANUALLY, + }); }); }); }, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-multiple-addresses-available.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-multiple-addresses-available.spec.js index bfbcb85603..40604f124b 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-multiple-addresses-available.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-multiple-addresses-available.spec.js @@ -17,7 +17,7 @@ const { const { ROOT, - POLICY: { BROKER_ADDRESSES_CHANGE, BROKER_CONFIRM_ADDRESS_CHANGE, CHECK_YOUR_ANSWERS }, + POLICY: { BROKER_ADDRESSES_CHANGE, BROKER_CONFIRM_ADDRESS_CHANGE, BROKER_DETAILS_ROOT, BROKER_MANUAL_ADDRESS_ROOT, CHECK_YOUR_ANSWERS }, } = INSURANCE_ROUTES; const optionValue = `${UNDERGROUND_STATION.ADDRESS_LINE_1} ${UNDERGROUND_STATION.ADDRESS_LINE_2}`; @@ -95,6 +95,39 @@ context( it(`should NOT render ${FULL_ADDRESS} field`, () => { checkSummaryList.BROKER[FULL_ADDRESS]({ shouldRender: false }); }); + + describe(`when going back to ${BROKER_DETAILS_ROOT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + + summaryList.field(NAME).changeLink().click(); + }); + + it('should retain the new values', () => { + cy.assertBrokerDetailsFieldValues({ + isBasedInUk: true, + expectedPostcode: WESTMINSTER_BRIDGE_STREET.POSTCODE, + expectedBuildingNumberOrName: WESTMINSTER_BRIDGE_STREET.BUILDING_NAME, + }); + }); + }); + + describe(`when going to ${BROKER_MANUAL_ADDRESS_ROOT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + + summaryList.field(SELECT_THE_ADDRESS).changeLink().click(); + + cy.clickEnterAddressManuallyLink(); + }); + + it(`should have an empty ${FULL_ADDRESS} value`, () => { + cy.checkTextareaValue({ + fieldId: FULL_ADDRESS, + expectedValue: '', + }); + }); + }); }); }, ); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-multiple-addresses-enter-address-manually.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-multiple-addresses-enter-address-manually.spec.js new file mode 100644 index 0000000000..575228ee1a --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-multiple-addresses-enter-address-manually.spec.js @@ -0,0 +1,143 @@ +import { summaryList } from '../../../../../../../pages/shared'; +import { brokerConfirmAddressPage } from '../../../../../../../pages/insurance/policy'; +import { ADDRESS_LOOKUP_INPUT_EXAMPLES } from '../../../../../../../constants'; +import { POLICY as POLICY_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/policy'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; +import checkSummaryList from '../../../../../../../commands/insurance/check-policy-summary-list'; +import application from '../../../../../../../fixtures/application'; + +const { WESTMINSTER_BRIDGE_STREET } = ADDRESS_LOOKUP_INPUT_EXAMPLES; + +const { + USING_BROKER, + IS_BASED_IN_UK, + BROKER_DETAILS: { NAME, EMAIL }, + BROKER_ADDRESSES: { SELECT_THE_ADDRESS }, + BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, +} = POLICY_FIELD_IDS; + +const { + ROOT, + POLICY: { + BROKER_ADDRESSES_CHANGE, + BROKER_CONFIRM_ADDRESS_CHANGE, + BROKER_DETAILS_ROOT, + BROKER_MANUAL_ADDRESS_ROOT, + BROKER_MANUAL_ADDRESS_CHANGE, + CHECK_YOUR_ANSWERS, + }, +} = INSURANCE_ROUTES; + +const baseUrl = Cypress.config('baseUrl'); + +context( + 'Insurance - Policy - Change your answers - Broker address - Not based in UK to Based in UK - Multiple addresses available - Enter address manually - As an exporter, I want to change my answers to the broker section', + () => { + let referenceNumber; + let checkYourAnswersUrl; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completePolicySection({ + usingBroker: true, + brokerIsBasedInUk: false, + }); + + checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe('when clicking the `change` link', () => { + it(`should redirect to ${BROKER_CONFIRM_ADDRESS_CHANGE}`, () => { + cy.navigateToUrl(checkYourAnswersUrl); + + summaryList.field(FULL_ADDRESS).changeLink().click(); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: BROKER_CONFIRM_ADDRESS_CHANGE, fieldId: FULL_ADDRESS }); + }); + }); + + describe('after changing the answer from yes to no and submitting the UK broker address manually', () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + }); + + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => { + summaryList.field(FULL_ADDRESS).changeLink().click(); + + brokerConfirmAddressPage.useDifferentAddressLink().click(); + + cy.completeAndSubmitBrokerDetailsForm({ + isBasedInUk: true, + postcode: WESTMINSTER_BRIDGE_STREET.POSTCODE, + buildingNumberOrName: WESTMINSTER_BRIDGE_STREET.BUILDING_NAME, + }); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: BROKER_ADDRESSES_CHANGE }); + + cy.clickEnterAddressManuallyLink(); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: BROKER_MANUAL_ADDRESS_CHANGE }); + + cy.completeAndSubmitBrokerManualAddressForm({}); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS }); + }); + + it(`should render the new ${SELECT_THE_ADDRESS} answer and related fields`, () => { + checkSummaryList[USING_BROKER]({ usingBroker: true }); + checkSummaryList.BROKER[NAME](); + checkSummaryList.BROKER[EMAIL](); + + checkSummaryList.BROKER[FULL_ADDRESS]({ shouldRender: true }); + }); + + it(`should NOT render ${SELECT_THE_ADDRESS} field`, () => { + checkSummaryList.BROKER[SELECT_THE_ADDRESS]({ shouldRender: false }); + }); + + describe(`when going back to ${BROKER_DETAILS_ROOT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + + summaryList.field(NAME).changeLink().click(); + }); + + it(`should retain the new ${IS_BASED_IN_UK} value and have empty address lookup fields`, () => { + cy.assertBrokerDetailsFieldValues({ + isBasedInUk: true, + expectedPostcode: '', + expectedBuildingNumberOrName: '', + }); + }); + }); + + describe(`when going to ${BROKER_MANUAL_ADDRESS_ROOT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + + summaryList.field(FULL_ADDRESS).changeLink().click(); + + cy.clickEnterAddressManuallyLink(); + }); + + it('should have the submitted value', () => { + cy.checkTextareaValue({ + fieldId: FULL_ADDRESS, + expectedValue: application.BROKER[FULL_ADDRESS], + }); + }); + }); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-single-address-available.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-single-address-available.spec.js index 7bbd5bfe32..505ffe4e53 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-single-address-available.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-single-address-available.spec.js @@ -13,7 +13,7 @@ const { const { ROOT, - POLICY: { BROKER_CONFIRM_ADDRESS_CHANGE, CHECK_YOUR_ANSWERS }, + POLICY: { BROKER_CONFIRM_ADDRESS_CHANGE, BROKER_DETAILS_ROOT, BROKER_MANUAL_ADDRESS_ROOT, CHECK_YOUR_ANSWERS }, } = INSURANCE_ROUTES; const baseUrl = Cypress.config('baseUrl'); @@ -83,6 +83,35 @@ context( it(`should NOT render ${FULL_ADDRESS} field`, () => { checkSummaryList.BROKER[FULL_ADDRESS]({ shouldRender: false }); }); + + describe(`when going back to ${BROKER_DETAILS_ROOT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + + summaryList.field(NAME).changeLink().click(); + }); + + it('should retain the new values', () => { + cy.assertBrokerDetailsFieldValues({ isBasedInUk: true }); + }); + }); + + describe(`when going to ${BROKER_MANUAL_ADDRESS_ROOT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + + summaryList.field(SELECT_THE_ADDRESS).changeLink().click(); + + cy.clickEnterAddressManuallyLink(); + }); + + it(`should have an empty ${FULL_ADDRESS} value`, () => { + cy.checkTextareaValue({ + fieldId: FULL_ADDRESS, + expectedValue: '', + }); + }); + }); }); }, ); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-single-address-enter-address-manually.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-single-address-enter-address-manually.spec.js new file mode 100644 index 0000000000..3332470dc5 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-address-not-based-in-uk-to-based-in-uk-single-address-enter-address-manually.spec.js @@ -0,0 +1,132 @@ +import { summaryList } from '../../../../../../../pages/shared'; +import { brokerConfirmAddressPage } from '../../../../../../../pages/insurance/policy'; +import { POLICY as POLICY_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/policy'; +import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; +import checkSummaryList from '../../../../../../../commands/insurance/check-policy-summary-list'; +import application from '../../../../../../../fixtures/application'; + +const { + USING_BROKER, + IS_BASED_IN_UK, + BROKER_DETAILS: { NAME, EMAIL }, + BROKER_ADDRESSES: { SELECT_THE_ADDRESS }, + BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, +} = POLICY_FIELD_IDS; + +const { + ROOT, + POLICY: { BROKER_CONFIRM_ADDRESS_CHANGE, BROKER_DETAILS_ROOT, BROKER_MANUAL_ADDRESS_ROOT, BROKER_MANUAL_ADDRESS_CHANGE, CHECK_YOUR_ANSWERS }, +} = INSURANCE_ROUTES; + +const baseUrl = Cypress.config('baseUrl'); + +context( + 'Insurance - Policy - Change your answers - Broker address - Not based in UK to Based in UK - Single address available - Enter address manually - As an exporter, I want to change my answers to the broker section', + () => { + let referenceNumber; + let checkYourAnswersUrl; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + cy.completePolicySection({ + usingBroker: true, + brokerIsBasedInUk: false, + }); + + checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe('when clicking the `change` link', () => { + it(`should redirect to ${BROKER_CONFIRM_ADDRESS_CHANGE}`, () => { + cy.navigateToUrl(checkYourAnswersUrl); + + summaryList.field(FULL_ADDRESS).changeLink().click(); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: BROKER_CONFIRM_ADDRESS_CHANGE, fieldId: FULL_ADDRESS }); + }); + }); + + describe('after changing the answer from yes to no and submitting the UK broker address manually', () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + }); + + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => { + summaryList.field(FULL_ADDRESS).changeLink().click(); + + brokerConfirmAddressPage.useDifferentAddressLink().click(); + + cy.completeAndSubmitBrokerDetailsForm({ + isBasedInUk: true, + brokerBuildingNumberOrName: '123456789', + }); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: BROKER_CONFIRM_ADDRESS_CHANGE }); + + cy.clickEnterAddressManuallyLink(); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: BROKER_MANUAL_ADDRESS_CHANGE }); + + cy.completeAndSubmitBrokerManualAddressForm({}); + + cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS }); + }); + + it(`should render the new ${SELECT_THE_ADDRESS} answer and related fields`, () => { + checkSummaryList[USING_BROKER]({ usingBroker: true }); + checkSummaryList.BROKER[NAME](); + checkSummaryList.BROKER[EMAIL](); + + checkSummaryList.BROKER[FULL_ADDRESS]({ shouldRender: true }); + }); + + it(`should NOT render ${SELECT_THE_ADDRESS} field`, () => { + checkSummaryList.BROKER[SELECT_THE_ADDRESS]({ shouldRender: false }); + }); + + describe(`when going back to ${BROKER_DETAILS_ROOT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + + summaryList.field(NAME).changeLink().click(); + }); + + it(`should retain the new ${IS_BASED_IN_UK} value and have empty address lookup fields`, () => { + cy.assertBrokerDetailsFieldValues({ + isBasedInUk: true, + expectedPostcode: '', + expectedBuildingNumberOrName: '', + }); + }); + }); + + describe(`when going to ${BROKER_MANUAL_ADDRESS_ROOT}`, () => { + beforeEach(() => { + cy.navigateToUrl(checkYourAnswersUrl); + + summaryList.field(FULL_ADDRESS).changeLink().click(); + + cy.clickEnterAddressManuallyLink(); + }); + + it('should have the submitted value', () => { + cy.checkTextareaValue({ + fieldId: FULL_ADDRESS, + expectedValue: application.BROKER[FULL_ADDRESS], + }); + }); + }); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-based-in-uk-no-to-yes.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-based-in-uk-no-to-yes.spec.js deleted file mode 100644 index 90298d4498..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-based-in-uk-no-to-yes.spec.js +++ /dev/null @@ -1,88 +0,0 @@ -import { summaryList } from '../../../../../../../pages/shared'; -import { POLICY as POLICY_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/policy'; -import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance'; -import checkSummaryList from '../../../../../../../commands/insurance/check-policy-summary-list'; - -const { - USING_BROKER, - BROKER_DETAILS: { NAME, EMAIL }, - BROKER_ADDRESSES: { SELECT_THE_ADDRESS }, - BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, -} = POLICY_FIELD_IDS; - -const { - ROOT, - POLICY: { BROKER_DETAILS_ROOT, CHECK_YOUR_ANSWERS }, -} = INSURANCE_ROUTES; - -const baseUrl = Cypress.config('baseUrl'); - -context('Insurance - Policy - Change your answers - Broker based in UK - No to yes - As an exporter, I want to change my answers to the broker section', () => { - let referenceNumber; - let checkYourAnswersUrl; - - before(() => { - cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { - referenceNumber = refNumber; - - cy.completePolicySection({ usingBroker: true, brokerIsBasedInUk: false }); - - checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; - }); - }); - - beforeEach(() => { - cy.saveSession(); - }); - - after(() => { - cy.deleteApplication(referenceNumber); - }); - - describe('after changing the answer from no to yes', () => { - before(() => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(NAME).changeLink().click(); - - cy.completeAndSubmitBrokerDetailsForm({ isBasedInUk: true }); - - // submit the "confirm broker address" form - cy.clickSubmitButton(); - }); - - it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => { - cy.assertChangeAnswersPageUrl({ referenceNumber, route: CHECK_YOUR_ANSWERS, fieldId: NAME }); - }); - - it('should render new broker details summary list rows', () => { - cy.navigateToUrl(checkYourAnswersUrl); - - checkSummaryList[USING_BROKER]({ usingBroker: true }); - - checkSummaryList.BROKER[NAME](); - - checkSummaryList.BROKER[EMAIL](); - - checkSummaryList.BROKER[SELECT_THE_ADDRESS]({ shouldRender: true }); - }); - - it(`should NOT render a ${FULL_ADDRESS} summary list row`, () => { - cy.navigateToUrl(checkYourAnswersUrl); - - checkSummaryList.BROKER[FULL_ADDRESS]({ shouldRender: false }); - }); - - describe(`when going back to ${BROKER_DETAILS_ROOT}`, () => { - beforeEach(() => { - cy.navigateToUrl(checkYourAnswersUrl); - - summaryList.field(NAME).changeLink().click(); - }); - - it('should retain the existing values', () => { - cy.assertBrokerDetailsFieldValues({ isBasedInUk: true }); - }); - }); - }); -}); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-using-a-broker-yes-to-no.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-using-a-broker-yes-to-no.spec.js index aaac157e9e..905fd3cced 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-using-a-broker-yes-to-no.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/change-your-answers/broker/change-your-answers-field-using-a-broker-yes-to-no.spec.js @@ -112,7 +112,7 @@ context('Insurance - Policy - Change your answers - Using a broker - Yes to no - buildingNumberOrName: '123456789', }); - cy.clickZeroAddressesEntryManuallyLink(); + cy.clickEnterAddressManuallyLink(); }); it('should have empty field values', () => { diff --git a/e2e-tests/pages/insurance/policy/brokerZeroAddresses.js b/e2e-tests/pages/insurance/policy/brokerZeroAddresses.js index 0a6219b6f9..de5f35d7a8 100644 --- a/e2e-tests/pages/insurance/policy/brokerZeroAddresses.js +++ b/e2e-tests/pages/insurance/policy/brokerZeroAddresses.js @@ -5,7 +5,6 @@ const brokerZeroAddresses = { youCan: () => cy.get('[data-cy="outro-you-can"'), searchAgainLink: () => cy.get('[data-cy="outro-search-again-link"'), or: () => cy.get('[data-cy="outro-or"'), - enterManuallyLink: () => cy.get('[data-cy="outro-enter-manually-link"'), }, }; diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 750d60bac2..5630a34900 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -7758,16 +7758,15 @@ var based_in_the_uk_default = mapBrokerAddressBasedInTheUk; // generate-xlsx/map-application-to-XLSX/map-policy/map-broker/map-broker-address/index.ts var { - BROKER_DETAILS: { IS_BASED_IN_UK }, BROKER_MANUAL_ADDRESS: { FULL_ADDRESS: FULL_ADDRESS3 }, } = POLICY; var { FIELDS: FIELDS11 } = XLSX; var mapBrokerAddress = (broker) => { let fieldValue = ''; - if (broker[IS_BASED_IN_UK]) { - fieldValue = based_in_the_uk_default(broker); - } else { + if (broker[FULL_ADDRESS3]) { fieldValue = broker[FULL_ADDRESS3]; + } else { + fieldValue = based_in_the_uk_default(broker); } return xlsx_row_default(String(FIELDS11[FULL_ADDRESS3]), fieldValue); }; diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-policy/map-broker/map-broker-address/index.test.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-policy/map-broker/map-broker-address/index.test.ts index c3dce59070..8487781e35 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-policy/map-broker/map-broker-address/index.test.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-policy/map-broker/map-broker-address/index.test.ts @@ -6,40 +6,37 @@ import xlsxRow from '../../../helpers/xlsx-row'; import { mockApplication } from '../../../../../test-mocks'; const { - BROKER_DETAILS: { IS_BASED_IN_UK }, BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, } = FIELD_IDS; const { FIELDS } = XLSX; describe('api/generate-xlsx/map-application-to-xlsx/map-policy/map-broker/map-broker-address', () => { - describe(`when ${IS_BASED_IN_UK} is true`, () => { + describe(`when ${FULL_ADDRESS} is populated`, () => { const mockBroker = { ...mockApplication.broker, - [IS_BASED_IN_UK]: true, + [FULL_ADDRESS]: 'Mock full broker address', }; - it('should return xlsxRow with the value via mapBrokerAddressBasedInTheUk', () => { + it(`should return xlsxRow with the value as ${FULL_ADDRESS}`, () => { const result = mapBrokerAddress(mockBroker); - const expectedValue = mapBrokerAddressBasedInTheUk(mockBroker); - - const expected = xlsxRow(String(FIELDS[FULL_ADDRESS]), expectedValue); + const expected = xlsxRow(String(FIELDS[FULL_ADDRESS]), mockBroker[FULL_ADDRESS]); expect(result).toEqual(expected); }); }); - describe(`when ${IS_BASED_IN_UK} is false`, () => { - const mockBroker = { - ...mockApplication.broker, - [IS_BASED_IN_UK]: false, - }; + describe(`when ${FULL_ADDRESS} is an empty string`, () => { + it('should return xlsxRow with the value via mapBrokerAddressBasedInTheUk', () => { + const mockBroker = { + ...mockApplication.broker, + [FULL_ADDRESS]: '', + }; - it(`should return xlsxRow with the value as ${FULL_ADDRESS}`, () => { const result = mapBrokerAddress(mockBroker); - const expectedValue = mockBroker[FULL_ADDRESS]; + const expectedValue = mapBrokerAddressBasedInTheUk(mockBroker); const expected = xlsxRow(String(FIELDS[FULL_ADDRESS]), expectedValue); diff --git a/src/api/generate-xlsx/map-application-to-XLSX/map-policy/map-broker/map-broker-address/index.ts b/src/api/generate-xlsx/map-application-to-XLSX/map-policy/map-broker/map-broker-address/index.ts index 54b7208ff2..2daa2b4498 100644 --- a/src/api/generate-xlsx/map-application-to-XLSX/map-policy/map-broker/map-broker-address/index.ts +++ b/src/api/generate-xlsx/map-application-to-XLSX/map-policy/map-broker/map-broker-address/index.ts @@ -5,7 +5,6 @@ import xlsxRow from '../../../helpers/xlsx-row'; import { ApplicationBroker } from '../../../../../types'; const { - BROKER_DETAILS: { IS_BASED_IN_UK }, BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, } = FIELD_IDS; @@ -14,18 +13,18 @@ const { FIELDS } = XLSX; /** * mapBrokerAddress * Map an application's broker address fields into an object for XLSX generation - * - If the broker is based in the UK, consume mapBrokerAddressBasedInTheUk. - * - Otherwise, simply consume the FULL_ADDRESS field. + * - If the broker has a FULL_ADDRESS field, consume the field value. + * - Otherwise, consume mapBrokerAddressBasedInTheUk. * @param {ApplicationBroker} broker * @returns {object} Object for XLSX generation */ const mapBrokerAddress = (broker: ApplicationBroker) => { let fieldValue = ''; - if (broker[IS_BASED_IN_UK]) { - fieldValue = mapBrokerAddressBasedInTheUk(broker); - } else { + if (broker[FULL_ADDRESS]) { fieldValue = broker[FULL_ADDRESS]; + } else { + fieldValue = mapBrokerAddressBasedInTheUk(broker); } return xlsxRow(String(FIELDS[FULL_ADDRESS]), fieldValue); diff --git a/src/ui/server/controllers/insurance/all-sections/index.test.ts b/src/ui/server/controllers/insurance/all-sections/index.test.ts index a11edec4d9..64e1e2c738 100644 --- a/src/ui/server/controllers/insurance/all-sections/index.test.ts +++ b/src/ui/server/controllers/insurance/all-sections/index.test.ts @@ -54,7 +54,7 @@ describe('controllers/insurance/all-sections', () => { }, } = exportContract; - const { isUsingBroker, isBasedInUk: brokerIsBasedInUk } = broker; + const { isUsingBroker, isBasedInUk: brokerIsBasedInUk, fullAddress: brokerFullAddress } = broker; const { hasDifferentTradingName } = company; const { hasAntiBriberyCodeOfConduct } = declaration; const { buyerTradingHistory, relationship } = buyer; @@ -71,6 +71,7 @@ describe('controllers/insurance/all-sections', () => { jointlyInsuredParty.requested, isUsingBroker, brokerIsBasedInUk, + brokerFullAddress, isAppointingLossPayee, lossPayeeIsLocatedInUk, lossPayeeIsLocatedInternationally, diff --git a/src/ui/server/controllers/insurance/all-sections/index.ts b/src/ui/server/controllers/insurance/all-sections/index.ts index 681461da14..a2e3ce74cd 100644 --- a/src/ui/server/controllers/insurance/all-sections/index.ts +++ b/src/ui/server/controllers/insurance/all-sections/index.ts @@ -46,7 +46,7 @@ export const get = (req: Request, res: Response) => { }, } = exportContract; - const { isUsingBroker, isBasedInUk: brokerIsBasedInUk } = broker; + const { isUsingBroker, isBasedInUk: brokerIsBasedInUk, fullAddress: brokerFullAddress } = broker; const { hasDifferentTradingName } = company; const { hasAntiBriberyCodeOfConduct } = declaration; const { buyerTradingHistory, relationship } = buyer; @@ -63,6 +63,7 @@ export const get = (req: Request, res: Response) => { jointlyInsuredParty.requested, isUsingBroker, brokerIsBasedInUk, + brokerFullAddress, isAppointingLossPayee, lossPayeeIsLocatedInUk, lossPayeeIsLocatedInternationally, 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 b7ceea8b70..25884584a5 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 @@ -4,6 +4,7 @@ import { TEMPLATES } from '../../../../constants'; import { INSURANCE_ROUTES } from '../../../../constants/routes/insurance'; import POLICY_FIELD_IDS from '../../../../constants/field-ids/insurance/policy'; import { POLICY_FIELDS } from '../../../../content-strings/fields/insurance/policy'; +import generateEnterBrokerAddressManuallyUrl from '../../../../helpers/generate-enter-broker-address-manually-url'; import insuranceCorePageVariables from '../../../../helpers/page-variables/core/insurance'; import getUserNameFromSession from '../../../../helpers/get-user-name-from-session'; import api from '../../../../api'; @@ -13,6 +14,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'; import { mockReq, mockRes, mockApplication, mockOrdnanceSurveyAddressResponse, mockSpyPromiseRejection, referenceNumber } from '../../../../test-mocks'; @@ -29,7 +31,6 @@ const { BROKER_DETAILS_ROOT, BROKER_ZERO_ADDRESSES_ROOT, BROKER_CONFIRM_ADDRESS_ROOT, - BROKER_MANUAL_ADDRESS_ROOT, BROKER_ADDRESSES_CHANGE, CHECK_YOUR_ANSWERS, }, @@ -42,6 +43,8 @@ const { postcode, buildingNumberOrName } = broker; const mappedAddresses = mapOrdnanceSurveyAddresses(mockOrdnanceSurveyAddressResponse.addresses, broker); +let isAChangeRoute = false; + describe('controllers/insurance/policy/broker-addresses', () => { let req: Request; let res: Response; @@ -54,6 +57,8 @@ describe('controllers/insurance/policy/broker-addresses', () => { api.keystone.getOrdnanceSurveyAddresses = getOrdnanceSurveyAddressesSpy; mapAndSave.broker = jest.fn(() => Promise.resolve(true)); + + isAChangeRoute = isChangeRoute(req.originalUrl); }); afterAll(() => { @@ -95,7 +100,7 @@ describe('controllers/insurance/policy/broker-addresses', () => { ...BROKER_ADDRESSES[SELECT_THE_ADDRESS], }, SEARCH_AGAIN_URL: `${INSURANCE_ROOT}/${referenceNumber}${BROKER_DETAILS_ROOT}`, - ENTER_ADDRESS_MANUALLY_URL: `${INSURANCE_ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`, + ENTER_ADDRESS_MANUALLY_URL: generateEnterBrokerAddressManuallyUrl(referenceNumber, isAChangeRoute), SAVE_AND_BACK_URL: `${INSURANCE_ROOT}/${referenceNumber}${BROKER_ADDRESSES_SAVE_AND_BACK}`, }; @@ -103,7 +108,7 @@ describe('controllers/insurance/policy/broker-addresses', () => { it('should have correct properties', () => { const mockTotalAddresses = 1; - const result = pageVariables(referenceNumber, mockTotalAddresses); + const result = pageVariables(referenceNumber, mockTotalAddresses, isAChangeRoute); const expected = { ...expectedGenericProperties, @@ -121,7 +126,7 @@ describe('controllers/insurance/policy/broker-addresses', () => { it('should have correct properties', () => { const mockTotalAddresses = 2; - const result = pageVariables(referenceNumber, mockTotalAddresses); + const result = pageVariables(referenceNumber, mockTotalAddresses, isAChangeRoute); const expected = { ...expectedGenericProperties, @@ -256,7 +261,7 @@ describe('controllers/insurance/policy/broker-addresses', () => { PAGE_CONTENT_STRINGS, BACK_LINK: req.headers.referer, }), - ...pageVariables(referenceNumber, mockOrdnanceSurveyAddressResponse.addresses.length), + ...pageVariables(referenceNumber, mockOrdnanceSurveyAddressResponse.addresses.length, isAChangeRoute), userName: getUserNameFromSession(req.session.user), mappedAddresses, postcode, @@ -367,7 +372,7 @@ describe('controllers/insurance/policy/broker-addresses', () => { PAGE_CONTENT_STRINGS, BACK_LINK: req.headers.referer, }), - ...pageVariables(referenceNumber, mockOrdnanceSurveyAddressResponse.addresses.length), + ...pageVariables(referenceNumber, mockOrdnanceSurveyAddressResponse.addresses.length, isAChangeRoute), userName: getUserNameFromSession(req.session.user), mappedAddresses, postcode, 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 bb8e238d89..d720a98224 100644 --- a/src/ui/server/controllers/insurance/policy/broker-addresses/index.ts +++ b/src/ui/server/controllers/insurance/policy/broker-addresses/index.ts @@ -3,6 +3,7 @@ import { TEMPLATES } from '../../../../constants'; import { INSURANCE_ROUTES } from '../../../../constants/routes/insurance'; import POLICY_FIELD_IDS from '../../../../constants/field-ids/insurance/policy'; import { POLICY_FIELDS } from '../../../../content-strings/fields/insurance/policy'; +import generateEnterBrokerAddressManuallyUrl from '../../../../helpers/generate-enter-broker-address-manually-url'; import insuranceCorePageVariables from '../../../../helpers/page-variables/core/insurance'; import getUserNameFromSession from '../../../../helpers/get-user-name-from-session'; import api from '../../../../api'; @@ -26,7 +27,6 @@ const { BROKER_ZERO_ADDRESSES_ROOT, BROKER_CONFIRM_ADDRESS_ROOT, BROKER_CONFIRM_ADDRESS_CHANGE, - BROKER_MANUAL_ADDRESS_ROOT, CHECK_YOUR_ANSWERS, }, } = INSURANCE_ROUTES; @@ -46,9 +46,10 @@ export const TEMPLATE = TEMPLATES.INSURANCE.POLICY.BROKER_ADDRESSES; * Page fields and "save and go back" URL * @param {Number} referenceNumber: Application reference number * @param {Number} totalAddresses: Total amount of addresses found + * @param {Boolean} isAChangeRoute: If the last part of a string/URL is 'change' * @returns {Object} Page variables */ -export const pageVariables = (referenceNumber: number, totalAddresses: number) => { +export const pageVariables = (referenceNumber: number, totalAddresses: number, isAChangeRoute: boolean) => { let ADDRESS_STRING = PAGE_CONTENT_STRINGS.INTRO.ADDRESSES; if (totalAddresses === 1) { @@ -65,7 +66,7 @@ export const pageVariables = (referenceNumber: number, totalAddresses: number) = ADDRESSES_FOUND: `${totalAddresses} ${ADDRESS_STRING} ${PAGE_CONTENT_STRINGS.INTRO.FOUND_FOR}`, }, SEARCH_AGAIN_URL: `${INSURANCE_ROOT}/${referenceNumber}${BROKER_DETAILS_ROOT}`, - ENTER_ADDRESS_MANUALLY_URL: `${INSURANCE_ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`, + ENTER_ADDRESS_MANUALLY_URL: generateEnterBrokerAddressManuallyUrl(referenceNumber, isAChangeRoute), SAVE_AND_BACK_URL: `${INSURANCE_ROOT}/${referenceNumber}${BROKER_ADDRESSES_SAVE_AND_BACK}`, }; }; @@ -111,6 +112,8 @@ export const get = async (req: Request, res: Response) => { return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${BROKER_ZERO_ADDRESSES_ROOT}`); } + const isAChangeRoute = isChangeRoute(req.originalUrl); + const { addresses } = response; /** @@ -130,7 +133,7 @@ export const get = async (req: Request, res: Response) => { return res.redirect(PROBLEM_WITH_SERVICE); } - if (isChangeRoute(req.originalUrl)) { + if (isAChangeRoute) { console.info(`Policy - broker addresses - Redirecting to ${BROKER_CONFIRM_ADDRESS_CHANGE}`); return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${BROKER_CONFIRM_ADDRESS_CHANGE}`); @@ -145,7 +148,7 @@ export const get = async (req: Request, res: Response) => { return res.render(TEMPLATE, { ...insuranceCorePageVariables({ PAGE_CONTENT_STRINGS, BACK_LINK: req.headers.referer }), - ...pageVariables(referenceNumber, addresses.length), + ...pageVariables(referenceNumber, addresses.length, isAChangeRoute), userName: getUserNameFromSession(req.session.user), mappedAddresses, postcode, @@ -186,13 +189,15 @@ export const post = async (req: Request, res: Response) => { const mappedAddresses = mapOrdnanceSurveyAddresses(addresses, broker); + const isAChangeRoute = isChangeRoute(req.originalUrl); + if (validationErrors) { return res.render(TEMPLATE, { ...insuranceCorePageVariables({ PAGE_CONTENT_STRINGS, BACK_LINK: req.headers.referer, }), - ...pageVariables(referenceNumber, addresses.length), + ...pageVariables(referenceNumber, addresses.length, isAChangeRoute), userName: getUserNameFromSession(req.session.user), mappedAddresses, postcode, @@ -208,7 +213,7 @@ export const post = async (req: Request, res: Response) => { return res.redirect(PROBLEM_WITH_SERVICE); } - if (isChangeRoute(req.originalUrl)) { + if (isAChangeRoute) { return res.redirect(`${INSURANCE_ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`); } diff --git a/src/ui/server/controllers/insurance/policy/broker-confirm-address/index.test.ts b/src/ui/server/controllers/insurance/policy/broker-confirm-address/index.test.ts index bd9c15787a..98d77b30db 100644 --- a/src/ui/server/controllers/insurance/policy/broker-confirm-address/index.test.ts +++ b/src/ui/server/controllers/insurance/policy/broker-confirm-address/index.test.ts @@ -3,6 +3,7 @@ import { PAGES } from '../../../../content-strings'; import { TEMPLATES } from '../../../../constants'; import { POLICY as POLICY_FIELD_IDS } from '../../../../constants/field-ids/insurance/policy'; import { INSURANCE_ROUTES } from '../../../../constants/routes/insurance'; +import generateEnterBrokerAddressManuallyUrl from '../../../../helpers/generate-enter-broker-address-manually-url'; import insuranceCorePageVariables from '../../../../helpers/page-variables/core/insurance'; import getUserNameFromSession from '../../../../helpers/get-user-name-from-session'; import isChangeRoute from '../../../../helpers/is-change-route'; @@ -18,15 +19,7 @@ const { const { INSURANCE_ROOT, ALL_SECTIONS, - POLICY: { - BROKER_DETAILS_ROOT, - BROKER_DETAILS_CHANGE, - BROKER_CONFIRM_ADDRESS_ROOT, - BROKER_CONFIRM_ADDRESS_CHANGE, - BROKER_MANUAL_ADDRESS_ROOT, - LOSS_PAYEE_ROOT, - CHECK_YOUR_ANSWERS, - }, + POLICY: { BROKER_DETAILS_ROOT, BROKER_DETAILS_CHANGE, BROKER_CONFIRM_ADDRESS_ROOT, BROKER_CONFIRM_ADDRESS_CHANGE, LOSS_PAYEE_ROOT, CHECK_YOUR_ANSWERS }, PROBLEM_WITH_SERVICE, } = INSURANCE_ROUTES; @@ -58,17 +51,19 @@ describe('controllers/insurance/policy/broker-confirm-address', () => { describe('pageVariables', () => { const expectedGenericVariables = { USE_DIFFERENT_ADDRESS_URL: `${INSURANCE_ROOT}/${referenceNumber}${BROKER_DETAILS_ROOT}`, - ENTER_ADDRESS_MANUALLY_URL: `${INSURANCE_ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`, SAVE_AND_BACK_URL: `${INSURANCE_ROOT}/${referenceNumber}${ALL_SECTIONS}`, }; describe("when the url's last substring is `change`", () => { it('should return the correct properties', () => { - const result = pageVariables(referenceNumber, isChangeRoute(BROKER_CONFIRM_ADDRESS_CHANGE)); + const isAChangeRoute = isChangeRoute(BROKER_CONFIRM_ADDRESS_CHANGE); + + const result = pageVariables(referenceNumber, isAChangeRoute); const expected = { ...expectedGenericVariables, USE_DIFFERENT_ADDRESS_URL: `${INSURANCE_ROOT}/${referenceNumber}${BROKER_DETAILS_CHANGE}`, + ENTER_ADDRESS_MANUALLY_URL: generateEnterBrokerAddressManuallyUrl(referenceNumber, isAChangeRoute), }; expect(result).toEqual(expected); @@ -77,9 +72,14 @@ describe('controllers/insurance/policy/broker-confirm-address', () => { describe("when the url's last substring is NOT `change`", () => { it('should return the correct properties', () => { - const result = pageVariables(referenceNumber, isChangeRoute(BROKER_CONFIRM_ADDRESS_ROOT)); + const isAChangeRoute = isChangeRoute(BROKER_CONFIRM_ADDRESS_ROOT); + + const result = pageVariables(referenceNumber, isAChangeRoute); - const expected = expectedGenericVariables; + const expected = { + ...expectedGenericVariables, + ENTER_ADDRESS_MANUALLY_URL: generateEnterBrokerAddressManuallyUrl(referenceNumber, isAChangeRoute), + }; expect(result).toEqual(expected); }); diff --git a/src/ui/server/controllers/insurance/policy/broker-confirm-address/index.ts b/src/ui/server/controllers/insurance/policy/broker-confirm-address/index.ts index fe9191df9d..c16aa96dc3 100644 --- a/src/ui/server/controllers/insurance/policy/broker-confirm-address/index.ts +++ b/src/ui/server/controllers/insurance/policy/broker-confirm-address/index.ts @@ -1,6 +1,7 @@ import { PAGES } from '../../../../content-strings'; import { TEMPLATES } from '../../../../constants'; import { INSURANCE_ROUTES } from '../../../../constants/routes/insurance'; +import generateEnterBrokerAddressManuallyUrl from '../../../../helpers/generate-enter-broker-address-manually-url'; import insuranceCorePageVariables from '../../../../helpers/page-variables/core/insurance'; import getUserNameFromSession from '../../../../helpers/get-user-name-from-session'; import isChangeRoute from '../../../../helpers/is-change-route'; @@ -10,7 +11,7 @@ import { Request, Response } from '../../../../../types'; const { INSURANCE_ROOT, ALL_SECTIONS, - POLICY: { BROKER_DETAILS_ROOT, BROKER_DETAILS_CHANGE, BROKER_MANUAL_ADDRESS_ROOT, LOSS_PAYEE_ROOT, CHECK_YOUR_ANSWERS }, + POLICY: { BROKER_DETAILS_ROOT, BROKER_DETAILS_CHANGE, LOSS_PAYEE_ROOT, CHECK_YOUR_ANSWERS }, PROBLEM_WITH_SERVICE, } = INSURANCE_ROUTES; @@ -26,12 +27,11 @@ export const TEMPLATE = TEMPLATES.INSURANCE.POLICY.BROKER_CONFIRM_ADDRESS; * @returns {Object} Page variables */ export const pageVariables = (referenceNumber: number, isAChangeRoute: boolean) => { - const useDifferentAddressRootUrl = `${INSURANCE_ROOT}/${referenceNumber}`; - let useDifferentAddressUrl = useDifferentAddressRootUrl; + let useDifferentAddressUrl = `${INSURANCE_ROOT}/${referenceNumber}`; /** * If the route is a "change" route, - * the "different address" link/URL should link to the BROKER_DETAILS_CHANGE. Otherwise, BROKER_DETAILS. + * the "use different address" link/URL should link to the BROKER_DETAILS_CHANGE. Otherwise, BROKER_DETAILS. * Otherwise, during the "change your answers" journey, a user would not be immediately taken back to "check your answers" */ if (isAChangeRoute) { @@ -42,7 +42,7 @@ export const pageVariables = (referenceNumber: number, isAChangeRoute: boolean) return { USE_DIFFERENT_ADDRESS_URL: useDifferentAddressUrl, - ENTER_ADDRESS_MANUALLY_URL: `${INSURANCE_ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`, + ENTER_ADDRESS_MANUALLY_URL: generateEnterBrokerAddressManuallyUrl(referenceNumber, isAChangeRoute), SAVE_AND_BACK_URL: `${INSURANCE_ROOT}/${referenceNumber}${ALL_SECTIONS}`, }; }; diff --git a/src/ui/server/controllers/insurance/policy/map-and-save/broker/index.test.ts b/src/ui/server/controllers/insurance/policy/map-and-save/broker/index.test.ts index 3b89fdcb76..2ee99802d8 100644 --- a/src/ui/server/controllers/insurance/policy/map-and-save/broker/index.test.ts +++ b/src/ui/server/controllers/insurance/policy/map-and-save/broker/index.test.ts @@ -3,7 +3,7 @@ import mapSubmittedData from '../../map-submitted-data/broker'; import save from '../../save-data/broker'; import generateValidationErrors from '../../../../../helpers/validation'; import { POLICY as POLICY_FIELD_IDS } from '../../../../../constants/field-ids/insurance/policy'; -import { mockApplication, mockBroker, mockSpyPromise } from '../../../../../test-mocks'; +import { mockApplication, mockSpyPromise } from '../../../../../test-mocks'; const { BROKER_DETAILS: { NAME }, @@ -14,13 +14,13 @@ describe('controllers/insurance/policy/map-and-save/broker', () => { const mockFormBody = { _csrf: '1234', - ...mockBroker, + ...mockApplication.broker, }; const mockSaveBroker = mockSpyPromise(); save.broker = mockSaveBroker; - const populatedData = mapSubmittedData(mockFormBody); + const populatedData = mapSubmittedData(mockFormBody, mockApplication.broker); const mockValidationErrors = generateValidationErrors(NAME, 'error', {}); diff --git a/src/ui/server/controllers/insurance/policy/map-and-save/broker/index.ts b/src/ui/server/controllers/insurance/policy/map-and-save/broker/index.ts index 156d0018d5..ad808c277c 100644 --- a/src/ui/server/controllers/insurance/policy/map-and-save/broker/index.ts +++ b/src/ui/server/controllers/insurance/policy/map-and-save/broker/index.ts @@ -14,7 +14,7 @@ import { Application, RequestBody, ValidationErrors } from '../../../../../../ty const broker = async (formBody: RequestBody, application: Application, validationErrors?: ValidationErrors) => { try { if (hasFormData(formBody)) { - const populatedData = mapSubmittedData(formBody); + const populatedData = mapSubmittedData(formBody, application.broker); let saveResponse; diff --git a/src/ui/server/controllers/insurance/policy/map-and-save/loss-payee/index-with-financial-international-data.test.ts b/src/ui/server/controllers/insurance/policy/map-and-save/loss-payee/index-with-financial-international-data.test.ts index 37a5573c7d..28a6eaf1a0 100644 --- a/src/ui/server/controllers/insurance/policy/map-and-save/loss-payee/index-with-financial-international-data.test.ts +++ b/src/ui/server/controllers/insurance/policy/map-and-save/loss-payee/index-with-financial-international-data.test.ts @@ -1,5 +1,5 @@ import mapAndSave from '.'; -import mapSubmittedData from '../../map-submitted-data/broker'; +import mapSubmittedData from '../../map-submitted-data/loss-payee'; import saveLossPayee from '../../save-data/nominated-loss-payee'; import nullifyLossPayeeFinancialInternationalData from '../../../../../helpers/nullify-loss-payee-financial-international-data'; import saveUk from '../../save-data/loss-payee-financial-details-uk'; diff --git a/src/ui/server/controllers/insurance/policy/map-and-save/loss-payee/index-with-financial-uk-data.test.ts b/src/ui/server/controllers/insurance/policy/map-and-save/loss-payee/index-with-financial-uk-data.test.ts index 2d3875c819..654e1685cd 100644 --- a/src/ui/server/controllers/insurance/policy/map-and-save/loss-payee/index-with-financial-uk-data.test.ts +++ b/src/ui/server/controllers/insurance/policy/map-and-save/loss-payee/index-with-financial-uk-data.test.ts @@ -1,5 +1,5 @@ import mapAndSave from '.'; -import mapSubmittedData from '../../map-submitted-data/broker'; +import mapSubmittedData from '../../map-submitted-data/loss-payee'; import saveLossPayee from '../../save-data/nominated-loss-payee'; import nullifyLossPayeeFinancialUkData from '../../../../../helpers/nullify-loss-payee-financial-uk-data'; import saveUk from '../../save-data/loss-payee-financial-details-uk'; diff --git a/src/ui/server/controllers/insurance/policy/map-and-save/loss-payee/index.test.ts b/src/ui/server/controllers/insurance/policy/map-and-save/loss-payee/index.test.ts index a3814d2b5d..ea2d555d39 100644 --- a/src/ui/server/controllers/insurance/policy/map-and-save/loss-payee/index.test.ts +++ b/src/ui/server/controllers/insurance/policy/map-and-save/loss-payee/index.test.ts @@ -1,5 +1,5 @@ import mapAndSave from '.'; -import mapSubmittedData from '../../map-submitted-data/broker'; +import mapSubmittedData from '../../map-submitted-data/loss-payee'; import saveLossPayee from '../../save-data/nominated-loss-payee'; import saveUk from '../../save-data/loss-payee-financial-details-uk'; import saveInternational from '../../save-data/loss-payee-financial-details-international'; diff --git a/src/ui/server/controllers/insurance/policy/map-submitted-data/broker/index.test.ts b/src/ui/server/controllers/insurance/policy/map-submitted-data/broker/index.test.ts index c8fb5bc057..c166b4f9d5 100644 --- a/src/ui/server/controllers/insurance/policy/map-submitted-data/broker/index.test.ts +++ b/src/ui/server/controllers/insurance/policy/map-submitted-data/broker/index.test.ts @@ -1,5 +1,6 @@ import mapSubmittedData from '.'; import FIELD_IDS from '../../../../../constants/field-ids/insurance/policy'; +import { mockApplication } from '../../../../../test-mocks'; const { USING_BROKER, @@ -8,6 +9,13 @@ const { BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, } = FIELD_IDS; +const { broker } = mockApplication; + +const mockBroker = { + ...broker, + [IS_BASED_IN_UK]: true, +}; + const mockFullyPopulatedBrokerBody = { [USING_BROKER]: 'false', [NAME]: 'mock name', @@ -28,7 +36,7 @@ describe('controllers/insurance/policy/map-submitted-data/broker', () => { [USING_BROKER]: 'false', }; - const result = mapSubmittedData(mockFormBody); + const result = mapSubmittedData(mockFormBody, mockBroker); const expected = { ...mockFormBody, @@ -55,7 +63,7 @@ describe('controllers/insurance/policy/map-submitted-data/broker', () => { [NAME]: 'mock name', }; - const result = mapSubmittedData(mockFormBody); + const result = mapSubmittedData(mockFormBody, mockBroker); const expected = mockFormBody; @@ -64,12 +72,12 @@ describe('controllers/insurance/policy/map-submitted-data/broker', () => { }); describe(`when ${USING_BROKER} is provided as an empty string`, () => { - it(`should delete ${USING_BROKER}`, () => { + it(`should wipe ${USING_BROKER}`, () => { const mockFormBody = { [USING_BROKER]: '', }; - const result = mapSubmittedData(mockFormBody); + const result = mapSubmittedData(mockFormBody, mockBroker); expect(result).toEqual({}); }); @@ -81,10 +89,35 @@ describe('controllers/insurance/policy/map-submitted-data/broker', () => { [IS_BASED_IN_UK]: '', }; - const result = mapSubmittedData(mockFormBody); + const result = mapSubmittedData(mockFormBody, mockBroker); + + const expected = { + [IS_BASED_IN_UK]: null, + }; + + expect(result).toEqual(expected); + }); + }); + + describe(`when ${IS_BASED_IN_UK} is provided with a value of 'false'`, () => { + it(`should return the form body with nullified/empty ${IS_BASED_IN_UK} related values`, () => { + const mockFormBody = { + ...mockFullyPopulatedBrokerBody, + [IS_BASED_IN_UK]: 'false', + }; + + const result = mapSubmittedData(mockFormBody, mockBroker); const expected = { + ...mockFormBody, [IS_BASED_IN_UK]: null, + [FULL_ADDRESS]: '', + [BUILDING_NUMBER_OR_NAME]: '', + [ADDRESS_LINE_1]: '', + [ADDRESS_LINE_2]: '', + [TOWN]: '', + [COUNTY]: '', + [POSTCODE]: '', }; expect(result).toEqual(expected); @@ -98,7 +131,7 @@ describe('controllers/insurance/policy/map-submitted-data/broker', () => { [IS_BASED_IN_UK]: 'false', }; - const result = mapSubmittedData(mockFormBody); + const result = mapSubmittedData(mockFormBody, mockBroker); const expected = { ...mockFormBody, @@ -116,14 +149,55 @@ describe('controllers/insurance/policy/map-submitted-data/broker', () => { }); }); + describe(`when broker data has ${IS_BASED_IN_UK} and ${FULL_ADDRESS} is populated`, () => { + it(`should return the form body with nullified/empty ${IS_BASED_IN_UK} related values`, () => { + const mockFormBody = { + ...mockFullyPopulatedBrokerBody, + [FULL_ADDRESS]: 'Mock full address', + }; + + const mockBrokerData = { + ...mockBroker, + [IS_BASED_IN_UK]: true, + }; + + const result = mapSubmittedData(mockFormBody, mockBrokerData); + + const expected = { + ...mockFormBody, + [BUILDING_NUMBER_OR_NAME]: '', + [ADDRESS_LINE_1]: '', + [ADDRESS_LINE_2]: '', + [TOWN]: '', + [COUNTY]: '', + [POSTCODE]: '', + }; + + expect(result).toEqual(expected); + }); + }); + + describe(`when ${POSTCODE} is populated`, () => { + it(`should wipe ${SELECT_THE_ADDRESS}`, () => { + const mockFormBody = { + [FULL_ADDRESS]: 'Mock full broker address', + [POSTCODE]: 'Mock postcode', + }; + + const result = mapSubmittedData(mockFormBody, mockBroker); + + expect(result[FULL_ADDRESS]).toEqual(''); + }); + }); + describe(`when ${SELECT_THE_ADDRESS} is provided as an empty string`, () => { - it(`should delete ${SELECT_THE_ADDRESS}`, () => { + it(`should wipe ${SELECT_THE_ADDRESS}`, () => { const mockFormBody = { [SELECT_THE_ADDRESS]: '', [POSTCODE]: '', }; - const result = mapSubmittedData(mockFormBody); + const result = mapSubmittedData(mockFormBody, mockBroker); const expected = { [POSTCODE]: '', @@ -134,13 +208,13 @@ describe('controllers/insurance/policy/map-submitted-data/broker', () => { }); describe(`when ${SELECT_THE_ADDRESS} is provided with a value`, () => { - it(`should delete ${SELECT_THE_ADDRESS}`, () => { + it(`should wipe ${SELECT_THE_ADDRESS}`, () => { const mockFormBody = { [SELECT_THE_ADDRESS]: '0', [POSTCODE]: '', }; - const result = mapSubmittedData(mockFormBody); + const result = mapSubmittedData(mockFormBody, mockBroker); const expected = { [POSTCODE]: '', diff --git a/src/ui/server/controllers/insurance/policy/map-submitted-data/broker/index.ts b/src/ui/server/controllers/insurance/policy/map-submitted-data/broker/index.ts index 2043cbbb9b..652261d4c1 100644 --- a/src/ui/server/controllers/insurance/policy/map-submitted-data/broker/index.ts +++ b/src/ui/server/controllers/insurance/policy/map-submitted-data/broker/index.ts @@ -1,7 +1,7 @@ import FIELD_IDS from '../../../../../constants/field-ids/insurance/policy'; import { isEmptyString } from '../../../../../helpers/string'; import { objectHasProperty } from '../../../../../helpers/object'; -import { RequestBody } from '../../../../../../types'; +import { RequestBody, ApplicationBroker } from '../../../../../../types'; const { USING_BROKER, @@ -14,16 +14,23 @@ const { * mapSubmittedData * Map broker fields * @param {RequestBody} formBody: Form body + * @param {ApplicationBroker} brokerData: Application broker data * @returns {Object} populatedData */ -const mapSubmittedData = (formBody: RequestBody): object => { +const mapSubmittedData = (formBody: RequestBody, brokerData: ApplicationBroker): object => { + /** + * Freeze an instance of the form body, + * so that we can check the original data at any stage. + */ + const formBodyData = Object.freeze({ ...formBody }); + const populatedData = formBody; /** * If USING_BROKER is false, - * nullify/wipe all USING_BROKER related fields. + * nullify/wipe all USING_BROKER and address lookup related fields. */ - if (formBody[USING_BROKER] === 'false') { + if (formBodyData[USING_BROKER] === 'false') { populatedData[NAME] = ''; populatedData[EMAIL] = ''; populatedData[IS_BASED_IN_UK] = null; @@ -41,7 +48,7 @@ const mapSubmittedData = (formBody: RequestBody): object => { * If USING_BROKER is an empty string, * delete the field. */ - if (isEmptyString(formBody[USING_BROKER])) { + if (isEmptyString(formBodyData[USING_BROKER])) { delete populatedData[USING_BROKER]; } @@ -49,15 +56,15 @@ const mapSubmittedData = (formBody: RequestBody): object => { * If IS_BASED_IN_UK is an empty string, * make the field null. */ - if (isEmptyString(formBody[IS_BASED_IN_UK])) { + if (isEmptyString(formBodyData[IS_BASED_IN_UK])) { populatedData[IS_BASED_IN_UK] = null; } /** * If IS_BASED_IN_UK is false, - * nullify/wipe all IS_BASED_IN_UK related fields + * nullify/wipe all address lookup related fields */ - if (formBody[IS_BASED_IN_UK] === 'false') { + if (formBodyData[IS_BASED_IN_UK] === 'false') { populatedData[POSTCODE] = ''; populatedData[BUILDING_NUMBER_OR_NAME] = ''; populatedData[ADDRESS_LINE_1] = ''; @@ -66,12 +73,39 @@ const mapSubmittedData = (formBody: RequestBody): object => { populatedData[COUNTY] = ''; } + /** + * If broker data has a IS_BASED_IN_UK flag, + * and FULL_ADDRESS is provided and empty, + * wipe all address lookup related fields. + */ + + const fullAddressValue = formBodyData[FULL_ADDRESS]; + + const fullAddressIsPopulated = fullAddressValue && !isEmptyString(fullAddressValue); + + if (brokerData[IS_BASED_IN_UK] && fullAddressIsPopulated) { + populatedData[BUILDING_NUMBER_OR_NAME] = ''; + populatedData[ADDRESS_LINE_1] = ''; + populatedData[ADDRESS_LINE_2] = ''; + populatedData[TOWN] = ''; + populatedData[COUNTY] = ''; + populatedData[POSTCODE] = ''; + } + + /** + * If POSTCODE is provided, + * wipe the FULL_ADDRESS field. + */ + if (objectHasProperty(formBodyData, POSTCODE)) { + populatedData[FULL_ADDRESS] = ''; + } + /** * If SELECT_THE_ADDRESS is provided, * or is an empty string, * delete the field. */ - if (objectHasProperty(formBody, SELECT_THE_ADDRESS) || isEmptyString(formBody[SELECT_THE_ADDRESS])) { + if (objectHasProperty(formBodyData, SELECT_THE_ADDRESS) || isEmptyString(formBodyData[SELECT_THE_ADDRESS])) { delete populatedData[SELECT_THE_ADDRESS]; } diff --git a/src/ui/server/helpers/flatten-application-data/map-broker/index.test.ts b/src/ui/server/helpers/flatten-application-data/map-broker/index.test.ts index 9370c84eb8..ccf243c245 100644 --- a/src/ui/server/helpers/flatten-application-data/map-broker/index.test.ts +++ b/src/ui/server/helpers/flatten-application-data/map-broker/index.test.ts @@ -26,11 +26,12 @@ const { broker } = mockApplication; describe('server/helpers/flatten-application-data/map-broker', () => { describe(`when ${USING_BROKER} is true`, () => { - describe(`when ${IS_BASED_IN_UK} is true`, () => { + describe(`when ${IS_BASED_IN_UK} is true and ${FULL_ADDRESS} is not populated`, () => { const mockBroker = { ...broker, [USING_BROKER]: true, [IS_BASED_IN_UK]: true, + [FULL_ADDRESS]: '', }; it('should return mapped broker IDs', () => { @@ -52,6 +53,30 @@ describe('server/helpers/flatten-application-data/map-broker', () => { }); }); + describe(`when ${IS_BASED_IN_UK} is true and ${FULL_ADDRESS} is populated`, () => { + const mockBroker = { + ...broker, + [USING_BROKER]: true, + [IS_BASED_IN_UK]: true, + [FULL_ADDRESS]: 'Mock full address', + }; + + it('should return mapped broker IDs', () => { + const result = mapBroker(mockBroker); + + const expected = { + id: mockBroker.id, + [USING_BROKER]: mockBroker[USING_BROKER], + [IS_BASED_IN_UK]: mockBroker[IS_BASED_IN_UK], + [BROKER_NAME]: mockBroker[NAME], + [BROKER_EMAIL]: mockBroker[EMAIL], + [BROKER_FULL_ADDRESS]: mockBroker[FULL_ADDRESS], + }; + + expect(result).toEqual(expected); + }); + }); + describe(`when ${IS_BASED_IN_UK} is false`, () => { const mockBroker = { ...broker, diff --git a/src/ui/server/helpers/flatten-application-data/map-broker/index.ts b/src/ui/server/helpers/flatten-application-data/map-broker/index.ts index 5c3ef056f5..acd3110733 100644 --- a/src/ui/server/helpers/flatten-application-data/map-broker/index.ts +++ b/src/ui/server/helpers/flatten-application-data/map-broker/index.ts @@ -29,7 +29,7 @@ const { * @returns {Object} ApplicationBroker with slightly different field IDs */ const mapBroker = (broker: ApplicationBroker) => { - const { isUsingBroker, isBasedInUk } = broker; + const { isUsingBroker, isBasedInUk, fullAddress } = broker; const mapped = { id: broker.id, @@ -41,7 +41,7 @@ const mapBroker = (broker: ApplicationBroker) => { mapped[BROKER_NAME] = broker[NAME]; mapped[BROKER_EMAIL] = broker[EMAIL]; - if (isBasedInUk) { + if (isBasedInUk && !fullAddress) { mapped[BROKER_BUILDING_NUMBER_OR_NAME] = broker[BUILDING_NUMBER_OR_NAME]; mapped[BROKER_ADDRESS_LINE_1] = broker[ADDRESS_LINE_1]; mapped[BROKER_ADDRESS_LINE_2] = broker[ADDRESS_LINE_2]; diff --git a/src/ui/server/helpers/generate-enter-broker-address-manually-url/index.test.ts b/src/ui/server/helpers/generate-enter-broker-address-manually-url/index.test.ts new file mode 100644 index 0000000000..d423f51e84 --- /dev/null +++ b/src/ui/server/helpers/generate-enter-broker-address-manually-url/index.test.ts @@ -0,0 +1,35 @@ +import generateEnterBrokerAddressManuallyUrl from '.'; +import { INSURANCE_ROUTES } from '../../constants/routes/insurance'; + +const { + INSURANCE_ROOT, + POLICY: { BROKER_MANUAL_ADDRESS_ROOT, BROKER_MANUAL_ADDRESS_CHANGE }, +} = INSURANCE_ROUTES; + +describe('server/helpers/generate-enter-broker-address-manually-url', () => { + const referenceNumber = 123; + + describe('when isAChangeRoute is true', () => { + it('should return the correct url', () => { + const isAChangeRoute = true; + + const response = generateEnterBrokerAddressManuallyUrl(referenceNumber, isAChangeRoute); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_CHANGE}`; + + expect(response).toEqual(expected); + }); + }); + + describe('when isAChangeRoute is true', () => { + it('should return the correct url', () => { + const isAChangeRoute = false; + + const response = generateEnterBrokerAddressManuallyUrl(referenceNumber, isAChangeRoute); + + const expected = `${INSURANCE_ROOT}/${referenceNumber}${BROKER_MANUAL_ADDRESS_ROOT}`; + + expect(response).toEqual(expected); + }); + }); +}); diff --git a/src/ui/server/helpers/generate-enter-broker-address-manually-url/index.ts b/src/ui/server/helpers/generate-enter-broker-address-manually-url/index.ts new file mode 100644 index 0000000000..0a89f44957 --- /dev/null +++ b/src/ui/server/helpers/generate-enter-broker-address-manually-url/index.ts @@ -0,0 +1,29 @@ +import { INSURANCE_ROUTES } from '../../constants/routes/insurance'; + +const { + INSURANCE_ROOT, + POLICY: { BROKER_MANUAL_ADDRESS_ROOT, BROKER_MANUAL_ADDRESS_CHANGE }, +} = INSURANCE_ROUTES; + +/** + * generateEnterBrokerAddressManuallyUrl + * If the route is a "change" route, + * the "enter address manually" link/URL should link to the BROKER_MANUAL_ADDRESS_CHANGE. Otherwise, BROKER_MANUAL_ADDRESS. + * Otherwise, during the "change your answers" journey, a user would not be immediately taken back to "check your answers" + * @param {Number} referenceNumber: Application reference number + * @param {Boolean} isAChangeRoute: If the last part of a string/URL is 'change' + * Generate a URL for a "enter broker address manually" link + */ +const generateEnterBrokerAddressManuallyUrl = (referenceNumber: number, isAChangeRoute: boolean) => { + let url = `${INSURANCE_ROOT}/${referenceNumber}`; + + if (isAChangeRoute) { + url += BROKER_MANUAL_ADDRESS_CHANGE; + } else { + url += BROKER_MANUAL_ADDRESS_ROOT; + } + + return url; +}; + +export default generateEnterBrokerAddressManuallyUrl; diff --git a/src/ui/server/helpers/required-fields/policy/index.test.ts b/src/ui/server/helpers/required-fields/policy/index.test.ts index 28e4e41106..4efb7f6151 100644 --- a/src/ui/server/helpers/required-fields/policy/index.test.ts +++ b/src/ui/server/helpers/required-fields/policy/index.test.ts @@ -9,7 +9,7 @@ const { POLICY_TYPE } = FIELD_VALUES; const { REQUESTED_START_DATE, POLICY_CURRENCY_CODE } = SHARED_CONTRACT_POLICY; const { - BROKER_DETAILS: { BROKER_NAME, BROKER_EMAIL, BROKER_ADDRESS_LINE_1, BROKER_ADDRESS_LINE_2, BROKER_POSTCODE }, + BROKER_DETAILS: { BROKER_NAME, BROKER_EMAIL, IS_BASED_IN_UK, BROKER_ADDRESS_LINE_1, BROKER_ADDRESS_LINE_2, BROKER_POSTCODE }, BROKER_MANUAL_ADDRESS: { BROKER_FULL_ADDRESS }, CONTRACT_POLICY: { SINGLE: { CONTRACT_COMPLETION_DATE, REQUESTED_CREDIT_LIMIT, TOTAL_CONTRACT_VALUE }, @@ -117,27 +117,29 @@ describe('server/helpers/required-fields/policy', () => { }); describe('getBrokerTasks', () => { - describe('when isUsingBroker is true, brokerIsBasedInUk is false', () => { + describe('when isUsingBroker is true, brokerIsBasedInUk is false, brokerFullAddress is a populated string', () => { it('should return multiple field ids in an array', () => { const isUsingBrokerFlag = true; const brokerIsBasedInUkFlag = false; + const brokerFullAddress = 'Mock broker full address'; - const result = getBrokerTasks(isUsingBrokerFlag, brokerIsBasedInUkFlag); + const result = getBrokerTasks(isUsingBrokerFlag, brokerIsBasedInUkFlag, brokerFullAddress); - const expected = [BROKER_NAME, BROKER_EMAIL, BROKER_FULL_ADDRESS]; + const expected = [BROKER_NAME, BROKER_EMAIL, IS_BASED_IN_UK, BROKER_FULL_ADDRESS]; expect(result).toEqual(expected); }); }); - describe('when isUsingBroker is true, brokerIsBasedInUk is true', () => { + describe('when isUsingBroker is true, brokerIsBasedInUk is true, brokerFullAddress is an empty string', () => { it('should return multiple field ids in an array', () => { const isUsingBrokerFlag = true; const brokerIsBasedInUkFlag = true; + const brokerFullAddress = ''; - const result = getBrokerTasks(isUsingBrokerFlag, brokerIsBasedInUkFlag); + const result = getBrokerTasks(isUsingBrokerFlag, brokerIsBasedInUkFlag, brokerFullAddress); - const expected = [BROKER_NAME, BROKER_EMAIL, BROKER_ADDRESS_LINE_1, BROKER_ADDRESS_LINE_2, BROKER_POSTCODE]; + const expected = [BROKER_NAME, BROKER_EMAIL, IS_BASED_IN_UK, BROKER_ADDRESS_LINE_1, BROKER_ADDRESS_LINE_2, BROKER_POSTCODE]; expect(result).toEqual(expected); }); diff --git a/src/ui/server/helpers/required-fields/policy/index.ts b/src/ui/server/helpers/required-fields/policy/index.ts index 5a96a2a521..dda7e4ab66 100644 --- a/src/ui/server/helpers/required-fields/policy/index.ts +++ b/src/ui/server/helpers/required-fields/policy/index.ts @@ -5,7 +5,7 @@ import { isSinglePolicyType, isMultiplePolicyType } from '../../policy-type'; const { REQUESTED_START_DATE, POLICY_CURRENCY_CODE } = SHARED_CONTRACT_POLICY; const { - BROKER_DETAILS: { BROKER_NAME, BROKER_EMAIL, BROKER_ADDRESS_LINE_1, BROKER_ADDRESS_LINE_2, BROKER_POSTCODE }, + BROKER_DETAILS: { BROKER_NAME, BROKER_EMAIL, IS_BASED_IN_UK, BROKER_ADDRESS_LINE_1, BROKER_ADDRESS_LINE_2, BROKER_POSTCODE }, BROKER_MANUAL_ADDRESS: { BROKER_FULL_ADDRESS }, CONTRACT_POLICY: { SINGLE: { CONTRACT_COMPLETION_DATE, REQUESTED_CREDIT_LIMIT, TOTAL_CONTRACT_VALUE }, @@ -74,18 +74,26 @@ export const getJointlyInsuredPartyTasks = (jointlyInsuredParty?: boolean) => { * Get "Broker" tasks depending on the isUsingBroker field * @param {Boolean} isUsingBroker: "Is using broker" flag * @param {Boolean} brokerIsBasedInUk: "Broker is based in the UK" flag + * @param {String} brokerFullAddress: Broker "full address" data * @returns {Array} Array of tasks/field IDs */ -export const getBrokerTasks = (isUsingBroker?: boolean, brokerIsBasedInUk?: boolean) => { +export const getBrokerTasks = (isUsingBroker?: boolean, brokerIsBasedInUk?: boolean, brokerFullAddress?: string) => { let tasks: Array = []; + /** + * If USING_BROKER is true: + * 1) A few fields are always required. + * 2) At this point, we assume BROKER_FULL_ADDRESS is required. + * 3) Otherwise, If IS_BASED_IN_UK is true and there is no BROKER_FULL_ADDRESS: + * - Address lookup fields are required. + * - BROKER_FULL_ADDRESS is NOT required (because address lookup fields are required). + */ if (isUsingBroker) { - tasks = [BROKER_NAME, BROKER_EMAIL]; + const genericTasks = [BROKER_NAME, BROKER_EMAIL, IS_BASED_IN_UK]; + tasks = [...genericTasks, BROKER_FULL_ADDRESS]; - if (brokerIsBasedInUk) { - tasks = [...tasks, BROKER_ADDRESS_LINE_1, BROKER_ADDRESS_LINE_2, BROKER_POSTCODE]; - } else { - tasks = [...tasks, BROKER_FULL_ADDRESS]; + if (brokerIsBasedInUk && !brokerFullAddress) { + tasks = [...genericTasks, BROKER_ADDRESS_LINE_1, BROKER_ADDRESS_LINE_2, BROKER_POSTCODE]; } } @@ -121,6 +129,7 @@ interface RequiredFields { jointlyInsuredParty?: boolean; isUsingBroker?: boolean; brokerIsBasedInUk?: boolean; + brokerFullAddress?: string; isAppointingLossPayee?: boolean; lossPayeeIsLocatedInUk?: boolean; lossPayeeIsLocatedInternationally?: boolean; @@ -133,6 +142,7 @@ interface RequiredFields { * @param {Boolean} jointlyInsuredParty: "Jointly insured party" flag * @param {Boolean} isUsingBroker: "Is using broker" * @param {Boolean} brokerIsBasedInUk: "Broker is based in the UK" flag + * @param {String} brokerFullAddress: Broker "full address" data * @param {Boolean} isAppointingLossPayee: "Is using loss payee" flag * @param {Boolean} lossPayeeIsLocatedInUk: "Loss payee is located in the UK" flag * @param {Boolean} lossPayeeIsLocatedInternationally: "Loss payee is located internationally" flag @@ -143,6 +153,7 @@ const requiredFields = ({ jointlyInsuredParty, isUsingBroker, brokerIsBasedInUk, + brokerFullAddress, isAppointingLossPayee, lossPayeeIsLocatedInUk, lossPayeeIsLocatedInternationally, @@ -158,7 +169,7 @@ const requiredFields = ({ POLICY_CONTACT_EMAIL, POSITION, USING_BROKER, - ...getBrokerTasks(isUsingBroker, brokerIsBasedInUk), + ...getBrokerTasks(isUsingBroker, brokerIsBasedInUk, brokerFullAddress), ...lossPayeeTasks(isAppointingLossPayee, lossPayeeIsLocatedInUk, lossPayeeIsLocatedInternationally), ]; diff --git a/src/ui/server/helpers/required-fields/prepare-application/index.test.ts b/src/ui/server/helpers/required-fields/prepare-application/index.test.ts index 2710aab36d..72ef1d2000 100644 --- a/src/ui/server/helpers/required-fields/prepare-application/index.test.ts +++ b/src/ui/server/helpers/required-fields/prepare-application/index.test.ts @@ -22,6 +22,7 @@ const { TYPE_OF_POLICY: { POLICY_TYPE }, USING_BROKER, BROKER_DETAILS: { IS_BASED_IN_UK }, + BROKER_MANUAL_ADDRESS: { BROKER_FULL_ADDRESS }, REQUESTED_JOINTLY_INSURED_PARTY: { REQUESTED }, LOSS_PAYEE: { IS_APPOINTED }, LOSS_PAYEE_DETAILS: { IS_LOCATED_IN_UK, IS_LOCATED_INTERNATIONALLY }, @@ -43,6 +44,7 @@ describe('server/helpers/required-fields/section-review', () => { jointlyInsuredParty: flatApplicationData[REQUESTED], isUsingBroker: flatApplicationData[USING_BROKER], brokerIsBasedInUk: flatApplicationData[IS_BASED_IN_UK], + brokerFullAddress: flatApplicationData[BROKER_FULL_ADDRESS], isAppointingLossPayee: flatApplicationData[IS_APPOINTED], lossPayeeIsLocatedInUk: flatApplicationData[IS_LOCATED_IN_UK], lossPayeeIsLocatedInternationally: flatApplicationData[IS_LOCATED_INTERNATIONALLY], diff --git a/src/ui/server/helpers/required-fields/prepare-application/index.ts b/src/ui/server/helpers/required-fields/prepare-application/index.ts index 5a23045bc3..b190391077 100644 --- a/src/ui/server/helpers/required-fields/prepare-application/index.ts +++ b/src/ui/server/helpers/required-fields/prepare-application/index.ts @@ -20,6 +20,7 @@ const { TYPE_OF_POLICY: { POLICY_TYPE }, USING_BROKER, BROKER_DETAILS: { IS_BASED_IN_UK }, + BROKER_MANUAL_ADDRESS: { BROKER_FULL_ADDRESS }, REQUESTED_JOINTLY_INSURED_PARTY: { REQUESTED }, LOSS_PAYEE: { IS_APPOINTED }, LOSS_PAYEE_DETAILS: { IS_LOCATED_IN_UK, IS_LOCATED_INTERNATIONALLY }, @@ -39,6 +40,7 @@ const requiredFields = (application: ApplicationFlat): Array => [ jointlyInsuredParty: application[REQUESTED], isUsingBroker: application[USING_BROKER], brokerIsBasedInUk: application[IS_BASED_IN_UK], + brokerFullAddress: application[BROKER_FULL_ADDRESS], isAppointingLossPayee: application[IS_APPOINTED], lossPayeeIsLocatedInUk: application[IS_LOCATED_IN_UK], lossPayeeIsLocatedInternationally: application[IS_LOCATED_INTERNATIONALLY], 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 index 2ffa93116c..6e83e73e7b 100644 --- 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 @@ -9,7 +9,6 @@ import generateMultipleFieldHtml from '../../../../generate-multiple-field-html' 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; @@ -21,64 +20,64 @@ const checkAndChange = false; const { addressLine1, addressLine2, town, county, postcode } = mockBroker; 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', () => { + describe(`when ${FULL_ADDRESS} is a populated string`, () => { + it(`should return an ${FULL_ADDRESS} field`, () => { const mockAnswers = { ...mockBroker, - [IS_BASED_IN_UK]: true, + [FULL_ADDRESS]: 'Mock broker full address', }; const result = brokerAddressField(mockAnswers, referenceNumber, checkAndChange); const expected = fieldGroupItem( { - field: getFieldById(POLICY_FIELDS.BROKER_ADDRESSES, SELECT_THE_ADDRESS), + field: getFieldById(POLICY_FIELDS.BROKER_MANUAL_ADDRESS, FULL_ADDRESS), data: mockAnswers, href: generateChangeLink( BROKER_CONFIRM_ADDRESS_CHANGE, BROKER_CONFIRM_ADDRESS_CHECK_AND_CHANGE, - `#${SELECT_THE_ADDRESS}-label`, + `#${FULL_ADDRESS}-label`, referenceNumber, checkAndChange, ), renderChangeLink: true, }, - generateMultipleFieldHtml({ - addressLine1, - addressLine2, - town, - county, - postcode, - }), + mockAnswers[FULL_ADDRESS], ); expect(result).toEqual(expected); }); }); - describe(`when ${IS_BASED_IN_UK} is false`, () => { - it('should return a non-UK address field', () => { + describe(`when ${FULL_ADDRESS} is an empty string`, () => { + it(`should return a ${SELECT_THE_ADDRESS} field with a value via generateMultipleFieldHtml`, () => { const mockAnswers = { ...mockBroker, - [IS_BASED_IN_UK]: false, + [FULL_ADDRESS]: '', }; const result = brokerAddressField(mockAnswers, referenceNumber, checkAndChange); const expected = fieldGroupItem( { - field: getFieldById(POLICY_FIELDS.BROKER_MANUAL_ADDRESS, FULL_ADDRESS), + field: getFieldById(POLICY_FIELDS.BROKER_ADDRESSES, SELECT_THE_ADDRESS), data: mockAnswers, href: generateChangeLink( BROKER_CONFIRM_ADDRESS_CHANGE, BROKER_CONFIRM_ADDRESS_CHECK_AND_CHANGE, - `#${FULL_ADDRESS}-label`, + `#${SELECT_THE_ADDRESS}-label`, referenceNumber, checkAndChange, ), renderChangeLink: true, }, - mockAnswers[FULL_ADDRESS], + generateMultipleFieldHtml({ + addressLine1, + addressLine2, + town, + county, + postcode, + }), ); 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 index 23192fe801..51b5929d2f 100644 --- 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 @@ -8,7 +8,6 @@ import generateMultipleFieldHtml from '../../../../generate-multiple-field-html' import { ApplicationBroker } from '../../../../../../types'; const { - BROKER_DETAILS: { IS_BASED_IN_UK }, BROKER_ADDRESSES: { SELECT_THE_ADDRESS }, BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, } = POLICY_FIELD_IDS; @@ -32,7 +31,12 @@ const brokerAddressField = (answers: ApplicationBroker, referenceNumber: number, const changeRoute = BROKER_CONFIRM_ADDRESS_CHANGE; const checkAndChangeRoute = BROKER_CONFIRM_ADDRESS_CHECK_AND_CHANGE; - if (answers[IS_BASED_IN_UK]) { + if (answers[FULL_ADDRESS]) { + field = getFieldById(POLICY_FIELDS.BROKER_MANUAL_ADDRESS, FULL_ADDRESS); + fieldValue = answers[FULL_ADDRESS]; + + href = generateChangeLink(changeRoute, checkAndChangeRoute, `#${FULL_ADDRESS}-label`, referenceNumber, checkAndChange); + } else { field = getFieldById(POLICY_FIELDS.BROKER_ADDRESSES, SELECT_THE_ADDRESS); const { addressLine1, addressLine2, town, county, postcode } = answers; @@ -46,11 +50,6 @@ const brokerAddressField = (answers: ApplicationBroker, referenceNumber: number, }); href = generateChangeLink(changeRoute, checkAndChangeRoute, `#${SELECT_THE_ADDRESS}-label`, referenceNumber, checkAndChange); - } else { - field = getFieldById(POLICY_FIELDS.BROKER_MANUAL_ADDRESS, FULL_ADDRESS); - fieldValue = answers[FULL_ADDRESS]; - - href = generateChangeLink(changeRoute, checkAndChangeRoute, `#${FULL_ADDRESS}-label`, referenceNumber, checkAndChange); } const groupItem = fieldGroupItem( diff --git a/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.test.ts b/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.test.ts index a420eb8b88..a539ed2947 100644 --- a/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.test.ts +++ b/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.test.ts @@ -10,7 +10,7 @@ const { INITIAL_CHECKS, PREPARE_APPLICATION, SUBMIT_APPLICATION } = TASKS.LIST; describe('server/helpers/task-list/generate-groups-and-tasks', () => { const { - broker: { isUsingBroker, isBasedInUk: brokerIsBasedInUk }, + broker: { isUsingBroker, isBasedInUk: brokerIsBasedInUk, fullAddress: brokerFullAddress }, buyer: { relationship: { exporterIsConnectedWithBuyer, exporterHasPreviousCreditInsuranceWithBuyer }, buyerTradingHistory: { exporterHasTradedWithBuyer, outstandingPayments }, @@ -47,6 +47,7 @@ describe('server/helpers/task-list/generate-groups-and-tasks', () => { jointlyInsuredParty.requested, isUsingBroker, brokerIsBasedInUk, + brokerFullAddress, isAppointingLossPayee, lossPayeeIsLocatedInUk, lossPayeeIsLocatedInInternationally, @@ -82,6 +83,7 @@ describe('server/helpers/task-list/generate-groups-and-tasks', () => { jointlyInsuredParty: jointlyInsuredParty.requested, isUsingBroker, brokerIsBasedInUk, + brokerFullAddress, isAppointingLossPayee, lossPayeeIsLocatedInUk, hasDifferentTradingName, diff --git a/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.ts b/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.ts index 24734c7fbe..0e6a8da86b 100644 --- a/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.ts +++ b/src/ui/server/helpers/task-list/generate-groups-and-tasks/index.ts @@ -15,6 +15,7 @@ const { INITIAL_CHECKS, PREPARE_APPLICATION, SUBMIT_APPLICATION } = TASKS.LIST; * @param {Boolean} jointlyInsuredParty: "Jointly insured party" flag * @param {Boolean} isUsingBroker: "Is using broker" flag * @param {Boolean} brokerIsBasedInUk: "Broker is based in the UK" flag + * @param {String} brokerFullAddress: Broker "full address" data * @param {Boolean} isAppointingLossPayee: "Is using loss payee" flag * @param {Boolean} lossPayeeIsLocatedInUk: "Loss payee is located in the UK" flag * @param {Boolean} lossPayeeIsLocatedInternationally: "Loss payee is located internationally" flag @@ -39,6 +40,7 @@ const generateGroupsAndTasks = ( jointlyInsuredParty?: boolean, isUsingBroker?: boolean, brokerIsBasedInUk?: boolean, + brokerFullAddress?: string, isAppointingLossPayee?: boolean, lossPayeeIsLocatedInUk?: boolean, lossPayeeIsLocatedInternationally?: boolean, @@ -77,6 +79,7 @@ const generateGroupsAndTasks = ( jointlyInsuredParty, isUsingBroker, brokerIsBasedInUk, + brokerFullAddress, isAppointingLossPayee, lossPayeeIsLocatedInUk, lossPayeeIsLocatedInternationally, diff --git a/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.test.ts b/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.test.ts index 691ae0f84b..d0552dc1e6 100644 --- a/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.test.ts +++ b/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.test.ts @@ -23,7 +23,7 @@ const { PREPARE_APPLICATION } = TASKS.LIST; describe('server/helpers/task-list/prepare-application', () => { const { - broker: { isUsingBroker, isBasedInUk: brokerIsBasedInUk }, + broker: { isUsingBroker, isBasedInUk: brokerIsBasedInUk, fullAddress: brokerFullAddress }, buyer: { relationship: { exporterIsConnectedWithBuyer, exporterHasPreviousCreditInsuranceWithBuyer }, buyerTradingHistory: { exporterHasTradedWithBuyer, outstandingPayments }, @@ -71,6 +71,7 @@ describe('server/helpers/task-list/prepare-application', () => { jointlyInsuredParty: jointlyInsuredParty.requested, isUsingBroker, brokerIsBasedInUk, + brokerFullAddress, isAppointingLossPayee, lossPayeeIsLocatedInUk, lossPayeeIsLocatedInternationally, @@ -120,6 +121,7 @@ describe('server/helpers/task-list/prepare-application', () => { jointlyInsuredParty: jointlyInsuredParty.requested, isUsingBroker, brokerIsBasedInUk, + brokerFullAddress, isAppointingLossPayee, lossPayeeIsLocatedInUk, lossPayeeIsLocatedInternationally, diff --git a/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.ts b/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.ts index d0f842b933..5dc06695e1 100644 --- a/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.ts +++ b/src/ui/server/helpers/task-list/generate-groups-and-tasks/prepare-application.ts @@ -25,6 +25,7 @@ const { PREPARE_APPLICATION } = TASKS.LIST; * @param {String} policyType: Application "Policy type" * @param {Boolean} isUsingBroker: "Is using broker" flag * @param {Boolean} brokerIsBasedInUk: "Broker is based in the UK" flag + * @param {String} brokerFullAddress: Broker "full address" data * @param {Boolean} isAppointingLossPayee: "Is using loss payee" flag * @param {Boolean} lossPayeeIsLocatedInUk: "Loss payee is located in the UK" flag * @param {Boolean} lossPayeeIsLocatedInternationally: "Loss payee is located internationally" flag @@ -43,6 +44,7 @@ const createPrepareApplicationTasks = ({ jointlyInsuredParty, isUsingBroker, brokerIsBasedInUk, + brokerFullAddress, isAppointingLossPayee, lossPayeeIsLocatedInUk, lossPayeeIsLocatedInternationally, @@ -95,6 +97,7 @@ const createPrepareApplicationTasks = ({ jointlyInsuredParty, isUsingBroker, brokerIsBasedInUk, + brokerFullAddress, isAppointingLossPayee, lossPayeeIsLocatedInUk, lossPayeeIsLocatedInternationally, diff --git a/src/ui/templates/insurance/policy/broker-zero-addresses.njk b/src/ui/templates/insurance/policy/broker-zero-addresses.njk index 66ff078556..535bc72b59 100644 --- a/src/ui/templates/insurance/policy/broker-zero-addresses.njk +++ b/src/ui/templates/insurance/policy/broker-zero-addresses.njk @@ -33,7 +33,7 @@ {{ CONTENT_STRINGS.OUTRO.OR }} - {{ CONTENT_STRINGS.OUTRO.ENTER_MANUALLY }} + {{ CONTENT_STRINGS.OUTRO.ENTER_MANUALLY }}

diff --git a/src/ui/types/task-list.ts b/src/ui/types/task-list.ts index 0cfd0ad8fc..b9b9d7edc5 100644 --- a/src/ui/types/task-list.ts +++ b/src/ui/types/task-list.ts @@ -38,6 +38,7 @@ interface CreatePrepareApplicationTasksParams { jointlyInsuredParty?: boolean; isUsingBroker?: boolean; brokerIsBasedInUk?: boolean; + brokerFullAddress?: string; isAppointingLossPayee?: boolean; lossPayeeIsLocatedInUk?: boolean; lossPayeeIsLocatedInternationally?: boolean;