From 74f558c35ad7b4a2354ba093a85c3c9177f94903 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 12 Sep 2019 15:39:06 -0400 Subject: [PATCH] test(document): repro #8149 --- test/document.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/document.test.js b/test/document.test.js index 242bcc3ec2a..3a840be158a 100644 --- a/test/document.test.js +++ b/test/document.test.js @@ -7835,6 +7835,22 @@ describe('document', function() { assert.equal(fromDb2.test, 'after'); }); }); + + it('immutable with strict mode (gh-8149)', function() { + return co(function*() { + const schema = new mongoose.Schema({ + name: String, + yearOfBirth: { type: Number, immutable: true } + }, { strict: 'throw' }); + const Person = db.model('gh8149', schema); + const joe = yield Person.create({ name: 'Joe', yearOfBirth: 2001 }); + + joe.set({ yearOfBirth: 2002 }); + const err = yield joe.save().then(() => null, err => err); + assert.ok(err); + assert.equal(err.errors['yearOfBirth'].name, 'StrictModeError'); + }); + }); }); it('consistent post order traversal for array subdocs (gh-7929)', function() {