use includes instead of indexOf

use _.uniq instead of filter&indexOf
v1.18.x
Barış Soner Uşaklı 7 years ago
parent a6c70412db
commit 26d4e0852f

@ -37,7 +37,7 @@ module.exports = function (grunt) {
// Do nothing, just restart // Do nothing, just restart
} }
if (compiling && incomplete.indexOf(compiling) === -1) { if (compiling && !incomplete.includes(compiling)) {
incomplete.push(compiling); incomplete.push(compiling);
} }

@ -1,6 +1,8 @@
'use strict'; 'use strict';
var async = require('async'); var async = require('async');
var _ = require('lodash');
var posts = require('../posts'); var posts = require('../posts');
var db = require('../database'); var db = require('../database');
@ -14,11 +16,7 @@ module.exports = function (Categories) {
posts.getPostsFields(pids, ['uid'], next); posts.getPostsFields(pids, ['uid'], next);
}, },
function (posts, next) { function (posts, next) {
var uids = posts.map(function (post) { var uids = _.uniq(posts.map(post => post.uid).filter(uid => parseInt(uid, 10)));
return post.uid;
}).filter(function (uid, index, array) {
return parseInt(uid, 10) && array.indexOf(uid) === index;
});
next(null, uids); next(null, uids);
}, },

