1
0
Fork 0
mirror of synced 2024-10-02 10:08:09 +13:00

Add state helpers for isolating account deletion test

This commit is contained in:
Rory Powell 2023-07-14 15:03:51 +01:00
parent fa94b8b9fc
commit f45a439b26
2 changed files with 38 additions and 16 deletions

View file

@ -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 () => {

View file

@ -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