mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Ported release pets, added unit tests, added route with integration tests
This commit is contained in:
42
test/api/v3/integration/user/POST-user_release_pets.test.js
Normal file
42
test/api/v3/integration/user/POST-user_release_pets.test.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('POST /user/release-pets', () => {
|
||||
let user;
|
||||
let animal = 'Wolf-Base';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser({
|
||||
'items.currentPet': animal,
|
||||
'items.pets': {animal: 5},
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error when user balance is too low', async () => {
|
||||
await expect(user.post('/user/release-pets'))
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('notEnoughGems'),
|
||||
});
|
||||
});
|
||||
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('releases pets', async () => {
|
||||
await user.update({
|
||||
balance: 1,
|
||||
});
|
||||
|
||||
let response = await user.post('/user/release-pets');
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('petsReleased'));
|
||||
expect(user.balance).to.equal(0);
|
||||
expect(user.items.currentPet).to.be.empty;
|
||||
expect(user.items.pets[animal]).to.equal(0);
|
||||
expect(user.achievements.beastMasterCount).to.equal(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user