Skip to content

Commit d9e5b3d

Browse files
committed
BAU: refactor reset password check email tests
- Delete redundant test - - The assertions in this test are covered in "should render reset password check email view" - Refactor overlapping tests into single parameterized test - Add missing assertion
1 parent 5b43e18 commit d9e5b3d

1 file changed

Lines changed: 15 additions & 58 deletions

File tree

src/components/reset-password-check-email/tests/reset-password-check-email-controller.test.ts

Lines changed: 15 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { fakeVerifyCodeServiceHelper } from "../../../../test/helpers/verify-cod
2222
import { createMockRequest } from "../../../../test/helpers/mock-request-helper.js";
2323
import { getDefaultSmsMfaMethod } from "../../../utils/mfa.js";
2424
import { match } from "sinon";
25-
import type { PartialMfaMethod } from "../../../../test/helpers/mfa-helper.js";
2625
import { buildMfaMethods } from "../../../../test/helpers/mfa-helper.js";
2726
import type { MfaMethod } from "../../../types.js";
2827

@@ -80,37 +79,6 @@ describe("reset password check email controller", () => {
8079
"reset-password-check-email/index.njk"
8180
);
8281
});
83-
84-
it("should record mfaMethods in user session", async () => {
85-
const partialMfaMethods: PartialMfaMethod[] = [
86-
{
87-
redactedPhoneNumber: "777",
88-
},
89-
{
90-
authApp: true,
91-
},
92-
];
93-
const expectedMfaMethods: MfaMethod[] =
94-
buildMfaMethods(partialMfaMethods);
95-
96-
const fakeService: ResetPasswordCheckEmailServiceInterface = {
97-
resetPasswordRequest: sinon.fake.returns({
98-
success: true,
99-
data: {
100-
mfaMethodType: "SMS",
101-
mfaMethods: expectedMfaMethods,
102-
phoneNumberLastThree: "777",
103-
},
104-
}),
105-
} as unknown as ResetPasswordCheckEmailServiceInterface;
106-
107-
await resetPasswordCheckEmailGet(fakeService)(
108-
req as Request,
109-
res as Response
110-
);
111-
112-
expect(req.session.user.mfaMethods).to.deep.equal(expectedMfaMethods);
113-
});
11482
});
11583

11684
describe("resetPasswordCheckEmailPost", () => {
@@ -199,37 +167,26 @@ describe("reset password check email controller", () => {
199167
);
200168
});
201169

202-
it("should redirect to /reset-password without calling the account interventions service when session.user.withinForcedPasswordResetJourney === true and enterEmailMfaType == SMS", async () => {
203-
req.session.user.withinForcedPasswordResetJourney = true;
204-
req.session.user.enterEmailMfaType = "SMS";
170+
["AUTH_APP", "SMS"].forEach((method) => {
171+
it(`should redirect to /reset-password without calling the account interventions service when session.user.withinForcedPasswordResetJourney === true and enterEmailMfaType == ${method}`, async () => {
172+
req.session.user.withinForcedPasswordResetJourney = true;
173+
req.session.user.enterEmailMfaType = method;
205174

206-
const fakeInterventionsService =
207-
accountInterventionsFakeHelper(noInterventions);
175+
const fakeInterventionsService =
176+
accountInterventionsFakeHelper(noInterventions);
208177

209-
const fakeService = fakeVerifyCodeServiceHelper(true);
210-
await resetPasswordCheckEmailPost(fakeService, fakeInterventionsService)(
211-
req as Request,
212-
res as Response
213-
);
178+
const fakeService = fakeVerifyCodeServiceHelper(true);
179+
await resetPasswordCheckEmailPost(
180+
fakeService,
181+
fakeInterventionsService
182+
)(req as Request, res as Response);
214183

215-
expect(res.redirect).to.have.calledWith(PATH_NAMES.RESET_PASSWORD);
184+
expect(fakeInterventionsService.accountInterventionStatus).to.not.be
185+
.called;
186+
expect(res.redirect).to.have.calledWith(PATH_NAMES.RESET_PASSWORD);
187+
});
216188
});
217189

218-
it("should redirect to /reset-password without calling the account interventions service when session.user.withinForcedPasswordResetJourney === true and enterEmailMfaType == AUTH_APP", async () => {
219-
req.session.user.withinForcedPasswordResetJourney = true;
220-
req.session.user.enterEmailMfaType = "AUTH_APP";
221-
222-
const fakeInterventionsService =
223-
accountInterventionsFakeHelper(noInterventions);
224-
225-
const fakeService = fakeVerifyCodeServiceHelper(true);
226-
await resetPasswordCheckEmailPost(fakeService, fakeInterventionsService)(
227-
req as Request,
228-
res as Response
229-
);
230-
231-
expect(res.redirect).to.have.calledWith(PATH_NAMES.RESET_PASSWORD);
232-
});
233190
describe("resendMfaCodeGet", () => {
234191
it("should render index-reset-password-resend-code.njk mfa code view", () => {
235192
resetPasswordResendCodeGet(req as Request, res as Response);

0 commit comments

Comments
 (0)