Skip to content

Commit

Permalink
test: add test coverage for #13219
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Apr 5, 2023
1 parent f059573 commit 1ae3088
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
20 changes: 20 additions & 0 deletions test/model.findOneAndUpdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2061,4 +2061,24 @@ describe('model: findOneAndUpdate:', function() {

assert.ifError(err);
});

it('casts array filters (gh-13219)', async function() {
const MyModel = db.model('Test', new Schema({
_id: Number,
grades: [Number]
}));

await MyModel.create([
{ _id: 1, grades: [95, 102, 90] }
]);

await MyModel.findOneAndUpdate(
{},
{ $set: { 'grades.$[element]': 100 } },
{ arrayFilters: [{ element: { $gt: '100' } }] }
);

const doc = await MyModel.findOne();
assert.deepEqual(doc.toObject().grades, [95, 100, 90]);
});
});
9 changes: 0 additions & 9 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3322,15 +3322,6 @@ describe('Model', function() {
});

describe('3.6 features', function() {
before(async function() {
const version = await start.mongodVersion();
const mongo36 = version[0] > 3 || (version[0] === 3 && version[1] >= 6);

if (!mongo36) {
this.skip();
}
});

it('arrayFilter (gh-5965)', async function() {

const MyModel = db.model('Test', new Schema({
Expand Down

0 comments on commit 1ae3088

Please sign in to comment.