Skip to content

Commit

Permalink
Merge pull request #1638 from govuk-one-login/BAU/use-common-variable…
Browse files Browse the repository at this point in the history
…s-in-more-tests

Bau/use common variables in more tests
  • Loading branch information
BeckaL authored May 22, 2024
2 parents b2c75d6 + 7b13f28 commit 8e10924
Show file tree
Hide file tree
Showing 34 changed files with 78 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ import { PATH_NAMES } from "../../../../app.constants";
import { mockResponse, RequestOutput, ResponseOutput } from "mock-req-res";
import { SendNotificationServiceInterface } from "../../../common/send-notification/types";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../../test/helpers/common-test-variables";

describe("resend mfa controller", () => {
let req: RequestOutput;
let res: ResponseOutput;
const { sessionId, clientSessionId, diPersistentSessionId, ip, email } =
commonVariables;

beforeEach(() => {
req = createMockRequest(PATH_NAMES.CHECK_YOUR_PHONE);
req.ip = ip;
res = mockResponse();
res.locals.sessionId = sessionId;
res.locals.clientSessionId = clientSessionId;
res.locals.persistentSessionId = diPersistentSessionId;
});

afterEach(() => {
Expand All @@ -44,10 +51,6 @@ describe("resend mfa controller", () => {
}),
} as unknown as SendNotificationServiceInterface;

res.locals.sessionId = "123456-djjad";
req.session.user = {
email: "[email protected]",
};
req.path = PATH_NAMES.RESEND_MFA_CODE_ACCOUNT_CREATION;

await resendMfaCodePost(fakeService)(req as Request, res as Response);
Expand All @@ -62,24 +65,20 @@ describe("resend mfa controller", () => {
success: true,
}),
} as unknown as SendNotificationServiceInterface;
res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "654321-djjad";
res.locals.persistentSessionId = "123123-djjad";

req.session.user = {
email: "[email protected]",
email,
isAccountRecoveryJourney: true,
};
req.path = PATH_NAMES.RESEND_MFA_CODE_ACCOUNT_CREATION;
req.ip = "127.0.0.1";
await resendMfaCodePost(fakeService)(req as Request, res as Response);
expect(fakeService.sendNotification).to.have.been.calledWith(
"123456-djjad",
"654321-djjad",
"[email protected]",
sessionId,
clientSessionId,
email,
"VERIFY_PHONE_NUMBER",
"127.0.0.1",
"123123-djjad",
ip,
diPersistentSessionId,
"",
req,
"ACCOUNT_RECOVERY"
Expand All @@ -92,24 +91,20 @@ describe("resend mfa controller", () => {
success: true,
}),
} as unknown as SendNotificationServiceInterface;
res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "654321-djjad";
res.locals.persistentSessionId = "123123-djjad";

req.session.user = {
email: "[email protected]",
email,
isAccountCreationJourney: true,
};
req.path = PATH_NAMES.RESEND_MFA_CODE_ACCOUNT_CREATION;
req.ip = "127.0.0.1";
await resendMfaCodePost(fakeService)(req as Request, res as Response);
expect(fakeService.sendNotification).to.have.been.calledWith(
"123456-djjad",
"654321-djjad",
"[email protected]",
sessionId,
clientSessionId,
email,
"VERIFY_PHONE_NUMBER",
"127.0.0.1",
"123123-djjad",
ip,
diPersistentSessionId,
"",
req,
"REGISTRATION"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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", () => {
describe("password reset required controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { AccountInterventionsInterface } from "../types";
import { accountInterventionService } from "../account-intervention-service";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
Expand All @@ -13,6 +12,7 @@ import {
import { API_ENDPOINTS, PATH_NAMES } from "../../../app.constants";
import { Http } from "../../../utils/http";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../test/helpers/common-test-variables";

describe("account interventions service", () => {
const httpInstance = new Http();
Expand Down
2 changes: 1 addition & 1 deletion src/components/authorize/tests/authorize-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { SinonStub } from "sinon";
import { AuthorizeServiceInterface } from "../types";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";
import {
commonVariables,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
setupApiKeyAndBaseUrlEnvVars,
} from "../../../../test/helpers/service-test-helper";
import { commonVariables } from "../../../../test/helpers/common-test-variables";

describe("authorize service", () => {
let getStub: SinonStub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { CheckEmailFraudBlockInterface } from "../types";
import { checkEmailFraudBlockService } from "../check-email-fraud-block-service";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
Expand All @@ -17,6 +16,7 @@ import {
PATH_NAMES,
} from "../../../app.constants";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../test/helpers/common-test-variables";

describe("check email fraud block service", () => {
const httpInstance = new Http();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { checkReauthUsersService } from "../check-reauth-users-service";
import { CheckReauthServiceInterface } from "../types";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
setupApiKeyAndBaseUrlEnvVars,
} from "../../../../test/helpers/service-test-helper";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../test/helpers/common-test-variables";

describe("re-authentication service", () => {
const httpInstance = new Http();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { AccountRecoveryInterface } from "../types";
import { accountRecoveryService } from "../account-recovery-service";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
setupApiKeyAndBaseUrlEnvVars,
} from "../../../../../test/helpers/service-test-helper";
import { API_ENDPOINTS, PATH_NAMES } from "../../../../app.constants";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../../test/helpers/common-test-variables";

describe("account recovery service", () => {
const httpInstance = new Http();
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/mfa/tests/mfa-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { MfaServiceInterface } from "../types";
import { mfaService } from "../mfa-service";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
Expand All @@ -18,6 +17,7 @@ import {
PATH_NAMES,
} from "../../../../app.constants";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../../test/helpers/common-test-variables";

describe("mfa service", () => {
const httpInstance = new Http();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import sinon, { SinonStub } from "sinon";
import { Http } from "../../../../utils/http";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
Expand All @@ -18,6 +17,7 @@ import { SendNotificationServiceInterface } from "../types";
import { sendNotificationService } from "../send-notification-service";
import { JOURNEY_TYPE } from "../../constants";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../../test/helpers/common-test-variables";

describe("send notification service", () => {
let postStub: SinonStub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Http } from "../../../../utils/http";
import { UpdateProfileServiceInterface, UpdateType } from "../types";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
Expand All @@ -17,6 +16,7 @@ import {
} from "../../../../app.constants";
import { updateProfileService } from "../update-profile-service";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../../test/helpers/common-test-variables";

describe("update profile service", () => {
const httpInstance = new Http();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import sinon, { SinonStub } from "sinon";
import { Http } from "../../../../utils/http";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
Expand All @@ -19,6 +18,7 @@ import {
import { VerifyCodeInterface } from "../types";
import { codeService } from "../verify-code-service";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../../test/helpers/common-test-variables";

describe("verify code service", () => {
const httpInstance = new Http();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import sinon, { SinonStub } from "sinon";
import { Http } from "../../../../utils/http";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
Expand All @@ -19,6 +18,7 @@ import {
import { VerifyMfaCodeInterface } from "../../../enter-authenticator-app-code/types";
import { verifyMfaCodeService } from "../verify-mfa-code-service";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../../test/helpers/common-test-variables";

describe("verify mfa code service", () => {
const httpInstance = new Http();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { describe } from "mocha";
import sinon, { SinonStub } from "sinon";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
Expand All @@ -17,6 +16,7 @@ import {
PATH_NAMES,
} from "../../../app.constants";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../test/helpers/common-test-variables";

describe("create password service", () => {
const httpInstance = new Http();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ describe("doc checking app controller", () => {
}),
} as unknown as DocCheckingAppInterface;

res.locals.sessionId = "s-123456-djjad";
res.locals.clientSessionId = "c-123456-djjad";
res.locals.persistentSessionId = "dips-123456-abc";

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

expect(req.session.user.journey.nextPath).to.equal(
Expand All @@ -55,10 +51,6 @@ describe("doc checking app controller", () => {
}),
} as unknown as DocCheckingAppInterface;

res.locals.sessionId = "s-123456-djjad";
res.locals.clientSessionId = "c-123456-djjad";
res.locals.persistentSessionId = "dips-123456-abc";

await expect(
docCheckingAppGet(fakeService)(req as Request, res as Response)
).to.be.rejectedWith("1222:Error occurred");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { describe } from "mocha";
import sinon, { SinonStub } from "sinon";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
Expand All @@ -17,6 +16,7 @@ import {
PATH_NAMES,
} from "../../../app.constants";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";
import { commonVariables } from "../../../../test/helpers/common-test-variables";

describe("mfa service", () => {
const httpInstance = new Http();
Expand Down
Loading

0 comments on commit 8e10924

Please sign in to comment.