Skip to content

Commit

Permalink
Merge pull request #640 from companieshouse/IDVA51707
Browse files Browse the repository at this point in the history
IDVA5-1707 Remove an AML body
  • Loading branch information
rdas-ch authored Feb 18, 2025
2 parents f58114e + 8068fc6 commit 092acb3
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 11 deletions.
5 changes: 4 additions & 1 deletion locales/en/update-your-details.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"goBackToAuthorisedAgentServices": "Go back to authorised agent services",
"updatedWarningCaption": "Details updated",
"updatedWarningNoteLineOne": "Pending until submitted",
"updatedWarningNoteLineTwo": " and accepted"
"updatedWarningNoteLineTwo": " and accepted",
"updateAMLDetailsRemoved": " Removed",
"updateAMLDetailsStatusLineOne": "Pending until submitted",
"updateAMLDetailsStatusLineTwo": "and accepted"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Request, Response, NextFunction } from "express";
import { addLangToUrl, selectLang } from "../../../utils/localise";
import { UPDATE_ACSP_DETAILS_BASE_URL, UPDATE_YOUR_ANSWERS } from "../../../types/pageURL";
import { amlSupervisor } from "../../../services/update-acsp/amlSupervisorService";

export const get = async (req: Request, res: Response, next: NextFunction) => {
amlSupervisor(req);
res.redirect(addLangToUrl(UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_YOUR_ANSWERS, selectLang(req.query.lang)));
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { NextFunction, Request, Response } from "express";
import { selectLang, getLocalesService, getLocaleInfo, addLangToUrl } from "../../../utils/localise";
import * as config from "../../../config";
import { AML_MEMBERSHIP_NUMBER, UPDATE_YOUR_ANSWERS, UPDATE_ACSP_DETAILS_BASE_URL, UPDATE_APPLICATION_CONFIRMATION, CANCEL_AN_UPDATE, UPDATE_ADD_AML_SUPERVISOR } from "../../../types/pageURL";
import { AML_MEMBERSHIP_NUMBER, UPDATE_YOUR_ANSWERS, UPDATE_ACSP_DETAILS_BASE_URL, UPDATE_APPLICATION_CONFIRMATION, CANCEL_AN_UPDATE, UPDATE_ADD_AML_SUPERVISOR, REMOVE_AML_SUPERVISOR } from "../../../types/pageURL";
import { Session } from "@companieshouse/node-session-handler";
import { ACSP_DETAILS, ACSP_DETAILS_UPDATED, ADD_AML_BODY_UPDATE, NEW_AML_BODIES } from "../../../common/__utils/constants";
import { getProfileDetails } from "../../../services/update-acsp/updateYourDetailsService";
import { AMLSupervisoryBodies } from "../../../model/AMLSupervisoryBodies";
import { AcspFullProfile } from "private-api-sdk-node/dist/services/acsp-profile/types";
import { ACSPFullProfileDetails } from "../../../model/ACSPFullProfileDetails";
import { AcspUpdateService } from "../../../services/update-acsp/acspUpdateService";
Expand All @@ -22,11 +21,12 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
const acspUpdatedFullProfile: AcspFullProfile = session.getExtraData(ACSP_DETAILS_UPDATED)!;
const profileDetails: ACSPFullProfileDetails = getProfileDetails(acspFullProfile);
const profileDetailsUpdated: ACSPFullProfileDetails = getProfileDetails(acspUpdatedFullProfile);
var updateFlag = JSON.stringify(profileDetails) !== JSON.stringify(profileDetailsUpdated);
var updateFlag = JSON.stringify(acspFullProfile) !== JSON.stringify(acspUpdatedFullProfile);
const addedAmlBodies: AmlSupervisoryBody[] = session.getExtraData(NEW_AML_BODIES) || [];
session.deleteExtraData(ADD_AML_BODY_UPDATE);

const cancelChangeUrl = addLangToUrl(UPDATE_ACSP_DETAILS_BASE_URL + CANCEL_AN_UPDATE, lang);
const removeAMLUrl = addLangToUrl(UPDATE_ACSP_DETAILS_BASE_URL + REMOVE_AML_SUPERVISOR, lang);

res.render(config.UPDATE_YOUR_ANSWERS, {
...getLocaleInfo(locales, lang),
Expand All @@ -38,9 +38,10 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
profileDetailsUpdated,
updateFlag,
acspFullProfile,
acspUpdatedFullProfile,
lang,
AMLSupervisoryBodies,
cancelChangeUrl,
removeAMLUrl,
AMLSupervioryBodiesFormatted,
addedAmlBodies
});
Expand Down
1 change: 1 addition & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ export * as businessAddressConfirmController from "./features/update-acsp/busine
export * as cancelAnUpdateController from "./features/update-acsp/cancelAnUpdateController";
export * as updateApplicationConfirmationController from "./features/update-acsp/applicationConfirmationController";
export * as addAmlSupervisorController from "./features/update-acsp/addAmlSupervisorController";
export * as removeAmlSupervisorController from "./features/update-acsp/removeAmlSupervisorController";
export * as updateAmlMembershipNumberController from "./features/update-acsp/amlMembershipNumberController";
3 changes: 3 additions & 0 deletions src/routes/updateAcsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
cancelAnUpdateController,
updateApplicationConfirmationController,
addAmlSupervisorController,
removeAmlSupervisorController,
updateAmlMembershipNumberController
} from "../controllers";
import { nameValidator } from "../validation/whatIsYourName";
Expand Down Expand Up @@ -74,6 +75,8 @@ updateRoutes.post(urls.UPDATE_WHAT_IS_THE_BUSINESS_NAME, unicorporatedWhatIsTheB
updateRoutes.get(urls.UPDATE_ADD_AML_SUPERVISOR, addAmlSupervisorController.get);
updateRoutes.post(urls.UPDATE_ADD_AML_SUPERVISOR, addAmlSupervisorValidator, addAmlSupervisorController.post);

updateRoutes.get(urls.REMOVE_AML_SUPERVISOR, removeAmlSupervisorController.get);

updateRoutes.get(urls.UPDATE_APPLICATION_CONFIRMATION, updateApplicationConfirmationController.get);

updateRoutes.get(urls.CANCEL_AN_UPDATE, cancelAnUpdateController.get);
Expand Down
21 changes: 21 additions & 0 deletions src/services/update-acsp/amlSupervisorService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Session } from "@companieshouse/node-session-handler";
import { ACSP_DETAILS, ACSP_DETAILS_UPDATED } from "../../common/__utils/constants";
import { AcspFullProfile } from "private-api-sdk-node/dist/services/acsp-profile/types";
import { Request } from "express";

