From caaa72b7529f09311a489c06c2df22d508701014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 27 Nov 2017 12:52:08 -0500 Subject: [PATCH] closes #6124 --- src/user/profile.js | 5 ++++- test/user.js | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/user/profile.js b/src/user/profile.js index 70dffeebe6..ae1e31c475 100644 --- a/src/user/profile.js +++ b/src/user/profile.js @@ -196,7 +196,7 @@ module.exports = function (User) { function updateUsername(uid, newUsername, callback) { if (!newUsername) { - return callback(); + return setImmediate(callback); } async.waterfall([ @@ -204,6 +204,9 @@ module.exports = function (User) { User.getUserFields(uid, ['username', 'userslug'], next); }, function (userData, next) { + if (userData.username === newUsername) { + return callback(); + } async.parallel([ function (next) { updateUidMapping('username', uid, newUsername, userData.username, next); diff --git a/test/user.js b/test/user.js index 0decbfe0f6..0db0b69840 100644 --- a/test/user.js +++ b/test/user.js @@ -627,6 +627,19 @@ describe('User', function () { }); }); + it('should not update a user\'s username if it did not change', function (done) { + socketUser.changeUsernameEmail({ uid: uid }, { uid: uid, username: 'updatedAgain', password: '123456' }, function (err) { + assert.ifError(err); + db.getSortedSetRevRange('user:' + uid + ':usernames', 0, -1, function (err, data) { + assert.ifError(err); + console.log(data); + assert(data[0].startsWith('updatedAgain')); + assert(data[1].startsWith('updatedUserName')); + done(); + }); + }); + }); + it('should change email', function (done) { socketUser.changeUsernameEmail({ uid: uid }, { uid: uid, email: 'updatedAgain@me.com', password: '123456' }, function (err) { assert.ifError(err);