From fa94b8b9fc43f8a58e130daa9ca7946821b585ab Mon Sep 17 00:00:00 2001 From: Mitch-Budibase Date: Fri, 14 Jul 2023 14:24:01 +0100 Subject: [PATCH] Changes for Account API Testing --- .../worker/src/api/controllers/global/auth.ts | 2 ++ .../src/account-api/api/apis/AccountAPI.ts | 7 ++++++ qa-core/src/account-api/api/apis/AuthAPI.ts | 2 +- .../account-api/config/TestConfiguration.ts | 6 ++--- .../account-api/tests/accounts/create.spec.ts | 2 +- .../account-api/tests/accounts/delete.spec.ts | 23 ++++++++++++++++--- .../tests/accounts/validate.spec.ts | 2 ++ .../account-api/tests/accounts/verify.spec.ts | 14 +++++++++++ .../src/shared/BudibaseTestConfiguration.ts | 3 ++- 9 files changed, 51 insertions(+), 10 deletions(-) diff --git a/packages/worker/src/api/controllers/global/auth.ts b/packages/worker/src/api/controllers/global/auth.ts index 131601c6ad..a458a98aa7 100644 --- a/packages/worker/src/api/controllers/global/auth.ts +++ b/packages/worker/src/api/controllers/global/auth.ts @@ -53,6 +53,8 @@ async function passportCallback( } export const login = async (ctx: Ctx, next: any) => { + const tenantId = context.getTenantId() + console.log(tenantId) const email = ctx.request.body.username const user = await userSdk.getUserByEmail(email) diff --git a/qa-core/src/account-api/api/apis/AccountAPI.ts b/qa-core/src/account-api/api/apis/AccountAPI.ts index 0e457c07e8..7897a3c210 100644 --- a/qa-core/src/account-api/api/apis/AccountAPI.ts +++ b/qa-core/src/account-api/api/apis/AccountAPI.ts @@ -73,6 +73,13 @@ export default class AccountAPI { return response } + async deleteCurrentAccount() { + const [response, json] = await this.client.del( + `/api/accounts` + ) + return response + } + async verifyAccount( verificationCode: string, opts: APIRequestOpts = { doExpect: true } diff --git a/qa-core/src/account-api/api/apis/AuthAPI.ts b/qa-core/src/account-api/api/apis/AuthAPI.ts index 4d2dee6a0d..9c375d2b5d 100644 --- a/qa-core/src/account-api/api/apis/AuthAPI.ts +++ b/qa-core/src/account-api/api/apis/AuthAPI.ts @@ -18,7 +18,7 @@ export default class AuthAPI { `/api/auth/login`, { body: { - username: email, + email: email, password: password, }, } diff --git a/qa-core/src/account-api/config/TestConfiguration.ts b/qa-core/src/account-api/config/TestConfiguration.ts index 827cee42b7..ee5f3fbd45 100644 --- a/qa-core/src/account-api/config/TestConfiguration.ts +++ b/qa-core/src/account-api/config/TestConfiguration.ts @@ -27,8 +27,6 @@ export default class TestConfiguration extends BudibaseTestConfiguration { this.state.apiKey = apiKeyResponse.apiKey } - async setCookieAuth() { - const apiKeyResponse = await this.internalApi.self.getApiKey() - this.state.apiKey = apiKeyResponse.apiKey - } + + } diff --git a/qa-core/src/account-api/tests/accounts/create.spec.ts b/qa-core/src/account-api/tests/accounts/create.spec.ts index e46a56e591..2c26c5170b 100644 --- a/qa-core/src/account-api/tests/accounts/create.spec.ts +++ b/qa-core/src/account-api/tests/accounts/create.spec.ts @@ -14,7 +14,7 @@ describe("Account API - Create Account", () => { it("Creates a new account", async () => { await config.api.accounts.create({ - ...fixtures.accounts.generateAccount() + ...fixtures.accounts.generateAccount() }) }) }) \ No newline at end of file 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 22fd39d17f..20df48dafb 100644 --- a/qa-core/src/account-api/tests/accounts/delete.spec.ts +++ b/qa-core/src/account-api/tests/accounts/delete.spec.ts @@ -12,9 +12,26 @@ describe("Account API - Delete Account", () => { await config.afterAll() }) - // it("Deletes an account", async () => { - // - // }) + it("Deletes an account", async () => { + // Create account + const createAccountRequest = fixtures.accounts.generateAccount() + + await config.api.accounts.create( + createAccountRequest + ) + + // 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) + }) it("Deletes an account by ID", async () => { const [response, account] = await config.api.accounts.create({ diff --git a/qa-core/src/account-api/tests/accounts/validate.spec.ts b/qa-core/src/account-api/tests/accounts/validate.spec.ts index 56894bb03f..5794949eee 100644 --- a/qa-core/src/account-api/tests/accounts/validate.spec.ts +++ b/qa-core/src/account-api/tests/accounts/validate.spec.ts @@ -18,10 +18,12 @@ describe("Account API - Validate Account", () => { it("Validates an email", async () => { + await config.api.accounts.validateEmail(email) }) it("Validates a tenant ID", async () => { + await config.api.accounts.validateTenantId(tenant) }) }) \ No newline at end of file diff --git a/qa-core/src/account-api/tests/accounts/verify.spec.ts b/qa-core/src/account-api/tests/accounts/verify.spec.ts index d3f2ff1a18..222c4cb4ea 100644 --- a/qa-core/src/account-api/tests/accounts/verify.spec.ts +++ b/qa-core/src/account-api/tests/accounts/verify.spec.ts @@ -15,10 +15,24 @@ describe("Account API - Verify Account", () => { it("Verify an account", async () => { + // Create account + await config.api.accounts.create({ + ...fixtures.accounts.generateAccount() + }) + // Invite user + + // Verify account via code await config.api.accounts.verifyAccount() }) it("Send account verification email ", async () => { + // Create account + await config.api.accounts.create({ + ...fixtures.accounts.generateAccount() + }) + // Invite user + + // Verify account via email await config.api.accounts.verifyAccountSendEmail() }) }) \ No newline at end of file diff --git a/qa-core/src/shared/BudibaseTestConfiguration.ts b/qa-core/src/shared/BudibaseTestConfiguration.ts index 12a0f16138..d8fd2bee61 100644 --- a/qa-core/src/shared/BudibaseTestConfiguration.ts +++ b/qa-core/src/shared/BudibaseTestConfiguration.ts @@ -43,7 +43,8 @@ export default class BudibaseTestConfiguration { async login(email: string, password: string, tenantId?: string) { if (!tenantId && this.state.tenantId) { tenantId = this.state.tenantId - } else { + } + if (!tenantId) { throw new Error("Could not determine tenant id") } const [res, cookie] = await this.internalApi.auth.login(