mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-14 19:47:03 +00:00
Repair negative quest scrolls on (gem)purchase (#11399)
* Fix: Reset negative quest scrolls number to zero on purchase(gem) * Refactor: rename website/common/script/ops/buy/buyQuest.js to website/common/script/ops/buy/buyQuestGold.js and update related files * Test: add two tests related to negative quest scrolls
This commit is contained in:
parent
916ebcacff
commit
ca7399f6c1
5 changed files with 24 additions and 3 deletions
|
|
@ -49,6 +49,15 @@ describe('shared.ops.buyQuestGems', () => {
|
|||
|
||||
buyQuest(user, {params: {key}});
|
||||
|
||||
expect(user.items.quests[key]).to.equal(1);
|
||||
expect(pinnedGearUtils.removeItemByPath.notCalled).to.equal(true);
|
||||
});
|
||||
it('if a user\'s count of a quest scroll is negative, it will be reset to 0 before incrementing when they buy a new one.', () => {
|
||||
let key = 'dustbunnies';
|
||||
user.items.quests[key] = -1;
|
||||
|
||||
buyQuest(user, {params: {key}});
|
||||
|
||||
expect(user.items.quests[key]).to.equal(1);
|
||||
expect(pinnedGearUtils.removeItemByPath.notCalled).to.equal(true);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
generateUser,
|
||||
} from '../../../helpers/common.helper';
|
||||
import {BuyQuestWithGoldOperation} from '../../../../website/common/script/ops/buy/buyQuest';
|
||||
import {BuyQuestWithGoldOperation} from '../../../../website/common/script/ops/buy/buyQuestGold';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
|
|
@ -43,6 +43,18 @@ describe('shared.ops.buyQuest', () => {
|
|||
expect(analytics.track).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('if a user\'s count of a quest scroll is negative, it will be reset to 0 before incrementing when they buy a new one.', () => {
|
||||
user.stats.gp = 205;
|
||||
let key = 'dilatoryDistress1';
|
||||
user.items.quests[key] = -1;
|
||||
buyQuest(user, {
|
||||
params: {key},
|
||||
}, analytics);
|
||||
expect(user.items.quests[key]).to.equal(1);
|
||||
expect(user.stats.gp).to.equal(5);
|
||||
expect(analytics.track).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('buys a Quest scroll with the right quantity if a string is passed for quantity', () => {
|
||||
user.stats.gp = 1000;
|
||||
buyQuest(user, {
|
||||
|
|
@ -6,7 +6,7 @@ import {BuyArmoireOperation} from './buyArmoire';
|
|||
import {BuyHealthPotionOperation} from './buyHealthPotion';
|
||||
import {BuyMarketGearOperation} from './buyMarketGear';
|
||||
import buyMysterySet from './buyMysterySet';
|
||||
import {BuyQuestWithGoldOperation} from './buyQuest';
|
||||
import {BuyQuestWithGoldOperation} from './buyQuestGold';
|
||||
import {BuySpellOperation} from './buySpell';
|
||||
import purchaseOp from './purchase';
|
||||
import hourglassPurchase from './hourglassPurchase';
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ export class BuyQuestWithGemOperation extends AbstractGemItemOperation {
|
|||
}
|
||||
|
||||
executeChanges (user, item, req) {
|
||||
user.items.quests[item.key] = user.items.quests[item.key] || 0;
|
||||
if (!user.items.quests[item.key] || user.items.quests[item.key] < 0) user.items.quests[item.key] = 0;
|
||||
user.items.quests[item.key] += this.quantity;
|
||||
if (user.markModified) user.markModified('items.quests');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue