Skip to content

Commit

Permalink
slightly refactor entry tests and creation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Feb 20, 2015
1 parent cd047fa commit 0654510
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ function storage(name, storage, pushover) {
if (err) { fn(err); return; }
// potentially a batch insert
var firstErr = null,
numDocs = docs.length,
totalCreated = 0;

docs.forEach(function(doc) {
collection.update(doc, doc, {upsert: true}, function (err, created) {
firstErr = firstErr || err;
if (++totalCreated >= docs.length) {
if (++totalCreated === numDocs) {
fn(firstErr, totalCreated, docs);
}
});
Expand Down
14 changes: 8 additions & 6 deletions tests/api.entries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,26 @@ describe('Entries REST api', function ( ) {
entries.should.be.ok;
});

it('/entries.json', function (done) {
it('gets requested number of entries', function (done) {
var count = 30;
request(this.app)
.get('/entries.json')
.get('/entries.json?count=' + count)
.expect(200)
.end(function (err, res) {
// console.log('body', res.body);
res.body.length.should.equal(10);
res.body.length.should.equal(count);
done( );
});
});

it('/entries.json?count=30', function (done) {
it('gets default number of entries', function (done) {
var defaultCount = 10;
request(this.app)
.get('/entries.json?count=30')
.get('/entries.json')
.expect(200)
.end(function (err, res) {
// console.log('body', res.body);
res.body.length.should.equal(30);
res.body.length.should.equal(defaultCount);
done( );
});
});
Expand Down

0 comments on commit 0654510

Please sign in to comment.