Skip to content

Commit

Permalink
Merge pull request #90 from companieshouse/lp-239-lp-person-or-legal-…
Browse files Browse the repository at this point in the history
…entity

LP-239 Add the limited partner choice page
  • Loading branch information
markpit authored Dec 11, 2024
2 parents 0037401 + f203308 commit c9bfca8
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 20 deletions.
7 changes: 7 additions & 0 deletions locales/cy/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
}
},

"limitedPartnerChoicePage" : {
"isPersonOrLegalEntity" : "WELSH - Is the limited partner a person or a legal entity?",
"isPersonOrLegalEntityHint" : "WELSH - You can add more later.",
"person" : "WELSH - A person",
"legalEntity" : "WELSH - A legal entity"
},

"namePage" : {
"title" : "WELSH - Limited partnership name",
"whatIsName" : "WELSH - What is the limited partnership name?",
Expand Down
7 changes: 7 additions & 0 deletions locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
}
},

"limitedPartnerChoicePage" : {
"isPersonOrLegalEntity" : "Is the limited partner a person or a legal entity?",
"isPersonOrLegalEntityHint" : "You can add more later.",
"person" : "A person",
"legalEntity" : "A legal entity"
},

"namePage" : {
"title" : "Limited partnership name",
"whatIsName" : "What is the limited partnership name?",
Expand Down
8 changes: 3 additions & 5 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export const ERROR_TEMPLATE = "error-page";
export const NOT_FOUND_TEMPLATE = "page-not-found";

// Routing Paths
export const SUBMISSION_ID = "submissionId";
export const TRANSACTION_ID = "transactionId";
export const BASE_URL = "/limited-partnerships";

export const TRANSACTION_ID = ":transactionId";
export const SUBMISSION_ID = ":submissionId";

export const BASE_WITH_IDS_URL = `${BASE_URL}/transaction/${TRANSACTION_ID}/submission/${SUBMISSION_ID}`;
export const BASE_WITH_IDS_URL = `${BASE_URL}/transaction/:${TRANSACTION_ID}/submission/:${SUBMISSION_ID}`;
5 changes: 3 additions & 2 deletions src/presentation/controller/AbstractController.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SUBMISSION_ID, TRANSACTION_ID } from "../../config/constants";
import { PageRouting, pageRoutingDefault, PagesRouting } from "./PageRouting";
import PageType from "./PageType";

Expand Down Expand Up @@ -41,11 +42,11 @@ abstract class AbstractController {
}

protected insertTransactionId(url: string, transactionId: string): string {
return transactionId ? url.replace(":transactionId", transactionId) : url;
return transactionId ? url.replace(`:${TRANSACTION_ID}`, transactionId) : url;
}

protected insertSubmissionId(url: string, submissionId: string): string {
return submissionId ? url.replace(":submissionId", submissionId) : url;
return submissionId ? url.replace(`:${SUBMISSION_ID}`, submissionId) : url;
}

