Remove all uses of config.createTable

This commit is contained in:
Sam Rose 2024-03-13 16:32:33 +00:00
parent d3c8a28ab6
commit 68777b0843
No known key found for this signature in database
1 changed files with 122 additions and 145 deletions

View File

@ -32,7 +32,6 @@ import {
expectAnyInternalColsAttributes,
generator,
mocks,
structures,
} from "@budibase/backend-core/tests"
import _, { merge } from "lodash"
import * as uuid from "uuid"
@ -149,19 +148,6 @@ describe.each([
}
: undefined
async function createTable(
cfg: Omit<SaveTableRequest, "sourceId" | "sourceType">,
opts?: { skipReassigning: boolean }
) {
let table
if (dsProvider) {
table = await config.createExternalTable(cfg, opts)
} else {
table = await config.createTable(cfg, opts)
}
return table
}
beforeAll(async () => {
table = await config.api.table.save(defaultTable())
})
@ -308,7 +294,8 @@ describe.each([
inclusion: ["Alpha", "Beta", "Gamma"],
},
}
const table = await createTable({
const table = await config.api.table.save(
saveTableRequest({
name: "TestTable2",
type: "table",
schema: {
@ -345,8 +332,11 @@ describe.each([
optsFieldStrKnown: optsField,
},
})
)
const row = {
const datetimeStr = "1984-04-20T00:00:00.000Z"
const row = await config.api.row.save(table._id!, {
name: "Test Row",
stringUndefined: undefined,
stringNull: null,
@ -359,8 +349,8 @@ describe.each([
datetimeEmptyString: "",
datetimeNull: null,
datetimeUndefined: undefined,
datetimeString: "1984-04-20T00:00:00.000Z",
datetimeDate: new Date("1984-04-20"),
datetimeString: datetimeStr,
datetimeDate: new Date(datetimeStr),
boolNull: null,
boolEmpty: "",
boolUndefined: undefined,
@ -379,69 +369,58 @@ describe.each([
optsFieldUndefined: undefined,
optsFieldNull: null,
optsFieldStrKnown: "Alpha",
}
})
const createdRow = await config.createRow(row)
const id = createdRow._id!
const saved = await config.api.row.get(table._id!, id)
expect(saved.stringUndefined).toBe(undefined)
expect(saved.stringNull).toBe(null)
expect(saved.stringString).toBe("i am a string")
expect(saved.numberEmptyString).toBe(null)
expect(saved.numberNull).toBe(null)
expect(saved.numberUndefined).toBe(undefined)
expect(saved.numberString).toBe(123)
expect(saved.numberNumber).toBe(123)
expect(saved.datetimeEmptyString).toBe(null)
expect(saved.datetimeNull).toBe(null)
expect(saved.datetimeUndefined).toBe(undefined)
expect(saved.datetimeString).toBe(
new Date(row.datetimeString).toISOString()
)
expect(saved.datetimeDate).toBe(row.datetimeDate.toISOString())
expect(saved.boolNull).toBe(null)
expect(saved.boolEmpty).toBe(null)
expect(saved.boolUndefined).toBe(undefined)
expect(saved.boolString).toBe(true)
expect(saved.boolBool).toBe(true)
expect(saved.attachmentNull).toEqual([])
expect(saved.attachmentUndefined).toBe(undefined)
expect(saved.attachmentEmpty).toEqual([])
expect(saved.attachmentEmptyArrayStr).toEqual([])
expect(saved.arrayFieldEmptyArrayStr).toEqual([])
expect(saved.arrayFieldNull).toEqual([])
expect(saved.arrayFieldUndefined).toEqual(undefined)
expect(saved.optsFieldEmptyStr).toEqual(null)
expect(saved.optsFieldUndefined).toEqual(undefined)
expect(saved.optsFieldNull).toEqual(null)
expect(saved.arrayFieldArrayStrKnown).toEqual(["One"])
expect(saved.optsFieldStrKnown).toEqual("Alpha")
expect(row.stringUndefined).toBe(undefined)
expect(row.stringNull).toBe(null)
expect(row.stringString).toBe("i am a string")
expect(row.numberEmptyString).toBe(null)
expect(row.numberNull).toBe(null)
expect(row.numberUndefined).toBe(undefined)
expect(row.numberString).toBe(123)
expect(row.numberNumber).toBe(123)
expect(row.datetimeEmptyString).toBe(null)
expect(row.datetimeNull).toBe(null)
expect(row.datetimeUndefined).toBe(undefined)
expect(row.datetimeString).toBe(new Date(datetimeStr).toISOString())
expect(row.datetimeDate).toBe(new Date(datetimeStr).toISOString())
expect(row.boolNull).toBe(null)
expect(row.boolEmpty).toBe(null)
expect(row.boolUndefined).toBe(undefined)
expect(row.boolString).toBe(true)
expect(row.boolBool).toBe(true)
expect(row.attachmentNull).toEqual([])
expect(row.attachmentUndefined).toBe(undefined)
expect(row.attachmentEmpty).toEqual([])
expect(row.attachmentEmptyArrayStr).toEqual([])
expect(row.arrayFieldEmptyArrayStr).toEqual([])
expect(row.arrayFieldNull).toEqual([])
expect(row.arrayFieldUndefined).toEqual(undefined)
expect(row.optsFieldEmptyStr).toEqual(null)
expect(row.optsFieldUndefined).toEqual(undefined)
expect(row.optsFieldNull).toEqual(null)
expect(row.arrayFieldArrayStrKnown).toEqual(["One"])
expect(row.optsFieldStrKnown).toEqual("Alpha")
})
})
describe("view save", () => {
it("views have extra data trimmed", async () => {
const table = await createTable({
type: "table",
const table = await config.api.table.save(
saveTableRequest({
name: "orders",
primary: ["OrderID"],
schema: {
Country: {
type: FieldType.STRING,
name: "Country",
},
OrderID: {
type: FieldType.NUMBER,
name: "OrderID",
},
Story: {
type: FieldType.STRING,
name: "Story",
},
},
})
)
const createViewResponse = await config.api.viewV2.create({
tableId: table._id!,
@ -450,9 +429,6 @@ describe.each([
Country: {
visible: true,
},
OrderID: {
visible: true,
},
},
})
@ -468,8 +444,8 @@ describe.each([
expect(row.Story).toBeUndefined()
expect(row).toEqual({
...defaultRowFields,
OrderID: createRowResponse.OrderID,
Country: "Aussy",
id: createRowResponse.id,
_id: createRowResponse._id,
_rev: createRowResponse._rev,
tableId: table._id,
@ -857,7 +833,7 @@ describe.each([
it("should allow enriching attachment rows", async () => {
const table = await config.createAttachmentTable()
const attachmentId = `${structures.uuid()}.csv`
const attachmentId = `${uuid.v4()}.csv`
const row = await config.createRow({
name: "test",
description: "test",
@ -1998,9 +1974,9 @@ describe.each([
`
).toString("base64")
const table = await config.createTable({
const table = await config.api.table.save(
saveTableRequest({
name: "table",
type: "table",
schema: {
text: {
name: "text",
@ -2014,6 +1990,7 @@ describe.each([
},
},
})
)
for (let i = 0; i < 10; i++) {
await config.api.row.save(table._id!, { text: "foo" })
@ -2051,9 +2028,8 @@ describe.each([
it("should not carry over context between formulas", async () => {
const js = Buffer.from(`return $("[text]");`).toString("base64")
const table = await config.createTable({
name: "table",
type: "table",
const table = await config.api.table.save(
saveTableRequest({
schema: {
text: {
name: "text",
@ -2067,6 +2043,7 @@ describe.each([
},
},
})
)
for (let i = 0; i < 10; i++) {
await config.api.row.save(table._id!, { text: `foo${i}` })