Add creation tests

This commit is contained in:
Adria Navarro 2024-02-09 15:27:31 +01:00
parent 7aa1176a36
commit c18a3d4abb
2 changed files with 47 additions and 2 deletions

View File

@ -14,7 +14,6 @@ import { events } from "@budibase/backend-core"
import { import {
BulkImportRequest, BulkImportRequest,
BulkImportResponse, BulkImportResponse,
DocumentType,
FetchTablesResponse, FetchTablesResponse,
MigrateRequest, MigrateRequest,
MigrateResponse, MigrateResponse,
@ -25,7 +24,6 @@ import {
TableResponse, TableResponse,
TableSourceType, TableSourceType,
UserCtx, UserCtx,
SEPARATOR,
} from "@budibase/types" } from "@budibase/types"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import { jsonFromCsvString } from "../../../utilities/csv" import { jsonFromCsvString } from "../../../utilities/csv"

View File

@ -18,6 +18,12 @@ import * as setup from "./utilities"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import * as uuid from "uuid" 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 const { basicTable } = setup.structures
describe("/tables", () => { describe("/tables", () => {
@ -60,6 +66,47 @@ describe("/tables", () => {
expect(events.table.created).toBeCalledWith(res.body) 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 () => { it("creates a table via data import", async () => {
const table: SaveTableRequest = basicTable() const table: SaveTableRequest = basicTable()
table.rows = [{ name: "test-name", description: "test-desc" }] table.rows = [{ name: "test-name", description: "test-desc" }]