admin controller tests

v1.18.x
barisusakli 8 years ago
parent 9db50a3eda
commit 7a8de6169b

@ -1,12 +1,12 @@
"use strict";
var async = require('async'),
var async = require('async');
db = require('../../database'),
groups = require('../../groups'),
meta = require('../../meta'),
pagination = require('../../pagination'),
helpers = require('../helpers');
var db = require('../../database');
var groups = require('../../groups');
var meta = require('../../meta');
var pagination = require('../../pagination');
var helpers = require('../helpers');
var groupsController = {};

@ -1,8 +1,10 @@
'use strict';
var settingsController = {};
var async = require('async'),
meta = require('../../meta');
var async = require('async');
var meta = require('../../meta');
var settingsController = module.exports;
settingsController.get = function (req, res, next) {
var term = req.params.term ? req.params.term : 'general';
@ -24,41 +26,41 @@ function renderEmail(req, res, next) {
var utils = require('../../../public/src/utils');
var emailsPath = path.join(__dirname, '../../../public/templates/emails');
utils.walk(emailsPath, function (err, emails) {
if (err) {
return next(err);
}
async.map(emails, function (email, next) {
var path = email.replace(emailsPath, '').substr(1).replace('.tpl', '');
async.waterfall([
function (next) {
utils.walk(emailsPath, next);
},
function (emails, next) {
async.map(emails, function (email, next) {
var path = email.replace(emailsPath, '').substr(1).replace('.tpl', '');
fs.readFile(email, function (err, original) {
if (err) {
return next(err);
}
fs.readFile(email, function (err, original) {
if (err) {
return next(err);
}
var text = meta.config['email:custom:' + path] ? meta.config['email:custom:' + path] : original.toString();
var text = meta.config['email:custom:' + path] ? meta.config['email:custom:' + path] : original.toString();
next(null, {
path: path,
fullpath: email,
text: text,
original: original.toString()
next(null, {
path: path,
fullpath: email,
text: text,
original: original.toString()
});
});
});
}, function (err, emails) {
if (err) {
return next(err);
}
}, next);
}
], function (err, emails) {
if (err) {
return next(err);
}
res.render('admin/settings/email', {
emails: emails,
sendable: emails.filter(function (email) {
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1;
})
});
res.render('admin/settings/email', {
emails: emails,
sendable: emails.filter(function (email) {
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1;
})
});
});
}
module.exports = settingsController;

@ -0,0 +1,121 @@
'use strict';
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 topics = require('../src/topics');
var user = require('../src/user');
var groups = require('../src/groups');
var helpers = require('./helpers');
describe('Admin Controllers', function () {
var tid;
var cid;
var pid;
var adminUid;
var jar;
before(function (done) {
async.series({
category: function (next) {
categories.create({
name: 'Test Category',
description: 'Test category created by testing script'
}, next);
},
user: function (next) {
async.waterfall([
function (next) {
user.create({username: 'admin', password: 'barbar'}, next);
},
function (_uid, next) {
adminUid = _uid;
next();
}
], next);
}
}, function (err, results) {
if (err) {
return done(err);
}
cid = results.category.cid;
topics.post({uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid}, function (err, result) {
tid = result.topicData.tid;
pid = result.postData.pid;
done(err);
});
});
});
it('should 403 if user is not admin', function (done) {
helpers.loginUser('admin', 'barbar', function (err, _jar) {
assert.ifError(err);
jar = _jar;
request(nconf.get('url') + '/admin', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 403);
assert(body);
done();
});
});
});
it('should load admin dashboard', function (done) {
groups.join('administrators', adminUid, function (err) {
assert.ifError(err);
request(nconf.get('url') + '/admin', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
});
it('should load groups page', function (done) {
request(nconf.get('url') + '/admin/manage/groups', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load groups detail page', function (done) {
request(nconf.get('url') + '/admin/manage/groups/administrators', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load general settings page', function (done) {
request(nconf.get('url') + '/admin/settings', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load email settings page', function (done) {
request(nconf.get('url') + '/admin/settings/email', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
after(function (done) {
db.emptydb(done);
});
});
Loading…
Cancel
Save