From b368c143087a8d8068212cd2368c001eeb3be023 Mon Sep 17 00:00:00 2001 From: adrinr Date: Wed, 29 Mar 2023 16:18:32 +0100 Subject: [PATCH] Add unit tests to test new users --- .../server/src/sdk/users/tests/utils.spec.ts | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 packages/server/src/sdk/users/tests/utils.spec.ts diff --git a/packages/server/src/sdk/users/tests/utils.spec.ts b/packages/server/src/sdk/users/tests/utils.spec.ts new file mode 100644 index 0000000000..3178978c46 --- /dev/null +++ b/packages/server/src/sdk/users/tests/utils.spec.ts @@ -0,0 +1,49 @@ +import { db } from "@budibase/backend-core" +import TestConfiguration from "../../../tests/utilities/TestConfiguration" +import { rawUserMetadata, syncGlobalUsers } from "../utils" + +describe("syncGlobalUsers", () => { + const config = new TestConfiguration() + + beforeAll(async () => { + await config.init() + }) + + afterAll(config.end) + + it("the default user is synced", async () => { + await config.doInContext(config.appId, async () => { + await syncGlobalUsers() + + const metadata = await rawUserMetadata() + expect(metadata).toHaveLength(1) + expect(metadata).toEqual([ + expect.objectContaining({ + _id: db.generateUserMetadataID(config.user._id), + }), + ]) + }) + }) + + it("app users are synced", async () => { + await config.doInContext(config.appId, async () => { + const user1 = await config.createUser() + const user2 = await config.createUser() + + await syncGlobalUsers() + + const metadata = await rawUserMetadata() + expect(metadata).toHaveLength(3) + expect(metadata).toContainEqual( + expect.objectContaining({ + _id: db.generateUserMetadataID(user1._id), + }) + ) + expect(metadata).toContainEqual( + expect.objectContaining({ + _id: db.generateUserMetadataID(user2._id), + }) + ) + }) + }) +})