Add Tests for changes to user information/roles

This commit is contained in:
Pedro Silva 2022-12-05 17:54:40 +00:00
parent 0034bbbe2d
commit 895c29d45f
2 changed files with 72 additions and 10 deletions

View File

@ -33,7 +33,7 @@ export default class UserManagementApi {
return [response, json]
}
async addUsers(body: any): Promise<[Response, responseMessage]> {
async addUsers(body: any): Promise<[Response, any]> {
const response = await this.api.post(`/global/users/bulk`, { body })
const json = await response.json()
expect(response).toHaveStatusCode(200)
@ -42,7 +42,7 @@ export default class UserManagementApi {
return [response, json]
}
async deleteUser(userId: string): Promise<[Response, responseMessage]> {
async deleteMultipleUsers(userId: string[]): Promise<[Response, responseMessage]> {
const body = {
delete: {
userIds: [
@ -58,6 +58,13 @@ export default class UserManagementApi {
expect(json.deleted.successful[0].userId).toEqual(userId)
return [response, json]
}
async deleteUser(userId: string): Promise<[Response, UserDeletedEvent]> {
const response = await this.api.del(`/global/users/${userId}`)
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.message).toEqual(`User ${userId} deleted.`)
return [response, json]
}
async inviteUser(body: any): Promise<[Response, responseMessage]> {
const response = await this.api.post(`/global/users/multi/invite`, { body })
@ -76,4 +83,27 @@ export default class UserManagementApi {
expect(json.length).toEqual(4)
return [response, json]
}
}
async changeUserInformation(body: any): Promise<[Response, User]> {
const response = await this.api.post(`/global/users/`, { body })
const json = await response.json()
expect(response).toHaveStatusCode(200)
return [response, json]
}
async forcePasswordReset(body: any): Promise<[Response, User]> {
const response = await this.api.post(`/global/users/`, { body })
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json._id).toEqual(body._id)
expect(json._rev).not.toEqual(body._rev)
return [response, json]
}
async getUserInformation(userId: string): Promise<[Response, User]> {
const response = await this.api.get(`/global/users/${userId}`)
const json = await response.json()
expect(response).toHaveStatusCode(200)
return [response, json]
}
}

View File

@ -1,11 +1,7 @@
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 { generateAdmin, generateAppUser, generateDeveloper, generateInviteUser } from "../../../config/internal-api/fixtures/userManagement"
import generate from "../../../config/internal-api/fixtures/applications"
describe("Internal API - User Management & Permissions", () => {
const api = new InternalAPIClient()
@ -28,13 +24,49 @@ describe("Internal API - User Management & Permissions", () => {
const developer = generateDeveloper()
const appUser = generateAppUser()
const [adminResponse, adminData] = await config.userManagement.addUsers(admin)
const [devResponse, devData] = await config.userManagement.addUsers(developer)
const [userResponse, userData] = await config.userManagement.addUsers(appUser)
await config.userManagement.addUsers(admin)
await config.userManagement.addUsers(developer)
await config.userManagement.addUsers(appUser)
const [allUsersResponse, allUsersData] = await config.userManagement.getAllUsers()
expect(allUsersData.length).toBeGreaterThan(0)
})
it("Delete User", async () => {
const appUser = generateAppUser()
const [userResponse, userData] = await config.userManagement.addUsers(appUser)
const userId = userData.created.successful[0]._id
await config.userManagement.deleteUser(<string>userId)
})
it("Reset Password", async () => {
const appUser = generateAppUser()
const [userResponse, userData] = await config.userManagement.addUsers(appUser)
const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userData.created.successful[0]._id)
const body = {
...userInfoJson,
password: "newPassword"
}
await config.userManagement.forcePasswordReset(body)
})
it("Change User information", async () => {
const appUser = generateAppUser()
const [userResponse, userData] = await config.userManagement.addUsers(appUser)
const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userData.created.successful[0]._id)
const body = {
...userInfoJson,
builder: {
global: true
}
}
const [changedUserResponse, changedUserJson] = await config.userManagement.changeUserInformation(body)
expect(changedUserJson.builder?.global).toBeDefined()
expect(changedUserJson.builder?.global).toEqual(true)
})