Add delete test

This commit is contained in:
adrinr 2023-03-14 11:47:40 +01:00
parent 4f9b5a6aea
commit fbd53d5fd3
3 changed files with 54 additions and 4 deletions

View File

@ -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 const patchScimUser = config.api.scimUsersAPI.patch
let user: ScimUserResponse let user: ScimUserResponse
@ -297,4 +297,40 @@ describe("/api/global/scim/v2/users", () => {
expect(persistedUser).toEqual(expectedScimUser) 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 })
})
})
}) })

View File

@ -6,6 +6,7 @@ export const initPro = async () => {
scimUserServiceConfig: { scimUserServiceConfig: {
functions: { functions: {
saveUser: userSdk.save, saveUser: userSdk.save,
removeUser: (id: string) => userSdk.destroy(id, undefined),
}, },
}, },
}) })

View File

@ -21,15 +21,19 @@ export class ScimUsersAPI extends TestAPI {
#createRequest = ( #createRequest = (
url: string, url: string,
method: "get" | "post" | "patch", method: "get" | "post" | "patch" | "delete",
requestSettings?: Partial<RequestSettings>, requestSettings?: Partial<RequestSettings>,
body?: object body?: object
) => { ) => {
const { expect, setHeaders } = { ...defaultConfig, ...requestSettings } const { expect, setHeaders } = { ...defaultConfig, ...requestSettings }
let request = this.request[method](url) let request =
.expect("Content-Type", /json/) this.request[method](url)
.expect(expect) .expect(expect)
if (method !== "delete") {
request = request.expect("Content-Type", /json/)
}
if (body) { if (body) {
request = request.send(body) request = request.send(body)
} }
@ -115,4 +119,13 @@ export class ScimUsersAPI extends TestAPI {
return res.body as ScimUser 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
}
} }