Changes to types and user generation
This commit is contained in:
parent
4467d2b005
commit
6d87a38ab3
|
@ -13,7 +13,7 @@ export default class TestConfiguration<T> {
|
|||
context: T
|
||||
tables: TablesApi
|
||||
rows: RowApi
|
||||
userManagement: UserManagementApi
|
||||
users: UserManagementApi
|
||||
|
||||
constructor(apiClient: InternalAPIClient) {
|
||||
this.applications = new ApplicationApi(apiClient)
|
||||
|
@ -21,15 +21,15 @@ 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.users = new UserManagementApi(apiClient)
|
||||
this.context = <T>{}
|
||||
}
|
||||
|
||||
async loginAsAdmin() {
|
||||
await this.auth.login(<String>process.env.BB_ADMIN_USER_EMAIL, <String>process.env.BB_ADMIN_USER_PASSWORD)
|
||||
await this.auth.login(<string>process.env.BB_ADMIN_USER_EMAIL, <string>process.env.BB_ADMIN_USER_PASSWORD)
|
||||
}
|
||||
|
||||
async login(email: String, password: String) {
|
||||
async login(email: string, password: string) {
|
||||
await this.auth.login(email, password)
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,13 @@ export default class UserManagementApi {
|
|||
return [response, json]
|
||||
}
|
||||
|
||||
async addUsers(body: any): Promise<[Response, any]> {
|
||||
async addMultipleUsers(userList: User[]): Promise<[Response, any]> {
|
||||
const body = {
|
||||
create: {
|
||||
users: userList,
|
||||
groups: []
|
||||
}
|
||||
}
|
||||
const response = await this.api.post(`/global/users/bulk`, { body })
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
|
|
|
@ -1,63 +1,51 @@
|
|||
import generator from "../../generator";
|
||||
import { User } from "@budibase/types";
|
||||
import { generateUserMetadataID } from "@budibase/backend-core/src/db";
|
||||
|
||||
export const generateDeveloper = (): Object => {
|
||||
|
||||
const generateDeveloper = (): User => {
|
||||
const randomId = generator.guid();
|
||||
return ({
|
||||
create: {
|
||||
users: [{
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
password: randomId,
|
||||
roles: {},
|
||||
forceResetPassword: true,
|
||||
builder: {
|
||||
global: true
|
||||
}
|
||||
}],
|
||||
groups: []
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
password: randomId,
|
||||
roles: {},
|
||||
forceResetPassword: true,
|
||||
builder: {
|
||||
global: true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const generateAdmin = (): Object => {
|
||||
const generateAdmin = (): User => {
|
||||
const randomId = generator.guid();
|
||||
return ({
|
||||
create: {
|
||||
users: [{
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
password: randomId,
|
||||
roles: {},
|
||||
forceResetPassword: true,
|
||||
admin: {
|
||||
global: true
|
||||
},
|
||||
builder: {
|
||||
global: true
|
||||
}
|
||||
}],
|
||||
groups: []
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
password: randomId,
|
||||
roles: {},
|
||||
forceResetPassword: true,
|
||||
admin: {
|
||||
global: true
|
||||
},
|
||||
builder: {
|
||||
global: true
|
||||
}
|
||||
})
|
||||
}
|
||||
export const generateAppUser = (): Object => {
|
||||
const generateAppUser = (): User => {
|
||||
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: []
|
||||
return ({
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
password: randomId,
|
||||
roles: {},
|
||||
forceResetPassword: true,
|
||||
admin: {
|
||||
global: false
|
||||
},
|
||||
builder: {
|
||||
global: false
|
||||
}
|
||||
}
|
||||
return user
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
export const generateInviteUser = (): Object[] => {
|
||||
|
@ -69,4 +57,25 @@ export const generateInviteUser = (): Object[] => {
|
|||
}
|
||||
}]
|
||||
|
||||
}
|
||||
|
||||
export const generateUser = (amount: number = 1, role?: string): User[] => {
|
||||
const userList: User[] = [];
|
||||
for (let i = 0; i < amount; i++) {
|
||||
switch (role) {
|
||||
case "admin":
|
||||
userList.push(generateAdmin());
|
||||
break;
|
||||
case "developer":
|
||||
userList.push(generateDeveloper());
|
||||
break;
|
||||
case "appUser":
|
||||
userList.push(generateAppUser());
|
||||
break;
|
||||
default:
|
||||
userList.push(generateAppUser());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return userList
|
||||
}
|
|
@ -2,7 +2,7 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration"
|
|||
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
||||
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
||||
import generateApp from "../../../config/internal-api/fixtures/applications"
|
||||
import { generateAdmin, generateAppUser, generateDeveloper, generateInviteUser } from "../../../config/internal-api/fixtures/userManagement"
|
||||
import { generateUser } from "../../../config/internal-api/fixtures/userManagement"
|
||||
import { User } from "@budibase/types"
|
||||
|
||||
describe("Internal API - User Management & Permissions", () => {
|
||||
|
@ -18,19 +18,24 @@ describe("Internal API - User Management & Permissions", () => {
|
|||
})
|
||||
|
||||
it("Add Users with different roles", async () => {
|
||||
await config.userManagement.searchUsers()
|
||||
await config.userManagement.getRoles()
|
||||
await config.users.searchUsers()
|
||||
await config.users.getRoles()
|
||||
|
||||
// These need to be saved to the context so the passwords can be used to login
|
||||
const admin = generateAdmin()
|
||||
const developer = generateDeveloper()
|
||||
const appUser = generateAppUser()
|
||||
const admin = generateUser(1, "admin")
|
||||
expect(admin[0].builder?.global).toEqual(true)
|
||||
expect(admin[0].admin?.global).toEqual(true)
|
||||
const developer = generateUser(1, "developer")
|
||||
expect(developer[0].builder?.global).toEqual(true)
|
||||
const appUser = generateUser(1, "appUser")
|
||||
expect(appUser[0].builder?.global).toEqual(false)
|
||||
expect(appUser[0].admin?.global).toEqual(false)
|
||||
|
||||
await config.userManagement.addUsers(admin)
|
||||
await config.userManagement.addUsers(developer)
|
||||
await config.userManagement.addUsers(appUser)
|
||||
await config.users.addMultipleUsers(admin)
|
||||
await config.users.addMultipleUsers(developer)
|
||||
await config.users.addMultipleUsers(appUser)
|
||||
|
||||
const [allUsersResponse, allUsersJson] = await config.userManagement.getAllUsers()
|
||||
const [allUsersResponse, allUsersJson] = await config.users.getAllUsers()
|
||||
expect(allUsersJson.length).toBeGreaterThan(0)
|
||||
|
||||
|
||||
|
@ -38,28 +43,34 @@ describe("Internal API - User Management & Permissions", () => {
|
|||
})
|
||||
|
||||
it("Delete User", async () => {
|
||||
const appUser = generateAppUser()
|
||||
const [userResponse, userJson] = await config.userManagement.addUsers(appUser)
|
||||
const appUser = generateUser()
|
||||
expect(appUser[0].builder?.global).toEqual(false)
|
||||
expect(appUser[0].admin?.global).toEqual(false)
|
||||
const [userResponse, userJson] = await config.users.addMultipleUsers(appUser)
|
||||
const userId = userJson.created.successful[0]._id
|
||||
await config.userManagement.deleteUser(<string>userId)
|
||||
await config.users.deleteUser(<string>userId)
|
||||
})
|
||||
|
||||
it("Reset Password", async () => {
|
||||
const appUser = generateAppUser()
|
||||
const [userResponse, userJson] = await config.userManagement.addUsers(appUser)
|
||||
const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userJson.created.successful[0]._id)
|
||||
const appUser = generateUser()
|
||||
expect(appUser[0].builder?.global).toEqual(false)
|
||||
expect(appUser[0].admin?.global).toEqual(false)
|
||||
const [userResponse, userJson] = await config.users.addMultipleUsers(appUser)
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(userJson.created.successful[0]._id)
|
||||
const body: User = {
|
||||
...userInfoJson,
|
||||
password: "newPassword"
|
||||
|
||||
}
|
||||
await config.userManagement.forcePasswordReset(body)
|
||||
await config.users.forcePasswordReset(body)
|
||||
})
|
||||
|
||||
it("Change User information", async () => {
|
||||
const appUser = generateAppUser()
|
||||
const [userResponse, userJson] = await config.userManagement.addUsers(appUser)
|
||||
const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userJson.created.successful[0]._id)
|
||||
const appUser = generateUser()
|
||||
expect(appUser[0].builder?.global).toEqual(false)
|
||||
expect(appUser[0].admin?.global).toEqual(false)
|
||||
const [userResponse, userJson] = await config.users.addMultipleUsers(appUser)
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(userJson.created.successful[0]._id)
|
||||
const body: User = {
|
||||
...userInfoJson,
|
||||
firstName: "newFirstName",
|
||||
|
@ -68,77 +79,80 @@ describe("Internal API - User Management & Permissions", () => {
|
|||
global: true
|
||||
}
|
||||
}
|
||||
await config.userManagement.changeUserInformation(body)
|
||||
await config.users.changeUserInformation(body)
|
||||
|
||||
const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(userJson.created.successful[0]._id)
|
||||
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(userJson.created.successful[0]._id)
|
||||
expect(changedUserInfoJson.builder?.global).toBeDefined()
|
||||
expect(changedUserInfoJson.builder?.global).toEqual(true)
|
||||
})
|
||||
|
||||
it("Add BASIC user to app", async () => {
|
||||
const basicUser = generateAppUser()
|
||||
|
||||
const [createUserResponse, createUserJson] = await config.userManagement.addUsers(basicUser)
|
||||
const appUser = generateUser()
|
||||
expect(appUser[0].builder?.global).toEqual(false)
|
||||
expect(appUser[0].admin?.global).toEqual(false)
|
||||
const [createUserResponse, createUserJson] = await config.users.addMultipleUsers(appUser)
|
||||
|
||||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id)
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id)
|
||||
const body: User = {
|
||||
...userInfoJson,
|
||||
roles: {
|
||||
[app.appId?.toString() || ""]: "BASIC",
|
||||
}
|
||||
}
|
||||
await config.userManagement.changeUserInformation(body)
|
||||
await config.users.changeUserInformation(body)
|
||||
|
||||
const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id)
|
||||
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id)
|
||||
expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined()
|
||||
expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toEqual("BASIC")
|
||||
|
||||
})
|
||||
|
||||
it("Add ADMIN user to app", async () => {
|
||||
const adminUser = generateAdmin()
|
||||
|
||||
const [createUserResponse, createUserJson] = await config.userManagement.addUsers(adminUser)
|
||||
const adminUser = generateUser(1, "admin")
|
||||
expect(adminUser[0].builder?.global).toEqual(true)
|
||||
expect(adminUser[0].admin?.global).toEqual(true)
|
||||
const [createUserResponse, createUserJson] = await config.users.addMultipleUsers(adminUser)
|
||||
|
||||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id)
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id)
|
||||
const body: User = {
|
||||
...userInfoJson,
|
||||
roles: {
|
||||
[app.appId?.toString() || ""]: "ADMIN",
|
||||
}
|
||||
}
|
||||
await config.userManagement.changeUserInformation(body)
|
||||
await config.users.changeUserInformation(body)
|
||||
|
||||
const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id)
|
||||
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id)
|
||||
expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined()
|
||||
expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toEqual("ADMIN")
|
||||
|
||||
})
|
||||
|
||||
it("Add POWER user to app", async () => {
|
||||
const powerUser = generateDeveloper()
|
||||
const powerUser = generateUser(1, 'Developer')
|
||||
expect(powerUser[0].builder?.global).toEqual(true)
|
||||
|
||||
const [createUserResponse, createUserJson] = await config.userManagement.addUsers(powerUser)
|
||||
const [createUserResponse, createUserJson] = await config.users.addMultipleUsers(powerUser)
|
||||
|
||||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id)
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id)
|
||||
const body: User = {
|
||||
...userInfoJson,
|
||||
roles: {
|
||||
[app.appId?.toString() || ""]: "POWER",
|
||||
}
|
||||
}
|
||||
await config.userManagement.changeUserInformation(body)
|
||||
await config.users.changeUserInformation(body)
|
||||
|
||||
const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id)
|
||||
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id)
|
||||
expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined()
|
||||
expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toEqual("POWER")
|
||||
|
||||
|
|
Loading…
Reference in New Issue