Skip to content

Commit

Permalink
test: add coverage for post
Browse files Browse the repository at this point in the history
  • Loading branch information
limianwang committed Sep 29, 2015
1 parent 522ebef commit ee5d608
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/test_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,57 @@ describe('mongodb driver', function() {
});
});
});

describe('when creating data', function() {
var document;

beforeEach(function() {
document = {
model: model
};
});

it('should catch error returned from collection', function(done) {
sinon.stub(driver.database, 'collection', function(bucket) {
return {
insert: function(spec, callback) {
process.nextTick(function() {
callback(new Error('fake'));
});
}
};
});

driver.post(document, { _id: 'b' })
.catch(function(err) {
expect(err).to.exist;

driver.database.collection.restore();

done();
});
});

it('should yield array of created objects', function(done) {
sinon.stub(driver.database, 'collection', function(bucket) {
return {
insert: function(spec, callback) {
process.nextTick(function() {
callback(null, [{ _id: 'test', a: 'b' }]);
});
}
};
});

driver.post(document, { _id: 'test' })
.then(function() {

driver.database.collection.restore();

done();
});
});

});

});

0 comments on commit ee5d608

Please sign in to comment.