From 7d8fc09226432b93203057c38e4951633b450ccf Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Sat, 13 Oct 2018 14:47:42 -0400 Subject: [PATCH] add test for pubsub --- test/pubsub.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/pubsub.js diff --git a/test/pubsub.js b/test/pubsub.js new file mode 100644 index 0000000000..12d31f9ceb --- /dev/null +++ b/test/pubsub.js @@ -0,0 +1,39 @@ +'use strict'; + +var assert = require('assert'); +var nconf = require('nconf'); + +var db = require('./mocks/databasemock'); +var pubsub = require('../src/pubsub'); + +describe('pubsub', function () { + it('should use singleHostCluster', function (done) { + var oldValue = nconf.get('singleHostCluster'); + var isCluster = nconf.get('isCluster'); + nconf.set('singleHostCluster', true); + nconf.set('isCluster', true); + pubsub.on('testEvent', function (message) { + assert.equal(message.foo, 1); + nconf.set('singleHostCluster', oldValue); + nconf.set('isCluster', isCluster); + pubsub.removeAllListeners('testEvent'); + done(); + }); + pubsub.publish('testEvent', { foo: 1 }); + }); + + it('should use the current database\'s pubsub', function (done) { + var oldValue = nconf.get('singleHostCluster'); + var isCluster = nconf.get('isCluster'); + nconf.set('singleHostCluster', false); + nconf.set('isCluster', true); + pubsub.on('testEvent', function (message) { + assert.equal(message.foo, 1); + nconf.set('singleHostCluster', oldValue); + nconf.set('isCluster', isCluster); + pubsub.removeAllListeners('testEvent'); + done(); + }); + pubsub.publish('testEvent', { foo: 1 }); + }); +});