From c2b370f4d355eb03cadd1822bca6099df68969fd Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Mon, 10 Jun 2024 11:23:46 +0200 Subject: [PATCH] handle error from invalid input --- test/common/ops/{unlock.js => unlock.test.js} | 11 ++++++++++- website/common/script/ops/unlock.js | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) rename test/common/ops/{unlock.js => unlock.test.js} (97%) diff --git a/test/common/ops/unlock.js b/test/common/ops/unlock.test.js similarity index 97% rename from test/common/ops/unlock.js rename to test/common/ops/unlock.test.js index 9ac8d1900e..b48c48f8a1 100644 --- a/test/common/ops/unlock.js +++ b/test/common/ops/unlock.test.js @@ -36,7 +36,7 @@ describe('shared.ops.unlock', () => { } }); - it('does not unlock lost gear', async () => { + it('does not unlock lost gear', async () => { user.items.gear.owned.headAccessory_special_bearEars = false; await unlock(user, { @@ -345,4 +345,13 @@ describe('shared.ops.unlock', () => { expect(get(user.purchased, backgroundUnlockPath)).to.be.true; expect(user.balance).to.equal(usersStartingGems - 1.75); }); + + it('handles an invalid hair path gracefully', async () => { + try { + await unlock(user, { query: { path: 'hair.invalid' } }); + } catch (err) { + expect(err).to.be.an.instanceof(BadRequest); + expect(err.message).to.equal(i18n.t('invalidUnlockSet')); + } + }); }); diff --git a/website/common/script/ops/unlock.js b/website/common/script/ops/unlock.js index 3d57273cab..4e5d7c3692 100644 --- a/website/common/script/ops/unlock.js +++ b/website/common/script/ops/unlock.js @@ -36,6 +36,7 @@ function getItemByPath (path, setType) { if (setType === 'hair') { // itemPathParent is in this format: hair.purple const hairType = itemPathParent.split('.')[1]; + if (!content.appearances.hair[hairType]) return null; return content.appearances.hair[hairType][itemKey]; }