Skip to content

Commit

Permalink
test: add test coverage for #13043 to show that issue is fixed by #13003
Browse files Browse the repository at this point in the history
 fix
  • Loading branch information
vkarpov15 committed Mar 6, 2023
1 parent da04458 commit 5af7c8c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12179,6 +12179,47 @@ describe('document', function() {
doc.init({ properties: { foo: 'foo' } });
assert.strictEqual(doc.properties.bar, undefined);
});

it('avoids overwriting array with sibling projection (gh-13043)', async function() {
const testSchema = new mongoose.Schema({
str: 'string',
obj: {
subObj: {
str: 'string'
},
subArr: [{
str: 'string'
}]
},
arr: [{
str: 'string'
}]
});
const Test = db.model('Test', testSchema);
// Create one test document : obj.subArr[0].str === 'subArr.test1'
await Test.create({
str: 'test1',
obj: {
subObj: {
str: 'subObj.test1'
},
subArr: [{
str: 'subArr.test1'
}]
},
arr: [{ str: 'arr.test1' }]
});

const test = await Test.findOne({ str: 'test1' }, 'str obj.subObj');

// Update one property
test.str = test.str + ' - updated';
await test.save();

const fromDb = await Test.findById(test);
assert.equal(fromDb.obj.subArr.length, 1);
assert.equal(fromDb.obj.subArr[0].str, 'subArr.test1');
});
});

describe('Check if instance function that is supplied in schema option is availabe', function() {
Expand Down

0 comments on commit 5af7c8c

Please sign in to comment.