Skip to content

Commit 76d4657

Browse files
authored
Merge pull request #607 from companieshouse/lp-1309-use-specific-date-of-upate-messages-lp6d
LP-1309 PT Specific date of update error messages for partnership upd…
2 parents 7ba2e28 + c2c5bf5 commit 76d4657

File tree

8 files changed

+56
-21
lines changed

8 files changed

+56
-21
lines changed

locales/cy/errors.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
"confirm": {
1515
"countryMissing": "WELSH - We cannot identify the country for this address. Select Change, then select the country."
1616
}
17+
},
18+
19+
"dateOfUpdate": {
20+
"registeredOfficeAddress": "WELSH - Date the registered office address changed must be the same as or after limited partnership’s registration date",
21+
"principalPlaceOfBusinessAddress": "WELSH - Date the principal place of business changed must be the same as or after limited partnership’s registration date’",
22+
"partnershipName": "WELSH - Date the partnership name changed must be the same as or after limited partnership’s registration date",
23+
"term": "WELSH - Date the term changed must be the same as or after limited partnership’s registration date"
1724
}
1825
}
1926
}

locales/en/errors.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
"confirm": {
1515
"countryMissing": "We cannot identify the country for this address. Select Change, then select the country."
1616
}
17+
},
18+
19+
"dateOfUpdate": {
20+
"registeredOfficeAddress": "Date the registered office address changed must be the same as or after limited partnership's registration date",
21+
"principalPlaceOfBusinessAddress": "Date the principal place of business changed must be the same as or after limited partnership's registration date",
22+
"partnershipName": "Date the partnership name changed must be the same as or after limited partnership's registration date",
23+
"term": "Date the term changed must be the same as or after limited partnership's registration date"
1724
}
1825
}
1926
}

src/presentation/controller/postTransition/LimitedPartnershipController.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ class LimitedPartnershipController extends AbstractController {
324324
}
325325

326326
if (patchResult?.errors) {
327+
this.specifyErrorMessagesForDateOfUpdate(patchResult.errors, response, pageRouting);
327328
return response.render(template, super.makeProps(pageRouting, errorData, patchResult.errors));
328329
}
329330

@@ -335,6 +336,13 @@ class LimitedPartnershipController extends AbstractController {
335336
};
336337
}
337338

