Updated upsert tests to check if newDoc has been sent back successfully, modeled after other insert tests

pull/2/head
Jason Rhodes 11 years ago
parent b3c69f67aa
commit 4346660187
  1. 13
      test/db.test.js

@ -851,14 +851,15 @@ describe('Database', function () {
d.find({}, function (err, docs) { d.find({}, function (err, docs) {
docs.length.should.equal(0); // Default option for upsert is false docs.length.should.equal(0); // Default option for upsert is false
d.update({ impossible: 'db is empty anyway' }, { newDoc: true }, { upsert: true }, function (err, nr, upsert) { d.update({ impossible: 'db is empty anyway' }, { something: "created ok" }, { upsert: true }, function (err, nr, newDoc) {
assert.isNull(err); assert.isNull(err);
nr.should.equal(1); nr.should.equal(1);
upsert.should.equal(true); newDoc.something.should.equal("created ok");
assert.isDefined(newDoc._id);
d.find({}, function (err, docs) { d.find({}, function (err, docs) {
docs.length.should.equal(1); // Default option for upsert is false docs.length.should.equal(1); // Default option for upsert is false
docs[0].newDoc.should.equal(true); docs[0].something.should.equal("created ok");
done(); done();
}); });
@ -912,10 +913,12 @@ describe('Database', function () {
}); });
it('Can upsert a document even with modifiers', function (done) { it('Can upsert a document even with modifiers', function (done) {
d.update({ bloup: 'blap' }, { $set: { hello: 'world' } }, { upsert: true }, function (err, nr, upsert) { d.update({ bloup: 'blap' }, { $set: { hello: 'world' } }, { upsert: true }, function (err, nr, newDoc) {
assert.isNull(err); assert.isNull(err);
nr.should.equal(1); nr.should.equal(1);
upsert.should.equal(true); newDoc.bloup.should.equal('blap');
newDoc.hello.should.equal('world');
assert.isDefined(newDoc._id);
d.find({}, function (err, docs) { d.find({}, function (err, docs) {
docs.length.should.equal(1); docs.length.should.equal(1);

Loading…
Cancel
Save