1
0
Fork 0
mirror of synced 2024-10-04 03:54:37 +13:00

Tests configs

This commit is contained in:
adrinr 2023-03-27 17:58:32 +01:00
parent d0772ee142
commit 1a9653a4db
4 changed files with 67 additions and 48 deletions

View file

@ -40,6 +40,7 @@ export enum Config {
GOOGLE = "google",
OIDC = "oidc",
OIDC_LOGOS = "logos_oidc",
SCIM = "scim",
}
export const MIN_VALID_DATE = new Date(-2147483647000)

View file

@ -108,7 +108,7 @@ export interface OIDCWellKnownConfig {
}
export interface SCIMConfig extends Config {
enabled: boolean
config: { enabled: boolean }
}
export const isSettingsConfig = (config: Config): config is SettingsConfig =>

View file

@ -11,11 +11,18 @@ import { events } from "@budibase/backend-core"
mocks.licenses.useScimIntegration()
const unauthorisedTests = (
fn: (
...params: any //settings: RequestSettings
) => Promise<any>
) => {
describe("scim", () => {
beforeEach(async () => {
jest.resetAllMocks()
tk.freeze(mocks.date.MOCK_DATE)
mocks.licenses.useScimIntegration()
await config.setSCIMConfig(true)
})
const config = new TestConfiguration()
const unauthorisedTests = (fn: (...params: any) => Promise<any>) => {
describe("unauthorised calls", () => {
it("unauthorised calls are not allowed", async () => {
const response = await fn(...Array(fn.length - 1).fill({}), {
@ -43,6 +50,7 @@ const unauthorisedTests = (
})
it("cannot be called when feature is enabled but the config disabled", async () => {
await config.setSCIMConfig(false)
const response = await fn(...Array(fn.length - 1).fill({}), {
expect: 400,
})
@ -55,15 +63,6 @@ const unauthorisedTests = (
})
}
describe("scim", () => {
beforeEach(() => {
jest.resetAllMocks()
tk.freeze(mocks.date.MOCK_DATE)
mocks.licenses.useScimIntegration()
})
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
@ -73,7 +72,7 @@ describe("scim", () => {
})
describe("/api/global/scim/v2/users", () => {
describe.only("GET /api/global/scim/v2/users", () => {
describe("GET /api/global/scim/v2/users", () => {
const getScimUsers = config.api.scimUsersAPI.get
unauthorisedTests(getScimUsers)

View file

@ -25,7 +25,13 @@ import {
utils,
} from "@budibase/backend-core"
import structures, { CSRF_TOKEN } from "./structures"
import { SaveUserResponse, User, AuthToken } from "@budibase/types"
import {
SaveUserResponse,
User,
AuthToken,
SCIMConfig,
ConfigType,
} from "@budibase/types"
import API from "./api"
class TestConfiguration {
@ -335,6 +341,19 @@ class TestConfiguration {
controllers.config.save
)
}
// CONFIGS - SCIM
async setSCIMConfig(enabled: boolean) {
await this.deleteConfig(Config.SCIM)
const config: SCIMConfig = {
type: ConfigType.SCIM,
config: { enabled },
}
await this._req(config, null, controllers.config.save)
return config
}
}
export default TestConfiguration