339+
private specifyErrorMessagesForDateOfUpdate(errors: UIErrors, response: Response<any, Record<string, any>>, pageRouting: PageRouting) {
340+
if (errors.errors.errorList[0].href === "#date_of_update") {
341+
errors.errors.errorList[0].text = response.locals.i18n.errorMessages.dateOfUpdate[pageRouting?.data?.titleKey];
342+
errors.errors.date_of_update.text = response.locals.i18n.errorMessages.dateOfUpdate[pageRouting?.data?.titleKey];
343+
}
344+
}
345+
338346
getDateOfUpdate() {
339347
return async (request: Request, response: Response, next: NextFunction) => {
340348
try {

src/presentation/test/integration/postTransition/limitedPartnership/dateOfUpdate/when-did-the-name-of-the-partnership-change.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { LimitedPartnership } from "@companieshouse/api-sdk-node/dist/services/l
33

44
import enTranslationText from "../../../../../../../locales/en/translations.json";
55
import cyTranslationText from "../../../../../../../locales/cy/translations.json";
6+
import enErrorMessages from "../../../../../../../locales/en/errors.json";
67

78
import app from "../../../app";
89
import { appDevDependencies } from "../../../../../../config/dev-dependencies";
9-
import { getUrl, setLocalesEnabled } from "../../../../utils";
10+
import { getUrl, setLocalesEnabled, toEscapedHtml } from "../../../../utils";
1011
import { ApiErrors } from "../../../../../../domain/entities/UIErrors";
1112

1213
import {
@@ -74,14 +75,15 @@ describe("Partnership name change date page", () => {
7475
});
7576
});
7677

77-
it("should replay entered data when invalid date of update is entered and a validation error occurs", async () => {
78+
it("should display the specifc error message rather than the original when the date is before the incorporation date", async () => {
7879
const limitedPartnership = new LimitedPartnershipBuilder().withDateOfUpdate("2024-10-10").build();
7980

8081
appDevDependencies.limitedPartnershipGateway.feedLimitedPartnerships([limitedPartnership]);
8182

82-
const errorMessage = "The date is invalid";
83+
const originalErrorMessage = "Default";
84+
const expectedErrorMessage = toEscapedHtml(enErrorMessages.errorMessages.dateOfUpdate.partnershipName);
8385
const apiErrors: ApiErrors = {
84-
errors: { date_of_update: errorMessage }
86+
errors: { date_of_update: originalErrorMessage }
8587
};
8688
appDevDependencies.limitedPartnershipGateway.feedErrors(apiErrors);
8789

@@ -90,6 +92,7 @@ describe("Partnership name change date page", () => {
9092
});
9193

9294
expect(res.status).toBe(200);
93-
expect(res.text).toContain(errorMessage);
95+
expect(res.text).not.toContain(originalErrorMessage);
96+
expect(res.text).toContain(expectedErrorMessage);
9497
});
9598
});

src/presentation/test/integration/postTransition/limitedPartnership/dateOfUpdate/when-did-the-principal-place-of-business-address-change.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import request from "supertest";
22
import enTranslationText from "../../../../../../../locales/en/translations.json";
33
import cyTranslationText from "../../../../../../../locales/cy/translations.json";
4+
import enErrorMessages from "../../../../../../../locales/en/errors.json";
45
import app from "../../../app";
5-
import { getUrl, setLocalesEnabled } from "../../../../utils";
6+
import { getUrl, setLocalesEnabled, toEscapedHtml } from "../../../../utils";
67
import { appDevDependencies } from "../../../../../../config/dev-dependencies";
78
import LimitedPartnershipBuilder from "../../../../builder/LimitedPartnershipBuilder";
89
import PostTransitionPageType from "../../../../../controller/postTransition/pageType";
@@ -50,14 +51,16 @@ describe("Partnership principal place of business address change date page", ()
5051
expect(res.text).toContain(`Redirecting to ${redirectUrl}`);
5152
});
5253

53-
it("should replay entered data when invalid date of update is entered and a validation error occurs", async () => {
54+
it("should display the specifc error message rather than the original when the date is before the incorporation date", async () => {
5455
const limitedPartnership = new LimitedPartnershipBuilder().withDateOfUpdate("2024-10-10").build();
5556

5657
appDevDependencies.limitedPartnershipGateway.feedLimitedPartnerships([limitedPartnership]);
5758

58-
const errorMessage = "The date is invalid";
59+
const originalErrorMessage = "Default";
60+
const expectedErrorMessage = toEscapedHtml(enErrorMessages.errorMessages.dateOfUpdate.principalPlaceOfBusinessAddress);
61+
5962
const apiErrors: ApiErrors = {
60-
errors: { date_of_update: errorMessage }
63+
errors: { date_of_update: originalErrorMessage }
6164
};
6265
appDevDependencies.limitedPartnershipGateway.feedErrors(apiErrors);
6366

@@ -66,7 +69,8 @@ describe("Partnership principal place of business address change date page", ()
6669
});
6770

6871
expect(res.status).toBe(200);
69-
expect(res.text).toContain(errorMessage);
72+
expect(res.text).not.toContain(originalErrorMessage);
73+
expect(res.text).toContain(expectedErrorMessage);
7074
});
7175
});
7276
});

src/presentation/test/integration/postTransition/limitedPartnership/dateOfUpdate/when-did-the-registered-office-address-change.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import request from "supertest";
22
import enTranslationText from "../../../../../../../locales/en/translations.json";
33
import cyTranslationText from "../../../../../../../locales/cy/translations.json";
4+
import enErrorMessages from "../../../../../../../locales/en/errors.json";
45
import app from "../../../app";
56
import { appDevDependencies } from "../../../../../../config/dev-dependencies";
6-
import { getUrl, setLocalesEnabled } from "../../../../utils";
7+
import { getUrl, setLocalesEnabled, toEscapedHtml } from "../../../../utils";
78
import { REGISTERED_OFFICE_ADDRESS_CHANGE_CHECK_YOUR_ANSWERS_URL, WHEN_DID_THE_REGISTERED_OFFICE_ADDRESS_CHANGE_URL } from "../../../../../controller/postTransition/url";
89
import CompanyProfileBuilder from "../../../../builder/CompanyProfileBuilder";
910
import PostTransitionPageType from "../../../../../controller/postTransition/pageType";
@@ -57,14 +58,15 @@ describe("Registered office address change date page", () => {
5758
});
5859
});
5960

