Skip to content

Commit

Permalink
test(document): repro #11172
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 15, 2022
1 parent 36a9232 commit e4145f9
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7329,7 +7329,6 @@ describe('document', function() {

const User = db.model('User', userSchema);


const position = {
geometry: {
type: 'Point',
Expand Down Expand Up @@ -10960,6 +10959,29 @@ describe('document', function() {
};

await new Test(doc).save();
});

it('correctly handles modifying array subdoc after setting array subdoc to same value (gh-11172)', async function() {
const Order = db.model('Order', new Schema({
cumulativeConsumption: [{
_id: false,
unit: String,
value: Number
}]
}));

await Order.create({
cumulativeConsumption: [{ unit: 'foo', value: 123 }, { unit: 'bar', value: 42 }]
});

const doc = await Order.findOne();
doc.cumulativeConsumption = doc.toObject().cumulativeConsumption;

const match = doc.cumulativeConsumption.find(o => o.unit === 'bar');
match.value = 43;
match.unit = 'baz';

assert.ok(doc.isModified());
assert.ok(doc.isModified('cumulativeConsumption.1'));
});
});

0 comments on commit e4145f9

Please sign in to comment.