diff --git a/qa-core/src/account-api/api/apis/AccountAPI.ts b/qa-core/src/account-api/api/apis/AccountAPI.ts index 7897a3c210..37aa3313ba 100644 --- a/qa-core/src/account-api/api/apis/AccountAPI.ts +++ b/qa-core/src/account-api/api/apis/AccountAPI.ts @@ -1,5 +1,5 @@ import { Response } from "node-fetch" -import { Account, CreateAccountRequest } from "@budibase/types" +import { Account, CreateAccountRequest, SearchAccountsRequest, SearchAccountsResponse } from "@budibase/types" import AccountInternalAPIClient from "../AccountInternalAPIClient" import { APIRequestOpts } from "../../../types" @@ -116,8 +116,8 @@ export default class AccountAPI { searchType: string, search: 'email' | 'tenantId', opts: APIRequestOpts = { doExpect: true } - ): Promise { - let body: { email?: string; tenantId?: string } = {} + ): Promise<[Response, SearchAccountsResponse]> { + let body: SearchAccountsRequest = {} if (search === 'email') { body.email = searchType; @@ -132,6 +132,6 @@ export default class AccountAPI { if (opts.doExpect) { expect(response).toHaveStatusCode(200) } - return response + return [response, json] } } diff --git a/qa-core/src/account-api/config/TestConfiguration.ts b/qa-core/src/account-api/config/TestConfiguration.ts index ee5f3fbd45..6322be97f0 100644 --- a/qa-core/src/account-api/config/TestConfiguration.ts +++ b/qa-core/src/account-api/config/TestConfiguration.ts @@ -26,7 +26,4 @@ export default class TestConfiguration extends BudibaseTestConfiguration { const apiKeyResponse = await this.internalApi.self.getApiKey() this.state.apiKey = apiKeyResponse.apiKey } - - - } diff --git a/qa-core/src/account-api/tests/accounts/search.spec.ts b/qa-core/src/account-api/tests/accounts/search.spec.ts index 6f4437d119..a39cf8e325 100644 --- a/qa-core/src/account-api/tests/accounts/search.spec.ts +++ b/qa-core/src/account-api/tests/accounts/search.spec.ts @@ -12,11 +12,32 @@ describe("Account API - Search for Account", () => { await config.afterAll() }) - it("Search account by email", async () => { - await config.api.accounts.search(generator.email(), "email") - }) - it("Search account by tenantId", async () => { - await config.api.accounts.search(generator.word(), "tenantId") + describe("POST /api/accounts/search", () => { + describe("by tenant", () => { + it("returns 200 + empty", async () => { + const tenantId = generator.string() + const [res, body] = await config.api.accounts.search(tenantId, "tenantId") + expect(res.status).toBe(200) + expect(body.length).toBe(0) + }) + + it("returns 200 + found", async () => { + const [res, body] = await config.api.accounts.search(config.state.tenantId!, "tenantId") + expect(res.status).toBe(200) + expect(body.length).toBe(1) + expect(body[0].tenantId).toBe(config.state.tenantId) + }) + }) + + describe("by email", () => { + it("returns 200 + empty", async () => { + await config.api.accounts.search(generator.word(), "email") + }) + + it("returns 200 + found", async () => { + await config.api.accounts.search(generator.word(), "email") + }) + }) }) }) \ No newline at end of file diff --git a/qa-core/src/jest/globalSetup.ts b/qa-core/src/jest/globalSetup.ts index f73ea1011e..e52f8cfe16 100644 --- a/qa-core/src/jest/globalSetup.ts +++ b/qa-core/src/jest/globalSetup.ts @@ -89,6 +89,8 @@ async function setup() { // @ts-ignore global.qa.tenantId = account.tenantId // @ts-ignore + global.qa.email = account.email + // @ts-ignore global.qa.accountId = newAccount.accountId await loginAsAccount(account) } else { diff --git a/qa-core/src/shared/BudibaseTestConfiguration.ts b/qa-core/src/shared/BudibaseTestConfiguration.ts index c1aaeb0cae..c6955fd87f 100644 --- a/qa-core/src/shared/BudibaseTestConfiguration.ts +++ b/qa-core/src/shared/BudibaseTestConfiguration.ts @@ -23,6 +23,8 @@ export default class BudibaseTestConfiguration { // @ts-ignore this.state.tenantId = global.qa.tenantId // @ts-ignore + this.state.email = global.qa.email + // @ts-ignore this.state.cookie = global.qa.authCookie } @@ -53,6 +55,7 @@ export default class BudibaseTestConfiguration { this.state.cookie = state.cookie this.state.tableId = state.tableId this.state.tenantId = state.tenantId + this.state.email = state.email await task() @@ -62,6 +65,7 @@ export default class BudibaseTestConfiguration { this.state.cookie = original.cookie this.state.tableId = original.tableId this.state.tenantId = original.tenantId + this.state.email = original.email } async login(email: string, password: string, tenantId?: string) { diff --git a/qa-core/src/types/state.ts b/qa-core/src/types/state.ts index 0da471e090..8fab3998ce 100644 --- a/qa-core/src/types/state.ts +++ b/qa-core/src/types/state.ts @@ -4,4 +4,5 @@ export interface State { cookie?: string tableId?: string tenantId?: string + email?: string }