export const amlSupervisor = (req: Request): void => {
const amlRemovalIndex = req.query.amlindex;
const session: Session = req.session as any as Session;
const acspFullProfile: AcspFullProfile = session.getExtraData(ACSP_DETAILS)!;
const acspUpdatedFullProfile: AcspFullProfile = session.getExtraData(ACSP_DETAILS_UPDATED)!;
if (amlRemovalIndex) {
const indexAMLForRemoval = acspUpdatedFullProfile.amlDetails.findIndex(tmpRemovedAml => tmpRemovedAml.membershipDetails === amlRemovalIndex);
const indexAMLForUndoRemoval = acspFullProfile.amlDetails.findIndex(tmpRemovedAml => tmpRemovedAml.membershipDetails === amlRemovalIndex);
if (indexAMLForRemoval >= 0) {
acspUpdatedFullProfile.amlDetails.length > 1
? acspUpdatedFullProfile.amlDetails.splice(indexAMLForUndoRemoval, 1) : acspUpdatedFullProfile.amlDetails.pop();
} else if (indexAMLForUndoRemoval >= 0) {
acspUpdatedFullProfile.amlDetails.splice(indexAMLForUndoRemoval, 0, acspFullProfile.amlDetails[indexAMLForUndoRemoval]);
}
}
};
1 change: 1 addition & 0 deletions src/types/pageURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,5 @@ export const CANCEL_AN_UPDATE = "/cancel-an-update";

export const UPDATE_ADD_AML_SUPERVISOR = "/select-aml-supervisor";

export const REMOVE_AML_SUPERVISOR = "/remove-an-aml";
export const UPDATE_SELECT_AML_SUPERVISOR = "/select-aml-supervisor";
33 changes: 27 additions & 6 deletions src/views/features/update-acsp-details/update-your-details.njk
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %}
{% from "govuk/components/button/macro.njk" import govukButton %}
{% extends "layouts/default.njk" %}

