Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uar 1285 need changes entity before removed #1233

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export const UPDATE_STATEMENT_VALIDATION_ERRORS_PAGE = "update-statement-validat
export const REMOVE_SOLD_ALL_LAND_FILTER_PAGE = "remove-sold-all-land-filter";
export const REMOVE_IS_ENTITY_REGISTERED_OWNER_PAGE = "remove-is-entity-registered-owner";
export const REMOVE_CANNOT_USE_PAGE = "remove-cannot-use";
export const REMOVE_NEED_MAKE_CHANGES_PAGE = "remove-need-to-make-changes-to-entity";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a great choice of words for a constant name but totally understand that you've tried to match the defined HTML page name. How about if you drop the _MAKE_ so we're left with just REMOVE_NEED_CHANGES_PAGE?

(REMOVE_CHANGES_REQUIRED_PAGE would be my first choice, but then we diverge from the HTML page name)


// URL PARAMS
export const ROUTE_PARAM_TRUST_ID = "trustId";
Expand Down Expand Up @@ -304,6 +305,7 @@ export const UPDATE_PAYMENT_FAILED_URL = UPDATE_AN_OVERSEAS_ENTITY_URL + PAYMENT
export const REMOVE_SOLD_ALL_LAND_FILTER_URL = UPDATE_AN_OVERSEAS_ENTITY_URL + REMOVE_SOLD_ALL_LAND_FILTER_PAGE;
export const REMOVE_CANNOT_USE_URL = UPDATE_AN_OVERSEAS_ENTITY_URL + REMOVE_CANNOT_USE_PAGE;
export const REMOVE_IS_ENTITY_REGISTERED_OWNER_URL = UPDATE_AN_OVERSEAS_ENTITY_URL + REMOVE_IS_ENTITY_REGISTERED_OWNER_PAGE;
export const REMOVE_NEED_MAKE_CHANGES_URL = UPDATE_AN_OVERSEAS_ENTITY_URL + REMOVE_NEED_MAKE_CHANGES_PAGE;

// PAYMENT CONFIGs
export const PAYMENT = "payment";
Expand Down
1 change: 1 addition & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ export * as updateManageTrustsTellUsAboutTheLegalEntity from './update/update.ma
export * as removeSoldAllLandFilter from './update/remove.sold.all.land.filter.controller';
export * as removeCannotUse from "./update/remove.cannot.use.controller";
export * as removeIsEntityRegisteredOwner from "./update/remove.is.entity.registered.owner.controller";
export * as removeNeedMakeChanges from "./update/remove.need.to.make.changes.to.entity.controller";
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { NextFunction, Request, Response } from "express";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given my comments below and the fact that this is basically just an update screen, I wonder if the new controller for remove (and HTML template page) is required.

import * as config from "../../config";
import { logger } from "../../utils/logger";

