mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
prevent buying market gear if class doesn't match (#10818)
* prevent buying market gear if class doesn't match * add test
This commit is contained in:
@@ -53,4 +53,15 @@ describe('POST /user/buy-gear/:key', () => {
|
|||||||
message: 'You need to purchase a lower level gear before this one.',
|
message: 'You need to purchase a lower level gear before this one.',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns an error if tries to buy gear from a different class', async () => {
|
||||||
|
let key = 'armor_rogue_1';
|
||||||
|
|
||||||
|
return expect(user.post(`/user/buy-gear/${key}`))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
error: 'NotAuthorized',
|
||||||
|
message: 'You can\'t buy this item.',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,6 +24,15 @@ export class BuyMarketGearOperation extends AbstractGoldItemOperation {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canUserPurchase (user, item) {
|
||||||
|
super.canUserPurchase(user, item);
|
||||||
|
|
||||||
|
// check for different class gear
|
||||||
|
if (item.klass !== 'special' && item.klass !== user.stats.class) {
|
||||||
|
throw new NotAuthorized(this.i18n('cannotBuyItem'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extractAndValidateParams (user, req) {
|
extractAndValidateParams (user, req) {
|
||||||
let key = this.key = get(req, 'params.key');
|
let key = this.key = get(req, 'params.key');
|
||||||
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
||||||
|
|||||||
Reference in New Issue
Block a user