Rename users methods

This commit is contained in:
Pedro Silva 2022-12-09 18:00:13 +00:00
parent 22b1336063
commit d390fe7d8d
3 changed files with 35 additions and 35 deletions

View File

@ -10,7 +10,7 @@ export default class UserManagementApi {
this.api = apiClient
}
async searchUsers(): Promise<[Response, Partial<User>[]]> {
async search(): Promise<[Response, Partial<User>[]]> {
const response = await this.api.post(`/global/users/search`, {})
const json = await response.json()
expect(response).toHaveStatusCode(200)
@ -25,7 +25,7 @@ export default class UserManagementApi {
return [response, json]
}
async getAllUsers(): Promise<[Response, Partial<User>[]]> {
async getAll(): Promise<[Response, Partial<User>[]]> {
const response = await this.api.get(`/global/users`)
const json = await response.json()
expect(response).toHaveStatusCode(200)
@ -33,7 +33,7 @@ export default class UserManagementApi {
return [response, json]
}
async addMultipleUsers(userList: Partial<User>[]): Promise<[Response, any]> {
async addMultiple(userList: Partial<User>[]): Promise<[Response, any]> {
const body = {
create: {
users: userList,
@ -48,7 +48,7 @@ export default class UserManagementApi {
return [response, json]
}
async deleteMultipleUsers(userId: string[]): Promise<[Response, responseMessage]> {
async deleteMultiple(userId: string[]): Promise<[Response, responseMessage]> {
const body = {
delete: {
userIds: [
@ -64,7 +64,7 @@ export default class UserManagementApi {
expect(json.deleted.successful[0].userId).toEqual(userId)
return [response, json]
}
async deleteUser(userId: string): Promise<[Response, UserDeletedEvent]> {
async delete(userId: string): Promise<[Response, UserDeletedEvent]> {
const response = await this.api.del(`/global/users/${userId}`)
const json = await response.json()
expect(response).toHaveStatusCode(200)
@ -72,7 +72,7 @@ export default class UserManagementApi {
return [response, json]
}
async inviteUser(body: any): Promise<[Response, responseMessage]> {
async invite(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)
@ -90,7 +90,7 @@ export default class UserManagementApi {
return [response, json]
}
async changeUserInformation(body: any): Promise<[Response, User]> {
async updateInfo(body: any): Promise<[Response, User]> {
const response = await this.api.post(`/global/users/`, { body })
const json = await response.json()
expect(response).toHaveStatusCode(200)
@ -108,7 +108,7 @@ export default class UserManagementApi {
return [response, json]
}
async getUserInformation(userId: string): Promise<[Response, User]> {
async getInfo(userId: string): Promise<[Response, User]> {
const response = await this.api.get(`/global/users/${userId}`)
const json = await response.json()
expect(response).toHaveStatusCode(200)

View File

@ -49,9 +49,9 @@ const generateAppUser = (): Partial<User> => {
}
export const generateInviteUser = (): Object[] => {
//const randomId = generator.guid();
const randomId = generator.guid();
return [{
email: `pedro+test@budibase.com`,
email: `pedro+${randomId}@budibase.com`,
userInfo: {
userGroups: []
}

View File

@ -18,7 +18,7 @@ describe("Internal API - User Management & Permissions", () => {
})
it("Add Users with different roles", async () => {
await config.users.searchUsers()
await config.users.search()
await config.users.getRoles()
// These need to be saved to the context so the passwords can be used to login
@ -31,11 +31,11 @@ describe("Internal API - User Management & Permissions", () => {
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
await config.users.addMultipleUsers(admin)
await config.users.addMultipleUsers(developer)
await config.users.addMultipleUsers(appUser)
await config.users.addMultiple(admin)
await config.users.addMultiple(developer)
await config.users.addMultiple(appUser)
const [allUsersResponse, allUsersJson] = await config.users.getAllUsers()
const [allUsersResponse, allUsersJson] = await config.users.getAll()
expect(allUsersJson.length).toBeGreaterThan(0)
@ -46,17 +46,17 @@ describe("Internal API - User Management & Permissions", () => {
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 [userResponse, userJson] = await config.users.addMultiple(appUser)
const userId = userJson.created.successful[0]._id
await config.users.deleteUser(<string>userId)
await config.users.delete(<string>userId)
})
it("Reset Password", async () => {
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 [userResponse, userJson] = await config.users.addMultiple(appUser)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id)
const body: User = {
...userInfoJson,
password: "newPassword"
@ -69,8 +69,8 @@ describe("Internal API - User Management & Permissions", () => {
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 [userResponse, userJson] = await config.users.addMultiple(appUser)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id)
const body: User = {
...userInfoJson,
firstName: "newFirstName",
@ -79,9 +79,9 @@ describe("Internal API - User Management & Permissions", () => {
global: true
}
}
await config.users.changeUserInformation(body)
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(userJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id)
expect(changedUserInfoJson.builder?.global).toBeDefined()
expect(changedUserInfoJson.builder?.global).toEqual(true)
})
@ -90,21 +90,21 @@ describe("Internal API - User Management & Permissions", () => {
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 [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const body: User = {
...userInfoJson,
roles: {
[app.appId?.toString() || ""]: "BASIC",
}
}
await config.users.changeUserInformation(body)
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("BASIC")
@ -114,21 +114,21 @@ describe("Internal API - User Management & Permissions", () => {
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 [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser)
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const body: User = {
...userInfoJson,
roles: {
[app.appId?.toString() || ""]: "ADMIN",
}
}
await config.users.changeUserInformation(body)
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("ADMIN")
@ -138,21 +138,21 @@ describe("Internal API - User Management & Permissions", () => {
const powerUser = generateUser(1, 'developer')
expect(powerUser[0].builder?.global).toEqual(true)
const [createUserResponse, createUserJson] = await config.users.addMultipleUsers(powerUser)
const [createUserResponse, createUserJson] = await config.users.addMultiple(powerUser)
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const body: User = {
...userInfoJson,
roles: {
[app.appId?.toString() || ""]: "POWER",
}
}
await config.users.changeUserInformation(body)
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("POWER")