Skip to content

Commit

Permalink
test(update): repro #9537
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Nov 12, 2020
1 parent af6fb1b commit d4d3e63
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions test/model.update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3328,19 +3328,29 @@ describe('model: updateOne: ', function() {
});
});

it('moves $set of immutable properties to $setOnInsert (gh-8467)', function() {
it('moves $set of immutable properties to $setOnInsert (gh-8467) (gh-9537)', function() {
const childSchema = Schema({ name: String });
const Model = db.model('Test', Schema({
name: String,
age: { type: Number, default: 25, immutable: true }
age: { type: Number, default: 25, immutable: true },
child: { type: childSchema, immutable: true }
}));

const _opts = { upsert: true, setDefaultsOnInsert: true };

return co(function*() {
yield Model.updateOne({ name: 'John' }, { name: 'John', age: 20 }, _opts);
yield Model.deleteMany({});
yield Model.updateOne({}, { name: 'John', age: 20, child: { name: 'test' } }, _opts);

const doc = yield Model.findOne().lean();
assert.equal(doc.age, 20);
assert.equal(doc.name, 'John');
assert.equal(doc.child.name, 'test');

yield Model.updateOne({}, { name: 'new', age: 29, child: { name: 'new' } }, _opts);
assert.equal(doc.age, 20);
assert.equal(doc.name, 'John');
assert.equal(doc.child.name, 'test');
});
});

Expand Down

0 comments on commit d4d3e63

Please sign in to comment.