Skip to content

Commit

Permalink
Merge pull request #144 from companieshouse/fix/roe-144-fix-id-for-bo…
Browse files Browse the repository at this point in the history
…-type-and-remove-optional-text-from-address

Fix/roe 144 fix id for bo type and remove optional text from address
  • Loading branch information
mouhajer-ch authored May 24, 2022
2 parents 4d4be37 + 0bbca64 commit dffa746
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/controllers/beneficial.owner.type.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { logger } from "../utils/logger";
import * as config from "../config";
import {
BeneficialOwnerTypeChoice,
BeneficialOwnerTypeKey,
ManagingOfficerTypeChoice,
} from "../model/beneficial.owner.type.model";

Expand All @@ -27,13 +28,12 @@ export const get = (req: Request, res: Response, next: NextFunction) => {

export const post = (req: Request, res: Response) => {
logger.debugRequest(req, `POST ${config.BENEFICIAL_OWNER_TYPE_PAGE}`);
const { selectedOwnerOfficerType } = req.body;

return res.redirect(getNextPage(selectedOwnerOfficerType));
return res.redirect(getNextPage(req.body[BeneficialOwnerTypeKey]));
};

// With validation in place we have got just these 5 possible choices
const getNextPage = (beneficialOwnerTypeChoices?: BeneficialOwnerTypeChoice): string => {
const getNextPage = (beneficialOwnerTypeChoices?: BeneficialOwnerTypeChoice | ManagingOfficerTypeChoice): string => {
if (beneficialOwnerTypeChoices === BeneficialOwnerTypeChoice.individual) {
return config.BENEFICIAL_OWNER_INDIVIDUAL_URL;
} else if (beneficialOwnerTypeChoices === BeneficialOwnerTypeChoice.otherLegal) {
Expand Down
2 changes: 2 additions & 0 deletions src/model/beneficial.owner.type.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const BeneficialOwnerTypeKey = "beneficial_owner_type";

export enum BeneficialOwnerTypeChoice {
individual = "individualOwner",
otherLegal = "otherLegalOwner",
Expand Down
2 changes: 1 addition & 1 deletion src/validation/beneficial.owner.type.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { body } from "express-validator";
import { ErrorMessages } from "./error.messages";

export const beneficialOwnersType = [
body("selectedOwnerOfficerType").not().isEmpty().withMessage(ErrorMessages.SELECT_THE_TYPE_OF_BENEFICIAL_OWNER_OR_MANAGING_OFFICER_YOU_WANT_TO_ADD),
body("beneficial_owner_type").not().isEmpty().withMessage(ErrorMessages.SELECT_THE_TYPE_OF_BENEFICIAL_OWNER_OR_MANAGING_OFFICER_YOU_WANT_TO_ADD),
];
11 changes: 6 additions & 5 deletions test/controllers/beneficial.owner.type.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { APPLICATION_DATA_MOCK, ERROR } from '../__mocks__/session.mock';
import {
BeneficialOwnerTypeChoice,
BeneficialOwnerTypeKey,
ManagingOfficerTypeChoice,
} from "../../src/model/beneficial.owner.type.model";
import { ErrorMessages } from '../../src/validation/error.messages';
Expand Down Expand Up @@ -55,7 +56,7 @@ describe("BENEFICIAL OWNER TYPE controller", () => {
test(`redirects to the ${config.BENEFICIAL_OWNER_INDIVIDUAL_PAGE} page`, async () => {
const resp = await request(app)
.post(config.BENEFICIAL_OWNER_TYPE_URL)
.send({ selectedOwnerOfficerType: BeneficialOwnerTypeChoice.individual });
.send({ [BeneficialOwnerTypeKey]: BeneficialOwnerTypeChoice.individual });

expect(resp.status).toEqual(302);
expect(resp.header.location).toEqual(config.BENEFICIAL_OWNER_INDIVIDUAL_URL);
Expand All @@ -64,7 +65,7 @@ describe("BENEFICIAL OWNER TYPE controller", () => {
test(`redirects to the ${config.BENEFICIAL_OWNER_OTHER_PAGE} page`, async () => {
const resp = await request(app)
.post(config.BENEFICIAL_OWNER_TYPE_URL)
.send({ selectedOwnerOfficerType: BeneficialOwnerTypeChoice.otherLegal });
.send({ [BeneficialOwnerTypeKey]: BeneficialOwnerTypeChoice.otherLegal });

expect(resp.status).toEqual(302);
expect(resp.header.location).toEqual(config.BENEFICIAL_OWNER_OTHER_URL);
Expand All @@ -73,7 +74,7 @@ describe("BENEFICIAL OWNER TYPE controller", () => {
test(`redirects to the ${config.BENEFICIAL_OWNER_GOV_PAGE} page`, async () => {
const resp = await request(app)
.post(config.BENEFICIAL_OWNER_TYPE_URL)
.send({ selectedOwnerOfficerType: BeneficialOwnerTypeChoice.government });
.send({ [BeneficialOwnerTypeKey]: BeneficialOwnerTypeChoice.government });

expect(resp.status).toEqual(302);
expect(resp.header.location).toEqual(config.BENEFICIAL_OWNER_GOV_URL);
Expand All @@ -82,7 +83,7 @@ describe("BENEFICIAL OWNER TYPE controller", () => {
test(`redirects to the ${config.MANAGING_OFFICER_PAGE} page`, async () => {
const resp = await request(app)
.post(config.BENEFICIAL_OWNER_TYPE_URL)
.send({ selectedOwnerOfficerType: ManagingOfficerTypeChoice.individual });
.send({ [BeneficialOwnerTypeKey]: ManagingOfficerTypeChoice.individual });

expect(resp.status).toEqual(302);
expect(resp.header.location).toEqual(config.MANAGING_OFFICER_URL);
Expand All @@ -91,7 +92,7 @@ describe("BENEFICIAL OWNER TYPE controller", () => {
test(`redirects to the ${config.MANAGING_OFFICER_CORPORATE_PAGE} page`, async () => {
const resp = await request(app)
.post(config.BENEFICIAL_OWNER_TYPE_URL)
.send({ selectedOwnerOfficerType: ManagingOfficerTypeChoice.corporate });
.send({ [BeneficialOwnerTypeKey]: ManagingOfficerTypeChoice.corporate });

expect(resp.status).toEqual(302);
expect(resp.header.location).toEqual(config.MANAGING_OFFICER_CORPORATE_URL);
Expand Down
6 changes: 3 additions & 3 deletions views/beneficial-owner-type.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ <h1 class="govuk-heading-xl govuk-!-margin-0">Which type of beneficial owner or
<form method="post">

{{ govukRadios({
errorMessage: errors.selectedOwnerOfficerType if errors,
idPrefix: "beneficial-owner-type",
name: "selectedOwnerOfficerType",
errorMessage: errors.beneficial_owner_type if errors,
idPrefix: "beneficial_owner_type",
name: "beneficial_owner_type",
fieldset: {
legend: {
isPageHeading: false,
Expand Down
2 changes: 1 addition & 1 deletion views/includes/inputs/address/principal-address-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{{ govukInput({
errorMessage: errors.principal_address_property_name_number if errors,
label: {
html: 'Property name or number (optional)'
html: 'Property name or number'
},
hint: {
text: propertyNameNumberText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

{{ govukInput({
label: {
html: 'Property name or number (optional)'
html: 'Property name or number'
},
hint: {
text: propertyNameNumberText
Expand Down
2 changes: 1 addition & 1 deletion views/includes/inputs/address/service-address-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{ govukInput({
errorMessage: errors.service_address_property_name_number if errors,
label: {
html: 'Property name or number (optional)'
html: 'Property name or number'
},
hint: {
text: propertyNameNumberText
Expand Down

0 comments on commit dffa746

Please sign in to comment.