From d96674da64308f1265b99036cac90905029f8a24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 23 Nov 2017 19:13:43 -0500 Subject: [PATCH] add test for composer fix --- src/controllers/composer.js | 10 +++++----- test/controllers.js | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/controllers/composer.js b/src/controllers/composer.js index 3bc95fae4a..7bd61a5bb2 100644 --- a/src/controllers/composer.js +++ b/src/controllers/composer.js @@ -8,15 +8,15 @@ var plugins = require('../plugins'); var topics = require('../topics'); var helpers = require('./helpers'); -exports.get = function (req, res, next) { +exports.get = function (req, res, callback) { async.waterfall([ - function (_next) { + function (next) { plugins.fireHook('filter:composer.build', { req: req, res: res, - next: next, + next: callback, templateData: {}, - }, _next); + }, next); }, function (data) { if (data.templateData.disabled) { @@ -28,7 +28,7 @@ exports.get = function (req, res, next) { res.render('compose', data.templateData); } }, - ], next); + ], callback); }; exports.post = function (req, res) { diff --git a/test/controllers.js b/test/controllers.js index 213472d548..6293f60e2f 100644 --- a/test/controllers.js +++ b/test/controllers.js @@ -2036,6 +2036,27 @@ describe('Controllers', function () { }); }); + it('should 404 if plugin calls next', function (done) { + function hookMethod(hookData, callback) { + hookData.next(); + } + + plugins.registerHook('myTestPlugin', { + hook: 'filter:composer.build', + method: hookMethod, + }); + + request(nconf.get('url') + '/api/compose', { json: true }, function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 404); + console.log(body); + + plugins.unregisterHook('myTestPlugin', 'filter:composer.build', hookMethod); + done(); + }); + }); + + it('should error with invalid data', function (done) { request.post(nconf.get('url') + '/compose', { form: {