Skip to content

Commit

Permalink
test(Model.updateOne): repro Automattic#8678
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelrahmanHafez committed Mar 18, 2020
1 parent 6065eff commit 9b13947
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions test/model.update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3054,21 +3054,13 @@ describe('model: update:', function() {
});
});
it('casts objects to array when clobbering with $set (gh-6532)', function(done) {
const sub = new Schema({
x: String
});
const sub = new Schema({ x: String });

const schema = new Schema({
name: String,
arr: [sub]
});
const schema = new Schema({ name: String, arr: [sub] });

const Test = db.model('Test', schema);

const test = {
name: 'Xyz',
arr: [{ x: 'Z' }]
};
const test = { name: 'Xyz', arr: [{ x: 'Z' }] };

const cond = { name: 'Xyz' };
const obj1 = { x: 'Y' };
Expand Down Expand Up @@ -3389,4 +3381,16 @@ describe('model: updateOne: ', function() {
});
});
});

it('works with aliases (gh-8678)', function() {
const User = db.model('Test', new Schema({ n: { type: String, alias: 'name' } }));
return co(function*() {
const user = yield User.create({ name: 'Hafez' });

yield User.updateMany({ _id: user._id }, { name: 'new name' });

const updatedUser = yield User.findOne({ _id: user._id });
assert.equal(updatedUser.name, 'new name');
});
});
});

0 comments on commit 9b13947

Please sign in to comment.