Feature tests
This commit is contained in:
parent
97e181fffe
commit
f62647f284
|
@ -86,6 +86,10 @@ export const useAuditLogs = () => {
|
||||||
return useFeature(Feature.AUDIT_LOGS)
|
return useFeature(Feature.AUDIT_LOGS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useScimIntegration = () => {
|
||||||
|
return useFeature(Feature.SCIM_INTEGRATION)
|
||||||
|
}
|
||||||
|
|
||||||
// QUOTAS
|
// QUOTAS
|
||||||
|
|
||||||
export const setAutomationLogsQuota = (value: number) => {
|
export const setAutomationLogsQuota = (value: number) => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import tk from "timekeeper"
|
import tk from "timekeeper"
|
||||||
import { structures } from "@budibase/backend-core/tests"
|
import { mocks, structures } from "@budibase/backend-core/tests"
|
||||||
import { ScimCreateUserRequest } from "@budibase/types"
|
import { ScimCreateUserRequest } from "@budibase/types"
|
||||||
import { TestConfiguration } from "../../../../../tests"
|
import { TestConfiguration } from "../../../../../tests"
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ describe("/api/global/scim/v2/users", () => {
|
||||||
tk.reset()
|
tk.reset()
|
||||||
mockedTime = new Date(structures.generator.timestamp())
|
mockedTime = new Date(structures.generator.timestamp())
|
||||||
tk.freeze(mockedTime)
|
tk.freeze(mockedTime)
|
||||||
|
|
||||||
|
mocks.licenses.useScimIntegration()
|
||||||
})
|
})
|
||||||
|
|
||||||
const config = new TestConfiguration()
|
const config = new TestConfiguration()
|
||||||
|
@ -26,9 +28,21 @@ describe("/api/global/scim/v2/users", () => {
|
||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const featureDisabledResponse = {
|
||||||
|
error: {
|
||||||
|
code: "feature_disabled",
|
||||||
|
featureName: "scimIntegration",
|
||||||
|
type: "license_error",
|
||||||
|
},
|
||||||
|
message: "scimIntegration is not currently enabled",
|
||||||
|
status: 400,
|
||||||
|
}
|
||||||
|
|
||||||
describe("GET /api/global/scim/v2/users", () => {
|
describe("GET /api/global/scim/v2/users", () => {
|
||||||
|
const getScimUsers = config.api.scimUsersAPI.get
|
||||||
|
|
||||||
it("unauthorised calls are not allowed", async () => {
|
it("unauthorised calls are not allowed", async () => {
|
||||||
const response = await config.api.scimUsersAPI.get({
|
const response = await getScimUsers({
|
||||||
setHeaders: false,
|
setHeaders: false,
|
||||||
expect: 403,
|
expect: 403,
|
||||||
})
|
})
|
||||||
|
@ -36,9 +50,16 @@ describe("/api/global/scim/v2/users", () => {
|
||||||
expect(response).toEqual({ message: "Tenant id not set", status: 403 })
|
expect(response).toEqual({ message: "Tenant id not set", status: 403 })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("cannot be called when feature is disabled", async () => {
|
||||||
|
mocks.licenses.useCloudFree()
|
||||||
|
const response = await getScimUsers({ expect: 400 })
|
||||||
|
|
||||||
|
expect(response).toEqual(featureDisabledResponse)
|
||||||
|
})
|
||||||
|
|
||||||
describe("no users exist", () => {
|
describe("no users exist", () => {
|
||||||
it("should retrieve empty list", async () => {
|
it("should retrieve empty list", async () => {
|
||||||
const response = await config.api.scimUsersAPI.get()
|
const response = await getScimUsers()
|
||||||
|
|
||||||
expect(response).toEqual({
|
expect(response).toEqual({
|
||||||
Resources: [],
|
Resources: [],
|
||||||
|
@ -52,8 +73,10 @@ describe("/api/global/scim/v2/users", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("POST /api/global/scim/v2/users", () => {
|
describe("POST /api/global/scim/v2/users", () => {
|
||||||
|
const postScimUser = config.api.scimUsersAPI.post
|
||||||
|
|
||||||
it("unauthorised calls are not allowed", async () => {
|
it("unauthorised calls are not allowed", async () => {
|
||||||
const response = await config.api.scimUsersAPI.post(
|
const response = await postScimUser(
|
||||||
{ body: {} as any },
|
{ body: {} as any },
|
||||||
{
|
{
|
||||||
setHeaders: false,
|
setHeaders: false,
|
||||||
|
@ -64,6 +87,13 @@ describe("/api/global/scim/v2/users", () => {
|
||||||
expect(response).toEqual({ message: "Tenant id not set", status: 403 })
|
expect(response).toEqual({ message: "Tenant id not set", status: 403 })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("cannot be called when feature is disabled", async () => {
|
||||||
|
mocks.licenses.useCloudFree()
|
||||||
|
const response = await postScimUser({ body: {} as any }, { expect: 400 })
|
||||||
|
|
||||||
|
expect(response).toEqual(featureDisabledResponse)
|
||||||
|
})
|
||||||
|
|
||||||
describe("no users exist", () => {
|
describe("no users exist", () => {
|
||||||
it("a new user can be created and persisted", async () => {
|
it("a new user can be created and persisted", async () => {
|
||||||
const userData = {
|
const userData = {
|
||||||
|
@ -98,7 +128,7 @@ describe("/api/global/scim/v2/users", () => {
|
||||||
roles: [],
|
roles: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await config.api.scimUsersAPI.post({ body })
|
const response = await postScimUser({ body })
|
||||||
|
|
||||||
const expectedScimUser = {
|
const expectedScimUser = {
|
||||||
schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
|
schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
|
||||||
|
|
Loading…
Reference in New Issue