mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
add routes for buy ops and integration tests
This commit is contained in:
42
test/api/v3/integration/user/POST-user_buy.test.js
Normal file
42
test/api/v3/integration/user/POST-user_buy.test.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import shared from '../../../../../common/script';
|
||||
|
||||
let content = shared.content;
|
||||
|
||||
describe('POST /user/buy/: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/notExisting`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('itemNotFound', {key: 'notExisting'}),
|
||||
});
|
||||
});
|
||||
|
||||
it('buys an item', async () => {
|
||||
let potion = content.potion;
|
||||
let res = await user.post(`/user/buy/potion`);
|
||||
await user.sync();
|
||||
|
||||
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()}));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user