Skip to content

Commit

Permalink
All tests passed (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
zerberio committed Jun 16, 2015
1 parent a42d47e commit d4e4600
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ exports.validate = function(raw, schema) {

// If schema passed as id — get registry schema by id and validate against it
registry.get().then(function(R) {
var profile = _.findWhere({id: schemaID}, R);
var profile = _.findWhere(R, {id: schemaID});

if(!profile) {
RJ('No profile found with id ' + schemaID);
Expand Down Expand Up @@ -101,7 +101,7 @@ exports.validateUrl = function(dpurl, callback) {
}]
});
} else {
callback(exports.validate(body));
exports.validate(body).then(function(O) { callback(O) });
}
});
}
Expand Down
13 changes: 9 additions & 4 deletions test/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,29 @@ describe('validate JSON', function() {
});

describe('validate schema', function() {
it('invalid for schema', function() {
tools.validate('["xyz"]', {valid: 'schema'}).then(function(O) {
it('invalid for schema', function(done) {
this.timeout(10000);
tools.validate('["xyz"]').then(function(O) {
// console.log(JSON.stringify(out, null, 2));
assert.equal(O.valid, false);
assert.equal(O.errors.length, 1);
assert.equal(O.errors[0].message, 'invalid type: array (expected object)')
assert.equal(O.errors[0].message.toLowerCase(), 'invalid type: array (expected object)')
done();
});
});
it('good datapackage.json', function() {
it('good datapackage.json', function(done) {
var data = {
"name": "abc",
"resources": [{
"path": "data/data.csv"
}]
};
this.timeout(10000);
tools.validate(data).then(function(O) {
// console.log(JSON.stringify(out, null, 2));
assert.equal(O.valid, true);
assert.equal(O.errors.length, 0);
done();
});
});
});
Expand All @@ -51,6 +55,7 @@ describe('validate remote data package', function() {
var sourceUrl = 'https://raw.github.com/datasets/gold-prices/master/datapackage.json';

it('remote datapackage.json ok', function(done) {
this.timeout(10000);
tools.validateUrl(sourceUrl, function(out) {
assert.equal(out.valid, true);
done();
Expand Down

0 comments on commit d4e4600

Please sign in to comment.