{% set amlList = [] %}
{% for body in acspFullProfile.amlDetails %}
{% set chkFlagForAMLUpdate = true %}
{% set updateAMLDetailsStatusText = "" %}
{% set amlActionText = i18n.updateYourDetailsRemove %}
{% if chkFlagForAMLUpdate === true %}
{% for bodyUpdated in acspUpdatedFullProfile.amlDetails %}
{% if body.supervisoryBody === bodyUpdated.supervisoryBody %}
{% set chkFlagForAMLUpdate = false %}
{%endif%}
{% endfor %}
{%endif%}
{% if chkFlagForAMLUpdate %}
{% set amlActionText = i18n.updateYourDetailsCancel %}
{% set updateAMLDetailsStatusText =
"<div class='govuk-!-static-padding-top-3'>
<p class='govuk-tag govuk-tag--red govuk-!-static-margin-bottom-1'>"+i18n.updateAMLDetailsRemoved+"</p>
<p class='govuk-body-s'>"+i18n.updateAMLDetailsStatusLineOne+"<br>"+i18n.updateAMLDetailsStatusLineTwo+"</p>
</div>"
%}
{%endif%}
{% set amlSummaryObject = {
key: {
text: i18n.checkYourAnswersAMLTab
text: i18n.checkYourAnswersAMLTab + tmp,
classes: "govuk-!-width-one-third"
},
value: {
html: "<ul class='govuk-list govuk-list--bullet'><li>" + AMLSupervioryBodiesFormatted[body.supervisoryBody] + "</li><li>" + body.membershipDetails + "</li></ul>"
+updateAMLDetailsStatusText,
classes: "govuk-!-width-one-third"
},
actions: {
items: [
{
href: "#",
text: i18n.updateYourDetailsRemove,
href: removeAMLUrl + "&amlindex=" + body.membershipDetails,
text: amlActionText,
visuallyHiddenText: AMLSupervioryBodiesFormatted[body.supervisoryBody]
}
]
}],
classes: "govuk-!-width-one-third"
}
} %}
{% set amlList = amlList.concat(amlSummaryObject) %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import mocks from "../../../mocks/all_middleware_mock";
import supertest from "supertest";
import app from "../../../../src/app";
import { UPDATE_ACSP_DETAILS_BASE_URL, UPDATE_YOUR_ANSWERS, REMOVE_AML_SUPERVISOR } from "../../../../src/types/pageURL";
const router = supertest(app);

describe("GET " + REMOVE_AML_SUPERVISOR, () => {
it("should redirect to the correct URL", async () => {
const response = await router.get(UPDATE_ACSP_DETAILS_BASE_URL + REMOVE_AML_SUPERVISOR);
expect(response.status).toBe(302);
expect(mocks.mockUpdateAcspAuthenticationMiddleware).toHaveBeenCalled();
expect(response.header.location).toBe(UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_YOUR_ANSWERS + "?lang=en");
});
});
91 changes: 91 additions & 0 deletions test/src/services/update_acsp/amlSupervisorService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { createRequest, MockRequest } from "node-mocks-http";
import { amlSupervisor } from "../../../../src/services/update-acsp/amlSupervisorService";
import { Request } from "express";
import { getSessionRequestWithPermission } from "../../../mocks/session.mock";
import { Session } from "@companieshouse/node-session-handler";
import { ACSP_DETAILS, ACSP_DETAILS_UPDATED } from "../../../../src/common/__utils/constants";
import { AcspFullProfile } from "private-api-sdk-node/dist/services/acsp-profile/types";

describe("amlSupervisor", () => {
let req: MockRequest<Request>;
let session: Partial<Session>;
let acspFullProfile: AcspFullProfile;
let acspUpdatedFullProfile: AcspFullProfile;

beforeEach(() => {
req = createRequest({
method: "GET",
url: "/"
});
req.session = getSessionRequestWithPermission();
acspFullProfile = {
amlDetails: [
{ membershipDetails: "123" },
{ membershipDetails: "456" }
]
} as AcspFullProfile;

acspUpdatedFullProfile = {
amlDetails: [
{ membershipDetails: "123" },
{ membershipDetails: "456" }
]
} as AcspFullProfile;

session = {
getExtraData: jest.fn((key: string) => {
if (key === ACSP_DETAILS) return acspFullProfile;
if (key === ACSP_DETAILS_UPDATED) return acspUpdatedFullProfile;
})
} as Partial<Session>;

req.session = session as Session;
});

it("should remove AML detail if index is found in updated profile", () => {
req.query.amlindex = "123";

amlSupervisor(req as Request);

expect(acspUpdatedFullProfile.amlDetails).toHaveLength(1);
expect(acspUpdatedFullProfile.amlDetails[0].membershipDetails).toBe("456");
});

it("should clear AML details if only one detail is present and index is found", () => {
acspUpdatedFullProfile.amlDetails = [{ membershipDetails: "123", supervisoryBody: "SomeBody" }];
req.query.amlindex = "123";

amlSupervisor(req as Request);

expect(acspUpdatedFullProfile.amlDetails).toHaveLength(0);
});

it("should undo removal of AML detail if index is not found in updated profile but found in original profile", () => {
acspUpdatedFullProfile.amlDetails = [{ membershipDetails: "456", supervisoryBody: "SomeBody" }];
req.query.amlindex = "123";

amlSupervisor(req as Request);

expect(acspUpdatedFullProfile.amlDetails).toHaveLength(2);
expect(acspUpdatedFullProfile.amlDetails[0].membershipDetails).toBe("123");
expect(acspUpdatedFullProfile.amlDetails[1].membershipDetails).toBe("456");
});

it("should do nothing if amlindex is not provided", () => {
amlSupervisor(req as Request);

expect(acspUpdatedFullProfile.amlDetails).toHaveLength(2);
expect(acspUpdatedFullProfile.amlDetails[0].membershipDetails).toBe("123");
expect(acspUpdatedFullProfile.amlDetails[1].membershipDetails).toBe("456");
});

it("should do nothing if amlindex is not found in both profiles", () => {
req.query.amlindex = "789";

amlSupervisor(req as Request);

expect(acspUpdatedFullProfile.amlDetails).toHaveLength(2);
expect(acspUpdatedFullProfile.amlDetails[0].membershipDetails).toBe("123");
expect(acspUpdatedFullProfile.amlDetails[1].membershipDetails).toBe("456");
});
});

0 comments on commit 092acb3

Please sign in to comment.