Skip to content

Node.js based forum software built for the modern web

fix test on redis

Barış Soner Uşaklı6fdad4b0023c
diff --git a/src/socket.io/user.js b/src/socket.io/user.js
index a2e4413c9a..9777c46f05 100644
--- a/src/socket.io/user.js
+++ b/src/socket.io/user.js
@@ -15,7 +15,7 @@ var db = require('../database');
var userController = require('../controllers/user');
var privileges = require('../privileges');
-var SocketUser = {};
+var SocketUser = module.exports;
require('./user/profile')(SocketUser);
require('./user/search')(SocketUser);
@@ -327,7 +327,7 @@ SocketUser.setModerationNote = function (socket, data, callback) {
},
function (allowed, next) {
if (allowed) {
- return next(null, allowed);
+ return setImmediate(next, null, allowed);
}
user.isModeratorOfAnyCategory(socket.uid, next);
@@ -346,5 +346,3 @@ SocketUser.setModerationNote = function (socket, data, callback) {
},
], callback);
};
-
-module.exports = SocketUser;
diff --git a/test/user.js b/test/user.js
index bfef9a1178..1cdcce717b 100644
--- a/test/user.js
+++ b/test/user.js
@@ -975,24 +975,33 @@ describe('User', function () {
});
it('should set moderation note', function (done) {
- User.create({ username: 'noteadmin' }, function (err, adminUid) {
+ var adminUid;
+ async.waterfall([
+ function (next) {
+ User.create({ username: 'noteadmin' }, next);
+ },
+ function (_adminUid, next) {
+ adminUid = _adminUid;
+ groups.join('administrators', adminUid, next);
+ },
+ function (next) {
+ socketUser.setModerationNote({ uid: adminUid }, { uid: testUid, note: 'this is a test user' }, next);
+ },
+ function (next) {
+ setTimeout(next, 50);
+ },
+ function (next) {
+ socketUser.setModerationNote({ uid: adminUid }, { uid: testUid, note: 'second moderation note' }, next);
+ },
+ function (next) {
+ User.getModerationNotes(testUid, 0, -1, next);
+ },
+ ], function (err, notes) {
assert.ifError(err);
- groups.join('administrators', adminUid, function (err) {
- assert.ifError(err);
- socketUser.setModerationNote({ uid: adminUid }, { uid: testUid, note: 'this is a test user' }, function (err) {
- assert.ifError(err);
- socketUser.setModerationNote({ uid: adminUid }, { uid: testUid, note: 'second moderation note' }, function (err) {
- assert.ifError(err);
- User.getModerationNotes(testUid, 0, -1, function (err, notes) {
- assert.ifError(err);
- assert.equal(notes[0].note, 'second moderation note');
- assert.equal(notes[0].uid, adminUid);
- assert(notes[0].timestamp);
- done();
- });
- });
- });
- });
+ assert.equal(notes[0].note, 'second moderation note');
+ assert.equal(notes[0].uid, adminUid);
+ assert(notes[0].timestamp);
+ done();
});
});
});