mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-26 08:31:22 +01:00
some more tests
This commit is contained in:
@@ -38,72 +38,75 @@ Controllers.errors = require('./errors');
|
||||
Controllers.home = function (req, res, next) {
|
||||
var route = meta.config.homePageRoute || (meta.config.homePageCustom || '').replace(/^\/+/, '') || 'categories';
|
||||
|
||||
user.getSettings(req.uid, function (err, settings) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (parseInt(meta.config.allowUserHomePage, 10) === 1 && settings.homePageRoute !== 'undefined' && settings.homePageRoute !== 'none') {
|
||||
route = settings.homePageRoute || route;
|
||||
}
|
||||
|
||||
var hook = 'action:homepage.get:' + route;
|
||||
|
||||
if (plugins.hasListeners(hook)) {
|
||||
return plugins.fireHook(hook, {
|
||||
req: req,
|
||||
res: res,
|
||||
next: next,
|
||||
});
|
||||
}
|
||||
|
||||
if (route === 'categories' || route === '/') {
|
||||
Controllers.categories.list(req, res, next);
|
||||
} else if (route === 'unread') {
|
||||
Controllers.unread.get(req, res, next);
|
||||
} else if (route === 'recent') {
|
||||
Controllers.recent.get(req, res, next);
|
||||
} else if (route === 'popular') {
|
||||
Controllers.popular.get(req, res, next);
|
||||
} else {
|
||||
var match = /^category\/(\d+)\/(.*)$/.exec(route);
|
||||
|
||||
if (match) {
|
||||
req.params.topic_index = '1';
|
||||
req.params.category_id = match[1];
|
||||
req.params.slug = match[2];
|
||||
Controllers.category.get(req, res, next);
|
||||
} else {
|
||||
res.redirect(route);
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
user.getSettings(req.uid, next);
|
||||
},
|
||||
function (settings, next) {
|
||||
if (parseInt(meta.config.allowUserHomePage, 10) === 1 && settings.homePageRoute !== 'undefined' && settings.homePageRoute !== 'none') {
|
||||
route = settings.homePageRoute || route;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var hook = 'action:homepage.get:' + route;
|
||||
|
||||
if (plugins.hasListeners(hook)) {
|
||||
return plugins.fireHook(hook, {
|
||||
req: req,
|
||||
res: res,
|
||||
next: next,
|
||||
});
|
||||
}
|
||||
|
||||
if (route === 'categories' || route === '/') {
|
||||
Controllers.categories.list(req, res, next);
|
||||
} else if (route === 'unread') {
|
||||
Controllers.unread.get(req, res, next);
|
||||
} else if (route === 'recent') {
|
||||
Controllers.recent.get(req, res, next);
|
||||
} else if (route === 'popular') {
|
||||
Controllers.popular.get(req, res, next);
|
||||
} else {
|
||||
var match = /^category\/(\d+)\/(.*)$/.exec(route);
|
||||
|
||||
if (match) {
|
||||
req.params.topic_index = '1';
|
||||
req.params.category_id = match[1];
|
||||
req.params.slug = match[2];
|
||||
Controllers.category.get(req, res, next);
|
||||
} else {
|
||||
helpers.redirect(res, route);
|
||||
}
|
||||
}
|
||||
},
|
||||
], next);
|
||||
};
|
||||
|
||||
Controllers.reset = function (req, res, next) {
|
||||
if (req.params.code) {
|
||||
user.reset.validate(req.params.code, function (err, valid) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.render('reset_code', {
|
||||
valid: valid,
|
||||
displayExpiryNotice: req.session.passwordExpired,
|
||||
code: req.params.code,
|
||||
minimumPasswordLength: parseInt(meta.config.minimumPasswordLength, 10),
|
||||
breadcrumbs: helpers.buildBreadcrumbs([
|
||||
{
|
||||
text: '[[reset_password:reset_password]]',
|
||||
url: '/reset',
|
||||
},
|
||||
{
|
||||
text: '[[reset_password:update_password]]',
|
||||
},
|
||||
]),
|
||||
title: '[[pages:reset]]',
|
||||
});
|
||||
|
||||
delete req.session.passwordExpired;
|
||||
});
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
user.reset.validate(req.params.code, next);
|
||||
},
|
||||
function (valid) {
|
||||
res.render('reset_code', {
|
||||
valid: valid,
|
||||
displayExpiryNotice: req.session.passwordExpired,
|
||||
code: req.params.code,
|
||||
minimumPasswordLength: parseInt(meta.config.minimumPasswordLength, 10),
|
||||
breadcrumbs: helpers.buildBreadcrumbs([
|
||||
{
|
||||
text: '[[reset_password:reset_password]]',
|
||||
url: '/reset',
|
||||
},
|
||||
{
|
||||
text: '[[reset_password:update_password]]',
|
||||
},
|
||||
]),
|
||||
title: '[[pages:reset]]',
|
||||
});
|
||||
delete req.session.passwordExpired;
|
||||
},
|
||||
], next);
|
||||
} else {
|
||||
res.render('reset', {
|
||||
code: null,
|
||||
|
||||
@@ -14,6 +14,7 @@ var groups = require('../src/groups');
|
||||
var meta = require('../src/meta');
|
||||
var translator = require('../src/translator');
|
||||
var privileges = require('../src/privileges');
|
||||
var plugins = require('../src/plugins');
|
||||
var helpers = require('./helpers');
|
||||
|
||||
describe('Controllers', function () {
|
||||
@@ -107,6 +108,37 @@ describe('Controllers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should redirect to custom homepage', function (done) {
|
||||
meta.config.homePageRoute = 'groups';
|
||||
request(nconf.get('url'), function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(body);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should render custom homepage with hook', function (done) {
|
||||
function hookMethod(hookData) {
|
||||
assert(hookData.req);
|
||||
assert(hookData.res);
|
||||
assert(hookData.next);
|
||||
hookData.res.json('works');
|
||||
}
|
||||
plugins.registerHook('myTestPlugin', {
|
||||
hook: 'action:homepage.get:custom',
|
||||
method: hookMethod,
|
||||
});
|
||||
meta.config.homePageRoute = 'custom';
|
||||
request(nconf.get('url'), function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.equal(body, '"works"');
|
||||
plugins.unregisterHook('myTestPlugin', 'action:homepage.get:custom', hookMethod);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load /reset without code', function (done) {
|
||||
request(nconf.get('url') + '/reset', function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
@@ -144,7 +176,6 @@ 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);
|
||||
|
||||
Reference in New Issue
Block a user