Skip to content

Commit

Permalink
AUT-3826: Wire in new cannot change security codes page to state machine
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BeckaL committed Dec 13, 2024
1 parent 969608f commit 68a6cdf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/components/common/state-machine/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
},
},
},
{
Expand Down
11 changes: 9 additions & 2 deletions src/components/ipv-callback/ipv-callback-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/ipv-callback/ipv-callback-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ router.get(
router.get(
PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES,
validateSessionMiddleware,
allowUserJourneyMiddleware,
cannotChangeSecurityCodesGet
);

Expand Down
21 changes: 21 additions & 0 deletions src/components/ipv-callback/tests/ipv-callback-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
);
});
});

0 comments on commit 68a6cdf

Please sign in to comment.