Node.js based forum software built for the modern web
intersititial test
barisusakli2e47cf4db31e
diff --git a/src/controllers/index.js b/src/controllers/index.jsindex 1ec1696e21..59f5527ef4 100644--- a/src/controllers/index.js+++ b/src/controllers/index.js@@ -201,37 +201,35 @@ Controllers.registerInterstitial = function (req, res, next) {return res.redirect(nconf.get('relative_path') + '/register');}- plugins.fireHook('filter:register.interstitial', {- userData: req.session.registration,- interstitials: [],- }, function (err, data) {- if (err) {- return next(err);- }-- if (!data.interstitials.length) {- // No interstitials, redirect to home- delete req.session.registration;- return res.redirect('/');- }-- var renders = data.interstitials.map(function (interstitial) {- return async.apply(req.app.render.bind(req.app), interstitial.template, interstitial.data || {});- });- var errors = req.flash('error');-- async.parallel(renders, function (err, sections) {- if (err) {- return next(err);+ async.waterfall([+ function (next) {+ plugins.fireHook('filter:register.interstitial', {+ userData: req.session.registration,+ interstitials: [],+ }, next);+ },+ function (data, next) {+ if (!data.interstitials.length) {+ // No interstitials, redirect to home+ delete req.session.registration;+ return res.redirect('/');}+ var renders = data.interstitials.map(function (interstitial) {+ return async.apply(req.app.render.bind(req.app), interstitial.template, interstitial.data || {});+ });++ async.parallel(renders, next);+ },+ function (sections) {+ var errors = req.flash('error');res.render('registerComplete', {title: '[[pages:registration-complete]]',errors: errors,sections: sections,});- });- });+ },+ ], next);};Controllers.compose = function (req, res, next) {diff --git a/src/plugins/hooks.js b/src/plugins/hooks.jsindex 208eaae1b8..12303555fc 100644--- a/src/plugins/hooks.js+++ b/src/plugins/hooks.js@@ -75,6 +75,13 @@ module.exports = function (Plugins) {}};+ Plugins.unregisterHook = function (id, hook, method) {+ var hooks = Plugins.loadedHooks[hook] || [];+ Plugins.loadedHooks[hook] = hooks.filter(function (hookData) {+ return hookData && hookData.id !== id && hookData.method !== method;+ });+ };+Plugins.fireHook = function (hook, params, callback) {callback = typeof callback === 'function' ? callback : function () {};diff --git a/test/controllers.js b/test/controllers.jsindex c456d3fd69..d79235d16f 100644--- a/test/controllers.js+++ b/test/controllers.js@@ -136,6 +136,59 @@ describe('Controllers', function () {});});+ it('should load /register/complete', function (done) {+ var plugins = require('../src/plugins');+ function hookMethod(data, next) {+ data.interstitials.push({ template: 'topic.tpl', data: {} });+ next(null, data);+ }++ plugins.registerHook('myTestPlugin', {+ hook: 'filter:register.interstitial',+ method: hookMethod,+ });++ var data = {+ username: 'interstitial',+ password: '123456',+ email: '[email protected]',+ };++ var jar = request.jar();+ request({+ url: nconf.get('url') + '/api/config',+ json: true,+ jar: jar,+ }, function (err, response, body) {+ assert.ifError(err);++ request.post(nconf.get('url') + '/register', {+ form: data,+ json: true,+ jar: jar,+ headers: {+ 'x-csrf-token': body.csrf_token,+ },+ }, function (err, res, body) {+ assert.ifError(err);+ assert.equal(res.statusCode, 200);+ assert.equal(body.referrer, nconf.get('relative_path') + '/register/complete');+ request(nconf.get('url') + '/api/register/complete', {+ jar: jar,+ json: true,+ }, function (err, res, body) {+ assert.ifError(err);+ assert.equal(res.statusCode, 200);+ assert(body.sections);+ assert(body.errors);+ assert(body.title);+ plugins.unregisterHook('myTestPlugin', 'filter:register.interstitial', hookMethod);+ done();+ });+ });+ });+ });+it('should load /robots.txt', function (done) {request(nconf.get('url') + '/robots.txt', function (err, res, body) {assert.ifError(err);@@ -471,7 +524,7 @@ describe('Controllers', function () {hidden: 1,}, function (err) {assert.ifError(err);- request(nconf.get('url') + '/groups/hidden-group/members', function (err, res, body) {+ request(nconf.get('url') + '/groups/hidden-group/members', function (err, res) {assert.ifError(err);assert.equal(res.statusCode, 404);done();@@ -531,7 +584,7 @@ describe('Controllers', function () {headers: {'x-csrf-token': csrf_token,},- }, function (err, res, body) {+ }, function (err, res) {assert.ifError(err);assert.equal(res.statusCode, 404);done();@@ -689,7 +742,7 @@ describe('Controllers', function () {});it('should return 503 in maintenance mode', function (done) {- request(nconf.get('url') + '/recent', { json: true }, function (err, res, body) {+ request(nconf.get('url') + '/recent', { json: true }, function (err, res) {assert.ifError(err);assert.equal(res.statusCode, 503);done();