Add creation tests
This commit is contained in:
parent
7aa1176a36
commit
c18a3d4abb
|
@ -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"
|
||||
|
|
|
@ -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" }]
|
||||
|
|
Loading…
Reference in New Issue