Closed pludov closed 6 years ago
So I'm going to run a bit more testing today, replacing assign
with merge
seems to also remove the need to have a RestoreObjectIDs()
function in certain cases. Going to look into it, and make sure it's working as intended.
@pludov Can you add the following tests to replace the test here: https://github.com/williamkapke/mongo-mock/blob/085f83bf0333149e856f9a0d130bb2dedbc40fa7/test/mock.test.js#L251-L264
it('should update one (updateOne)', function (done) {
//query, data, options, callback
collection.updateOne({test:123}, { $set: { foo: { bar: "buzz", fang: "dang" } } }, function (err, opResult) {
if(err) return done(err);
opResult.result.n.should.equal(1);
collection.findOne({test:123}, function (err, doc) {
if(err) return done(err);
(!!doc).should.be.true;
doc.should.have.property("foo", { bar: "buzz", fang: "dang" });
done();
});
});
});
it('should update one (updateOne) with shallow overwrite', function (done) {
//query, data, options, callback
collection.updateOne({ test: 123 }, { $set: { foo: { newValue: "bar" } } }, function (err, opResult) {
if (err) return done(err);
opResult.result.n.should.equal(1);
collection.findOne({ test: 123 }, function (err, doc) {
if (err) return done(err);
(!!doc).should.be.true;
doc.should.have.property("foo", { newValue: "bar" });
done();
});
});
});
I'm closing this because I opened a PR with your changes adding a unit test
Merge is unable to remove properties within nested object.
https://github.com/williamkapke/mongo-mock/issues/55