From 7c7e5f061dc18981d2de8b7a9c6d68cbd03e9e96 Mon Sep 17 00:00:00 2001 From: BeckaL Date: Wed, 22 May 2024 15:22:03 +0100 Subject: [PATCH] BAU: test refactors to clarify tests asserting on what is sent through to send notification service Hopefully this makes it a bit more obvious what the point of these tests are --- .../tests/resend-mfa-code-controller.test.ts | 15 ++++++----- .../tests/check-your-phone-controller.test.ts | 25 ++++++------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/components/account-creation/resend-mfa-code/tests/resend-mfa-code-controller.test.ts b/src/components/account-creation/resend-mfa-code/tests/resend-mfa-code-controller.test.ts index 0e2311f0c5..3e01f7a289 100644 --- a/src/components/account-creation/resend-mfa-code/tests/resend-mfa-code-controller.test.ts +++ b/src/components/account-creation/resend-mfa-code/tests/resend-mfa-code-controller.test.ts @@ -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); @@ -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); @@ -97,7 +96,7 @@ describe("resend mfa controller", () => { diPersistentSessionId, "", req, - "REGISTRATION" + expectedJourneyType ); }); }); diff --git a/src/components/check-your-phone/tests/check-your-phone-controller.test.ts b/src/components/check-your-phone/tests/check-your-phone-controller.test.ts index 50122b45d0..55b7eecd4c 100644 --- a/src/components/check-your-phone/tests/check-your-phone-controller.test.ts +++ b/src/components/check-your-phone/tests/check-your-phone-controller.test.ts @@ -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; @@ -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({ @@ -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, @@ -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, @@ -109,9 +111,6 @@ 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 @@ -119,7 +118,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.ACCOUNT_CREATED_CONFIRMATION, @@ -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, @@ -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, @@ -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 @@ -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