Add User endpoints
This commit is contained in:
parent
d3679a598c
commit
b3dea56363
|
@ -4,6 +4,7 @@ import InternalAPIClient from "./InternalAPIClient"
|
||||||
import TablesApi from "./tables"
|
import TablesApi from "./tables"
|
||||||
import RowApi from "./rows"
|
import RowApi from "./rows"
|
||||||
import ScreenApi from "./screens"
|
import ScreenApi from "./screens"
|
||||||
|
import UserManagementApi from "./userManagement"
|
||||||
|
|
||||||
export default class TestConfiguration<T> {
|
export default class TestConfiguration<T> {
|
||||||
applications: ApplicationApi
|
applications: ApplicationApi
|
||||||
|
@ -12,6 +13,7 @@ export default class TestConfiguration<T> {
|
||||||
context: T
|
context: T
|
||||||
tables: TablesApi
|
tables: TablesApi
|
||||||
rows: RowApi
|
rows: RowApi
|
||||||
|
userManagement: UserManagementApi
|
||||||
|
|
||||||
constructor(apiClient: InternalAPIClient) {
|
constructor(apiClient: InternalAPIClient) {
|
||||||
this.applications = new ApplicationApi(apiClient)
|
this.applications = new ApplicationApi(apiClient)
|
||||||
|
@ -19,6 +21,7 @@ export default class TestConfiguration<T> {
|
||||||
this.rows = new RowApi(apiClient)
|
this.rows = new RowApi(apiClient)
|
||||||
this.auth = new AuthApi(apiClient)
|
this.auth = new AuthApi(apiClient)
|
||||||
this.screen = new ScreenApi(apiClient)
|
this.screen = new ScreenApi(apiClient)
|
||||||
|
this.userManagement = new UserManagementApi(apiClient)
|
||||||
this.context = <T>{}
|
this.context = <T>{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
import { Response } from "node-fetch"
|
||||||
|
import { User } from "@budibase/types"
|
||||||
|
import InternalAPIClient from "./InternalAPIClient"
|
||||||
|
import { responseMessage } from "../fixtures/types/responseMessage"
|
||||||
|
|
||||||
|
export default class UserManagementApi {
|
||||||
|
api: InternalAPIClient
|
||||||
|
|
||||||
|
constructor(apiClient: InternalAPIClient) {
|
||||||
|
this.api = apiClient
|
||||||
|
}
|
||||||
|
|
||||||
|
async searchUsers(): Promise<[Response, User[]]> {
|
||||||
|
const response = await this.api.post(`/global/users/search`, {})
|
||||||
|
const json = await response.json()
|
||||||
|
expect(response).toHaveStatusCode(200)
|
||||||
|
expect(json.length).toBeGreaterThan(0)
|
||||||
|
return [response, json]
|
||||||
|
}
|
||||||
|
|
||||||
|
async getSelf(): Promise<[Response, User]> {
|
||||||
|
const response = await this.api.get(`/global/self`)
|
||||||
|
const json = await response.json()
|
||||||
|
expect(response).toHaveStatusCode(200)
|
||||||
|
return [response, json]
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAllUsers(): Promise<[Response, User]> {
|
||||||
|
const response = await this.api.get(`/global/users`)
|
||||||
|
const json = await response.json()
|
||||||
|
expect(response).toHaveStatusCode(200)
|
||||||
|
return [response, json]
|
||||||
|
}
|
||||||
|
|
||||||
|
async inviteUsers(body: User[]): Promise<[Response, responseMessage]> {
|
||||||
|
const response = await this.api.post(`/global/users/multi/invite`, { body })
|
||||||
|
const json = await response.json()
|
||||||
|
expect(response).toHaveStatusCode(200)
|
||||||
|
expect(json.successful.length).toEqual(body.length)
|
||||||
|
expect(json.unsuccessful.length).toEqual(0)
|
||||||
|
return [response, json]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
import generator from "../../generator";
|
||||||
|
|
||||||
|
const randomId = generator.guid;
|
||||||
|
export const generateDeveloper = (): any => ({
|
||||||
|
create: {
|
||||||
|
users: [{
|
||||||
|
email: `pedro+${randomId()}@budibase.com`,
|
||||||
|
password: randomId,
|
||||||
|
roles: {},
|
||||||
|
forceResetPassword: true,
|
||||||
|
builder: {
|
||||||
|
global: true
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
groups: []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const generateAdmin = (): any => ({
|
||||||
|
create: {
|
||||||
|
users: [{
|
||||||
|
email: `pedro+${randomId()}@budibase.com`,
|
||||||
|
password: randomId,
|
||||||
|
roles: {},
|
||||||
|
forceResetPassword: true,
|
||||||
|
admin: {
|
||||||
|
global: true
|
||||||
|
},
|
||||||
|
builder: {
|
||||||
|
global: true
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
groups: []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
export const generateAppUser = (): any => ({
|
||||||
|
create: {
|
||||||
|
users: [{
|
||||||
|
email: `pedro+${randomId()}@budibase.com`,
|
||||||
|
password: randomId,
|
||||||
|
roles: {},
|
||||||
|
forceResetPassword: true,
|
||||||
|
admin: {
|
||||||
|
global: false
|
||||||
|
},
|
||||||
|
builder: {
|
||||||
|
global: false
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
groups: []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const generateInviteUser = (): any => (
|
||||||
|
[{
|
||||||
|
email: `pedro+${randomId()}@budibase.com`,
|
||||||
|
userInfo: {
|
||||||
|
admin: {
|
||||||
|
global: true
|
||||||
|
},
|
||||||
|
builder: {
|
||||||
|
global: true
|
||||||
|
},
|
||||||
|
userGroups: []
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
)
|
|
@ -0,0 +1,24 @@
|
||||||
|
import TestConfiguration from "../../../config/internal-api/TestConfiguration"
|
||||||
|
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
||||||
|
import { db } from "@budibase/backend-core"
|
||||||
|
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
||||||
|
import generateApp from "../../../config/internal-api/fixtures/applications"
|
||||||
|
import generator from "../../../config/generator"
|
||||||
|
import generateScreen from "../../../config/internal-api/fixtures/screens"
|
||||||
|
|
||||||
|
describe("Internal API - User Management", () => {
|
||||||
|
const api = new InternalAPIClient()
|
||||||
|
const config = new TestConfiguration<Application>(api)
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await config.beforeAll()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await config.afterAll()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Get all users", async () => {
|
||||||
|
await config.userManagement.searchUsers()
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue