Merge pull request #10740 from Budibase/test/qa-23-add-test-clean-up

Add teardown logic for multitenancy
This commit is contained in:
Pedro Silva 2023-05-30 22:18:04 +01:00 committed by GitHub
commit 8103534d42
3 changed files with 31 additions and 6 deletions

View File

@ -58,4 +58,10 @@ export default class AccountAPI {
}
return [response, json]
}
async delete(accountID: string) {
const [response, json] = await this.client.del(`/api/accounts/${accountID}`)
expect(response).toHaveStatusCode(200)
return response
}
}

View File

@ -2,7 +2,7 @@ import { DEFAULT_TENANT_ID, logging } from "@budibase/backend-core"
import { AccountInternalAPI } from "../account-api"
import * as fixtures from "../internal-api/fixtures"
import { BudibaseInternalAPI } from "../internal-api"
import { CreateAccountRequest, Feature } from "@budibase/types"
import { Account, CreateAccountRequest, Feature } from "@budibase/types"
import env from "../environment"
import { APIRequestOpts } from "../types"
@ -18,13 +18,13 @@ const API_OPTS: APIRequestOpts = { doExpect: false }
// @ts-ignore
global.qa = {}
async function createAccount() {
async function createAccount(): Promise<[CreateAccountRequest, Account]> {
const account = fixtures.accounts.generateAccount()
await accountsApi.accounts.validateEmail(account.email, API_OPTS)
await accountsApi.accounts.validateTenantId(account.tenantId, API_OPTS)
const [res, newAccount] = await accountsApi.accounts.create(account, API_OPTS)
await updateLicense(newAccount.accountId)
return account
return [account, newAccount]
}
const UNLIMITED = { value: -1 }
@ -85,9 +85,11 @@ async function setup() {
console.log(`Environment: ${JSON.stringify(env)}`)
if (env.multiTenancy) {
const account = await createAccount()
const [account, newAccount] = await createAccount()
// @ts-ignore
global.qa.tenantId = account.tenantId
// @ts-ignore
global.qa.accountId = newAccount.accountId
await loginAsAccount(account)
} else {
// @ts-ignore

View File

@ -1,7 +1,24 @@
import { AccountInternalAPI } from "../account-api"
import { BudibaseInternalAPI } from "../internal-api"
import { APIRequestOpts } from "../types"
const accountsApi = new AccountInternalAPI({})
const internalApi = new BudibaseInternalAPI({})
const API_OPTS: APIRequestOpts = { doExpect: false }
async function deleteAccount() {
// @ts-ignore
const accountID = global.qa.accountId
await accountsApi.accounts.delete(accountID)
}
async function teardown() {
console.log("\nGLOBAL TEARDOWN STARTING")
// TODO: Delete account and apps after test run
const env = await internalApi.environment.getEnvironment(API_OPTS)
if (env.multiTenancy) {
await deleteAccount()
}
console.log("GLOBAL TEARDOWN COMPLETE")
}