Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LP-486 Choose principal place of business page #186

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions locales/cy/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion src/presentation/controller/addressLookUp/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class AddressLookUpController extends AbstractController {
}

private isAddressListRequired(pageType: string): boolean {
return pageType === AddressLookUpPageType.chooseRegisteredOfficeAddress;

return pageType === AddressLookUpPageType.chooseRegisteredOfficeAddress ||
pageType === AddressLookUpPageType.choosePrincipalPlaceOfBusinessAddress ;
}

postcodeValidation(): RequestHandler {
Expand Down
3 changes: 2 additions & 1 deletion src/presentation/controller/addressLookUp/PageType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ enum AddressPageType {
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;
18 changes: 15 additions & 3 deletions src/presentation/controller/addressLookUp/Routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,16 +63,27 @@ 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: "#",
confirmAddressUrl: "#"
}
};

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<
Expand Down
2 changes: 2 additions & 0 deletions src/presentation/controller/addressLookUp/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions src/presentation/controller/addressLookUp/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
4 changes: 2 additions & 2 deletions src/presentation/controller/registration/Routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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}registered_office_address`]:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update this, it is breaking tests atm

Copy link
Contributor Author

@mattch1 mattch1 Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked this is used by the controller for the address lookup it might need renaming to something more generic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add an if statement into the address controller here https://github.com/companieshouse/limited-partnerships-web/blob/main/src/presentation/controller/addressLookUp/Controller.ts#L250, to say, if pagetype == your page, use a different cache key for the address?

{
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}`
);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import request from "supertest";
import enTranslationText from "../../../../../locales/en/translations.json";
import cyTranslationText from "../../../../../locales/cy/translations.json";
import app from "../app";
import enTranslationText from "../../../../../../locales/en/translations.json";
import cyTranslationText from "../../../../../../locales/cy/translations.json";
import app from "../../app";
import {
CHOOSE_REGISTERED_OFFICE_ADDRESS_URL,
CONFIRM_REGISTERED_OFFICE_ADDRESS_URL
} from "presentation/controller/addressLookUp/url";
import { getUrl, setLocalesEnabled, testTranslations } from "../../utils";
import { getUrl, setLocalesEnabled, testTranslations } from "../../../utils";
import { appDevDependencies } from "config/dev-dependencies";
import * as config from "config";
import AddressPageType from "presentation/controller/addressLookUp/PageType";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand Down
14 changes: 13 additions & 1 deletion src/routes/addressLookUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -67,6 +68,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;
57 changes: 57 additions & 0 deletions src/views/choose-principal-place-of-business-address.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% extends "layout.njk" %}

{% import 'includes/macros.njk' as macros %}

{% set pageTitle = i18n.choosePrincipalPlaceOfBusinessPage.title %}

{% set addressItems = [] %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be extracted into a common component used by the various choose pages
Look at postcode

{% 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 %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form class="form" action={{ props.currentUrl }} method="post">
<input type="hidden" name="pageType" value={{ props.pageType }}>
{% include "includes/csrf_token.njk" %}

{% include "includes/proposed-name.njk" %}

{{ govukRadios({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be extracted into a common component used by the various choose pages
Look at postcode

classes: "govuk-radios",
name: "selected_address",
value: props.data.cache['registration_choose-principal-place-of-business-address'] | dump,
fieldset: {
legend: {
text: i18n.choosePrincipalPlaceOfBusinessPage.title,
isPageHeading: true,
classes: "govuk-fieldset__legend--xl"
}
},
items: addressItems
}) }}

<p>
<a href="{{ props.currentUrl | replace(props.pageType, props.data.enterPrincipalPlaceOfBusinessPageType) }}" class="govuk-body-m govuk-link" data-event-id="address-not-on-list">{{ i18n.choosePrincipalPlaceOfBusinessPage.addressLink }}</a>
<p>

{{ govukButton({
text: i18n.buttons.continue,
attributes: {
"id": "submit",
"onclick": "_paq.push(['trackEvent', 'Limited Partnerships', '" + props.pageType + "', document.querySelector('input[name=selected_address]:checked').getAttribute('radio-event-id')])"
}
}) }}
</form>
</div>
</div>
{% endblock %}