Debian Codegraph @

ajv-formats/tests/issues/617_full_format_leap_year.spec.ts

raw symbols SCIP
1 import Ajv from "ajv"
2 import addFormats from "../../dist"
3
4 describe("PR #617, full date format validation should understand leap years", () => {
5 let ajv: Ajv
6
7 beforeAll(() => {
8 ajv = new Ajv({strictTypes: false})
9 addFormats(ajv)
10 })
11
12 test("should handle non leap year affected dates with date-time", () => {
13 const schema = {format: "date-time"}
14 const validDateTime = "2016-01-31T00:00:00Z"
15
16 expect(ajv.validate(schema, validDateTime)).toBe(true)
17 })
18
19 test("should handle non leap year affected dates with date", () => {
20 const schema = {format: "date"}
21 const validDate = "2016-11-30"
22
23 expect(ajv.validate(schema, validDate)).toBe(true)
24 })
25
26 test("should handle year leaps as date-time", () => {
27 const schema = {format: "date-time"}
28 const validDateTime = "2016-02-29T00:00:00Z"
29 const invalidDateTime = "2017-02-29T00:00:00Z"
30
31 expect(ajv.validate(schema, validDateTime)).toBe(true)
32 expect(ajv.validate(schema, invalidDateTime)).toBe(false)
33 })
34
35 test("should handle year leaps as date", () => {
36 const schema = {format: "date"}
37 const validDate = "2016-02-29"
38 const invalidDate = "2017-02-29"
39
40 expect(ajv.validate(schema, validDate)).toBe(true)
41 expect(ajv.validate(schema, invalidDate)).toBe(false)
42 })
43 })