mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Ported purchase, add unit tests, created new user purchase route, and added tests
This commit is contained in:
35
test/api/v3/integration/user/POST-user_purchase.test.js
Normal file
35
test/api/v3/integration/user/POST-user_purchase.test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('POST /user/purchase/:type/:key', () => {
|
||||
let user;
|
||||
let type = 'hatchingPotions';
|
||||
let key = 'Base';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser({
|
||||
balance: 40,
|
||||
});
|
||||
});
|
||||
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('returns an error when key is not provided', async () => {
|
||||
await expect(user.post(`/user/purchase/gems/gem`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('mustSubscribeToPurchaseGems'),
|
||||
});
|
||||
});
|
||||
|
||||
it('purchases a gem item', async () => {
|
||||
let res = await user.post(`/user/purchase/${type}/${key}`);
|
||||
await user.sync();
|
||||
|
||||
expect(res.message).to.equal(t('purchased', {type, key}));
|
||||
expect(user.items[type][key]).to.equal(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user