Skip to content

Commit

Permalink
test(document): repro #9459
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Oct 4, 2020
1 parent 4da58f8 commit 18973c0
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9448,4 +9448,46 @@ describe('document', function() {
const err = doc.validateSync();
assert.ok(err.errors['num'].reason);
});

it('init tracks cast error reason (gh-9459)', function() {
const preferencesSchema = mongoose.Schema({
notifications: {
email: Boolean,
push: Boolean
},
keepSession: Boolean
}, { _id: false });

const User = db.model('User', Schema({
email: String,
username: String,
preferences: preferencesSchema
}));

const userFixture = {
email: 'foo@bar.com',
username: 'foobars',
preferences: {
keepSession: true,
notifications: {
email: false,
push: false
}
}
};

let userWithEmailNotifications = Object.assign({}, userFixture, {
'preferences.notifications': { email: true }
});
let testUser = new User(userWithEmailNotifications);

assert.deepEqual(testUser.toObject().preferences.notifications, { email: true });

userWithEmailNotifications = Object.assign({}, userFixture, {
'preferences.notifications.email': true
});
testUser = new User(userWithEmailNotifications);

assert.deepEqual(testUser.toObject().preferences.notifications, { email: true, push: false });
});
});

0 comments on commit 18973c0

Please sign in to comment.