Add setup for account and tenant creation

This commit is contained in:
Pedro Silva 2022-12-19 18:00:51 +00:00
parent 69873152b6
commit aefa3a65c2
3 changed files with 42 additions and 2 deletions

View File

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

View File

@ -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<T> {
applications: ApplicationApi
auth: AuthApi
@ -31,6 +33,14 @@ export default class TestConfiguration<T> {
await this.auth.login(<string>process.env.BB_ADMIN_USER_EMAIL, <string>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)
}

View File

@ -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}`,
}
}