Skip to content

Commit d747103

Browse files
authored
Merge pull request #1701 from companieshouse/feat/roe-2732/fix-redirect-from-bo-warning-page
feat/roe-2732: redirect to correct url from beneficial-owner-delete-warning page
2 parents 8014128 + db93b63 commit d747103

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/controllers/beneficial.owner.delete.warning.controller.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const post = async (req: Request, res: Response, next: NextFunction): Pro
5555
try {
5656

5757
logger.debugRequest(req, `POST ${config.BENEFICIAL_OWNER_DELETE_WARNING_PAGE}`);
58+
let nextPageUrl: string;
5859

5960
if (req.body["delete_beneficial_owners"] === '1') {
6061
const boStatement = req.body[BeneficialOwnerStatementKey];
@@ -77,14 +78,19 @@ export const post = async (req: Request, res: Response, next: NextFunction): Pro
7778
await updateOverseasEntity(req, req.session as Session, appData);
7879
}
7980
setExtraData(req.session, appData);
80-
const nextPageUrl = isActiveFeature(config.FEATURE_FLAG_ENABLE_REDIS_REMOVAL)
81+
nextPageUrl = isActiveFeature(config.FEATURE_FLAG_ENABLE_REDIS_REMOVAL)
8182
? getUrlWithParamsToPath(config.BENEFICIAL_OWNER_TYPE_WITH_PARAMS_URL, req)
8283
: config.BENEFICIAL_OWNER_TYPE_URL;
8384

8485
return res.redirect(nextPageUrl);
8586
}
8687

87-
return res.redirect(config.BENEFICIAL_OWNER_STATEMENTS_URL);
88+
nextPageUrl = isActiveFeature(config.FEATURE_FLAG_ENABLE_REDIS_REMOVAL)
89+
? getUrlWithParamsToPath(config.BENEFICIAL_OWNER_STATEMENTS_WITH_PARAMS_URL, req)
90+
: config.BENEFICIAL_OWNER_STATEMENTS_URL;
91+
92+
return res.redirect(nextPageUrl);
93+
8894
} catch (error) {
8995
logger.errorRequest(req, error);
9096
next(error);

test/controllers/beneficial.owner.delete.warning.controller.spec.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe("BENEFICIAL OWNER DELETE WARNING controller", () => {
144144
});
145145

146146
describe("POST tests", () => {
147-
test("redirects to the beneficial owner type page if No option has been selected", async () => {
147+
test("redirects to the beneficial owner type page if No option has been selected and REDIS_removal flag is set to OFF", async () => {
148148
const resp = await request(app)
149149
.post(config.BENEFICIAL_OWNER_DELETE_WARNING_URL)
150150
.send({ delete_beneficial_owners: "0" });
@@ -157,7 +157,21 @@ describe("BENEFICIAL OWNER DELETE WARNING controller", () => {
157157
expect(mockUpdateOverseasEntity).not.toHaveBeenCalled();
158158
});
159159

160-
test(`redirects to the beneficial owner type page if Yes option has been selected and REDIS_removal flag is set to ON and
160+
test("redirects to the beneficial owner type page if No option has been selected and REDIS_removal flag is set to ON", async () => {
161+
const resp = await request(app)
162+
.post(config.BENEFICIAL_OWNER_DELETE_WARNING_WITH_PARAMS_URL)
163+
.send({ delete_beneficial_owners: "0" });
164+
mockIsActiveFeature.mockReturnValueOnce(true);
165+
mockIsActiveFeature.mockReturnValueOnce(true);
166+
expect(resp.status).toEqual(302);
167+
expect(resp.header.location).toEqual(config.BENEFICIAL_OWNER_STATEMENTS_URL);
168+
expect(mockSetExtraData).not.toHaveBeenCalled();
169+
expect(mockCheckBOsDetailsEntered).not.toHaveBeenCalled();
170+
expect(mockCheckMOsDetailsEntered).not.toHaveBeenCalled();
171+
expect(mockUpdateOverseasEntity).not.toHaveBeenCalled();
172+
});
173+
174+
test(`redirects to the beneficial owner type page if Yes option has been selected when REDIS_removal flag is set to ON and
161175
${BeneficialOwnersStatementType.SOME_IDENTIFIED_ALL_DETAILS} as statement type`, async () => {
162176

163177
mockFetchApplicationData.mockReturnValueOnce(APPLICATION_DATA_MOCK);

0 commit comments

Comments
 (0)