You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, Great blog post and sample code. I am finding that when I stub a Schema Find and try to get the following I never get a response. I looks like the validator starts, but the find in the call does not resolve.
it('should be invalid if emailkey is not unique', sinon.test(function() {
var atpl = { emailKey: 'one', name: 'one' };
this.stub(Template, 'find').yields(null, atpl );
var m = new Template({ emailKey: 'one', name: ''});
m.validate(function(err) {
expect(err.errors.name).to.not.exist;
done();
});
}));
schema.path('emailKey').validate(function (emailKey, fn) {
// We allow empty phone numbers.
if (!emailKey) return fn(true);
// Check only when it is a new user or when phone_number field is modified
if (this.isNew || this.isModified('emailKey')) {
var Template = mongoose.model('Template');
Template.find({ emailKey: emailKey }).exec(function (err, results) {
fn(!err && results.length === 0);
});
} else fn(true);
}, 'Email Key already exists');
The text was updated successfully, but these errors were encountered:
Hi, Great blog post and sample code. I am finding that when I stub a Schema Find and try to get the following I never get a response. I looks like the validator starts, but the find in the call does not resolve.
The text was updated successfully, but these errors were encountered: