Add unit tests to test new users

This commit is contained in:
adrinr 2023-03-29 16:18:32 +01:00
parent e25429632b
commit b368c14308
1 changed files with 49 additions and 0 deletions

View File

@ -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),
})
)
})
})
})