From 65e09ef281130a6b6112023c52202952af5996c1 Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Wed, 9 Sep 2015 11:08:55 -0400 Subject: [PATCH] Added integration for the bus - Added a new file that exercises the subscribe/unsubscribe/close methods with a test service - Removed a duplicate call to inherit --- integration/regtest-bus.js | 74 ++++++++++++++++++++++++++++++++++++++ lib/node.js | 2 -- 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 integration/regtest-bus.js diff --git a/integration/regtest-bus.js b/integration/regtest-bus.js new file mode 100644 index 00000000..f79f04fa --- /dev/null +++ b/integration/regtest-bus.js @@ -0,0 +1,74 @@ +'use strict'; + +var Bus = require('../lib/bus'); +var util = require('util'); +var BaseService = require('../lib/service'); + +function TestService() { + this.subscriptions = {}; + this.subscriptions['test/test'] = {}; +} +util.inherits(TestService, BaseService); + +TestService.prototype.subscribe = function(name, emitter) { + emitter.emit('Subscribe'); +}; + +TestService.prototype.unsubscribe = function(name, emitter) { + emitter.emit('Unsubscribe'); +}; + +TestService.prototype.getPublishEvents = function() { + return [ + { + name: 'test/test', + scope: this, + subscribe: this.subscribe.bind(this, 'test/test'), + unsubscribe: this.unsubscribe.bind(this, 'test/test') + } + ]; +} + +describe('Bus Functionality', function() { + var params; + before(function() { + params = { + node : { + services : [ + new TestService() + ] + } + } + }); + + after(function(done) { + done(); + }); + + it('#subscribe', function(done) { + var bus = new Bus(params); + bus.on('Subscribe', function() { + done(); + }); + bus.subscribe('test/test'); + }); + + it('#unsubscribe', function(done) { + var bus = new Bus(params); + bus.on('Unsubscribe', function() { + done(); + }); + bus.subscribe('test/test'); + bus.unsubscribe('test/test'); + }); + + it('#close', function(done) { + var bus = new Bus(params); + bus.on('Unsubscribe', function() { + done(); + }); + bus.close(); + }); + +}); + diff --git a/lib/node.js b/lib/node.js index 908f0978..3061610c 100644 --- a/lib/node.js +++ b/lib/node.js @@ -41,8 +41,6 @@ function Node(config) { util.inherits(Node, EventEmitter); -util.inherits(Node, EventEmitter); - Node.prototype._setNetwork = function(config) { if (config.network === 'testnet') { this.network = Networks.get('testnet');