Skip to content

Commit

Permalink
BAU: Use already created helper methods in setup for ipv call back te…
Browse files Browse the repository at this point in the history
…st block
  • Loading branch information
alhcomer committed Jan 14, 2025
1 parent 18d1695 commit de58f9c
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions src/components/ipv-callback/tests/ipv-callback-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import * as cheerio from "cheerio";
describe("Integration:: ipv callback", () => {
let app: express.Application;
let baseApi: string;
let sessionMiddleware: any;

before(async () => {
process.env.SUPPORT_MFA_RESET_WITH_IPV = "1";
Expand All @@ -26,28 +25,8 @@ describe("Integration:: ipv callback", () => {

describe("ipv callback", () => {
before(async () => {
decache("../../../app");
decache("../../../middleware/session-middleware");
baseApi = process.env.FRONTEND_API_BASE_URL;
sessionMiddleware = require("../../../middleware/session-middleware");

sinon
.stub(sessionMiddleware, "validateSessionMiddleware")
.callsFake(function (req: any, res: any, next: any): void {
res.locals.sessionId = "tDy103saszhcxbQq0-mjdzU854";

req.session.user = {
email: "[email protected]",
phoneNumber: "7867",
journey: {
nextPath: PATH_NAMES.IPV_CALLBACK,
},
};

next();
});

app = await require("../../../app").createApp();
app = await stubSessionMiddlewareAndCreateApp(PATH_NAMES.IPV_CALLBACK);
});

after(() => {
Expand Down Expand Up @@ -106,7 +85,9 @@ describe("Integration:: ipv callback", () => {
});

it("returns a dummy page when an option is selected", async () => {
const app = await stubSessionMiddlewareAndCreateApp();
const app = await stubSessionMiddlewareAndCreateApp(
PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES
);
const { token, cookies } =
await getCannotChangeSecurityCodesAndReturnTokenAndCookies(app);

Expand All @@ -131,7 +112,9 @@ describe("Integration:: ipv callback", () => {
});

it("returns a validation error when no option is selected", async () => {
const app = await stubSessionMiddlewareAndCreateApp();
const app = await stubSessionMiddlewareAndCreateApp(
PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES
);
const { token, cookies } =
await getCannotChangeSecurityCodesAndReturnTokenAndCookies(app);

Expand All @@ -158,7 +141,10 @@ describe("Integration:: ipv callback", () => {
});

it("goes to /enter-code when user selects retry security code radio button and their mfaMethodType is SMS", async () => {
const app = await stubSessionMiddlewareAndCreateApp(MFA_METHOD_TYPE.SMS);
const app = await stubSessionMiddlewareAndCreateApp(
PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES,
MFA_METHOD_TYPE.SMS
);
const { token, cookies } =
await getCannotChangeSecurityCodesAndReturnTokenAndCookies(app);

Expand All @@ -182,6 +168,7 @@ describe("Integration:: ipv callback", () => {

it("goes to /enter-authenticator-app-code when user selects retry security code radio button and their mfaMethodType is AUTH_APP", async () => {
const app = await stubSessionMiddlewareAndCreateApp(
PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES,
MFA_METHOD_TYPE.AUTH_APP
);
const { token, cookies } =
Expand All @@ -208,6 +195,7 @@ describe("Integration:: ipv callback", () => {
});

const stubSessionMiddlewareAndCreateApp = async (
nextPath: string,
mfaMethodType?: MFA_METHOD_TYPE
): Promise<express.Application> => {
decache("../../../app");
Expand All @@ -223,7 +211,7 @@ const stubSessionMiddlewareAndCreateApp = async (
email: "[email protected]",
phoneNumber: "7867",
journey: {
nextPath: PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES,
nextPath: nextPath,
},
mfaMethodType: mfaMethodType,
};
Expand Down

0 comments on commit de58f9c

Please sign in to comment.