Remove all uses of config.createTable
This commit is contained in:
parent
d3c8a28ab6
commit
68777b0843
|
@ -32,7 +32,6 @@ import {
|
||||||
expectAnyInternalColsAttributes,
|
expectAnyInternalColsAttributes,
|
||||||
generator,
|
generator,
|
||||||
mocks,
|
mocks,
|
||||||
structures,
|
|
||||||
} from "@budibase/backend-core/tests"
|
} from "@budibase/backend-core/tests"
|
||||||
import _, { merge } from "lodash"
|
import _, { merge } from "lodash"
|
||||||
import * as uuid from "uuid"
|
import * as uuid from "uuid"
|
||||||
|
@ -149,19 +148,6 @@ describe.each([
|
||||||
}
|
}
|
||||||
: undefined
|
: 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 () => {
|
beforeAll(async () => {
|
||||||
table = await config.api.table.save(defaultTable())
|
table = await config.api.table.save(defaultTable())
|
||||||
})
|
})
|
||||||
|
@ -308,45 +294,49 @@ describe.each([
|
||||||
inclusion: ["Alpha", "Beta", "Gamma"],
|
inclusion: ["Alpha", "Beta", "Gamma"],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const table = await createTable({
|
const table = await config.api.table.save(
|
||||||
name: "TestTable2",
|
saveTableRequest({
|
||||||
type: "table",
|
name: "TestTable2",
|
||||||
schema: {
|
type: "table",
|
||||||
name: str,
|
schema: {
|
||||||
stringUndefined: str,
|
name: str,
|
||||||
stringNull: str,
|
stringUndefined: str,
|
||||||
stringString: str,
|
stringNull: str,
|
||||||
numberEmptyString: number,
|
stringString: str,
|
||||||
numberNull: number,
|
numberEmptyString: number,
|
||||||
numberUndefined: number,
|
numberNull: number,
|
||||||
numberString: number,
|
numberUndefined: number,
|
||||||
numberNumber: number,
|
numberString: number,
|
||||||
datetimeEmptyString: datetime,
|
numberNumber: number,
|
||||||
datetimeNull: datetime,
|
datetimeEmptyString: datetime,
|
||||||
datetimeUndefined: datetime,
|
datetimeNull: datetime,
|
||||||
datetimeString: datetime,
|
datetimeUndefined: datetime,
|
||||||
datetimeDate: datetime,
|
datetimeString: datetime,
|
||||||
boolNull: bool,
|
datetimeDate: datetime,
|
||||||
boolEmpty: bool,
|
boolNull: bool,
|
||||||
boolUndefined: bool,
|
boolEmpty: bool,
|
||||||
boolString: bool,
|
boolUndefined: bool,
|
||||||
boolBool: bool,
|
boolString: bool,
|
||||||
attachmentNull: attachment,
|
boolBool: bool,
|
||||||
attachmentUndefined: attachment,
|
attachmentNull: attachment,
|
||||||
attachmentEmpty: attachment,
|
attachmentUndefined: attachment,
|
||||||
attachmentEmptyArrayStr: attachment,
|
attachmentEmpty: attachment,
|
||||||
arrayFieldEmptyArrayStr: arrayField,
|
attachmentEmptyArrayStr: attachment,
|
||||||
arrayFieldArrayStrKnown: arrayField,
|
arrayFieldEmptyArrayStr: arrayField,
|
||||||
arrayFieldNull: arrayField,
|
arrayFieldArrayStrKnown: arrayField,
|
||||||
arrayFieldUndefined: arrayField,
|
arrayFieldNull: arrayField,
|
||||||
optsFieldEmptyStr: optsField,
|
arrayFieldUndefined: arrayField,
|
||||||
optsFieldUndefined: optsField,
|
optsFieldEmptyStr: optsField,
|
||||||
optsFieldNull: optsField,
|
optsFieldUndefined: optsField,
|
||||||
optsFieldStrKnown: optsField,
|
optsFieldNull: optsField,
|
||||||
},
|
optsFieldStrKnown: optsField,
|
||||||
})
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
const row = {
|
const datetimeStr = "1984-04-20T00:00:00.000Z"
|
||||||
|
|
||||||
|
const row = await config.api.row.save(table._id!, {
|
||||||
name: "Test Row",
|
name: "Test Row",
|
||||||
stringUndefined: undefined,
|
stringUndefined: undefined,
|
||||||
stringNull: null,
|
stringNull: null,
|
||||||
|
@ -359,8 +349,8 @@ describe.each([
|
||||||
datetimeEmptyString: "",
|
datetimeEmptyString: "",
|
||||||
datetimeNull: null,
|
datetimeNull: null,
|
||||||
datetimeUndefined: undefined,
|
datetimeUndefined: undefined,
|
||||||
datetimeString: "1984-04-20T00:00:00.000Z",
|
datetimeString: datetimeStr,
|
||||||
datetimeDate: new Date("1984-04-20"),
|
datetimeDate: new Date(datetimeStr),
|
||||||
boolNull: null,
|
boolNull: null,
|
||||||
boolEmpty: "",
|
boolEmpty: "",
|
||||||
boolUndefined: undefined,
|
boolUndefined: undefined,
|
||||||
|
@ -379,69 +369,58 @@ describe.each([
|
||||||
optsFieldUndefined: undefined,
|
optsFieldUndefined: undefined,
|
||||||
optsFieldNull: null,
|
optsFieldNull: null,
|
||||||
optsFieldStrKnown: "Alpha",
|
optsFieldStrKnown: "Alpha",
|
||||||
}
|
})
|
||||||
|
|
||||||
const createdRow = await config.createRow(row)
|
expect(row.stringUndefined).toBe(undefined)
|
||||||
const id = createdRow._id!
|
expect(row.stringNull).toBe(null)
|
||||||
|
expect(row.stringString).toBe("i am a string")
|
||||||
const saved = await config.api.row.get(table._id!, id)
|
expect(row.numberEmptyString).toBe(null)
|
||||||
|
expect(row.numberNull).toBe(null)
|
||||||
expect(saved.stringUndefined).toBe(undefined)
|
expect(row.numberUndefined).toBe(undefined)
|
||||||
expect(saved.stringNull).toBe(null)
|
expect(row.numberString).toBe(123)
|
||||||
expect(saved.stringString).toBe("i am a string")
|
expect(row.numberNumber).toBe(123)
|
||||||
expect(saved.numberEmptyString).toBe(null)
|
expect(row.datetimeEmptyString).toBe(null)
|
||||||
expect(saved.numberNull).toBe(null)
|
expect(row.datetimeNull).toBe(null)
|
||||||
expect(saved.numberUndefined).toBe(undefined)
|
expect(row.datetimeUndefined).toBe(undefined)
|
||||||
expect(saved.numberString).toBe(123)
|
expect(row.datetimeString).toBe(new Date(datetimeStr).toISOString())
|
||||||
expect(saved.numberNumber).toBe(123)
|
expect(row.datetimeDate).toBe(new Date(datetimeStr).toISOString())
|
||||||
expect(saved.datetimeEmptyString).toBe(null)
|
expect(row.boolNull).toBe(null)
|
||||||
expect(saved.datetimeNull).toBe(null)
|
expect(row.boolEmpty).toBe(null)
|
||||||
expect(saved.datetimeUndefined).toBe(undefined)
|
expect(row.boolUndefined).toBe(undefined)
|
||||||
expect(saved.datetimeString).toBe(
|
expect(row.boolString).toBe(true)
|
||||||
new Date(row.datetimeString).toISOString()
|
expect(row.boolBool).toBe(true)
|
||||||
)
|
expect(row.attachmentNull).toEqual([])
|
||||||
expect(saved.datetimeDate).toBe(row.datetimeDate.toISOString())
|
expect(row.attachmentUndefined).toBe(undefined)
|
||||||
expect(saved.boolNull).toBe(null)
|
expect(row.attachmentEmpty).toEqual([])
|
||||||
expect(saved.boolEmpty).toBe(null)
|
expect(row.attachmentEmptyArrayStr).toEqual([])
|
||||||
expect(saved.boolUndefined).toBe(undefined)
|
expect(row.arrayFieldEmptyArrayStr).toEqual([])
|
||||||
expect(saved.boolString).toBe(true)
|
expect(row.arrayFieldNull).toEqual([])
|
||||||
expect(saved.boolBool).toBe(true)
|
expect(row.arrayFieldUndefined).toEqual(undefined)
|
||||||
expect(saved.attachmentNull).toEqual([])
|
expect(row.optsFieldEmptyStr).toEqual(null)
|
||||||
expect(saved.attachmentUndefined).toBe(undefined)
|
expect(row.optsFieldUndefined).toEqual(undefined)
|
||||||
expect(saved.attachmentEmpty).toEqual([])
|
expect(row.optsFieldNull).toEqual(null)
|
||||||
expect(saved.attachmentEmptyArrayStr).toEqual([])
|
expect(row.arrayFieldArrayStrKnown).toEqual(["One"])
|
||||||
expect(saved.arrayFieldEmptyArrayStr).toEqual([])
|
expect(row.optsFieldStrKnown).toEqual("Alpha")
|
||||||
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")
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("view save", () => {
|
describe("view save", () => {
|
||||||
it("views have extra data trimmed", async () => {
|
it("views have extra data trimmed", async () => {
|
||||||
const table = await createTable({
|
const table = await config.api.table.save(
|
||||||
type: "table",
|
saveTableRequest({
|
||||||
name: "orders",
|
name: "orders",
|
||||||
primary: ["OrderID"],
|
schema: {
|
||||||
schema: {
|
Country: {
|
||||||
Country: {
|
type: FieldType.STRING,
|
||||||
type: FieldType.STRING,
|
name: "Country",
|
||||||
name: "Country",
|
},
|
||||||
|
Story: {
|
||||||
|
type: FieldType.STRING,
|
||||||
|
name: "Story",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
OrderID: {
|
})
|
||||||
type: FieldType.NUMBER,
|
)
|
||||||
name: "OrderID",
|
|
||||||
},
|
|
||||||
Story: {
|
|
||||||
type: FieldType.STRING,
|
|
||||||
name: "Story",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const createViewResponse = await config.api.viewV2.create({
|
const createViewResponse = await config.api.viewV2.create({
|
||||||
tableId: table._id!,
|
tableId: table._id!,
|
||||||
|
@ -450,9 +429,6 @@ describe.each([
|
||||||
Country: {
|
Country: {
|
||||||
visible: true,
|
visible: true,
|
||||||
},
|
},
|
||||||
OrderID: {
|
|
||||||
visible: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -468,8 +444,8 @@ describe.each([
|
||||||
expect(row.Story).toBeUndefined()
|
expect(row.Story).toBeUndefined()
|
||||||
expect(row).toEqual({
|
expect(row).toEqual({
|
||||||
...defaultRowFields,
|
...defaultRowFields,
|
||||||
OrderID: createRowResponse.OrderID,
|
|
||||||
Country: "Aussy",
|
Country: "Aussy",
|
||||||
|
id: createRowResponse.id,
|
||||||
_id: createRowResponse._id,
|
_id: createRowResponse._id,
|
||||||
_rev: createRowResponse._rev,
|
_rev: createRowResponse._rev,
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
|
@ -857,7 +833,7 @@ describe.each([
|
||||||
|
|
||||||
it("should allow enriching attachment rows", async () => {
|
it("should allow enriching attachment rows", async () => {
|
||||||
const table = await config.createAttachmentTable()
|
const table = await config.createAttachmentTable()
|
||||||
const attachmentId = `${structures.uuid()}.csv`
|
const attachmentId = `${uuid.v4()}.csv`
|
||||||
const row = await config.createRow({
|
const row = await config.createRow({
|
||||||
name: "test",
|
name: "test",
|
||||||
description: "test",
|
description: "test",
|
||||||
|
@ -1998,22 +1974,23 @@ describe.each([
|
||||||
`
|
`
|
||||||
).toString("base64")
|
).toString("base64")
|
||||||
|
|
||||||
const table = await config.createTable({
|
const table = await config.api.table.save(
|
||||||
name: "table",
|
saveTableRequest({
|
||||||
type: "table",
|
name: "table",
|
||||||
schema: {
|
schema: {
|
||||||
text: {
|
text: {
|
||||||
name: "text",
|
name: "text",
|
||||||
type: FieldType.STRING,
|
type: FieldType.STRING,
|
||||||
|
},
|
||||||
|
formula: {
|
||||||
|
name: "formula",
|
||||||
|
type: FieldType.FORMULA,
|
||||||
|
formula: `{{ js "${js}"}}`,
|
||||||
|
formulaType: FormulaType.DYNAMIC,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
formula: {
|
})
|
||||||
name: "formula",
|
)
|
||||||
type: FieldType.FORMULA,
|
|
||||||
formula: `{{ js "${js}"}}`,
|
|
||||||
formulaType: FormulaType.DYNAMIC,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
await config.api.row.save(table._id!, { text: "foo" })
|
await config.api.row.save(table._id!, { text: "foo" })
|
||||||
|
@ -2051,22 +2028,22 @@ describe.each([
|
||||||
|
|
||||||
it("should not carry over context between formulas", async () => {
|
it("should not carry over context between formulas", async () => {
|
||||||
const js = Buffer.from(`return $("[text]");`).toString("base64")
|
const js = Buffer.from(`return $("[text]");`).toString("base64")
|
||||||
const table = await config.createTable({
|
const table = await config.api.table.save(
|
||||||
name: "table",
|
saveTableRequest({
|
||||||
type: "table",
|
schema: {
|
||||||
schema: {
|
text: {
|
||||||
text: {
|
name: "text",
|
||||||
name: "text",
|
type: FieldType.STRING,
|
||||||
type: FieldType.STRING,
|
},
|
||||||
|
formula: {
|
||||||
|
name: "formula",
|
||||||
|
type: FieldType.FORMULA,
|
||||||
|
formula: `{{ js "${js}"}}`,
|
||||||
|
formulaType: FormulaType.DYNAMIC,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
formula: {
|
})
|
||||||
name: "formula",
|
)
|
||||||
type: FieldType.FORMULA,
|
|
||||||
formula: `{{ js "${js}"}}`,
|
|
||||||
formulaType: FormulaType.DYNAMIC,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
await config.api.row.save(table._id!, { text: `foo${i}` })
|
await config.api.row.save(table._id!, { text: `foo${i}` })
|
||||||
|
|
Loading…
Reference in New Issue