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

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
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 })
})
})
})

View file

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

View file

@ -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
}
}