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 { LicenseAPI } from "./license"
|
||||||
import { AuditLogAPI } from "./auditLogs"
|
import { AuditLogAPI } from "./auditLogs"
|
||||||
import { ScimUsersAPI } from "./scim/users"
|
import { ScimUsersAPI } from "./scim/users"
|
||||||
|
import { ScimGroupsAPI } from "./scim/groups"
|
||||||
|
|
||||||
export default class API {
|
export default class API {
|
||||||
accounts: AccountAPI
|
accounts: AccountAPI
|
||||||
|
@ -35,6 +36,7 @@ export default class API {
|
||||||
license: LicenseAPI
|
license: LicenseAPI
|
||||||
auditLogs: AuditLogAPI
|
auditLogs: AuditLogAPI
|
||||||
scimUsersAPI: ScimUsersAPI
|
scimUsersAPI: ScimUsersAPI
|
||||||
|
scimGroupsAPI: ScimGroupsAPI
|
||||||
|
|
||||||
constructor(config: TestConfiguration) {
|
constructor(config: TestConfiguration) {
|
||||||
this.accounts = new AccountAPI(config)
|
this.accounts = new AccountAPI(config)
|
||||||
|
@ -54,5 +56,6 @@ export default class API {
|
||||||
this.license = new LicenseAPI(config)
|
this.license = new LicenseAPI(config)
|
||||||
this.auditLogs = new AuditLogAPI(config)
|
this.auditLogs = new AuditLogAPI(config)
|
||||||
this.scimUsersAPI = new ScimUsersAPI(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,
|
ScimUpdateRequest,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import TestConfiguration from "../../TestConfiguration"
|
import TestConfiguration from "../../TestConfiguration"
|
||||||
import { TestAPI } from "../base"
|
import { RequestSettings, ScimTestAPI } from "./shared"
|
||||||
|
|
||||||
const defaultConfig = {
|
export class ScimUsersAPI extends ScimTestAPI {
|
||||||
expect: 200,
|
|
||||||
setHeaders: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
type RequestSettings = typeof defaultConfig
|
|
||||||
|
|
||||||
export class ScimUsersAPI extends TestAPI {
|
|
||||||
constructor(config: TestConfiguration) {
|
constructor(config: TestConfiguration) {
|
||||||
super(config)
|
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 (
|
get = async (
|
||||||
requestSettings?: Partial<RequestSettings> & {
|
requestSettings?: Partial<RequestSettings> & {
|
||||||
params?: {
|
params?: {
|
||||||
|
@ -67,12 +32,12 @@ export class ScimUsersAPI extends TestAPI {
|
||||||
if (params?.filter) {
|
if (params?.filter) {
|
||||||
url += `filter=${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
|
return res.body as ScimUserListResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
find = async (id: string, requestSettings?: Partial<RequestSettings>) => {
|
find = async (id: string, requestSettings?: Partial<RequestSettings>) => {
|
||||||
const res = await this.#createRequest(
|
const res = await this.call(
|
||||||
`/api/global/scim/v2/users/${id}`,
|
`/api/global/scim/v2/users/${id}`,
|
||||||
"get",
|
"get",
|
||||||
requestSettings
|
requestSettings
|
||||||
|
@ -88,7 +53,7 @@ export class ScimUsersAPI extends TestAPI {
|
||||||
},
|
},
|
||||||
requestSettings?: Partial<RequestSettings>
|
requestSettings?: Partial<RequestSettings>
|
||||||
) => {
|
) => {
|
||||||
const res = await this.#createRequest(
|
const res = await this.call(
|
||||||
`/api/global/scim/v2/users`,
|
`/api/global/scim/v2/users`,
|
||||||
"post",
|
"post",
|
||||||
requestSettings,
|
requestSettings,
|
||||||
|
@ -108,7 +73,7 @@ export class ScimUsersAPI extends TestAPI {
|
||||||
},
|
},
|
||||||
requestSettings?: Partial<RequestSettings>
|
requestSettings?: Partial<RequestSettings>
|
||||||
) => {
|
) => {
|
||||||
const res = await this.#createRequest(
|
const res = await this.call(
|
||||||
`/api/global/scim/v2/users/${id}`,
|
`/api/global/scim/v2/users/${id}`,
|
||||||
"patch",
|
"patch",
|
||||||
requestSettings,
|
requestSettings,
|
||||||
|
@ -119,7 +84,7 @@ export class ScimUsersAPI extends TestAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
delete = async (id: string, requestSettings?: Partial<RequestSettings>) => {
|
delete = async (id: string, requestSettings?: Partial<RequestSettings>) => {
|
||||||
const res = await this.#createRequest(
|
const res = await this.call(
|
||||||
`/api/global/scim/v2/users/${id}`,
|
`/api/global/scim/v2/users/${id}`,
|
||||||
"delete",
|
"delete",
|
||||||
requestSettings
|
requestSettings
|
||||||
|
|
Loading…
Reference in New Issue