diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts index 2ff9450939..17fe5e0b0f 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -1,5 +1,5 @@ import { Response } from "node-fetch" -import { User, UserDeletedEvent } from "@budibase/types" +import { Role, User, UserDeletedEvent } from "@budibase/types" import InternalAPIClient from "./InternalAPIClient" import { responseMessage } from "../fixtures/types/responseMessage" @@ -15,7 +15,6 @@ export default class UserManagementApi { const json = await response.json() expect(response).toHaveStatusCode(200) expect(json.data.length).toBeGreaterThan(0) - expect(json.hasNextPage).toBe(false) return [response, json] } @@ -26,19 +25,20 @@ export default class UserManagementApi { return [response, json] } - async getAllUsers(): Promise<[Response, User]> { + async getAllUsers(): Promise<[Response, User[]]> { const response = await this.api.get(`/global/users`) const json = await response.json() expect(response).toHaveStatusCode(200) + expect(json.length).toBeGreaterThan(0) return [response, json] } - async inviteUsers(body: User[]): Promise<[Response, responseMessage]> { - const response = await this.api.post(`/global/users/multi/invite`, { body }) + async addUsers(body: any): Promise<[Response, responseMessage]> { + const response = await this.api.post(`/global/users/bulk`, { body }) const json = await response.json() expect(response).toHaveStatusCode(200) - expect(json.successful.length).toEqual(body.length) - expect(json.unsuccessful.length).toEqual(0) + expect(json.created.unsuccessful.length).toEqual(0) + expect(json.created.successful.length).toEqual(body.create.users.length) return [response, json] } @@ -58,4 +58,21 @@ export default class UserManagementApi { expect(json.deleted.successful[0].userId).toEqual(userId) return [response, json] } + + async inviteUser(body: any): 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.created.successful.length).toEqual(body.length) + expect(json.created.unsuccessful.length).toEqual(0) + return [response, json] + } + + async getRoles(): Promise<[Response, Role[]]> { + const response = await this.api.get(`/roles`) + const json = await response.json() + expect(response).toHaveStatusCode(200) + expect(json.length).toEqual(4) + return [response, json] + } } diff --git a/qa-core/src/config/internal-api/fixtures/userManagement.ts b/qa-core/src/config/internal-api/fixtures/userManagement.ts index ce15eb08e8..6ada85bb49 100644 --- a/qa-core/src/config/internal-api/fixtures/userManagement.ts +++ b/qa-core/src/config/internal-api/fixtures/userManagement.ts @@ -1,59 +1,69 @@ 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 generateDeveloper = (): Object => { + const randomId = generator.guid(); + return ({ + 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 generateAdmin = (): Object => { + const randomId = generator.guid(); + return ({ + create: { + users: [{ + email: `pedro+${randomId}@budibase.com`, + password: randomId, + roles: {}, + forceResetPassword: true, + admin: { + global: true + }, + builder: { + global: true + } + }], + groups: [] + } + }) +} +export const generateAppUser = (): Object => { + const randomId = generator.guid(); + const user = { + create: { + users: [{ + email: `pedro+${randomId}@budibase.com`, + password: randomId, + roles: {}, + forceResetPassword: true, + admin: { + global: false + }, + builder: { + global: false + } + }], + groups: [] + } } -}) -export const generateAppUser = (): any => ({ - create: { - users: [{ - email: `pedro+${randomId()}@budibase.com`, - password: randomId, - roles: {}, - forceResetPassword: true, - admin: { - global: false - }, - builder: { - global: false - } - }], - groups: [] - } -}) + return user +} -export const generateInviteUser = (): any => ( - [{ - email: `pedro+${randomId()}@budibase.com`, +export const generateInviteUser = (): Object[] => { + const randomId = generator.guid(); + return [{ + email: `pedro+${randomId}@budibase.com`, userInfo: { admin: { global: true @@ -64,4 +74,5 @@ export const generateInviteUser = (): any => ( userGroups: [] } }] -) \ No newline at end of file + +} \ No newline at end of file diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index 67fee8e53d..62d27ec2a4 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -4,9 +4,9 @@ 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" +import { generateAdmin, generateAppUser, generateDeveloper, generateInviteUser } from "../../../config/internal-api/fixtures/userManagement" -describe("Internal API - User Management", () => { +describe("Internal API - User Management & Permissions", () => { const api = new InternalAPIClient() const config = new TestConfiguration(api) @@ -18,7 +18,20 @@ describe("Internal API - User Management", () => { await config.afterAll() }) - it("Get all users", async () => { + it("Add Users with different roles", async () => { await config.userManagement.searchUsers() + await config.userManagement.getRoles() + + const [adminResponse, adminData] = await config.userManagement.addUsers(generateAdmin()) + const [devResponse, devData] = await config.userManagement.addUsers(generateDeveloper()) + const [userResponse, userData] = await config.userManagement.addUsers(generateAppUser()) + + const [invitedUserResponse, invitedUserData] = await config.userManagement.addUsers(generateInviteUser()) + + const [allUsersResponse, allUsersData] = await config.userManagement.getAllUsers() + expect(allUsersData.length).toEqual(4) + }) + + })