test: increase test coverage for lib/node.js

This commit is contained in:
Braydon Fuller 2016-05-23 15:45:13 -04:00
parent 202971ec0c
commit a4888e5354
1 changed files with 34 additions and 4 deletions

View File

@ -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() {