protected insertIdsInAllUrl(
Expand Down
9 changes: 5 additions & 4 deletions src/presentation/controller/registration/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import RegistrationService from "../../../application/registration/Service";
import registrationsRouting from "./Routing";
import AbstractController from "../AbstractController";
import PageType from "./PageType";
import { SUBMISSION_ID, TRANSACTION_ID } from "../../../config/constants";

class RegistrationController extends AbstractController {
private registrationService: RegistrationService;
Expand Down Expand Up @@ -83,15 +84,15 @@ class RegistrationController extends AbstractController {

const registrationRouting = super.getRouting(
registrationsRouting,
type
type,
request.params[TRANSACTION_ID],
request.params[SUBMISSION_ID]
);

const url = super.insertIdsInUrl(registrationRouting.nextUrl);

const pageType = escape(request.body.pageType);
const parameter = escape(request.body.parameter);

response.redirect(`${url}?${pageType}=${parameter}`);
response.redirect(`${registrationRouting.nextUrl}?${pageType}=${parameter}`);
} catch (error) {
next(error);
}
Expand Down
1 change: 1 addition & 0 deletions src/presentation/controller/registration/PageType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enum RegistrationPageType {
generalPartners = "general-partners",
limitedPartners = "limited-partners",
generalPartnerChoice = "general-partner-choice",
limitedPartnerChoice = "limited-partner-choice",
next = "next",
}

Expand Down
23 changes: 16 additions & 7 deletions src/presentation/controller/registration/Routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ import {
import RegistrationPageType from "./PageType";
import PageType from "../PageType";

const START_URL = `${BASE_URL}/start`;
// Templates
export const WHICH_TYPE_TEMPLATE = RegistrationPageType.whichType;
export const NAME_TEMPLATE = RegistrationPageType.name;
export const EMAIL_TEMPLATE = RegistrationPageType.email;
export const GENERAL_PARTNERS_TEMPLATE = RegistrationPageType.generalPartners;
export const LIMITED_PARTNERS_TEMPLATE = RegistrationPageType.limitedPartners;
export const GENERAL_PARTNER_CHOICE_TEMPLATE = RegistrationPageType.generalPartnerChoice;

export const LIMITED_PARTNER_CHOICE_TEMPLATE = RegistrationPageType.limitedPartnerChoice;
export const NEXT_TEMPLATE = RegistrationPageType.next;

// URLs
const START_URL = `${BASE_URL}/start`;
export const WHICH_TYPE_URL = `${BASE_URL}/${WHICH_TYPE_TEMPLATE}`;
export const NAME_URL = `${BASE_URL}/${NAME_TEMPLATE}`;
export const EMAIL_URL = `${BASE_WITH_IDS_URL}/${EMAIL_TEMPLATE}`;

export const GENERAL_PARTNERS_URL = `${BASE_WITH_IDS_URL}/${GENERAL_PARTNERS_TEMPLATE}`;
export const GENERAL_PARTNER_CHOICE_URL = `${BASE_WITH_IDS_URL}/${GENERAL_PARTNER_CHOICE_TEMPLATE}`;

export const LIMITED_PARTNERS_URL = `${BASE_WITH_IDS_URL}/${LIMITED_PARTNERS_TEMPLATE}`;

export const LIMITED_PARTNER_CHOICE_URL = `${BASE_WITH_IDS_URL}/${LIMITED_PARTNER_CHOICE_TEMPLATE}`;
export const NEXT_URL = `${BASE_WITH_IDS_URL}/${NEXT_TEMPLATE}`;

const registrationRoutingPartnershipType = {
Expand All @@ -43,7 +44,7 @@ const registrationRoutingName = {
};

const registrationRoutingEmail = {
previousUrl: WHICH_TYPE_URL,
previousUrl: NAME_URL,
currentUrl: EMAIL_URL,
nextUrl: GENERAL_PARTNERS_URL,
pageType: RegistrationPageType.email,
Expand All @@ -66,12 +67,19 @@ const registrationRoutingLimitedPartners = {
const registrationRoutingGeneralPartnerChoice = {
previousUrl: GENERAL_PARTNERS_URL,
currentUrl: GENERAL_PARTNER_CHOICE_URL,
nextUrl: NEXT_URL,
nextUrl: LIMITED_PARTNER_CHOICE_URL,
pageType: RegistrationPageType.generalPartnerChoice,
};

export const registrationRoutingLimitedPartnerChoice = {
previousUrl: GENERAL_PARTNER_CHOICE_URL,
currentUrl: LIMITED_PARTNER_CHOICE_URL,
nextUrl: NEXT_URL,
pageType: RegistrationPageType.limitedPartnerChoice,
};

const registrationRoutingNext = {
previousUrl: GENERAL_PARTNERS_URL,
previousUrl: LIMITED_PARTNER_CHOICE_URL,
currentUrl: NEXT_URL,
nextUrl: "/",
pageType: RegistrationPageType.next,
Expand All @@ -84,6 +92,7 @@ const list = [
registrationRoutingGeneralPartners,
registrationRoutingLimitedPartners,
registrationRoutingGeneralPartnerChoice,
registrationRoutingLimitedPartnerChoice,
registrationRoutingNext,

];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cyTranslationText from "../../../../../locales/cy/translations.json";
import app from "../app";
import {
GENERAL_PARTNER_CHOICE_URL,
NEXT_URL,
LIMITED_PARTNER_CHOICE_URL,
} from "../../../controller/registration/Routing";
import RegistrationPageType from "../../../../presentation/controller/registration/PageType";

Expand Down Expand Up @@ -43,7 +43,7 @@ describe("General Partner Choice Page", () => {
parameter: selectedType,
});

const redirectUrl = `${NEXT_URL}?${RegistrationPageType.generalPartnerChoice}=${selectedType}`;
const redirectUrl = `${LIMITED_PARTNER_CHOICE_URL}?${RegistrationPageType.generalPartnerChoice}=${selectedType}`;
expect(res.status).toBe(302);
expect(res.text).toContain(redirectUrl);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import request from "supertest";
import { LocalesService } from "@companieshouse/ch-node-utils";
import * as constants from "../../../../config/constants";
import { appDevDependencies } from "../../../../config";
import enTranslationText from "../../../../../locales/en/translations.json";
import cyTranslationText from "../../../../../locales/cy/translations.json";
import app from "../app";
import {
LIMITED_PARTNER_CHOICE_URL,
NEXT_URL,
registrationRoutingLimitedPartnerChoice,
} from "../../../controller/registration/Routing";
import RegistrationPageType from "../../../controller/registration/PageType";

describe("Limited Partner Choice Page", () => {
beforeEach(() => {
setLocalesEnabled(false);
});

const setLocalesEnabled = (bool: boolean) => {
jest.spyOn(constants, "isLocalesEnabled").mockReturnValue(bool);
LocalesService.getInstance().enabled = bool;
};

it("should load the limited partner choice page with Welsh text", async () => {
setLocalesEnabled(true);
const res = await request(app).get(LIMITED_PARTNER_CHOICE_URL + "?lang=cy");

expect(res.status).toBe(200);
expect(res.text).toContain(cyTranslationText.limitedPartnerChoicePage.isPersonOrLegalEntity);
});

it("should load the limited partner choice page with English text", async () => {
setLocalesEnabled(true);
const res = await request(app).get(LIMITED_PARTNER_CHOICE_URL + "?lang=en");

expect(res.status).toBe(200);
expect(res.text).toContain(enTranslationText.limitedPartnerChoicePage.isPersonOrLegalEntity);
});

it("should pass the limited partner choice as a url query param to next page", async () => {
const transactionId = "3664373";
const submissionId = "1543454";
const selectedChoice = "person";

const url = appDevDependencies.registrationController.insertIdsInUrl(
LIMITED_PARTNER_CHOICE_URL,
transactionId,
submissionId
);

const res = await request(app)
.post(url)
.send({
pageType: registrationRoutingLimitedPartnerChoice.pageType,
parameter: selectedChoice,
});

expect(res.status).toBe(302);
const nextPageUrl = appDevDependencies.registrationController.insertIdsInUrl(
NEXT_URL,
transactionId,
submissionId
) + `?${RegistrationPageType.limitedPartnerChoice}=${selectedChoice}`;
expect(res.header.location).toEqual(nextPageUrl);
});
});
16 changes: 16 additions & 0 deletions src/routes/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
LIMITED_PARTNERS_URL,
GENERAL_PARTNERS_URL,
GENERAL_PARTNER_CHOICE_URL,
LIMITED_PARTNER_CHOICE_URL,
} from "../presentation/controller/registration/Routing";

export const registrationEndpoints = (
Expand All @@ -38,6 +39,11 @@ export const registrationEndpoints = (
authentication,
dependencies.registrationController.createTransactionAndFirstSubmission()
);
router.get(
GENERAL_PARTNERS_URL,
authentication,
dependencies.registrationController.getPageRouting()
);
router.get(
EMAIL_URL,
authentication,
Expand Down Expand Up @@ -69,6 +75,16 @@ export const registrationEndpoints = (
dependencies.registrationController.getPageRouting()
);

router.get(
LIMITED_PARTNER_CHOICE_URL,
authentication,
dependencies.registrationController.getPageRouting()
);
router.post(
LIMITED_PARTNER_CHOICE_URL,
authentication,
dependencies.registrationController.redirectWithParameter()
);
router.get(
NEXT_URL,
authentication,
Expand Down
46 changes: 46 additions & 0 deletions src/views/limited-partner-choice.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% extends "layout.njk" %}

{% 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" %}

{{ govukRadios({
name: "parameter",
value: props.data.limitedPartnership.limited_partner,
fieldset: {
legend: {
text: i18n.limitedPartnerChoicePage.isPersonOrLegalEntity,
isPageHeading: true,
classes: "govuk-fieldset__legend--xl"
}
},
hint: {
text: i18n.limitedPartnerChoicePage.isPersonOrLegalEntityHint
},
items: [
{
value: "person",
text: i18n.limitedPartnerChoicePage.person,
attributes : {
required : true
}
},
{
value: "legal_entity",
text: i18n.limitedPartnerChoicePage.legalEntity,
attributes : {
required : true
}
}
]
}) }}

{% include "includes/save-and-continue-button.njk" %}
</form>
</div>
</div>
{% endblock %}

0 comments on commit c9bfca8

Please sign in to comment.