Skip to content

Commit 8fb20ae

Browse files
authored
Merge pull request #602 from companieshouse/lp-924-country-missing-error
LP-924 change country missing error on address confirmation
2 parents 039946b + 48e21be commit 8fb20ae

20 files changed

+174
-298
lines changed

locales/cy/errors.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"noComma": "WELSH - Value must not include a comma",
99
"atLeastOneType": "WELSH - Select at least one type of contribution",
1010
"currencyRequired": "WELSH - Select the currency of the capital contribution"
11+
},
12+
13+
"address": {
14+
"confirm": {
15+
"countryMissing": "WELSH - We cannot identify the country for this address. Select Change, then select the country."
16+
}
1117
}
1218
}
1319
}

locales/en/errors.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"noComma": "Value must not include a comma",
99
"atLeastOneType": "Select at least one type of contribution",
1010
"currencyRequired": "Select the currency of the capital contribution"
11+
},
12+
13+
"address": {
14+
"confirm": {
15+
"countryMissing": "We cannot identify the country for this address. Select Change, then select the country."
16+
}
1117
}
1218
}
1319
}

src/application/service/AddressService.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ class AddressService {
167167
}
168168
}
169169

170+
hasCountry(address: Address, uiErrors?: UIErrors | undefined): UIErrors | undefined {
171+
if (!address.country) {
172+
uiErrors ??= new UIErrors();
173+
uiErrors.setWebError("change", this.i18n?.errorMessages?.address?.confirm?.countryMissing);
174+
}
175+
176+
return uiErrors;
177+
}
178+
170179
private checkAddressFieldForCharacterLimit(fieldName: string, fieldValue: string): Record<string, string> {
171180
const fieldNamesWithMaxLength = {
172181
address_line_1: "addressLine1Length",

src/presentation/controller/addressLookUp/Controller.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,26 @@ class AddressLookUpController extends AbstractController {
288288
const isGeneralPartnerAddress = AddressLookUpController.GENERAL_PARTNER_PAGES.has(pageType);
289289
const isLimitedPartnerAddress = AddressLookUpController.LIMITED_PARTNER_PAGES.has(pageType);
290290

291+
const uiErrors = this.addressService.hasCountry(address);
292+
291293
// store in api
292294
let result;
293-
294-
if (isGeneralPartnerAddress) {
295-
result = await this.generalPartnerService.sendPageData(tokens, ids.transactionId, ids.generalPartnerId, data);
296-
} else if (isLimitedPartnerAddress) {
297-
result = await this.limitedPartnerService.sendPageData(tokens, ids.transactionId, ids.limitedPartnerId, data);
295+
if (uiErrors?.hasErrors()) {
296+
result = { errors: uiErrors };
298297
} else {
299-
result = await this.limitedPartnershipService.sendPageData(
300-
tokens,
301-
ids.transactionId,
302-
ids.submissionId,
303-
pageType,
304-
data
305-
);
298+
if (isGeneralPartnerAddress) {
299+
result = await this.generalPartnerService.sendPageData(tokens, ids.transactionId, ids.generalPartnerId, data);
300+
} else if (isLimitedPartnerAddress) {
301+
result = await this.limitedPartnerService.sendPageData(tokens, ids.transactionId, ids.limitedPartnerId, data);
302+
} else {
303+
result = await this.limitedPartnershipService.sendPageData(
304+
tokens,
305+
ids.transactionId,
306+
ids.submissionId,
307+
pageType,
308+
data
309+
);
310+
}
306311
}
307312

308313
if (result?.errors) {

src/presentation/test/integration/postTransition/generalPartner/address/confirm-general-partner-correspondence-address.test.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import request from "supertest";
33
import app from "../../../app";
44
import enTranslationText from "../../../../../../../locales/en/translations.json";
55
import cyTranslationText from "../../../../../../../locales/cy/translations.json";
6+
import enErrorMessages from "../../../../../../../locales/en/errors.json";
7+
import cyErrorMessages from "../../../../../../../locales/cy/errors.json";
68

79
import { getUrl, setLocalesEnabled, testTranslations } from "../../../../utils";
810
import {
@@ -12,7 +14,6 @@ import {
1214
} from "../../../../../controller/addressLookUp/url/postTransition";
1315
import { appDevDependencies } from "../../../../../../config/dev-dependencies";
1416
import AddressPageType from "../../../../../controller/addressLookUp/PageType";
15-
import { ApiErrors } from "../../../../../../domain/entities/UIErrors";
1617
import GeneralPartnerBuilder from "../../../../builder/GeneralPartnerBuilder";
1718
import { GENERAL_PARTNER_CHECK_YOUR_ANSWERS_URL } from "../../../../../controller/postTransition/url";
1819

@@ -127,29 +128,18 @@ describe("Confirm General Partner Correspondence Address Page", () => {
127128
expect(res.text).toContain("You must provide an address");
128129
});
129130

130-
it("should show validation error message if validation error occurs when saving address", async () => {
131-
const generalPartner = new GeneralPartnerBuilder()
132-
.withId(appDevDependencies.generalPartnerGateway.generalPartnerId)
133-
.isPerson()
134-
.build();
135-
136-
appDevDependencies.generalPartnerGateway.feedGeneralPartners([generalPartner]);
137-
138-
const apiErrors: ApiErrors = {
139-
errors: {
140-
"correspondenceAddress.country": "must not be null"
141-
}
142-
};
143-
144-
appDevDependencies.generalPartnerGateway.feedErrors(apiErrors);
145-
146-
const res = await request(app).post(URL).send({
131+
it.each([
132+
[ "en", enErrorMessages, ],
133+
[ "cy", cyErrorMessages ]
134+
])("should show validation error message if validation error occurs when saving address with lang %s", async (lang: string, errorMessagesJson: any) => {
135+
setLocalesEnabled(true);
136+
const res = await request(app).post(`${URL}?lang=${lang}`).send({
147137
pageType: AddressPageType.confirmGeneralPartnerCorrespondenceAddress,
148138
address: `{"postal_code": "ST6 3LJ","premises": "4","address_line_1": "DUNCALF STREET","address_line_2": "","locality": "STOKE-ON-TRENT","country": ""}`
149139
});
150140

151141
expect(res.status).toBe(200);
152-
expect(res.text).toContain("must not be null");
142+
expect(res.text).toContain(errorMessagesJson.errorMessages.address.confirm.countryMissing);
153143
});
154144
});
155145
});

src/presentation/test/integration/postTransition/generalPartner/address/confirm-general-partner-principal-office-address.test.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import request from "supertest";
22

33
import enTranslationText from "../../../../../../../locales/en/translations.json";
44
import cyTranslationText from "../../../../../../../locales/cy/translations.json";
5+
import enErrorMessages from "../../../../../../../locales/en/errors.json";
6+
import cyErrorMessages from "../../../../../../../locales/cy/errors.json";
57

68
import app from "../../../app";
79
import { getUrl, setLocalesEnabled, testTranslations } from "../../../../utils";
810
import { appDevDependencies } from "../../../../../../config/dev-dependencies";
9-
import { ApiErrors } from "../../../../../../domain/entities/UIErrors";
1011

1112
import {
1213
CONFIRM_GENERAL_PARTNER_PRINCIPAL_OFFICE_ADDRESS_URL,
@@ -128,29 +129,18 @@ describe("Confirm General Partner Principal Office Address Page", () => {
128129
expect(res.text).toContain("You must provide an address");
129130
});
130131

131-
it("should show validation error message if validation error occurs when saving address", async () => {
132-
const generalPartner = new GeneralPartnerBuilder()
133-
.withId(appDevDependencies.generalPartnerGateway.generalPartnerId)
134-
.isPerson()
135-
.build();
136-
137-
appDevDependencies.generalPartnerGateway.feedGeneralPartners([generalPartner]);
138-
139-
const apiErrors: ApiErrors = {
140-
errors: {
141-
"usualResidentialAddress.country": "must not be null"
142-
}
143-
};
144-
145-
appDevDependencies.generalPartnerGateway.feedErrors(apiErrors);
146-
147-
const res = await request(app).post(URL).send({
132+
it.each([
133+
[ "en", enErrorMessages, ],
134+
[ "cy", cyErrorMessages ]
135+
])("should show validation error message if validation error occurs when saving address with lang %s", async (lang: string, errorMessagesJson: any) => {
136+
setLocalesEnabled(true);
137+
const res = await request(app).post(`${URL}?lang=${lang}`).send({
148138
pageType: AddressPageType.confirmGeneralPartnerPrincipalOfficeAddress,
149139
address: `{"postal_code": "ST6 3LJ","premises": "4","address_line_1": "DUNCALF STREET","address_line_2": "","locality": "STOKE-ON-TRENT","country": ""}`
150140
});
151141

152142
expect(res.status).toBe(200);
153-
expect(res.text).toContain("must not be null");
143+
expect(res.text).toContain(errorMessagesJson.errorMessages.address.confirm.countryMissing);
154144
});
155145
});
156146
});

src/presentation/test/integration/postTransition/generalPartner/address/confirm-general-partner-usual-residential-address.test.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import request from "supertest";
33
import app from "../../../app";
44
import enTranslationText from "../../../../../../../locales/en/translations.json";
55
import cyTranslationText from "../../../../../../../locales/cy/translations.json";
6+
import enErrorMessages from "../../../../../../../locales/en/errors.json";
7+
import cyErrorMessages from "../../../../../../../locales/cy/errors.json";
68

79
import { getUrl, setLocalesEnabled, testTranslations } from "../../../../utils";
810
import {
@@ -14,7 +16,6 @@ import {
1416
} from "../../../../../controller/addressLookUp/url/postTransition";
1517
import { appDevDependencies } from "../../../../../../config/dev-dependencies";
1618
import AddressPageType from "../../../../../controller/addressLookUp/PageType";
17-
import { ApiErrors } from "../../../../../../domain/entities/UIErrors";
1819
import GeneralPartnerBuilder from "../../../../builder/GeneralPartnerBuilder";
1920

2021
describe("Confirm General Partner Usual Residential Address Page", () => {
@@ -135,29 +136,18 @@ describe("Confirm General Partner Usual Residential Address Page", () => {
135136
expect(res.text).toContain("You must provide an address");
136137
});
137138

138-
it("should show validation error message if validation error occurs when saving address", async () => {
139-
const generalPartner = new GeneralPartnerBuilder()
140-
.withId(appDevDependencies.generalPartnerGateway.generalPartnerId)
141-
.isPerson()
142-
.build();
143-
144-
appDevDependencies.generalPartnerGateway.feedGeneralPartners([generalPartner]);
145-
146-
const apiErrors: ApiErrors = {
147-
errors: {
148-
"usualResidentialAddress.country": "must not be null"
149-
}
150-
};
151-
152-
appDevDependencies.generalPartnerGateway.feedErrors(apiErrors);
153-
154-
const res = await request(app).post(URL).send({
139+
it.each([
140+
[ "en", enErrorMessages, ],
141+
[ "cy", cyErrorMessages ]
142+
])("should show validation error message if validation error occurs when saving address with lang %s", async (lang: string, errorMessagesJson: any) => {
143+
setLocalesEnabled(true);
144+
const res = await request(app).post(`${URL}?lang=${lang}`).send({
155145
pageType: AddressPageType.confirmGeneralPartnerUsualResidentialAddress,
156146
address: `{"postal_code": "ST6 3LJ","premises": "4","address_line_1": "DUNCALF STREET","address_line_2": "","locality": "STOKE-ON-TRENT","country": ""}`
157147
});
158148

159149
expect(res.status).toBe(200);
160-
expect(res.text).toContain("must not be null");
150+
expect(res.text).toContain(errorMessagesJson.errorMessages.address.confirm.countryMissing);
161151
});
162152

163153
it("should redirect to the confirm correspondance address if already saved", async () => {

src/presentation/test/integration/postTransition/limitedPartner/address/confirm-limited-partner-principal-office-address.test.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import request from "supertest";
22

33
import enTranslationText from "../../../../../../../locales/en/translations.json";
44
import cyTranslationText from "../../../../../../../locales/cy/translations.json";
5+
import enErrorMessages from "../../../../../../../locales/en/errors.json";
6+
import cyErrorMessages from "../../../../../../../locales/cy/errors.json";
57

68
import app from "../../../app";
79
import { getUrl, setLocalesEnabled, testTranslations } from "../../../../utils";
810
import { appDevDependencies } from "../../../../../../config/dev-dependencies";
9-
import { ApiErrors } from "../../../../../../domain/entities/UIErrors";
1011

1112
import {
1213
CONFIRM_LIMITED_PARTNER_PRINCIPAL_OFFICE_ADDRESS_URL,
@@ -128,29 +129,18 @@ describe("Confirm Limited Partner Principal Office Address Page", () => {
128129
expect(res.text).toContain("You must provide an address");
129130
});
130131

131-
it("should show validation error message if validation error occurs when saving address", async () => {
132-
const limitedPartner = new LimitedPartnerBuilder()
133-
.withId(appDevDependencies.limitedPartnerGateway.limitedPartnerId)
134-
.isPerson()
135-
.build();
136-
137-
appDevDependencies.limitedPartnerGateway.feedLimitedPartners([limitedPartner]);
138-
139-
const apiErrors: ApiErrors = {
140-
errors: {
141-
"usualResidentialAddress.country": "must not be null"
142-
}
143-
};
144-
145-
appDevDependencies.limitedPartnerGateway.feedErrors(apiErrors);
146-
147-
const res = await request(app).post(URL).send({
132+
it.each([
133+
[ "en", enErrorMessages, ],
134+
[ "cy", cyErrorMessages ]
135+
])("should show validation error message if validation error occurs when saving address with lang %s", async (lang: string, errorMessagesJson: any) => {
136+
setLocalesEnabled(true);
137+
const res = await request(app).post(`${URL}?lang=${lang}`).send({
148138
pageType: AddressPageType.confirmLimitedPartnerPrincipalOfficeAddress,
149139
address: `{"postal_code": "ST6 3LJ","premises": "4","address_line_1": "DUNCALF STREET","address_line_2": "","locality": "STOKE-ON-TRENT","country": ""}`
150140
});
151141

152142
expect(res.status).toBe(200);
153-
expect(res.text).toContain("must not be null");
143+
expect(res.text).toContain(errorMessagesJson.errorMessages.address.confirm.countryMissing);
154144
});
155145
});
156146
});

src/presentation/test/integration/postTransition/limitedPartner/address/confirm-limited-partner-usual-residential-address.test.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import request from "supertest";
33
import app from "../../../app";
44
import enTranslationText from "../../../../../../../locales/en/translations.json";
55
import cyTranslationText from "../../../../../../../locales/cy/translations.json";
6+
import enErrorMessages from "../../../../../../../locales/en/errors.json";
7+
import cyErrorMessages from "../../../../../../../locales/cy/errors.json";
68

79
import { getUrl, setLocalesEnabled, testTranslations } from "../../../../utils";
810
import {
@@ -12,7 +14,6 @@ import {
1214
} from "../../../../../controller/addressLookUp/url/postTransition";
1315
import { appDevDependencies } from "../../../../../../config/dev-dependencies";
1416
import AddressPageType from "../../../../../controller/addressLookUp/PageType";
15-
import { ApiErrors } from "../../../../../../domain/entities/UIErrors";
1617
import LimitedPartnerBuilder from "../../../../builder/LimitedPartnerBuilder";
1718
import { LIMITED_PARTNER_CHECK_YOUR_ANSWERS_URL } from "../../../../../controller/postTransition/url";
1819

@@ -134,29 +135,18 @@ describe("Confirm Limited Partner Usual Residential Address Page", () => {
134135
expect(res.text).toContain("You must provide an address");
135136
});
136137

137-
it("should show validation error message if validation error occurs when saving address", async () => {
138-
const limitedPartner = new LimitedPartnerBuilder()
139-
.withId(appDevDependencies.limitedPartnerGateway.limitedPartnerId)
140-
.isPerson()
141-
.build();
142-
143-
appDevDependencies.limitedPartnerGateway.feedLimitedPartners([limitedPartner]);
144-
145-
const apiErrors: ApiErrors = {
146-
errors: {
147-
"usualResidentialAddress.country": "must not be null"
148-
}
149-
};
150-
151-
appDevDependencies.limitedPartnerGateway.feedErrors(apiErrors);
152-
153-
const res = await request(app).post(URL).send({
138+
it.each([
139+
[ "en", enErrorMessages, ],
140+
[ "cy", cyErrorMessages ]
141+
])("should show validation error message if validation error occurs when saving address with lang %s", async (lang: string, errorMessagesJson: any) => {
142+
setLocalesEnabled(true);
143+
const res = await request(app).post(`${URL}?lang=${lang}`).send({
154144
pageType: AddressPageType.confirmLimitedPartnerUsualResidentialAddress,
155145
address: `{"postal_code": "ST6 3LJ","premises": "4","address_line_1": "DUNCALF STREET","address_line_2": "","locality": "STOKE-ON-TRENT","country": ""}`
156146
});
157147

158148
expect(res.status).toBe(200);
159-
expect(res.text).toContain("must not be null");
149+
expect(res.text).toContain(errorMessagesJson.errorMessages.address.confirm.countryMissing);
160150
});
161151
});
162152
});

0 commit comments

Comments
 (0)