Normal query test 1

pull/2/head
Louis Chatriot 11 years ago
parent 14f4b375ec
commit 308eba79fb
  1. 51
      test/cursor.test.js

@ -40,16 +40,51 @@ describe.only('Cursor', function () {
], done); ], done);
}); });
describe('Querying without modifier', function () {
it('Without query', function (done) {
async.waterfall([
function (cb) {
d.insert({ age: 5 }, function (err) {
d.insert({ age: 57 }, function (err) {
d.insert({ age: 52 }, function (err) {
d.insert({ age: 23 }, function (err) {
d.insert({ age: 89 }, function (err) {
return cb();
});
});
});
});
});
}
, function (cb) {
var cursor = new Cursor(d);
cursor.exec(function (err, docs) {
assert.isNull(err);
docs.length.should.equal(5);
_.filter(docs, function(doc) { return doc.age === 5; })[0].age.should.equal(5);
_.filter(docs, function(doc) { return doc.age === 57; })[0].age.should.equal(57);
_.filter(docs, function(doc) { return doc.age === 52; })[0].age.should.equal(52);
_.filter(docs, function(doc) { return doc.age === 23; })[0].age.should.equal(23);
_.filter(docs, function(doc) { return doc.age === 89; })[0].age.should.equal(89);
cb();
});
}
], done);
});
});
describe('Sorting of the results', function () { describe('Sorting of the results', function () {
it('Using one sort', function (done) { it('Using one sort', function (done) {
var cursor, i; var cursor, i;
// We don't know the order in which docs wil be inserted but we ensure correctness by testing both sort orders
d.insert({ age: 5 }); d.insert({ age: 5 }, function (err) {
d.insert({ age: 57 }); d.insert({ age: 57 }, function (err) {
d.insert({ age: 52 }); d.insert({ age: 52 }, function (err) {
d.insert({ age: 23 }); d.insert({ age: 23 }, function (err) {
d.insert({ age: 89 }, function (err) { // We only need the last callback as all operations are queued d.insert({ age: 89 }, function (err) {
cursor = new Cursor(d, {}); cursor = new Cursor(d, {});
cursor.sort({ age: 1 }); cursor.sort({ age: 1 });
cursor.exec(function (err, docs) { cursor.exec(function (err, docs) {
@ -72,6 +107,10 @@ describe.only('Cursor', function () {
}); });
}); });
}); });
});
});
});
});
}); });

Loading…
Cancel
Save