Merge branch 'account-api-tests' into tests/offline-license

This commit is contained in:
Rory Powell 2023-07-14 21:00:38 +01:00
commit 7449fd97b7
44 changed files with 482 additions and 40 deletions

View File

@ -34,7 +34,6 @@ jobs:
exit 1
fi
- uses: actions/setup-node@v1
with:
node-version: 14.x
@ -58,9 +57,12 @@ jobs:
echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} >> .npmrc
yarn release
- name: "Get Previous tag"
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
- name: "Get Current tag"
id: currenttag
run: |
version=v$(./scripts/getCurrentVersion.sh)
echo 'Using tag $version'
echo "::set-output name=tag::$resversionult"
- name: Build/release Docker images
run: |
@ -69,7 +71,7 @@ jobs:
env:
DOCKER_USER: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_API_KEY }}
BUDIBASE_RELEASE_VERSION: ${{ steps.previoustag.outputs.tag }}
BUDIBASE_RELEASE_VERSION: ${{ steps.currenttag.outputs.tag }}
release-helm-chart:
needs: [release-images]

View File

@ -1,5 +1,5 @@
{
"version": "2.8.2-alpha.2",
"version": "2.8.2-alpha.5",
"npmClient": "yarn",
"packages": [
"packages/*"

View File

@ -20,6 +20,8 @@ export enum Header {
TYPE = "x-budibase-type",
PREVIEW_ROLE = "x-budibase-role",
TENANT_ID = "x-budibase-tenant-id",
VERIFICATION_CODE = "x-budibase-verification-code",
RETURN_VERIFICATION_CODE = "x-budibase-return-verification-code",
TOKEN = "x-budibase-token",
CSRF_TOKEN = "x-csrf-token",
CORRELATION_ID = "x-budibase-correlation-id",

View File

@ -62,6 +62,13 @@
}
}
const getInputMode = type => {
if (type === "bigint") {
return "numeric"
}
return type === "number" ? "decimal" : "text"
}
onMount(() => {
focus = autofocus
if (focus) field.focus()
@ -103,7 +110,7 @@
{type}
class="spectrum-Textfield-input"
style={align ? `text-align: ${align};` : ""}
inputmode={type === "number" ? "decimal" : "text"}
inputmode={getInputMode(type)}
{autocomplete}
/>
</div>

View File

@ -135,5 +135,5 @@ export const userSelectedResourceMap = derived(userStore, $userStore => {
})
export const isOnlyUser = derived(userStore, $userStore => {
return $userStore.length === 1
return $userStore.length < 2
})

View File

@ -4,6 +4,7 @@ import { getSchemaForDatasource } from "../../../dataBinding"
const fieldTypeToComponentMap = {
string: "stringfield",
number: "numberfield",
bigint: "bigintfield",
options: "optionsfield",
array: "multifieldselect",
boolean: "booleanfield",

View File

@ -326,6 +326,7 @@
FIELDS.NUMBER,
FIELDS.BOOLEAN,
FIELDS.FORMULA,
FIELDS.BIGINT,
]
// no-sql or a spreadsheet
if (!external || table.sql) {

View File

@ -52,6 +52,7 @@ const componentMap = {
"field/sortable": SortableFieldSelect,
"field/string": FormFieldSelect,
"field/number": FormFieldSelect,
"field/bigint": FormFieldSelect,
"field/options": FormFieldSelect,
"field/boolean": FormFieldSelect,
"field/longform": FormFieldSelect,

View File

@ -228,7 +228,7 @@
on:change={event => (filter.value = event.detail)}
{fillWidth}
/>
{:else if ["string", "longform", "number", "formula"].includes(filter.type)}
{:else if ["string", "longform", "number", "bigint", "formula"].includes(filter.type)}
<Input disabled={filter.noValue} bind:value={filter.value} />
{:else if filter.type === "array" || (filter.type === "options" && filter.operator === "oneOf")}
<Multiselect

View File

@ -53,6 +53,10 @@ export const FIELDS = {
numericality: { greaterThanOrEqualTo: "", lessThanOrEqualTo: "" },
},
},
BIGINT: {
name: "BigInt",
type: "bigint",
},
BOOLEAN: {
name: "Boolean",
type: "boolean",

View File

@ -15,12 +15,7 @@
{
"name": "Layout",
"icon": "ClassicGridView",
"children": [
"container",
"section",
"grid",
"sidepanel"
]
"children": ["container", "section", "grid", "sidepanel"]
},
{
"name": "Data",
@ -63,6 +58,7 @@
"fieldgroup",
"stringfield",
"numberfield",
"bigintfield",
"passwordfield",
"optionsfield",
"booleanfield",
@ -79,13 +75,6 @@
{
"name": "Chart",
"icon": "GraphBarVertical",
"children": [
"bar",
"line",
"area",
"candlestick",
"pie",
"donut"
]
"children": ["bar", "line", "area", "candlestick", "pie", "donut"]
}
]

View File

@ -2509,6 +2509,57 @@
}
]
},
"bigintfield": {
"name": "BigInt Field",
"icon": "TagBold",
"styles": ["size"],
"requiredAncestors": ["form"],
"editable": true,
"size": {
"width": 400,
"height": 50
},
"settings": [
{
"type": "field/bigint",
"label": "Field",
"key": "field",
"required": true
},
{
"type": "text",
"label": "Label",
"key": "label"
},
{
"type": "text",
"label": "Placeholder",
"key": "placeholder"
},
{
"type": "text",
"label": "Default value",
"key": "defaultValue"
},
{
"type": "event",
"label": "On change",
"key": "onChange",
"context": [
{
"label": "Field Value",
"key": "value"
}
]
},
{
"type": "boolean",
"label": "Disabled",
"key": "disabled",
"defaultValue": false
}
]
},
"passwordfield": {
"name": "Password Field",
"icon": "LockClosed",

View File

@ -21,6 +21,7 @@
const FieldTypeToComponentMap = {
string: "stringfield",
number: "numberfield",
bigint: "bigintfield",
options: "optionsfield",
array: "multifieldselect",
boolean: "booleanfield",

View File

@ -133,7 +133,7 @@
on:change={e => onOperatorChange(filter, e.detail)}
placeholder={null}
/>
{#if ["string", "longform", "number", "formula"].includes(filter.type)}
{#if ["string", "longform", "number", "bigint", "formula"].includes(filter.type)}
<Input disabled={filter.noValue} bind:value={filter.value} />
{:else if ["options", "array"].includes(filter.type)}
<Combobox

View File

@ -0,0 +1,7 @@
<script>
import StringField from "./StringField.svelte"
export let defaultValue
</script>
<StringField {...$$props} type="bigint" {defaultValue} />

View File

@ -33,7 +33,10 @@
formStep
)
$: schemaType = fieldSchema?.type !== "formula" ? fieldSchema?.type : "string"
$: schemaType =
fieldSchema?.type !== "formula" && fieldSchema?.type !== "bigint"
? fieldSchema?.type
: "string"
// Focus label when editing
let labelNode

View File

@ -2,6 +2,7 @@ export { default as form } from "./Form.svelte"
export { default as fieldgroup } from "./FieldGroup.svelte"
export { default as stringfield } from "./StringField.svelte"
export { default as numberfield } from "./NumberField.svelte"
export { default as bigintfield } from "./BigIntField.svelte"
export { default as optionsfield } from "./OptionsField.svelte"
export { default as multifieldselect } from "./MultiFieldSelect.svelte"
export { default as booleanfield } from "./BooleanField.svelte"

View File

@ -6,6 +6,7 @@ const schemaComponentMap = {
string: "stringfield",
options: "optionsfield",
number: "numberfield",
bigint: "bigintfield",
datetime: "datetimefield",
boolean: "booleanfield",
formula: "stringfield",

View File

@ -37,8 +37,12 @@
$: sortedBy = column.name === $sort.column
$: canMoveLeft = orderable && idx > 0
$: canMoveRight = orderable && idx < $renderedColumns.length - 1
$: ascendingLabel = column.schema?.type === "number" ? "low-high" : "A-Z"
$: descendingLabel = column.schema?.type === "number" ? "high-low" : "Z-A"
$: ascendingLabel = ["number", "bigint"].includes(column.schema?.type)
? "low-high"
: "A-Z"
$: descendingLabel = ["number", "bigint"].includes(column.schema?.type)
? "high-low"
: "Z-A"
const editColumn = () => {
dispatch("edit-column", column.schema)

View File

@ -18,6 +18,7 @@ const TypeIconMap = {
link: "DataCorrelated",
formula: "Calculator",
json: "Brackets",
bigint: "TagBold",
}
export const getColumnIcon = column => {

View File

@ -155,7 +155,7 @@ export default class DataFetch {
let sortType = "string"
if (sortColumn) {
const type = schema?.[sortColumn]?.type
sortType = type === "number" ? "number" : "string"
sortType = type === "number" || type === "bigint" ? "number" : "string"
}
this.options.sortType = sortType

View File

@ -53,6 +53,9 @@ function generateSchema(
schema.float(key)
}
break
case FieldTypes.BIGINT:
schema.bigint(key)
break
case FieldTypes.BOOLEAN:
schema.boolean(key)
break

View File

@ -48,7 +48,6 @@ const SQL_STRING_TYPE_MAP = {
blob: FieldTypes.STRING,
long: FieldTypes.STRING,
text: FieldTypes.STRING,
bigint: FieldTypes.STRING,
}
const SQL_BOOLEAN_TYPE_MAP = {
@ -59,6 +58,7 @@ const SQL_BOOLEAN_TYPE_MAP = {
const SQL_MISC_TYPE_MAP = {
json: FieldTypes.JSON,
bigint: FieldTypes.BIGINT,
}
const SQL_TYPE_MAP = {

View File

@ -38,7 +38,7 @@ export const getValidOperatorsForType = (
}[] = []
if (type === "string") {
ops = stringOps
} else if (type === "number") {
} else if (type === "number" || type === "bigint") {
ops = numOps
} else if (type === "options") {
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]

View File

@ -1,3 +1,4 @@
import { Account } from "../../documents"
import { Hosting } from "../../sdk"
export interface CreateAccountRequest {
@ -11,3 +12,11 @@ export interface CreateAccountRequest {
name?: string
password: string
}
export interface SearchAccountsRequest {
// one or the other - not both
email?: string
tenantId?: string
}
export type SearchAccountsResponse = Account[]

View File

@ -15,6 +15,7 @@ export enum FieldType {
JSON = "json",
INTERNAL = "internal",
BARCODEQR = "barcodeqr",
BIGINT = "bigint",
}
export interface RowAttachment {

View File

@ -53,6 +53,8 @@ async function passportCallback(
}
export const login = async (ctx: Ctx<LoginRequest>, next: any) => {
const tenantId = context.getTenantId()
console.log(tenantId)
const email = ctx.request.body.username
const user = await userSdk.getUserByEmail(email)

View File

@ -1,15 +1,17 @@
import AccountInternalAPIClient from "./AccountInternalAPIClient"
import { AccountAPI, LicenseAPI } from "./apis"
import { AccountAPI, LicenseAPI, AuthAPI } from "./apis"
import { State } from "../../types"
export default class AccountInternalAPI {
client: AccountInternalAPIClient
auth: AuthAPI
accounts: AccountAPI
licenses: LicenseAPI
constructor(state: State) {
this.client = new AccountInternalAPIClient(state)
this.auth = new AuthAPI(this.client)
this.accounts = new AccountAPI(this.client)
this.licenses = new LicenseAPI(this.client)
}

View File

@ -1,5 +1,5 @@
import { Response } from "node-fetch"
import { Account, CreateAccountRequest } from "@budibase/types"
import { Account, CreateAccountRequest, SearchAccountsRequest, SearchAccountsResponse } from "@budibase/types"
import AccountInternalAPIClient from "../AccountInternalAPIClient"
import { APIRequestOpts } from "../../../types"
@ -72,4 +72,66 @@ export default class AccountAPI {
}
return response
}
async deleteCurrentAccount() {
const [response, json] = await this.client.del(
`/api/accounts`
)
return response
}
async verifyAccount(
verificationCode: string,
opts: APIRequestOpts = { doExpect: true }
): Promise<Response> {
const [response, json] = await this.client.post(
`/api/accounts/verify`,
{
body: { verificationCode },
}
)
if (opts.doExpect) {
expect(response).toHaveStatusCode(200)
}
return response
}
async verifyAccountSendEmail(
email: string,
opts: APIRequestOpts = { doExpect: true }
): Promise<Response> {
const [response, json] = await this.client.post(
`/api/accounts/verify/send`,
{
body: { email },
}
)
if (opts.doExpect) {
expect(response).toHaveStatusCode(200)
}
return response
}
async search(
searchType: string,
search: 'email' | 'tenantId',
opts: APIRequestOpts = { doExpect: true }
): Promise<[Response, SearchAccountsResponse]> {
let body: SearchAccountsRequest = {}
if (search === 'email') {
body.email = searchType;
} else if (search === 'tenantId') {
body.tenantId = searchType;
}
const [response, json] = await this.client.post(
`/api/accounts/search`,
{body: body}
)
if (opts.doExpect) {
expect(response).toHaveStatusCode(200)
}
return [response, json]
}
}

View File

@ -0,0 +1,32 @@
import { Response } from "node-fetch"
import AccountInternalAPIClient from "../AccountInternalAPIClient"
import { APIRequestOpts } from "../../../types"
export default class AuthAPI {
client: AccountInternalAPIClient
constructor(client: AccountInternalAPIClient) {
this.client = client
}
async login(
email: string,
password: string,
opts: APIRequestOpts = { doExpect: true }
): Promise<[Response, string]> {
const [response, json] = await this.client.post(
`/api/auth/login`,
{
body: {
email: email,
password: password,
},
}
)
if (opts.doExpect) {
expect(response).toHaveStatusCode(200)
}
const cookie = response.headers.get("set-cookie")
return [response, cookie!]
}
}

View File

@ -1,2 +1,3 @@
export { default as AuthAPI } from "./AuthAPI"
export { default as AccountAPI } from "./AccountAPI"
export { default as LicenseAPI } from "./LicenseAPI"

View File

@ -0,0 +1,29 @@
import { AccountInternalAPI } from "../api"
import { BudibaseTestConfiguration } from "../../shared"
export default class TestConfiguration<T> extends BudibaseTestConfiguration {
// apis
api: AccountInternalAPI
context: T
constructor() {
super()
this.api = new AccountInternalAPI(this.state)
this.context = <T>{}
}
async beforeAll() {
await super.beforeAll()
await this.setApiKey()
}
async afterAll() {
await super.afterAll()
}
async setApiKey() {
const apiKeyResponse = await this.internalApi.self.getApiKey()
this.state.apiKey = apiKeyResponse.apiKey
}
}

View File

@ -0,0 +1,20 @@
import { generator } from "../../shared"
import { Hosting, CreateAccountRequest } from "@budibase/types"
export const generateAccount = (): CreateAccountRequest => {
const uuid = generator.guid()
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,
}
}

View File

@ -0,0 +1 @@
export * as accounts from "./accounts"

View File

@ -0,0 +1,20 @@
import TestConfiguration from "../../config/TestConfiguration"
import * as fixtures from "../../fixtures"
describe("Account API - Create Account", () => {
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
it("Creates a new account", async () => {
await config.api.accounts.create({
...fixtures.accounts.generateAccount()
})
})
})

View File

@ -0,0 +1,40 @@
import TestConfiguration from "../../config/TestConfiguration"
import * as fixtures from "../../fixtures"
describe("Account API - Delete Account", () => {
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
it("Deletes an account", async () => {
await config.doInNewState(async () => {
// Create account
const createAccountRequest = fixtures.accounts.generateAccount()
await config.api.accounts.create(createAccountRequest)
// Login - Get cookie
await config.login(
createAccountRequest.email,
createAccountRequest.password,
createAccountRequest.tenantId
)
// Delete account
const res = await config.api.accounts.deleteCurrentAccount()
expect(res.status).toBe(204)
})
})
it("Deletes an account by ID", async () => {
const [response, account] = await config.api.accounts.create({
...fixtures.accounts.generateAccount()
})
await config.api.accounts.delete(account.accountId)
})
})

View File

@ -0,0 +1,43 @@
import TestConfiguration from "../../config/TestConfiguration"
import { generator } from "../../../shared"
describe("Account API - Search for Account", () => {
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
describe("POST /api/accounts/search", () => {
describe("by tenant", () => {
it("returns 200 + empty", async () => {
const tenantId = generator.string()
const [res, body] = await config.api.accounts.search(tenantId, "tenantId")
expect(res.status).toBe(200)
expect(body.length).toBe(0)
})
it("returns 200 + found", async () => {
const [res, body] = await config.api.accounts.search(config.state.tenantId!, "tenantId")
expect(res.status).toBe(200)
expect(body.length).toBe(1)
expect(body[0].tenantId).toBe(config.state.tenantId)
})
})
describe("by email", () => {
it("returns 200 + empty", async () => {
await config.api.accounts.search(generator.word(), "email")
})
it("returns 200 + found", async () => {
await config.api.accounts.search(generator.word(), "email")
})
})
})
})

View File

@ -0,0 +1,29 @@
import TestConfiguration from "../../config/TestConfiguration"
import { generator } from "../../../shared"
import * as fixtures from "../../fixtures";
describe("Account API - Validate Account", () => {
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
const tenant = generator.word({length: 6})
const email = `${tenant}@budibase.com`
it("Validates an email", async () => {
await config.api.accounts.validateEmail(email)
})
it("Validates a tenant ID", async () => {
await config.api.accounts.validateTenantId(tenant)
})
})

View File

@ -0,0 +1,38 @@
import TestConfiguration from "../../config/TestConfiguration"
import { generator } from "../../../shared"
import * as fixtures from "../../fixtures";
describe("Account API - Verify Account", () => {
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
it("Verify an account", async () => {
// Create account
await config.api.accounts.create({
...fixtures.accounts.generateAccount()
})
// Invite user
// Verify account via code
await config.api.accounts.verifyAccount()
})
it("Send account verification email ", async () => {
// Create account
await config.api.accounts.create({
...fixtures.accounts.generateAccount()
})
// Invite user
// Verify account via email
await config.api.accounts.verifyAccountSendEmail()
})
})

View File

@ -68,8 +68,7 @@ async function loginAsAdmin() {
}
async function loginAsAccount(account: CreateAccountRequest) {
const [res, cookie] = await internalApi.auth.login(
account.tenantId,
const [res, cookie] = await accountsApi.auth.login(
account.email,
account.password,
API_OPTS
@ -90,6 +89,8 @@ async function setup() {
// @ts-ignore
global.qa.tenantId = account.tenantId
// @ts-ignore
global.qa.email = account.email
// @ts-ignore
global.qa.accountId = newAccount.accountId
await loginAsAccount(account)
} else {

View File

@ -23,6 +23,8 @@ export default class BudibaseTestConfiguration {
// @ts-ignore
this.state.tenantId = global.qa.tenantId
// @ts-ignore
this.state.email = global.qa.email
// @ts-ignore
this.state.cookie = global.qa.authCookie
}
@ -40,10 +42,37 @@ export default class BudibaseTestConfiguration {
// AUTH
async doInNewState(task: any) {
return this.doWithState(task, {})
}
async doWithState(task: any, state: State) {
const original = this.state
// override the state
this.state.apiKey = state.apiKey
this.state.appId = state.appId
this.state.cookie = state.cookie
this.state.tableId = state.tableId
this.state.tenantId = state.tenantId
this.state.email = state.email
await task()
// restore the state
this.state.apiKey = original.apiKey
this.state.appId = original.appId
this.state.cookie = original.cookie
this.state.tableId = original.tableId
this.state.tenantId = original.tenantId
this.state.email = original.email
}
async login(email: string, password: string, tenantId?: string) {
if (!tenantId && this.state.tenantId) {
tenantId = this.state.tenantId
} else {
}
if (!tenantId) {
throw new Error("Could not determine tenant id")
}
const [res, cookie] = await this.internalApi.auth.login(

View File

@ -4,4 +4,5 @@ export interface State {
cookie?: string
tableId?: string
tenantId?: string
email?: string
}

7
scripts/getCurrentVersion.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
version=$(cat lerna.json \
| grep version \
| head -1 \
| awk -F: '{gsub(/"/,"",$2);gsub(/[[:space:]]*/,"",$2); print $2}' \
| sed 's/[",]//g')
echo $version

View File

@ -1,9 +1,5 @@
#!/bin/bash
version=$(cat lerna.json \
| grep version \
| head -1 \
| awk -F: '{gsub(/"/,"",$2);gsub(/[[:space:]]*/,"",$2); print $2}' \
| sed 's/[",]//g')
version=$(./scripts/getCurrentVersion.sh)
echo "Setting version $version"
yarn lerna exec "yarn version --no-git-tag-version --new-version=$version"
echo "Updating dependencies"