Commit 9fc408be authored by joel Grenon's avatar joel Grenon

Add capacity to stub seneca service in unit tests

parent 771d5e13
......@@ -306,7 +306,7 @@ CMBF.prototype.launch = P.method(function(pluginOpts) {
// Register security plugins (auth strategies)
.then(function() {
_this.log.debug("Configure security plugin strategies");
return _this.callHook('configure-security', {server:server, config:config}, function() {
return _this.callHook('configure-security', {server:server, config:config, pluginOptions: pluginOpts}, function() {
_this.log.debug("Configure Security: Loading 3 auth strategies: hapi-auth-bearer-token, hapi-auth-cookie, hapi-auth-basic");
var registerPlugin = P.promisify(server.register, server);
return P.join(
......
......@@ -3,6 +3,7 @@ var path = require('path');
var P = require('bluebird');
var fs = require('fs');
var _ = require('lodash');
var sinon = require('sinon');
// Register all test hooks before launching the test server
if(fs.existsSync(path.resolve('./test/test-server-hooks.js'))) {
......@@ -49,6 +50,15 @@ module.exports = cmbf.launch({testMode: true}).then(function() {
return require(path.resolve(modulePath))(ctx.server, ctx.config, ctx.log);
};
ctx.createServiceStub = function(fn) {
this._oldService = this.server.service;
this.server.decorate('server', 'service', sinon.stub(this.server, 'service', fn));
};
ctx.restoreService = function() {
this.server.decorate('server', 'service', this._oldService);
};
// Loop through all registered plugins and ask them to expose their test mode services
return P.map(_.values(cmbf.server.plugins), function(plugin) {
if(_.isFunction(plugin.setupTestMode)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment