diff --git a/qa-core/src/account-api/api/apis/AccountAPI.ts b/qa-core/src/account-api/api/apis/AccountAPI.ts index a97fe29fd0..c18dde3d4a 100644 --- a/qa-core/src/account-api/api/apis/AccountAPI.ts +++ b/qa-core/src/account-api/api/apis/AccountAPI.ts @@ -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 + } } diff --git a/qa-core/src/jest/globalSetup.ts b/qa-core/src/jest/globalSetup.ts index e222e7c043..12d227df02 100644 --- a/qa-core/src/jest/globalSetup.ts +++ b/qa-core/src/jest/globalSetup.ts @@ -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 diff --git a/qa-core/src/jest/globalTeardown.ts b/qa-core/src/jest/globalTeardown.ts index 9cd7fff041..51f6046f4f 100644 --- a/qa-core/src/jest/globalTeardown.ts +++ b/qa-core/src/jest/globalTeardown.ts @@ -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") }