handle error from invalid input

This commit is contained in:
Phillip Thelen
2024-06-10 11:23:46 +02:00
parent 3313584d60
commit c2b370f4d3
2 changed files with 11 additions and 1 deletions

View File

@@ -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'));
}
});
});

View File

@@ -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];
}