Created
April 21, 2015 21:19
-
-
Save simon-p-r/4b65d6164d9007609bdf to your computer and use it in GitHub Desktop.
Test problem
This file contains hidden or 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
it('should validate data against schema async', function (done) { | |
var plus = new Plus({ | |
directory: [Path.resolve(__dirname, './schemata')] | |
}); | |
var data = new Plus({ | |
directory: [Path.resolve(__dirname, './fixtures/lookup')] | |
}); | |
var options = { | |
moduleSet: plus.moduleSet, | |
zSchema: {} | |
}; | |
var manager = new Manager(options); | |
manager.start(); | |
var schema = manager.schemaSet.records.lookup.bankCodeType; | |
var json = data.moduleSet.bankCodeType[0]; | |
manager.validateData(json, schema, function (err, valid) { | |
expect(err).to.be.null(); | |
expect(valid).to.be.true(); | |
done(); | |
}); | |
}); |
Author
simon-p-r
commented
Apr 24, 2015
internals.Manager.prototype.validateData = function (json, schema, callback) {
this.validator.validate(json, schema, function(errors, valid) {
if (!valid) {
var es = [];
errors.forEach(function (error) {
var e = '';
if (error.path.length > 0) {
e = error.message + ' - for fld[' + error.path.join('.') + ']';
} else {
e = error.message;
}
es.push(e);
});
return callback(es, null);
} else {
return callback(null, valid);
}
});
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment