Skip to content

Node.js based forum software built for the modern web

multiple test fixes

barisusakli5d6e2ad083d3
diff --git a/src/database/mongo.js b/src/database/mongo.js
index b5af8b57ab..2733e0ef31 100644
--- a/src/database/mongo.js
+++ b/src/database/mongo.js
@@ -171,6 +171,9 @@
};
module.info = function (db, callback) {
+ if (!db) {
+ return callback();
+ }
async.parallel({
serverStatus: function (next) {
db.command({'serverStatus': 1}, next);
diff --git a/src/database/mongo/hash.js b/src/database/mongo/hash.js
index 7baf70b401..4951b44529 100644
--- a/src/database/mongo/hash.js
+++ b/src/database/mongo/hash.js
@@ -5,7 +5,7 @@ module.exports = function (db, module) {
module.setObject = function (key, data, callback) {
callback = callback || helpers.noop;
- if (!key) {
+ if (!key || !data) {
return callback();
}
diff --git a/src/database/redis.js b/src/database/redis.js
index 46c1748fc3..e583aff4ff 100644
--- a/src/database/redis.js
+++ b/src/database/redis.js
@@ -127,6 +127,9 @@
};
module.info = function (cxn, callback) {
+ if (!cxn) {
+ return callback();
+ }
cxn.info(function (err, data) {
if (err) {
return callback(err);
diff --git a/src/database/redis/hash.js b/src/database/redis/hash.js
index a728852f1a..f679f7637d 100644
--- a/src/database/redis/hash.js
+++ b/src/database/redis/hash.js
@@ -6,6 +6,14 @@ module.exports = function (redisClient, module) {
module.setObject = function (key, data, callback) {
callback = callback || function () {};
+ if (!key || !data) {
+ return callback();
+ }
+ Object.keys(data).forEach(function (key) {
+ if (data[key] === undefined) {
+ delete data[key];
+ }
+ });
redisClient.hmset(key, data, function (err) {
callback(err);
});
diff --git a/src/database/redis/sorted.js b/src/database/redis/sorted.js
index 576b2fe363..2230f0498a 100644
--- a/src/database/redis/sorted.js
+++ b/src/database/redis/sorted.js
@@ -51,6 +51,9 @@ module.exports = function (redisClient, module) {
module.sortedSetRemove = function (key, value, callback) {
callback = callback || function () {};
+ if (!value) {
+ return callback();
+ }
if (!Array.isArray(value)) {
value = [value];
}
diff --git a/src/plugins/install.js b/src/plugins/install.js
index 44b9c3747b..c9b57909c9 100644
--- a/src/plugins/install.js
+++ b/src/plugins/install.js
@@ -107,7 +107,7 @@ module.exports = function (Plugins) {
if (err) {
return callback(err);
}
- winston.info('[plugins] ' + stdout);
+ winston.verbose('[plugins] ' + stdout);
callback();
});
}
diff --git a/src/user/admin.js b/src/user/admin.js
index 44aa72e059..8b5a6ebef4 100644
--- a/src/user/admin.js
+++ b/src/user/admin.js
@@ -28,7 +28,7 @@ module.exports = function (User) {
};
User.getUsersCSV = function (callback) {
- winston.info('[user/getUsersCSV] Compiling User CSV data');
+ winston.verbose('[user/getUsersCSV] Compiling User CSV data');
var csvContent = '';
var uids;
async.waterfall([
diff --git a/src/user/delete.js b/src/user/delete.js
index e03333d7c1..e648c5dfb0 100644
--- a/src/user/delete.js
+++ b/src/user/delete.js
@@ -15,6 +15,7 @@ module.exports = function (User) {
if (!parseInt(uid, 10)) {
return callback(new Error('[[error:invalid-uid]]'));
}
+
async.waterfall([
function (next) {
deletePosts(callerUid, uid, next);
@@ -48,6 +49,12 @@ module.exports = function (User) {
var userData;
async.waterfall([
function (next) {
+ User.exists(uid, next);
+ },
+ function (exists, next) {
+ if (!exists) {
+ return callback();
+ }
User.getUserFields(uid, ['username', 'userslug', 'fullname', 'email'], next);
},
function (_userData, next) {
diff --git a/src/user/digest.js b/src/user/digest.js
index 604bad9041..84cb8af489 100644
--- a/src/user/digest.js
+++ b/src/user/digest.js
@@ -1,6 +1,6 @@
"use strict";
-var async = require('async');
+var async = require('async');
var winston = require('winston');
var nconf = require('nconf');
@@ -57,7 +57,7 @@ var utils = require('../../public/src/utils');
if (err) {
winston.error('[user/jobs] Could not send digests (' + interval + '): ' + err.message);
} else {
- winston.info('[user/jobs] Digest (' + interval + ') scheduling completed. ' + subscribers.length + ' email(s) sent.');
+ winston.verbose('[user/jobs] Digest (' + interval + ') scheduling completed. ' + subscribers.length + ' email(s) sent.');
}
callback(err);
@@ -65,25 +65,27 @@ var utils = require('../../public/src/utils');
};
Digest.getSubscribers = function (interval, callback) {
- db.getSortedSetRange('digest:' + interval + ':uids', 0, -1, function (err, subscribers) {
- if (err) {
- return callback(err);
+ async.waterfall([
+ function (next) {
+ db.getSortedSetRange('digest:' + interval + ':uids', 0, -1, next);
+ },
+ function (subscribers, next) {
+ plugins.fireHook('filter:digest.subscribers', {
+ interval: interval,
+ subscribers: subscribers
+ }, next);
+ },
+ function (results, next) {
+ next(null, results.subscribers);
}
-
- plugins.fireHook('filter:digest.subscribers', {
- interval: interval,
- subscribers: subscribers
- }, function (err, returnData) {
- callback(err, returnData.subscribers);
- });
- });
+ ], callback);
};
Digest.send = function (data, callback) {
if (!data || !data.subscribers || !data.subscribers.length) {
return callback();
}
- var now = new Date();
+ var now = new Date();
async.waterfall([
function (next) {
diff --git a/test/database/hash.js b/test/database/hash.js
index d00d746e77..811f5254e7 100644
--- a/test/database/hash.js
+++ b/test/database/hash.js
@@ -24,6 +24,24 @@ describe('Hash methods', function () {
done();
});
});
+
+ it('should do nothing if key is falsy', function (done) {
+ db.setObject('', {foo: 1, derp: 2}, function (err) {
+ assert.ifError(err);
+ done();
+ });
+ });
+
+ it('should do nothing if data is falsy', function (done) {
+ db.setObject('falsy', null, function (err) {
+ assert.ifError(err);
+ db.exists('falsy', function (err, exists) {
+ assert.ifError(err);
+ assert.equal(exists, false);
+ done();
+ });
+ });
+ });
});
describe('setObjectField()', function () {
diff --git a/test/messaging.js b/test/messaging.js
index e3680caa92..16f611821d 100644
--- a/test/messaging.js
+++ b/test/messaging.js
@@ -14,15 +14,16 @@ var helpers = require('./helpers');
describe('Messaging Library', function () {
- var testUids;
+ //var testUids;
var fooUid;
var bazUid;
var herpUid;
var roomId;
before(function (done) {
+ Groups.resetCache();
// Create 3 users: 1 admin, 2 regular
- async.parallel([
+ async.series([
async.apply(User.create, { username: 'foo', password: 'barbar' }), // admin
async.apply(User.create, { username: 'baz', password: 'quuxquux' }), // restricted user
async.apply(User.create, { username: 'herp', password: 'derpderp' }) // regular user
@@ -31,36 +32,29 @@ describe('Messaging Library', function () {
return done(err);
}
- testUids = uids;
fooUid = uids[0];
bazUid = uids[1];
herpUid = uids[2];
async.parallel([
- async.apply(Groups.join, 'administrators', uids[0]),
- async.apply(User.setSetting, testUids[1], 'restrictChat', '1')
+ async.apply(Groups.join, 'administrators', fooUid),
+ async.apply(User.setSetting, bazUid, 'restrictChat', '1')
], done);
});
});
describe('.canMessage()', function () {
- it('should not error out', function (done) {
- Messaging.canMessageUser(testUids[1], testUids[2], function (err) {
- assert.ifError(err);
- done();
- });
- });
-
it('should allow messages to be sent to an unrestricted user', function (done) {
- Messaging.canMessageUser(testUids[1], testUids[2], function (err) {
+ Messaging.canMessageUser(bazUid, herpUid, function (err) {
assert.ifError(err);
done();
});
});
it('should NOT allow messages to be sent to a restricted user', function (done) {
- User.setSetting(testUids[1], 'restrictChat', '1', function () {
- Messaging.canMessageUser(testUids[2], testUids[1], function (err) {
+ User.setSetting(bazUid, 'restrictChat', '1', function (err) {
+ assert.ifError(err);
+ Messaging.canMessageUser(herpUid, bazUid, function (err) {
assert.strictEqual(err.message, '[[error:chat-restricted]]');
done();
});
@@ -68,15 +62,15 @@ describe('Messaging Library', function () {
});
it('should always allow admins through', function (done) {
- Messaging.canMessageUser(testUids[0], testUids[1], function (err) {
+ Messaging.canMessageUser(fooUid, bazUid, function (err) {
assert.ifError(err);
done();
});
});
it('should allow messages to be sent to a restricted user if restricted user follows sender', function (done) {
- User.follow(testUids[1], testUids[2], function () {
- Messaging.canMessageUser(testUids[2], testUids[1], function (err) {
+ User.follow(bazUid, herpUid, function () {
+ Messaging.canMessageUser(herpUid, bazUid, function (err) {
assert.ifError(err);
done();
});
diff --git a/test/topics.js b/test/topics.js
index 8dfc024f64..4972257f5b 100644
--- a/test/topics.js
+++ b/test/topics.js
@@ -18,6 +18,7 @@ describe('Topic\'s', function () {
var adminUid;
before(function (done) {
+ groups.resetCache();
User.create({username: 'admin'}, function (err, uid) {
if (err) {
return done(err);
diff --git a/test/user.js b/test/user.js
index 8b133301fe..bf0649bb7d 100644
--- a/test/user.js
+++ b/test/user.js
@@ -573,17 +573,27 @@ describe('User', function () {
});
});
-
- it('should send digests', function (done) {
- User.updateDigestSetting(testUid, 'day', function (err) {
- assert.ifError(err);
- User.digest.execute('day', function (err) {
+ describe('digests', function () {
+ var uid;
+ before(function (done) {
+ User.create({username: 'digestuser', email: '[email protected]'}, function (err, _uid) {
assert.ifError(err);
+ uid = _uid;
done();
});
});
- });
+ it('should send digests', function (done) {
+ User.updateDigestSetting(uid, 'day', function (err) {
+ assert.ifError(err);
+ User.digest.execute('day', function (err) {
+ assert.ifError(err);
+ done();
+ });
+ });
+ });
+
+ });
after(function (done) {