mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
handle error from invalid input
This commit is contained in:
@@ -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;
|
user.items.gear.owned.headAccessory_special_bearEars = false;
|
||||||
|
|
||||||
await unlock(user, {
|
await unlock(user, {
|
||||||
@@ -345,4 +345,13 @@ describe('shared.ops.unlock', () => {
|
|||||||
expect(get(user.purchased, backgroundUnlockPath)).to.be.true;
|
expect(get(user.purchased, backgroundUnlockPath)).to.be.true;
|
||||||
expect(user.balance).to.equal(usersStartingGems - 1.75);
|
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'));
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -36,6 +36,7 @@ function getItemByPath (path, setType) {
|
|||||||
if (setType === 'hair') {
|
if (setType === 'hair') {
|
||||||
// itemPathParent is in this format: hair.purple
|
// itemPathParent is in this format: hair.purple
|
||||||
const hairType = itemPathParent.split('.')[1];
|
const hairType = itemPathParent.split('.')[1];
|
||||||
|
if (!content.appearances.hair[hairType]) return null;
|
||||||
return content.appearances.hair[hairType][itemKey];
|
return content.appearances.hair[hairType][itemKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user