Skip to content

Commit

Permalink
Added test for "Allow to define a type for schema validators"
Browse files Browse the repository at this point in the history
  • Loading branch information
Tino Butz committed Nov 8, 2013
1 parent 94f9996 commit c5b1ffb
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/schema.validation.test.js
Expand Up @@ -459,5 +459,46 @@ describe('schema', function(){
})
})
})

describe('types', function(){
describe('are customizable', function(){
it('for single custom validators', function(done){
function validate () {
return false;
}
var validator = [validate, '{PATH} failed validation ({VALUE})', 'customType'];

var schema = new Schema({ x: { type: [], validate: validator }});
var M = mongoose.model('custom-validator-'+random(), schema);

var m = new M({ x: [3,4,5,6] });

m.validate(function (err) {
assert.equal('x failed validation (3,4,5,6)', String(err.errors.x));
assert.equal('customType', err.errors.x.type);
done();
})
})

it('for many custom validators', function(done){
function validate () {
return false;
}
var validator = [
{ validator: validate, msg: '{PATH} failed validation ({VALUE})', 'customType'}
]
var schema = new Schema({ x: { type: [], validate: validator }});
var M = mongoose.model('custom-validator-'+random(), schema);

var m = new M({ x: [3,4,5,6] });

m.validate(function (err) {
assert.equal('x failed validation (3,4,5,6)', String(err.errors.x));
assert.equal('customType', err.errors.x.type);
done();
})
})
})
})
});
});

0 comments on commit c5b1ffb

Please sign in to comment.