diff --git a/qa-core/src/config/internal-api/TestConfiguration/accounts.ts b/qa-core/src/config/internal-api/TestConfiguration/accounts.ts index 3acad4ebb1..cb544d18a0 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/accounts.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/accounts.ts @@ -1,7 +1,6 @@ import { Response } from "node-fetch" -import { Table } from "@budibase/types" +import { Account } from "@budibase/types" import InternalAPIClient from "./InternalAPIClient" -import { responseMessage } from "../fixtures/types/responseMessage" export default class AccountsApi { api: InternalAPIClient @@ -16,4 +15,18 @@ export default class AccountsApi { expect(response).toHaveStatusCode(200) return [response, json] } + + async validateTenantId(tenantId: string): Promise<[Response, any]> { + const response = await this.api.post(`/accounts/validate/tenantId`, { body: { tenantId } }) + const json = await response.json() + expect(response).toHaveStatusCode(200) + return [response, json] + } + + async create(body: Account): Promise<[Response, Account]> { + const response = await this.api.post(`/accounts`, { body }) + const json = await response.json() + expect(response).toHaveStatusCode(200) + return [response, json] + } } diff --git a/qa-core/src/config/internal-api/TestConfiguration/index.ts b/qa-core/src/config/internal-api/TestConfiguration/index.ts index 85ce0d9166..39a839f58d 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/index.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/index.ts @@ -6,6 +6,8 @@ import RowApi from "./rows" import ScreenApi from "./screens" import UserManagementApi from "./userManagement" import AccountsApi from "./accounts" +import { generateAccount } from "../fixtures/accounts" + export default class TestConfiguration { applications: ApplicationApi auth: AuthApi @@ -31,6 +33,14 @@ export default class TestConfiguration { await this.auth.login(process.env.BB_ADMIN_USER_EMAIL, process.env.BB_ADMIN_USER_PASSWORD) } + async setupAccountAndTenant() { + const account = generateAccount() + const [emailValidationResponse, emailValidationJson] = await this.accounts.validateEmail(account.email) + const [tenantIdValidationResponse, tenantIdValidationJson] = await this.accounts.validateTenantId(account.tenantId) + const [accountCreationResponse, accountCreationJson] = await this.accounts.create(account) + await this.auth.login(account.email, account.password) + } + async login(email: string, password: string) { await this.auth.login(email, password) } diff --git a/qa-core/src/config/internal-api/fixtures/accounts.ts b/qa-core/src/config/internal-api/fixtures/accounts.ts new file mode 100644 index 0000000000..4c1660c0aa --- /dev/null +++ b/qa-core/src/config/internal-api/fixtures/accounts.ts @@ -0,0 +1,17 @@ +import { Account } from "@budibase/types"; +import generator from "../../generator"; + +export const generateAccount = (): Account => { + const randomGuid = generator.guid(); + return { + email: `qa+${randomGuid}@budibase.com`, + hosting: "cloud", + name: `qa+${randomGuid}@budibase.com`, + password: `${randomGuid}`, + profession: "software_engineer", + size: "10+", + tenantId: `${randomGuid}`, + tenantName: `${randomGuid}`, + } +} +