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

Extra tests

This commit is contained in:
Adria Navarro 2024-05-23 14:00:15 +02:00
parent bed18615b5
commit fb06254964

View file

@ -6,6 +6,7 @@ import {
} from "@budibase/types"
import { generateTableID } from "../../../../db/utils"
import { validate } from "../utils"
import { generator } from "@budibase/backend-core/tests"
describe("validate", () => {
describe("time only", () => {
@ -24,7 +25,7 @@ describe("validate", () => {
},
})
it("should accept empty fields", async () => {
it("should accept empty values", async () => {
const row = {}
const table = getTable()
const output = await validate({ table, tableId: table._id!, row })
@ -32,8 +33,26 @@ describe("validate", () => {
expect(output.errors).toEqual({})
})
it("should accept valid times with HH:mm format", async () => {
const row = {
time: `${generator.hour()}:${generator.minute()}`,
}
const table = getTable()
const output = await validate({ table, tableId: table._id!, row })
expect(output.valid).toBe(true)
})
it("should accept valid times with HH:mm:ss format", async () => {
const row = {
time: `${generator.hour()}:${generator.minute()}:${generator.second()}`,
}
const table = getTable()
const output = await validate({ table, tableId: table._id!, row })
expect(output.valid).toBe(true)
})
describe("required", () => {
it("should reject empty fields", async () => {
it("should reject empty values", async () => {
const row = {}
const table = getTable()
table.schema.time.constraints = {
@ -43,6 +62,17 @@ describe("validate", () => {
expect(output.valid).toBe(false)
expect(output.errors).toEqual({ time: ["can't be blank"] })
})
it.each([undefined, null])("should reject %s values", async time => {
const row = { time }
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"] })
})
})
})
})