Improve test helpers
This commit is contained in:
parent
b120fce5dd
commit
7fef377e1d
|
@ -6,18 +6,48 @@ import {
|
||||||
import TestConfiguration from "../../TestConfiguration"
|
import TestConfiguration from "../../TestConfiguration"
|
||||||
import { TestAPI } from "../base"
|
import { TestAPI } from "../base"
|
||||||
|
|
||||||
|
export interface RequestSettings {
|
||||||
|
expect: number
|
||||||
|
setHeaders: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultConfig: RequestSettings = {
|
||||||
|
expect: 200,
|
||||||
|
setHeaders: true,
|
||||||
|
}
|
||||||
|
|
||||||
export class ScimUsersAPI extends TestAPI {
|
export class ScimUsersAPI extends TestAPI {
|
||||||
constructor(config: TestConfiguration) {
|
constructor(config: TestConfiguration) {
|
||||||
super(config)
|
super(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
get = async (expect = 200) => {
|
#createRequest = (
|
||||||
const res = await this.request
|
url: string,
|
||||||
.get(`/api/global/scim/v2/users`)
|
method: "get" | "post",
|
||||||
.set(this.config.bearerAPIHeaders())
|
requestSettings?: Partial<RequestSettings>,
|
||||||
|
body?: object
|
||||||
|
) => {
|
||||||
|
const { expect, setHeaders } = { ...defaultConfig, ...requestSettings }
|
||||||
|
let request = this.request[method](url)
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(expect)
|
.expect(expect)
|
||||||
|
|
||||||
|
if (body) {
|
||||||
|
request = request.send(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setHeaders) {
|
||||||
|
request = request.set(this.config.bearerAPIHeaders())
|
||||||
|
}
|
||||||
|
return request
|
||||||
|
}
|
||||||
|
|
||||||
|
get = async (requestSettings?: Partial<RequestSettings>) => {
|
||||||
|
const res = await this.#createRequest(
|
||||||
|
`/api/global/scim/v2/users`,
|
||||||
|
"get",
|
||||||
|
requestSettings
|
||||||
|
)
|
||||||
return res.body as ScimListResponse
|
return res.body as ScimListResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,14 +57,14 @@ export class ScimUsersAPI extends TestAPI {
|
||||||
}: {
|
}: {
|
||||||
body: ScimUserRequest
|
body: ScimUserRequest
|
||||||
},
|
},
|
||||||
expect = 200
|
requestSettings?: Partial<RequestSettings>
|
||||||
) => {
|
) => {
|
||||||
const res = await this.request
|
const res = await this.#createRequest(
|
||||||
.post(`/api/global/scim/v2/users`)
|
`/api/global/scim/v2/users`,
|
||||||
.send(body)
|
"post",
|
||||||
.set(this.config.bearerAPIHeaders())
|
requestSettings,
|
||||||
.expect("Content-Type", /json/)
|
body
|
||||||
.expect(expect)
|
)
|
||||||
|
|
||||||
return res.body as ScimListResponse
|
return res.body as ScimListResponse
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue