mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Separated out buy functions into buyGear, buyArmoire, and buyPotion (#7065)
This commit is contained in:
committed by
Matteo Pagliazzi
parent
f44dbbbd71
commit
9e3d8ba4ac
@@ -26,17 +26,28 @@ describe('POST /user/buy/:key', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('buys an item', async () => {
|
||||
it('buys a potion', async () => {
|
||||
await user.update({
|
||||
'stats.gp': 400,
|
||||
});
|
||||
|
||||
let potion = content.potion;
|
||||
let res = await user.post('/user/buy/potion');
|
||||
await user.sync();
|
||||
|
||||
expect(user.stats.hp).to.equal(50);
|
||||
expect(res.data).to.eql({
|
||||
items: JSON.parse(JSON.stringify(user.items)), // otherwise dates can't be compared
|
||||
achievements: user.achievements,
|
||||
stats: user.stats,
|
||||
flags: JSON.parse(JSON.stringify(user.flags)), // otherwise dates can't be compared
|
||||
});
|
||||
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
|
||||
});
|
||||
|
||||
it('buys a piece of gear', async () => {
|
||||
let key = 'armor_warrior_1';
|
||||
|
||||
await user.post(`/user/buy/${key}`);
|
||||
await user.sync();
|
||||
|
||||
expect(user.items.gear.owned).to.eql({ armor_warrior_1: true }); // eslint-disable-line camelcase
|
||||
});
|
||||
});
|
||||
|
||||
44
test/api/v3/integration/user/POST-user_buy_armoire.test.js
Normal file
44
test/api/v3/integration/user/POST-user_buy_armoire.test.js
Normal file
@@ -0,0 +1,44 @@
|
||||
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,
|
||||
});
|
||||
});
|
||||
|
||||
// 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'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('messageNotEnoughGold'),
|
||||
});
|
||||
});
|
||||
|
||||
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');
|
||||
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()}));
|
||||
});
|
||||
});
|
||||
34
test/api/v3/integration/user/POST-user_buy_gear.test.js
Normal file
34
test/api/v3/integration/user/POST-user_buy_gear.test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('POST /user/buy-gear/:key', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser({
|
||||
'stats.gp': 400,
|
||||
});
|
||||
});
|
||||
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('returns an error if the item is not found', async () => {
|
||||
await expect(user.post('/user/buy-gear/notExisting'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('itemNotFound', {key: 'notExisting'}),
|
||||
});
|
||||
});
|
||||
|
||||
it('buys a piece of gear', async () => {
|
||||
let key = 'armor_warrior_1';
|
||||
|
||||
await user.post(`/user/buy-gear/${key}`);
|
||||
await user.sync();
|
||||
|
||||
expect(user.items.gear.owned).to.eql({ armor_warrior_1: true }); // eslint-disable-line camelcase
|
||||
});
|
||||
});
|
||||
44
test/api/v3/integration/user/POST-user_buy_potion.test.js
Normal file
44
test/api/v3/integration/user/POST-user_buy_potion.test.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import shared from '../../../../../common/script';
|
||||
|
||||
let content = shared.content;
|
||||
|
||||
describe('POST /user/buy-potion', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser({
|
||||
'stats.hp': 40,
|
||||
});
|
||||
});
|
||||
|
||||
// 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'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('messageNotEnoughGold'),
|
||||
});
|
||||
});
|
||||
|
||||
it('buys a potion', async () => {
|
||||
await user.update({
|
||||
'stats.gp': 400,
|
||||
});
|
||||
|
||||
let potion = content.potion;
|
||||
let res = await user.post('/user/buy-potion');
|
||||
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()}));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user