|
|
|
@ -4,6 +4,8 @@ var async = require('async');
|
|
|
|
|
var assert = require('assert');
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
var request = require('request');
|
|
|
|
|
var fs = require('fs');
|
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
|
|
var db = require('./mocks/databasemock');
|
|
|
|
|
var categories = require('../src/categories');
|
|
|
|
@ -15,6 +17,7 @@ var meta = require('../src/meta');
|
|
|
|
|
var translator = require('../src/translator');
|
|
|
|
|
var privileges = require('../src/privileges');
|
|
|
|
|
var plugins = require('../src/plugins');
|
|
|
|
|
var utils = require('../src/utils');
|
|
|
|
|
var helpers = require('./helpers');
|
|
|
|
|
|
|
|
|
|
describe('Controllers', function () {
|
|
|
|
@ -58,20 +61,29 @@ describe('Controllers', function () {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('homepage', function () {
|
|
|
|
|
function hookMethod(hookData) {
|
|
|
|
|
assert(hookData.req);
|
|
|
|
|
assert(hookData.res);
|
|
|
|
|
assert(hookData.next);
|
|
|
|
|
|
|
|
|
|
it('should load default home route', function (done) {
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert(body);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
hookData.res.render('custom', {
|
|
|
|
|
works: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
var message = utils.generateUUID();
|
|
|
|
|
var tplPath = path.join(nconf.get('views_dir'), 'custom.tpl');
|
|
|
|
|
|
|
|
|
|
it('should load unread as home route', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'unread', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
before(function () {
|
|
|
|
|
plugins.registerHook('myTestPlugin', {
|
|
|
|
|
hook: 'action:homepage.get:custom',
|
|
|
|
|
method: hookMethod,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(tplPath, message);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should load default', function (done) {
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
@ -79,105 +91,131 @@ describe('Controllers', function () {
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should load recent as home route', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'recent', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
it('should load unread', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'unread', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert(body);
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert(body);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should load popular as home route', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'popular', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
it('should load recent', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'recent', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert(body);
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert(body);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should load category as home route', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'category/1/test-category', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
it('should load popular', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'popular', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert(body);
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert(body);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should load not load breadcrumbs on home page route', function (done) {
|
|
|
|
|
request(nconf.get('url') + '/api', { json: true }, function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert(body);
|
|
|
|
|
assert(!body.breadcrumbs);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it('should load category', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'category/1/test-category', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
|
|
it('should redirect to custom homepage', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'groups', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert(body);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
it('should not load breadcrumbs on home page route', function (done) {
|
|
|
|
|
request(nconf.get('url') + '/api', { json: true }, function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert(body);
|
|
|
|
|
assert(!body.breadcrumbs);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should 404 if custom homepage does not exist', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'this-route-does-not-exist', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
it('should redirect to custom', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'groups', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert(body);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should 404 if custom does not exist', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'this-route-does-not-exist', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 404);
|
|
|
|
|
assert(body);
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 404);
|
|
|
|
|
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,
|
|
|
|
|
it('api should work with hook', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'custom', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
|
|
request(nconf.get('url') + '/api', { json: true }, function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert.equal(body.works, true);
|
|
|
|
|
assert.equal(body.template.custom, true);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
meta.configs.set('homePageRoute', 'custom', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
it('should render with hook', function (done) {
|
|
|
|
|
meta.configs.set('homePageRoute', 'custom', function (err) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert.equal(body, '"works"');
|
|
|
|
|
plugins.unregisterHook('myTestPlugin', 'action:homepage.get:custom', hookMethod);
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
|
|
request(nconf.get('url'), function (err, res, body) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
assert.ok(body);
|
|
|
|
|
assert.ok(body.indexOf('<main id="panel"'));
|
|
|
|
|
assert.ok(body.indexOf(message) !== -1);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
|
plugins.unregisterHook('myTestPlugin', 'action:homepage.get:custom', hookMethod);
|
|
|
|
|
fs.unlinkSync(tplPath);
|
|
|
|
|
fs.unlinkSync(tplPath.replace(/\.tpl$/, '.js'));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should load /reset without code', function (done) {
|
|
|
|
|