|
|
@ -285,7 +285,7 @@ describe('Database', function () { |
|
|
|
insertedDoc.createdAt.should.equal(insertedDoc.updatedAt); |
|
|
|
insertedDoc.createdAt.should.equal(insertedDoc.updatedAt); |
|
|
|
assert.isDefined(insertedDoc._id); |
|
|
|
assert.isDefined(insertedDoc._id); |
|
|
|
Object.keys(insertedDoc).length.should.equal(4); |
|
|
|
Object.keys(insertedDoc).length.should.equal(4); |
|
|
|
assert.isBelow(Math.abs(insertedDoc.createdAt.getTime() - beginning), 15); // No more than 15ms should have elapsed
|
|
|
|
assert.isBelow(Math.abs(insertedDoc.createdAt.getTime() - beginning), 30); // No more than 30ms should have elapsed (worst case, if there is a flush)
|
|
|
|
|
|
|
|
|
|
|
|
// Modifying results of insert doesn't change the cache
|
|
|
|
// Modifying results of insert doesn't change the cache
|
|
|
|
insertedDoc.bloup = "another"; |
|
|
|
insertedDoc.bloup = "another"; |
|
|
@ -332,7 +332,7 @@ describe('Database', function () { |
|
|
|
d.insert(newDoc, function (err, insertedDoc) { |
|
|
|
d.insert(newDoc, function (err, insertedDoc) { |
|
|
|
Object.keys(insertedDoc).length.should.equal(4); |
|
|
|
Object.keys(insertedDoc).length.should.equal(4); |
|
|
|
insertedDoc.createdAt.getTime().should.equal(234); // Not modified
|
|
|
|
insertedDoc.createdAt.getTime().should.equal(234); // Not modified
|
|
|
|
assert.isBelow(insertedDoc.updatedAt.getTime() - beginning, 15); // Created
|
|
|
|
assert.isBelow(insertedDoc.updatedAt.getTime() - beginning, 30); // Created
|
|
|
|
|
|
|
|
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
assert.deepEqual(insertedDoc, docs[0]); |
|
|
|
assert.deepEqual(insertedDoc, docs[0]); |
|
|
@ -354,7 +354,7 @@ describe('Database', function () { |
|
|
|
d.insert(newDoc, function (err, insertedDoc) { |
|
|
|
d.insert(newDoc, function (err, insertedDoc) { |
|
|
|
Object.keys(insertedDoc).length.should.equal(4); |
|
|
|
Object.keys(insertedDoc).length.should.equal(4); |
|
|
|
insertedDoc.updatedAt.getTime().should.equal(234); // Not modified
|
|
|
|
insertedDoc.updatedAt.getTime().should.equal(234); // Not modified
|
|
|
|
assert.isBelow(insertedDoc.createdAt.getTime() - beginning, 15); // Created
|
|
|
|
assert.isBelow(insertedDoc.createdAt.getTime() - beginning, 30); // Created
|
|
|
|
|
|
|
|
|
|
|
|
d.find({}, function (err, docs) { |
|
|
|
d.find({}, function (err, docs) { |
|
|
|
assert.deepEqual(insertedDoc, docs[0]); |
|
|
|
assert.deepEqual(insertedDoc, docs[0]); |
|
|
@ -961,8 +961,8 @@ describe('Database', function () { |
|
|
|
var beginning = Date.now(); |
|
|
|
var beginning = Date.now(); |
|
|
|
d = new Datastore({ filename: testDb, autoload: true, timestampData: true }); |
|
|
|
d = new Datastore({ filename: testDb, autoload: true, timestampData: true }); |
|
|
|
d.insert({ hello: 'world' }, function (err, insertedDoc) { |
|
|
|
d.insert({ hello: 'world' }, function (err, insertedDoc) { |
|
|
|
assert.isBelow(insertedDoc.updatedAt.getTime() - beginning, 15); |
|
|
|
assert.isBelow(insertedDoc.updatedAt.getTime() - beginning, 30); |
|
|
|
assert.isBelow(insertedDoc.createdAt.getTime() - beginning, 15); |
|
|
|
assert.isBelow(insertedDoc.createdAt.getTime() - beginning, 30); |
|
|
|
Object.keys(insertedDoc).length.should.equal(4); |
|
|
|
Object.keys(insertedDoc).length.should.equal(4); |
|
|
|
|
|
|
|
|
|
|
|
// Wait 100ms before performing the update
|
|
|
|
// Wait 100ms before performing the update
|
|
|
@ -976,7 +976,7 @@ describe('Database', function () { |
|
|
|
docs[0].createdAt.should.equal(insertedDoc.createdAt); |
|
|
|
docs[0].createdAt.should.equal(insertedDoc.createdAt); |
|
|
|
docs[0].hello.should.equal('mars'); |
|
|
|
docs[0].hello.should.equal('mars'); |
|
|
|
assert.isAbove(docs[0].updatedAt.getTime() - beginning, 99); // updatedAt modified
|
|
|
|
assert.isAbove(docs[0].updatedAt.getTime() - beginning, 99); // updatedAt modified
|
|
|
|
assert.isBelow(docs[0].updatedAt.getTime() - step1, 15); // updatedAt modified
|
|
|
|
assert.isBelow(docs[0].updatedAt.getTime() - step1, 30); // updatedAt modified
|
|
|
|
|
|
|
|
|
|
|
|
done(); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -1815,19 +1815,19 @@ describe('Database', function () { |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
d.getAllData().length.should.equal(0); |
|
|
|
d.getAllData().length.should.equal(0); |
|
|
|
|
|
|
|
d.ensureIndex({ fieldName: 'z' }, function () { |
|
|
|
d.ensureIndex({ fieldName: 'z' }); |
|
|
|
d.ensureIndex({ fieldName: 'a' }, function () { |
|
|
|
d.ensureIndex({ fieldName: 'a' }); |
|
|
|
|
|
|
|
d.indexes.a.tree.getNumberOfKeys().should.equal(0); |
|
|
|
d.indexes.a.tree.getNumberOfKeys().should.equal(0); |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(0); |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(0); |
|
|
|
|
|
|
|
|
|
|
|
fs.writeFile(testDb, rawData, 'utf8', function () { |
|
|
|
fs.writeFile(testDb, rawData, 'utf8', function () { |
|
|
|
d.loadDatabase(function () { |
|
|
|
d.loadDatabase(function (err) { |
|
|
|
var doc1 = _.find(d.getAllData(), function (doc) { return doc.z === "1"; }) |
|
|
|
var doc1 = _.find(d.getAllData(), function (doc) { return doc.z === "1"; }) |
|
|
|
, doc2 = _.find(d.getAllData(), function (doc) { return doc.z === "2"; }) |
|
|
|
, doc2 = _.find(d.getAllData(), function (doc) { return doc.z === "2"; }) |
|
|
|
, doc3 = _.find(d.getAllData(), function (doc) { return doc.z === "3"; }) |
|
|
|
, doc3 = _.find(d.getAllData(), function (doc) { return doc.z === "3"; }) |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert.isNull(err); |
|
|
|
d.getAllData().length.should.equal(3); |
|
|
|
d.getAllData().length.should.equal(3); |
|
|
|
|
|
|
|
|
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(3); |
|
|
|
d.indexes.z.tree.getNumberOfKeys().should.equal(3); |
|
|
@ -1845,6 +1845,9 @@ describe('Database', function () { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('If a unique constraint is not respected, database loading will not work and no data will be inserted', function (done) { |
|
|
|
it('If a unique constraint is not respected, database loading will not work and no data will be inserted', function (done) { |
|
|
|
var now = new Date() |
|
|
|
var now = new Date() |
|
|
|
, rawData = model.serialize({ _id: "aaa", z: "1", a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|
, rawData = model.serialize({ _id: "aaa", z: "1", a: 2, ages: [1, 5, 12] }) + '\n' + |
|
|
|