Skip to content

Commit

Permalink
BAU: Remove uncessary setup from enter email controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BeckaL committed May 22, 2024
1 parent 03f5566 commit b2b028e
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions src/components/enter-email/tests/enter-email-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ describe("enter email controller", () => {

beforeEach(() => {
res = mockResponse();
res.locals.sessionId = commonVariables.sessionId;
res.locals.clientSessionId = commonVariables.clientSessionId;
res.locals.persistentSessionId = commonVariables.diPersistentSessionId;
clock = sinon.useFakeTimers({
now: date.valueOf(),
});
Expand Down Expand Up @@ -141,6 +138,7 @@ describe("enter email controller", () => {
describe("enterEmailPost", () => {
beforeEach(() => {
req = createMockRequest(PATH_NAMES.ENTER_EMAIL_SIGN_IN);
req.body.email = email;
});
it("should redirect to /enter-password when account exists", async () => {
const fakeService: EnterEmailServiceInterface = {
Expand All @@ -150,8 +148,6 @@ describe("enter email controller", () => {
}),
} as unknown as EnterEmailServiceInterface;

req.body.email = email;

await enterEmailPost(
fakeService,
checkReauthSuccessfulFakeService,
Expand All @@ -170,8 +166,6 @@ describe("enter email controller", () => {
}),
} as unknown as EnterEmailServiceInterface;

req.body.email = email;

await enterEmailPost(
fakeService,
checkReauthSuccessfulFakeService,
Expand Down Expand Up @@ -201,8 +195,6 @@ describe("enter email controller", () => {
}),
} as unknown as EnterEmailServiceInterface;

req.body.email = email;

await enterEmailPost(
fakeService,
checkReauthSuccessfulFakeService,
Expand All @@ -225,8 +217,6 @@ describe("enter email controller", () => {
userExists: sinon.fake.throws(error),
};

req.body.email = email;

await expect(
enterEmailPost(fakeService)(req as Request, res as Response)
).to.be.rejectedWith(Error, "Internal server error");
Expand All @@ -238,7 +228,6 @@ describe("enter email controller", () => {
userExists: sinon.fake(),
};

req.body.email = email;
req.session.user = undefined;

await expect(
Expand All @@ -261,8 +250,6 @@ describe("enter email controller", () => {
}),
} as unknown as EnterEmailServiceInterface;

req.body.email = email;

await enterEmailPost(fakeService)(req as Request, res as Response);

expect(res.render).to.have.calledWith(
Expand All @@ -274,7 +261,6 @@ describe("enter email controller", () => {
it("should redirect to /enter-email when re-authentication is required and re-auth check is unsuccessful", async () => {
process.env.SUPPORT_REAUTHENTICATION = "1";

req.body.email = email;
req.session.user = {
email,
reauthenticate: "12345",
Expand Down Expand Up @@ -312,7 +298,6 @@ describe("enter email controller", () => {
it("should redirect to /enter-password blocked screen when the user has been blocked for entering max incorrect password during reauth journey", async () => {
process.env.SUPPORT_REAUTHENTICATION = "1";

req.body.email = email;
req.session.user = {
email,
reauthenticate: "12345",
Expand Down Expand Up @@ -350,7 +335,6 @@ describe("enter email controller", () => {
it("should redirect to /enter-email when re-authentication is required and re-auth check is unsuccessful", async () => {
process.env.SUPPORT_REAUTHENTICATION = "1";

req.body.email = email;
req.session.user = {
email,
reauthenticate: "12345",
Expand Down Expand Up @@ -388,8 +372,6 @@ describe("enter email controller", () => {
it("should redirect to sign in details entered too many times when re-authentication is required and user is blocked from entering email", async () => {
process.env.SUPPORT_REAUTHENTICATION = "1";

req.body.email = email;

const date = new Date();
const futureDate = new Date(
date.setDate(date.getDate() + 6)
Expand Down Expand Up @@ -432,7 +414,6 @@ describe("enter email controller", () => {

it("should redirect to /enter-password re-auth page when re-authentication is required and service call is successful", async () => {
process.env.SUPPORT_REAUTHENTICATION = "1";
req.body.email = email;
req.session.user = {
email,
reauthenticate: "12345",
Expand All @@ -458,6 +439,7 @@ describe("enter email controller", () => {
describe("enterEmailCreatePost", () => {
beforeEach(() => {
req = createMockRequest(PATH_NAMES.ENTER_EMAIL_CREATE_ACCOUNT);
req.body.email = email;
});

it("should redirect to /enter-password when account exists", async () => {
Expand All @@ -468,8 +450,6 @@ describe("enter email controller", () => {
}),
} as unknown as EnterEmailServiceInterface;

req.body.email = email;

await enterEmailCreatePost(fakeService)(req as Request, res as Response);

expect(fakeService.userExists).to.have.been.calledOnce;
Expand All @@ -492,8 +472,6 @@ describe("enter email controller", () => {
}),
} as unknown as SendNotificationServiceInterface;

req.body.email = email;

await enterEmailCreatePost(fakeService, fakeNotificationService)(
req as Request,
res as Response
Expand All @@ -520,8 +498,6 @@ describe("enter email controller", () => {
}),
} as unknown as SendNotificationServiceInterface;

req.body.email = email;

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

0 comments on commit b2b028e

Please sign in to comment.