1
0
Fork 0
mirror of synced 2024-08-23 05:51:29 +12:00

Add basic tests

This commit is contained in:
Adria Navarro 2024-05-23 13:57:42 +02:00
parent e169454490
commit bed18615b5

View file

@ -0,0 +1,48 @@
import {
FieldType,
INTERNAL_TABLE_SOURCE_ID,
Table,
TableSourceType,
} from "@budibase/types"
import { generateTableID } from "../../../../db/utils"
import { validate } from "../utils"
describe("validate", () => {
describe("time only", () => {
const getTable = (): Table => ({
type: "table",
_id: generateTableID(),
name: "table",
sourceId: INTERNAL_TABLE_SOURCE_ID,
sourceType: TableSourceType.INTERNAL,
schema: {
time: {
name: "time",
type: FieldType.DATETIME,
timeOnly: true,
},
},
})
it("should accept empty fields", async () => {
const row = {}
const table = getTable()
const output = await validate({ table, tableId: table._id!, row })
expect(output.valid).toBe(true)
expect(output.errors).toEqual({})
})
describe("required", () => {
it("should reject empty fields", async () => {
const row = {}
const table = getTable()
table.schema.time.constraints = {
presence: true,
}
const output = await validate({ table, tableId: table._id!, row })
expect(output.valid).toBe(false)
expect(output.errors).toEqual({ time: ["can't be blank"] })
})
})
})
})