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:
cheng-shiqi
2019-10-06 23:06:02 +08:00
committed by Matteo Pagliazzi
parent 916ebcacff
commit ca7399f6c1
5 changed files with 24 additions and 3 deletions

View File

@@ -49,6 +49,15 @@ describe('shared.ops.buyQuestGems', () => {
buyQuest(user, {params: {key}}); 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(user.items.quests[key]).to.equal(1);
expect(pinnedGearUtils.removeItemByPath.notCalled).to.equal(true); expect(pinnedGearUtils.removeItemByPath.notCalled).to.equal(true);
}); });

View File

@@ -1,7 +1,7 @@
import { import {
generateUser, generateUser,
} from '../../../helpers/common.helper'; } from '../../../helpers/common.helper';
import {BuyQuestWithGoldOperation} from '../../../../website/common/script/ops/buy/buyQuest'; import {BuyQuestWithGoldOperation} from '../../../../website/common/script/ops/buy/buyQuestGold';
import { import {
BadRequest, BadRequest,
NotAuthorized, NotAuthorized,
@@ -43,6 +43,18 @@ describe('shared.ops.buyQuest', () => {
expect(analytics.track).to.be.calledOnce; 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', () => { it('buys a Quest scroll with the right quantity if a string is passed for quantity', () => {
user.stats.gp = 1000; user.stats.gp = 1000;
buyQuest(user, { buyQuest(user, {

View File

@@ -6,7 +6,7 @@ import {BuyArmoireOperation} from './buyArmoire';
import {BuyHealthPotionOperation} from './buyHealthPotion'; import {BuyHealthPotionOperation} from './buyHealthPotion';
import {BuyMarketGearOperation} from './buyMarketGear'; import {BuyMarketGearOperation} from './buyMarketGear';
import buyMysterySet from './buyMysterySet'; import buyMysterySet from './buyMysterySet';
import {BuyQuestWithGoldOperation} from './buyQuest'; import {BuyQuestWithGoldOperation} from './buyQuestGold';
import {BuySpellOperation} from './buySpell'; import {BuySpellOperation} from './buySpell';
import purchaseOp from './purchase'; import purchaseOp from './purchase';
import hourglassPurchase from './hourglassPurchase'; import hourglassPurchase from './hourglassPurchase';

View File

@@ -46,7 +46,7 @@ export class BuyQuestWithGemOperation extends AbstractGemItemOperation {
} }
executeChanges (user, item, req) { 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; user.items.quests[item.key] += this.quantity;
if (user.markModified) user.markModified('items.quests'); if (user.markModified) user.markModified('items.quests');