From 194913c561975a33a25d6696e17704b54dc37ebc Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 9 Sep 2014 22:21:42 -0300 Subject: [PATCH] fix insight tests --- test/mocks/FakeBlockchainSocket.js | 9 ++++++++- test/test.blockchain.Insight.js | 26 +++++++++----------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/test/mocks/FakeBlockchainSocket.js b/test/mocks/FakeBlockchainSocket.js index 85c6c98e4..941013ae6 100644 --- a/test/mocks/FakeBlockchainSocket.js +++ b/test/mocks/FakeBlockchainSocket.js @@ -30,9 +30,16 @@ FakeSocket.prototype.removeEventListener = function() { return; } + + FakeSocket.prototype.destroy = function() { this.connected = false; this.removeAllListeners(); }; -module.exports = FakeSocket; \ No newline at end of file + +FakeSocket.prototype.disconnect = function() { + this.destroy(); +}; + +module.exports = FakeSocket; diff --git a/test/test.blockchain.Insight.js b/test/test.blockchain.Insight.js index 46eecdc0e..b43003ed6 100644 --- a/test/test.blockchain.Insight.js +++ b/test/test.blockchain.Insight.js @@ -79,9 +79,9 @@ describe('Insight model', function() { var socket = blockchain.getSocket(); blockchain.on('connect', function() { blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM'); - blockchain.getSubscriptions().length.should.equal(1); + Object.keys(blockchain.getSubscriptions()).length.should.equal(1); blockchain.destroy(); - blockchain.getSubscriptions().length.should.equal(0); + Object.keys(blockchain.getSubscriptions()).length.should.equal(0); blockchain.status.should.be.equal('destroyed'); done(); }); @@ -93,7 +93,7 @@ describe('Insight model', function() { var emitSpy = sinon.spy(socket, 'emit'); blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM'); - blockchain.getSubscriptions().length.should.equal(1); + Object.keys(blockchain.getSubscriptions()).length.should.equal(1); emitSpy.calledWith('subscribe', 'mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM'); }); @@ -102,7 +102,7 @@ describe('Insight model', function() { blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM'); blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM'); - blockchain.getSubscriptions().length.should.equal(1); + Object.keys(blockchain.getSubscriptions()).length.should.equal(1); }); it('should subscribe to a list of addresses', function() { @@ -114,27 +114,19 @@ describe('Insight model', function() { 'mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM', '2NBBHBjB5sd7HFqKtout1L7d6dPhwJgP2j8' ]); - blockchain.getSubscriptions().length.should.equal(2); + Object.keys(blockchain.getSubscriptions()).length.should.equal(2); emitSpy.calledWith('subscribe', 'mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM'); emitSpy.calledWith('subscribe', '2NBBHBjB5sd7HFqKtout1L7d6dPhwJgP2j8'); }); - it('should unsubscribe to an address', function() { - var blockchain = new Insight(FAKE_OPTS); - blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM'); - blockchain.getSubscriptions().length.should.equal(1); - blockchain.unsubscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM'); - blockchain.getSubscriptions().length.should.equal(0); - }); - - it('should unsubscribe to all addresses', function() { + it('should resubscribe to all addresses', function() { var blockchain = new Insight(FAKE_OPTS); blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM'); blockchain.subscribe('2NBBHBjB5sd7HFqKtout1L7d6dPhwJgP2j8'); - blockchain.getSubscriptions().length.should.equal(2); + Object.keys(blockchain.getSubscriptions()).length.should.equal(2); - blockchain.unsubscribeAll('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM'); - blockchain.getSubscriptions().length.should.equal(0); + blockchain.reSubscribe(); + Object.keys(blockchain.getSubscriptions()).length.should.equal(2); }); it('should broadcast a raw transaction', function(done) {