Run coerced only for internal
This commit is contained in:
parent
8ee23e6168
commit
66524d998b
|
@ -304,167 +304,168 @@ describe.each([
|
||||||
await assertQueryUsage(queryUsage) // no change
|
await assertQueryUsage(queryUsage) // no change
|
||||||
})
|
})
|
||||||
|
|
||||||
it("row values are coerced", async () => {
|
isInternal &&
|
||||||
const str = {
|
it("row values are coerced", async () => {
|
||||||
type: FieldType.STRING,
|
const str = {
|
||||||
name: "str",
|
type: FieldType.STRING,
|
||||||
constraints: { type: "string", presence: false },
|
name: "str",
|
||||||
}
|
constraints: { type: "string", presence: false },
|
||||||
const attachment = {
|
}
|
||||||
type: FieldType.ATTACHMENT,
|
const attachment = {
|
||||||
name: "attachment",
|
type: FieldType.ATTACHMENT,
|
||||||
constraints: { type: "array", presence: false },
|
name: "attachment",
|
||||||
}
|
constraints: { type: "array", presence: false },
|
||||||
const bool = {
|
}
|
||||||
type: FieldType.BOOLEAN,
|
const bool = {
|
||||||
name: "boolean",
|
type: FieldType.BOOLEAN,
|
||||||
constraints: { type: "boolean", presence: false },
|
name: "boolean",
|
||||||
}
|
constraints: { type: "boolean", presence: false },
|
||||||
const number = {
|
}
|
||||||
type: FieldType.NUMBER,
|
const number = {
|
||||||
name: "str",
|
type: FieldType.NUMBER,
|
||||||
constraints: { type: "number", presence: false },
|
name: "str",
|
||||||
}
|
constraints: { type: "number", presence: false },
|
||||||
const datetime = {
|
}
|
||||||
type: FieldType.DATETIME,
|
const datetime = {
|
||||||
name: "datetime",
|
type: FieldType.DATETIME,
|
||||||
constraints: {
|
name: "datetime",
|
||||||
type: "string",
|
|
||||||
presence: false,
|
|
||||||
datetime: { earliest: "", latest: "" },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
const arrayField = {
|
|
||||||
type: FieldType.ARRAY,
|
|
||||||
constraints: {
|
|
||||||
type: "array",
|
|
||||||
presence: false,
|
|
||||||
inclusion: ["One", "Two", "Three"],
|
|
||||||
},
|
|
||||||
name: "Sample Tags",
|
|
||||||
sortable: false,
|
|
||||||
}
|
|
||||||
const optsField = {
|
|
||||||
fieldName: "Sample Opts",
|
|
||||||
name: "Sample Opts",
|
|
||||||
type: FieldType.OPTIONS,
|
|
||||||
constraints: {
|
constraints: {
|
||||||
type: "string",
|
type: "string",
|
||||||
presence: false,
|
presence: false,
|
||||||
inclusion: ["Alpha", "Beta", "Gamma"],
|
datetime: { earliest: "", latest: "" },
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
table = await config.createTable({
|
const arrayField = {
|
||||||
name: "TestTable2",
|
type: FieldType.ARRAY,
|
||||||
type: "table",
|
constraints: {
|
||||||
schema: {
|
type: "array",
|
||||||
name: str,
|
presence: false,
|
||||||
stringUndefined: str,
|
inclusion: ["One", "Two", "Three"],
|
||||||
stringNull: str,
|
|
||||||
stringString: str,
|
|
||||||
numberEmptyString: number,
|
|
||||||
numberNull: number,
|
|
||||||
numberUndefined: number,
|
|
||||||
numberString: number,
|
|
||||||
numberNumber: number,
|
|
||||||
datetimeEmptyString: datetime,
|
|
||||||
datetimeNull: datetime,
|
|
||||||
datetimeUndefined: datetime,
|
|
||||||
datetimeString: datetime,
|
|
||||||
datetimeDate: datetime,
|
|
||||||
boolNull: bool,
|
|
||||||
boolEmpty: bool,
|
|
||||||
boolUndefined: bool,
|
|
||||||
boolString: bool,
|
|
||||||
boolBool: bool,
|
|
||||||
attachmentNull: attachment,
|
|
||||||
attachmentUndefined: attachment,
|
|
||||||
attachmentEmpty: attachment,
|
|
||||||
attachmentEmptyArrayStr: attachment,
|
|
||||||
arrayFieldEmptyArrayStr: arrayField,
|
|
||||||
arrayFieldArrayStrKnown: arrayField,
|
|
||||||
arrayFieldNull: arrayField,
|
|
||||||
arrayFieldUndefined: arrayField,
|
|
||||||
optsFieldEmptyStr: optsField,
|
|
||||||
optsFieldUndefined: optsField,
|
|
||||||
optsFieldNull: optsField,
|
|
||||||
optsFieldStrKnown: optsField,
|
|
||||||
},
|
},
|
||||||
})
|
name: "Sample Tags",
|
||||||
|
sortable: false,
|
||||||
|
}
|
||||||
|
const optsField = {
|
||||||
|
fieldName: "Sample Opts",
|
||||||
|
name: "Sample Opts",
|
||||||
|
type: FieldType.OPTIONS,
|
||||||
|
constraints: {
|
||||||
|
type: "string",
|
||||||
|
presence: false,
|
||||||
|
inclusion: ["Alpha", "Beta", "Gamma"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
table = await config.createTable({
|
||||||
|
name: "TestTable2",
|
||||||
|
type: "table",
|
||||||
|
schema: {
|
||||||
|
name: str,
|
||||||
|
stringUndefined: str,
|
||||||
|
stringNull: str,
|
||||||
|
stringString: str,
|
||||||
|
numberEmptyString: number,
|
||||||
|
numberNull: number,
|
||||||
|
numberUndefined: number,
|
||||||
|
numberString: number,
|
||||||
|
numberNumber: number,
|
||||||
|
datetimeEmptyString: datetime,
|
||||||
|
datetimeNull: datetime,
|
||||||
|
datetimeUndefined: datetime,
|
||||||
|
datetimeString: datetime,
|
||||||
|
datetimeDate: datetime,
|
||||||
|
boolNull: bool,
|
||||||
|
boolEmpty: bool,
|
||||||
|
boolUndefined: bool,
|
||||||
|
boolString: bool,
|
||||||
|
boolBool: bool,
|
||||||
|
attachmentNull: attachment,
|
||||||
|
attachmentUndefined: attachment,
|
||||||
|
attachmentEmpty: attachment,
|
||||||
|
attachmentEmptyArrayStr: attachment,
|
||||||
|
arrayFieldEmptyArrayStr: arrayField,
|
||||||
|
arrayFieldArrayStrKnown: arrayField,
|
||||||
|
arrayFieldNull: arrayField,
|
||||||
|
arrayFieldUndefined: arrayField,
|
||||||
|
optsFieldEmptyStr: optsField,
|
||||||
|
optsFieldUndefined: optsField,
|
||||||
|
optsFieldNull: optsField,
|
||||||
|
optsFieldStrKnown: optsField,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
row = {
|
row = {
|
||||||
name: "Test Row",
|
name: "Test Row",
|
||||||
stringUndefined: undefined,
|
stringUndefined: undefined,
|
||||||
stringNull: null,
|
stringNull: null,
|
||||||
stringString: "i am a string",
|
stringString: "i am a string",
|
||||||
numberEmptyString: "",
|
numberEmptyString: "",
|
||||||
numberNull: null,
|
numberNull: null,
|
||||||
numberUndefined: undefined,
|
numberUndefined: undefined,
|
||||||
numberString: "123",
|
numberString: "123",
|
||||||
numberNumber: 123,
|
numberNumber: 123,
|
||||||
datetimeEmptyString: "",
|
datetimeEmptyString: "",
|
||||||
datetimeNull: null,
|
datetimeNull: null,
|
||||||
datetimeUndefined: undefined,
|
datetimeUndefined: undefined,
|
||||||
datetimeString: "1984-04-20T00:00:00.000Z",
|
datetimeString: "1984-04-20T00:00:00.000Z",
|
||||||
datetimeDate: new Date("1984-04-20"),
|
datetimeDate: new Date("1984-04-20"),
|
||||||
boolNull: null,
|
boolNull: null,
|
||||||
boolEmpty: "",
|
boolEmpty: "",
|
||||||
boolUndefined: undefined,
|
boolUndefined: undefined,
|
||||||
boolString: "true",
|
boolString: "true",
|
||||||
boolBool: true,
|
boolBool: true,
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
attachmentNull: null,
|
attachmentNull: null,
|
||||||
attachmentUndefined: undefined,
|
attachmentUndefined: undefined,
|
||||||
attachmentEmpty: "",
|
attachmentEmpty: "",
|
||||||
attachmentEmptyArrayStr: "[]",
|
attachmentEmptyArrayStr: "[]",
|
||||||
arrayFieldEmptyArrayStr: "[]",
|
arrayFieldEmptyArrayStr: "[]",
|
||||||
arrayFieldUndefined: undefined,
|
arrayFieldUndefined: undefined,
|
||||||
arrayFieldNull: null,
|
arrayFieldNull: null,
|
||||||
arrayFieldArrayStrKnown: "['One']",
|
arrayFieldArrayStrKnown: "['One']",
|
||||||
optsFieldEmptyStr: "",
|
optsFieldEmptyStr: "",
|
||||||
optsFieldUndefined: undefined,
|
optsFieldUndefined: undefined,
|
||||||
optsFieldNull: null,
|
optsFieldNull: null,
|
||||||
optsFieldStrKnown: "Alpha",
|
optsFieldStrKnown: "Alpha",
|
||||||
}
|
}
|
||||||
|
|
||||||
const createdRow = await config.createRow(row)
|
const createdRow = await config.createRow(row)
|
||||||
const id = createdRow._id!
|
const id = createdRow._id!
|
||||||
|
|
||||||
const saved = (await loadRow(id, table._id!)).body
|
const saved = (await loadRow(id, table._id!)).body
|
||||||
|
|
||||||
expect(saved.stringUndefined).toBe(undefined)
|
expect(saved.stringUndefined).toBe(undefined)
|
||||||
expect(saved.stringNull).toBe("")
|
expect(saved.stringNull).toBe("")
|
||||||
expect(saved.stringString).toBe("i am a string")
|
expect(saved.stringString).toBe("i am a string")
|
||||||
expect(saved.numberEmptyString).toBe(null)
|
expect(saved.numberEmptyString).toBe(null)
|
||||||
expect(saved.numberNull).toBe(null)
|
expect(saved.numberNull).toBe(null)
|
||||||
expect(saved.numberUndefined).toBe(undefined)
|
expect(saved.numberUndefined).toBe(undefined)
|
||||||
expect(saved.numberString).toBe(123)
|
expect(saved.numberString).toBe(123)
|
||||||
expect(saved.numberNumber).toBe(123)
|
expect(saved.numberNumber).toBe(123)
|
||||||
expect(saved.datetimeEmptyString).toBe(null)
|
expect(saved.datetimeEmptyString).toBe(null)
|
||||||
expect(saved.datetimeNull).toBe(null)
|
expect(saved.datetimeNull).toBe(null)
|
||||||
expect(saved.datetimeUndefined).toBe(undefined)
|
expect(saved.datetimeUndefined).toBe(undefined)
|
||||||
expect(saved.datetimeString).toBe(
|
expect(saved.datetimeString).toBe(
|
||||||
new Date(row.datetimeString).toISOString()
|
new Date(row.datetimeString).toISOString()
|
||||||
)
|
)
|
||||||
expect(saved.datetimeDate).toBe(row.datetimeDate.toISOString())
|
expect(saved.datetimeDate).toBe(row.datetimeDate.toISOString())
|
||||||
expect(saved.boolNull).toBe(null)
|
expect(saved.boolNull).toBe(null)
|
||||||
expect(saved.boolEmpty).toBe(null)
|
expect(saved.boolEmpty).toBe(null)
|
||||||
expect(saved.boolUndefined).toBe(undefined)
|
expect(saved.boolUndefined).toBe(undefined)
|
||||||
expect(saved.boolString).toBe(true)
|
expect(saved.boolString).toBe(true)
|
||||||
expect(saved.boolBool).toBe(true)
|
expect(saved.boolBool).toBe(true)
|
||||||
expect(saved.attachmentNull).toEqual([])
|
expect(saved.attachmentNull).toEqual([])
|
||||||
expect(saved.attachmentUndefined).toBe(undefined)
|
expect(saved.attachmentUndefined).toBe(undefined)
|
||||||
expect(saved.attachmentEmpty).toEqual([])
|
expect(saved.attachmentEmpty).toEqual([])
|
||||||
expect(saved.attachmentEmptyArrayStr).toEqual([])
|
expect(saved.attachmentEmptyArrayStr).toEqual([])
|
||||||
expect(saved.arrayFieldEmptyArrayStr).toEqual([])
|
expect(saved.arrayFieldEmptyArrayStr).toEqual([])
|
||||||
expect(saved.arrayFieldNull).toEqual([])
|
expect(saved.arrayFieldNull).toEqual([])
|
||||||
expect(saved.arrayFieldUndefined).toEqual(undefined)
|
expect(saved.arrayFieldUndefined).toEqual(undefined)
|
||||||
expect(saved.optsFieldEmptyStr).toEqual(null)
|
expect(saved.optsFieldEmptyStr).toEqual(null)
|
||||||
expect(saved.optsFieldUndefined).toEqual(undefined)
|
expect(saved.optsFieldUndefined).toEqual(undefined)
|
||||||
expect(saved.optsFieldNull).toEqual(null)
|
expect(saved.optsFieldNull).toEqual(null)
|
||||||
expect(saved.arrayFieldArrayStrKnown).toEqual(["One"])
|
expect(saved.arrayFieldArrayStrKnown).toEqual(["One"])
|
||||||
expect(saved.optsFieldStrKnown).toEqual("Alpha")
|
expect(saved.optsFieldStrKnown).toEqual("Alpha")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("view save", () => {
|
describe("view save", () => {
|
||||||
|
|
Loading…
Reference in New Issue