Skip to content

Commit 945bd39

Browse files
authored
Merge pull request #595 from companieshouse/lp-1346-trim-company-number-input
LP-1346 Trailing spaces in company number should be valid
2 parents 13b47c9 + 087da6f commit 945bd39

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

src/presentation/controller/postTransition/LimitedPartnershipController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,20 @@ class LimitedPartnershipController extends AbstractController {
123123
const pageRouting = super.getRouting(postTransitionRouting, pageType, request);
124124
const { company_number } = request.body;
125125

126-
const result = await this.companyService.buildLimitedPartnershipFromCompanyProfile(tokens, company_number);
126+
const result = await this.companyService.buildLimitedPartnershipFromCompanyProfile(tokens, company_number.trim());
127127

128128
if (result.errors) {
129129
response.render(
130130
super.templateName(pageRouting.currentUrl),
131-
super.makeProps(pageRouting, { company_number }, result.errors)
131+
super.makeProps(pageRouting, { company_number: company_number.trim() }, result.errors)
132132
);
133133

134134
return;
135135
}
136136

137137
const url = super.insertIdsInUrl(pageRouting.nextUrl, {
138138
...ids,
139-
companyId: company_number
139+
companyId: company_number.trim()
140140
});
141141

142142
response.redirect(url);

src/presentation/controller/transition/LimitedPartnershipController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,18 @@ class LimitedPartnershipController extends PartnershipController {
188188
const pageRouting = super.getRouting(transitionRouting, pageType, request);
189189
const { company_number } = request.body;
190190

191-
const result = await this.companyService.buildLimitedPartnershipFromCompanyProfile(tokens, company_number);
191+
const result = await this.companyService.buildLimitedPartnershipFromCompanyProfile(tokens, company_number.trim());
192192

193193
if (result.errors) {
194194
response.render(
195195
super.templateName(pageRouting.currentUrl),
196-
super.makeProps(pageRouting, { company_number }, result.errors)
196+
super.makeProps(pageRouting, { company_number: company_number.trim() }, result.errors)
197197
);
198198

199199
return;
200200
}
201201

202-
const url = super.insertIdsInUrl(pageRouting.nextUrl, { ...ids, companyId: company_number }, request.url);
202+
const url = super.insertIdsInUrl(pageRouting.nextUrl, { ...ids, companyId: company_number.trim() }, request.url);
203203

204204
response.redirect(url);
205205
} catch (error) {

src/presentation/test/integration/postTransition/company-number.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ describe("Company number page", () => {
6565
expect(res.text).toContain(`Redirecting to ${REDIRECT_URL}`);
6666
});
6767

68+
it("should redirect to confirmation page if company_number has trailing spaces", async () => {
69+
const res = await request(app).post(URL).send({
70+
pageType: TransitionPageType.companyNumber,
71+
company_number: "LP123456 "
72+
});
73+
74+
const REDIRECT_URL = getUrl(CONFIRM_LIMITED_PARTNERSHIP_URL);
75+
76+
expect(res.status).toBe(302);
77+
expect(res.text).toContain(`Redirecting to ${REDIRECT_URL}`);
78+
});
79+
6880
it("should return an error if company_number is not valid", async () => {
6981
appDevDependencies.companyGateway.setError(true);
7082

src/presentation/test/integration/transition/company-number.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ describe("Company number page", () => {
6565
expect(res.text).toContain(`Redirecting to ${REDIRECT_URL}`);
6666
});
6767

68+
it("should redirect to confirmation page if company_number has trailing spaces", async () => {
69+
const res = await request(app).post(URL).send({
70+
pageType: TransitionPageType.companyNumber,
71+
company_number: "LP123456 "
72+
});
73+
74+
const REDIRECT_URL = getUrl(CONFIRM_LIMITED_PARTNERSHIP_URL);
75+
76+
expect(res.status).toBe(302);
77+
expect(res.text).toContain(`Redirecting to ${REDIRECT_URL}`);
78+
});
79+
6880
it("should return an error if company_number is not valid", async () => {
6981
appDevDependencies.companyGateway.setError(true);
7082

0 commit comments

Comments
 (0)