From 68a6cdfbf07a471b9648cfe327d94d11605804f8 Mon Sep 17 00:00:00 2001 From: BeckaL Date: Fri, 13 Dec 2024 15:07:12 +0000 Subject: [PATCH] AUT-3826: Wire in new cannot change security codes page to state machine This prevents users from navigating to this page out of journey. Currently, the page is defined as final. This will change as we add more of the journey --- .../common/state-machine/state-machine.ts | 10 +++++++++ .../ipv-callback/ipv-callback-controller.ts | 11 ++++++++-- .../ipv-callback/ipv-callback-routes.ts | 1 + .../tests/ipv-callback-integration.test.ts | 21 +++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/components/common/state-machine/state-machine.ts b/src/components/common/state-machine/state-machine.ts index d91085a30..14f475627 100644 --- a/src/components/common/state-machine/state-machine.ts +++ b/src/components/common/state-machine/state-machine.ts @@ -59,6 +59,8 @@ const USER_JOURNEY_EVENTS = { COMMON_PASSWORD_AND_AIS_STATUS: "COMMON_PASSWORD_AND_AIS_STATUS", IPV_REVERIFICATION_INIT: "IPV_REVERIFICATION_INIT", IPV_REVERIFICATION_COMPLETED: "IPV_REVERIFICATION_COMPLETED", + IPV_REVERIFICATION_INCOMPLETE_OR_UNAVAILABLE: + "IPV_REVERIFICATION_INCOMPLETE_OR_UNAVAILABLE", }; const authStateMachine = createMachine( @@ -744,8 +746,16 @@ const authStateMachine = createMachine( target: [PATH_NAMES.GET_SECURITY_CODES], }, ], + [USER_JOURNEY_EVENTS.IPV_REVERIFICATION_INCOMPLETE_OR_UNAVAILABLE]: [ + { + target: [PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES], + }, + ], }, }, + [PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES]: { + type: "final", + }, }, }, { diff --git a/src/components/ipv-callback/ipv-callback-controller.ts b/src/components/ipv-callback/ipv-callback-controller.ts index 03dd2c092..56c747e61 100644 --- a/src/components/ipv-callback/ipv-callback-controller.ts +++ b/src/components/ipv-callback/ipv-callback-controller.ts @@ -10,7 +10,6 @@ import { reverificationResultService } from "./reverification-result-service"; import { BadRequestError } from "../../utils/error"; import { getNextPathAndUpdateJourney } from "../common/constants"; import { USER_JOURNEY_EVENTS } from "../common/state-machine/state-machine"; -import { PATH_NAMES } from "../../app.constants"; export function ipvCallbackGet( service: ReverificationResultInterface = reverificationResultService() @@ -53,7 +52,15 @@ export function ipvCallbackGet( REVERIFICATION_ERROR_CODE.IDENTITY_CHECK_INCOMPLETE, ].includes(failedResponse.data.failure_code) ) { - return res.redirect(PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES); + return res.redirect( + await getNextPathAndUpdateJourney( + req, + req.path, + USER_JOURNEY_EVENTS.IPV_REVERIFICATION_INCOMPLETE_OR_UNAVAILABLE, + {}, + sessionId + ) + ); } throw new Error(failedResponse.data.failure_code); } diff --git a/src/components/ipv-callback/ipv-callback-routes.ts b/src/components/ipv-callback/ipv-callback-routes.ts index 08f23b98a..ae698226f 100644 --- a/src/components/ipv-callback/ipv-callback-routes.ts +++ b/src/components/ipv-callback/ipv-callback-routes.ts @@ -20,6 +20,7 @@ router.get( router.get( PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES, validateSessionMiddleware, + allowUserJourneyMiddleware, cannotChangeSecurityCodesGet ); diff --git a/src/components/ipv-callback/tests/ipv-callback-integration.test.ts b/src/components/ipv-callback/tests/ipv-callback-integration.test.ts index 1793e1c47..797b37377 100644 --- a/src/components/ipv-callback/tests/ipv-callback-integration.test.ts +++ b/src/components/ipv-callback/tests/ipv-callback-integration.test.ts @@ -61,4 +61,25 @@ describe("Integration:: ipv callback", () => { } ); }); + + it("should redirect to CANNOT_CHANGE_SECURITY_CODES when the reverification result is successful", async () => { + nock(baseApi) + .post(API_ENDPOINTS.REVERIFICATION_RESULT) + .once() + .reply(200, { success: false, failure_code: "no_identity_available" }); + + const requestPath = PATH_NAMES.IPV_CALLBACK + "?code=" + "12345"; + + await request( + app, + (test) => + test + .get(requestPath) + .expect(302) + .expect("Location", PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES), + { + expectAnalyticsPropertiesMatchSnapshot: false, + } + ); + }); });