Allow user to buy numbered special gear (#9823)

* fix(buy): allow user to buy numbered special gear

* fix(buy): correct content constant
This commit is contained in:
Sabe Jones
2018-01-29 15:02:55 -06:00
committed by GitHub
parent 23dd402e79
commit 99ab9726b4
2 changed files with 24 additions and 3 deletions

View File

@@ -138,5 +138,27 @@ describe('shared.ops.buyGear', () => {
done();
}
});
it('does not buyGear equipment if user does not own prior item in sequence', (done) => {
user.stats.gp = 200;
try {
buyGear(user, {params: {key: 'armor_warrior_2'}});
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('previousGearNotOwned'));
expect(user.items.gear.owned).to.not.have.property('armor_warrior_2');
done();
}
});
it('does buyGear equipment if item is a numbered special item user qualifies for', () => {
user.stats.gp = 200;
user.items.gear.owned.head_special_2 = false;
buyGear(user, {params: {key: 'head_special_2'}});
expect(user.items.gear.owned).to.have.property('head_special_2', true);
});
});
});

View File

@@ -37,10 +37,10 @@ module.exports = function buyGear (user, req = {}, analytics) {
let itemIndex = Number(item.index);
if (Number.isInteger(itemIndex)) {
if (Number.isInteger(itemIndex) && content.classes.includes(item.klass)) {
let previousLevelGear = key.replace(/[0-9]/, itemIndex - 1);
let hasPreviousLevelGear = user.items.gear.owned[previousLevelGear];
let checkIndexToType = itemIndex > (item.type === 'weapon' ? 0 : 1);
let checkIndexToType = itemIndex > (item.type === 'weapon' || item.type === 'shield' && item.klass === 'rogue' ? 0 : 1);
if (checkIndexToType && !hasPreviousLevelGear) {
throw new NotAuthorized(i18n.t('previousGearNotOwned', req.language));
@@ -52,7 +52,6 @@ module.exports = function buyGear (user, req = {}, analytics) {
message = handleTwoHanded(user, item, undefined, req);
}
removePinnedGearAddPossibleNewOnes(user, `gear.flat.${item.key}`, item.key);
if (item.last) ultimateGear(user);