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 () => {
|
it("Deletes an account", async () => {
|
||||||
// Create account
|
await config.doInNewState(async () => {
|
||||||
const createAccountRequest = fixtures.accounts.generateAccount()
|
// Create account
|
||||||
|
const createAccountRequest = fixtures.accounts.generateAccount()
|
||||||
|
await config.api.accounts.create(createAccountRequest)
|
||||||
|
|
||||||
await config.api.accounts.create(
|
// Login - Get cookie
|
||||||
createAccountRequest
|
await config.login(
|
||||||
)
|
createAccountRequest.email,
|
||||||
|
createAccountRequest.password,
|
||||||
|
createAccountRequest.tenantId
|
||||||
|
)
|
||||||
|
|
||||||
// Login - Get cookie
|
// Delete account
|
||||||
await config.login(
|
const res = await config.api.accounts.deleteCurrentAccount()
|
||||||
createAccountRequest.email,
|
expect(res.status).toBe(204)
|
||||||
createAccountRequest.password,
|
})
|
||||||
createAccountRequest.tenantId
|
|
||||||
)
|
|
||||||
|
|
||||||
// Delete account
|
|
||||||
const [ res ] = await config.api.accounts.deleteCurrentAccount()
|
|
||||||
|
|
||||||
expect(res.status).toBe(204)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Deletes an account by ID", async () => {
|
it("Deletes an account by ID", async () => {
|
||||||
|
|
|
@ -40,6 +40,30 @@ export default class BudibaseTestConfiguration {
|
||||||
|
|
||||||
// AUTH
|
// 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) {
|
async login(email: string, password: string, tenantId?: string) {
|
||||||
if (!tenantId && this.state.tenantId) {
|
if (!tenantId && this.state.tenantId) {
|
||||||
tenantId = this.state.tenantId
|
tenantId = this.state.tenantId
|
||||||
|
|
Loading…
Reference in New Issue