diff --git a/src/module.js b/src/module.js index 839576c..517aacf 100644 --- a/src/module.js +++ b/src/module.js @@ -51,7 +51,7 @@ class Module extends EventEmitter { } options = _.defaults(options, defaults); - if (!options instanceof Module) { + if (!(options instanceof Module)) { logger.debug('Initializing module with options:', options); } diff --git a/test/module.spec.js b/test/module.spec.js index 83b466a..00d32c1 100644 --- a/test/module.spec.js +++ b/test/module.spec.js @@ -1,6 +1,7 @@ import * as chai from 'chai'; import dirtyChai from 'dirty-chai'; import Module from '../src/module'; +import logger from '../src/logging/logger'; import dockerNames from 'docker-names'; // TEST SETUP @@ -22,6 +23,48 @@ describe('Module', function () { }); }); + it('Should log when a new module is being initialized with options', function (done) { + + logger._test_debug = logger.debug; + logger.debug = function () { + if (arguments[0] === 'Initializing module with options:') { + // reset logger; + logger.debug = logger._test_debug; + done(); + } + logger._test_debug.apply(logger, arguments); + + }; + + const m = new Module({ service: 'testService' }); + + logger.info(`Module initialized [${m.service}]-[${m.name}]`); + + }); + + it('Should NOT log when a new module is being initialized with Module', function (done) { + + let m = new Module({ service: 'testService' }); + + logger._test_debug = logger.debug; + logger.debug = function () { + if (arguments[0] === 'Initializing module with options:') { + // reset logger; + logger.debug = logger._test_debug; + done(new Error('Module initialization with module should not be logged')); + } + logger._test_debug.apply(logger, arguments); + + }; + + m = new Module(m); + + logger.info(`Module initialized [${m.service}]-[${m.name}]`); + logger.debug = logger._test_debug; + done(); + + }); + it('Should fail when a new property is added and not reflected in the test', function () { const m = new Module('test-service-name'); diff --git a/test/orchestrator.spec.js b/test/orchestrator.spec.js index a10d66a..e08cbb5 100644 --- a/test/orchestrator.spec.js +++ b/test/orchestrator.spec.js @@ -20,7 +20,7 @@ let o; describe('Orchestrator', function () { const registerMock = function () { - mock({ + return mock({ registerQueue: o.registerQueue }).register(); }; @@ -385,5 +385,21 @@ describe('Orchestrator', function () { }); }); + it('Should always only have 1 persistence module', function () { + registerMock(); + return o.listen() + .then(() => { + chai.expect(o.modulesCollection.find({ type: 'persistence' })) + .to.have.lengthOf(1); + return registerMock() + .then((newModule) => { + const registeredModules = o.modulesCollection.find({ type: 'persistence' }); + + chai.expect(registeredModules).to.have.lengthOf(1); + chai.expect(registeredModules[0].name).to.be.equal(newModule.name); + }); + }); + }); + }) ;