Skip to content

Commit

Permalink
Merge pull request #8983 from AbdelrahmanHafez/test/casting-discrimin…
Browse files Browse the repository at this point in the history
…ator-key

add test case to assert #8892
  • Loading branch information
vkarpov15 committed May 12, 2020
2 parents 28c845a + 537154e commit b293a36
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3629,4 +3629,21 @@ describe('Query', function() {
assert.equal(user.age, 25);
});
});

it('casts update object according to child discriminator schema when `discriminatorKey` is present (gh-8982)', function() {
const userSchema = new Schema({ }, { discriminatorKey: 'kind' });
const Person = db.model('Person', userSchema);

return co(function*() {
const Worker = Person.discriminator('Worker', new Schema({ locations: [String] }));
const worker = yield Worker.create({ locations: ['US'] });

// should cast `update` according to `Worker` schema
yield Person.updateOne({ _id: worker._id, kind: 'Worker' }, { $push: { locations: 'UK' } });

const person = yield Person.findOne({ _id: worker._id });

assert.deepEqual(person.locations, ['US', 'UK']);
});
});
});

0 comments on commit b293a36

Please sign in to comment.