@ -121,11 +121,7 @@ module.exports = function (Categories) {
topic.teaserPid = topic.teaserPid || topic.mainPid; topic.teaserPid = topic.teaserPid || topic.mainPid;
} }
}); });
var cids = _topicData.map(function (topic) { var cids = _.uniq(topicData.map(topic => topic && topic.cid).filter(cid => parseInt(cid, 10)));
return topic && topic.cid;
}).filter(function (cid, index, array) {
return cid && array.indexOf(cid) === index;
});
async.parallel({ async.parallel({
categoryData: async.apply(Categories.getCategoriesFields, cids, ['cid', 'parentCid']), categoryData: async.apply(Categories.getCategoriesFields, cids, ['cid', 'parentCid']),

@ -102,7 +102,7 @@ module.exports = function (Categories) {
}, },
function (normalTids, next) { function (normalTids, next) {
normalTids = normalTids.filter(function (tid) { normalTids = normalTids.filter(function (tid) {
return pinnedTids.indexOf(tid) === -1; return !pinnedTids.includes(tid);
}); });
next(null, pinnedTids.concat(normalTids)); next(null, pinnedTids.concat(normalTids));

@ -50,7 +50,7 @@ try {
checkVersion('commander'); checkVersion('commander');
checkVersion('colors'); checkVersion('colors');
} catch (e) { } catch (e) {
if (['ENOENT', 'DEP_WRONG_VERSION', 'MODULE_NOT_FOUND'].indexOf(e.code) !== -1) { if (['ENOENT', 'DEP_WRONG_VERSION', 'MODULE_NOT_FOUND'].includes(e.code)) {
console.warn('Dependencies outdated or not yet installed.'); console.warn('Dependencies outdated or not yet installed.');
console.log('Installing them now...\n'); console.log('Installing them now...\n');

@ -201,7 +201,7 @@ function upgradePlugins(callback) {
return callback(err); return callback(err);
} }
if (['y', 'Y', 'yes', 'YES'].indexOf(result.upgrade) !== -1) { if (['y', 'Y', 'yes', 'YES'].includes(result.upgrade)) {
console.log('\nUpgrading packages...'); console.log('\nUpgrading packages...');
var args = packageManagerInstallArgs.concat(found.map(function (suggestObj) { var args = packageManagerInstallArgs.concat(found.map(function (suggestObj) {
return suggestObj.name + '@' + suggestObj.suggested; return suggestObj.name + '@' + suggestObj.suggested;

@ -21,7 +21,7 @@ exports.handle404 = function (req, res) {
if (isClientScript.test(req.url)) { if (isClientScript.test(req.url)) {
res.type('text/javascript').status(200).send(''); res.type('text/javascript').status(200).send('');
} else if (req.path.startsWith(relativePath + '/assets/uploads') || (req.get('accept') && req.get('accept').indexOf('text/html') === -1) || req.path === '/favicon.ico') { } else if (req.path.startsWith(relativePath + '/assets/uploads') || (req.get('accept') && !req.get('accept').includes('text/html')) || req.path === '/favicon.ico') {
meta.errors.log404(req.path || ''); meta.errors.log404(req.path || '');
res.sendStatus(404); res.sendStatus(404);
} else if (req.accepts('html')) { } else if (req.accepts('html')) {

@ -55,7 +55,7 @@ pluginsController.get = function (req, res, next) {
return !plugin.installed; return !plugin.installed;
}), }),
incompatible: payload.all.filter(function (plugin) { incompatible: payload.all.filter(function (plugin) {
return compatiblePkgNames.indexOf(plugin.name) === -1; return !compatiblePkgNames.includes(plugin.name);
}), }),
}); });
}, },

@ -36,7 +36,7 @@ function renderEmail(req, res, next) {
res.render('admin/settings/email', { res.render('admin/settings/email', {
emails: results.emails, emails: results.emails,
sendable: results.emails.filter(function (email) { sendable: results.emails.filter(function (email) {
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1; return !email.path.includes('_plaintext') && !email.path.includes('partials');
}), }),
services: results.services, services: results.services,
}); });

@ -261,7 +261,7 @@ function upload(name, req, res, next) {
} }
function validateUpload(req, res, next, uploadedFile, allowedTypes) { function validateUpload(req, res, next, uploadedFile, allowedTypes) {
if (allowedTypes.indexOf(uploadedFile.type) === -1) { if (!allowedTypes.includes(uploadedFile.type)) {
file.delete(uploadedFile.path); file.delete(uploadedFile.path);
res.json({ error: '[[error:invalid-image-type, ' + allowedTypes.join(', ') + ']]' }); res.json({ error: '[[error:invalid-image-type, ' + allowedTypes.join(', ') + ']]' });
return false; return false;

@ -221,7 +221,7 @@ authenticationController.login = function (req, res, next) {
var loginWith = meta.config.allowLoginWith || 'username-email'; var loginWith = meta.config.allowLoginWith || 'username-email';
if (req.body.username && utils.isEmailValid(req.body.username) && loginWith.indexOf('email') !== -1) { if (req.body.username && utils.isEmailValid(req.body.username) && loginWith.includes('email')) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
user.getUsernameByEmail(req.body.username, next); user.getUsernameByEmail(req.body.username, next);
@ -231,7 +231,7 @@ authenticationController.login = function (req, res, next) {
continueLogin(req, res, next); continueLogin(req, res, next);
}, },
], next); ], next);
} else if (loginWith.indexOf('username') !== -1 && !validator.isEmail(req.body.username)) { } else if (loginWith.includes('username') && !validator.isEmail(req.body.username)) {
continueLogin(req, res, next); continueLogin(req, res, next);
} else { } else {
var err = '[[error:wrong-login-type-' + loginWith + ']]'; var err = '[[error:wrong-login-type-' + loginWith + ']]';

@ -268,7 +268,7 @@ function getCategoryData(cids, uid, selectedCid, callback) {
var selectedCategory = []; var selectedCategory = [];
var selectedCids = []; var selectedCids = [];
categoryData.forEach(function (category) { categoryData.forEach(function (category) {
category.selected = selectedCid ? selectedCid.indexOf(String(category.cid)) !== -1 : false; category.selected = selectedCid ? selectedCid.includes(String(category.cid)) : false;
category.parentCid = category.hasOwnProperty('parentCid') && utils.isNumber(category.parentCid) ? category.parentCid : 0; category.parentCid = category.hasOwnProperty('parentCid') && utils.isNumber(category.parentCid) ? category.parentCid : 0;
if (category.selected) { if (category.selected) {
selectedCategory.push(category); selectedCategory.push(category);

@ -67,9 +67,9 @@ modsController.flags.list = function (req, res, next) {
} else if (Array.isArray(filters.cid)) { } else if (Array.isArray(filters.cid)) {
// Remove cids they do not moderate // Remove cids they do not moderate
filters.cid = filters.cid.filter(function (cid) { filters.cid = filters.cid.filter(function (cid) {
return res.locals.cids.indexOf(String(cid)) !== -1; return res.locals.cids.includes(String(cid));
}); });
} else if (res.locals.cids.indexOf(String(filters.cid)) === -1) { } else if (!res.locals.cids.includes(String(filters.cid))) {
filters.cid = res.locals.cids; filters.cid = res.locals.cids;
hasFilter = false; hasFilter = false;
} }

@ -213,7 +213,7 @@ uploadsController.uploadFile = function (uid, uploadedFile, callback) {
var allowed = file.allowedExtensions(); var allowed = file.allowedExtensions();
var extension = path.extname(uploadedFile.name).toLowerCase(); var extension = path.extname(uploadedFile.name).toLowerCase();
if (allowed.length > 0 && (!extension || extension === '.' || allowed.indexOf(extension) === -1)) { if (allowed.length > 0 && (!extension || extension === '.' || !allowed.includes(extension))) {
return callback(new Error('[[error:invalid-file-type, ' + allowed.join(', ') + ']]')); return callback(new Error('[[error:invalid-file-type, ' + allowed.join(', ') + ']]'));
} }

@ -117,10 +117,8 @@ module.exports = function (db, module) {
return callback(err); return callback(err);
} }
values = values.map(function (value) { const membersSet = new Set(items && Array.isArray(items.members) ? items.members : []);
return !!(items && Array.isArray(items.members) && items.members.indexOf(value) !== -1); values = values.map(value => membersSet.has(value));
});
callback(null, values); callback(null, values);
}); });
}; };

@ -120,11 +120,7 @@ events.getEvents = function (filter, start, stop, callback) {
}; };
function addUserData(eventsData, field, objectName, callback) { function addUserData(eventsData, field, objectName, callback) {
var uids = eventsData.map(function (event) { var uids = _.uniq(eventsData.map(event => event && event[field]));
return event && event[field];
}).filter(function (uid, index, array) {
return uid && array.indexOf(uid) === index;
});
if (!uids.length) { if (!uids.length) {
return callback(null, eventsData); return callback(null, eventsData);

@ -137,7 +137,7 @@ file.allowedExtensions = function () {
return extension.toLowerCase(); return extension.toLowerCase();
}); });
if (allowedExtensions.indexOf('.jpg') !== -1 && allowedExtensions.indexOf('.jpeg') === -1) { if (allowedExtensions.includes('.jpg') && !allowedExtensions.includes('.jpeg')) {
allowedExtensions.push('.jpeg'); allowedExtensions.push('.jpeg');
} }

@ -40,7 +40,7 @@ Groups.getEphemeralGroup = function (groupName) {
Groups.removeEphemeralGroups = function (groups) { Groups.removeEphemeralGroups = function (groups) {
for (var x = groups.length; x >= 0; x -= 1) { for (var x = groups.length; x >= 0; x -= 1) {
if (Groups.ephemeralGroups.indexOf(groups[x]) !== -1) { if (Groups.ephemeralGroups.includes(groups[x])) {
groups.splice(x, 1); groups.splice(x, 1);
} }
} }
@ -209,7 +209,7 @@ Groups.getOwnersAndMembers = function (groupName, uid, start, stop, callback) {
}); });
results.members = results.members.filter(function (user) { results.members = results.members.filter(function (user) {
return user && user.uid && ownerUids.indexOf(user.uid.toString()) === -1; return user && user.uid && !ownerUids.includes(user.uid.toString());
}); });
results.members = results.owners.concat(results.members); results.members = results.owners.concat(results.members);
@ -266,34 +266,24 @@ function isFieldOn(groupName, field, callback) {
Groups.exists = function (name, callback) { Groups.exists = function (name, callback) {
if (Array.isArray(name)) { if (Array.isArray(name)) {
var slugs = name.map(function (groupName) { var slugs = name.map(groupName => utils.slugify(groupName));
return utils.slugify(groupName); async.waterfall([
});
async.parallel([
function (next) {
next(null, slugs.map(function (slug) {
return Groups.ephemeralGroups.indexOf(slug) !== -1;
}));
},
async.apply(db.isSortedSetMembers, 'groups:createtime', name), async.apply(db.isSortedSetMembers, 'groups:createtime', name),
], function (err, results) { function (isMembersOfRealGroups, next) {
if (err) { const isMembersOfEphemeralGroups = slugs.map(slug => Groups.ephemeralGroups.includes(slug));
return callback(err); const exists = name.map((n, index) => isMembersOfRealGroups[index] || isMembersOfEphemeralGroups[index]);
} next(null, exists);
callback(null, name.map(function (n, index) { },
return results[0][index] || results[1][index]; ], callback);
}));
});
} else { } else {
var slug = utils.slugify(name); var slug = utils.slugify(name);
async.parallel([ async.waterfall([
function (next) {
next(null, Groups.ephemeralGroups.indexOf(slug) !== -1);
},
async.apply(db.isSortedSetMember, 'groups:createtime', name), async.apply(db.isSortedSetMember, 'groups:createtime', name),
], function (err, results) { function (isMemberOfRealGroups, next) {
callback(err, !err ? (results[0] || results[1]) : null); const isMemberOfEphemeralGroups = Groups.ephemeralGroups.includes(slug);
}); next(null, isMemberOfRealGroups || isMemberOfEphemeralGroups);
},
], callback);
} }
}; };

@ -19,7 +19,7 @@ module.exports = function (Groups) {
}); });
var ephemeralIdx = groupNames.reduce(function (memo, cur, idx) { var ephemeralIdx = groupNames.reduce(function (memo, cur, idx) {
if (Groups.ephemeralGroups.indexOf(cur) !== -1) { if (Groups.ephemeralGroups.includes(cur)) {
memo.push(idx); memo.push(idx);
} }
return memo; return memo;

@ -265,14 +265,14 @@ module.exports = function (Groups) {
}, },
function (groupNames, next) { function (groupNames, next) {
groupNames = Groups.removeEphemeralGroups(groupNames); groupNames = Groups.removeEphemeralGroups(groupNames);
if (groupNames.length === 0) { if (!groupNames.length) {
return callback(null, false); return callback(null, false);
} }
Groups.isMemberOfGroups(uid, groupNames, next); Groups.isMemberOfGroups(uid, groupNames, next);
}, },
function (isMembers, next) { function (isMembers, next) {
next(null, isMembers.indexOf(true) !== -1); next(null, isMembers.includes(true));
}, },
], callback); ], callback);
}; };

@ -18,7 +18,7 @@ module.exports = function (Groups) {
// Ephemeral groups and the registered-users groups are searchable // Ephemeral groups and the registered-users groups are searchable
groupNames = Groups.ephemeralGroups.concat(groupNames).concat('registered-users'); groupNames = Groups.ephemeralGroups.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().includes(query) && name !== 'administrators' && !Groups.isPrivilegeGroup(name);
}); });
groupNames = groupNames.slice(0, 100); groupNames = groupNames.slice(0, 100);
Groups.getGroupsData(groupNames, next); Groups.getGroupsData(groupNames, next);

@ -7,6 +7,8 @@ var path = require('path');
var prompt = require('prompt'); var prompt = require('prompt');
var winston = require('winston'); var winston = require('winston');
var nconf = require('nconf'); var nconf = require('nconf');
var _ = require('lodash');
var utils = require('./utils.js'); var utils = require('./utils.js');
var install = module.exports; var install = module.exports;
@ -488,9 +490,7 @@ function enableDefaultPlugins(next) {
} }
} }
defaultEnabled = defaultEnabled.filter(function (plugin, index, array) { defaultEnabled = _.uniq(defaultEnabled);
return array.indexOf(plugin) === index;
});
winston.info('[install/enableDefaultPlugins] activating default plugins', defaultEnabled); winston.info('[install/enableDefaultPlugins] activating default plugins', defaultEnabled);

