|
|
|
@ -957,6 +957,34 @@ describe('Database', function () { |
|
|
|
|
], done); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("If timestampData option is set, update the updatedAt field", function (done) { |
|
|
|
|
var beginning = Date.now(); |
|
|
|
|
d = new Datastore({ filename: testDb, autoload: true, timestampData: true }); |
|
|
|
|
d.insert({ hello: 'world' }, function (err, insertedDoc) { |
|
|
|
|
assert.isBelow(insertedDoc.updatedAt.getTime() - beginning, 15); |
|
|
|
|
assert.isBelow(insertedDoc.createdAt.getTime() - beginning, 15); |
|
|
|
|
Object.keys(insertedDoc).length.should.equal(4); |
|
|
|
|
|
|
|
|
|
// Wait 100ms before performing the update
|
|
|
|
|
setTimeout(function () { |
|
|
|
|
var step1 = Date.now(); |
|
|
|
|
d.update({ _id: insertedDoc._id }, { $set: { hello: 'mars' } }, {}, function () { |
|
|
|
|
d.find({ _id: insertedDoc._id }, function (err, docs) { |
|
|
|
|
docs.length.should.equal(1); |
|
|
|
|
Object.keys(docs[0]).length.should.equal(4); |
|
|
|
|
docs[0]._id.should.equal(insertedDoc._id); |
|
|
|
|
docs[0].createdAt.should.equal(insertedDoc.createdAt); |
|
|
|
|
docs[0].hello.should.equal('mars'); |
|
|
|
|
assert.isAbove(docs[0].updatedAt.getTime() - beginning, 99); // updatedAt modified
|
|
|
|
|
assert.isBelow(docs[0].updatedAt.getTime() - step1, 15); // updatedAt modified
|
|
|
|
|
|
|
|
|
|
done(); |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
}, 100); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("Can update multiple documents matching the query", function (done) { |
|
|
|
|
var id1, id2, id3; |
|
|
|
|
|
|
|
|
|