1
0
Fork 0
mirror of synced 2024-10-04 03:54:37 +13:00

Patch endpoint

This commit is contained in:
adrinr 2023-03-13 17:24:36 +01:00
parent 7c719df895
commit 3500aabc8a
2 changed files with 75 additions and 1 deletions

View file

@ -226,4 +226,58 @@ describe("/api/global/scim/v2/users", () => {
})
})
})
describe("PATCH /api/global/scim/v2/users", () => {
const patchScimUser = config.api.scimUsersAPI.patch
let user: ScimUser
beforeEach(async () => {
const body = createScimCreateUserRequest()
user = await config.api.scimUsersAPI.post({ body })
})
it("unauthorised calls are not allowed", async () => {
const response = await patchScimUser({} as any, {
setHeaders: false,
expect: 403,
})
expect(response).toEqual({ message: "Tenant id not set", status: 403 })
})
it("cannot be called when feature is disabled", async () => {
mocks.licenses.useCloudFree()
const response = await patchScimUser({} as any, { expect: 400 })
expect(response).toEqual(featureDisabledResponse)
})
it("an existing user can be updated", async () => {
const body: ScimUpdateRequest = {
schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
Operations: [
{
op: "add",
path: "string",
value: "string",
},
],
}
const response = await patchScimUser({ id: user.id, body })
const expectedScimUser = { ...user }
expect(response).toEqual(expectedScimUser)
const persistedUsers = await config.api.scimUsersAPI.get()
expect(persistedUsers).toEqual(
expect.objectContaining({
totalResults: 1,
Resources: [expectedScimUser],
})
)
})
})
})

View file

@ -20,7 +20,7 @@ export class ScimUsersAPI extends TestAPI {
#createRequest = (
url: string,
method: "get" | "post",
method: "get" | "post" | "patch",
requestSettings?: Partial<RequestSettings>,
body?: object
) => {
@ -83,4 +83,24 @@ export class ScimUsersAPI extends TestAPI {
return res.body as ScimUserResponse
}
patch = async (
{
id,
body,
}: {
id: string
body: ScimUpdateRequest
},
requestSettings?: Partial<RequestSettings>
) => {
const res = await this.#createRequest(
`/api/global/scim/v2/users/${id}`,
"patch",
requestSettings,
body
)
return res.body as ScimUser
}
}