2023-04-05 16:33:56 +02:00
|
|
|
import { BudibaseInternalAPI } from "../internal-api"
|
|
|
|
import { AccountInternalAPI } from "../account-api"
|
|
|
|
import { CreateAppRequest, State } from "../types"
|
|
|
|
import * as fixtures from "../internal-api/fixtures"
|
|
|
|
|
|
|
|
export default class BudibaseTestConfiguration {
|
|
|
|
// apis
|
|
|
|
internalApi: BudibaseInternalAPI
|
|
|
|
accountsApi: AccountInternalAPI
|
|
|
|
|
|
|
|
// state
|
|
|
|
state: State
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.state = {}
|
|
|
|
this.internalApi = new BudibaseInternalAPI(this.state)
|
|
|
|
this.accountsApi = new AccountInternalAPI(this.state)
|
|
|
|
}
|
|
|
|
|
|
|
|
// LIFECYCLE
|
|
|
|
|
|
|
|
async beforeAll() {
|
|
|
|
// @ts-ignore
|
|
|
|
this.state.tenantId = global.qa.tenantId
|
|
|
|
// @ts-ignore
|
|
|
|
this.state.cookie = global.qa.authCookie
|
|
|
|
}
|
|
|
|
|
|
|
|
async afterAll() {
|
|
|
|
// nothing yet
|
|
|
|
}
|
|
|
|
|
|
|
|
async createApp(overrides: Partial<CreateAppRequest> = {}) {
|
|
|
|
const app = await this.internalApi.apps.create(
|
|
|
|
fixtures.apps.generateApp(overrides)
|
|
|
|
)
|
|
|
|
this.state.appId = app.appId
|
|
|
|
return app
|
|
|
|
}
|
|
|
|
|
|
|
|
// AUTH
|
|
|
|
|
|
|
|
async login(email: string, password: string, tenantId?: string) {
|
|
|
|
if (!tenantId && this.state.tenantId) {
|
|
|
|
tenantId = this.state.tenantId
|
2023-07-14 15:24:01 +02:00
|
|
|
}
|
|
|
|
if (!tenantId) {
|
2023-04-05 16:33:56 +02:00
|
|
|
throw new Error("Could not determine tenant id")
|
|
|
|
}
|
|
|
|
const [res, cookie] = await this.internalApi.auth.login(
|
|
|
|
tenantId,
|
|
|
|
email,
|
|
|
|
password
|
|
|
|
)
|
|
|
|
this.state.cookie = cookie
|
|
|
|
}
|
|
|
|
}
|