diff --git a/qa-core/src/account-api/tests/accounts/delete.spec.ts b/qa-core/src/account-api/tests/accounts/delete.spec.ts index 20df48dafb..2d476d78c0 100644 --- a/qa-core/src/account-api/tests/accounts/delete.spec.ts +++ b/qa-core/src/account-api/tests/accounts/delete.spec.ts @@ -13,24 +13,22 @@ describe("Account API - Delete Account", () => { }) it("Deletes an account", async () => { - // Create account - const createAccountRequest = fixtures.accounts.generateAccount() + await config.doInNewState(async () => { + // Create account + const createAccountRequest = fixtures.accounts.generateAccount() + await config.api.accounts.create(createAccountRequest) - await config.api.accounts.create( - createAccountRequest - ) + // Login - Get cookie + await config.login( + createAccountRequest.email, + createAccountRequest.password, + createAccountRequest.tenantId + ) - // Login - Get cookie - await config.login( - createAccountRequest.email, - createAccountRequest.password, - createAccountRequest.tenantId - ) - - // Delete account - const [ res ] = await config.api.accounts.deleteCurrentAccount() - - expect(res.status).toBe(204) + // Delete account + const res = await config.api.accounts.deleteCurrentAccount() + expect(res.status).toBe(204) + }) }) it("Deletes an account by ID", async () => { diff --git a/qa-core/src/shared/BudibaseTestConfiguration.ts b/qa-core/src/shared/BudibaseTestConfiguration.ts index d8fd2bee61..c1aaeb0cae 100644 --- a/qa-core/src/shared/BudibaseTestConfiguration.ts +++ b/qa-core/src/shared/BudibaseTestConfiguration.ts @@ -40,6 +40,30 @@ export default class BudibaseTestConfiguration { // AUTH + async doInNewState(task: any) { + return this.doWithState(task, {}) + } + + async doWithState(task: any, state: State) { + const original = this.state + + // override the state + this.state.apiKey = state.apiKey + this.state.appId = state.appId + this.state.cookie = state.cookie + this.state.tableId = state.tableId + this.state.tenantId = state.tenantId + + await task() + + // restore the state + this.state.apiKey = original.apiKey + this.state.appId = original.appId + this.state.cookie = original.cookie + this.state.tableId = original.tableId + this.state.tenantId = original.tenantId + } + async login(email: string, password: string, tenantId?: string) { if (!tenantId && this.state.tenantId) { tenantId = this.state.tenantId