Add User endpoints

This commit is contained in:
Pedro Silva 2022-11-22 16:52:56 +00:00
parent 3dbea26407
commit cb2b861032
4 changed files with 137 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import InternalAPIClient from "./InternalAPIClient"
import TablesApi from "./tables"
import RowApi from "./rows"
import ScreenApi from "./screens"
import UserManagementApi from "./userManagement"
export default class TestConfiguration<T> {
applications: ApplicationApi
@ -12,6 +13,7 @@ export default class TestConfiguration<T> {
context: T
tables: TablesApi
rows: RowApi
userManagement: UserManagementApi
constructor(apiClient: InternalAPIClient) {
this.applications = new ApplicationApi(apiClient)
@ -19,6 +21,7 @@ export default class TestConfiguration<T> {
this.rows = new RowApi(apiClient)
this.auth = new AuthApi(apiClient)
this.screen = new ScreenApi(apiClient)
this.userManagement = new UserManagementApi(apiClient)
this.context = <T>{}
}

View File

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

View File

@ -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: []
}
}]
)

View File

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