Refactor auth controller tests to reuse common behaviour
This commit is contained in:
parent
f7d91f7cd6
commit
5f5fe92807
|
@ -61,37 +61,37 @@ describe("/api/admin/auth", () => {
|
||||||
auth.oidc.strategyFactory = strategyFactory
|
auth.oidc.strategyFactory = strategyFactory
|
||||||
|
|
||||||
const passportSpy = jest.spyOn(auth.passport, "authenticate")
|
const passportSpy = jest.spyOn(auth.passport, "authenticate")
|
||||||
|
let oidcConf
|
||||||
|
|
||||||
describe("/api/admin/auth/oidc", () => {
|
beforeEach(async () => {
|
||||||
it("should load the oidc config and calculate the correct callback url", async () => {
|
oidcConf = await config.saveOIDCConfig()
|
||||||
const oidcConf = await config.saveOIDCConfig()
|
})
|
||||||
|
|
||||||
await request.get(`/api/admin/auth/oidc`)
|
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
expect(strategyFactory).toBeCalledWith(
|
expect(strategyFactory).toBeCalledWith(
|
||||||
oidcConf.config,
|
oidcConf.config,
|
||||||
"http://127.0.0.1:4003/api/admin/auth/oidc/callback" // calculated url
|
"http://127.0.0.1:4003/api/admin/auth/oidc/callback" // calculated url
|
||||||
)
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("/api/admin/auth/oidc", () => {
|
||||||
|
it("should load strategy and delegate to passport", async () => {
|
||||||
|
await request.get(`/api/admin/auth/oidc`)
|
||||||
|
|
||||||
expect(passportSpy).toBeCalledWith(mockStrategyReturn, {
|
expect(passportSpy).toBeCalledWith(mockStrategyReturn, {
|
||||||
scope: ["profile", "email"],
|
scope: ["profile", "email"],
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(passportSpy.mock.calls.length).toBe(1);
|
expect(passportSpy.mock.calls.length).toBe(1);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("/api/admin/auth/oidc/callback", () => {
|
describe("/api/admin/auth/oidc/callback", () => {
|
||||||
it("should do something", async () => {
|
it("should load strategy and delegate to passport", async () => {
|
||||||
const oidcConf = await config.saveOIDCConfig()
|
|
||||||
const passportSpy = jest.spyOn(auth.passport, "authenticate")
|
|
||||||
|
|
||||||
await request.get(`/api/admin/auth/oidc/callback`)
|
await request.get(`/api/admin/auth/oidc/callback`)
|
||||||
|
|
||||||
expect(passportSpy).toBeCalledWith(mockStrategyReturn, {
|
expect(passportSpy).toBeCalledWith(mockStrategyReturn, {
|
||||||
successRedirect: "/", failureRedirect: "/error"
|
successRedirect: "/", failureRedirect: "/error"
|
||||||
}, expect.anything())
|
}, expect.anything())
|
||||||
|
|
||||||
expect(passportSpy.mock.calls.length).toBe(1);
|
expect(passportSpy.mock.calls.length).toBe(1);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue