Skip to content

Instantly share code, notes, and snippets.

@simon-p-r
Created April 21, 2015 21:19
Show Gist options
  • Save simon-p-r/4b65d6164d9007609bdf to your computer and use it in GitHub Desktop.
Save simon-p-r/4b65d6164d9007609bdf to your computer and use it in GitHub Desktop.
Test problem
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();
});
});
@simon-p-r
Copy link
Author

  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