Skip to content

Commit

Permalink
fix: correctly use new validator in date specs
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdavis committed Jul 10, 2024
1 parent 3e7b454 commit ec13c2e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsonresume/schema",
"version": "1.1.1",
"version": "1.1.2",
"description": "JSON Resume Schema",
"private": false,
"main": "validator.js",
Expand Down
52 changes: 27 additions & 25 deletions test/dates.spec.js
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();
});

0 comments on commit ec13c2e

Please sign in to comment.