Auth test fix for oidc strategy mocks

This commit is contained in:
Dean 2022-07-04 09:04:55 +01:00
parent 129a5c2672
commit da9e675847
1 changed files with 11 additions and 8 deletions

View File

@ -77,27 +77,30 @@ describe("/api/global/auth", () => {
describe("oidc", () => {
const auth = require("@budibase/backend-core/auth")
// mock the oidc strategy implementation and return value
let strategyFactory = jest.fn()
let mockStrategyReturn = jest.fn()
strategyFactory.mockReturnValue(mockStrategyReturn)
auth.oidc.strategyFactory = strategyFactory
const passportSpy = jest.spyOn(auth.passport, "authenticate")
let oidcConf
let chosenConfig
let configId
// mock the oidc strategy implementation and return value
let strategyFactory = jest.fn()
let mockStrategyReturn = jest.fn()
let mockStrategyConfig = jest.fn()
auth.oidc.fetchStrategyConfig = mockStrategyConfig
strategyFactory.mockReturnValue(mockStrategyReturn)
auth.oidc.strategyFactory = strategyFactory
beforeEach(async () => {
oidcConf = await config.saveOIDCConfig()
chosenConfig = oidcConf.config.configs[0]
configId = chosenConfig.uuid
mockStrategyConfig.mockReturnValue(chosenConfig)
})
afterEach(() => {
expect(strategyFactory).toBeCalledWith(
chosenConfig,
`http://localhost:10000/api/global/auth/${TENANT_ID}/oidc/callback`,
expect.any(Function)
)
})
@ -107,7 +110,7 @@ describe("/api/global/auth", () => {
await request.get(`/api/global/auth/${TENANT_ID}/oidc/configs/${configId}`)
expect(passportSpy).toBeCalledWith(mockStrategyReturn, {
scope: ["profile", "email"],
scope: ["profile", "email", "offline_access"]
})
expect(passportSpy.mock.calls.length).toBe(1);
})