From a4888e535471f35672e8feb50d4b7c7c8daacdd2 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 23 May 2016 15:45:13 -0400 Subject: [PATCH] test: increase test coverage for lib/node.js --- test/node.unit.js | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/test/node.unit.js b/test/node.unit.js index 94d22c3c..dc7b4a3e 100644 --- a/test/node.unit.js +++ b/test/node.unit.js @@ -34,7 +34,6 @@ describe('Bitcore Node', function() { }); it('will set properties', function() { var config = { - datadir: 'testdir', services: [ { name: 'test1', @@ -49,11 +48,15 @@ describe('Bitcore Node', function() { node._unloadedServices[0].name.should.equal('test1'); node._unloadedServices[0].module.should.equal(TestService); node.network.should.equal(Networks.defaultNetwork); + var node2 = TestNode(config); + node2._unloadedServices.length.should.equal(1); + node2._unloadedServices[0].name.should.equal('test1'); + node2._unloadedServices[0].module.should.equal(TestService); + node2.network.should.equal(Networks.defaultNetwork); }); it('will set network to testnet', function() { var config = { network: 'testnet', - datadir: 'testdir', services: [ { name: 'test1', @@ -69,7 +72,6 @@ describe('Bitcore Node', function() { it('will set network to regtest', function() { var config = { network: 'regtest', - datadir: 'testdir', services: [ { name: 'test1', @@ -84,6 +86,26 @@ describe('Bitcore Node', function() { should.exist(regtest); node.network.should.equal(regtest); }); + it('will be able to disable log formatting', function() { + var config = { + network: 'regtest', + services: [ + { + name: 'test1', + module: TestService + } + ], + formatLogs: false + }; + var TestNode = proxyquire('../lib/node', {}); + var node = new TestNode(config); + node.log.formatting.should.equal(false); + + var TestNode = proxyquire('../lib/node', {}); + config.formatLogs = true; + var node2 = new TestNode(config); + node2.log.formatting.should.equal(true); + }); }); describe('#openBus', function() { @@ -92,6 +114,11 @@ describe('Bitcore Node', function() { var bus = node.openBus(); bus.node.should.equal(node); }); + it('will use remoteAddress config option', function() { + var node = new Node(baseConfig); + var bus = node.openBus({remoteAddress: '127.0.0.1'}); + bus.remoteAddress.should.equal('127.0.0.1'); + }); }); describe('#getAllAPIMethods', function() { @@ -183,7 +210,8 @@ describe('Bitcore Node', function() { function TestService() {} util.inherits(TestService, BaseService); TestService.prototype.start = sinon.stub().callsArg(0); - TestService.prototype.getData = function() {}; + var getData = sinon.stub(); + TestService.prototype.getData = getData; TestService.prototype.getAPIMethods = function() { return [ ['getData', this, this.getData, 1] @@ -201,6 +229,8 @@ describe('Bitcore Node', function() { TestService.prototype.start.callCount.should.equal(1); should.exist(node.services.testservice); should.exist(node.getData); + node.getData(); + getData.callCount.should.equal(1); }); }); it('will give an error from start', function() {