controller tests

v1.18.x
barisusakli 8 years ago
parent c512a02c83
commit 9131f9d8f6

@ -81,7 +81,7 @@ Controllers.reset = function (req, res, next) {
res.render('reset_code', {
valid: valid,
displayExpiryNotice: req.session.passwordExpired,
code: req.params.code ? req.params.code : null,
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]]'
@ -91,12 +91,11 @@ Controllers.reset = function (req, res, next) {
});
} else {
res.render('reset', {
code: req.params.code ? req.params.code : null,
code: null,
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[reset_password:reset_password]]'}]),
title: '[[pages:reset]]'
});
}
};
Controllers.login = function (req, res, next) {
@ -275,12 +274,12 @@ Controllers.robots = function (req, res) {
Controllers.manifest = function (req, res) {
var manifest = {
name: meta.config.title || 'NodeBB',
start_url: nconf.get('relative_path') + '/',
display: 'standalone',
orientation: 'portrait',
icons: []
};
name: meta.config.title || 'NodeBB',
start_url: nconf.get('relative_path') + '/',
display: 'standalone',
orientation: 'portrait',
icons: []
};
if (meta.config['brand:touchIcon']) {
manifest.icons.push({

@ -0,0 +1,198 @@
'use strict';
/*global require, before, after*/
var async = require('async');
var assert = require('assert');
var nconf = require('nconf');
var request = require('request');
var db = require('./mocks/databasemock');
var categories = require('../src/categories');
var meta = require('../src/meta');
describe('Controllers', function () {
before(function (done) {
categories.create({
name: 'Test Category',
description: 'Test category created by testing script'
}, function (err) {
done(err);
});
});
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();
});
});
it('should load unread as home route', function (done) {
meta.config.homePageRoute = 'unread';
request(nconf.get('url'), function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load recent as home route', function (done) {
meta.config.homePageRoute = 'recent';
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.config.homePageRoute = 'popular';
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.config.homePageRoute = 'category/1/test-category';
request(nconf.get('url'), function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /reset without code', function (done) {
request(nconf.get('url') + '/reset', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /reset with invalid code', function (done) {
request(nconf.get('url') + '/reset/123123', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /login', function (done) {
request(nconf.get('url') + '/login', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /register', function (done) {
request(nconf.get('url') + '/register', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /robots.txt', function (done) {
request(nconf.get('url') + '/robots.txt', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /manifest.json', function (done) {
request(nconf.get('url') + '/manifest.json', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /outgoing?url=<url>', function (done) {
request(nconf.get('url') + '/outgoing?url=http//youtube.com', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should 404 on /outgoing with no url', function (done) {
request(nconf.get('url') + '/outgoing', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 404);
assert(body);
done();
});
});
it('should load /tos', function (done) {
meta.config.termsOfUse = 'please accept our tos';
request(nconf.get('url') + '/tos', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load 404 if meta.config.termsOfUse is empty', function (done) {
meta.config.termsOfUse = '';
request(nconf.get('url') + '/tos', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 404);
assert(body);
done();
});
});
it('should load /sping', function (done) {
request(nconf.get('url') + '/sping', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.equal(body, 'healthy');
done();
});
});
it('should load /ping', function (done) {
request(nconf.get('url') + '/ping', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.equal(body, '200');
done();
});
});
it('should handle 404', function (done) {
request(nconf.get('url') + '/arouteinthevoid', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 404);
assert(body);
done();
});
});
after(function (done) {
db.emptydb(done);
});
});
Loading…
Cancel
Save