From c18a3d4abb92c0b33221c0dc52969ee642fccfd1 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 9 Feb 2024 15:27:31 +0100 Subject: [PATCH] Add creation tests --- .../server/src/api/controllers/table/index.ts | 2 - .../server/src/api/routes/tests/table.spec.ts | 47 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/table/index.ts b/packages/server/src/api/controllers/table/index.ts index db2bd672d0..40fc2aedb4 100644 --- a/packages/server/src/api/controllers/table/index.ts +++ b/packages/server/src/api/controllers/table/index.ts @@ -14,7 +14,6 @@ import { events } from "@budibase/backend-core" import { BulkImportRequest, BulkImportResponse, - DocumentType, FetchTablesResponse, MigrateRequest, MigrateResponse, @@ -25,7 +24,6 @@ import { TableResponse, TableSourceType, UserCtx, - SEPARATOR, } from "@budibase/types" import sdk from "../../../sdk" import { jsonFromCsvString } from "../../../utilities/csv" diff --git a/packages/server/src/api/routes/tests/table.spec.ts b/packages/server/src/api/routes/tests/table.spec.ts index 62efdda448..4da4e25ace 100644 --- a/packages/server/src/api/routes/tests/table.spec.ts +++ b/packages/server/src/api/routes/tests/table.spec.ts @@ -18,6 +18,12 @@ import * as setup from "./utilities" import sdk from "../../../sdk" import * as uuid from "uuid" +import tk from "timekeeper" +import { mocks } from "@budibase/backend-core/tests" +import { TableToBuild } from "src/tests/utilities/TestConfiguration" + +tk.freeze(mocks.date.MOCK_DATE) + const { basicTable } = setup.structures describe("/tables", () => { @@ -60,6 +66,47 @@ describe("/tables", () => { expect(events.table.created).toBeCalledWith(res.body) }) + it("creates all the passed fields", async () => { + const tableData: TableToBuild = { + name: "TestTable", + type: "table", + schema: { + autoId: { + name: "id", + type: FieldType.NUMBER, + subtype: AutoFieldSubType.AUTO_ID, + autocolumn: true, + constraints: { + type: "number", + presence: false, + }, + }, + }, + views: { + view1: { + id: "viewId", + version: 2, + name: "table view", + tableId: "tableId", + }, + }, + } + const testTable = await config.createTable(tableData) + + const expected: Table = { + ...tableData, + type: "table", + sourceType: TableSourceType.INTERNAL, + sourceId: expect.any(String), + _rev: expect.stringMatching(/^1-.+/), + updatedAt: mocks.date.MOCK_DATE.toISOString(), + } + expect(testTable).toEqual(expected) + + const persistedTable = await config.api.table.get(testTable._id!) + expect(persistedTable).toEqual(expected) + }) + it("creates a table via data import", async () => { const table: SaveTableRequest = basicTable() table.rows = [{ name: "test-name", description: "test-desc" }]