From f62647f284a7941e7e6e5992c49eaafd5dfead15 Mon Sep 17 00:00:00 2001 From: adrinr Date: Mon, 13 Mar 2023 16:34:08 +0100 Subject: [PATCH] Feature tests --- .../tests/utilities/mocks/licenses.ts | 4 ++ .../routes/global/tests/scim/users.spec.ts | 40 ++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/backend-core/tests/utilities/mocks/licenses.ts b/packages/backend-core/tests/utilities/mocks/licenses.ts index 2ca41616e4..85bf9c8a35 100644 --- a/packages/backend-core/tests/utilities/mocks/licenses.ts +++ b/packages/backend-core/tests/utilities/mocks/licenses.ts @@ -86,6 +86,10 @@ export const useAuditLogs = () => { return useFeature(Feature.AUDIT_LOGS) } +export const useScimIntegration = () => { + return useFeature(Feature.SCIM_INTEGRATION) +} + // QUOTAS export const setAutomationLogsQuota = (value: number) => { diff --git a/packages/worker/src/api/routes/global/tests/scim/users.spec.ts b/packages/worker/src/api/routes/global/tests/scim/users.spec.ts index e39f8fc94e..6d3e04213e 100644 --- a/packages/worker/src/api/routes/global/tests/scim/users.spec.ts +++ b/packages/worker/src/api/routes/global/tests/scim/users.spec.ts @@ -1,5 +1,5 @@ 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 { TestConfiguration } from "../../../../../tests" @@ -10,6 +10,8 @@ describe("/api/global/scim/v2/users", () => { tk.reset() mockedTime = new Date(structures.generator.timestamp()) tk.freeze(mockedTime) + + mocks.licenses.useScimIntegration() }) const config = new TestConfiguration() @@ -26,9 +28,21 @@ describe("/api/global/scim/v2/users", () => { 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", () => { + const getScimUsers = config.api.scimUsersAPI.get + it("unauthorised calls are not allowed", async () => { - const response = await config.api.scimUsersAPI.get({ + const response = await getScimUsers({ setHeaders: false, expect: 403, }) @@ -36,9 +50,16 @@ describe("/api/global/scim/v2/users", () => { 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", () => { it("should retrieve empty list", async () => { - const response = await config.api.scimUsersAPI.get() + const response = await getScimUsers() expect(response).toEqual({ Resources: [], @@ -52,8 +73,10 @@ describe("/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 () => { - const response = await config.api.scimUsersAPI.post( + const response = await postScimUser( { body: {} as any }, { setHeaders: false, @@ -64,6 +87,13 @@ describe("/api/global/scim/v2/users", () => { 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", () => { it("a new user can be created and persisted", async () => { const userData = { @@ -98,7 +128,7 @@ describe("/api/global/scim/v2/users", () => { roles: [], } - const response = await config.api.scimUsersAPI.post({ body }) + const response = await postScimUser({ body }) const expectedScimUser = { schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],