60-
it("should replay entered data when invalid date of update is entered and a validation error occurs", async () => {
61+
it("should display the specifc error message rather than the original when the date is before the incorporation date", async () => {
6162
const limitedPartnership = new LimitedPartnershipBuilder().withDateOfUpdate("2024-10-10").build();
6263

6364
appDevDependencies.limitedPartnershipGateway.feedLimitedPartnerships([limitedPartnership]);
6465

65-
const errorMessage = "The date is invalid";
66+
const originalErrorMessage = "Default";
67+
const expectedErrorMessage = toEscapedHtml(enErrorMessages.errorMessages.dateOfUpdate.registeredOfficeAddress);
6668
const apiErrors: ApiErrors = {
67-
errors: { date_of_update: errorMessage }
69+
errors: { date_of_update: originalErrorMessage }
6870
};
6971
appDevDependencies.limitedPartnershipGateway.feedErrors(apiErrors);
7072

@@ -73,6 +75,7 @@ describe("Registered office address change date page", () => {
7375
});
7476

7577
expect(res.status).toBe(200);
76-
expect(res.text).toContain(errorMessage);
78+
expect(res.text).not.toContain(originalErrorMessage);
79+
expect(res.text).toContain(expectedErrorMessage);
7780
});
7881
});

src/presentation/test/integration/postTransition/limitedPartnership/dateOfUpdate/when-did-the-term-change.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ 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";
56

67
import app from "../../../app";
78
import { appDevDependencies } from "../../../../../../config/dev-dependencies";
8-
import { getUrl, setLocalesEnabled } from "../../../../utils";
9+
import { getUrl, setLocalesEnabled, toEscapedHtml } from "../../../../utils";
910
import { ApiErrors } from "../../../../../../domain/entities/UIErrors";
1011

1112
import {
@@ -64,14 +65,15 @@ describe("Partnership term change date page", () => {
6465
});
6566
});
6667

67-
it("should replay entered data when invalid date of update is entered and a validation error occurs", async () => {
68+
it("should display the specifc error message rather than the original when the date is before the incorporation date", async () => {
6869
const limitedPartnership = new LimitedPartnershipBuilder().withDateOfUpdate("2024-10-10").build();
6970

7071
appDevDependencies.limitedPartnershipGateway.feedLimitedPartnerships([limitedPartnership]);
7172

72-
const errorMessage = "The date is invalid";
73+
const originalErrorMessage = "Default";
74+
const expectedErrorMessage = toEscapedHtml(enErrorMessages.errorMessages.dateOfUpdate.term);
7375
const apiErrors: ApiErrors = {
74-
errors: { date_of_update: errorMessage }
76+
errors: { date_of_update: originalErrorMessage }
7577
};
7678
appDevDependencies.limitedPartnershipGateway.feedErrors(apiErrors);
7779

@@ -80,6 +82,7 @@ describe("Partnership term change date page", () => {
8082
});
8183

8284
expect(res.status).toBe(200);
83-
expect(res.text).toContain(errorMessage);
85+
expect(res.text).not.toContain(originalErrorMessage);
86+
expect(res.text).toContain(expectedErrorMessage);
8487
});
8588
});

src/views/date-of-update.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{{ govukDateInput({
3232
id: "date_of_update",
3333
namePrefix: "date_of_update",
34-
errorMessage: props.errors.date_of_update if props.errors,
34+
errorMessage: props.errors.date_of_update if props.errors.date_of_update,
3535
fieldset: {
3636
legend: {
3737
text: pageTitle,

0 commit comments

Comments
 (0)