Merge branch 'master' of github.com:nodebb/nodebb

v1.18.x
Peter Jaszkowiak 8 years ago
commit 5223bb5191

@ -35,7 +35,6 @@ module.exports = function (grunt) {
incomplete.push(compiling); incomplete.push(compiling);
} }
// @psychobunny, re: #5211, instead of this, just call `node app --build js` or `node app --build css,tpl`
updateArgs.push('--build'); updateArgs.push('--build');
updateArgs.push(incomplete.join(',')); updateArgs.push(incomplete.join(','));

@ -39,47 +39,58 @@ exports.build = function build(targets, callback) {
exports.buildTargets = function (targets, callback) { exports.buildTargets = function (targets, callback) {
var meta = require('./src/meta'); var meta = require('./src/meta');
buildStart = buildStart || Date.now(); buildStart = buildStart || Date.now();
var startTime;
var step = function (target, next) { var step = function (startTime, target, next) {
winston.info('[build] => Completed in ' + ((Date.now() - startTime) / 1000) + 's'); winston.info('[build] ' + target + ' => Completed in ' + ((Date.now() - startTime) / 1000) + 's');
next(); next();
}; };
// eachSeries because it potentially(tm) runs faster on Windows this way
async.eachSeries(targets, function (target, next) { async.parallel([
switch(target) { function (next) {
case 'js': if (targets.indexOf('js') !== -1) {
winston.info('[build] Building javascript'); winston.info('[build] Building javascript');
startTime = Date.now(); var startTime = Date.now();
async.series([ async.series([
async.apply(meta.js.minify, 'nodebb.min.js'), async.apply(meta.js.minify, 'nodebb.min.js'),
async.apply(meta.js.minify, 'acp.min.js') async.apply(meta.js.minify, 'acp.min.js')
], step.bind(this, target, next)); ], step.bind(this, startTime, 'js', next));
break; } else {
case 'clientCSS':
winston.info('[build] Building client-side CSS');
startTime = Date.now();
meta.css.minify('stylesheet.css', step.bind(this, target, next));
break;
case 'acpCSS':
winston.info('[build] Building admin control panel CSS');
startTime = Date.now();
meta.css.minify('admin.css', step.bind(this, target, next));
break;
case 'tpl':
winston.info('[build] Building templates');
startTime = Date.now();
meta.templates.compile(step.bind(this, target, next));
break;
default:
winston.warn('[build] Unknown build target: \'' + target + '\'');
setImmediate(next); setImmediate(next);
break; }
},
function (next) {
async.eachSeries(targets, function (target, next) {
var startTime;
switch(target) {
case 'js':
setImmediate(next);
break;
case 'clientCSS':
winston.info('[build] Building client-side CSS');
startTime = Date.now();
meta.css.minify('stylesheet.css', step.bind(this, startTime, target, next));
break;
case 'acpCSS':
winston.info('[build] Building admin control panel CSS');
startTime = Date.now();
meta.css.minify('admin.css', step.bind(this, startTime, target, next));
break;
case 'tpl':
winston.info('[build] Building templates');
startTime = Date.now();
meta.templates.compile(step.bind(this, startTime, target, next));
break;
default:
winston.warn('[build] Unknown build target: \'' + target + '\'');
setImmediate(next);
break;
}
}, next);
} }
}, function (err) { ], function (err) {
if (err) { if (err) {
winston.error('[build] Encountered error during build step: ' + err.message); winston.error('[build] Encountered error during build step: ' + err.message);
return process.exit(1); return process.exit(1);

@ -82,9 +82,9 @@
"semver": "^5.1.0", "semver": "^5.1.0",
"serve-favicon": "^2.1.5", "serve-favicon": "^2.1.5",
"sitemap": "^1.4.0", "sitemap": "^1.4.0",
"socket.io": "^1.4.8", "socket.io": "1.7.1",
"socket.io-client": "^1.4.0", "socket.io-client": "1.7.1",
"socket.io-redis": "1.1.1", "socket.io-redis": "2.0.0",
"socketio-wildcard": "~0.3.0", "socketio-wildcard": "~0.3.0",
"string": "^3.0.0", "string": "^3.0.0",
"templates.js": "0.3.4", "templates.js": "0.3.4",

@ -258,7 +258,7 @@ define('chat', [
Chats.addScrollHandler(chatModal.attr('roomId'), data.uid, chatModal.find('.chat-content')); Chats.addScrollHandler(chatModal.attr('roomId'), data.uid, chatModal.find('.chat-content'));
taskbar.push('chat', chatModal.attr('UUID'), { taskbar.push('chat', chatModal.attr('UUID'), {
title: data.users.length ? data.users[0].username : '', title: data.roomName || (data.users.length ? data.users[0].username : ''),
roomId: data.roomId, roomId: data.roomId,
icon: 'fa-comment', icon: 'fa-comment',
state: '' state: ''

@ -150,7 +150,12 @@ if ('undefined' !== typeof window) {
overrides.overrideTimeago = function () { overrides.overrideTimeago = function () {
var timeagoFn = $.fn.timeago; var timeagoFn = $.fn.timeago;
$.timeago.settings.cutoff = 1000 * 60 * 60 * 24 * (parseInt(config.timeagoCutoff, 10) || 60); if (parseInt(config.timeagoCutoff, 10) === 0) {
$.timeago.settings.cutoff = 1;
} else if (parseInt(config.timeagoCutoff, 10) > 0) {
$.timeago.settings.cutoff = 1000 * 60 * 60 * 24 * (parseInt(config.timeagoCutoff, 10) || 30);
}
$.fn.timeago = function () { $.fn.timeago = function () {
var els = $(this); var els = $(this);

@ -97,56 +97,63 @@ postsController.getTopics = function (req, res, next) {
getFromUserSet(data, req, res, next); getFromUserSet(data, req, res, next);
}; };
function getFromUserSet(data, req, res, next) { function getFromUserSet(data, req, res, callback) {
async.parallel({ var userData;
settings: function (next) { var itemsPerPage;
user.getSettings(req.uid, next); var page = Math.max(1, parseInt(req.query.page, 10) || 1);
async.waterfall([
function (next) {
async.parallel({
settings: function (next) {
user.getSettings(req.uid, next);
},
userData: function (next) {
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
}
}, next);
}, },
userData: function (next) { function (results, next) {
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next); if (!results.userData) {
} return callback();
}, function (err, results) { }
if (err || !results.userData) {
return next(err);
}
var userData = results.userData; userData = results.userData;
var setName = 'uid:' + userData.uid + ':' + data.set; var setName = 'uid:' + userData.uid + ':' + data.set;
var page = Math.max(1, parseInt(req.query.page, 10) || 1); itemsPerPage = (data.template === 'account/topics' || data.template === 'account/watched') ? results.settings.topicsPerPage : results.settings.postsPerPage;
var itemsPerPage = (data.template === 'account/topics' || data.template === 'account/watched') ? results.settings.topicsPerPage : results.settings.postsPerPage;
async.parallel({ async.parallel({
itemCount: function (next) { itemCount: function (next) {
if (results.settings.usePagination) { if (results.settings.usePagination) {
db.sortedSetCard(setName, next); db.sortedSetCard(setName, next);
} else { } else {
next(null, 0); next(null, 0);
}
},
data: function (next) {
var start = (page - 1) * itemsPerPage;
var stop = start + itemsPerPage - 1;
data.method(setName, req.uid, start, stop, next);
} }
}, }, next);
data: function (next) { }
var start = (page - 1) * itemsPerPage; ], function (err, results) {
var stop = start + itemsPerPage - 1; if (err) {
data.method(setName, req.uid, start, stop, next); return callback(err);
} }
}, function (err, results) {
if (err) {
return next(err);
}
userData[data.type] = results.data[data.type]; userData[data.type] = results.data[data.type];
userData.nextStart = results.data.nextStart; userData.nextStart = results.data.nextStart;
var pageCount = Math.ceil(results.itemCount / itemsPerPage); var pageCount = Math.ceil(results.itemCount / itemsPerPage);
userData.pagination = pagination.create(page, pageCount); userData.pagination = pagination.create(page, pageCount);
userData.noItemsFoundKey = data.noItemsFoundKey; userData.noItemsFoundKey = data.noItemsFoundKey;
userData.title = '[[pages:' + data.template + ', ' + userData.username + ']]'; userData.title = '[[pages:' + data.template + ', ' + userData.username + ']]';
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: data.crumb}]); userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: data.crumb}]);
res.render(data.template, userData); res.render(data.template, userData);
});
}); });
} }

@ -63,7 +63,9 @@ apiController.getConfig = function (req, res, next) {
config.csrf_token = req.csrfToken(); config.csrf_token = req.csrfToken();
config.searchEnabled = plugins.hasListeners('filter:search.query'); config.searchEnabled = plugins.hasListeners('filter:search.query');
config.bootswatchSkin = 'default'; config.bootswatchSkin = 'default';
config.timeagoCutoff = meta.config.timeagoCutoff;
var timeagoCutoff = meta.config.timeagoCutoff === undefined ? 30 : meta.config.timeagoCutoff;
config.timeagoCutoff = timeagoCutoff !== '' ? Math.max(0, parseInt(timeagoCutoff, 10)) : timeagoCutoff;
config.cookies = { config.cookies = {
enabled: parseInt(meta.config.cookieConsentEnabled, 10) === 1, enabled: parseInt(meta.config.cookieConsentEnabled, 10) === 1,

@ -92,7 +92,7 @@ module.exports = function (Groups) {
return callback(new Error('[[error:group-name-too-long]]')); return callback(new Error('[[error:group-name-too-long]]'));
} }
if (name.indexOf('/') !== -1) { if (name.indexOf('/') !== -1 || !utils.slugify(name)) {
return callback(new Error('[[error:invalid-group-name]]')); return callback(new Error('[[error:invalid-group-name]]'));
} }

@ -1,10 +1,10 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
var user = require('../user');
var db = require('./../database');
user = require('../user'),
db = require('./../database'),
groups = module.parent.exports;
module.exports = function (Groups) { module.exports = function (Groups) {
@ -17,7 +17,7 @@ module.exports = function (Groups) {
async.apply(db.getObjectValues, 'groupslug:groupname'), async.apply(db.getObjectValues, 'groupslug:groupname'),
function (groupNames, next) { function (groupNames, next) {
// Ephemeral groups and the registered-users groups are searchable // Ephemeral groups and the registered-users groups are searchable
groupNames = groups.getEphemeralGroups().concat(groupNames).concat('registered-users'); groupNames = Groups.getEphemeralGroups().concat(groupNames).concat('registered-users');
groupNames = groupNames.filter(function (name) { groupNames = groupNames.filter(function (name) {
return name.toLowerCase().indexOf(query) !== -1 && name !== 'administrators' && !Groups.isPrivilegeGroup(name); return name.toLowerCase().indexOf(query) !== -1 && name !== 'administrators' && !Groups.isPrivilegeGroup(name);
}); });
@ -66,10 +66,6 @@ module.exports = function (Groups) {
Groups.searchMembers = function (data, callback) { Groups.searchMembers = function (data, callback) {
function findUids(query, searchBy, callback) { function findUids(query, searchBy, callback) {
if (!query) {
return Groups.getMembers(data.groupName, 0, -1, callback);
}
query = query.toLowerCase(); query = query.toLowerCase();
async.waterfall([ async.waterfall([

@ -16,7 +16,7 @@ module.exports = function (Meta) {
scripts: { scripts: {
base: [ base: [
'./node_modules/jquery/dist/jquery.js', './node_modules/jquery/dist/jquery.js',
'./node_modules/socket.io-client/socket.io.js', './node_modules/socket.io-client/dist/socket.io.js',
'public/vendor/jquery/timeago/jquery.timeago.js', 'public/vendor/jquery/timeago/jquery.timeago.js',
'public/vendor/jquery/js/jquery.form.min.js', 'public/vendor/jquery/js/jquery.form.min.js',
'public/vendor/visibility/visibility.min.js', 'public/vendor/visibility/visibility.min.js',

@ -261,7 +261,7 @@ module.exports = function (Plugins) {
} }
var pathToFolder = path.join(__dirname, '../../node_modules/', pluginData.id, pluginData.languages); var pathToFolder = path.join(__dirname, '../../node_modules/', pluginData.id, pluginData.languages);
var defaultLang = pluginData.defaultLang.replace('_', '-').replace('@', '-x-'); var defaultLang = (pluginData.defaultLang || 'en_GB').replace('_', '-').replace('@', '-x-');
utils.walk(pathToFolder, function (err, languages) { utils.walk(pathToFolder, function (err, languages) {
if (err) { if (err) {
@ -346,9 +346,11 @@ module.exports = function (Plugins) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
var pluginData;
var packageData;
try { try {
var pluginData = JSON.parse(results.plugin); pluginData = JSON.parse(results.plugin);
var packageData = JSON.parse(results.package); packageData = JSON.parse(results.package);
pluginData.id = packageData.name; pluginData.id = packageData.name;
pluginData.name = packageData.name; pluginData.name = packageData.name;
@ -356,16 +358,15 @@ module.exports = function (Plugins) {
pluginData.version = packageData.version; pluginData.version = packageData.version;
pluginData.repository = packageData.repository; pluginData.repository = packageData.repository;
pluginData.nbbpm = packageData.nbbpm; pluginData.nbbpm = packageData.nbbpm;
callback(null, pluginData);
} catch(err) { } catch(err) {
var pluginDir = pluginPath.split(path.sep); var pluginDir = pluginPath.split(path.sep);
pluginDir = pluginDir[pluginDir.length - 1]; pluginDir = pluginDir[pluginDir.length - 1];
winston.error('[plugins/' + pluginDir + '] Error in plugin.json or package.json! ' + err.message); winston.error('[plugins/' + pluginDir + '] Error in plugin.json or package.json! ' + err.message);
callback(new Error('[[error:parse-error]]')); return callback(new Error('[[error:parse-error]]'));
} }
callback(null, pluginData);
}); });
}; };
}; };

@ -237,7 +237,7 @@ SocketGroups.search = function (socket, data, callback) {
return; return;
} }
groups.search(data.query, data.options || {}, callback); groups.search(data.query, data.options, callback);
}; };
SocketGroups.loadMore = function (socket, data, callback) { SocketGroups.loadMore = function (socket, data, callback) {

@ -46,7 +46,7 @@ SocketUser.deleteAccount = function (socket, data, callback) {
user.deleteAccount(socket.uid, next); user.deleteAccount(socket.uid, next);
}, },
function (next) { function (next) {
socket.broadcast.emit('event:user_status_change', {uid: socket.uid, status: 'offline'}); require('./index').server.sockets.emit('event:user_status_change', {uid: socket.uid, status: 'offline'});
events.log({ events.log({
type: 'user-delete', type: 'user-delete',

@ -1,9 +1,9 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
plugins = require('../plugins'), var plugins = require('../plugins');
db = require('../database'); var db = require('../database');
module.exports = function (User) { module.exports = function (User) {
@ -73,25 +73,22 @@ module.exports = function (User) {
if (!parseInt(uid, 10)) { if (!parseInt(uid, 10)) {
return callback(null, []); return callback(null, []);
} }
async.waterfall([
db.getSortedSetRevRange(type + ':' + uid, start, stop, function (err, uids) { function (next) {
if (err) { db.getSortedSetRevRange(type + ':' + uid, start, stop, next);
return callback(err); },
function (uids, next) {
plugins.fireHook('filter:user.' + type, {
uids: uids,
uid: uid,
start: start,
stop: stop
}, next);
},
function (data, next) {
User.getUsers(data.uids, uid, next);
} }
], callback);
plugins.fireHook('filter:user.' + type, {
uids: uids,
uid: uid,
start: start,
stop: stop
}, function (err, data) {
if (err) {
return callback(err);
}
User.getUsers(data.uids, uid, callback);
});
});
} }
User.isFollowing = function (uid, theirid, callback) { User.isFollowing = function (uid, theirid, callback) {

@ -90,11 +90,11 @@
<form> <form>
<div class="form-group"> <div class="form-group">
<label for="timeagoCutoff">Date cut-off (in days)</label> <label for="timeagoCutoff">Date cut-off (in days)</label>
<input type="number" class="form-control" id="timeagoCutoff" data-field="timeagoCutoff" placeholder="30" value="30" /> <input type="number" class="form-control" id="timeagoCutoff" data-field="timeagoCutoff" />
<p class="help-block"> <p class="help-block">
Dates &amp; times will be shown in a relative manner (e.g. "3 hours ago" / "5 days ago"), and localised into various Dates &amp; times will be shown in a relative manner (e.g. "3 hours ago" / "5 days ago"), and localised into various
languages. After a certain point, this text can be switched to display the localised date itself languages. After a certain point, this text can be switched to display the localised date itself
(e.g. 5 Nov 2016 15:30).<br /><em>(Default: <code>30</code>, or one month)</em> (e.g. 5 Nov 2016 15:30).<br /><em>(Default: <code>30</code>, or one month). Set to 0 to always display dates, leave blank to always display relative times.</em>
</p> </p>
</div> </div>
</form> </form>

@ -703,6 +703,132 @@ describe('Controllers', function () {
}); });
}); });
describe('account post pages', function () {
var helpers = require('./helpers');
var jar;
before(function (done) {
helpers.loginUser('foo', 'barbar', function (err, _jar) {
assert.ifError(err);
jar = _jar;
done();
});
});
it('should load /user/foo/posts', function (done) {
request(nconf.get('url') + '/api/user/foo/posts', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should 401 if not logged in', function (done) {
request(nconf.get('url') + '/api/user/foo/bookmarks', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 401);
assert(body);
done();
});
});
it('should load /user/foo/bookmarks', function (done) {
request(nconf.get('url') + '/api/user/foo/bookmarks', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /user/foo/upvoted', function (done) {
request(nconf.get('url') + '/api/user/foo/upvoted', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /user/foo/downvoted', function (done) {
request(nconf.get('url') + '/api/user/foo/downvoted', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /user/foo/best', function (done) {
request(nconf.get('url') + '/api/user/foo/best', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /user/foo/watched', function (done) {
request(nconf.get('url') + '/api/user/foo/watched', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /user/foo/topics', function (done) {
request(nconf.get('url') + '/api/user/foo/topics', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
});
describe('account follow page', function () {
var socketUser = require('../src/socket.io/user');
var uid;
before(function (done) {
user.create({username: 'follower'}, function (err, _uid) {
assert.ifError(err);
uid = _uid;
socketUser.follow({uid: uid}, {uid: fooUid}, done);
});
});
it('should get followers page', function (done) {
request(nconf.get('url') + '/api/user/foo/followers', {json: true}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.equal(body.users[0].username, 'follower');
done();
});
});
it('should get following page', function (done) {
request(nconf.get('url') + '/api/user/follower/following', {json: true}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.equal(body.users[0].username, 'foo');
done();
});
});
it('should return empty after unfollow', function (done ) {
socketUser.unfollow({uid: uid}, {uid: fooUid}, function (err) {
assert.ifError(err);
request(nconf.get('url') + '/api/user/foo/followers', {json: true}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.equal(body.users.length, 0);
done();
});
});
});
});
after(function (done) { after(function (done) {
var analytics = require('../src/analytics'); var analytics = require('../src/analytics');
analytics.writeData(function (err) { analytics.writeData(function (err) {

@ -93,14 +93,68 @@ describe('Groups', function () {
}); });
describe('.search()', function () { describe('.search()', function () {
var socketGroups = require('../src/socket.io/groups');
it('should return the groups when search query is empty', function (done) {
socketGroups.search({uid: adminUid}, {query: ''}, function (err, groups) {
assert.ifError(err);
assert.equal(3, groups.length);
done();
});
});
it('should return the "Test" group when searched for', function (done) { it('should return the "Test" group when searched for', function (done) {
Groups.search('test', {}, function (err, groups) { socketGroups.search({uid: adminUid}, {query: 'test'}, function (err, groups) {
assert.ifError(err); assert.ifError(err);
assert.equal(1, groups.length); assert.equal(1, groups.length);
assert.strictEqual('Test', groups[0].name); assert.strictEqual('Test', groups[0].name);
done(); done();
}); });
}); });
it('should return the "Test" group when searched for and sort by member count', function (done) {
Groups.search('test', {filterHidden: true, sort: 'count'}, function (err, groups) {
assert.ifError(err);
assert.equal(1, groups.length);
assert.strictEqual('Test', groups[0].name);
done();
});
});
it('should return the "Test" group when searched for and sort by creation time', function (done) {
Groups.search('test', {filterHidden: true, sort: 'date'}, function (err, groups) {
assert.ifError(err);
assert.equal(1, groups.length);
assert.strictEqual('Test', groups[0].name);
done();
});
});
it('should return all users if no query', function (done) {
User.create({
username: 'newuser',
email: 'newuser@b.com'
}, function (err, uid) {
assert.ifError(err);
Groups.join('Test', uid, function (err) {
assert.ifError(err);
socketGroups.searchMembers({uid: adminUid}, {groupName: 'Test', query: ''}, function (err, data) {
assert.ifError(err);
assert.equal(data.users.length, 2);
done();
});
});
});
});
it('should search group members', function (done) {
socketGroups.searchMembers({uid: adminUid}, {groupName: 'Test', query: 'test'}, function (err, data) {
assert.ifError(err);
assert.strictEqual('testuser', data.users[0].username);
done();
});
});
}); });
describe('.isMember()', function () { describe('.isMember()', function () {
@ -184,6 +238,20 @@ describe('Groups', function () {
done(); done();
}); });
}); });
it('should fail to create group if slug is empty', function (done) {
Groups.create({name: '>>>>'}, function (err) {
assert.equal(err.message, '[[error:invalid-group-name]]');
done();
});
});
it('should fail if group name is invalid', function (done) {
Groups.create({name: 'not/valid'}, function (err) {
assert.equal(err.message, '[[error:invalid-group-name]]');
done();
});
});
}); });
describe('.hide()', function () { describe('.hide()', function () {

@ -4,6 +4,7 @@
var assert = require('assert'); var assert = require('assert');
var path = require('path'); var path = require('path');
var nconf = require('nconf'); var nconf = require('nconf');
var request = require('request');
var db = require('./mocks/databasemock'); var db = require('./mocks/databasemock');
var plugins = require('../src/plugins'); var plugins = require('../src/plugins');
@ -149,6 +150,35 @@ describe('Plugins', function () {
}); });
}); });
describe('static assets', function () {
it('should 404 if resource does not exist', function (done) {
request.get(nconf.get('url') + '/plugins/doesnotexist/should404.tpl', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 404);
assert(body);
done();
});
});
it('should 404 if resource does not exist', function (done) {
request.get(nconf.get('url') + '/plugins/nodebb-plugin-dbsearch/dbsearch/templates/admin/plugins/should404.tpl', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 404);
assert(body);
done();
});
});
it('should get resource', function (done) {
request.get(nconf.get('url') + '/plugins/nodebb-plugin-dbsearch/dbsearch/templates/admin/plugins/dbsearch.tpl', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
});
}); });

@ -610,7 +610,55 @@ describe('User', function () {
}); });
}); });
}); });
});
describe('socket methods', function () {
var socketUser = require('../src/socket.io/user');
it('should fail with invalid data', function (done) {
socketUser.exists({uid: testUid}, null, function (err) {
assert.equal(err.message, '[[error:invalid-data]]');
done();
});
});
it('should return true if user/group exists', function (done) {
socketUser.exists({uid: testUid}, {username: 'registered-users'}, function (err, exists) {
assert.ifError(err);
assert(exists);
done();
});
});
it('should return true if user/group exists', function (done) {
socketUser.exists({uid: testUid}, {username: 'John Smith'}, function (err, exists) {
assert.ifError(err);
assert(exists);
done();
});
});
it('should return false if user/group does not exists', function (done) {
socketUser.exists({uid: testUid}, {username: 'doesnot exist'}, function (err, exists) {
assert.ifError(err);
assert(!exists);
done();
});
});
it('should delete user', function (done) {
User.create({username: 'tobedeleted'}, function (err, _uid) {
assert.ifError(err);
socketUser.deleteAccount({uid: _uid}, {}, function (err) {
assert.ifError(err);
socketUser.exists({uid: testUid}, {username: 'doesnot exist'}, function (err, exists) {
assert.ifError(err);
assert(!exists);
done();
});
});
});
});
}); });

Loading…
Cancel
Save