Skip to content

Commit

Permalink
refactor: fix a few tests re: #5891
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Dec 24, 2017
1 parent ccec46f commit f59defb
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions test/schema.validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,66 +377,80 @@ describe('schema', function() {
likes: {type: Array, required: true}
});

var remaining = 3;

Loki.path('likes').doValidate(null, function(err) {
assert.ok(err instanceof ValidatorError);
--remaining || done();
});

Loki.path('likes').doValidate(undefined, function(err) {
assert.ok(err instanceof ValidatorError);
--remaining || done();
});

Loki.path('likes').doValidate([], function(err) {
assert.ok(err instanceof ValidatorError);
--remaining || done();
});
done();
});

it('boolean required', function(done) {
var Animal = new Schema({
isFerret: {type: Boolean, required: true}
});

var remaining = 4;

Animal.path('isFerret').doValidate(null, function(err) {
assert.ok(err instanceof ValidatorError);
--remaining || done();
});

Animal.path('isFerret').doValidate(undefined, function(err) {
assert.ok(err instanceof ValidatorError);
--remaining || done();
});

Animal.path('isFerret').doValidate(true, function(err) {
assert.ifError(err);
--remaining || done();
});

Animal.path('isFerret').doValidate(false, function(err) {
assert.ifError(err);
--remaining || done();
});
done();
});

it('mixed required', function(done) {
var Animal = new Schema({
characteristics: {type: Mixed, required: true}
});

var remaining = 4;

Animal.path('characteristics').doValidate(null, function(err) {
assert.ok(err instanceof ValidatorError);
--remaining || done();
});

Animal.path('characteristics').doValidate(undefined, function(err) {
assert.ok(err instanceof ValidatorError);
--remaining || done();
});

Animal.path('characteristics').doValidate({
aggresive: true
}, function(err) {
assert.ifError(err);
--remaining || done();
});

Animal.path('characteristics').doValidate('none available', function(err) {
assert.ifError(err);
--remaining || done();
});
done();
});
});

Expand Down

0 comments on commit f59defb

Please sign in to comment.