From b120fce5dda80323b0f05d69199ec6258c98690e Mon Sep 17 00:00:00 2001 From: adrinr Date: Fri, 10 Mar 2023 11:19:22 +0100 Subject: [PATCH] Add tests --- .../routes/global/tests/scim/users.spec.ts | 35 +++++++++++++++++++ packages/worker/src/tests/api/scim/users.ts | 26 ++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) 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 21bef3d5a5..4321d56051 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 @@ -38,4 +38,39 @@ describe("/api/global/scim/v2/users", () => { }) }) }) + + describe("POST /api/global/scim/v2/users", () => { + describe("no users exist", () => { + it("should retrieve empty list", async () => { + const body = {} as any + const response = await config.api.scimUsersAPI.post(body) + + expect(response).toEqual({ + schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"], + id: "48af03ac28ad4fb88478", + externalId: "0a21f0f2-8d2a-4f8e-bf98-7363c4aed4ef", + meta: { + resourceType: "User", + created: "2018-03-27T19:59:26.000Z", + lastModified: "2018-03-27T19:59:26.000Z", + }, + userName: "Test_User_ab6490ee-1e48-479e-a20b-2d77186b5dd1", + name: { + formatted: "givenName familyName", + familyName: "familyName", + givenName: "givenName", + }, + active: true, + emails: [ + { + value: + "Test_User_fd0ea19b-0777-472c-9f96-4f70d2226f2e@testuser.com", + type: "work", + primary: true, + }, + ], + }) + }) + }) + }) }) diff --git a/packages/worker/src/tests/api/scim/users.ts b/packages/worker/src/tests/api/scim/users.ts index fd0a99b671..935467ac8c 100644 --- a/packages/worker/src/tests/api/scim/users.ts +++ b/packages/worker/src/tests/api/scim/users.ts @@ -1,4 +1,8 @@ -import { AccountMetadata, ScimListResponse } from "@budibase/types" +import { + AccountMetadata, + ScimListResponse, + ScimUserRequest, +} from "@budibase/types" import TestConfiguration from "../../TestConfiguration" import { TestAPI } from "../base" @@ -7,7 +11,7 @@ export class ScimUsersAPI extends TestAPI { super(config) } - get = async ({ expect }: { expect: number } = { expect: 200 }) => { + get = async (expect = 200) => { const res = await this.request .get(`/api/global/scim/v2/users`) .set(this.config.bearerAPIHeaders()) @@ -16,4 +20,22 @@ export class ScimUsersAPI extends TestAPI { return res.body as ScimListResponse } + + post = async ( + { + body, + }: { + body: ScimUserRequest + }, + expect = 200 + ) => { + const res = await this.request + .post(`/api/global/scim/v2/users`) + .send(body) + .set(this.config.bearerAPIHeaders()) + .expect("Content-Type", /json/) + .expect(expect) + + return res.body as ScimListResponse + } }