From baca156a174b84ceacc09a34ea97f7f39ae705d6 Mon Sep 17 00:00:00 2001 From: adrinr Date: Fri, 17 Mar 2023 12:23:24 +0100 Subject: [PATCH] Implement delete endpoint --- .../routes/global/tests/scim/groups.spec.ts | 40 +++++++++++++++++++ packages/worker/src/tests/api/scim/groups.ts | 9 +++++ 2 files changed, 49 insertions(+) diff --git a/packages/worker/src/api/routes/global/tests/scim/groups.spec.ts b/packages/worker/src/api/routes/global/tests/scim/groups.spec.ts index f2d13cbc7c..4076ab3477 100644 --- a/packages/worker/src/api/routes/global/tests/scim/groups.spec.ts +++ b/packages/worker/src/api/routes/global/tests/scim/groups.spec.ts @@ -222,4 +222,44 @@ describe("/api/global/scim/v2/groups", () => { }) }) }) + + describe("DELETE /api/global/scim/v2/groups/:id", () => { + const deleteScimGroup = config.api.scimGroupsAPI.delete + + let group: ScimGroupResponse + + beforeEach(async () => { + const body = createScimCreateGroupRequest() + + group = await config.api.scimGroupsAPI.post({ body }) + }) + + it("unauthorised calls are not allowed", async () => { + const response = await deleteScimGroup(group.id, { + setHeaders: false, + expect: 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 deleteScimGroup(group.id, { expect: 400 }) + + expect(response).toEqual(featureDisabledResponse) + }) + + it("an existing group can be deleted", async () => { + const response = await deleteScimGroup(group.id, { expect: 204 }) + + expect(response).toEqual({}) + + await config.api.scimGroupsAPI.find(group.id, { expect: 404 }) + }) + + it("an non existing group can not be deleted", async () => { + await deleteScimGroup(structures.uuid(), { expect: 404 }) + }) + }) }) diff --git a/packages/worker/src/tests/api/scim/groups.ts b/packages/worker/src/tests/api/scim/groups.ts index 7f3bc4803b..413e85b96a 100644 --- a/packages/worker/src/tests/api/scim/groups.ts +++ b/packages/worker/src/tests/api/scim/groups.ts @@ -61,4 +61,13 @@ export class ScimGroupsAPI extends ScimTestAPI { ) return res.body as ScimGroupResponse } + + delete = async (id: string, requestSettings?: Partial) => { + const res = await this.call( + `/api/global/scim/v2/groups/${id}`, + "delete", + requestSettings + ) + return res.body as ScimGroupResponse + } }