From 16c8825b2b21a64be3672b5dc28a2457e8ca488d Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Sun, 6 Oct 2019 17:08:11 +0200 Subject: [PATCH] Hall Fixes (#11403) * fix(hall): correctly casts owned gear and mounts * typo --- test/api/unit/libs/items/utils.test.js | 15 ++++++++++++--- website/server/libs/items/utils.js | 12 ++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/test/api/unit/libs/items/utils.test.js b/test/api/unit/libs/items/utils.test.js index 3238fbd1dc..6a0e7ce34d 100644 --- a/test/api/unit/libs/items/utils.test.js +++ b/test/api/unit/libs/items/utils.test.js @@ -100,14 +100,23 @@ describe('Items Utils', () => { }); it('converts values for mounts paths to numbers', () => { - expect(castItemVal('items.mounts.Cactus-Base', '5')).to.equal(5); - expect(castItemVal('items.mounts.Aether-Invisible', '5')).to.equal(5); - expect(castItemVal('items.mounts.Aether-Invalid', '5')).to.equal(5); + expect(castItemVal('items.mounts.Cactus-Base', 'true')).to.equal(true); + expect(castItemVal('items.mounts.Aether-Invisible', 'false')).to.equal(false); + expect(castItemVal('items.mounts.Aether-Invalid', 'true')).to.equal(true); + expect(castItemVal('items.mounts.Aether-Invalid', 'truish')).to.equal(true); + expect(castItemVal('items.mounts.Aether-Invalid', 0)).to.equal(false); }); it('converts values for quests paths to numbers', () => { expect(castItemVal('items.quests.atom3', '5')).to.equal(5); expect(castItemVal('items.quests.invalid', '5')).to.equal(5); }); + + it('converts values for owned gear', () => { + expect(castItemVal('items.gear.owned.shield_warrior_0', 'true')).to.equal(true); + expect(castItemVal('items.gear.owned.invalid', 'false')).to.equal(false); + expect(castItemVal('items.gear.owned.invalid', 'thruthy')).to.equal(true); + expect(castItemVal('items.gear.owned.invalid', 0)).to.equal(false); + }); }); }); diff --git a/website/server/libs/items/utils.js b/website/server/libs/items/utils.js index 308bfcc8a7..cfa2b19bc2 100644 --- a/website/server/libs/items/utils.js +++ b/website/server/libs/items/utils.js @@ -60,18 +60,26 @@ export function validateItemPath (itemPath) { // value to the correct format. // Example a numeric string like "5" applied to a food item (expecting an interger) // will be converted to the number 5 -// TODO cast the correct value for `items.gear.owned` export function castItemVal (itemPath, itemVal) { if ( itemPath.indexOf('items.pets') === 0 || itemPath.indexOf('items.eggs') === 0 || itemPath.indexOf('items.hatchingPotions') === 0 || itemPath.indexOf('items.food') === 0 || - itemPath.indexOf('items.mounts') === 0 || itemPath.indexOf('items.quests') === 0 ) { return Number(itemVal); } + if ( + itemPath.indexOf('items.mounts') === 0 || + itemPath.indexOf('items.gear.owned') === 0 + ) { + if (itemVal === 'true') return true; + if (itemVal === 'false') return false; + + return Boolean(itemVal); + } + return itemVal; } \ No newline at end of file