Extra tests
This commit is contained in:
parent
bed18615b5
commit
fb06254964
|
@ -6,6 +6,7 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { generateTableID } from "../../../../db/utils"
|
import { generateTableID } from "../../../../db/utils"
|
||||||
import { validate } from "../utils"
|
import { validate } from "../utils"
|
||||||
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
|
|
||||||
describe("validate", () => {
|
describe("validate", () => {
|
||||||
describe("time only", () => {
|
describe("time only", () => {
|
||||||
|
@ -24,7 +25,7 @@ describe("validate", () => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should accept empty fields", async () => {
|
it("should accept empty values", async () => {
|
||||||
const row = {}
|
const row = {}
|
||||||
const table = getTable()
|
const table = getTable()
|
||||||
const output = await validate({ table, tableId: table._id!, row })
|
const output = await validate({ table, tableId: table._id!, row })
|
||||||
|
@ -32,8 +33,26 @@ describe("validate", () => {
|
||||||
expect(output.errors).toEqual({})
|
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", () => {
|
describe("required", () => {
|
||||||
it("should reject empty fields", async () => {
|
it("should reject empty values", async () => {
|
||||||
const row = {}
|
const row = {}
|
||||||
const table = getTable()
|
const table = getTable()
|
||||||
table.schema.time.constraints = {
|
table.schema.time.constraints = {
|
||||||
|
@ -43,6 +62,17 @@ describe("validate", () => {
|
||||||
expect(output.valid).toBe(false)
|
expect(output.valid).toBe(false)
|
||||||
expect(output.errors).toEqual({ time: ["can't be blank"] })
|
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"] })
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue