From ecf75a96857ce1cb454f749bbc65df7b1828880c Mon Sep 17 00:00:00 2001 From: Mitch-Budibase Date: Wed, 19 Jul 2023 15:42:12 +0100 Subject: [PATCH] lint --- packages/types/src/api/account/accounts.ts | 2 +- qa-core/scripts/createEnv.js | 2 +- .../api/AccountInternalAPIClient.ts | 2 +- .../src/account-api/api/apis/AccountAPI.ts | 109 ++++++++---------- qa-core/src/account-api/api/apis/AuthAPI.ts | 15 +-- qa-core/src/account-api/api/apis/BaseAPI.ts | 6 +- .../src/account-api/api/apis/LicenseAPI.ts | 11 +- .../account-api/config/TestConfiguration.ts | 38 +++--- qa-core/src/account-api/fixtures/accounts.ts | 26 ++--- qa-core/src/account-api/fixtures/index.ts | 2 +- .../tests/accounts/accounts.spec.ts | 19 ++- qa-core/src/jest/globalSetup.ts | 42 ++++--- qa-core/src/jest/globalTeardown.ts | 4 +- .../src/shared/BudibaseTestConfiguration.ts | 5 +- 14 files changed, 140 insertions(+), 143 deletions(-) diff --git a/packages/types/src/api/account/accounts.ts b/packages/types/src/api/account/accounts.ts index e2accf7c18..bb3419c5d1 100644 --- a/packages/types/src/api/account/accounts.ts +++ b/packages/types/src/api/account/accounts.ts @@ -19,4 +19,4 @@ export interface SearchAccountsRequest { tenantId?: string } -export type SearchAccountsResponse = Account[] \ No newline at end of file +export type SearchAccountsResponse = Account[] diff --git a/qa-core/scripts/createEnv.js b/qa-core/scripts/createEnv.js index ebb165f3a9..64b9664049 100644 --- a/qa-core/scripts/createEnv.js +++ b/qa-core/scripts/createEnv.js @@ -13,7 +13,7 @@ function init() { BB_ADMIN_USER_PASSWORD: "admin", LOG_LEVEL: "info", JEST_TIMEOUT: "60000", - DISABLE_PINO_LOGGER: "1" + DISABLE_PINO_LOGGER: "1", } let envFile = "" Object.keys(envFileJson).forEach(key => { diff --git a/qa-core/src/account-api/api/AccountInternalAPIClient.ts b/qa-core/src/account-api/api/AccountInternalAPIClient.ts index b1e32cac1f..1b73f51320 100644 --- a/qa-core/src/account-api/api/AccountInternalAPIClient.ts +++ b/qa-core/src/account-api/api/AccountInternalAPIClient.ts @@ -48,7 +48,7 @@ export default class AccountInternalAPIClient { if (options.internal) { requestOptions.headers = { ...requestOptions.headers, - ...{ [Header.API_KEY] : env.ACCOUNT_PORTAL_API_KEY }, + ...{ [Header.API_KEY]: env.ACCOUNT_PORTAL_API_KEY }, } } diff --git a/qa-core/src/account-api/api/apis/AccountAPI.ts b/qa-core/src/account-api/api/apis/AccountAPI.ts index 8c6ccec6b8..33e64da7ad 100644 --- a/qa-core/src/account-api/api/apis/AccountAPI.ts +++ b/qa-core/src/account-api/api/apis/AccountAPI.ts @@ -1,5 +1,10 @@ import { Response } from "node-fetch" -import { Account, CreateAccountRequest, SearchAccountsRequest, SearchAccountsResponse } from "@budibase/types" +import { + Account, + CreateAccountRequest, + SearchAccountsRequest, + SearchAccountsResponse, +} from "@budibase/types" import AccountInternalAPIClient from "../AccountInternalAPIClient" import { APIRequestOpts } from "../../../types" import { Header } from "@budibase/backend-core" @@ -13,17 +18,11 @@ export default class AccountAPI extends BaseAPI { this.client = client } - async validateEmail( - email: string, - opts: APIRequestOpts = { status: 200 } - ) { + async validateEmail(email: string, opts: APIRequestOpts = { status: 200 }) { return this.doRequest(() => { - return this.client.post( - `/api/accounts/validate/email`, - { - body: { email }, - } - ) + return this.client.post(`/api/accounts/validate/email`, { + body: { email }, + }) }, opts) } @@ -32,22 +31,22 @@ export default class AccountAPI extends BaseAPI { opts: APIRequestOpts = { status: 200 } ) { return this.doRequest(() => { - return this.client.post( - `/api/accounts/validate/tenantId`, - { - body: { tenantId }, - } - ) + return this.client.post(`/api/accounts/validate/tenantId`, { + body: { tenantId }, + }) }, opts) } async create( body: CreateAccountRequest, - opts: APIRequestOpts & { autoVerify: boolean } = { status: 201, autoVerify: false } + opts: APIRequestOpts & { autoVerify: boolean } = { + status: 201, + autoVerify: false, + } ): Promise<[Response, Account]> { return this.doRequest(() => { const headers = { - "no-verify": opts.autoVerify ? "1" : "0" + "no-verify": opts.autoVerify ? "1" : "0", } return this.client.post(`/api/accounts`, { body, @@ -56,81 +55,63 @@ export default class AccountAPI extends BaseAPI { }, opts) } - async delete( - accountID: string, - opts: APIRequestOpts = { status: 204 }) { + async delete(accountID: string, opts: APIRequestOpts = { status: 204 }) { return this.doRequest(() => { - return this.client.del( - `/api/accounts/${accountID}`, - { - internal: true, - } - ) + return this.client.del(`/api/accounts/${accountID}`, { + internal: true, + }) }, opts) } - async deleteCurrentAccount( - opts: APIRequestOpts = { status: 204 } - ) { + async deleteCurrentAccount(opts: APIRequestOpts = { status: 204 }) { return this.doRequest(() => { - return this.client.del( - `/api/accounts` - ) + return this.client.del(`/api/accounts`) }, opts) } async verifyAccount( verificationCode: string, opts: APIRequestOpts = { status: 200 } - ){ + ) { return this.doRequest(() => { - return this.client.post( - `/api/accounts/verify`, - { - body: { verificationCode }, - } - ) + return this.client.post(`/api/accounts/verify`, { + body: { verificationCode }, + }) }, opts) } async sendVerificationEmail( - email: string, - opts: APIRequestOpts = { status: 200 } + email: string, + opts: APIRequestOpts = { status: 200 } ): Promise<[Response, string]> { return this.doRequest(async () => { - const [response] = await this.client.post( - `/api/accounts/verify/send`, - { - body: { email }, - headers: { - [Header.RETURN_VERIFICATION_CODE]: "1" - } - } - ) + const [response] = await this.client.post(`/api/accounts/verify/send`, { + body: { email }, + headers: { + [Header.RETURN_VERIFICATION_CODE]: "1", + }, + }) const code = response.headers.get(Header.VERIFICATION_CODE) return [response, code] }, opts) } async search( - searchType: string, - search: 'email' | 'tenantId', - opts: APIRequestOpts = { status: 200 } + searchType: string, + search: "email" | "tenantId", + opts: APIRequestOpts = { status: 200 } ): Promise<[Response, SearchAccountsResponse]> { return this.doRequest(() => { let body: SearchAccountsRequest = {} - if (search === 'email') { + if (search === "email") { body.email = searchType - } else if (search === 'tenantId') { + } else if (search === "tenantId") { body.tenantId = searchType } - return this.client.post( - `/api/accounts/search`, - { - body, - internal: true - } - ) + return this.client.post(`/api/accounts/search`, { + body, + internal: true, + }) }, opts) } } diff --git a/qa-core/src/account-api/api/apis/AuthAPI.ts b/qa-core/src/account-api/api/apis/AuthAPI.ts index c5d654ade0..50345c891b 100644 --- a/qa-core/src/account-api/api/apis/AuthAPI.ts +++ b/qa-core/src/account-api/api/apis/AuthAPI.ts @@ -17,15 +17,12 @@ export default class AuthAPI extends BaseAPI { opts: APIRequestOpts = { doExpect: true, status: 200 } ): Promise<[Response, string]> { return this.doRequest(async () => { - const [res] = await this.client.post( - `/api/auth/login`, - { - body: { - email: email, - password: password, - }, - } - ) + const [res] = await this.client.post(`/api/auth/login`, { + body: { + email: email, + password: password, + }, + }) const cookie = res.headers.get("set-cookie") return [res, cookie] }, opts) diff --git a/qa-core/src/account-api/api/apis/BaseAPI.ts b/qa-core/src/account-api/api/apis/BaseAPI.ts index db0d921dd6..7b74a2d3f5 100644 --- a/qa-core/src/account-api/api/apis/BaseAPI.ts +++ b/qa-core/src/account-api/api/apis/BaseAPI.ts @@ -4,10 +4,10 @@ import { APIRequestOpts } from "../../../types" // TODO: Add to LicenseAPI export default class BaseAPI { - async doRequest( request: () => Promise<[Response, any]>, - opts: APIRequestOpts): Promise<[Response, any]> { + opts: APIRequestOpts + ): Promise<[Response, any]> { const [response, body] = await request() // do expect on by default @@ -19,4 +19,4 @@ export default class BaseAPI { } return [response, body] } -} \ No newline at end of file +} diff --git a/qa-core/src/account-api/api/apis/LicenseAPI.ts b/qa-core/src/account-api/api/apis/LicenseAPI.ts index 67e67edcb1..f0398ade95 100644 --- a/qa-core/src/account-api/api/apis/LicenseAPI.ts +++ b/qa-core/src/account-api/api/apis/LicenseAPI.ts @@ -18,13 +18,10 @@ export default class LicenseAPI extends BaseAPI { opts: APIRequestOpts = { status: 200 } ): Promise<[Response, Account]> { return this.doRequest(() => { - return this.client.put( - `/api/accounts/${accountId}/license`, - { - body, - internal: true, - } - ) + return this.client.put(`/api/accounts/${accountId}/license`, { + body, + internal: true, + }) }, opts) } } diff --git a/qa-core/src/account-api/config/TestConfiguration.ts b/qa-core/src/account-api/config/TestConfiguration.ts index 6322be97f0..66adb85ca2 100644 --- a/qa-core/src/account-api/config/TestConfiguration.ts +++ b/qa-core/src/account-api/config/TestConfiguration.ts @@ -2,28 +2,28 @@ import { AccountInternalAPI } from "../api" import { BudibaseTestConfiguration } from "../../shared" export default class TestConfiguration extends BudibaseTestConfiguration { - // apis - api: AccountInternalAPI + // apis + api: AccountInternalAPI - context: T + context: T - constructor() { - super() - this.api = new AccountInternalAPI(this.state) - this.context = {} - } + constructor() { + super() + this.api = new AccountInternalAPI(this.state) + this.context = {} + } - async beforeAll() { - await super.beforeAll() - await this.setApiKey() - } + async beforeAll() { + await super.beforeAll() + await this.setApiKey() + } - async afterAll() { - await super.afterAll() - } + async afterAll() { + await super.afterAll() + } - async setApiKey() { - const apiKeyResponse = await this.internalApi.self.getApiKey() - this.state.apiKey = apiKeyResponse.apiKey - } + async setApiKey() { + const apiKeyResponse = await this.internalApi.self.getApiKey() + this.state.apiKey = apiKeyResponse.apiKey + } } diff --git a/qa-core/src/account-api/fixtures/accounts.ts b/qa-core/src/account-api/fixtures/accounts.ts index 6c52cb52b0..62c84f3647 100644 --- a/qa-core/src/account-api/fixtures/accounts.ts +++ b/qa-core/src/account-api/fixtures/accounts.ts @@ -3,19 +3,19 @@ import { Hosting, CreateAccountRequest } from "@budibase/types" // TODO: Refactor me to central location export const generateAccount = (): CreateAccountRequest => { - const uuid = generator.guid() + const uuid = generator.guid() - const email = `${uuid}@budibase.com` - const tenant = `tenant${uuid.replace(/-/g, "")}` + const email = `${uuid}@budibase.com` + const tenant = `tenant${uuid.replace(/-/g, "")}` - return { - email, - hosting: Hosting.CLOUD, - name: email, - password: uuid, - profession: "software_engineer", - size: "10+", - tenantId: tenant, - tenantName: tenant, - } + return { + email, + hosting: Hosting.CLOUD, + name: email, + password: uuid, + profession: "software_engineer", + size: "10+", + tenantId: tenant, + tenantName: tenant, + } } diff --git a/qa-core/src/account-api/fixtures/index.ts b/qa-core/src/account-api/fixtures/index.ts index 7d09ee1c2c..952f4a8cc8 100644 --- a/qa-core/src/account-api/fixtures/index.ts +++ b/qa-core/src/account-api/fixtures/index.ts @@ -1 +1 @@ -export * as accounts from "./accounts" \ No newline at end of file +export * as accounts from "./accounts" diff --git a/qa-core/src/account-api/tests/accounts/accounts.spec.ts b/qa-core/src/account-api/tests/accounts/accounts.spec.ts index e1c0dd2c20..e3a4d4eacf 100644 --- a/qa-core/src/account-api/tests/accounts/accounts.spec.ts +++ b/qa-core/src/account-api/tests/accounts/accounts.spec.ts @@ -35,7 +35,9 @@ describe("Accounts", () => { await config.loginAsAccount(createAccountRequest, { status: 400 }) // Re-send verification email to get access to code - const [_, code] = await config.accountsApi.accounts.sendVerificationEmail(email) + const [_, code] = await config.accountsApi.accounts.sendVerificationEmail( + email + ) // Send the verification request await config.accountsApi.accounts.verifyAccount(code!) @@ -56,11 +58,17 @@ describe("Accounts", () => { const tenantId = generator.string() // Empty result - const [_, emptyBody] = await config.api.accounts.search(tenantId, "tenantId") + const [_, emptyBody] = await config.api.accounts.search( + tenantId, + "tenantId" + ) expect(emptyBody.length).toBe(0) // Hit result - const [hitRes, hitBody] = await config.api.accounts.search(config.state.tenantId!, "tenantId") + const [hitRes, hitBody] = await config.api.accounts.search( + config.state.tenantId!, + "tenantId" + ) expect(hitBody.length).toBe(1) expect(hitBody[0].tenantId).toBe(config.state.tenantId) }) @@ -73,7 +81,10 @@ describe("Accounts", () => { expect(emptyBody.length).toBe(0) // Hit result - const [hitRes, hitBody] = await config.api.accounts.search(config.state.email!, "email") + const [hitRes, hitBody] = await config.api.accounts.search( + config.state.email!, + "email" + ) expect(hitBody.length).toBe(1) expect(hitBody[0].email).toBe(config.state.email) }) diff --git a/qa-core/src/jest/globalSetup.ts b/qa-core/src/jest/globalSetup.ts index 68300cee26..103126d74c 100644 --- a/qa-core/src/jest/globalSetup.ts +++ b/qa-core/src/jest/globalSetup.ts @@ -9,7 +9,7 @@ import { APIRequestOpts } from "../types" const accountsApi = new AccountInternalAPI({}) const internalApi = new BudibaseInternalAPI({}) -const API_OPTS: APIRequestOpts = { doExpect: false} +const API_OPTS: APIRequestOpts = { doExpect: false } // @ts-ignore global.qa = {} @@ -18,8 +18,10 @@ async function createAccount(): Promise<[CreateAccountRequest, Account]> { const account = fixtures.accounts.generateAccount() await accountsApi.accounts.validateEmail(account.email, API_OPTS) await accountsApi.accounts.validateTenantId(account.tenantId, API_OPTS) - const [res, newAccount] = await accountsApi.accounts.create( - account, {...API_OPTS, autoVerify: true }) + const [res, newAccount] = await accountsApi.accounts.create(account, { + ...API_OPTS, + autoVerify: true, + }) await updateLicense(newAccount.accountId) return [account, newAccount] } @@ -27,25 +29,29 @@ async function createAccount(): Promise<[CreateAccountRequest, Account]> { const UNLIMITED = { value: -1 } async function updateLicense(accountId: string) { - const [response] = await accountsApi.licenses.updateLicense(accountId, { - overrides: { - // add all features - features: Object.values(Feature), - quotas: { - usage: { - monthly: { - automations: UNLIMITED, - }, - static: { - rows: UNLIMITED, - users: UNLIMITED, - userGroups: UNLIMITED, - plugins: UNLIMITED, + const [response] = await accountsApi.licenses.updateLicense( + accountId, + { + overrides: { + // add all features + features: Object.values(Feature), + quotas: { + usage: { + monthly: { + automations: UNLIMITED, + }, + static: { + rows: UNLIMITED, + users: UNLIMITED, + userGroups: UNLIMITED, + plugins: UNLIMITED, + }, }, }, }, }, - }, { doExpect: false }) + { doExpect: false } + ) if (response.status !== 200) { throw new Error( `Could not update license for accountId=${accountId}: ${response.status}` diff --git a/qa-core/src/jest/globalTeardown.ts b/qa-core/src/jest/globalTeardown.ts index f1b8c1d541..ff3fea7b7c 100644 --- a/qa-core/src/jest/globalTeardown.ts +++ b/qa-core/src/jest/globalTeardown.ts @@ -11,7 +11,9 @@ async function deleteAccount() { // @ts-ignore const accountID = global.qa.accountId - const [response] = await accountsApi.accounts.delete(accountID, { doExpect: false }) + const [response] = await accountsApi.accounts.delete(accountID, { + doExpect: false, + }) if (response.status !== 204) { throw new Error(`status: ${response.status} not equal to expected: 201`) } diff --git a/qa-core/src/shared/BudibaseTestConfiguration.ts b/qa-core/src/shared/BudibaseTestConfiguration.ts index 9841b8d163..18b7c89ec8 100644 --- a/qa-core/src/shared/BudibaseTestConfiguration.ts +++ b/qa-core/src/shared/BudibaseTestConfiguration.ts @@ -69,7 +69,10 @@ export default class BudibaseTestConfiguration { this.state.email = original.email } - async loginAsAccount(account: CreateAccountRequest, opts: APIRequestOpts = {}) { + async loginAsAccount( + account: CreateAccountRequest, + opts: APIRequestOpts = {} + ) { const [_, cookie] = await this.accountsApi.auth.login( account.email, account.password,