mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 05:37:22 +01:00
* Only unequip Gen 1 pets/mounts when releasing pets/mounts * Changed mount declaration to match releasePets * Check if a pet/mount is a drop type instead of checking for its name in the list of pets * Changed references to pet and mount to petInfo and mountInfo for consistency with releasePets and releaseMounts * Test that releasePets, releaseMounts, and releaseBoth do not unequip quest pets * Fixed test names, and tests verify that a pet/mount is/is not a drop pet/mount on release * Removed unneeded comments
This commit is contained in:
committed by
Blade Barringer
parent
2e2dc179c4
commit
d2756278c3
@@ -1,4 +1,5 @@
|
|||||||
import releaseBoth from '../../../website/common/script/ops/releaseBoth';
|
import releaseBoth from '../../../website/common/script/ops/releaseBoth';
|
||||||
|
import content from '../../../website/common/script/content/index';
|
||||||
import i18n from '../../../website/common/script/i18n';
|
import i18n from '../../../website/common/script/i18n';
|
||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
@@ -65,19 +66,41 @@ describe('shared.ops.releaseBoth', () => {
|
|||||||
expect(user.items.mounts[animal]).to.equal(null);
|
expect(user.items.mounts[animal]).to.equal(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes currentPet', () => {
|
it('removes drop currentPet', () => {
|
||||||
|
let petInfo = content.petInfo[user.items.currentPet];
|
||||||
|
expect(petInfo.type).to.equal('drop');
|
||||||
releaseBoth(user);
|
releaseBoth(user);
|
||||||
|
|
||||||
expect(user.items.currentMount).to.be.empty;
|
expect(user.items.currentMount).to.be.empty;
|
||||||
expect(user.items.currentPet).to.be.empty;
|
expect(user.items.currentPet).to.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes currentMount', () => {
|
it('removes drop currentMount', () => {
|
||||||
|
let mountInfo = content.mountInfo[user.items.currentMount];
|
||||||
|
expect(mountInfo.type).to.equal('drop');
|
||||||
releaseBoth(user);
|
releaseBoth(user);
|
||||||
|
|
||||||
expect(user.items.currentMount).to.be.empty;
|
expect(user.items.currentMount).to.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('leaves non-drop pets and mounts equipped', () => {
|
||||||
|
let questAnimal = 'Gryphon-Base';
|
||||||
|
user.items.currentMount = questAnimal;
|
||||||
|
user.items.currentPet = questAnimal;
|
||||||
|
user.items.pets[questAnimal] = 5;
|
||||||
|
user.items.mounts[questAnimal] = true;
|
||||||
|
|
||||||
|
let petInfo = content.petInfo[user.items.currentPet];
|
||||||
|
expect(petInfo.type).to.not.equal('drop');
|
||||||
|
let mountInfo = content.mountInfo[user.items.currentMount];
|
||||||
|
expect(mountInfo.type).to.not.equal('drop');
|
||||||
|
|
||||||
|
releaseBoth(user);
|
||||||
|
|
||||||
|
expect(user.items.currentMount).to.equal(questAnimal);
|
||||||
|
expect(user.items.currentPet).to.equal(questAnimal);
|
||||||
|
});
|
||||||
|
|
||||||
it('decreases user\'s balance', () => {
|
it('decreases user\'s balance', () => {
|
||||||
releaseBoth(user);
|
releaseBoth(user);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import releaseMounts from '../../../website/common/script/ops/releaseMounts';
|
import releaseMounts from '../../../website/common/script/ops/releaseMounts';
|
||||||
|
import content from '../../../website/common/script/content/index';
|
||||||
import i18n from '../../../website/common/script/i18n';
|
import i18n from '../../../website/common/script/i18n';
|
||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
@@ -37,12 +38,26 @@ describe('shared.ops.releaseMounts', () => {
|
|||||||
expect(user.items.mounts[animal]).to.equal(null);
|
expect(user.items.mounts[animal]).to.equal(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes currentMount', () => {
|
it('removes drop currentMount', () => {
|
||||||
|
let mountInfo = content.mountInfo[user.items.currentMount];
|
||||||
|
expect(mountInfo.type).to.equal('drop');
|
||||||
releaseMounts(user);
|
releaseMounts(user);
|
||||||
|
|
||||||
expect(user.items.currentMount).to.be.empty;
|
expect(user.items.currentMount).to.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('leaves non-drop mount equipped', () => {
|
||||||
|
let questAnimal = 'Gryphon-Base';
|
||||||
|
user.items.currentMount = questAnimal;
|
||||||
|
user.items.mounts[questAnimal] = true;
|
||||||
|
|
||||||
|
let mountInfo = content.mountInfo[user.items.currentMount];
|
||||||
|
expect(mountInfo.type).to.not.equal('drop');
|
||||||
|
releaseMounts(user);
|
||||||
|
|
||||||
|
expect(user.items.currentMount).to.equal(questAnimal);
|
||||||
|
});
|
||||||
|
|
||||||
it('increases mountMasterCount achievement', () => {
|
it('increases mountMasterCount achievement', () => {
|
||||||
releaseMounts(user);
|
releaseMounts(user);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import releasePets from '../../../website/common/script/ops/releasePets';
|
import releasePets from '../../../website/common/script/ops/releasePets';
|
||||||
|
import content from '../../../website/common/script/content/index';
|
||||||
import i18n from '../../../website/common/script/i18n';
|
import i18n from '../../../website/common/script/i18n';
|
||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
@@ -37,12 +38,26 @@ describe('shared.ops.releasePets', () => {
|
|||||||
expect(user.items.pets[animal]).to.equal(0);
|
expect(user.items.pets[animal]).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes currentPet', () => {
|
it('removes drop currentPet', () => {
|
||||||
|
let petInfo = content.petInfo[user.items.currentPet];
|
||||||
|
expect(petInfo.type).to.equal('drop');
|
||||||
releasePets(user);
|
releasePets(user);
|
||||||
|
|
||||||
expect(user.items.currentPet).to.be.empty;
|
expect(user.items.currentPet).to.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('leaves non-drop pets equipped', () => {
|
||||||
|
let questAnimal = 'Gryphon-Base';
|
||||||
|
user.items.currentPet = questAnimal;
|
||||||
|
user.items.pets[questAnimal] = 5;
|
||||||
|
|
||||||
|
let petInfo = content.petInfo[user.items.currentPet];
|
||||||
|
expect(petInfo.type).to.not.equal('drop');
|
||||||
|
releasePets(user);
|
||||||
|
|
||||||
|
expect(user.items.currentPet).to.equal(questAnimal);
|
||||||
|
});
|
||||||
|
|
||||||
it('decreases user\'s balance', () => {
|
it('decreases user\'s balance', () => {
|
||||||
releasePets(user);
|
releasePets(user);
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,17 @@ module.exports = function releaseBoth (user, req = {}, analytics) {
|
|||||||
user.balance -= 1.5;
|
user.balance -= 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
user.items.currentMount = '';
|
let mountInfo = content.mountInfo[user.items.currentMount];
|
||||||
user.items.currentPet = '';
|
|
||||||
|
if (mountInfo && mountInfo.type === 'drop') {
|
||||||
|
user.items.currentMount = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
let petInfo = content.petInfo[user.items.currentPet];
|
||||||
|
|
||||||
|
if (petInfo && petInfo.type === 'drop') {
|
||||||
|
user.items.currentPet = '';
|
||||||
|
}
|
||||||
|
|
||||||
for (animal in content.pets) {
|
for (animal in content.pets) {
|
||||||
if (user.items.pets[animal] === -1) {
|
if (user.items.pets[animal] === -1) {
|
||||||
|
|||||||
@@ -5,16 +5,19 @@ import {
|
|||||||
} from '../libs/errors';
|
} from '../libs/errors';
|
||||||
|
|
||||||
module.exports = function releaseMounts (user, req = {}, analytics) {
|
module.exports = function releaseMounts (user, req = {}, analytics) {
|
||||||
let mount;
|
|
||||||
|
|
||||||
if (user.balance < 1) {
|
if (user.balance < 1) {
|
||||||
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
|
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
|
||||||
}
|
}
|
||||||
|
|
||||||
user.balance -= 1;
|
user.balance -= 1;
|
||||||
user.items.currentMount = '';
|
|
||||||
|
|
||||||
for (mount in content.pets) {
|
let mountInfo = content.mountInfo[user.items.currentMount];
|
||||||
|
|
||||||
|
if (mountInfo && mountInfo.type === 'drop') {
|
||||||
|
user.items.currentMount = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let mount in content.pets) {
|
||||||
user.items.mounts[mount] = null;
|
user.items.mounts[mount] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,12 @@ module.exports = function releasePets (user, req = {}, analytics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.balance -= 1;
|
user.balance -= 1;
|
||||||
user.items.currentPet = '';
|
|
||||||
|
let petInfo = content.petInfo[user.items.currentPet];
|
||||||
|
|
||||||
|
if (petInfo && petInfo.type === 'drop') {
|
||||||
|
user.items.currentPet = '';
|
||||||
|
}
|
||||||
|
|
||||||
for (let pet in content.pets) {
|
for (let pet in content.pets) {
|
||||||
user.items.pets[pet] = 0;
|
user.items.pets[pet] = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user