diff --git a/test/validations.test.js b/test/validations.test.js index f9bf41e4..d2494fcc 100644 --- a/test/validations.test.js +++ b/test/validations.test.js @@ -610,7 +610,55 @@ describe('validations', function() { }); describe('inclusion', function() { - it('should validate inclusion'); + it('fails when included value is not used for property', function(done) { + User.validatesInclusionOf('name', {in: ['bob', 'john']}); + User.create({name: 'bobby'}, function(err) { + err.should.be.instanceof(Error); + err.details.messages.should.match({name: /is not included in the list/}); + done(); + }); + }); + + it('passes when included value is used for property', function(done) { + User.validatesInclusionOf('name', {in: ['bob', 'john']}); + User.create({name: 'bob'}, function(err, user) { + if (err) return done(err); + user.name.should.eql('bob'); + done(); + }); + }); + + it('fails with a custom error message', function(done) { + User.validatesInclusionOf('name', {in: ['bob', 'john'], message: 'not used'}); + User.create({name: 'dude'}, function(err) { + err.should.be.instanceof(Error); + err.details.messages.should.match({name: /not used/}); + done(); + }); + }); + + it('fails with a null value when allowNull is false', function(done) { + User.validatesInclusionOf('name', {in: ['bob'], allowNull: false}); + User.create({name: null}, function(err) { + err.should.be.instanceof(Error); + err.details.messages.should.match({name: /is null/}); + done(); + }); + }); + + it('passes with a null value when allowNull is true', function(done) { + User.validatesInclusionOf('name', {in: ['bob'], allowNull: true}); + User.create({name: null}, done); + }); + + it('fails if value is used for integer property', function(done) { + User.validatesInclusionOf('age', {in: [123, 456]}); + User.create({age: 789}, function(err) { + err.should.be.instanceof(Error); + err.details.messages.should.match({age: /is not included in the list/}); + done(); + }); + }); }); describe('exclusion', function() {