generated from companieshouse/node-review-web-starter-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #640 from companieshouse/IDVA51707
IDVA5-1707 Remove an AML body
- Loading branch information
Showing
10 changed files
with
176 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/controllers/features/update-acsp/removeAmlSupervisorController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 27 additions & 6 deletions
33
src/views/features/update-acsp-details/update-your-details.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/src/controllers/updateAcspDetails/removeAmlSupervisorController.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
91
test/src/services/update_acsp/amlSupervisorService.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); |