@ -353,7 +353,7 @@ Messaging.hasPrivateChat = function (uid, withUid, callback) {
}, },
function (results, next) { function (results, next) {
var roomIds = results.myRooms.filter(function (roomId) { var roomIds = results.myRooms.filter(function (roomId) {
return roomId && results.theirRooms.indexOf(roomId) !== -1; return roomId && results.theirRooms.includes(roomId);
}); });
if (!roomIds.length) { if (!roomIds.length) {

@ -3,6 +3,7 @@
var ipaddr = require('ipaddr.js'); var ipaddr = require('ipaddr.js');
var winston = require('winston'); var winston = require('winston');
var async = require('async'); var async = require('async');
var _ = require('lodash');
var db = require('../database'); var db = require('../database');
var pubsub = require('../pubsub'); var pubsub = require('../pubsub');
@ -79,8 +80,8 @@ Blacklist.test = function (clientIp, callback) {
} }
if ( if (
Blacklist._rules.ipv4.indexOf(clientIp) === -1 && // not explicitly specified in ipv4 list !Blacklist._rules.ipv4.includes(clientIp) && // not explicitly specified in ipv4 list
Blacklist._rules.ipv6.indexOf(clientIp) === -1 && // not explicitly specified in ipv6 list !Blacklist._rules.ipv6.includes(clientIp) && // not explicitly specified in ipv6 list
!Blacklist._rules.cidr.some(function (subnet) { !Blacklist._rules.cidr.some(function (subnet) {
var cidr = ipaddr.parseCIDR(subnet); var cidr = ipaddr.parseCIDR(subnet);
if (addr.kind() !== cidr[0].kind()) { if (addr.kind() !== cidr[0].kind()) {
@ -127,14 +128,9 @@ Blacklist.validate = function (rules, callback) {
}).filter(Boolean); }).filter(Boolean);
// Filter out duplicates // Filter out duplicates
rules = rules.filter(function (rule, index) { const uniqRules = _.uniq(rules);
const pass = rules.indexOf(rule) === index; duplicateCount += rules.length - uniqRules.length;
if (!pass) { rules = uniqRules;
duplicateCount += 1;
}
return pass;
});
// Filter out invalid rules // Filter out invalid rules
rules = rules.filter(function (rule) { rules = rules.filter(function (rule) {
@ -153,7 +149,7 @@ Blacklist.validate = function (rules, callback) {
// Do nothing // Do nothing
} }
if (!addr || whitelist.indexOf(rule) !== -1) { if (!addr || whitelist.includes(rule)) {
invalid.push(rule); invalid.push(rule);
return false; return false;
} }

@ -156,7 +156,7 @@ function build(targets, options, callback) {
target = target.toLowerCase().replace(/-/g, ''); target = target.toLowerCase().replace(/-/g, '');
if (!aliases[target]) { if (!aliases[target]) {
winston.warn('[build] Unknown target: ' + target); winston.warn('[build] Unknown target: ' + target);
if (target.indexOf(',') !== -1) { if (target.includes(',')) {
winston.warn('[build] Are you specifying multiple targets? Separate them with spaces:'); winston.warn('[build] Are you specifying multiple targets? Separate them with spaces:');
winston.warn('[build] e.g. `./nodebb build adminjs tpl`'); winston.warn('[build] e.g. `./nodebb build adminjs tpl`');
} }

@ -72,7 +72,7 @@ Dependencies.doesSatisfy = function (moduleData, packageJSONVersion) {
return false; return false;
} }
var versionOk = !semver.validRange(packageJSONVersion) || semver.satisfies(moduleData.version, packageJSONVersion); var versionOk = !semver.validRange(packageJSONVersion) || semver.satisfies(moduleData.version, packageJSONVersion);
var githubRepo = moduleData._resolved && moduleData._resolved.indexOf('//github.com') !== -1; var githubRepo = moduleData._resolved && moduleData._resolved.includes('//github.com');
var satisfies = versionOk || githubRepo; var satisfies = versionOk || githubRepo;
if (!satisfies) { if (!satisfies) {
winston.warn('[' + 'outdated'.yellow + '] ' + moduleData.name.bold + ' installed v' + moduleData.version + ', package.json requires ' + packageJSONVersion + '\n'); winston.warn('[' + 'outdated'.yellow + '] ' + moduleData.name.bold + ' installed v' + moduleData.version + ', package.json requires ' + packageJSONVersion + '\n');

@ -115,7 +115,7 @@ var basePath = path.resolve(__dirname, '../..');
function minifyModules(modules, fork, callback) { function minifyModules(modules, fork, callback) {
var moduleDirs = modules.reduce(function (prev, mod) { var moduleDirs = modules.reduce(function (prev, mod) {
var dir = path.resolve(path.dirname(mod.destPath)); var dir = path.resolve(path.dirname(mod.destPath));
if (prev.indexOf(dir) === -1) { if (!prev.includes(dir)) {
prev.push(dir); prev.push(dir);
} }
return prev; return prev;

@ -171,7 +171,7 @@ middleware.applyBlacklist = function (req, res, next) {
}; };
middleware.processTimeagoLocales = function (req, res, next) { middleware.processTimeagoLocales = function (req, res, next) {
var fallback = req.path.indexOf('-short') === -1 ? 'jquery.timeago.en.js' : 'jquery.timeago.en-short.js'; var fallback = !req.path.includes('-short') ? 'jquery.timeago.en.js' : 'jquery.timeago.en-short.js';
var localPath = path.join(__dirname, '../../public/vendor/jquery/timeago/locales', req.path); var localPath = path.join(__dirname, '../../public/vendor/jquery/timeago/locales', req.path);
async.waterfall([ async.waterfall([

@ -122,27 +122,20 @@ Notifications.filterExists = function (nids, callback) {
Notifications.findRelated = function (mergeIds, set, callback) { Notifications.findRelated = function (mergeIds, set, callback) {
// A related notification is one in a zset that has the same mergeId // A related notification is one in a zset that has the same mergeId
var _nids; var nids;
async.waterfall([ async.waterfall([
async.apply(db.getSortedSetRevRange, set, 0, -1), async.apply(db.getSortedSetRevRange, set, 0, -1),
function (nids, next) { function (_nids, next) {
_nids = nids; nids = _nids;
var keys = nids.map(function (nid) {
return 'notifications:' + nid;
});
var keys = nids.map(nid => 'notifications:' + nid);
db.getObjectsFields(keys, ['mergeId'], next); db.getObjectsFields(keys, ['mergeId'], next);
}, },
function (sets, next) { function (sets, next) {
sets = sets.map(function (set) { sets = sets.map(set => set.mergeId);
return set.mergeId; var mergeSet = new Set(mergeIds);
}); next(null, nids.filter((nid, idx) => mergeSet.has(sets[idx])));
next(null, _nids.filter(function (nid, idx) {
return mergeIds.indexOf(sets[idx]) !== -1;
}));
}, },
], callback); ], callback);
}; };
@ -536,7 +529,7 @@ Notifications.merge = function (notifications, callback) {
// Each isolated mergeId may have multiple differentiators, so process each separately // Each isolated mergeId may have multiple differentiators, so process each separately
differentiators = isolated.reduce(function (cur, next) { differentiators = isolated.reduce(function (cur, next) {
differentiator = next.mergeId.split('|')[1] || 0; differentiator = next.mergeId.split('|')[1] || 0;
if (cur.indexOf(differentiator) === -1) { if (!cur.includes(differentiator)) {
cur.push(differentiator); cur.push(differentiator);
} }

@ -32,9 +32,7 @@ pagination.create = function (currentPage, pageCount, queryObj) {
pagesToShow.push(startPage + i); pagesToShow.push(startPage + i);
} }
pagesToShow = pagesToShow.filter(function (page, index, array) { pagesToShow = _.uniq(pagesToShow).filter(page => page > 0 && page <= pageCount).sort(function (a, b) {
return page > 0 && page <= pageCount && array.indexOf(page) === index;
}).sort(function (a, b) {
return a - b; return a - b;
}); });

@ -33,7 +33,7 @@ module.exports = function (Plugins) {
var method; var method;
if (Object.keys(Plugins.deprecatedHooks).indexOf(data.hook) !== -1) { if (Object.keys(Plugins.deprecatedHooks).includes(data.hook)) {
winston.warn('[plugins/' + id + '] Hook `' + data.hook + '` is deprecated, ' + winston.warn('[plugins/' + id + '] Hook `' + data.hook + '` is deprecated, ' +
(Plugins.deprecatedHooks[data.hook] ? (Plugins.deprecatedHooks[data.hook] ?
'please use `' + Plugins.deprecatedHooks[data.hook] + '` instead.' : 'please use `' + Plugins.deprecatedHooks[data.hook] + '` instead.' :

@ -157,7 +157,7 @@ module.exports = function (Plugins) {
function checkVersion(pluginData) { function checkVersion(pluginData) {
function add() { function add() {
if (Plugins.versionWarning.indexOf(pluginData.id) === -1) { if (!Plugins.versionWarning.includes(pluginData.id)) {
Plugins.versionWarning.push(pluginData.id); Plugins.versionWarning.push(pluginData.id);
} }
} }

@ -1,6 +1,8 @@
'use strict'; 'use strict';
var async = require('async'); var async = require('async');
var _ = require('lodash');
var db = require('../database'); var db = require('../database');
var privileges = require('../privileges'); var privileges = require('../privileges');
@ -42,11 +44,8 @@ module.exports = function (Posts) {
Posts.getPostsFields(pids, ['uid'], next); Posts.getPostsFields(pids, ['uid'], next);
}, },
function (postData, next) { function (postData, next) {
var uids = postData.map(function (post) { var uids = _.uniq(postData.map(post => post && post.uid).filter(uid => parseInt(uid, 10)));
return post && post.uid;
}).filter(function (uid, index, array) {
return uid && array.indexOf(uid) === index;
});
next(null, uids); next(null, uids);
}, },
], callback); ], callback);

@ -33,23 +33,20 @@ module.exports = function (Posts) {
user.blocks.filter(uid, posts, next); user.blocks.filter(uid, posts, next);
}, },
function (_posts, next) { function (_posts, next) {
var uids = []; posts = _posts;
var topicKeys = []; var uids = {};
var topicKeys = {};
posts.forEach(function (post, i) { posts.forEach(function (post) {
if (uids.indexOf(posts[i].uid) === -1) { uids[post.uid] = 1;
uids.push(posts[i].uid); topicKeys[post.tid] = 1;
}
if (topicKeys.indexOf(posts[i].tid) === -1) {
topicKeys.push(posts[i].tid);
}
}); });
async.parallel({ async.parallel({
users: function (next) { users: function (next) {
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next); user.getUsersFields(Object.keys(uids), ['uid', 'username', 'userslug', 'picture'], next);
}, },
topicsAndCategories: function (next) { topicsAndCategories: function (next) {
getTopicAndCategories(topicKeys, next); getTopicAndCategories(Object.keys(topicKeys), next);
}, },
}, next); }, next);
}, },

@ -147,7 +147,7 @@ helpers.getUserPrivileges = function (cid, hookName, userPrivilegeList, callback
memberData.forEach(function (member) { memberData.forEach(function (member) {
member.privileges = {}; member.privileges = {};
for (var x = 0, numPrivs = userPrivileges.length; x < numPrivs; x += 1) { for (var x = 0, numPrivs = userPrivileges.length; x < numPrivs; x += 1) {
member.privileges[userPrivileges[x]] = memberSets[x].indexOf(parseInt(member.uid, 10)) !== -1; member.privileges[userPrivileges[x]] = memberSets[x].includes(parseInt(member.uid, 10));
} }
}); });
@ -178,7 +178,7 @@ helpers.getGroupPrivileges = function (cid, hookName, groupPrivilegeList, callba
var uniqueGroups = _.uniq(_.flatten(memberSets)); var uniqueGroups = _.uniq(_.flatten(memberSets));
var groupNames = results.groupNames.filter(function (groupName) { var groupNames = results.groupNames.filter(function (groupName) {
return groupName.indexOf(':privileges:') === -1 && uniqueGroups.indexOf(groupName) !== -1; return !groupName.includes(':privileges:') && uniqueGroups.includes(groupName);
}); });
groupNames = groups.ephemeralGroups.concat(groupNames); groupNames = groups.ephemeralGroups.concat(groupNames);
@ -200,7 +200,7 @@ helpers.getGroupPrivileges = function (cid, hookName, groupPrivilegeList, callba
memberPrivs = {}; memberPrivs = {};
for (var x = 0, numPrivs = groupPrivileges.length; x < numPrivs; x += 1) { for (var x = 0, numPrivs = groupPrivileges.length; x < numPrivs; x += 1) {
memberPrivs[groupPrivileges[x]] = memberSets[x].indexOf(member) !== -1; memberPrivs[groupPrivileges[x]] = memberSets[x].includes(member);
} }
return { return {
name: member, name: member,

@ -88,9 +88,8 @@ module.exports = function (privileges) {
}, },
function (_posts, next) { function (_posts, next) {
postData = _posts; postData = _posts;
tids = _.uniq(_posts.map(function (post) {
return post && post.tid; tids = _.uniq(_posts.map(post => post && post.tid).filter(Boolean));
}).filter(Boolean));
topics.getTopicsFields(tids, ['deleted', 'cid'], next); topics.getTopicsFields(tids, ['deleted', 'cid'], next);
}, },
@ -107,9 +106,9 @@ module.exports = function (privileges) {
post.topic = tidToTopic[post.tid]; post.topic = tidToTopic[post.tid];
} }
return tidToTopic[post.tid] && tidToTopic[post.tid].cid; return tidToTopic[post.tid] && tidToTopic[post.tid].cid;
}).filter(function (cid, index, array) { }).filter(cid => parseInt(cid, 10));
return cid && array.indexOf(cid) === index;
}); cids = _.uniq(cids);
privileges.categories.getBase(privilege, cids, uid, next); privileges.categories.getBase(privilege, cids, uid, next);
}, },
@ -121,13 +120,12 @@ module.exports = function (privileges) {
(results.allowedTo[index] || results.isAdmin || results.isModerators[index]); (results.allowedTo[index] || results.isAdmin || results.isModerators[index]);
}); });
const cidsSet = new Set(cids);
pids = postData.filter(function (post) { pids = postData.filter(function (post) {
return post.topic && cids.indexOf(post.topic.cid) !== -1 && return post.topic && cidsSet.has(post.topic.cid) &&
((parseInt(post.topic.deleted, 10) !== 1 && parseInt(post.deleted, 10) !== 1) || results.isAdmin || isModOf[post.cid]); ((parseInt(post.topic.deleted, 10) !== 1 && parseInt(post.deleted, 10) !== 1) || results.isAdmin || isModOf[post.cid]);
}).map(function (post) { }).map(post => post.pid);
return post.pid;
});
plugins.fireHook('filter:privileges.posts.filter', { plugins.fireHook('filter:privileges.posts.filter', {
privilege: privilege, privilege: privilege,

@ -86,9 +86,7 @@ module.exports = function (privileges) {
}, },
function (_topicsData, next) { function (_topicsData, next) {
topicsData = _topicsData; topicsData = _topicsData;
cids = _.uniq(topicsData.map(function (topic) { cids = _.uniq(topicsData.map(topic => topic.cid));
return topic.cid;
}));
privileges.categories.getBase(privilege, cids, uid, next); privileges.categories.getBase(privilege, cids, uid, next);
}, },
@ -100,12 +98,12 @@ module.exports = function (privileges) {
(results.allowedTo[index] || results.isAdmin || results.isModerators[index]); (results.allowedTo[index] || results.isAdmin || results.isModerators[index]);
}); });
const cidsSet = new Set(cids);
tids = topicsData.filter(function (topic) { tids = topicsData.filter(function (topic) {
return cids.indexOf(topic.cid) !== -1 && return cidsSet.has(topic.cid) &&
(parseInt(topic.deleted, 10) !== 1 || results.isAdmin || isModOf[topic.cid]); (parseInt(topic.deleted, 10) !== 1 || results.isAdmin || isModOf[topic.cid]);
}).map(function (topic) { }).map(topic => topic.tid);
return topic.tid;
});
plugins.fireHook('filter:privileges.topics.filter', { plugins.fireHook('filter:privileges.topics.filter', {
privilege: privilege, privilege: privilege,

@ -39,8 +39,8 @@ social.getPostSharing = function (callback) {
db.getSetMembers('social:posts.activated', next); db.getSetMembers('social:posts.activated', next);
}, },
function (activated, next) { function (activated, next) {
networks.forEach(function (network, i) { networks.forEach(function (network) {
networks[i].activated = (activated.indexOf(network.id) !== -1); network.activated = activated.includes(network.id);
}); });
social.postSharing = networks; social.postSharing = networks;

@ -47,7 +47,7 @@ SocketCategories.getWatchedCategories = function (socket, data, callback) {
}, },
function (results, next) { function (results, next) {
var watchedCategories = results.categories.filter(function (category) { var watchedCategories = results.categories.filter(function (category) {
return category && results.ignoredCids.indexOf(category.cid.toString()) === -1; return category && !results.ignoredCids.includes(String(category.cid));
}); });
next(null, watchedCategories); next(null, watchedCategories);
@ -197,7 +197,7 @@ function ignoreOrWatch(fn, socket, cid, callback) {
var cat; var cat;
do { do {
cat = categoryData.find(function (c) { cat = categoryData.find(function (c) {
return cids.indexOf(c.cid) === -1 && cids.indexOf(c.parentCid) !== -1; return !cids.includes(c.cid) && cids.includes(c.parentCid);
}); });
if (cat) { if (cat) {
cids.push(cat.cid); cids.push(cat.cid);

@ -199,7 +199,7 @@ SocketHelpers.upvote = function (data, notification) {
return votes > 0 && votes % 10 === 0; return votes > 0 && votes % 10 === 0;
}, },
threshold: function () { threshold: function () {
return [1, 5, 10, 25].indexOf(votes) !== -1 || (votes >= 50 && votes % 50 === 0); return [1, 5, 10, 25].includes(votes) || (votes >= 50 && votes % 50 === 0);
}, },
logarithmic: function () { logarithmic: function () {
return votes > 1 && Math.log10(votes) % 1 === 0; return votes > 1 && Math.log10(votes) % 1 === 0;

@ -318,7 +318,7 @@ SocketModules.chats.markRead = function (socket, roomId, callback) {
Messaging.pushUnreadCount(socket.uid); Messaging.pushUnreadCount(socket.uid);
server.in('uid_' + socket.uid).emit('event:chats.markedAsRead', { roomId: roomId }); server.in('uid_' + socket.uid).emit('event:chats.markedAsRead', { roomId: roomId });
if (results.uidsInRoom.indexOf(socket.uid.toString()) === -1) { if (!results.uidsInRoom.includes(String(socket.uid))) {
return callback(); return callback();
} }

@ -101,7 +101,7 @@ SocketTopics.changeWatching = function (socket, data, callback) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
var commands = ['follow', 'unfollow', 'ignore']; var commands = ['follow', 'unfollow', 'ignore'];
if (commands.indexOf(data.type) === -1) { if (!commands.includes(data.type)) {
return callback(new Error('[[error:invalid-command]]')); return callback(new Error('[[error:invalid-command]]'));
} }
followCommand(topics[data.type], socket, data.tid, callback); followCommand(topics[data.type], socket, data.tid, callback);

@ -105,7 +105,7 @@ module.exports = function (SocketTopics) {
function logTopicAction(action, socket, tid, title, callback) { function logTopicAction(action, socket, tid, title, callback) {
var actionsToLog = ['delete', 'restore', 'purge']; var actionsToLog = ['delete', 'restore', 'purge'];
if (actionsToLog.indexOf(action) === -1) { if (!actionsToLog.includes(action)) {
return setImmediate(callback); return setImmediate(callback);
} }
events.log({ events.log({

@ -26,7 +26,7 @@ module.exports = function (SocketUser) {
} }
var allowedStatus = ['online', 'offline', 'dnd', 'away']; var allowedStatus = ['online', 'offline', 'dnd', 'away'];
if (allowedStatus.indexOf(status) === -1) { if (!allowedStatus.includes(status)) {
return callback(new Error('[[error:invalid-user-status]]')); return callback(new Error('[[error:invalid-user-status]]'));
} }

@ -107,7 +107,7 @@ function printStartupInfo() {
winston.info('Initializing NodeBB v%s %s', nconf.get('version'), nconf.get('url')); winston.info('Initializing NodeBB v%s %s', nconf.get('version'), nconf.get('url'));
var host = nconf.get(nconf.get('database') + ':host'); var host = nconf.get(nconf.get('database') + ':host');
var storeLocation = host ? 'at ' + host + (host.indexOf('/') === -1 ? ':' + nconf.get(nconf.get('database') + ':port') : '') : ''; var storeLocation = host ? 'at ' + host + (!host.includes('/') ? ':' + nconf.get(nconf.get('database') + ':port') : '') : '';
winston.verbose('* using %s store %s', nconf.get('database'), storeLocation); winston.verbose('* using %s store %s', nconf.get('database'), storeLocation);
winston.verbose('* using themes stored in: %s', nconf.get('themes_path')); winston.verbose('* using themes stored in: %s', nconf.get('themes_path'));

@ -57,24 +57,20 @@ module.exports = function (Topics) {
} }
function getPostUserData(field, method, callback) { function getPostUserData(field, method, callback) {
var uids = []; var uidsMap = {};
postData.forEach(function (postData) { postData.forEach((post) => {
if (postData && parseInt(postData[field], 10) >= 0 && uids.indexOf(postData[field]) === -1) { if (post && parseInt(post[field], 10) >= 0) {
uids.push(postData[field]); uidsMap[post[field]] = 1;
} }
}); });
const uids = Object.keys(uidsMap);
async.waterfall([ async.waterfall([
function (next) { function (next) {
method(uids, next); method(uids, next);
}, },
function (users, next) { function (users, next) {
var userData = {}; next(null, _.zipObject(uids, users));
users.forEach(function (user, index) {
userData[uids[index]] = user;
});
next(null, userData);
}, },
], callback); ], callback);
} }

@ -65,9 +65,8 @@ module.exports = function (Topics) {
if (!tagWhitelist.length) { if (!tagWhitelist.length) {
return next(null, tags); return next(null, tags);
} }
tags = tags.filter(function (tag) { var whitelistSet = new Set(tagWhitelist);
return tagWhitelist.indexOf(tag) !== -1; tags = tags.filter(tag => whitelistSet.has(tag));
});
next(null, tags); next(null, tags);
}, },
], callback); ], callback);

@ -87,7 +87,7 @@ Upgrade.check = function (callback) {
} }
var remainder = files.filter(function (name) { var remainder = files.filter(function (name) {
return executed.indexOf(path.basename(name, '.js')) === -1; return !executed.includes(path.basename(name, '.js'));
}); });
next(remainder.length > 0 ? new Error('schema-out-of-date') : null); next(remainder.length > 0 ? new Error('schema-out-of-date') : null);
@ -112,7 +112,7 @@ Upgrade.run = function (callback) {
} }
queue = data.available.reduce(function (memo, cur) { queue = data.available.reduce(function (memo, cur) {
if (data.completed.indexOf(path.basename(cur, '.js')) === -1) { if (!data.completed.includes(path.basename(cur, '.js'))) {
memo.push(cur); memo.push(cur);
} else { } else {
skipped += 1; skipped += 1;
@ -132,7 +132,7 @@ Upgrade.runParticular = function (names, callback) {
async.apply(file.walk, path.join(__dirname, './upgrades')), async.apply(file.walk, path.join(__dirname, './upgrades')),
function (files, next) { function (files, next) {
var upgrades = files.filter(function (file) { var upgrades = files.filter(function (file) {
return names.indexOf(path.basename(file, '.js')) !== -1; return names.includes(path.basename(file, '.js'));
}); });
Upgrade.process(upgrades, 0, next); Upgrade.process(upgrades, 0, next);

@ -27,7 +27,7 @@ module.exports = {
} }
keys.forEach(function (key) { keys.forEach(function (key) {
if (settings[key] && settings[key].indexOf(' | ') === -1) { if (settings[key] && !settings[key].includes(' | ')) {
settings[key] = map[settings[key]] || ''; settings[key] = map[settings[key]] || '';
} }
}); });
@ -46,7 +46,7 @@ module.exports = {
} }
var newSettings = {}; var newSettings = {};
keys.forEach(function (key) { keys.forEach(function (key) {
if (settings[key] && settings[key].indexOf(' | ') === -1) { if (settings[key] && !settings[key].includes(' | ')) {
newSettings[key] = map[settings[key]] || ''; newSettings[key] = map[settings[key]] || '';
} }
}); });

@ -23,8 +23,10 @@ module.exports = function (User) {
}, next); }, next);
}, },
function (results, next) { function (results, next) {
const ignored = new Set(results.ignored);
var watched = results.all.filter(function (cid) { var watched = results.all.filter(function (cid) {
return cid && results.ignored.indexOf(cid) === -1; return cid && !ignored.has(cid);
}); });
next(null, watched); next(null, watched);
}, },

@ -4,6 +4,7 @@ var async = require('async');
var validator = require('validator'); var validator = require('validator');
var nconf = require('nconf'); var nconf = require('nconf');
var winston = require('winston'); var winston = require('winston');
var _ = require('lodash');
var db = require('../database'); var db = require('../database');
var meta = require('../meta'); var meta = require('../meta');
@ -49,27 +50,25 @@ module.exports = function (User) {
var fieldsToRemove = []; var fieldsToRemove = [];
function addField(field) { function addField(field) {
if (fields.indexOf(field) === -1) { if (!fields.includes(field)) {
fields.push(field); fields.push(field);
fieldsToRemove.push(field); fieldsToRemove.push(field);
} }
} }
if (fields.length && fields.indexOf('uid') === -1) { if (fields.length && !fields.includes('uid')) {
fields.push('uid'); fields.push('uid');
} }
if (fields.indexOf('picture') !== -1) { if (fields.includes('picture')) {
addField('uploadedpicture'); addField('uploadedpicture');
} }
if (fields.indexOf('status') !== -1) { if (fields.includes('status')) {
addField('lastonline'); addField('lastonline');
} }
var uniqueUids = uids.filter(function (uid, index) { var uniqueUids = _.uniq(uids);
return index === uids.indexOf(uid);
});
async.waterfall([ async.waterfall([
function (next) { function (next) {

@ -225,19 +225,14 @@ UserNotifications.getUnreadByField = function (uid, field, values, callback) {
return callback(null, []); return callback(null, []);
} }
var keys = nids.map(function (nid) { var keys = nids.map(nid => 'notifications:' + nid);
return 'notifications:' + nid;
});
db.getObjectsFields(keys, ['nid', field], next); db.getObjectsFields(keys, ['nid', field], next);
}, },
function (notifications, next) { function (notifications, next) {
values = values.map(function () { return values.toString(); }); const valuesSet = new Set(values.map(value => String(value)));
nids = notifications.filter(function (notification) { nids = notifications.filter(function (notification) {
return notification && notification[field] && values.indexOf(notification[field].toString()) !== -1; return notification && notification[field] && valuesSet.has(String(notification[field]));
}).map(function (notification) { }).map(notification => notification.nid);
return notification.nid;
});
next(null, nids); next(null, nids);
}, },

@ -176,7 +176,7 @@ module.exports = function (User) {
db.sortedSetsRemove(['digest:day:uids', 'digest:week:uids', 'digest:month:uids'], uid, next); db.sortedSetsRemove(['digest:day:uids', 'digest:week:uids', 'digest:month:uids'], uid, next);
}, },
function (next) { function (next) {
if (['day', 'week', 'month'].indexOf(dailyDigestFreq) !== -1) { if (['day', 'week', 'month'].includes(dailyDigestFreq)) {
db.sortedSetAdd('digest:' + dailyDigestFreq + ':uids', Date.now(), uid, next); db.sortedSetAdd('digest:' + dailyDigestFreq + ':uids', Date.now(), uid, next);
} else { } else {
next(); next();

@ -481,9 +481,9 @@ describe('Admin Controllers', function () {
body = body.posts.map(function (network) { body = body.posts.map(function (network) {
return network && network.id; return network && network.id;
}); });
assert(body.indexOf('facebook') !== -1); assert(body.includes('facebook'));
assert(body.indexOf('twitter') !== -1); assert(body.includes('twitter'));
assert(body.indexOf('google') !== -1); assert(body.includes('google'));
done(); done();
}); });
}); });
@ -665,16 +665,16 @@ describe('Admin Controllers', function () {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 200); assert.equal(res.statusCode, 200);
assert(body); assert(body);
assert(body.indexOf('"someValue":"\\\\"foo\\\\""') !== -1); assert(body.includes('"someValue":"\\\\"foo\\\\""'));
assert(body.indexOf('"otherValue":"\\\'123\\\'"') !== -1); assert(body.includes('"otherValue":"\\\'123\\\'"'));
assert(body.indexOf('"script":"<\\/script>"') !== -1); assert(body.includes('"script":"<\\/script>"'));
request(nconf.get('url'), { jar: jar }, function (err, res, body) { request(nconf.get('url'), { jar: jar }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 200); assert.equal(res.statusCode, 200);
assert(body); assert(body);
assert(body.indexOf('"someValue":"\\\\"foo\\\\""') !== -1); assert(body.includes('"someValue":"\\\\"foo\\\\""'));
assert(body.indexOf('"otherValue":"\\\'123\\\'"') !== -1); assert(body.includes('"otherValue":"\\\'123\\\'"'));
assert(body.indexOf('"script":"<\\/script>"') !== -1); assert(body.includes('"script":"<\\/script>"'));
plugins.unregisterHook('somePlugin', 'filter:config.get', onConfigGet); plugins.unregisterHook('somePlugin', 'filter:config.get', onConfigGet);
done(); done();
}); });

@ -218,7 +218,7 @@ describe('Controllers', function () {
assert.equal(res.statusCode, 200); assert.equal(res.statusCode, 200);
assert.ok(body); assert.ok(body);
assert.ok(body.indexOf('<main id="panel"')); assert.ok(body.indexOf('<main id="panel"'));
assert.ok(body.indexOf(message) !== -1); assert.ok(body.includes(message));
done(); done();
}); });
@ -1056,7 +1056,7 @@ describe('Controllers', function () {
request(nconf.get('url') + '/me/bookmarks', { json: true }, function (err, res, body) { request(nconf.get('url') + '/me/bookmarks', { json: true }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 200); assert.equal(res.statusCode, 200);
assert(body.indexOf('Login to your account') !== -1); assert(body.includes('Login to your account'));
done(); done();
}); });
}); });
@ -1422,7 +1422,7 @@ describe('Controllers', function () {
var contents = body.posts.map(function (p) { var contents = body.posts.map(function (p) {
return p.content; return p.content;
}); });
assert(contents.indexOf('1st reply') === -1); assert(!contents.includes('1st reply'));
done(); done();
}); });
}, },
@ -1770,7 +1770,7 @@ describe('Controllers', function () {
request(nconf.get('url') + '/assets/vendor/jquery/timeago/locales/jquery.timeago.af.js', function (err, res, body) { request(nconf.get('url') + '/assets/vendor/jquery/timeago/locales/jquery.timeago.af.js', function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 200); assert.equal(res.statusCode, 200);
assert(body.indexOf('Afrikaans') !== -1); assert(body.includes('Afrikaans'));
done(); done();
}); });
}); });
@ -1779,7 +1779,7 @@ describe('Controllers', function () {
request(nconf.get('url') + '/assets/vendor/jquery/timeago/locales/jquery.timeago.404.js', function (err, res, body) { request(nconf.get('url') + '/assets/vendor/jquery/timeago/locales/jquery.timeago.404.js', function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 200); assert.equal(res.statusCode, 200);
assert(body.indexOf('English') !== -1); assert(body.includes('English'));
done(); done();
}); });
}); });
@ -2108,7 +2108,7 @@ describe('Controllers', function () {
request(nconf.get('url') + '//admin/advanced/database', { json: true }, function (err, res, body) { request(nconf.get('url') + '//admin/advanced/database', { json: true }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 200); assert.equal(res.statusCode, 200);
assert(body.indexOf('Login to your account') !== -1); assert(body.includes('Login to your account'));
done(); done();
}); });
}); });

@ -97,7 +97,7 @@ describe('feeds', function () {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 200); assert.equal(res.statusCode, 200);
assert(body); assert(body);
assert(body.indexOf('Login to your account') !== -1); assert(body.includes('Login to your account'));
privileges.categories.give(['topics:read'], cid, 'guests', done); privileges.categories.give(['topics:read'], cid, 'guests', done);
}); });
}); });
@ -118,7 +118,7 @@ describe('feeds', function () {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 200); assert.equal(res.statusCode, 200);
assert(body); assert(body);
assert(body.indexOf('Login to your account') !== -1); assert(body.includes('Login to your account'));
privileges.categories.give(['read'], cid, 'guests', done); privileges.categories.give(['read'], cid, 'guests', done);
}); });
}); });
@ -159,8 +159,8 @@ describe('feeds', function () {
assert.ifError(err); assert.ifError(err);
assert.equal(results.test1[0].statusCode, 200); assert.equal(results.test1[0].statusCode, 200);
assert.equal(results.test2[0].statusCode, 200); assert.equal(results.test2[0].statusCode, 200);
assert(results.test1[0].body.indexOf('Login to your account') !== -1); assert(results.test1[0].body.includes('Login to your account'));
assert(results.test2[0].body.indexOf('Login to your account') !== -1); assert(results.test2[0].body.includes('Login to your account'));
done(); done();
}); });
}); });
@ -170,7 +170,7 @@ describe('feeds', function () {
request(nconf.get('url') + '/category/' + cid + '.rss?uid=' + fooUid + '&token=sometoken', { }, function (err, res, body) { request(nconf.get('url') + '/category/' + cid + '.rss?uid=' + fooUid + '&token=sometoken', { }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 200); assert.equal(res.statusCode, 200);
assert(body.indexOf('Login to your account') !== -1); assert(body.includes('Login to your account'));
done(); done();
}); });
}); });
@ -194,7 +194,7 @@ describe('feeds', function () {
request(nconf.get('url') + '/category/' + cid + '.rss?uid=' + fooUid + '&token=' + rssToken, { }, function (err, res, body) { request(nconf.get('url') + '/category/' + cid + '.rss?uid=' + fooUid + '&token=' + rssToken, { }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 200); assert.equal(res.statusCode, 200);
assert(body.indexOf('Login to your account') !== -1); assert(body.includes('Login to your account'));
done(); done();
}); });
}); });

@ -1919,8 +1919,8 @@ describe('Topic\'s', function () {
var tags = result.topic.tags.map(function (tag) { var tags = result.topic.tags.map(function (tag) {
return tag.value; return tag.value;
}); });
assert(tags.indexOf('tag1') !== -1); assert(tags.includes('tag1'));
assert(tags.indexOf('tag2') !== -1); assert(tags.includes('tag2'));
done(); done();
}); });
}); });

Loading…
Cancel
Save