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