From b676fc0b71b9210263fa6b300c599825a5880fa8 Mon Sep 17 00:00:00 2001 From: Alys Date: Mon, 16 May 2016 15:20:43 +1000 Subject: [PATCH] fix incorrect Armoire test; remove unneeded param details from apidocs; disambiguate health potion --- common/script/ops/buy.js | 2 +- common/script/ops/buyPotion.js | 2 +- .../user/POST-user_buy_armoire.test.js | 29 ++++++++----------- website/server/controllers/api-v3/user.js | 6 +--- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/common/script/ops/buy.js b/common/script/ops/buy.js index d62842acea..c79bd65e0d 100644 --- a/common/script/ops/buy.js +++ b/common/script/ops/buy.js @@ -12,7 +12,7 @@ module.exports = function buy (user, req = {}, analytics) { if (!key) throw new BadRequest(i18n.t('missingKeyParam', req.language)); let buyRes; - if (key === 'potion') { + if (key === 'potion') { // health potion buyRes = buyPotion(user, req, analytics); } else if (key === 'armoire') { buyRes = buyArmoire(user, req, analytics); diff --git a/common/script/ops/buyPotion.js b/common/script/ops/buyPotion.js index 5c64b19609..0a15777d56 100644 --- a/common/script/ops/buyPotion.js +++ b/common/script/ops/buyPotion.js @@ -4,7 +4,7 @@ import { NotAuthorized, } from '../libs/errors'; -module.exports = function buyPotion (user, req = {}, analytics) { +module.exports = function buyPotion (user, req = {}, analytics) { // health potion let item = content.potion; if (user.stats.gp < item.value) { diff --git a/test/api/v3/integration/user/POST-user_buy_armoire.test.js b/test/api/v3/integration/user/POST-user_buy_armoire.test.js index 7538be64b8..0db5f5cec3 100644 --- a/test/api/v3/integration/user/POST-user_buy_armoire.test.js +++ b/test/api/v3/integration/user/POST-user_buy_armoire.test.js @@ -2,23 +2,23 @@ import { generateUser, translate as t, } from '../../../../helpers/api-integration/v3'; -import shared from '../../../../../common/script'; - -let content = shared.content; describe('POST /user/buy-armoire', () => { let user; beforeEach(async () => { user = await generateUser({ - 'stats.hp': 40, + 'stats.gp': 400, }); }); // More tests in common code unit tests it('returns an error if user does not have enough gold', async () => { - await expect(user.post('/user/buy-potion')) + await user.update({ + 'stats.gp': 5, + }); + await expect(user.post('/user/buy-armoire')) .to.eventually.be.rejected.and.eql({ code: 401, error: 'NotAuthorized', @@ -26,19 +26,14 @@ describe('POST /user/buy-armoire', () => { }); }); - xit('buys a piece of armoire', async () => { - await user.update({ - 'stats.gp': 400, - }); - - let potion = content.potion; - let res = await user.post('/user/buy-potion'); + it('reduces gold when buying from the armoire', async () => { + await user.post('/user/buy-armoire'); await user.sync(); - expect(user.stats.hp).to.equal(50); - expect(res.data).to.eql({ - stats: user.stats, - }); - expect(res.message).to.equal(t('messageBought', {itemText: potion.text()})); + expect(user.stats.gp).to.equal(300); + }); + + xit('buys a piece of armoire', async () => { + // Skipped because can't stub predictableRandom correctly }); }); diff --git a/website/server/controllers/api-v3/user.js b/website/server/controllers/api-v3/user.js index d13b853176..f477631b58 100644 --- a/website/server/controllers/api-v3/user.js +++ b/website/server/controllers/api-v3/user.js @@ -557,8 +557,6 @@ api.buyGear = { * @apiName UserBuyArmoire * @apiGroup User * - * @apiParam {string} key The item to buy. - * * @apiSuccess {object} data.items user.items * @apiSuccess {object} data.flags user.flags * @apiSuccess {object} data.armoire Extra item given by the armoire @@ -577,13 +575,11 @@ api.buyArmoire = { }; /** - * @api {post} /user/buy-potion Buy a potion. + * @api {post} /user/buy-potion Buy a health potion * @apiVersion 3.0.0 * @apiName UserBuyPotion * @apiGroup User * - * @apiParam {string} key The item to buy. - * * @apiSuccess {Object} data user.stats * @apiSuccess {string} message Success message */