add stub to _request

This commit is contained in:
Matias Alejo Garcia 2014-07-07 19:33:59 -03:00
parent 1cb10219e9
commit b9b09d5f11
1 changed files with 13 additions and 22 deletions

View File

@ -180,29 +180,20 @@ describe('Insight model', function() {
});
it('should handle getTransaction errors', function(done) {
var http = require('http');
var request = {
statusCode: 200
};
request.on = function(event, cb) {
if (event === 'error') return;
if (event === 'data') return cb('{ "txid": "1234" }');
return cb();
};
var req = {};
req.write = function() {};
req.end = function() {};
sinon
.stub(http, 'request')
.returns(req)
.yields(request);
it('should handle getTransaction null response', function(done) {
var w = new Insight();
w._request = sinon.stub().yields();
w.getTransactions(['asdasd'], function(ret) {
ret.length.should.equal(0);
done();
});
});
it('should handle getTransaction empty response', function(done) {
var w = new Insight();
w._request = sinon.stub().yields([]);
w.getTransactions(['asdasd'], function(ret) {
ret.length.should.equal(0);
done();