-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BAU: Use common variables in enter password controller tests
This reduces some noisy test setup. Also moves some common setup to a before block to reduce noise in individual tests further
- Loading branch information
Showing
1 changed file
with
13 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,14 +18,21 @@ import { ERROR_CODES } from "../../common/constants"; | |
import * as journey from "../../common/journey/journey"; | ||
import { accountInterventionsFakeHelper } from "../../../../test/helpers/account-interventions-helpers"; | ||
import { createMockRequest } from "../../../../test/helpers/mock-request-helper"; | ||
import { commonVariables } from "../../../../test/helpers/common-test-variables"; | ||
|
||
describe("enter password controller", () => { | ||
let req: RequestOutput; | ||
let res: ResponseOutput; | ||
const { sessionId, clientSessionId, diPersistentSessionId, email } = | ||
commonVariables; | ||
|
||
beforeEach(() => { | ||
req = createMockRequest(PATH_NAMES.ENTER_PASSWORD); | ||
res = mockResponse(); | ||
res.locals.sessionId = sessionId; | ||
res.locals.clientSessionId = clientSessionId; | ||
res.locals.persistentSessionId = diPersistentSessionId; | ||
req.session.user = { email }; | ||
process.env.SUPPORT_ACCOUNT_INTERVENTIONS = "1"; | ||
}); | ||
|
||
|
@@ -44,6 +51,10 @@ describe("enter password controller", () => { | |
|
||
describe("enterPasswordPost", () => { | ||
describe("sending MFA code", () => { | ||
beforeEach(() => { | ||
req.body["password"] = "password"; | ||
}); | ||
|
||
it("should call the MFA service to send an code when required and able to", async () => { | ||
const fakeService: EnterPasswordServiceInterface = { | ||
loginUser: sinon.fake.returns({ | ||
|
@@ -66,14 +77,6 @@ describe("enter password controller", () => { | |
}), | ||
} as unknown as MfaServiceInterface; | ||
|
||
res.locals.sessionId = "123456-djjad"; | ||
res.locals.clientSessionId = "00000-djjad"; | ||
res.locals.persistentSessionId = "dips-123456-abc"; | ||
req.session.user = { | ||
email: "[email protected]", | ||
}; | ||
req.body["password"] = "password"; | ||
|
||
await enterPasswordPost( | ||
false, | ||
fakeService, | ||
|
@@ -110,14 +113,7 @@ describe("enter password controller", () => { | |
"getJourneyTypeFromUserSession" | ||
); | ||
|
||
res.locals.sessionId = "123456-djjad"; | ||
res.locals.clientSessionId = "00000-djjad"; | ||
res.locals.persistentSessionId = "dips-123456-abc"; | ||
req.session.user = { | ||
email: "[email protected]", | ||
reauthenticate: "test_data", | ||
}; | ||
req.body["password"] = "password"; | ||
req.session.user = { email, reauthenticate: "test_data" }; | ||
|
||
await enterPasswordPost( | ||
false, | ||
|
@@ -173,14 +169,7 @@ describe("enter password controller", () => { | |
"getJourneyTypeFromUserSession" | ||
); | ||
|
||
res.locals.sessionId = "123456-djjad"; | ||
res.locals.clientSessionId = "00000-djjad"; | ||
res.locals.persistentSessionId = "dips-123456-abc"; | ||
req.session.user = { | ||
email: "[email protected]", | ||
reauthenticate: "test_data", | ||
}; | ||
req.body["password"] = "password"; | ||
req.session.user = { email, reauthenticate: "test_data" }; | ||
|
||
await enterPasswordPost( | ||
false, | ||
|
@@ -228,14 +217,6 @@ describe("enter password controller", () => { | |
}), | ||
} as unknown as MfaServiceInterface; | ||
|
||
res.locals.sessionId = "123456-djjad"; | ||
res.locals.clientSessionId = "00000-djjad"; | ||
res.locals.persistentSessionId = "dips-123456-abc"; | ||
req.session.user = { | ||
email: "[email protected]", | ||
}; | ||
req.body["password"] = "password"; | ||
|
||
await enterPasswordPost( | ||
false, | ||
fakeService, | ||
|
@@ -259,14 +240,6 @@ describe("enter password controller", () => { | |
}), | ||
} as unknown as EnterPasswordServiceInterface; | ||
|
||
res.locals.sessionId = "123456-djjad"; | ||
res.locals.clientSessionId = "00000-djjad"; | ||
res.locals.persistentSessionId = "dips-123456-abc"; | ||
req.session.user = { | ||
email: "[email protected]", | ||
}; | ||
req.body["password"] = "password"; | ||
|
||
await enterPasswordPost(false, fakeService)( | ||
req as Request, | ||
res as Response | ||
|
@@ -288,14 +261,6 @@ describe("enter password controller", () => { | |
}), | ||
} as unknown as EnterPasswordServiceInterface; | ||
|
||
res.locals.sessionId = "123456-djjad"; | ||
res.locals.clientSessionId = "00000-djjad"; | ||
res.locals.persistentSessionId = "dips-123456-abc"; | ||
req.session.user = { | ||
email: "[email protected]", | ||
}; | ||
req.body["password"] = "password"; | ||
|
||
await enterPasswordPost(false, fakeService)( | ||
req as Request, | ||
res as Response | ||
|
@@ -318,14 +283,6 @@ describe("enter password controller", () => { | |
}), | ||
} as unknown as EnterPasswordServiceInterface; | ||
|
||
res.locals.sessionId = "123456-djjad"; | ||
res.locals.clientSessionId = "00000-djjad"; | ||
res.locals.persistentSessionId = "dips-123456-abc"; | ||
req.session.user = { | ||
email: "[email protected]", | ||
}; | ||
req.body["password"] = "password"; | ||
|
||
await enterPasswordPost(false, fakeService)( | ||
req as Request, | ||
res as Response | ||
|
@@ -347,13 +304,6 @@ describe("enter password controller", () => { | |
sendMfaCode: sinon.fake(), | ||
}; | ||
|
||
res.locals.sessionId = "123456-djjad"; | ||
res.locals.clientSessionId = "00000-djjad"; | ||
req.session.user = { | ||
email: "[email protected]", | ||
}; | ||
req.body["password"] = "password"; | ||
|
||
await expect( | ||
enterPasswordPost( | ||
false, | ||
|
@@ -420,13 +370,6 @@ describe("enter password controller", () => { | |
temporarilySuspended: testCase.interventions.temporarilySuspended, | ||
reproveIdentity: false, | ||
}); | ||
res.locals.sessionId = "123456-djjad"; | ||
res.locals.clientSessionId = "00000-djjad"; | ||
res.locals.persistentSessionId = "dips-123456-abc"; | ||
req.session.user = { | ||
email: "[email protected]", | ||
}; | ||
req.body["password"] = "password"; | ||
|
||
await enterPasswordPost( | ||
false, | ||
|
@@ -443,25 +386,13 @@ describe("enter password controller", () => { | |
}); | ||
|
||
describe("enterSignInRetryBlockedGet", () => { | ||
const SESSION_ID = "123456-djjad"; | ||
const CLIENT_SESSION_ID = "00000-djjad"; | ||
const PERSISTENT_SESSION_ID = "dips-123456-abc"; | ||
const EMAIL = "[email protected]"; | ||
|
||
it("should render /enter-password view when account is unblocked", async () => { | ||
const fakeService: EnterEmailServiceInterface = { | ||
userExists: sinon.fake.returns({ | ||
success: true, | ||
}), | ||
} as unknown as EnterEmailServiceInterface; | ||
|
||
res.locals.sessionId = SESSION_ID; | ||
res.locals.clientSessionId = CLIENT_SESSION_ID; | ||
res.locals.persistentSessionId = PERSISTENT_SESSION_ID; | ||
req.session.user = { | ||
email: EMAIL, | ||
}; | ||
|
||
await enterSignInRetryBlockedGet(fakeService)( | ||
req as Request, | ||
res as Response | ||
|
@@ -480,13 +411,6 @@ describe("enter password controller", () => { | |
}), | ||
} as unknown as EnterEmailServiceInterface; | ||
|
||
res.locals.sessionId = SESSION_ID; | ||
res.locals.clientSessionId = CLIENT_SESSION_ID; | ||
res.locals.persistentSessionId = PERSISTENT_SESSION_ID; | ||
req.session.user = { | ||
email: EMAIL, | ||
}; | ||
|
||
await enterSignInRetryBlockedGet(fakeService)( | ||
req as Request, | ||
res as Response | ||
|