Add delete test
This commit is contained in:
parent
4f9b5a6aea
commit
fbd53d5fd3
|
@ -234,7 +234,7 @@ describe("/api/global/scim/v2/users", () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe("PATCH /api/global/scim/v2/users", () => {
|
||||
describe("PATCH /api/global/scim/v2/users/:id", () => {
|
||||
const patchScimUser = config.api.scimUsersAPI.patch
|
||||
|
||||
let user: ScimUserResponse
|
||||
|
@ -297,4 +297,40 @@ describe("/api/global/scim/v2/users", () => {
|
|||
expect(persistedUser).toEqual(expectedScimUser)
|
||||
})
|
||||
})
|
||||
|
||||
describe("DELETE /api/global/scim/v2/users/:id", () => {
|
||||
const deleteScimUser = config.api.scimUsersAPI.delete
|
||||
|
||||
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 deleteScimUser({} 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 deleteScimUser({} as any, { expect: 400 })
|
||||
|
||||
expect(response).toEqual(featureDisabledResponse)
|
||||
})
|
||||
|
||||
it("an existing user can be deleted", async () => {
|
||||
const response = await deleteScimUser(user.id, { expect: 204 })
|
||||
|
||||
expect(response).toEqual({})
|
||||
|
||||
await config.api.scimUsersAPI.find(user.id, { expect: 404 })
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -6,6 +6,7 @@ export const initPro = async () => {
|
|||
scimUserServiceConfig: {
|
||||
functions: {
|
||||
saveUser: userSdk.save,
|
||||
removeUser: (id: string) => userSdk.destroy(id, undefined),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
@ -21,15 +21,19 @@ export class ScimUsersAPI extends TestAPI {
|
|||
|
||||
#createRequest = (
|
||||
url: string,
|
||||
method: "get" | "post" | "patch",
|
||||
method: "get" | "post" | "patch" | "delete",
|
||||
requestSettings?: Partial<RequestSettings>,
|
||||
body?: object
|
||||
) => {
|
||||
const { expect, setHeaders } = { ...defaultConfig, ...requestSettings }
|
||||
let request = this.request[method](url)
|
||||
.expect("Content-Type", /json/)
|
||||
let request =
|
||||
this.request[method](url)
|
||||
.expect(expect)
|
||||
|
||||
if (method !== "delete") {
|
||||
request = request.expect("Content-Type", /json/)
|
||||
}
|
||||
|
||||
if (body) {
|
||||
request = request.send(body)
|
||||
}
|
||||
|
@ -115,4 +119,13 @@ export class ScimUsersAPI extends TestAPI {
|
|||
|
||||
return res.body as ScimUser
|
||||
}
|
||||
|
||||
delete = async (id: string, requestSettings?: Partial<RequestSettings>) => {
|
||||
const res = await this.#createRequest(
|
||||
`/api/global/scim/v2/users/${id}`,
|
||||
"delete",
|
||||
requestSettings
|
||||
)
|
||||
return res.body as ScimUser
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue