lint
This commit is contained in:
parent
7eb65ed347
commit
ecf75a9685
|
@ -19,4 +19,4 @@ export interface SearchAccountsRequest {
|
|||
tenantId?: string
|
||||
}
|
||||
|
||||
export type SearchAccountsResponse = Account[]
|
||||
export type SearchAccountsResponse = Account[]
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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 },
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,28 +2,28 @@ import { AccountInternalAPI } from "../api"
|
|||
import { BudibaseTestConfiguration } from "../../shared"
|
||||
|
||||
export default class TestConfiguration<T> extends BudibaseTestConfiguration {
|
||||
// apis
|
||||
api: AccountInternalAPI
|
||||
// apis
|
||||
api: AccountInternalAPI
|
||||
|
||||
context: T
|
||||
context: T
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.api = new AccountInternalAPI(this.state)
|
||||
this.context = <T>{}
|
||||
}
|
||||
constructor() {
|
||||
super()
|
||||
this.api = new AccountInternalAPI(this.state)
|
||||
this.context = <T>{}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
export * as accounts from "./accounts"
|
||||
export * as accounts from "./accounts"
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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}`
|
||||
|
|
|
@ -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`)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue