Add scim group api test tools
This commit is contained in:
parent
fd0c88afac
commit
8196277a01
|
@ -16,6 +16,7 @@ import { TemplatesAPI } from "./templates"
|
|||
import { LicenseAPI } from "./license"
|
||||
import { AuditLogAPI } from "./auditLogs"
|
||||
import { ScimUsersAPI } from "./scim/users"
|
||||
import { ScimGroupsAPI } from "./scim/groups"
|
||||
|
||||
export default class API {
|
||||
accounts: AccountAPI
|
||||
|
@ -35,6 +36,7 @@ export default class API {
|
|||
license: LicenseAPI
|
||||
auditLogs: AuditLogAPI
|
||||
scimUsersAPI: ScimUsersAPI
|
||||
scimGroupsAPI: ScimGroupsAPI
|
||||
|
||||
constructor(config: TestConfiguration) {
|
||||
this.accounts = new AccountAPI(config)
|
||||
|
@ -54,5 +56,6 @@ export default class API {
|
|||
this.license = new LicenseAPI(config)
|
||||
this.auditLogs = new AuditLogAPI(config)
|
||||
this.scimUsersAPI = new ScimUsersAPI(config)
|
||||
this.scimGroupsAPI = new ScimGroupsAPI(config)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
import {
|
||||
ScimCreateGroupRequest,
|
||||
ScimGroupListResponse,
|
||||
ScimGroupResponse,
|
||||
} from "@budibase/types"
|
||||
import TestConfiguration from "../../TestConfiguration"
|
||||
import { RequestSettings, ScimTestAPI } from "./shared"
|
||||
|
||||
export class ScimGroupsAPI extends ScimTestAPI {
|
||||
constructor(config: TestConfiguration) {
|
||||
super(config)
|
||||
}
|
||||
|
||||
get = async (
|
||||
requestSettings?: Partial<RequestSettings> & {
|
||||
params?: {
|
||||
startIndex?: number
|
||||
pageSize?: number
|
||||
filter?: string
|
||||
}
|
||||
}
|
||||
) => {
|
||||
let url = `/api/global/scim/v2/groups?`
|
||||
const params = requestSettings?.params
|
||||
if (params?.pageSize) {
|
||||
url += `count=${params.pageSize}&`
|
||||
}
|
||||
if (params?.startIndex) {
|
||||
url += `startIndex=${params.startIndex}&`
|
||||
}
|
||||
if (params?.filter) {
|
||||
url += `filter=${params.filter}&`
|
||||
}
|
||||
const res = await this.call(url, "get", requestSettings)
|
||||
return res.body as ScimGroupListResponse
|
||||
}
|
||||
|
||||
post = async (
|
||||
{
|
||||
body,
|
||||
}: {
|
||||
body: ScimCreateGroupRequest
|
||||
},
|
||||
requestSettings?: Partial<RequestSettings>
|
||||
) => {
|
||||
const res = await this.call(
|
||||
`/api/global/scim/v2/groups`,
|
||||
"post",
|
||||
requestSettings,
|
||||
body
|
||||
)
|
||||
|
||||
return res.body as ScimGroupResponse
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
import TestConfiguration from "../../TestConfiguration"
|
||||
import { TestAPI } from "../base"
|
||||
|
||||
const defaultConfig = {
|
||||
expect: 200,
|
||||
setHeaders: true,
|
||||
}
|
||||
|
||||
export type RequestSettings = typeof defaultConfig
|
||||
|
||||
export abstract class ScimTestAPI extends TestAPI {
|
||||
constructor(config: TestConfiguration) {
|
||||
super(config)
|
||||
}
|
||||
|
||||
call = (
|
||||
url: string,
|
||||
method: "get" | "post" | "patch" | "delete",
|
||||
requestSettings?: Partial<RequestSettings>,
|
||||
body?: object
|
||||
) => {
|
||||
const { expect, setHeaders } = { ...defaultConfig, ...requestSettings }
|
||||
let request = this.request[method](url).expect(expect)
|
||||
|
||||
request = request.set(
|
||||
"content-type",
|
||||
"application/scim+json; charset=utf-8"
|
||||
)
|
||||
|
||||
if (method !== "delete") {
|
||||
request = request.expect("Content-Type", /json/)
|
||||
}
|
||||
|
||||
if (body) {
|
||||
request = request.send(body)
|
||||
}
|
||||
|
||||
if (setHeaders) {
|
||||
request = request.set(this.config.bearerAPIHeaders())
|
||||
}
|
||||
return request
|
||||
}
|
||||
}
|
|
@ -5,48 +5,13 @@ import {
|
|||
ScimUpdateRequest,
|
||||
} from "@budibase/types"
|
||||
import TestConfiguration from "../../TestConfiguration"
|
||||
import { TestAPI } from "../base"
|
||||
import { RequestSettings, ScimTestAPI } from "./shared"
|
||||
|
||||
const defaultConfig = {
|
||||
expect: 200,
|
||||
setHeaders: true,
|
||||
}
|
||||
|
||||
type RequestSettings = typeof defaultConfig
|
||||
|
||||
export class ScimUsersAPI extends TestAPI {
|
||||
export class ScimUsersAPI extends ScimTestAPI {
|
||||
constructor(config: TestConfiguration) {
|
||||
super(config)
|
||||
}
|
||||
|
||||
#createRequest = (
|
||||
url: string,
|
||||
method: "get" | "post" | "patch" | "delete",
|
||||
requestSettings?: Partial<RequestSettings>,
|
||||
body?: object
|
||||
) => {
|
||||
const { expect, setHeaders } = { ...defaultConfig, ...requestSettings }
|
||||
let request = this.request[method](url).expect(expect)
|
||||
|
||||
request = request.set(
|
||||
"content-type",
|
||||
"application/scim+json; charset=utf-8"
|
||||
)
|
||||
|
||||
if (method !== "delete") {
|
||||
request = request.expect("Content-Type", /json/)
|
||||
}
|
||||
|
||||
if (body) {
|
||||
request = request.send(body)
|
||||
}
|
||||
|
||||
if (setHeaders) {
|
||||
request = request.set(this.config.bearerAPIHeaders())
|
||||
}
|
||||
return request
|
||||
}
|
||||
|
||||
get = async (
|
||||
requestSettings?: Partial<RequestSettings> & {
|
||||
params?: {
|
||||
|
@ -67,12 +32,12 @@ export class ScimUsersAPI extends TestAPI {
|
|||
if (params?.filter) {
|
||||
url += `filter=${params.filter}&`
|
||||
}
|
||||
const res = await this.#createRequest(url, "get", requestSettings)
|
||||
const res = await this.call(url, "get", requestSettings)
|
||||
return res.body as ScimUserListResponse
|
||||
}
|
||||
|
||||
find = async (id: string, requestSettings?: Partial<RequestSettings>) => {
|
||||
const res = await this.#createRequest(
|
||||
const res = await this.call(
|
||||
`/api/global/scim/v2/users/${id}`,
|
||||
"get",
|
||||
requestSettings
|
||||
|
@ -88,7 +53,7 @@ export class ScimUsersAPI extends TestAPI {
|
|||
},
|
||||
requestSettings?: Partial<RequestSettings>
|
||||
) => {
|
||||
const res = await this.#createRequest(
|
||||
const res = await this.call(
|
||||
`/api/global/scim/v2/users`,
|
||||
"post",
|
||||
requestSettings,
|
||||
|
@ -108,7 +73,7 @@ export class ScimUsersAPI extends TestAPI {
|
|||
},
|
||||
requestSettings?: Partial<RequestSettings>
|
||||
) => {
|
||||
const res = await this.#createRequest(
|
||||
const res = await this.call(
|
||||
`/api/global/scim/v2/users/${id}`,
|
||||
"patch",
|
||||
requestSettings,
|
||||
|
@ -119,7 +84,7 @@ export class ScimUsersAPI extends TestAPI {
|
|||
}
|
||||
|
||||
delete = async (id: string, requestSettings?: Partial<RequestSettings>) => {
|
||||
const res = await this.#createRequest(
|
||||
const res = await this.call(
|
||||
`/api/global/scim/v2/users/${id}`,
|
||||
"delete",
|
||||
requestSettings
|
||||
|
|
Loading…
Reference in New Issue