From 8b5e616668605ec29fd2084d97a0101192ceed3a Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 19 Jun 2014 00:33:27 -0300 Subject: [PATCH] add tests for node --- js/models/blockchain/Insight.js | 2 + test/test.blockchain.Insight.js | 109 +++++++++++++++++--------------- 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/js/models/blockchain/Insight.js b/js/models/blockchain/Insight.js index 060863cb6..ae94b95dc 100644 --- a/js/models/blockchain/Insight.js +++ b/js/models/blockchain/Insight.js @@ -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); }); }); diff --git a/test/test.blockchain.Insight.js b/test/test.blockchain.Insight.js index 12167ea4b..f24e581d2 100644 --- a/test/test.blockchain.Insight.js +++ b/test/test.blockchain.Insight.js @@ -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(); + }); + }); + } });