-
-
Notifications
You must be signed in to change notification settings - Fork 886
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add timestamp option for jtd * tests for JTD timestamp option * configurable timestamp check * address feedback * doc Co-authored-by: Evgeny Poberezkin <[email protected]>
- Loading branch information
1 parent
a60eff7
commit df964e4
Showing
5 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import _AjvJTD from "./ajv_jtd" | ||
import assert = require("assert") | ||
|
||
describe("JTD Timestamps", () => { | ||
it("Should accept dates or strings by default", () => { | ||
const ajv = new _AjvJTD() | ||
const schema = { | ||
type: "timestamp", | ||
} | ||
assert.strictEqual(ajv.validate(schema, new Date()), true) | ||
assert.strictEqual(ajv.validate(schema, "2021-05-03T05:24:43.906Z"), true) | ||
assert.strictEqual(ajv.validate(schema, "foo"), false) | ||
}) | ||
|
||
it("Should enforce timestamp=string", () => { | ||
const ajv = new _AjvJTD({timestamp: "string"}) | ||
const schema = { | ||
type: "timestamp", | ||
} | ||
assert.strictEqual(ajv.validate(schema, new Date()), false) | ||
assert.strictEqual(ajv.validate(schema, "2021-05-03T05:24:43.906Z"), true) | ||
assert.strictEqual(ajv.validate(schema, "foo"), false) | ||
}) | ||
|
||
it("Should enforce timestamp=date", () => { | ||
const ajv = new _AjvJTD({timestamp: "date"}) | ||
const schema = { | ||
type: "timestamp", | ||
} | ||
assert.strictEqual(ajv.validate(schema, new Date()), true) | ||
assert.strictEqual(ajv.validate(schema, "2021-05-03T05:24:43.906Z"), false) | ||
assert.strictEqual(ajv.validate(schema, "foo"), false) | ||
}) | ||
}) |