Skip to content

Commit

Permalink
BAU: test refactors to clarify tests asserting on what is sent throug…
Browse files Browse the repository at this point in the history
…h to send notification service

Hopefully this makes it a bit more obvious what the point of these tests are
  • Loading branch information
BeckaL committed May 22, 2024
1 parent b286b7a commit 26f0f9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,22 @@ describe("resend mfa controller", () => {

beforeEach(() => {
fakeService = { sendNotification: sinon.fake.returns({ success: true }) };
req.path = PATH_NAMES.RESEND_MFA_CODE_ACCOUNT_CREATION;
});

it("should request new phone verification code from send notification service and if successful redirect to /enter-code view", async () => {
req.path = PATH_NAMES.RESEND_MFA_CODE_ACCOUNT_CREATION;

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

expect(res.redirect).to.have.been.calledWith(PATH_NAMES.CHECK_YOUR_PHONE);
expect(fakeService.sendNotification).to.have.been.calledOnce;
});

it("should request new phone verification code from send notification service and if successful redirect to /enter-code view", async () => {
it("should request new phone verification code with relevant registration journey type for account recovery journey", async () => {
req.session.user = {
email,
isAccountRecoveryJourney: true,
};
req.path = PATH_NAMES.RESEND_MFA_CODE_ACCOUNT_CREATION;
const expectedJourneyType = "ACCOUNT_RECOVERY";

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

Expand All @@ -76,16 +75,16 @@ describe("resend mfa controller", () => {
diPersistentSessionId,
"",
req,
"ACCOUNT_RECOVERY"
expectedJourneyType
);
});

it("should request new phone verification code from send notification service and if successful redirect to /enter-code view", async () => {
it("should request new phone verification code with relevant registration journey type for account creation journey", async () => {
req.session.user = {
email,
isAccountCreationJourney: true,
};
req.path = PATH_NAMES.RESEND_MFA_CODE_ACCOUNT_CREATION;
const expectedJourneyType = "REGISTRATION";

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

Expand All @@ -97,7 +96,7 @@ describe("resend mfa controller", () => {
diPersistentSessionId,
"",
req,
"REGISTRATION"
expectedJourneyType
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res";
import { VerifyMfaCodeInterface } from "../../enter-authenticator-app-code/types";
import * as journey from "../../common/journey/journey";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../test/helpers/common-test-variables";

describe("check your phone controller", () => {
let req: RequestOutput;
Expand Down Expand Up @@ -56,7 +57,10 @@ describe("check your phone controller", () => {

beforeEach(() => {
fakeNotificationService = { sendNotification: sinon.fake() };
res.locals.sessionId = commonVariables.sessionId;
req.body.code = "123456";
});

it("can send the journeyType when requesting the MFA code", async () => {
const fakeService: VerifyMfaCodeInterface = {
verifyMfaCode: sinon.fake.returns({
Expand All @@ -70,10 +74,8 @@ describe("check your phone controller", () => {
"getJourneyTypeFromUserSession"
);

req.body.code = "123456";
req.session.user.isAccountRecoveryPermitted = true;
req.session.user.isAccountRecoveryJourney = true;
res.locals.sessionId = "123456-djjad";

await checkYourPhonePost(fakeService, fakeNotificationService)(
req as Request,
Expand All @@ -92,7 +94,7 @@ describe("check your phone controller", () => {
expect(fakeService.verifyMfaCode).to.have.been.calledOnceWithExactly(
sinon.match.any,
sinon.match.any,
sinon.match.any,
commonVariables.sessionId,
sinon.match.any,
sinon.match.any,
sinon.match.any,
Expand All @@ -109,17 +111,14 @@ describe("check your phone controller", () => {
}),
} as unknown as VerifyMfaCodeInterface;

req.body.code = "123456";
res.locals.sessionId = "123456-djjad";

await checkYourPhonePost(fakeService, fakeNotificationService)(
req as Request,
res as Response
);

expect(fakeService.verifyMfaCode).to.have.been.calledOnce;
expect(fakeNotificationService.sendNotification).to.have.calledWith(
"123456-djjad",
commonVariables.sessionId,
undefined,
undefined,
NOTIFICATION_TYPE.ACCOUNT_CREATED_CONFIRMATION,
Expand All @@ -140,8 +139,6 @@ describe("check your phone controller", () => {
}),
} as unknown as VerifyMfaCodeInterface;

req.body.code = "123456";
res.locals.sessionId = "123456-djjad";
req.session.user = {
isAccountRecoveryPermitted: true,
isAccountRecoveryJourney: true,
Expand All @@ -154,7 +151,7 @@ describe("check your phone controller", () => {

expect(fakeService.verifyMfaCode).to.have.been.calledOnce;
expect(fakeNotificationService.sendNotification).to.have.calledWith(
"123456-djjad",
commonVariables.sessionId,
undefined,
undefined,
NOTIFICATION_TYPE.CHANGE_HOW_GET_SECURITY_CODES_CONFIRMATION,
Expand All @@ -178,10 +175,6 @@ describe("check your phone controller", () => {
}),
} as unknown as VerifyMfaCodeInterface;

req.t = sinon.fake.returns("translated string");
req.body.code = "678988";
res.locals.sessionId = "123456-djjad";

await checkYourPhonePost(fakeService, fakeNotificationService)(
req as Request,
res as Response
Expand All @@ -202,10 +195,6 @@ describe("check your phone controller", () => {
}),
} as unknown as VerifyMfaCodeInterface;

req.t = sinon.fake.returns("translated string");
req.body.code = "678988";
res.locals.sessionId = "123456-djjad";

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

0 comments on commit 26f0f9a

Please sign in to comment.