Test user groups
This commit is contained in:
parent
4cb6b99982
commit
efff31e181
|
@ -8,4 +8,5 @@ export * as plugins from "./plugins"
|
|||
export * as sso from "./sso"
|
||||
export * as tenant from "./tenants"
|
||||
export * as users from "./users"
|
||||
export * as userGroups from "./userGroups"
|
||||
export { generator } from "./generator"
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import { UserGroup } from "@budibase/types"
|
||||
import { generator } from "./generator"
|
||||
|
||||
export function userGroup(): UserGroup {
|
||||
return {
|
||||
name: generator.word(),
|
||||
icon: generator.word(),
|
||||
color: generator.word(),
|
||||
}
|
||||
}
|
|
@ -1,4 +1,7 @@
|
|||
import { db } from "@budibase/backend-core"
|
||||
import { db, roles } from "@budibase/backend-core"
|
||||
import { structures } from "@budibase/backend-core/tests"
|
||||
import { sdk as proSdk } from "@budibase/pro"
|
||||
|
||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||
import { rawUserMetadata, syncGlobalUsers } from "../utils"
|
||||
|
||||
|
@ -60,4 +63,38 @@ describe("syncGlobalUsers", () => {
|
|||
)
|
||||
})
|
||||
})
|
||||
|
||||
it("app users are removed when removed from the tenant", async () => {
|
||||
await config.doInTenant(async () => {
|
||||
const group = await proSdk.groups.save(structures.userGroups.userGroup())
|
||||
const user1 = await config.createUser({ admin: false, builder: false })
|
||||
const user2 = await config.createUser({ admin: false, builder: false })
|
||||
await proSdk.groups.addUsers(group.id, [user1._id, user2._id])
|
||||
|
||||
await config.doInContext(config.appId, async () => {
|
||||
await syncGlobalUsers()
|
||||
expect(await rawUserMetadata()).toHaveLength(1)
|
||||
|
||||
await proSdk.groups.updateGroupApps(group.id, {
|
||||
appsToAdd: [
|
||||
{ appId: config.prodAppId!, roleId: roles.BUILTIN_ROLE_IDS.BASIC },
|
||||
],
|
||||
})
|
||||
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),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue