From 6fdad4b0023c80cf838b5c93369a01ba0845d07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 13 May 2017 22:12:52 -0400 Subject: [PATCH] fix test on redis --- src/socket.io/user.js | 6 ++---- test/user.js | 43 ++++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 21 deletions(-) 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(); }); }); });