From b0ae0ef4da7000156c5a019a9bb49a1050cf4601 Mon Sep 17 00:00:00 2001 From: negue Date: Fri, 16 Feb 2018 17:56:05 +0100 Subject: [PATCH] HOTFIX: purchase marketGear (#9992) * fix purchase marketGear * test marketGear purchase in the client --- test/client/unit/specs/store/actions/shops.js | 55 +++++++++++++++++++ website/client/store/actions/shops.js | 6 +- 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 test/client/unit/specs/store/actions/shops.js diff --git a/test/client/unit/specs/store/actions/shops.js b/test/client/unit/specs/store/actions/shops.js new file mode 100644 index 0000000000..2d49f880a9 --- /dev/null +++ b/test/client/unit/specs/store/actions/shops.js @@ -0,0 +1,55 @@ +import axios from 'axios'; +import generateStore from 'client/store'; + +import content from 'common/script/content'; +import getItemInfo from 'common/script/libs/getItemInfo'; + +import getOfficialPinnedItems from 'common/script/libs/getOfficialPinnedItems'; + +describe('shops actions', () => { + let store; + + beforeEach(() => { + store = generateStore(); + }); + + describe('genericPurchase', () => { + it('buy gear', async () => { + let user = { + id: 1, + stats: { + class: 'rogue', + }, + items: { + gear: { + owned: {}, + equipped: {}, + }, + }, + pinnedItems: [], + preferences: { + autoEquip: true, + }, + }; + + store.state.user.data = user; + + // select a gear item + let gearItem = content.gear.flat.armor_rogue_1; + + let item = getItemInfo(user, 'marketGear', gearItem, getOfficialPinnedItems(user)); + + sandbox.stub(axios, 'post').withArgs('/api/v3/user/buy/armor_rogue_1').returns(Promise.resolve({data: {data: {}}})); + + await store.dispatch('shops:genericPurchase', { + pinType: item.pinType, + type: item.purchaseType, + key: item.key, + currency: item.currency, + quantity: 1, + }); + + expect(store.state.user.data.item.equipped.armor_rogue_1).to.equal(true); + }); + }); +}); diff --git a/website/client/store/actions/shops.js b/website/client/store/actions/shops.js index 3045742653..554694f499 100644 --- a/website/client/store/actions/shops.js +++ b/website/client/store/actions/shops.js @@ -11,7 +11,7 @@ import { getDropClass } from 'client/libs/notifications'; // @TODO: Purchase means gems and buy means gold. That wording is misused below, but we should also change // the generic buy functions to something else. Or have a Gold Vendor and Gem Vendor, etc -export function buyItem (store, params) { +function buyItem (store, params) { const quantity = params.quantity || 1; const user = store.state.user.data; @@ -151,7 +151,9 @@ export async function genericPurchase (store, params) { return store.dispatch('user:rebirth'); case 'potion': case 'marketGear': - return buyItem(store, params); + // 'marketGear' gets `type`= `gear` which is used for gem-purchasable gear + // resetting type to pinType only here + return buyItem(store, {...params, type: params.pinType}); case 'background': return unlock(store, { query: {