add tests for node

This commit is contained in:
Matias Alejo Garcia 2014-06-19 00:33:27 -03:00
parent 0481cf8e02
commit 8b5e616668
2 changed files with 60 additions and 51 deletions

View File

@ -195,6 +195,8 @@ Insight.prototype._requestNode = function(options, callback) {
return callback(e, ret);
});
response.on('error', function(e) {
console.log('[Insight.js.201]'); //TODO
return callback(e, ret);
});
});

View File

@ -58,64 +58,71 @@ describe('Insight model', function() {
var i = new Insight();
should.exist(i);
});
it.skip('should return array of unspent output', function(done) {
var i = new Insight();
// Tests for Node
if (process.version) {
it('should return array of unspent output', function(done) {
var i = new Insight();
var http = require('http');
var request = {
statusCode: 200
};
request.on = function(event, cb) {
if (event === 'error') return;
if (event === 'data') return {
hola: 'chau'
var http = require('http');
var request = {
statusCode: 200
};
return cb();
};
var req = {};
req.write = function() {};
req.end = function() {};
sinon
.stub(http, 'request')
.returns(req)
.yields(request);
i.getUnspent(['2MuD5LnZSViZZYwZbpVsagwrH8WWvCztdmV', '2NBSLoMvsHsf2Uv3LA17zV4beH6Gze6RovA'], function(e, ret) {
should.not.exist(e);
should.exist(ret);
done();
});
});
it.skip('should return txid', function(done) {
var i = new Insight();
var http = require('http');
var request = {
statusCode: 200
};
request.on = function(event, cb) {
if (event === 'error') return;
if (event === 'data') return {
hola: 'chau'
request.on = function(event, cb) {
if (event === 'error') return;
if (event === 'data') return cb(JSON.stringify(unspent));
return cb();
};
return cb();
};
var req = {};
req.write = function() {};
req.end = function() {};
var req = {};
req.write = function() {};
req.end = function() {};
i.sendRawTransaction(rawtx, function(a) {
should.exist(a);
done();
sinon
.stub(http, 'request')
.returns(req)
.yields(request);
i.getUnspent(['2MuD5LnZSViZZYwZbpVsagwrH8WWvCztdmV', '2NBSLoMvsHsf2Uv3LA17zV4beH6Gze6RovA'], function(e, ret) {
should.not.exist(e);
ret.should.deep.equal(unspent);
http.request.restore();
done();
});
});
});
it('should return txid', function(done) {
var i = new Insight();
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);
i.sendRawTransaction(rawtx, function(a) {
should.exist(a);
a.should.equal('1234');
http.request.restore();
done();
});
});
}
});