From ce1b626f68e5f11425c7b9e9d1f7906b19547472 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 28 Nov 2022 13:24:39 +0000 Subject: [PATCH] Updates to fix build. --- .../server/src/migrations/tests/index.spec.ts | 2 +- .../src/tests/utilities/TestConfiguration.js | 4 +- .../server/src/tests/utilities/controllers.js | 16 ----- .../server/src/tests/utilities/controllers.ts | 14 ++++ .../tests/utilities/{index.js => index.ts} | 4 +- .../{structures.js => structures.ts} | 72 ++++++++++--------- packages/server/tsconfig.build.json | 1 + 7 files changed, 59 insertions(+), 54 deletions(-) delete mode 100644 packages/server/src/tests/utilities/controllers.js create mode 100644 packages/server/src/tests/utilities/controllers.ts rename packages/server/src/tests/utilities/{index.js => index.ts} (77%) rename packages/server/src/tests/utilities/{structures.js => structures.ts} (58%) diff --git a/packages/server/src/migrations/tests/index.spec.ts b/packages/server/src/migrations/tests/index.spec.ts index 8effaec52b..cf283cf518 100644 --- a/packages/server/src/migrations/tests/index.spec.ts +++ b/packages/server/src/migrations/tests/index.spec.ts @@ -6,7 +6,7 @@ import { context, } from "@budibase/backend-core" import TestConfig from "../../tests/utilities/TestConfiguration" -import structures from "../../tests/utilities/structures" +import * as structures from "../../tests/utilities/structures" import { MIGRATIONS } from "../" import * as helpers from "./helpers" diff --git a/packages/server/src/tests/utilities/TestConfiguration.js b/packages/server/src/tests/utilities/TestConfiguration.js index 76c79b838f..fd9635e9f1 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.js +++ b/packages/server/src/tests/utilities/TestConfiguration.js @@ -27,7 +27,7 @@ const controllers = require("./controllers") const supertest = require("supertest") const { cleanup } = require("../../utilities/fileSystem") const newid = require("../../db/newid") -const { DocumentType, generateUserMetadataID } = require("../../db/utils") +const { generateUserMetadataID } = require("../../db/utils") const { startup } = require("../../startup") const GLOBAL_USER_ID = "us_uuid1" @@ -360,7 +360,7 @@ class TestConfiguration { return context.doInAppContext(prodAppId, async () => { const db = context.getProdAppDB() - return await db.get(DocumentType.APP_METADATA) + return await db.get(dbCore.DocumentType.APP_METADATA) }) } diff --git a/packages/server/src/tests/utilities/controllers.js b/packages/server/src/tests/utilities/controllers.js deleted file mode 100644 index 8da6c97047..0000000000 --- a/packages/server/src/tests/utilities/controllers.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = { - table: require("../../api/controllers/table"), - row: require("../../api/controllers/row"), - role: require("../../api/controllers/role"), - perms: require("../../api/controllers/permission"), - view: require("../../api/controllers/view"), - app: require("../../api/controllers/application"), - user: require("../../api/controllers/user"), - automation: require("../../api/controllers/automation"), - datasource: require("../../api/controllers/datasource"), - query: require("../../api/controllers/query"), - screen: require("../../api/controllers/screen"), - webhook: require("../../api/controllers/webhook"), - layout: require("../../api/controllers/layout"), - deploy: require("../../api/controllers/deploy"), -} diff --git a/packages/server/src/tests/utilities/controllers.ts b/packages/server/src/tests/utilities/controllers.ts new file mode 100644 index 0000000000..315b61551c --- /dev/null +++ b/packages/server/src/tests/utilities/controllers.ts @@ -0,0 +1,14 @@ +export * as table from "../../api/controllers/table" +export * as row from "../../api/controllers/row" +export * as role from "../../api/controllers/role" +export * as perms from "../../api/controllers/permission" +export * as view from "../../api/controllers/view" +export * as app from "../../api/controllers/application" +export * as user from "../../api/controllers/user" +export * as automation from "../../api/controllers/automation" +export * as datasource from "../../api/controllers/datasource" +export * as query from "../../api/controllers/query" +export * as screen from "../../api/controllers/screen" +export * as webhook from "../../api/controllers/webhook" +export * as layout from "../../api/controllers/layout" +export * as deploy from "../../api/controllers/deploy" diff --git a/packages/server/src/tests/utilities/index.js b/packages/server/src/tests/utilities/index.ts similarity index 77% rename from packages/server/src/tests/utilities/index.js rename to packages/server/src/tests/utilities/index.ts index aa8039ce2f..270e8b7b49 100644 --- a/packages/server/src/tests/utilities/index.js +++ b/packages/server/src/tests/utilities/index.ts @@ -1,5 +1,5 @@ -exports.makePartial = obj => { - const newObj = {} +export function makePartial(obj: any) { + const newObj: any = {} for (let key of Object.keys(obj)) { if (typeof obj[key] === "object") { newObj[key] = exports.makePartial(obj[key]) diff --git a/packages/server/src/tests/utilities/structures.js b/packages/server/src/tests/utilities/structures.ts similarity index 58% rename from packages/server/src/tests/utilities/structures.js rename to packages/server/src/tests/utilities/structures.ts index 610084b04e..a412be4931 100644 --- a/packages/server/src/tests/utilities/structures.js +++ b/packages/server/src/tests/utilities/structures.ts @@ -1,13 +1,13 @@ -const { roles, permissions } = require("@budibase/backend-core") -const { createHomeScreen } = require("../../constants/screens") -const { EMPTY_LAYOUT } = require("../../constants/layouts") -const { cloneDeep } = require("lodash/fp") +import { roles, permissions } from "@budibase/backend-core" +import { createHomeScreen } from "../../constants/screens" +import { EMPTY_LAYOUT } from "../../constants/layouts" +import { cloneDeep } from "lodash/fp" +import { TRIGGER_DEFINITIONS, ACTION_DEFINITIONS } from "../../automations" const { v4: uuidv4 } = require("uuid") -const { TRIGGER_DEFINITIONS, ACTION_DEFINITIONS } = require("../../automations") -exports.TENANT_ID = "default" +export const TENANT_ID = "default" -exports.basicTable = () => { +export function basicTable() { return { name: "TestTable", type: "table", @@ -29,16 +29,16 @@ exports.basicTable = () => { } } -exports.basicView = tableId => { +export function basicView(tableId: string) { return { tableId, name: "ViewTest", } } -exports.filterView = tableId => { +export function filterView(tableId: string) { return { - ...this.basicView(tableId), + ...basicView(tableId), filters: [ { value: 0, @@ -49,56 +49,58 @@ exports.filterView = tableId => { } } -exports.calculationView = tableId => { +export function calculationView(tableId: string) { return { - ...this.basicView(tableId), + ...basicView(tableId), field: "count", calculation: "sum", } } -exports.view = tableId => { +export function view(tableId: string) { return { - ...this.filterView(tableId), - ...this.calculationView(tableId), + ...filterView(tableId), + ...calculationView(tableId), } } -exports.automationStep = (actionDefinition = ACTION_DEFINITIONS.CREATE_ROW) => { +export function automationStep( + actionDefinition = ACTION_DEFINITIONS.CREATE_ROW +) { return { id: uuidv4(), ...actionDefinition, } } -exports.automationTrigger = ( +export function automationTrigger( triggerDefinition = TRIGGER_DEFINITIONS.ROW_SAVED -) => { +) { return { id: uuidv4(), ...triggerDefinition, } } -exports.newAutomation = ({ steps, trigger } = {}) => { - const automation = exports.basicAutomation() +export function newAutomation({ steps, trigger }: any = {}) { + const automation: any = basicAutomation() if (trigger) { automation.definition.trigger = trigger } else { - automation.definition.trigger = exports.automationTrigger() + automation.definition.trigger = automationTrigger() } if (steps) { automation.definition.steps = steps } else { - automation.definition.steps = [exports.automationStep()] + automation.definition.steps = [automationStep()] } return automation } -exports.basicAutomation = () => { +export function basicAutomation() { return { name: "My Automation", screenId: "kasdkfldsafkl", @@ -114,7 +116,7 @@ exports.basicAutomation = () => { } } -exports.basicRow = tableId => { +export function basicRow(tableId: string) { return { name: "Test Contact", description: "original description", @@ -122,15 +124,19 @@ exports.basicRow = tableId => { } } -exports.basicLinkedRow = (tableId, linkedRowId, linkField = "link") => { +export function basicLinkedRow( + tableId: string, + linkedRowId: string, + linkField: string = "link" +) { // this is based on the basic linked tables you get from the test configuration return { - ...exports.basicRow(tableId), + ...basicRow(tableId), [linkField]: [linkedRowId], } } -exports.basicRole = () => { +export function basicRole() { return { name: "NewRole", inherits: roles.BUILTIN_ROLE_IDS.BASIC, @@ -138,7 +144,7 @@ exports.basicRole = () => { } } -exports.basicDatasource = () => { +export function basicDatasource() { return { datasource: { type: "datasource", @@ -149,7 +155,7 @@ exports.basicDatasource = () => { } } -exports.basicQuery = datasourceId => { +export function basicQuery(datasourceId: string) { return { datasourceId: datasourceId, name: "New Query", @@ -160,7 +166,7 @@ exports.basicQuery = datasourceId => { } } -exports.basicUser = role => { +export function basicUser(role: string) { return { email: "bill@bill.com", password: "yeeooo", @@ -168,15 +174,15 @@ exports.basicUser = role => { } } -exports.basicScreen = () => { +export function basicScreen() { return createHomeScreen() } -exports.basicLayout = () => { +export function basicLayout() { return cloneDeep(EMPTY_LAYOUT) } -exports.basicWebhook = automationId => { +export function basicWebhook(automationId: string) { return { live: true, name: "webhook", diff --git a/packages/server/tsconfig.build.json b/packages/server/tsconfig.build.json index 2212a5e100..bbc0bfa0ee 100644 --- a/packages/server/tsconfig.build.json +++ b/packages/server/tsconfig.build.json @@ -1,6 +1,7 @@ { "compilerOptions": { "target": "es6", + "allowJs": true, "module": "commonjs", "lib": ["es2020"], "strict": true,