Add scim tests

This commit is contained in:
Adria Navarro 2024-03-12 09:46:10 +01:00
parent b2000c0805
commit cd0004ec3d
3 changed files with 78 additions and 2 deletions

@ -1 +1 @@
Subproject commit e565db07f6c51868087e88dfebde0328493443e6
Subproject commit 7accd0cb0b21258e9085568143dbf885f9f87afe

View File

@ -103,6 +103,71 @@ describe("/api/global/groups", () => {
expect(events.group.updated).toBeCalledTimes(1)
expect(events.group.permissionsEdited).not.toBeCalled()
})
describe("scim", () => {
async function createScimGroup() {
mocks.licenses.useScimIntegration()
await config.setSCIMConfig(true)
const scimGroup = await config.api.scimGroupsAPI.post({
body: structures.scim.createGroupRequest({
displayName: generator.word(),
}),
})
const { body: group } = await config.api.groups.find(scimGroup.id)
expect(group).toBeDefined()
return group
}
it("update will not allow sending SCIM fields", async () => {
const group = await createScimGroup()
const updatedGroup: UserGroup = {
...group,
name: generator.word(),
}
await config.api.groups.saveGroup(updatedGroup, {
expect: {
message: 'Invalid body - "scimInfo" is not allowed',
status: 400,
},
})
expect(events.group.updated).not.toBeCalled()
})
it("update will not amend the SCIM fields", async () => {
const group: UserGroup = await createScimGroup()
const updatedGroup: UserGroup = {
...group,
name: generator.word(),
scimInfo: undefined,
}
await config.api.groups.saveGroup(updatedGroup, {
expect: 200,
})
expect(events.group.updated).toBeCalledTimes(1)
expect(
(
await config.api.groups.find(group._id!, {
expect: 200,
})
).body
).toEqual(
expect.objectContaining({
...group,
name: updatedGroup.name,
scimInfo: group.scimInfo,
_rev: expect.any(String),
})
)
})
})
})
describe("destroy", () => {

View File

@ -7,7 +7,10 @@ export class GroupsAPI extends TestAPI {
super(config)
}
saveGroup = (group: UserGroup, { expect } = { expect: 200 }) => {
saveGroup = (
group: UserGroup,
{ expect }: { expect: number | object } = { expect: 200 }
) => {
return this.request
.post(`/api/global/groups`)
.send(group)
@ -61,4 +64,12 @@ export class GroupsAPI extends TestAPI {
.expect("Content-Type", /json/)
.expect(expect)
}
find = (id: string, { expect } = { expect: 200 }) => {
return this.request
.get(`/api/global/groups/${id}`)
.set(this.config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(expect)
}
}