Files
habitica/test/api/v3/integration/user/POST-user_release_pets.test.js
jerellmendoodoo a9195f0d96 Fixed release pets mounts (#8545)
* Fixed release pets/mounts achievements when fully earned and added unit tests for these changes

* Fixed release pets/mounts achievements to award only when fully earned and added unit tests for these changes, also fixed linting issues

* Updated variable assignments to make more readable

* Revised releaseBoth/Pets/Mounts to include null or undefined checks, also updated unit tests

* fixed integration tests
2017-07-18 13:34:54 -07:00

53 lines
1.3 KiB
JavaScript

import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
import content from '../../../../../website/common/script/content/index';
describe('POST /user/release-pets', () => {
let user;
let animal = 'Wolf-Base';
const loadPets = () => {
let pets = {};
for (let p in content.pets) {
pets[p] = content.pets[p];
pets[p] = 5;
}
return pets;
};
beforeEach(async () => {
user = await generateUser({
'items.currentPet': animal,
'items.pets': loadPets(),
});
});
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);
});
});