AbstractGemItemOperation - BuyQuestWithGemOperation (#10476)
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import pinnedGearUtils from '../../../../website/common/script/ops/pinnedGearUtils';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../../../../website/common/script/libs/errors';
|
||||
import i18n from '../../../../website/common/script/i18n';
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../../helpers/common.helper';
|
||||
import {BuyQuestWithGemOperation} from '../../../../website/common/script/ops/buy/buyQuestGem';
|
||||
|
||||
describe('shared.ops.buyQuestGems', () => {
|
||||
let user;
|
||||
let goldPoints = 40;
|
||||
let analytics = {track () {}};
|
||||
|
||||
function buyQuest (_user, _req, _analytics) {
|
||||
const buyOp = new BuyQuestWithGemOperation(_user, _req, _analytics);
|
||||
|
||||
return buyOp.purchase();
|
||||
}
|
||||
|
||||
before(() => {
|
||||
user = generateUser({'stats.class': 'rogue'});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
sinon.stub(analytics, 'track');
|
||||
sinon.spy(pinnedGearUtils, 'removeItemByPath');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
analytics.track.restore();
|
||||
pinnedGearUtils.removeItemByPath.restore();
|
||||
});
|
||||
|
||||
context('successful purchase', () => {
|
||||
let userGemAmount = 10;
|
||||
|
||||
before(() => {
|
||||
user.balance = userGemAmount;
|
||||
user.stats.gp = goldPoints;
|
||||
user.purchased.plan.gemsBought = 0;
|
||||
user.purchased.plan.customerId = 'customer-id';
|
||||
user.pinnedItems.push({type: 'quests', key: 'gryphon'});
|
||||
});
|
||||
|
||||
it('purchases quests', () => {
|
||||
let key = 'gryphon';
|
||||
|
||||
buyQuest(user, {params: {key}});
|
||||
|
||||
expect(user.items.quests[key]).to.equal(1);
|
||||
expect(pinnedGearUtils.removeItemByPath.notCalled).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
context('bulk purchase', () => {
|
||||
let userGemAmount = 10;
|
||||
|
||||
beforeEach(() => {
|
||||
user.balance = userGemAmount;
|
||||
user.stats.gp = goldPoints;
|
||||
user.purchased.plan.gemsBought = 0;
|
||||
user.purchased.plan.customerId = 'customer-id';
|
||||
});
|
||||
|
||||
it('errors when user does not have enough gems', (done) => {
|
||||
user.balance = 1;
|
||||
let key = 'gryphon';
|
||||
|
||||
try {
|
||||
buyQuest(user, {
|
||||
params: {key},
|
||||
quantity: 2,
|
||||
});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('notEnoughGems'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('makes bulk purchases of quests', () => {
|
||||
let key = 'gryphon';
|
||||
|
||||
buyQuest(user, {
|
||||
params: {key},
|
||||
quantity: 3,
|
||||
});
|
||||
|
||||
expect(user.items.quests[key]).to.equal(4);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -121,7 +121,6 @@ describe('shared.ops.purchase', () => {
|
||||
user.pinnedItems.push({type: 'eggs', key: 'Wolf'});
|
||||
user.pinnedItems.push({type: 'hatchingPotions', key: 'Base'});
|
||||
user.pinnedItems.push({type: 'food', key: SEASONAL_FOOD});
|
||||
user.pinnedItems.push({type: 'quests', key: 'gryphon'});
|
||||
user.pinnedItems.push({type: 'gear', key: 'headAccessory_special_tigerEars'});
|
||||
user.pinnedItems.push({type: 'bundles', key: 'featheredFriends'});
|
||||
});
|
||||
@@ -157,16 +156,6 @@ describe('shared.ops.purchase', () => {
|
||||
expect(pinnedGearUtils.removeItemByPath.notCalled).to.equal(true);
|
||||
});
|
||||
|
||||
it('purchases quests', () => {
|
||||
let type = 'quests';
|
||||
let key = 'gryphon';
|
||||
|
||||
purchase(user, {params: {type, key}});
|
||||
|
||||
expect(user.items[type][key]).to.equal(1);
|
||||
expect(pinnedGearUtils.removeItemByPath.notCalled).to.equal(true);
|
||||
});
|
||||
|
||||
it('purchases gear', () => {
|
||||
let type = 'gear';
|
||||
let key = 'headAccessory_special_tigerEars';
|
||||
|
||||
Reference in New Issue
Block a user