From 9474d249080eb25c27a4abd73608fbb814ca5425 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Thu, 23 Feb 2023 16:32:42 +0000 Subject: [PATCH 01/11] Add base for multiple environment support --- .../TestConfiguration/InternalAPIClient.ts | 2 - .../TestConfiguration/PublicAPIClient.ts | 26 ++++++-- .../public-api/TestConfiguration/accounts.ts | 38 +++++++++++ .../TestConfiguration/accountsAPIClient.ts | 64 +++++++++++++++++++ .../public-api/TestConfiguration/auth.ts | 48 ++++++++++++++ .../public-api/TestConfiguration/index.ts | 41 +++++++++++- .../config/public-api/fixtures/accounts.ts | 21 ++++++ .../fixtures/types/apiKeyResponse.ts | 6 ++ .../public-api/fixtures/types/newAccount.ts | 5 ++ .../applications/applications.spec.ts | 4 +- .../src/tests/public-api/tables/rows.spec.ts | 7 +- .../tests/public-api/tables/tables.spec.ts | 6 +- .../src/tests/public-api/users/users.spec.ts | 4 +- 13 files changed, 256 insertions(+), 16 deletions(-) create mode 100644 qa-core/src/config/public-api/TestConfiguration/accounts.ts create mode 100644 qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts create mode 100644 qa-core/src/config/public-api/TestConfiguration/auth.ts create mode 100644 qa-core/src/config/public-api/fixtures/accounts.ts create mode 100644 qa-core/src/config/public-api/fixtures/types/apiKeyResponse.ts create mode 100644 qa-core/src/config/public-api/fixtures/types/newAccount.ts diff --git a/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts b/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts index ef47d8a12b..ce33a623b2 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts @@ -55,8 +55,6 @@ class InternalAPIClient { console.error(response) console.error("Response body:") console.error(response.body) - console.error("Request body:") - console.error(requestOptions.body) } return response } diff --git a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts index 3721e31da3..14bc93ef06 100644 --- a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts +++ b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts @@ -11,20 +11,29 @@ interface ApiOptions { class PublicAPIClient { host: string - apiKey: string + apiKey?: string + tenantName?: string appId?: string + cookie?: string constructor(appId?: string) { - if (!env.BUDIBASE_PUBLIC_API_KEY || !env.BUDIBASE_SERVER_URL) { + if (!env.BUDIBASE_HOST) { throw new Error( "Must set BUDIBASE_PUBLIC_API_KEY and BUDIBASE_SERVER_URL env vars" ) } - this.host = `${env.BUDIBASE_SERVER_URL}/api/public/v1` - this.apiKey = env.BUDIBASE_PUBLIC_API_KEY + this.host = `${env.BUDIBASE_HOST}/api/public/v1` this.appId = appId } + setTenantName(tenantName: string) { + this.tenantName = tenantName + } + + setApiKey(apiKey: string) { + this.apiKey = apiKey + } + apiCall = (method: APIMethod) => async (url = "", options: ApiOptions = {}) => { @@ -32,16 +41,21 @@ class PublicAPIClient { method, body: JSON.stringify(options.body), headers: { - "x-budibase-api-key": this.apiKey, + "x-budibase-api-key": this.apiKey ? this.apiKey : null, "x-budibase-app-id": this.appId, "Content-Type": "application/json", Accept: "application/json", ...options.headers, + cookie: this.cookie, + redirect: "follow", + follow: 20, }, } + // prettier-ignore // @ts-ignore - const response = await fetch(`${this.host}${url}`, requestOptions) + const response = await fetch(`https://${process.env.TENANT_ID}.${this.host}${url}`, requestOptions) + if (response.status !== 200) { console.error(response) } diff --git a/qa-core/src/config/public-api/TestConfiguration/accounts.ts b/qa-core/src/config/public-api/TestConfiguration/accounts.ts new file mode 100644 index 0000000000..fdf5aedbd0 --- /dev/null +++ b/qa-core/src/config/public-api/TestConfiguration/accounts.ts @@ -0,0 +1,38 @@ +import { Response } from "node-fetch" +import { Account } from "@budibase/types" +import AccountsAPIClient from "./accountsAPIClient" +import { NewAccount } from "../fixtures/types/newAccount" + +export default class AccountsApi { + api: AccountsAPIClient + + constructor(AccountsAPIClient: AccountsAPIClient) { + this.api = AccountsAPIClient + } + + async validateEmail(email: string): Promise { + const response = await this.api.post(`/accounts/validate/email`, { + body: { email }, + }) + expect(response).toHaveStatusCode(200) + return response + } + + async validateTenantId(tenantId: string): Promise { + const response = await this.api.post(`/accounts/validate/tenantId`, { + body: { tenantId }, + }) + expect(response).toHaveStatusCode(200) + return response + } + + async create(body: Partial): Promise<[Response, Account]> { + const headers = { + "no-verify": "1", + } + const response = await this.api.post(`/accounts`, { body, headers }) + const json = await response.json() + expect(response).toHaveStatusCode(201) + return [response, json] + } +} diff --git a/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts b/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts new file mode 100644 index 0000000000..aff821a7ac --- /dev/null +++ b/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts @@ -0,0 +1,64 @@ +import env from "../../../environment" +import fetch, { HeadersInit } from "node-fetch" + +type APIMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" + +interface ApiOptions { + method?: APIMethod + body?: object + headers?: HeadersInit | undefined +} + +class AccountsAPIClient { + host: string + appId?: string + cookie?: string + + constructor(appId?: string) { + if (!env.BUDIBASE_ACCOUNTS_URL) { + throw new Error("Must set BUDIBASE_SERVER_URL env var") + } + this.host = `${env.BUDIBASE_ACCOUNTS_URL}/api` + this.appId = appId + } + + apiCall = + (method: APIMethod) => + async (url = "", options: ApiOptions = {}) => { + const requestOptions = { + method, + body: JSON.stringify(options.body), + headers: { + "x-budibase-app-id": this.appId, + "Content-Type": "application/json", + Accept: "application/json", + cookie: this.cookie, + redirect: "follow", + follow: 20, + ...options.headers, + }, + credentials: "include", + } + + // @ts-ignore + const response = await fetch(`${this.host}${url}`, requestOptions) + if (response.status == 404 || response.status == 500) { + console.error("Error in apiCall") + console.error("Response:") + console.error(response) + console.error("Response body:") + console.error(response.body) + console.error("Request body:") + console.error(requestOptions.body) + } + return response + } + + post = this.apiCall("POST") + get = this.apiCall("GET") + patch = this.apiCall("PATCH") + del = this.apiCall("DELETE") + put = this.apiCall("PUT") +} + +export default AccountsAPIClient diff --git a/qa-core/src/config/public-api/TestConfiguration/auth.ts b/qa-core/src/config/public-api/TestConfiguration/auth.ts new file mode 100644 index 0000000000..663b39e5e9 --- /dev/null +++ b/qa-core/src/config/public-api/TestConfiguration/auth.ts @@ -0,0 +1,48 @@ +import { Response } from "node-fetch" +import PublicAPIClient from "./PublicAPIClient" +import { ApiKeyResponse } from "../fixtures/types/apiKeyResponse" + +export default class AuthApi { + api: PublicAPIClient + + constructor(apiClient: PublicAPIClient) { + this.api = apiClient + } + + async loginAsAdmin(): Promise<[Response, any]> { + const response = await this.api.post(`/global/auth/default/login`, { + body: { + username: process.env.BB_ADMIN_USER_EMAIL, + password: process.env.BB_ADMIN_USER_PASSWORD, + }, + }) + const cookie = response.headers.get("set-cookie") + this.api.cookie = cookie as any + return [response, cookie] + } + + async login(email: String, password: String): Promise<[Response, any]> { + const response = await this.api.post(`/global/auth/default/login`, { + body: { + username: email, + password: password, + }, + }) + expect(response).toHaveStatusCode(200) + const cookie = response.headers.get("set-cookie") + this.api.cookie = cookie as any + return [response, cookie] + } + + async logout(): Promise { + return this.api.post(`/global/auth/logout`) + } + + async getApiKey(): Promise { + const response = await this.api.get(`/global/self/api_key`) + const json = await response.json() + expect(response).toHaveStatusCode(200) + expect(json).toHaveProperty("apiKey") + return json + } +} diff --git a/qa-core/src/config/public-api/TestConfiguration/index.ts b/qa-core/src/config/public-api/TestConfiguration/index.ts index 36cc3022b0..1a760ae883 100644 --- a/qa-core/src/config/public-api/TestConfiguration/index.ts +++ b/qa-core/src/config/public-api/TestConfiguration/index.ts @@ -3,15 +3,31 @@ import ApplicationApi from "./applications" import TableApi from "./tables" import UserApi from "./users" import RowApi from "./rows" +import AuthApi from "./auth" +import AccountsApiClient from "./accountsAPIClient" +import AccountsApi from "./accounts" +import { generateAccount } from "../fixtures/accounts" export default class TestConfiguration { applications: ApplicationApi + auth: AuthApi users: UserApi tables: TableApi rows: RowApi context: T + accounts: AccountsApi + apiClient: PublicAPIClient + accountsApiClient: AccountsApiClient - constructor(apiClient: PublicAPIClient) { + constructor( + apiClient: PublicAPIClient, + accountsApiClient: AccountsApiClient + ) { + this.apiClient = apiClient + this.accountsApiClient = accountsApiClient + + this.auth = new AuthApi(this.apiClient) + this.accounts = new AccountsApi(this.accountsApiClient) this.applications = new ApplicationApi(apiClient) this.users = new UserApi(apiClient) this.tables = new TableApi(apiClient) @@ -19,6 +35,29 @@ export default class TestConfiguration { this.context = {} } + async setupAccountAndTenant() { + const account = generateAccount() + await this.accounts.validateEmail(account.email) + await this.accounts.validateTenantId(account.tenantId) + process.env.TENANT_ID = account.tenantId + await this.accounts.create(account) + await this.updateApiClients(account.tenantName) + await this.auth.login(account.email, account.password) + } + + async setApiKey() { + const apiKeyResponse = await this.auth.getApiKey() + this.apiClient.setApiKey(apiKeyResponse.apiKey) + } + async updateApiClients(tenantName: string) { + this.apiClient.setTenantName(tenantName) + this.applications = new ApplicationApi(this.apiClient) + this.rows = new RowApi(this.apiClient) + this.auth = new AuthApi(this.apiClient) + + this.context = {} + } + async beforeAll() {} async afterAll() { diff --git a/qa-core/src/config/public-api/fixtures/accounts.ts b/qa-core/src/config/public-api/fixtures/accounts.ts new file mode 100644 index 0000000000..dbeabae928 --- /dev/null +++ b/qa-core/src/config/public-api/fixtures/accounts.ts @@ -0,0 +1,21 @@ +import { NewAccount } from "./types/newAccount" + +import generator from "../../generator" +import { Hosting } from "@budibase/types" + +export const generateAccount = (): Partial => { + const randomGuid = generator.guid() + let tenant: string = "a" + randomGuid + tenant = tenant.replace(/-/g, "") + + return { + email: `qa+${randomGuid}@budibase.com`, + hosting: Hosting.CLOUD, + name: `qa+${randomGuid}@budibase.com`, + password: `${randomGuid}`, + profession: "software_engineer", + size: "10+", + tenantId: `${tenant}`, + tenantName: `${tenant}`, + } +} diff --git a/qa-core/src/config/public-api/fixtures/types/apiKeyResponse.ts b/qa-core/src/config/public-api/fixtures/types/apiKeyResponse.ts new file mode 100644 index 0000000000..4a62d60796 --- /dev/null +++ b/qa-core/src/config/public-api/fixtures/types/apiKeyResponse.ts @@ -0,0 +1,6 @@ +export interface ApiKeyResponse { + apiKey: string + createdAt: string + updatedAt: string + userId: string +} diff --git a/qa-core/src/config/public-api/fixtures/types/newAccount.ts b/qa-core/src/config/public-api/fixtures/types/newAccount.ts new file mode 100644 index 0000000000..e7ad88e697 --- /dev/null +++ b/qa-core/src/config/public-api/fixtures/types/newAccount.ts @@ -0,0 +1,5 @@ +import { Account } from "@budibase/types" + +export interface NewAccount extends Account { + password: string +} diff --git a/qa-core/src/tests/public-api/applications/applications.spec.ts b/qa-core/src/tests/public-api/applications/applications.spec.ts index cf85e6daf2..4a8751ce56 100644 --- a/qa-core/src/tests/public-api/applications/applications.spec.ts +++ b/qa-core/src/tests/public-api/applications/applications.spec.ts @@ -1,12 +1,14 @@ import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" +import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient" import generateApp from "../../../config/public-api/fixtures/applications" import { Application } from "@budibase/server/api/controllers/public/mapping/types" import { db as dbCore } from "@budibase/backend-core" describe("Public API - /applications endpoints", () => { const api = new PublicAPIClient() - const config = new TestConfiguration(api) + const accountsAPI = new AccountsAPIClient() + const config = new TestConfiguration(api, accountsAPI) beforeAll(async () => { await config.beforeAll() diff --git a/qa-core/src/tests/public-api/tables/rows.spec.ts b/qa-core/src/tests/public-api/tables/rows.spec.ts index 89149159ab..87dbd509cc 100644 --- a/qa-core/src/tests/public-api/tables/rows.spec.ts +++ b/qa-core/src/tests/public-api/tables/rows.spec.ts @@ -2,11 +2,12 @@ import { Row } from "@budibase/server/api/controllers/public/mapping/types" import { generateRow } from "../../../config/public-api/fixtures/tables" import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" +import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient" describe("Public API - /rows endpoints", () => { - let api = new PublicAPIClient() - - const config = new TestConfiguration(api) + const api = new PublicAPIClient() + const accountsAPI = new AccountsAPIClient() + const config = new TestConfiguration(api, accountsAPI) beforeAll(async () => { await config.beforeAll() diff --git a/qa-core/src/tests/public-api/tables/tables.spec.ts b/qa-core/src/tests/public-api/tables/tables.spec.ts index de1ce142ce..d0601d0835 100644 --- a/qa-core/src/tests/public-api/tables/tables.spec.ts +++ b/qa-core/src/tests/public-api/tables/tables.spec.ts @@ -2,10 +2,12 @@ import { Table } from "@budibase/server/api/controllers/public/mapping/types" import { generateTable } from "../../../config/public-api/fixtures/tables" import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" +import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient" describe("Public API - /tables endpoints", () => { - let api = new PublicAPIClient() - const config = new TestConfiguration(api) + const api = new PublicAPIClient() + const accountsAPI = new AccountsAPIClient() + const config = new TestConfiguration
(api, accountsAPI) beforeAll(async () => { await config.beforeAll() diff --git a/qa-core/src/tests/public-api/users/users.spec.ts b/qa-core/src/tests/public-api/users/users.spec.ts index 5e68c77c50..edc675fd81 100644 --- a/qa-core/src/tests/public-api/users/users.spec.ts +++ b/qa-core/src/tests/public-api/users/users.spec.ts @@ -2,10 +2,12 @@ import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" import generateUser from "../../../config/public-api/fixtures/users" import { User } from "@budibase/server/api/controllers/public/mapping/types" +import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient" describe("Public API - /users endpoints", () => { const api = new PublicAPIClient() - const config = new TestConfiguration(api) + const accountsAPI = new AccountsAPIClient() + const config = new TestConfiguration(api, accountsAPI) beforeAll(async () => { await config.beforeAll() From 655b235b7603b5b6054b9665d13084cd328911ff Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 24 Feb 2023 09:46:05 +0000 Subject: [PATCH 02/11] Auth flow --- .../public-api/TestConfiguration/PublicAPIClient.ts | 3 +++ .../src/config/public-api/TestConfiguration/auth.ts | 10 +++++----- qa-core/src/tests/public-api/users/users.spec.ts | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts index 14bc93ef06..0cff3eb840 100644 --- a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts +++ b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts @@ -23,6 +23,7 @@ class PublicAPIClient { ) } this.host = `${env.BUDIBASE_HOST}/api/public/v1` + this.appId = appId } @@ -32,6 +33,8 @@ class PublicAPIClient { setApiKey(apiKey: string) { this.apiKey = apiKey + process.env.BUDIBASE_PUBLIC_API_KEY = apiKey + this.host = `${env.BUDIBASE_HOST}/api/public/v1` } apiCall = diff --git a/qa-core/src/config/public-api/TestConfiguration/auth.ts b/qa-core/src/config/public-api/TestConfiguration/auth.ts index 663b39e5e9..b832d6f7f9 100644 --- a/qa-core/src/config/public-api/TestConfiguration/auth.ts +++ b/qa-core/src/config/public-api/TestConfiguration/auth.ts @@ -1,16 +1,16 @@ import { Response } from "node-fetch" -import PublicAPIClient from "./PublicAPIClient" +import AccountsAPIClient from "./accountsAPIClient" import { ApiKeyResponse } from "../fixtures/types/apiKeyResponse" export default class AuthApi { - api: PublicAPIClient + api: AccountsAPIClient - constructor(apiClient: PublicAPIClient) { + constructor(apiClient: AccountsAPIClient) { this.api = apiClient } async loginAsAdmin(): Promise<[Response, any]> { - const response = await this.api.post(`/global/auth/default/login`, { + const response = await this.api.post(`/auth/login`, { body: { username: process.env.BB_ADMIN_USER_EMAIL, password: process.env.BB_ADMIN_USER_PASSWORD, @@ -22,7 +22,7 @@ export default class AuthApi { } async login(email: String, password: String): Promise<[Response, any]> { - const response = await this.api.post(`/global/auth/default/login`, { + const response = await this.api.post(`/auth/login`, { body: { username: email, password: password, diff --git a/qa-core/src/tests/public-api/users/users.spec.ts b/qa-core/src/tests/public-api/users/users.spec.ts index edc675fd81..7f53a95057 100644 --- a/qa-core/src/tests/public-api/users/users.spec.ts +++ b/qa-core/src/tests/public-api/users/users.spec.ts @@ -11,6 +11,8 @@ describe("Public API - /users endpoints", () => { beforeAll(async () => { await config.beforeAll() + await config.setupAccountAndTenant() + await config.setApiKey() const [_, user] = await config.users.seed() config.context = user }) From 6a3fa60078670ea4ac4bbc36f7212fde3ffdff30 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Wed, 1 Mar 2023 11:46:26 +0000 Subject: [PATCH 03/11] Remove Env public api key --- qa-core/.env | 1 - .../public-api/TestConfiguration/accountsAPIClient.ts | 6 +++++- qa-core/src/config/public-api/TestConfiguration/index.ts | 3 +-- .../src/tests/public-api/applications/applications.spec.ts | 2 +- qa-core/src/tests/public-api/tables/rows.spec.ts | 2 +- qa-core/src/tests/public-api/tables/tables.spec.ts | 2 +- qa-core/src/tests/public-api/users/users.spec.ts | 1 - 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/qa-core/.env b/qa-core/.env index 096fb4e157..be24fd2d28 100644 --- a/qa-core/.env +++ b/qa-core/.env @@ -1,6 +1,5 @@ BB_ADMIN_USER_EMAIL=qa@budibase.com BB_ADMIN_USER_PASSWORD=budibase -ENCRYPTED_TEST_PUBLIC_API_KEY=a65722f06bee5caeadc5d7ca2f543a43-d610e627344210c643bb726f COUCH_DB_URL=http://budibase:budibase@localhost:4567 COUCH_DB_USER=budibase COUCH_DB_PASSWORD=budibase diff --git a/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts b/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts index aff821a7ac..f009084f0c 100644 --- a/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts +++ b/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts @@ -42,7 +42,11 @@ class AccountsAPIClient { // @ts-ignore const response = await fetch(`${this.host}${url}`, requestOptions) - if (response.status == 404 || response.status == 500) { + if ( + response.status == 404 || + response.status == 500 || + response.status == 400 + ) { console.error("Error in apiCall") console.error("Response:") console.error(response) diff --git a/qa-core/src/config/public-api/TestConfiguration/index.ts b/qa-core/src/config/public-api/TestConfiguration/index.ts index 1a760ae883..259742d7c3 100644 --- a/qa-core/src/config/public-api/TestConfiguration/index.ts +++ b/qa-core/src/config/public-api/TestConfiguration/index.ts @@ -26,7 +26,7 @@ export default class TestConfiguration { this.apiClient = apiClient this.accountsApiClient = accountsApiClient - this.auth = new AuthApi(this.apiClient) + this.auth = new AuthApi(this.accountsApiClient) this.accounts = new AccountsApi(this.accountsApiClient) this.applications = new ApplicationApi(apiClient) this.users = new UserApi(apiClient) @@ -53,7 +53,6 @@ export default class TestConfiguration { this.apiClient.setTenantName(tenantName) this.applications = new ApplicationApi(this.apiClient) this.rows = new RowApi(this.apiClient) - this.auth = new AuthApi(this.apiClient) this.context = {} } diff --git a/qa-core/src/tests/public-api/applications/applications.spec.ts b/qa-core/src/tests/public-api/applications/applications.spec.ts index 4a8751ce56..e651194452 100644 --- a/qa-core/src/tests/public-api/applications/applications.spec.ts +++ b/qa-core/src/tests/public-api/applications/applications.spec.ts @@ -5,7 +5,7 @@ import generateApp from "../../../config/public-api/fixtures/applications" import { Application } from "@budibase/server/api/controllers/public/mapping/types" import { db as dbCore } from "@budibase/backend-core" -describe("Public API - /applications endpoints", () => { +describe.skip("Public API - /applications endpoints", () => { const api = new PublicAPIClient() const accountsAPI = new AccountsAPIClient() const config = new TestConfiguration(api, accountsAPI) diff --git a/qa-core/src/tests/public-api/tables/rows.spec.ts b/qa-core/src/tests/public-api/tables/rows.spec.ts index 87dbd509cc..3cb339570d 100644 --- a/qa-core/src/tests/public-api/tables/rows.spec.ts +++ b/qa-core/src/tests/public-api/tables/rows.spec.ts @@ -4,7 +4,7 @@ import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient" -describe("Public API - /rows endpoints", () => { +describe.skip("Public API - /rows endpoints", () => { const api = new PublicAPIClient() const accountsAPI = new AccountsAPIClient() const config = new TestConfiguration(api, accountsAPI) diff --git a/qa-core/src/tests/public-api/tables/tables.spec.ts b/qa-core/src/tests/public-api/tables/tables.spec.ts index d0601d0835..5d96194599 100644 --- a/qa-core/src/tests/public-api/tables/tables.spec.ts +++ b/qa-core/src/tests/public-api/tables/tables.spec.ts @@ -4,7 +4,7 @@ import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient" -describe("Public API - /tables endpoints", () => { +describe.skip("Public API - /tables endpoints", () => { const api = new PublicAPIClient() const accountsAPI = new AccountsAPIClient() const config = new TestConfiguration
(api, accountsAPI) diff --git a/qa-core/src/tests/public-api/users/users.spec.ts b/qa-core/src/tests/public-api/users/users.spec.ts index 7f53a95057..d72b265386 100644 --- a/qa-core/src/tests/public-api/users/users.spec.ts +++ b/qa-core/src/tests/public-api/users/users.spec.ts @@ -10,7 +10,6 @@ describe("Public API - /users endpoints", () => { const config = new TestConfiguration(api, accountsAPI) beforeAll(async () => { - await config.beforeAll() await config.setupAccountAndTenant() await config.setApiKey() const [_, user] = await config.users.seed() From dfff64b847a744cffdc860c143b96ff8ad6bb6d4 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Thu, 2 Mar 2023 15:17:17 +0000 Subject: [PATCH 04/11] Add firstApp creation to public api tests --- .../public-api/TestConfiguration/accountsAPIClient.ts | 3 --- .../public-api/TestConfiguration/applications.ts | 11 +++++++++++ .../src/config/public-api/TestConfiguration/auth.ts | 2 +- .../src/config/public-api/TestConfiguration/index.ts | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts b/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts index f009084f0c..44b69aa247 100644 --- a/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts +++ b/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts @@ -48,11 +48,8 @@ class AccountsAPIClient { response.status == 400 ) { console.error("Error in apiCall") - console.error("Response:") console.error(response) - console.error("Response body:") console.error(response.body) - console.error("Request body:") console.error(requestOptions.body) } return response diff --git a/qa-core/src/config/public-api/TestConfiguration/applications.ts b/qa-core/src/config/public-api/TestConfiguration/applications.ts index ab25930544..56b0b70795 100644 --- a/qa-core/src/config/public-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/public-api/TestConfiguration/applications.ts @@ -63,4 +63,15 @@ export default class AppApi { const response = await this.api.post(`/applications/${id}/unpublish`) return [response] } + + async createFirstApp() { + const body = { + name: "My first app", + url: "my-first-app", + useTemplate: false, + sampleData: true, + } + const response = await this.api.post("/applications", { body }) + expect(response).toHaveStatusCode(200) + } } diff --git a/qa-core/src/config/public-api/TestConfiguration/auth.ts b/qa-core/src/config/public-api/TestConfiguration/auth.ts index b832d6f7f9..ceb10b8bfc 100644 --- a/qa-core/src/config/public-api/TestConfiguration/auth.ts +++ b/qa-core/src/config/public-api/TestConfiguration/auth.ts @@ -24,7 +24,7 @@ export default class AuthApi { async login(email: String, password: String): Promise<[Response, any]> { const response = await this.api.post(`/auth/login`, { body: { - username: email, + email: email, password: password, }, }) diff --git a/qa-core/src/config/public-api/TestConfiguration/index.ts b/qa-core/src/config/public-api/TestConfiguration/index.ts index 259742d7c3..fc2d2fd572 100644 --- a/qa-core/src/config/public-api/TestConfiguration/index.ts +++ b/qa-core/src/config/public-api/TestConfiguration/index.ts @@ -43,6 +43,7 @@ export default class TestConfiguration { await this.accounts.create(account) await this.updateApiClients(account.tenantName) await this.auth.login(account.email, account.password) + await this.applications.createFirstApp() } async setApiKey() { From ca489b531f438ee6238d300197998ad906584778 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Thu, 9 Mar 2023 15:30:27 +0000 Subject: [PATCH 05/11] Fix Login problems --- .../TestConfiguration/InternalAPIClient.ts | 9 ++++-- .../TestConfiguration/PublicAPIClient.ts | 10 ++++++- .../public-api/TestConfiguration/auth.ts | 4 +-- .../public-api/TestConfiguration/index.ts | 29 ++++++++++++++++--- .../applications/applications.spec.ts | 14 +++++++-- .../src/tests/public-api/tables/rows.spec.ts | 10 +++++-- .../tests/public-api/tables/tables.spec.ts | 10 +++++-- .../src/tests/public-api/users/users.spec.ts | 4 ++- 8 files changed, 71 insertions(+), 19 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts b/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts index ce33a623b2..2dc0487095 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts @@ -49,12 +49,17 @@ class InternalAPIClient { // @ts-ignore const response = await fetch(`https://${process.env.TENANT_ID}.${this.host}${url}`, requestOptions) - if (response.status == 404 || response.status == 500) { + if ( + response.status == 404 || + response.status == 500 || + response.status == 403 + ) { console.error("Error in apiCall") console.error("Response:") console.error(response) + const json = await response.json() console.error("Response body:") - console.error(response.body) + console.error(json) } return response } diff --git a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts index 0cff3eb840..d9f4aa4816 100644 --- a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts +++ b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts @@ -59,8 +59,16 @@ class PublicAPIClient { // @ts-ignore const response = await fetch(`https://${process.env.TENANT_ID}.${this.host}${url}`, requestOptions) - if (response.status !== 200) { + if ( + response.status == 404 || + response.status == 500 || + response.status == 403 + ) { + console.error("Error in apiCall") + console.error("Response:") console.error(response) + console.error("Response body:") + console.error(response.body) } return response } diff --git a/qa-core/src/config/public-api/TestConfiguration/auth.ts b/qa-core/src/config/public-api/TestConfiguration/auth.ts index ceb10b8bfc..3eb4df2245 100644 --- a/qa-core/src/config/public-api/TestConfiguration/auth.ts +++ b/qa-core/src/config/public-api/TestConfiguration/auth.ts @@ -22,9 +22,9 @@ export default class AuthApi { } async login(email: String, password: String): Promise<[Response, any]> { - const response = await this.api.post(`/auth/login`, { + const response = await this.api.post(`/global/auth/default/login`, { body: { - email: email, + username: email, password: password, }, }) diff --git a/qa-core/src/config/public-api/TestConfiguration/index.ts b/qa-core/src/config/public-api/TestConfiguration/index.ts index fc2d2fd572..a869448b36 100644 --- a/qa-core/src/config/public-api/TestConfiguration/index.ts +++ b/qa-core/src/config/public-api/TestConfiguration/index.ts @@ -7,6 +7,9 @@ import AuthApi from "./auth" import AccountsApiClient from "./accountsAPIClient" import AccountsApi from "./accounts" import { generateAccount } from "../fixtures/accounts" +import internalApplicationsApi from "../../internal-api/TestConfiguration/applications" + +import InternalAPIClient from "../../internal-api/TestConfiguration/InternalAPIClient" export default class TestConfiguration { applications: ApplicationApi @@ -18,20 +21,28 @@ export default class TestConfiguration { accounts: AccountsApi apiClient: PublicAPIClient accountsApiClient: AccountsApiClient + internalApiClient: InternalAPIClient + internalApplicationsApi: internalApplicationsApi constructor( apiClient: PublicAPIClient, - accountsApiClient: AccountsApiClient + accountsApiClient: AccountsApiClient, + internalApiClient: InternalAPIClient ) { this.apiClient = apiClient this.accountsApiClient = accountsApiClient + this.internalApiClient = internalApiClient - this.auth = new AuthApi(this.accountsApiClient) + this.auth = new AuthApi(this.internalApiClient) this.accounts = new AccountsApi(this.accountsApiClient) this.applications = new ApplicationApi(apiClient) this.users = new UserApi(apiClient) this.tables = new TableApi(apiClient) this.rows = new RowApi(apiClient) + this.internalApplicationsApi = new internalApplicationsApi( + internalApiClient + ) + this.context = {} } @@ -43,7 +54,13 @@ export default class TestConfiguration { await this.accounts.create(account) await this.updateApiClients(account.tenantName) await this.auth.login(account.email, account.password) - await this.applications.createFirstApp() + const body = { + name: "My first app", + url: "my-first-app", + useTemplate: false, + sampleData: true, + } + await this.internalApplicationsApi.create(body) } async setApiKey() { @@ -54,7 +71,11 @@ export default class TestConfiguration { this.apiClient.setTenantName(tenantName) this.applications = new ApplicationApi(this.apiClient) this.rows = new RowApi(this.apiClient) - + this.internalApiClient.setTenantName(tenantName) + this.internalApplicationsApi = new internalApplicationsApi( + this.internalApiClient + ) + this.auth = new AuthApi(this.internalApiClient) this.context = {} } diff --git a/qa-core/src/tests/public-api/applications/applications.spec.ts b/qa-core/src/tests/public-api/applications/applications.spec.ts index e651194452..a5c0ed3691 100644 --- a/qa-core/src/tests/public-api/applications/applications.spec.ts +++ b/qa-core/src/tests/public-api/applications/applications.spec.ts @@ -4,14 +4,22 @@ import AccountsAPIClient from "../../../config/public-api/TestConfiguration/acco import generateApp from "../../../config/public-api/fixtures/applications" import { Application } from "@budibase/server/api/controllers/public/mapping/types" import { db as dbCore } from "@budibase/backend-core" +import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" -describe.skip("Public API - /applications endpoints", () => { +describe("Public API - /applications endpoints", () => { const api = new PublicAPIClient() const accountsAPI = new AccountsAPIClient() - const config = new TestConfiguration(api, accountsAPI) + const internalAPI = new InternalAPIClient() + const config = new TestConfiguration( + api, + accountsAPI, + internalAPI + ) beforeAll(async () => { - await config.beforeAll() + await config.setupAccountAndTenant() + await config.setApiKey() + const [response, app] = await config.applications.seed() config.context = app }) diff --git a/qa-core/src/tests/public-api/tables/rows.spec.ts b/qa-core/src/tests/public-api/tables/rows.spec.ts index 3cb339570d..d21b61e41a 100644 --- a/qa-core/src/tests/public-api/tables/rows.spec.ts +++ b/qa-core/src/tests/public-api/tables/rows.spec.ts @@ -3,14 +3,18 @@ import { generateRow } from "../../../config/public-api/fixtures/tables" import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient" +import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" -describe.skip("Public API - /rows endpoints", () => { +describe("Public API - /rows endpoints", () => { const api = new PublicAPIClient() const accountsAPI = new AccountsAPIClient() - const config = new TestConfiguration(api, accountsAPI) + const internalAPI = new InternalAPIClient() + const config = new TestConfiguration(api, accountsAPI, internalAPI) beforeAll(async () => { - await config.beforeAll() + await config.setupAccountAndTenant() + await config.setApiKey() + const [aResp, app] = await config.applications.seed() config.tables.api.appId = app._id diff --git a/qa-core/src/tests/public-api/tables/tables.spec.ts b/qa-core/src/tests/public-api/tables/tables.spec.ts index 5d96194599..fc506d7bb6 100644 --- a/qa-core/src/tests/public-api/tables/tables.spec.ts +++ b/qa-core/src/tests/public-api/tables/tables.spec.ts @@ -3,14 +3,18 @@ import { generateTable } from "../../../config/public-api/fixtures/tables" import TestConfiguration from "../../../config/public-api/TestConfiguration" import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient" import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient" +import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" -describe.skip("Public API - /tables endpoints", () => { +describe("Public API - /tables endpoints", () => { const api = new PublicAPIClient() const accountsAPI = new AccountsAPIClient() - const config = new TestConfiguration
(api, accountsAPI) + const internalAPI = new InternalAPIClient() + const config = new TestConfiguration
(api, accountsAPI, internalAPI) beforeAll(async () => { - await config.beforeAll() + await config.setupAccountAndTenant() + await config.setApiKey() + const [appResp, app] = await config.applications.seed() config.tables.api.appId = app._id diff --git a/qa-core/src/tests/public-api/users/users.spec.ts b/qa-core/src/tests/public-api/users/users.spec.ts index d72b265386..597a8ff2dd 100644 --- a/qa-core/src/tests/public-api/users/users.spec.ts +++ b/qa-core/src/tests/public-api/users/users.spec.ts @@ -3,11 +3,13 @@ import PublicAPIClient from "../../../config/public-api/TestConfiguration/Public import generateUser from "../../../config/public-api/fixtures/users" import { User } from "@budibase/server/api/controllers/public/mapping/types" import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient" +import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" describe("Public API - /users endpoints", () => { const api = new PublicAPIClient() const accountsAPI = new AccountsAPIClient() - const config = new TestConfiguration(api, accountsAPI) + const internalAPI = new InternalAPIClient() + const config = new TestConfiguration(api, accountsAPI, internalAPI) beforeAll(async () => { await config.setupAccountAndTenant() From 2c20f242b402e3173f9b975690ea5f274c329dbd Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Thu, 9 Mar 2023 15:39:47 +0000 Subject: [PATCH 06/11] Remove current API keys --- qa-core/scripts/jestSetup.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/qa-core/scripts/jestSetup.js b/qa-core/scripts/jestSetup.js index cd63258f7a..36ff404532 100644 --- a/qa-core/scripts/jestSetup.js +++ b/qa-core/scripts/jestSetup.js @@ -1,10 +1,10 @@ -const env = require("../src/environment") +//const env = require("../src/environment") -env._set("BUDIBASE_SERVER_URL", "http://localhost:4100") -env._set( - "BUDIBASE_PUBLIC_API_KEY", - "a65722f06bee5caeadc5d7ca2f543a43-d610e627344210c643bb726f" -) +//env._set("BUDIBASE_SERVER_URL", "http://localhost:4100") +//env._set( +// "BUDIBASE_PUBLIC_API_KEY", +// "a65722f06bee5caeadc5d7ca2f543a43-d610e627344210c643bb726f" +//) // mock all dates to 2020-01-01T00:00:00.000Z // use tk.reset() to use real dates in individual tests From 3a4548778c01d5de5d0e191f09f516f630914e7f Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 13 Mar 2023 09:46:58 +0000 Subject: [PATCH 07/11] Remove unnecessary env variables from setup --- qa-core/scripts/jestSetup.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/qa-core/scripts/jestSetup.js b/qa-core/scripts/jestSetup.js index 36ff404532..a6f8a6478c 100644 --- a/qa-core/scripts/jestSetup.js +++ b/qa-core/scripts/jestSetup.js @@ -1,11 +1,3 @@ -//const env = require("../src/environment") - -//env._set("BUDIBASE_SERVER_URL", "http://localhost:4100") -//env._set( -// "BUDIBASE_PUBLIC_API_KEY", -// "a65722f06bee5caeadc5d7ca2f543a43-d610e627344210c643bb726f" -//) - // mock all dates to 2020-01-01T00:00:00.000Z // use tk.reset() to use real dates in individual tests const MOCK_DATE = new Date("2020-01-01T00:00:00.000Z") From cf04fffdad6ecbdfe5b0ed13529fb414632b9087 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 13 Mar 2023 16:22:55 +0000 Subject: [PATCH 08/11] Fix API Error handling --- .../TestConfiguration/InternalAPIClient.ts | 7 +++---- .../TestConfiguration/accountsAPIClient.ts | 10 ++++------ .../public-api/TestConfiguration/PublicAPIClient.ts | 8 ++++---- .../public-api/TestConfiguration/accountsAPIClient.ts | 7 ++++--- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts b/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts index 2dc0487095..1c79f47609 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/InternalAPIClient.ts @@ -55,11 +55,10 @@ class InternalAPIClient { response.status == 403 ) { console.error("Error in apiCall") - console.error("Response:") - console.error(response) + console.error("Response:", response) const json = await response.json() - console.error("Response body:") - console.error(json) + console.error("Response body:", json) + console.error("Request body:", requestOptions.body) } return response } diff --git a/qa-core/src/config/internal-api/TestConfiguration/accountsAPIClient.ts b/qa-core/src/config/internal-api/TestConfiguration/accountsAPIClient.ts index aff821a7ac..9de03b75b6 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/accountsAPIClient.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/accountsAPIClient.ts @@ -44,12 +44,10 @@ class AccountsAPIClient { const response = await fetch(`${this.host}${url}`, requestOptions) if (response.status == 404 || response.status == 500) { console.error("Error in apiCall") - console.error("Response:") - console.error(response) - console.error("Response body:") - console.error(response.body) - console.error("Request body:") - console.error(requestOptions.body) + console.error("Response:", response) + const json = await response.json() + console.error("Response body:", json) + console.error("Request body:", requestOptions.body) } return response } diff --git a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts index d9f4aa4816..657ca22ff8 100644 --- a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts +++ b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts @@ -65,10 +65,10 @@ class PublicAPIClient { response.status == 403 ) { console.error("Error in apiCall") - console.error("Response:") - console.error(response) - console.error("Response body:") - console.error(response.body) + console.error("Response:", response) + const json = await response.json() + console.error("Response body:", json) + console.error("Request body:", requestOptions.body) } return response } diff --git a/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts b/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts index 44b69aa247..2ea465adda 100644 --- a/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts +++ b/qa-core/src/config/public-api/TestConfiguration/accountsAPIClient.ts @@ -48,9 +48,10 @@ class AccountsAPIClient { response.status == 400 ) { console.error("Error in apiCall") - console.error(response) - console.error(response.body) - console.error(requestOptions.body) + console.error("Response:", response) + const json = await response.json() + console.error("Response body:", json) + console.error("Request body:", requestOptions.body) } return response } From 464a10f64165626fe106ebe8a2ee5c35b00e94ce Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 13 Mar 2023 16:24:20 +0000 Subject: [PATCH 09/11] Fix Bad APIkey handling --- .../src/config/public-api/TestConfiguration/PublicAPIClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts index 657ca22ff8..1f563e7ab5 100644 --- a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts +++ b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts @@ -44,7 +44,7 @@ class PublicAPIClient { method, body: JSON.stringify(options.body), headers: { - "x-budibase-api-key": this.apiKey ? this.apiKey : null, + "x-budibase-api-key": this.apiKey || null, "x-budibase-app-id": this.appId, "Content-Type": "application/json", Accept: "application/json", From 1fc46002e21622def0d8f7e35fc24edc33ffe72e Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 13 Mar 2023 18:05:46 +0000 Subject: [PATCH 10/11] Add comments --- .../config/public-api/TestConfiguration/PublicAPIClient.ts | 6 +----- qa-core/src/config/public-api/TestConfiguration/index.ts | 3 +++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts index 1f563e7ab5..0dfe74bb6a 100644 --- a/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts +++ b/qa-core/src/config/public-api/TestConfiguration/PublicAPIClient.ts @@ -59,11 +59,7 @@ class PublicAPIClient { // @ts-ignore const response = await fetch(`https://${process.env.TENANT_ID}.${this.host}${url}`, requestOptions) - if ( - response.status == 404 || - response.status == 500 || - response.status == 403 - ) { + if (response.status == 500 || response.status == 403) { console.error("Error in apiCall") console.error("Response:", response) const json = await response.json() diff --git a/qa-core/src/config/public-api/TestConfiguration/index.ts b/qa-core/src/config/public-api/TestConfiguration/index.ts index a869448b36..e67da27883 100644 --- a/qa-core/src/config/public-api/TestConfiguration/index.ts +++ b/qa-core/src/config/public-api/TestConfiguration/index.ts @@ -47,6 +47,8 @@ export default class TestConfiguration { } async setupAccountAndTenant() { + // This step is required to create a new account and tenant for the tests, its part of + // the support for running tests in multiple environments. const account = generateAccount() await this.accounts.validateEmail(account.email) await this.accounts.validateTenantId(account.tenantId) @@ -63,6 +65,7 @@ export default class TestConfiguration { await this.internalApplicationsApi.create(body) } + // After the account and tenant have been created, we need to get and set the API key for the test async setApiKey() { const apiKeyResponse = await this.auth.getApiKey() this.apiClient.setApiKey(apiKeyResponse.apiKey) From 55214876d8a9883de3abd388bad77fc026669028 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 14 Mar 2023 10:07:16 +0000 Subject: [PATCH 11/11] Improve tenant generation --- qa-core/src/config/internal-api/fixtures/accounts.ts | 3 ++- qa-core/src/config/public-api/fixtures/accounts.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/qa-core/src/config/internal-api/fixtures/accounts.ts b/qa-core/src/config/internal-api/fixtures/accounts.ts index dbeabae928..64b6d51f44 100644 --- a/qa-core/src/config/internal-api/fixtures/accounts.ts +++ b/qa-core/src/config/internal-api/fixtures/accounts.ts @@ -5,7 +5,8 @@ import { Hosting } from "@budibase/types" export const generateAccount = (): Partial => { const randomGuid = generator.guid() - let tenant: string = "a" + randomGuid + //Needs to start with a letter + let tenant: string = "tenant" + randomGuid tenant = tenant.replace(/-/g, "") return { diff --git a/qa-core/src/config/public-api/fixtures/accounts.ts b/qa-core/src/config/public-api/fixtures/accounts.ts index dbeabae928..64b6d51f44 100644 --- a/qa-core/src/config/public-api/fixtures/accounts.ts +++ b/qa-core/src/config/public-api/fixtures/accounts.ts @@ -5,7 +5,8 @@ import { Hosting } from "@budibase/types" export const generateAccount = (): Partial => { const randomGuid = generator.guid() - let tenant: string = "a" + randomGuid + //Needs to start with a letter + let tenant: string = "tenant" + randomGuid tenant = tenant.replace(/-/g, "") return {