From a6864a8055ae479ac3d764300e92da1b14d8bfbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 21 Nov 2018 23:34:08 -0500 Subject: [PATCH] add groupTitle test for guests --- src/user/data.js | 22 ++++++++++++++++------ test/user.js | 9 +++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/user/data.js b/src/user/data.js index 32ffe0624a..ec3a51000f 100644 --- a/src/user/data.js +++ b/src/user/data.js @@ -141,9 +141,6 @@ module.exports = function (User) { db.parseIntFields(user, intFields, requestedFields); - if (user.hasOwnProperty('groupTitle')) { - parseGroupTitle(user); - } if (user.hasOwnProperty('username')) { user.username = validator.escape(user.username ? user.username.toString() : ''); } @@ -155,6 +152,11 @@ module.exports = function (User) { user.picture = User.getDefaultAvatar(); user['icon:text'] = '?'; user['icon:bgColor'] = '#aaa'; + user.groupTitle = ''; + } + + if (user.hasOwnProperty('groupTitle')) { + parseGroupTitle(user); } if (user.picture && user.picture === user.uploadedpicture) { @@ -204,12 +206,20 @@ module.exports = function (User) { try { user.groupTitleArray = JSON.parse(user.groupTitle); } catch (err) { - user.groupTitleArray = [user.groupTitle]; + if (user.groupTitle) { + user.groupTitleArray = [user.groupTitle]; + } else { + user.groupTitleArray = []; + } } if (!Array.isArray(user.groupTitleArray)) { - user.groupTitleArray = [user.groupTitleArray]; + if (user.groupTitleArray) { + user.groupTitleArray = [user.groupTitleArray]; + } else { + user.groupTitleArray = []; + } } - if (!meta.config.allowMultipleBadges) { + if (!meta.config.allowMultipleBadges && user.groupTitleArray.length) { user.groupTitleArray = [user.groupTitleArray[0]]; } } diff --git a/test/user.js b/test/user.js index ef349acccd..387b038ba2 100644 --- a/test/user.js +++ b/test/user.js @@ -605,6 +605,15 @@ describe('User', function () { done(); }); }); + + it('should not get groupTitle for guests', function (done) { + User.getUserData(0, function (err, userData) { + assert.ifError(err); + assert.strictEqual(userData.groupTitle, ''); + assert.deepStrictEqual(userData.groupTitleArray, []); + done(); + }); + }); }); describe('not logged in', function () {