Add state helpers for isolating account deletion test
This commit is contained in:
parent
fa94b8b9fc
commit
f45a439b26
|
@ -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 () => {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue