-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly use new validator in date specs
- Loading branch information
1 parent
3e7b454
commit ec13c2e
Showing
3 changed files
with
30 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,54 +1,56 @@ | ||
var test = require('tape'); | ||
var ZSchema = require('z-schema'); | ||
const fixtures = require('./__test__/dates.json'); | ||
var test = require("tape"); | ||
var Validator = require("jsonschema").Validator; | ||
|
||
const fixtures = require("./__test__/dates.json"); | ||
// var mockDateSchema = require('./__test__/mockDateSchema.json'); | ||
|
||
const mockDateSchema = { | ||
"type": "string", | ||
"description": "Mock Date Format", | ||
"pattern": "^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$" | ||
type: "string", | ||
description: "Mock Date Format", | ||
pattern: | ||
"^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$", | ||
}; | ||
|
||
function dateValidate(resumeJson, callback) { | ||
var callbackWrapper = function(err, valid) { | ||
if(err) { | ||
callback(err) | ||
} else { | ||
callback(null, {valid: valid}); | ||
} | ||
var v = new Validator(); | ||
|
||
const validation = v.validate(resumeJson, mockDateSchema); | ||
|
||
if (!validation.valid) { | ||
return callback(validation.errors, false); | ||
} | ||
|
||
new ZSchema().validate(resumeJson, mockDateSchema, callbackWrapper); | ||
return callback(null, true); | ||
} | ||
|
||
test('dates - YYYY-MM-DD', (t) => { | ||
test("dates - YYYY-MM-DD", (t) => { | ||
dateValidate(fixtures.yearMonthDay, (err, valid) => { | ||
t.equal(err, null, 'err should be null'); | ||
t.true(valid, 'valid is true'); | ||
t.equal(err, null, "err should be null"); | ||
t.true(valid, "valid is true"); | ||
}); | ||
t.end(); | ||
}); | ||
|
||
test('dates - YYYY-MM', (t) => { | ||
test("dates - YYYY-MM", (t) => { | ||
dateValidate(fixtures.yearMonth, (err, valid) => { | ||
t.equal(err, null, 'err should be null'); | ||
t.true(valid, 'valid is true'); | ||
t.equal(err, null, "err should be null"); | ||
t.true(valid, "valid is true"); | ||
}); | ||
t.end(); | ||
}); | ||
|
||
test('dates - YYYY', (t) => { | ||
test("dates - YYYY", (t) => { | ||
dateValidate(fixtures.yearMonthDay, (err, valid) => { | ||
t.equal(err, null, 'err should be null'); | ||
t.true(valid, 'valid is true'); | ||
t.equal(err, null, "err should be null"); | ||
t.true(valid, "valid is true"); | ||
}); | ||
t.end(); | ||
}); | ||
|
||
test('dates - invalid', (t) => { | ||
test("dates - invalid", (t) => { | ||
dateValidate(fixtures.invalid, (err, valid) => { | ||
t.notEqual(err, null, 'err should contain an error'); | ||
t.false(valid, 'valid is false'); | ||
t.notEqual(err, null, "err should contain an error"); | ||
t.false(valid, "valid is false"); | ||
}); | ||
t.end(); | ||
}); |