|
1 | 1 | import { describe } from "mocha"; |
2 | 2 | import type { Request, Response } from "express"; |
3 | 3 | import { expect } from "chai"; |
4 | | -import { howDoYouWantSecurityCodesGet } from "../how-do-you-want-security-codes-controller.js"; |
| 4 | +import { strict as assert } from "assert"; |
| 5 | +import { |
| 6 | + howDoYouWantSecurityCodesGet, |
| 7 | + howDoYouWantSecurityCodesPost, |
| 8 | +} from "../how-do-you-want-security-codes-controller.js"; |
5 | 9 | import { mockResponse } from "mock-req-res"; |
6 | 10 | import type { RequestOutput, ResponseOutput } from "mock-req-res"; |
7 | 11 | import { createMockRequest } from "../../../../test/helpers/mock-request-helper.js"; |
8 | 12 | import { PATH_NAMES } from "../../../app.constants.js"; |
9 | 13 | import { sinon } from "../../../../test/utils/test-utils.js"; |
| 14 | +import { BadRequestError } from "../../../utils/error.js"; |
| 15 | +import { buildMfaMethods } from "../../../../test/helpers/mfa-helper.js"; |
10 | 16 |
|
11 | 17 | describe("how do you want security codes controller", () => { |
12 | 18 | let req: RequestOutput; |
@@ -59,4 +65,33 @@ describe("how do you want security codes controller", () => { |
59 | 65 | ); |
60 | 66 | }); |
61 | 67 | }); |
| 68 | + |
| 69 | + describe("howDoYouWantSecurityCodesPost", () => { |
| 70 | + it("should throw error if the user has no MFA methods", async () => { |
| 71 | + req.session.user.mfaMethods = []; |
| 72 | + |
| 73 | + await assert.rejects( |
| 74 | + async () => howDoYouWantSecurityCodesPost(req, res), |
| 75 | + BadRequestError, |
| 76 | + "No MFA methods found" |
| 77 | + ); |
| 78 | + }); |
| 79 | + |
| 80 | + it("should redirect to /enter-authenticator-app-code if 'authenticator app' is selected", async () => { |
| 81 | + req.body["mfa-method-id"] = "testAuthApp"; |
| 82 | + req.session.user.mfaMethods = buildMfaMethods([ |
| 83 | + { |
| 84 | + id: "testPhone", |
| 85 | + redactedPhoneNumber: "07000000000", |
| 86 | + }, |
| 87 | + { id: "testAuthApp", authApp: true }, |
| 88 | + ]); |
| 89 | + |
| 90 | + await howDoYouWantSecurityCodesPost(req, res); |
| 91 | + |
| 92 | + expect(res.redirect).to.have.been.calledWith( |
| 93 | + PATH_NAMES.ENTER_AUTHENTICATOR_APP_CODE |
| 94 | + ); |
| 95 | + }); |
| 96 | + }); |
62 | 97 | }); |
0 commit comments