Add generic login method
This commit is contained in:
parent
1c0767f549
commit
c0c8262561
|
@ -8,7 +8,7 @@ export default class AuthApi {
|
|||
this.api = apiClient
|
||||
}
|
||||
|
||||
async login(): Promise<[Response, any]> {
|
||||
async loginAsAdmin(): Promise<[Response, any]> {
|
||||
const response = await this.api.post(`/global/auth/default/login`, {
|
||||
body: {
|
||||
username: process.env.BB_ADMIN_USER_EMAIL,
|
||||
|
@ -20,6 +20,18 @@ export default class AuthApi {
|
|||
return [response, cookie]
|
||||
}
|
||||
|
||||
async login(email: String, password: String): Promise<[Response, any]> {
|
||||
const response = await this.api.post(`/global/auth/default/login`, {
|
||||
body: {
|
||||
username: email,
|
||||
password: password,
|
||||
},
|
||||
})
|
||||
const cookie = response.headers.get("set-cookie")
|
||||
this.api.cookie = cookie as any
|
||||
return [response, cookie]
|
||||
}
|
||||
|
||||
async logout(): Promise<any> {
|
||||
return this.api.post(`/global/auth/logout`)
|
||||
}
|
||||
|
|
|
@ -25,8 +25,12 @@ export default class TestConfiguration<T> {
|
|||
this.context = <T>{}
|
||||
}
|
||||
|
||||
async beforeAll() {
|
||||
await this.auth.login()
|
||||
async loginAsAdmin() {
|
||||
await this.auth.login(<String>process.env.BB_ADMIN_USER_EMAIL, <String>process.env.BB_ADMIN_USER_PASSWORD)
|
||||
}
|
||||
|
||||
async login(email: String, password: String) {
|
||||
await this.auth.login(email, password)
|
||||
}
|
||||
|
||||
async afterAll() {
|
||||
|
|
|
@ -61,9 +61,9 @@ export const generateAppUser = (): Object => {
|
|||
}
|
||||
|
||||
export const generateInviteUser = (): Object[] => {
|
||||
const randomId = generator.guid();
|
||||
//const randomId = generator.guid();
|
||||
return [{
|
||||
email: `pedro+${randomId}@budibase.com`,
|
||||
email: `pedro+test@budibase.com`,
|
||||
userInfo: {
|
||||
userGroups: []
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
|
|||
const config = new TestConfiguration<Application>(api)
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.beforeAll()
|
||||
await config.loginAsAdmin()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
|
@ -11,7 +11,7 @@ describe("Internal API - /screens endpoints", () => {
|
|||
const appConfig = new TestConfiguration<App>(api)
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.beforeAll()
|
||||
await config.loginAsAdmin()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
|
@ -13,7 +13,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
|
|||
const config = new TestConfiguration<Application>(api)
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.beforeAll()
|
||||
await config.loginAsAdmin()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
|
@ -11,7 +11,7 @@ describe("Internal API - User Management & Permissions", () => {
|
|||
const config = new TestConfiguration<Application>(api)
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.beforeAll()
|
||||
await config.loginAsAdmin()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
|
@ -26,10 +26,8 @@ describe("Internal API - User Management & Permissions", () => {
|
|||
const [devResponse, devData] = await config.userManagement.addUsers(generateDeveloper())
|
||||
const [userResponse, userData] = await config.userManagement.addUsers(generateAppUser())
|
||||
|
||||
const [invitedUserResponse, invitedUserData] = await config.userManagement.inviteUser(generateInviteUser())
|
||||
|
||||
const [allUsersResponse, allUsersData] = await config.userManagement.getAllUsers()
|
||||
expect(allUsersData.length).toEqual(4)
|
||||
expect(allUsersData.length).toBeGreaterThan(0)
|
||||
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue