diff --git a/locales/cy/translations.json b/locales/cy/translations.json index fb7dac2..82773f8 100644 --- a/locales/cy/translations.json +++ b/locales/cy/translations.json @@ -52,6 +52,11 @@ "payment" : "WELSH - Continue to payment" }, + "choosePrincipalPlaceOfBusinessPage" : { + "title": "WELSH - Choose the principal place of business", + "addressLink": "WELSH - The address is not on the list" + }, + "chooseRegisteredOfficeAddressPage" : { "title": "WELSH - Choose the registered office address", "addressLink": "WELSH - The address is not on the list" diff --git a/locales/en/translations.json b/locales/en/translations.json index 7fa4059..b73122c 100644 --- a/locales/en/translations.json +++ b/locales/en/translations.json @@ -52,6 +52,11 @@ "payment" : "Continue to payment" }, + "choosePrincipalPlaceOfBusinessPage" : { + "title": "Choose the principal place of business", + "addressLink": "The address is not on the list" + }, + "chooseRegisteredOfficeAddressPage" : { "title": "Choose the registered office address", "addressLink": "The address is not on the list" diff --git a/src/presentation/controller/addressLookUp/Controller.ts b/src/presentation/controller/addressLookUp/Controller.ts index c05cd6b..bfec569 100644 --- a/src/presentation/controller/addressLookUp/Controller.ts +++ b/src/presentation/controller/addressLookUp/Controller.ts @@ -16,6 +16,8 @@ import { PageRouting, pageRoutingDefault } from "../PageRouting"; class AddressLookUpController extends AbstractController { public readonly REGISTERED_OFFICE_ADDRESS_CACHE_KEY = APPLICATION_CACHE_KEY_PREFIX_REGISTRATION + "registered_office_address"; + public readonly PRINCIPAL_PLACE_OF_BUSINESS_CACHE_KEY = + APPLICATION_CACHE_KEY_PREFIX_REGISTRATION + "principal_place_of_business"; constructor( private addressService: AddressService, @@ -55,8 +57,12 @@ class AddressLookUpController extends AbstractController { let addressList: Address[] = []; if (this.isAddressListRequired(pageRouting.pageType)) { - const postcode = - cache[this.REGISTERED_OFFICE_ADDRESS_CACHE_KEY].postal_code; + let postcode = ""; + if (pageType === AddressLookUpPageType.choosePrincipalPlaceOfBusinessAddress) { + postcode = cache[this.PRINCIPAL_PLACE_OF_BUSINESS_CACHE_KEY].postal_code; + } else { + postcode = cache[this.REGISTERED_OFFICE_ADDRESS_CACHE_KEY].postal_code; + } addressList = await this.addressService.getAddressListForPostcode( tokens, @@ -81,7 +87,9 @@ class AddressLookUpController extends AbstractController { } private isAddressListRequired(pageType: string): boolean { - return pageType === AddressLookUpPageType.chooseRegisteredOfficeAddress; + + return pageType === AddressLookUpPageType.chooseRegisteredOfficeAddress || + pageType === AddressLookUpPageType.choosePrincipalPlaceOfBusinessAddress ; } postcodeValidation(): RequestHandler { @@ -350,7 +358,12 @@ class AddressLookUpController extends AbstractController { request ); - const cacheKey = this.REGISTERED_OFFICE_ADDRESS_CACHE_KEY; + let cacheKey = ""; + if (pageType === AddressLookUpPageType.choosePrincipalPlaceOfBusinessAddress) { + cacheKey = this.PRINCIPAL_PLACE_OF_BUSINESS_CACHE_KEY; + } else { + cacheKey = this.REGISTERED_OFFICE_ADDRESS_CACHE_KEY; + } await this.cacheService.addDataToCache(session, { [cacheKey]: dataToStore diff --git a/src/presentation/controller/addressLookUp/PageType.ts b/src/presentation/controller/addressLookUp/PageType.ts index 4749868..cc73711 100644 --- a/src/presentation/controller/addressLookUp/PageType.ts +++ b/src/presentation/controller/addressLookUp/PageType.ts @@ -3,7 +3,9 @@ enum AddressPageType { chooseRegisteredOfficeAddress = "choose-registered-office-address", enterRegisteredOfficeAddress = "enter-registered-office-address", confirmRegisteredOfficeAddress = "confirm-registered-office-address", - postcodePrincipalPlaceOfBusinessAddress = "postcode-principal-place-of-business-address" + + postcodePrincipalPlaceOfBusinessAddress = "postcode-principal-place-of-business-address", + choosePrincipalPlaceOfBusinessAddress = "choose-principal-place-of-business-address" } export default AddressPageType; diff --git a/src/presentation/controller/addressLookUp/Routing.ts b/src/presentation/controller/addressLookUp/Routing.ts index 43dd6ff..873f396 100644 --- a/src/presentation/controller/addressLookUp/Routing.ts +++ b/src/presentation/controller/addressLookUp/Routing.ts @@ -11,7 +11,8 @@ import { CHOOSE_REGISTERED_OFFICE_ADDRESS_URL, ENTER_REGISTERED_OFFICE_ADDRESS_URL, CONFIRM_REGISTERED_OFFICE_ADDRESS_URL, - POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL + POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, + CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL } from "./url"; // Registered Office Address @@ -65,7 +66,7 @@ const registeredOfficeAddress = [ const addressRoutingPostcodePrincipalPlaceOfBusinessAddress = { previousUrl: CONFIRM_REGISTERED_OFFICE_ADDRESS_URL, currentUrl: POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, - nextUrl: GENERAL_PARTNERS_URL, + nextUrl: CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, pageType: AddressPageType.postcodePrincipalPlaceOfBusinessAddress, data: { enterManualAddressPageType: "#", @@ -73,8 +74,19 @@ const addressRoutingPostcodePrincipalPlaceOfBusinessAddress = { } }; +const addressRoutingChoosePrincipalPlaceOfBusinessAddress = { + previousUrl: POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, + currentUrl: CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, + nextUrl: GENERAL_PARTNERS_URL, + pageType: AddressPageType.choosePrincipalPlaceOfBusinessAddress, + data: { + + } +}; + const principalPlaceOfBusinessAddress = [ - addressRoutingPostcodePrincipalPlaceOfBusinessAddress + addressRoutingPostcodePrincipalPlaceOfBusinessAddress, + addressRoutingChoosePrincipalPlaceOfBusinessAddress ]; export const addressLookUpRouting: PagesRouting = new Map< diff --git a/src/presentation/controller/addressLookUp/template.ts b/src/presentation/controller/addressLookUp/template.ts index 7b1edd9..71a872f 100644 --- a/src/presentation/controller/addressLookUp/template.ts +++ b/src/presentation/controller/addressLookUp/template.ts @@ -13,3 +13,5 @@ export const CONFIRM_REGISTERED_OFFICE_ADDRESS_TEMPLATE = // principal place of business export const POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_TEMPLATE = AddressPageType.postcodePrincipalPlaceOfBusinessAddress; +export const CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_TEMPLATE = + AddressPageType.choosePrincipalPlaceOfBusinessAddress; diff --git a/src/presentation/controller/addressLookUp/url.ts b/src/presentation/controller/addressLookUp/url.ts index 26a159d..0d94c66 100644 --- a/src/presentation/controller/addressLookUp/url.ts +++ b/src/presentation/controller/addressLookUp/url.ts @@ -10,3 +10,4 @@ export const CONFIRM_REGISTERED_OFFICE_ADDRESS_URL = `${BASE_WITH_IDS_URL}/${tem // principal place of business export const POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL = `${BASE_WITH_IDS_URL}/${template.POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_TEMPLATE}`; +export const CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL = `${BASE_WITH_IDS_URL}/${template.CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_TEMPLATE}`; diff --git a/src/presentation/controller/registration/Routing.ts b/src/presentation/controller/registration/Routing.ts index e7a3d5d..d80c769 100644 --- a/src/presentation/controller/registration/Routing.ts +++ b/src/presentation/controller/registration/Routing.ts @@ -4,7 +4,7 @@ import RegistrationPageType from "./PageType"; import PageType from "../PageType"; import * as url from "./url"; import { - POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, + CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, POSTCODE_REGISTERED_OFFICE_ADDRESS_URL } from "../addressLookUp/url"; @@ -41,7 +41,7 @@ const registrationRoutingJurisdiction = { // principal place of business const registrationRoutingGeneralPartners = { - previousUrl: POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, + previousUrl: CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, currentUrl: url.GENERAL_PARTNERS_URL, nextUrl: url.GENERAL_PARTNER_CHOICE_URL, pageType: RegistrationPageType.generalPartners diff --git a/src/presentation/test/integration/registration/address/choose-principal-place-of-business-address.test.ts b/src/presentation/test/integration/registration/address/choose-principal-place-of-business-address.test.ts new file mode 100644 index 0000000..b790ffe --- /dev/null +++ b/src/presentation/test/integration/registration/address/choose-principal-place-of-business-address.test.ts @@ -0,0 +1,130 @@ +import request from "supertest"; +import enTranslationText from "../../../../../../locales/en/translations.json"; +import cyTranslationText from "../../../../../../locales/cy/translations.json"; +import app from "../../app"; +import { + CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL +} from "presentation/controller/addressLookUp/url"; +import { GENERAL_PARTNERS_URL } from "../../../../controller/registration/url"; +import { getUrl, setLocalesEnabled, testTranslations } from "../../../utils"; +import { appDevDependencies } from "config/dev-dependencies"; +import * as config from "config"; +import AddressPageType from "presentation/controller/addressLookUp/PageType"; + +describe("Choose Principal Place Of Business Address Page", () => { + const URL = getUrl(CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL); + const REDIRECT_URL = getUrl(GENERAL_PARTNERS_URL); + + beforeEach(() => { + setLocalesEnabled(false); + appDevDependencies.addressLookUpGateway.setError(false); + appDevDependencies.cacheRepository.feedCache({ + [`${config.APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}principal_place_of_business`]: + { + postal_code: "ST6 3LJ", + premises: "", + address_line_1: "", + address_line_2: "", + locality: "", + country: "" + } + }); + }); + + describe("GET Choose Principal Place Of Business Address Page", () => { + it("should load the choose principal place of business address page with Welsh text", async () => { + setLocalesEnabled(true); + + const res = await request(app).get(URL + "?lang=cy"); + + expect(res.status).toBe(200); + testTranslations( + res.text, + cyTranslationText.choosePrincipalPlaceOfBusinessPage + ); + }); + + it("should load the choose principal place of business address page with English text", async () => { + setLocalesEnabled(true); + + const res = await request(app).get(URL + "?lang=en"); + + expect(res.status).toBe(200); + testTranslations( + res.text, + enTranslationText.choosePrincipalPlaceOfBusinessPage + ); + }); + + it("should populate the address list", async () => { + const res = await request(app).get(URL); + + expect(res.status).toBe(200); + expect(res.text).toContain("2 Duncalf Street, Stoke-On-Trent, ST6 3LJ"); + expect(res.text).toContain( + "The Lodge Duncalf Street, Castle Hill, Stoke-On-Trent, ST6 3LJ" + ); + expect(res.text).toContain("4 Duncalf Street, Stoke-On-Trent, ST6 3LJ"); + expect(res.text).toContain("6 Duncalf Street, Stoke-On-Trent, ST6 3LJ"); + }); + + it("should return error page when gateway getListOfValidPostcodeAddresses throws an error", async () => { + appDevDependencies.addressLookUpGateway.setError(true); + + const res = await request(app).get(URL); + + expect(res.status).toBe(500); + expect(res.text).toContain(enTranslationText.errorPage.title); + }); + }); + + describe("POST Choose Principal Place Of Business Page", () => { + it("should redirect to the next page and add select address to cache", async () => { + const res = await request(app) + .post(URL) + .send({ + pageType: AddressPageType.choosePrincipalPlaceOfBusinessAddress, + selected_address: `{ + "postal_code": "ST6 3LJ", + "premises": "4", + "address_line_1": "DUNCALF STREET", + "address_line_2": "", + "locality": "STOKE-ON-TRENT", + "country": "GB-ENG" + }` + }); + + expect(res.status).toBe(302); + expect(res.text).toContain(`Redirecting to ${REDIRECT_URL}`); + + // Will need to be uncommented when the confirm page is introduced + /* const cache = appDevDependencies.cacheRepository.cache; + expect(cache?.[`${config.APPLICATION_CACHE_KEY}`]).toHaveProperty( + `${config.APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}principal_place_of_business_address`, + { + postal_code: "ST6 3LJ", + premises: "4", + address_line_1: "DUNCALF STREET", + address_line_2: "", + locality: "STOKE-ON-TRENT", + country: "GB-ENG" + } + ); */ + }); + + it("should redirect to the error page if address can't be deserialised", async () => { + const res = await request(app).post(URL).send({ + pageType: AddressPageType.choosePrincipalPlaceOfBusinessAddress, + selected_address: `some address` + }); + + expect(res.status).toBe(500); + expect(res.text).toContain(enTranslationText.errorPage.title); + + const cache = appDevDependencies.cacheRepository.cache; + expect(cache?.[`${config.APPLICATION_CACHE_KEY}`]).not.toHaveProperty( + `${config.APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${AddressPageType.choosePrincipalPlaceOfBusinessAddress}` + ); + }); + }); +}); diff --git a/src/presentation/test/integration/registration/address/postcode-principal-place-of-business-address.test.ts b/src/presentation/test/integration/registration/address/postcode-principal-place-of-business-address.test.ts index c88ccff..6cd993b 100644 --- a/src/presentation/test/integration/registration/address/postcode-principal-place-of-business-address.test.ts +++ b/src/presentation/test/integration/registration/address/postcode-principal-place-of-business-address.test.ts @@ -7,10 +7,9 @@ import cyTranslationText from "../../../../../../locales/cy/translations.json"; import { appDevDependencies } from "../../../../../config/dev-dependencies"; import app from "../../app"; -import { POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL } from "../../../../controller/addressLookUp/url"; +import { POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL } from "../../../../controller/addressLookUp/url"; import { getUrl, setLocalesEnabled, testTranslations } from "../../../utils"; import LimitedPartnershipBuilder from "../../../builder/LimitedPartnershipBuilder"; -import { GENERAL_PARTNERS_URL } from "../../../../controller/registration/url"; import AddressPageType from "../../../../controller/addressLookUp/PageType"; import { APPLICATION_CACHE_KEY, @@ -20,7 +19,7 @@ import { PartnershipType } from "@companieshouse/api-sdk-node/dist/services/limi describe("Postcode Principal Place Of Business Address Page", () => { const URL = getUrl(POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL); - const REDIRECT_URL = getUrl(GENERAL_PARTNERS_URL); + const REDIRECT_URL = getUrl(CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL); const addresses: UKAddress[] = appDevDependencies.addressLookUpGateway.addresses; diff --git a/src/routes/addressLookUp.ts b/src/routes/addressLookUp.ts index 2fda825..aef689e 100644 --- a/src/routes/addressLookUp.ts +++ b/src/routes/addressLookUp.ts @@ -9,7 +9,8 @@ import { CONFIRM_REGISTERED_OFFICE_ADDRESS_URL, ENTER_REGISTERED_OFFICE_ADDRESS_URL, POSTCODE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, - POSTCODE_REGISTERED_OFFICE_ADDRESS_URL + POSTCODE_REGISTERED_OFFICE_ADDRESS_URL, + CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL } from "../presentation/controller/addressLookUp/url"; export const addressLookUpEndpoints = ( @@ -72,6 +73,17 @@ export const addressLookUpEndpoints = ( authentication, dependencies.addressLookUpController.postcodeValidation() ); + + router.get( + CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, + authentication, + dependencies.addressLookUpController.getPageRouting() + ); + router.post( + CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL, + authentication, + dependencies.addressLookUpController.selectAddress() + ); }; export default addressLookUpEndpoints; diff --git a/src/views/choose-principal-place-of-business-address.njk b/src/views/choose-principal-place-of-business-address.njk new file mode 100644 index 0000000..fa1a8b3 --- /dev/null +++ b/src/views/choose-principal-place-of-business-address.njk @@ -0,0 +1,57 @@ +{% extends "layout.njk" %} + +{% import 'includes/macros.njk' as macros %} + +{% set pageTitle = i18n.choosePrincipalPlaceOfBusinessPage.title %} + +{% set addressItems = [] %} +{% for address in props.data.addressList %} + {% set newItem = { + value: address | dump, + text: macros.formatAddress(address), + attributes: { + required: true, + "radio-event-id": "address-radio-selected" + } + } %} + {% set addressItems = addressItems.concat([newItem]) %} +{% endfor %} + +{% block content %} +