Skip to content

Commit

Permalink
BAU: Use common variables in enter password controller tests
Browse files Browse the repository at this point in the history
This reduces some noisy test setup. Also moves some common setup to a before block to reduce noise in individual tests further
  • Loading branch information
BeckaL committed May 21, 2024
1 parent 08984b1 commit 56b9693
Showing 1 changed file with 13 additions and 89 deletions.
102 changes: 13 additions & 89 deletions src/components/enter-password/tests/enter-password-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ import { ERROR_CODES } from "../../common/constants";
import * as journey from "../../common/journey/journey";
import { accountInterventionsFakeHelper } from "../../../../test/helpers/account-interventions-helpers";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../test/helpers/common-test-variables";

describe("enter password controller", () => {
let req: RequestOutput;
let res: ResponseOutput;
const { sessionId, clientSessionId, diPersistentSessionId, email } =
commonVariables;

beforeEach(() => {
req = createMockRequest(PATH_NAMES.ENTER_PASSWORD);
res = mockResponse();
res.locals.sessionId = sessionId;
res.locals.clientSessionId = clientSessionId;
res.locals.persistentSessionId = diPersistentSessionId;
req.session.user = { email };
process.env.SUPPORT_ACCOUNT_INTERVENTIONS = "1";
});

Expand All @@ -44,6 +51,10 @@ describe("enter password controller", () => {

describe("enterPasswordPost", () => {
describe("sending MFA code", () => {
beforeEach(() => {
req.body["password"] = "password";
});

it("should call the MFA service to send an code when required and able to", async () => {
const fakeService: EnterPasswordServiceInterface = {
loginUser: sinon.fake.returns({
Expand All @@ -66,14 +77,6 @@ describe("enter password controller", () => {
}),
} as unknown as MfaServiceInterface;

res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
req.session.user = {
email: "[email protected]",
};
req.body["password"] = "password";

await enterPasswordPost(
false,
fakeService,
Expand Down Expand Up @@ -110,14 +113,7 @@ describe("enter password controller", () => {
"getJourneyTypeFromUserSession"
);

res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
req.session.user = {
email: "[email protected]",
reauthenticate: "test_data",
};
req.body["password"] = "password";
req.session.user = { email, reauthenticate: "test_data" };

await enterPasswordPost(
false,
Expand Down Expand Up @@ -173,14 +169,7 @@ describe("enter password controller", () => {
"getJourneyTypeFromUserSession"
);

res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
req.session.user = {
email: "[email protected]",
reauthenticate: "test_data",
};
req.body["password"] = "password";
req.session.user = { email, reauthenticate: "test_data" };

await enterPasswordPost(
false,
Expand Down Expand Up @@ -228,14 +217,6 @@ describe("enter password controller", () => {
}),
} as unknown as MfaServiceInterface;

res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
req.session.user = {
email: "[email protected]",
};
req.body["password"] = "password";

await enterPasswordPost(
false,
fakeService,
Expand All @@ -259,14 +240,6 @@ describe("enter password controller", () => {
}),
} as unknown as EnterPasswordServiceInterface;

res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
req.session.user = {
email: "[email protected]",
};
req.body["password"] = "password";

await enterPasswordPost(false, fakeService)(
req as Request,
res as Response
Expand All @@ -288,14 +261,6 @@ describe("enter password controller", () => {
}),
} as unknown as EnterPasswordServiceInterface;

res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
req.session.user = {
email: "[email protected]",
};
req.body["password"] = "password";

await enterPasswordPost(false, fakeService)(
req as Request,
res as Response
Expand All @@ -318,14 +283,6 @@ describe("enter password controller", () => {
}),
} as unknown as EnterPasswordServiceInterface;

res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
req.session.user = {
email: "[email protected]",
};
req.body["password"] = "password";

await enterPasswordPost(false, fakeService)(
req as Request,
res as Response
Expand All @@ -347,13 +304,6 @@ describe("enter password controller", () => {
sendMfaCode: sinon.fake(),
};

res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
req.session.user = {
email: "[email protected]",
};
req.body["password"] = "password";

await expect(
enterPasswordPost(
false,
Expand Down Expand Up @@ -420,13 +370,6 @@ describe("enter password controller", () => {
temporarilySuspended: testCase.interventions.temporarilySuspended,
reproveIdentity: false,
});
res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
req.session.user = {
email: "[email protected]",
};
req.body["password"] = "password";

await enterPasswordPost(
false,
Expand All @@ -443,25 +386,13 @@ describe("enter password controller", () => {
});

describe("enterSignInRetryBlockedGet", () => {
const SESSION_ID = "123456-djjad";
const CLIENT_SESSION_ID = "00000-djjad";
const PERSISTENT_SESSION_ID = "dips-123456-abc";
const EMAIL = "[email protected]";

it("should render /enter-password view when account is unblocked", async () => {
const fakeService: EnterEmailServiceInterface = {
userExists: sinon.fake.returns({
success: true,
}),
} as unknown as EnterEmailServiceInterface;

res.locals.sessionId = SESSION_ID;
res.locals.clientSessionId = CLIENT_SESSION_ID;
res.locals.persistentSessionId = PERSISTENT_SESSION_ID;
req.session.user = {
email: EMAIL,
};

await enterSignInRetryBlockedGet(fakeService)(
req as Request,
res as Response
Expand All @@ -480,13 +411,6 @@ describe("enter password controller", () => {
}),
} as unknown as EnterEmailServiceInterface;

res.locals.sessionId = SESSION_ID;
res.locals.clientSessionId = CLIENT_SESSION_ID;
res.locals.persistentSessionId = PERSISTENT_SESSION_ID;
req.session.user = {
email: EMAIL,
};

await enterSignInRetryBlockedGet(fakeService)(
req as Request,
res as Response
Expand Down

0 comments on commit 56b9693

Please sign in to comment.