mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 10:35:55 +01:00
intersititial test
This commit is contained in:
@@ -201,37 +201,35 @@ Controllers.registerInterstitial = function (req, res, next) {
|
|||||||
return res.redirect(nconf.get('relative_path') + '/register');
|
return res.redirect(nconf.get('relative_path') + '/register');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
plugins.fireHook('filter:register.interstitial', {
|
plugins.fireHook('filter:register.interstitial', {
|
||||||
userData: req.session.registration,
|
userData: req.session.registration,
|
||||||
interstitials: [],
|
interstitials: [],
|
||||||
}, function (err, data) {
|
}, next);
|
||||||
if (err) {
|
},
|
||||||
return next(err);
|
function (data, next) {
|
||||||
}
|
|
||||||
|
|
||||||
if (!data.interstitials.length) {
|
if (!data.interstitials.length) {
|
||||||
// No interstitials, redirect to home
|
// No interstitials, redirect to home
|
||||||
delete req.session.registration;
|
delete req.session.registration;
|
||||||
return res.redirect('/');
|
return res.redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
var renders = data.interstitials.map(function (interstitial) {
|
var renders = data.interstitials.map(function (interstitial) {
|
||||||
return async.apply(req.app.render.bind(req.app), interstitial.template, interstitial.data || {});
|
return async.apply(req.app.render.bind(req.app), interstitial.template, interstitial.data || {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
async.parallel(renders, next);
|
||||||
|
},
|
||||||
|
function (sections) {
|
||||||
var errors = req.flash('error');
|
var errors = req.flash('error');
|
||||||
|
|
||||||
async.parallel(renders, function (err, sections) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
res.render('registerComplete', {
|
res.render('registerComplete', {
|
||||||
title: '[[pages:registration-complete]]',
|
title: '[[pages:registration-complete]]',
|
||||||
errors: errors,
|
errors: errors,
|
||||||
sections: sections,
|
sections: sections,
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
});
|
], next);
|
||||||
};
|
};
|
||||||
|
|
||||||
Controllers.compose = function (req, res, next) {
|
Controllers.compose = function (req, res, next) {
|
||||||
|
|||||||
@@ -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) {
|
Plugins.fireHook = function (hook, params, callback) {
|
||||||
callback = typeof callback === 'function' ? callback : function () {};
|
callback = typeof callback === 'function' ? callback : function () {};
|
||||||
|
|
||||||
|
|||||||
@@ -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: 'test@me.com',
|
||||||
|
};
|
||||||
|
|
||||||
|
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) {
|
it('should load /robots.txt', function (done) {
|
||||||
request(nconf.get('url') + '/robots.txt', function (err, res, body) {
|
request(nconf.get('url') + '/robots.txt', function (err, res, body) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
@@ -471,7 +524,7 @@ describe('Controllers', function () {
|
|||||||
hidden: 1,
|
hidden: 1,
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
assert.ifError(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.ifError(err);
|
||||||
assert.equal(res.statusCode, 404);
|
assert.equal(res.statusCode, 404);
|
||||||
done();
|
done();
|
||||||
@@ -531,7 +584,7 @@ describe('Controllers', function () {
|
|||||||
headers: {
|
headers: {
|
||||||
'x-csrf-token': csrf_token,
|
'x-csrf-token': csrf_token,
|
||||||
},
|
},
|
||||||
}, function (err, res, body) {
|
}, function (err, res) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(res.statusCode, 404);
|
assert.equal(res.statusCode, 404);
|
||||||
done();
|
done();
|
||||||
@@ -689,7 +742,7 @@ describe('Controllers', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return 503 in maintenance mode', function (done) {
|
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.ifError(err);
|
||||||
assert.equal(res.statusCode, 503);
|
assert.equal(res.statusCode, 503);
|
||||||
done();
|
done();
|
||||||
|
|||||||
Reference in New Issue
Block a user