From 1a7619367b37786a2e7b80325b1e5d5f203fe41e Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Tue, 13 Jul 2021 10:28:15 +0100 Subject: [PATCH] Refactor auth controller tests to reuse common behaviour --- .../worker/src/api/routes/tests/auth.spec.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/worker/src/api/routes/tests/auth.spec.js b/packages/worker/src/api/routes/tests/auth.spec.js index 5cfcec5373..c8a57d9aed 100644 --- a/packages/worker/src/api/routes/tests/auth.spec.js +++ b/packages/worker/src/api/routes/tests/auth.spec.js @@ -61,37 +61,37 @@ describe("/api/admin/auth", () => { auth.oidc.strategyFactory = strategyFactory const passportSpy = jest.spyOn(auth.passport, "authenticate") + let oidcConf + + beforeEach(async () => { + oidcConf = await config.saveOIDCConfig() + }) + + afterEach(() => { + expect(strategyFactory).toBeCalledWith( + oidcConf.config, + "http://127.0.0.1:4003/api/admin/auth/oidc/callback" // calculated url + ) + }) describe("/api/admin/auth/oidc", () => { - it("should load the oidc config and calculate the correct callback url", async () => { - const oidcConf = await config.saveOIDCConfig() - + it("should load strategy and delegate to passport", async () => { await request.get(`/api/admin/auth/oidc`) - expect(strategyFactory).toBeCalledWith( - oidcConf.config, - "http://127.0.0.1:4003/api/admin/auth/oidc/callback" // calculated url - ) - expect(passportSpy).toBeCalledWith(mockStrategyReturn, { scope: ["profile", "email"], }) - expect(passportSpy.mock.calls.length).toBe(1); }) }) describe("/api/admin/auth/oidc/callback", () => { - it("should do something", async () => { - const oidcConf = await config.saveOIDCConfig() - const passportSpy = jest.spyOn(auth.passport, "authenticate") - + it("should load strategy and delegate to passport", async () => { await request.get(`/api/admin/auth/oidc/callback`) expect(passportSpy).toBeCalledWith(mockStrategyReturn, { successRedirect: "/", failureRedirect: "/error" }, expect.anything()) - expect(passportSpy.mock.calls.length).toBe(1); }) })