From 7297a6fa762e0677e7a5985730e9262a8e050cc0 Mon Sep 17 00:00:00 2001 From: Keith Holliday Date: Wed, 25 May 2016 13:52:17 +0100 Subject: [PATCH] Updated logic to not assign armoire incorrectly (#7476) * Updated logic to not assign armoire incorrectly * Updated test and added new test to ensure armorie is not enabled prematurely. * Fixed linting issue * Removed toObject from being called when called on the server --- common/script/fns/ultimateGear.js | 11 ++++++++++- test/common/fns/ultimateGear.js | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/common/script/fns/ultimateGear.js b/common/script/fns/ultimateGear.js index be5553201d..5bca8ff912 100644 --- a/common/script/fns/ultimateGear.js +++ b/common/script/fns/ultimateGear.js @@ -15,7 +15,16 @@ module.exports = function ultimateGear (user) { } }); - if (_.contains(user.achievements.ultimateGearSets, true) && user.flags.armoireEnabled !== true) { + let ultimateGearSetValues; + if (user.achievements.ultimateGearSets.toObject) { + ultimateGearSetValues = Object.values(user.achievements.ultimateGearSets.toObject()); + } else { + ultimateGearSetValues = Object.values(user.achievements.ultimateGearSets); + } + + let hasFullSet = _.includes(ultimateGearSetValues, true); + + if (hasFullSet && user.flags.armoireEnabled !== true) { user.flags.armoireEnabled = true; } diff --git a/test/common/fns/ultimateGear.js b/test/common/fns/ultimateGear.js index 8da991b565..242b57f3c1 100644 --- a/test/common/fns/ultimateGear.js +++ b/test/common/fns/ultimateGear.js @@ -8,6 +8,9 @@ describe('shared.fns.ultimateGear', () => { beforeEach(() => { user = generateUser(); + user.achievements.ultimateGearSets.toObject = function () { + return this; + }; }); it('sets armoirEnabled when partial achievement already achieved', () => { @@ -30,4 +33,25 @@ describe('shared.fns.ultimateGear', () => { ultimateGear(user); expect(user.flags.armoireEnabled).to.equal(true); }); + + it('does not set armoirEnabled when gear is not owned', () => { + let items = { + gear: { + owned: { + toObject: () => { + return { + armor_warrior_5: true, // eslint-disable-line camelcase + shield_warrior_5: true, // eslint-disable-line camelcase + head_warrior_5: true, // eslint-disable-line camelcase + weapon_warrior_6: false, // eslint-disable-line camelcase + }; + }, + }, + }, + }; + + user.items = items; + ultimateGear(user); + expect(user.flags.armoireEnabled).to.equal(false); + }); });