export const get = (req: Request, res: Response, next: NextFunction) => {
try {
logger.debugRequest(req, `GET ${config.REMOVE_NEED_MAKE_CHANGES_PAGE}`);
return res.render(config.REMOVE_NEED_MAKE_CHANGES_PAGE, {
journey: config.JourneyType.remove,
backLinkUrl: `${config.OVERSEAS_ENTITY_PRESENTER_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, back link here doesn't need to set the JOURNEY_REMOVE_QUERY_PARAM because by this point the 'is_remove=true' flag is set in the session and Mongo JSON, so that screen can pick it up from there (changes will be required for this though...). A discussion required, perhaps.

templateName: config.REMOVE_NEED_MAKE_CHANGES_PAGE
});
} catch (error) {
next(error);
}
};

export const post = (req: Request, res: Response, next: NextFunction) => {
try {
logger.debugRequest(req, `POST ${config.REMOVE_NEED_MAKE_CHANGES_PAGE}`);

if (req.body["make_changes"] === 'yes') {
return res.redirect(`${config.WHO_IS_MAKING_UPDATE_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to pass the JOURNEY_REMOVE_QUERY_PARAM in now for future pages as it is the update journey and we are avoiding changing all those controllers (for now).

}
// TODO redirect to new component - Has the overseas entity identified any registrable beneficial owners?
return res.redirect(`${config.UPDATE_LANDING_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Mural board, looks like the 'No' option takes you to an existing update screen, so in theory this could be done now (no need for TODO).

} catch (error) {
next(error);
}
};
9 changes: 9 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
removeSoldAllLandFilter,
removeIsEntityRegisteredOwner,
resumeSubmission,
removeNeedMakeChanges,
overseasName,
startingNew,
overseasEntityPayment,
Expand Down Expand Up @@ -1098,6 +1099,14 @@ router.route(config.UPDATE_STATEMENT_VALIDATION_ERRORS_URL)
.get(validateStatements, statementValidationErrorsGuard, updateStatementValidationErrors.get)
.post(validateStatements, ...validator.statementResolution, updateStatementValidationErrors.post);

router.route(config.REMOVE_NEED_MAKE_CHANGES_URL)
.all(
authentication,
companyAuthentication,
navigation.hasUpdatePresenter)
.get(removeNeedMakeChanges.get)
.post(...validator.removeNeedMakeChanges, checkValidations, removeNeedMakeChanges.post);

router.get(config.REMOVE_CANNOT_USE_URL, authentication, removeCannotUse.get);

export default router;
5 changes: 5 additions & 0 deletions src/utils/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,9 @@ export const NAVIGATION: Navigation = {
previousPage: () => `${config.REMOVE_SOLD_ALL_LAND_FILTER_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`,
nextPage: [`${config.SECURE_UPDATE_FILTER_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`]
},
[config.REMOVE_NEED_MAKE_CHANGES_URL]: { // TODO set next and previous to specification in ACs on UAR-1285
currentPage: config.REMOVE_NEED_MAKE_CHANGES_PAGE,
previousPage: () => `${config.WHO_IS_MAKING_FILING_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`,
nextPage: [`${config.WHO_IS_MAKING_UPDATE_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`]
}
};
1 change: 1 addition & 0 deletions src/validation/error.messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export enum ErrorMessages {
SELECT_DO_YOU_WANT_TO_MAKE_CHANGES_UPDATE_STATEMENT = "Select yes if all the information in this update statement is correct",
SELECT_UPDATE_STATEMENT_VALIDATION_RESOLUTION = "Select if you want to change your statements or change the information provided in this update",
SELECT_IF_REMOVE_SOLD_ALL_LAND_FILTER = "Select yes if the entity has disposed of all its property or land in the UK",
SELECT_REMOVE_NEED_TO_MAKE_CHANGES = "Select yes if you need to make changes to this overseas entity before it is removed",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the validation error message is the only thing changing here for the remove journey, I think we can probably use the isRemove() check to vary this.


// MAX Lengths
MAX_FIRST_NAME_LENGTH = "First name must be 50 characters or less",
Expand Down
4 changes: 3 additions & 1 deletion src/validation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { doYouWantToMakeOeChange } from "./update/do.you.want.to.make.oe.change.
import { reviewUpdateStatementChange, statementResolution } from "./update/review.update.statement.validation";
import { removeSoldAllLandFilter } from "./update/remove.sold.all.land.filter.validation";
import { removeIsEntityRegisteredOwner } from "./update/remove.is.entity.registered.owner.validation";
import { removeNeedMakeChanges } from "./update/remove.need.to.make.changes.to.entity.validation";
export const validator = {
soldLandFilter,
secureRegisterFilter,
Expand Down Expand Up @@ -87,5 +88,6 @@ export const validator = {
reviewUpdateStatementChange,
statementResolution,
removeSoldAllLandFilter,
removeIsEntityRegisteredOwner
removeIsEntityRegisteredOwner,
removeNeedMakeChanges
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { body } from "express-validator";

import { ErrorMessages } from "../error.messages";

export const removeNeedMakeChanges = [
body("make_changes").not().isEmpty().withMessage(ErrorMessages.SELECT_REMOVE_NEED_TO_MAKE_CHANGES)
];
1 change: 1 addition & 0 deletions test/__mocks__/text.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export const UPDATE_MANAGE_TRUSTS_REVIEWED_HEADING = "What you have reviewed";
export const REMOVE_SOLD_ALL_LAND_FILTER_PAGE_TITLE = "Has the overseas entity disposed of all its property or land in the UK?";
export const REMOVE_IS_ENTITY_REGISTERED_OWNER_TITLE = "Is the overseas entity currently listed on any land registry records as the registered owner of property or land in the UK?";
export const REMOVE_INTERRUPT_CARD_TEXT = "Once an overseas entity is removed";
export const REMOVE_NEED_MAKE_CHANGES_TITLE = "Do you need to make any changes to this overseas entity before it is removed?";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, we should be able to vary the title displayed in the existing HTML template without the need for a new controller and template for Remove.


// Manage Trusts
export const UPDATE_MANAGE_TRUSTS_REVIEW_FORMER_BO_TITLE = "Review former beneficial owners";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
jest.mock("ioredis");
jest.mock("../../../src/utils/logger");
jest.mock('../../../src/middleware/authentication.middleware');
jest.mock('../../../src/middleware/company.authentication.middleware');
jest.mock('../../../src/middleware/service.availability.middleware');
jest.mock('../../../src/middleware/navigation/update/has.presenter.middleware');
jest.mock('../../../src/utils/application.data');

import { NextFunction, Request, Response } from "express";
import * as config from "../../../src/config";
import request from "supertest";
import { logger } from "../../../src/utils/logger";
import app from "../../../src/app";
import { ErrorMessages } from '../../../src/validation/error.messages';
import { hasUpdatePresenter } from "../../../src/middleware/navigation/update/has.presenter.middleware";
import { serviceAvailabilityMiddleware } from "../../../src/middleware/service.availability.middleware";
import { authentication } from "../../../src/middleware/authentication.middleware";
import { companyAuthentication } from "../../../src/middleware/company.authentication.middleware";
import {
ANY_MESSAGE_ERROR,
PAGE_TITLE_ERROR,
FOUND_REDIRECT_TO,
REMOVE_NEED_MAKE_CHANGES_TITLE,
SERVICE_UNAVAILABLE,
} from "../../__mocks__/text.mock";
import { REMOVE_SERVICE_NAME } from "../../../src/config";
import { getApplicationData } from "../../../src/utils/application.data";
import { APPLICATION_DATA_CH_REF_UPDATE_MOCK } from "../../__mocks__/session.mock";

const mockGetApplicationData = getApplicationData as jest.Mock;

const mockHasUpdatePresenter = hasUpdatePresenter as jest.Mock;
mockHasUpdatePresenter.mockImplementation((req: Request, res: Response, next: NextFunction) => next() );

const mockCompanyAuthenticationMiddleware = companyAuthentication as jest.Mock;
mockCompanyAuthenticationMiddleware.mockImplementation((req: Request, res: Response, next: NextFunction) => next() );

const mockAuthenticationMiddleware = authentication as jest.Mock;
mockAuthenticationMiddleware.mockImplementation((req: Request, res: Response, next: NextFunction) => next());

const mockServiceAvailabilityMiddleware = serviceAvailabilityMiddleware as jest.Mock;
mockServiceAvailabilityMiddleware.mockImplementation((req: Request, res: Response, next: NextFunction) => next());

const mockLoggerDebugRequest = logger.debugRequest as jest.Mock;

describe("Remove need to make changes to entity controller", () => {
beforeEach(() => {
jest.clearAllMocks();
});

describe("GET tests", () => {
test(`renders the ${config.REMOVE_NEED_MAKE_CHANGES_URL} page`, async () => {
mockGetApplicationData.mockReturnValueOnce({
...APPLICATION_DATA_CH_REF_UPDATE_MOCK
});
const resp = await request(app).get(`${config.REMOVE_NEED_MAKE_CHANGES_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`);
expect(resp.status).toEqual(200);
expect(resp.text).toContain(REMOVE_NEED_MAKE_CHANGES_TITLE);
expect(resp.text).toContain(REMOVE_SERVICE_NAME);
expect(resp.text).not.toContain(PAGE_TITLE_ERROR);
expect(mockLoggerDebugRequest).toHaveBeenCalledTimes(1);
});

test("catch error on current page for GET method", async () => {
mockLoggerDebugRequest.mockImplementationOnce(() => { throw new Error(ANY_MESSAGE_ERROR); });
const resp = await request(app).get(`${config.REMOVE_NEED_MAKE_CHANGES_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`);
expect(resp.status).toEqual(500);
expect(resp.text).toContain(SERVICE_UNAVAILABLE);
});
});

describe("POST tests", () => {
test(`redirects to the ${config.REMOVE_NEED_MAKE_CHANGES_URL} page when yes is selected`, async () => {
const resp = await request(app)
.post(`${config.REMOVE_NEED_MAKE_CHANGES_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`)
.send({ make_changes: 'yes' });
expect(resp.status).toEqual(302);
expect(resp.text).toEqual(`${FOUND_REDIRECT_TO} ${config.WHO_IS_MAKING_UPDATE_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`);
expect(resp.header.location).toEqual(`${config.WHO_IS_MAKING_UPDATE_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`);
expect(mockLoggerDebugRequest).toHaveBeenCalledTimes(1);
});

test(`redirects to the ${config.REMOVE_NEED_MAKE_CHANGES_URL} page when no is selected`, async () => {
const resp = await request(app)
.post(`${config.REMOVE_NEED_MAKE_CHANGES_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`)
.send({ make_changes: 'no' });
expect(resp.status).toEqual(302);
// TODO redirect to new component - Has the overseas entity identified any registrable beneficial owners?
expect(resp.text).toEqual(`${FOUND_REDIRECT_TO} ${config.UPDATE_LANDING_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`);
expect(resp.header.location).toEqual(`${config.UPDATE_LANDING_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`);
expect(mockLoggerDebugRequest).toHaveBeenCalledTimes(1);
});

test("renders the current page with error message and correct page title", async () => {
const resp = await request(app)
.post(`${config.REMOVE_NEED_MAKE_CHANGES_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`);

expect(resp.status).toEqual(200);
expect(resp.text).toContain(REMOVE_NEED_MAKE_CHANGES_TITLE);
expect(resp.text).toContain(PAGE_TITLE_ERROR);
expect(resp.text).toContain(ErrorMessages.SELECT_REMOVE_NEED_TO_MAKE_CHANGES);
expect(resp.text).toContain(REMOVE_SERVICE_NAME);
});

test("catch error on current page for POST method", async () => {
mockLoggerDebugRequest.mockImplementationOnce(() => { throw new Error(ANY_MESSAGE_ERROR); });
const resp = await request(app)
.post(`${config.REMOVE_SOLD_ALL_LAND_FILTER_URL}${config.JOURNEY_REMOVE_QUERY_PARAM}`)
.send({ disposed_all_land: 'yes' });

expect(resp.status).toEqual(500);
expect(resp.text).toContain(SERVICE_UNAVAILABLE);
});

});
});
76 changes: 76 additions & 0 deletions views/update/remove-need-to-make-changes-to-entity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{% extends "update-layout.html" %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially, no new template required here - see earlier comments and take a look at update-interrupt-card.html where an existing Update screen content is varied depending on the journey.


{% set title = "Do you need to make any changes to this overseas entity before it is removed?" %}

{% block pageTitle %}
{% include "includes/update-page-title.html" %}
{% endblock %}

{% block backLink %}
{% include "includes/back-link.html" %}
{% endblock %}

{% block content %}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

{% include "includes/list/errors.html" %}

<form method="post">
<input type="hidden" name="journey" value="{{ journey }}"/>
<span class="govuk-caption-l">{{ data['overseas-name'] }} - OE001485</span>
<h1 class="govuk-heading-xl">Do you need to make any changes to this overseas entity before it is removed?</h1>
<p class="govuk-hint govuk-!-margin-bottom-5 govuk-!-margin-top-5">
All information about the overseas entity must be up to date before the entity can be removed. It should be correct as at the date of this application. This includes information about any beneficial owners and managing officers.
</p>
{{ govukRadios({
errorMessage: errors.make_changes if errors,
idPrefix: "make_changes",
name: "make_changes",
fieldset: {
legend: {
text: "Have you made any changes to the overseas entity?",
isPageHeading: false,
classes: "govuk-visually-hidden"
}
},
items: [
{
value: "yes",
text: "Yes, I need to make changes",
attributes: {
"data-event-id": "make_changes"
}
},
{
value: "no",
text: "No, I do not need to make changes",
attributes: {
"data-event-id": "make_changes"
}
}
]
})
}}
{{ govukButton({
text: "Save and continue"
})
}}
<details class="govuk-details" data-module="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
What verification checks are needed?
</span>
</summary>
<div class="govuk-details__text">
Verification checks are needed on any changes made to information about the overseas entity, its beneficial owners or managing officers.
</div>
<div class="govuk-details__text">
Verification checks can only be carried out by a UK-regulated agent, and must have been completed no more than 3 months before the date of this update statement. </div>
</div>
</details>
</form>
</div>
</div>
{% endblock %}