Skip to content

Commit ec13c2e

Browse files
committed
fix: correctly use new validator in date specs
1 parent 3e7b454 commit ec13c2e

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jsonresume/schema",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "JSON Resume Schema",
55
"private": false,
66
"main": "validator.js",

test/dates.spec.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,56 @@
1-
var test = require('tape');
2-
var ZSchema = require('z-schema');
3-
const fixtures = require('./__test__/dates.json');
1+
var test = require("tape");
2+
var Validator = require("jsonschema").Validator;
3+
4+
const fixtures = require("./__test__/dates.json");
45
// var mockDateSchema = require('./__test__/mockDateSchema.json');
56

67
const mockDateSchema = {
7-
"type": "string",
8-
"description": "Mock Date Format",
9-
"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})$"
8+
type: "string",
9+
description: "Mock Date Format",
10+
pattern:
11+
"^([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})$",
1012
};
1113

1214
function dateValidate(resumeJson, callback) {
13-
var callbackWrapper = function(err, valid) {
14-
if(err) {
15-
callback(err)
16-
} else {
17-
callback(null, {valid: valid});
18-
}
15+
var v = new Validator();
16+
17+
const validation = v.validate(resumeJson, mockDateSchema);
18+
19+
if (!validation.valid) {
20+
return callback(validation.errors, false);
1921
}
2022

21-
new ZSchema().validate(resumeJson, mockDateSchema, callbackWrapper);
23+
return callback(null, true);
2224
}
2325

24-
test('dates - YYYY-MM-DD', (t) => {
26+
test("dates - YYYY-MM-DD", (t) => {
2527
dateValidate(fixtures.yearMonthDay, (err, valid) => {
26-
t.equal(err, null, 'err should be null');
27-
t.true(valid, 'valid is true');
28+
t.equal(err, null, "err should be null");
29+
t.true(valid, "valid is true");
2830
});
2931
t.end();
3032
});
3133

32-
test('dates - YYYY-MM', (t) => {
34+
test("dates - YYYY-MM", (t) => {
3335
dateValidate(fixtures.yearMonth, (err, valid) => {
34-
t.equal(err, null, 'err should be null');
35-
t.true(valid, 'valid is true');
36+
t.equal(err, null, "err should be null");
37+
t.true(valid, "valid is true");
3638
});
3739
t.end();
3840
});
3941

40-
test('dates - YYYY', (t) => {
42+
test("dates - YYYY", (t) => {
4143
dateValidate(fixtures.yearMonthDay, (err, valid) => {
42-
t.equal(err, null, 'err should be null');
43-
t.true(valid, 'valid is true');
44+
t.equal(err, null, "err should be null");
45+
t.true(valid, "valid is true");
4446
});
4547
t.end();
4648
});
4749

48-
test('dates - invalid', (t) => {
50+
test("dates - invalid", (t) => {
4951
dateValidate(fixtures.invalid, (err, valid) => {
50-
t.notEqual(err, null, 'err should contain an error');
51-
t.false(valid, 'valid is false');
52+
t.notEqual(err, null, "err should contain an error");
53+
t.false(valid, "valid is false");
5254
});
5355
t.end();
5456
});

0 commit comments

Comments
 (0)