Skip to content

Commit

Permalink
Merge pull request #1580 from govuk-one-login/BAU/remove-duplication-…
Browse files Browse the repository at this point in the history
…from-mock-requests

Bau/remove duplication from mock requests
  • Loading branch information
BeckaL authored Apr 25, 2024
2 parents 00d39e8 + c583030 commit 2d79d43
Show file tree
Hide file tree
Showing 44 changed files with 226 additions and 730 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,15 @@ import {
accountCreatedPost,
} from "../account-created-controller";
import { PATH_NAMES } from "../../../app.constants";
import {
mockRequest,
mockResponse,
RequestOutput,
ResponseOutput,
} from "mock-req-res";
import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";

describe("account created controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

beforeEach(() => {
req = mockRequest({
path: PATH_NAMES.CREATE_ACCOUNT_SUCCESSFUL,
session: {
client: {},
user: {},
save: (callback: () => void) => callback(),
},
log: { info: sinon.fake(), debug: sinon.fake() },
});
req = createMockRequest(PATH_NAMES.CREATE_ACCOUNT_SUCCESSFUL);
res = mockResponse();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,16 @@ import {
resendMfaCodePost,
} from "../resend-mfa-code-controller";
import { PATH_NAMES } from "../../../../app.constants";
import {
mockRequest,
mockResponse,
RequestOutput,
ResponseOutput,
} from "mock-req-res";
import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res";
import { SendNotificationServiceInterface } from "../../../common/send-notification/types";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";

describe("resend mfa controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

beforeEach(() => {
req = mockRequest({
path: PATH_NAMES.CHECK_YOUR_PHONE,
session: { client: {}, user: {} },
log: { info: sinon.fake() },
t: sinon.fake(),
i18n: { language: "en" },
});
req = createMockRequest(PATH_NAMES.CHECK_YOUR_PHONE);
res = mockResponse();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@ import { describe } from "mocha";

import { sinon } from "../../../../../test/utils/test-utils";

import {
mockRequest,
mockResponse,
RequestOutput,
ResponseOutput,
} from "mock-req-res";
import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res";
import { passwordResetRequiredGet } from "../password-reset-required-controller";
import { PATH_NAMES } from "../../../../app.constants";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";

describe("account intervention controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

beforeEach(() => {
req = mockRequest({
path: PATH_NAMES.PASSWORD_RESET_REQUIRED,
session: { client: {}, user: {} },
log: { info: sinon.fake() },
});
req = createMockRequest(PATH_NAMES.PASSWORD_RESET_REQUIRED);
res = mockResponse();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@ import { describe } from "mocha";

import { sinon } from "../../../../../test/utils/test-utils";

import {
mockRequest,
mockResponse,
RequestOutput,
ResponseOutput,
} from "mock-req-res";
import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res";
import { permanentlyBlockedGet } from "../permanently-blocked-controller";
import { PATH_NAMES } from "../../../../app.constants";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";

describe("permanently blocked controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

beforeEach(() => {
req = mockRequest({
path: PATH_NAMES.UNAVAILABLE_PERMANENT,
session: { client: {}, user: {} },
log: { info: sinon.fake() },
});
req = createMockRequest(PATH_NAMES.UNAVAILABLE_PERMANENT);
res = mockResponse();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@ import { describe } from "mocha";

import { sinon } from "../../../../../test/utils/test-utils";

import {
mockRequest,
mockResponse,
RequestOutput,
ResponseOutput,
} from "mock-req-res";
import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res";
import { temporarilyBlockedGet } from "../temporarily-blocked-controller";
import { PATH_NAMES } from "../../../../app.constants";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";

describe("temporarily blocked controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

beforeEach(() => {
req = mockRequest({
path: PATH_NAMES.UNAVAILABLE_TEMPORARY,
session: { client: {}, user: {} },
log: { info: sinon.fake() },
});
req = createMockRequest(PATH_NAMES.UNAVAILABLE_TEMPORARY);
res = mockResponse();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,15 @@ import {
} from "../account-not-found-controller";
import { PATH_NAMES, SERVICE_TYPE } from "../../../app.constants";
import { SendNotificationServiceInterface } from "../../common/send-notification/types";
import {
mockRequest,
mockResponse,
RequestOutput,
ResponseOutput,
} from "mock-req-res";
import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";

describe("account not found controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

beforeEach(() => {
req = mockRequest({
path: PATH_NAMES.ACCOUNT_NOT_FOUND,
session: {
client: {},
user: {},
save: (callback: () => void) => callback(),
},
log: { info: sinon.fake(), debug: sinon.fake() },
});
req = createMockRequest(PATH_NAMES.ACCOUNT_NOT_FOUND);
res = mockResponse();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,19 @@ import { sinon } from "../../../../../test/utils/test-utils";
import { Request, Response } from "express";

import { MFA_METHOD_TYPE, PATH_NAMES } from "../../../../app.constants";
import {
mockRequest,
mockResponse,
RequestOutput,
ResponseOutput,
} from "mock-req-res";
import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res";
import {
changeSecurityCodesConfirmationGet,
changeSecurityCodesConfirmationPost,
} from "../change-security-codes-confirmation-controller";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";

describe("change security codes confirmation controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

beforeEach(() => {
req = mockRequest({
path: PATH_NAMES.CHANGE_SECURITY_CODES_CONFIRMATION,
session: { client: {}, user: {} },
log: { info: sinon.fake() },
});
req = createMockRequest(PATH_NAMES.CHANGE_SECURITY_CODES_CONFIRMATION);
res = mockResponse();
});

Expand Down Expand Up @@ -57,15 +49,7 @@ describe("change security codes confirmation controller", () => {

describe("changeSecurityCodesConfirmationPost", () => {
it("should redirect to auth code after security codes confirmation ", async () => {
req = mockRequest({
path: PATH_NAMES.CHANGE_SECURITY_CODES_CONFIRMATION,
session: {
client: {},
user: {},
save: (callback: () => void) => callback(),
},
log: { info: sinon.fake(), debug: sinon.fake() },
});
req = createMockRequest(PATH_NAMES.CHANGE_SECURITY_CODES_CONFIRMATION);
await changeSecurityCodesConfirmationPost(
req as Request,
res as Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,21 @@ import {
checkYourEmailSecurityCodesPost,
} from "../check-your-email-security-codes-controller";
import { PATH_NAMES } from "../../../../app.constants";
import {
mockRequest,
mockResponse,
RequestOutput,
ResponseOutput,
} from "mock-req-res";
import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res";
import {
accountInterventionsFakeHelper,
noInterventions,
} from "../../../../../test/helpers/account-interventions-helpers";
import { fakeVerifyCodeServiceHelper } from "../../../../../test/helpers/verify-code-helpers";
import { ERROR_CODES } from "../../../common/constants";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";

describe("check your email change security codes controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

beforeEach(() => {
req = mockRequest({
path: PATH_NAMES.CHECK_YOUR_EMAIL_CHANGE_SECURITY_CODES,
session: {
client: {},
user: {},
save: (callback: () => void) => callback(),
},
log: { info: sinon.fake(), debug: sinon.fake() },
t: sinon.fake(),
i18n: { language: "en" },
});
req = createMockRequest(PATH_NAMES.CHECK_YOUR_EMAIL_CHANGE_SECURITY_CODES);
res = mockResponse();
});

Expand Down
28 changes: 7 additions & 21 deletions src/components/authorize/tests/authorize-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import {
OIDC_PROMPT,
PATH_NAMES,
} from "../../../app.constants";
import {
mockRequest,
mockResponse,
RequestOutput,
ResponseOutput,
} from "mock-req-res";
import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res";
import {
AuthorizeServiceInterface,
JwtServiceInterface,
Expand All @@ -26,6 +21,7 @@ import { BadRequestError } from "../../../utils/error";
import { createmockclaims } from "./test-data";
import { Claims } from "../claims-config";
import { getOrchToAuthExpectedClientId } from "../../../config";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";

describe("authorize controller", () => {
let req: RequestOutput;
Expand All @@ -39,21 +35,11 @@ describe("authorize controller", () => {

beforeEach(() => {
mockClaims = createmockclaims();
req = mockRequest({
path: PATH_NAMES.AUTHORIZE,
session: {
client: {},
user: {},
save: (callback: () => void) => callback(),
},
log: { info: sinon.fake(), debug: sinon.fake() },
t: sinon.fake(),
i18n: { language: "en" },
query: {
client_id: getOrchToAuthExpectedClientId(),
response_type: "code",
},
});
req = createMockRequest(PATH_NAMES.AUTHORIZE);
req.query = {
client_id: getOrchToAuthExpectedClientId(),
response_type: "code",
};
res = mockResponse();
authServiceResponseData = createAuthServiceReponseData();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,15 @@ import {
} from "../check-your-email-controller";
import { PATH_NAMES } from "../../../app.constants";
import { ERROR_CODES, getErrorPathByCode } from "../../common/constants";
import {
mockRequest,
mockResponse,
RequestOutput,
ResponseOutput,
} from "mock-req-res";
import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";

describe("check your email controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

beforeEach(() => {
req = mockRequest({
path: PATH_NAMES.CHECK_YOUR_EMAIL,
session: {
client: {},
user: {},
save: (callback: () => void) => callback(),
},
log: { info: sinon.fake(), debug: sinon.fake() },
t: sinon.fake(),
i18n: { language: "en" },
});
req = createMockRequest(PATH_NAMES.CHECK_YOUR_EMAIL);
res = mockResponse();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,17 @@ import {
PATH_NAMES,
} from "../../../app.constants";
import { ERROR_CODES } from "../../common/constants";
import {
mockRequest,
mockResponse,
RequestOutput,
ResponseOutput,
} from "mock-req-res";
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";

describe("check your phone controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

beforeEach(() => {
req = mockRequest({
path: PATH_NAMES.CHECK_YOUR_PHONE,
session: {
client: {},
user: {},
save: (callback: () => void) => callback(),
},
log: { info: sinon.fake(), debug: sinon.fake() },
t: sinon.fake(),
i18n: { language: "en" },
});
req = createMockRequest(PATH_NAMES.CHECK_YOUR_PHONE);
res = mockResponse();
});

Expand Down
Loading

0 comments on commit 2d79d43

Please sign in to comment.