mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-13 17:52:22 +00:00
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
This commit is contained in:
parent
f713bf53c1
commit
7297a6fa76
2 changed files with 34 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue