mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
multiple test fixes
This commit is contained in:
@@ -171,6 +171,9 @@
|
||||
};
|
||||
|
||||
module.info = function (db, callback) {
|
||||
if (!db) {
|
||||
return callback();
|
||||
}
|
||||
async.parallel({
|
||||
serverStatus: function (next) {
|
||||
db.command({'serverStatus': 1}, next);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -127,6 +127,9 @@
|
||||
};
|
||||
|
||||
module.info = function (cxn, callback) {
|
||||
if (!cxn) {
|
||||
return callback();
|
||||
}
|
||||
cxn.info(function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ module.exports = function (Plugins) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
winston.info('[plugins] ' + stdout);
|
||||
winston.verbose('[plugins] ' + stdout);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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([
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
22
test/user.js
22
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: 'test@example.com'}, 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) {
|
||||
|
||||
Reference in New Issue
Block a user