mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
fix incorrect Armoire test; remove unneeded param details from apidocs; disambiguate health potion
This commit is contained in:
@@ -12,7 +12,7 @@ module.exports = function buy (user, req = {}, analytics) {
|
|||||||
if (!key) throw new BadRequest(i18n.t('missingKeyParam', req.language));
|
if (!key) throw new BadRequest(i18n.t('missingKeyParam', req.language));
|
||||||
|
|
||||||
let buyRes;
|
let buyRes;
|
||||||
if (key === 'potion') {
|
if (key === 'potion') { // health potion
|
||||||
buyRes = buyPotion(user, req, analytics);
|
buyRes = buyPotion(user, req, analytics);
|
||||||
} else if (key === 'armoire') {
|
} else if (key === 'armoire') {
|
||||||
buyRes = buyArmoire(user, req, analytics);
|
buyRes = buyArmoire(user, req, analytics);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
NotAuthorized,
|
NotAuthorized,
|
||||||
} from '../libs/errors';
|
} from '../libs/errors';
|
||||||
|
|
||||||
module.exports = function buyPotion (user, req = {}, analytics) {
|
module.exports = function buyPotion (user, req = {}, analytics) { // health potion
|
||||||
let item = content.potion;
|
let item = content.potion;
|
||||||
|
|
||||||
if (user.stats.gp < item.value) {
|
if (user.stats.gp < item.value) {
|
||||||
|
|||||||
@@ -2,23 +2,23 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../../helpers/api-integration/v3';
|
} from '../../../../helpers/api-integration/v3';
|
||||||
import shared from '../../../../../common/script';
|
|
||||||
|
|
||||||
let content = shared.content;
|
|
||||||
|
|
||||||
describe('POST /user/buy-armoire', () => {
|
describe('POST /user/buy-armoire', () => {
|
||||||
let user;
|
let user;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
user = await generateUser({
|
user = await generateUser({
|
||||||
'stats.hp': 40,
|
'stats.gp': 400,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// More tests in common code unit tests
|
// More tests in common code unit tests
|
||||||
|
|
||||||
it('returns an error if user does not have enough gold', async () => {
|
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({
|
.to.eventually.be.rejected.and.eql({
|
||||||
code: 401,
|
code: 401,
|
||||||
error: 'NotAuthorized',
|
error: 'NotAuthorized',
|
||||||
@@ -26,19 +26,14 @@ describe('POST /user/buy-armoire', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('buys a piece of armoire', async () => {
|
it('reduces gold when buying from the armoire', async () => {
|
||||||
await user.update({
|
await user.post('/user/buy-armoire');
|
||||||
'stats.gp': 400,
|
|
||||||
});
|
|
||||||
|
|
||||||
let potion = content.potion;
|
|
||||||
let res = await user.post('/user/buy-potion');
|
|
||||||
await user.sync();
|
await user.sync();
|
||||||
|
|
||||||
expect(user.stats.hp).to.equal(50);
|
expect(user.stats.gp).to.equal(300);
|
||||||
expect(res.data).to.eql({
|
});
|
||||||
stats: user.stats,
|
|
||||||
});
|
xit('buys a piece of armoire', async () => {
|
||||||
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
|
// Skipped because can't stub predictableRandom correctly
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -557,8 +557,6 @@ api.buyGear = {
|
|||||||
* @apiName UserBuyArmoire
|
* @apiName UserBuyArmoire
|
||||||
* @apiGroup User
|
* @apiGroup User
|
||||||
*
|
*
|
||||||
* @apiParam {string} key The item to buy.
|
|
||||||
*
|
|
||||||
* @apiSuccess {object} data.items user.items
|
* @apiSuccess {object} data.items user.items
|
||||||
* @apiSuccess {object} data.flags user.flags
|
* @apiSuccess {object} data.flags user.flags
|
||||||
* @apiSuccess {object} data.armoire Extra item given by the armoire
|
* @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
|
* @apiVersion 3.0.0
|
||||||
* @apiName UserBuyPotion
|
* @apiName UserBuyPotion
|
||||||
* @apiGroup User
|
* @apiGroup User
|
||||||
*
|
*
|
||||||
* @apiParam {string} key The item to buy.
|
|
||||||
*
|
|
||||||
* @apiSuccess {Object} data user.stats
|
* @apiSuccess {Object} data user.stats
|
||||||
* @apiSuccess {string} message Success message
|
* @apiSuccess {string} message Success message
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user