mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-14 19:47:03 +00:00
Fixing healing light not being castable when user full hp (#10603)
* Fixing healing light not being castable on server and client sides when user has already full health Adding integration test for spell cast of healing light when full health Adding test for heal cast if user has full health * Fixing ESLint syntax in the spells test files
This commit is contained in:
parent
ec444384f4
commit
7630c02e13
4 changed files with 68 additions and 1 deletions
|
|
@ -58,6 +58,21 @@ describe('POST /user/class/cast/:spellId', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('returns an error if use Healing Light spell with full health', async () => {
|
||||
await user.update({
|
||||
'stats.class': 'healer',
|
||||
'stats.lvl': 11,
|
||||
'stats.hp': 50,
|
||||
'stats.mp': 200,
|
||||
});
|
||||
await expect(user.post('/user/class/cast/heal'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('messageHealthAlreadyMax'),
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error if spell.lvl > user.level', async () => {
|
||||
await user.update({'stats.mp': 200, 'stats.class': 'wizard'});
|
||||
await expect(user.post('/user/class/cast/earth'))
|
||||
|
|
|
|||
38
test/common/ops/spells.js
Normal file
38
test/common/ops/spells.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
import spells from '../../../website/common/script/content/spells';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../../../website/common/script/libs/errors';
|
||||
import i18n from '../../../website/common/script/i18n';
|
||||
|
||||
// TODO complete the test suite...
|
||||
|
||||
describe('shared.ops.spells', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser();
|
||||
});
|
||||
|
||||
it('returns an error when healer tries to cast Healing Light with full health', (done) => {
|
||||
user.stats.class = 'healer';
|
||||
user.stats.lvl = 11;
|
||||
user.stats.hp = 50;
|
||||
user.stats.mp = 200;
|
||||
|
||||
let spell = spells.healer.heal;
|
||||
|
||||
try {
|
||||
spell.cast(user);
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageHealthAlreadyMax'));
|
||||
expect(user.stats.hp).to.eql(50);
|
||||
expect(user.stats.mp).to.eql(200);
|
||||
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -85,7 +85,20 @@ export default {
|
|||
|
||||
// the selected member doesn't have the flags property which sets `cardReceived`
|
||||
if (spell.pinType !== 'card') {
|
||||
spell.cast(this.user, target);
|
||||
try {
|
||||
spell.cast(this.user, target);
|
||||
} catch (e) {
|
||||
if (!e.request) {
|
||||
this.$store.dispatch('snackbars:add', {
|
||||
title: '',
|
||||
text: e.message,
|
||||
type: 'error',
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let targetId = target ? target._id : null;
|
||||
|
|
|
|||
|
|
@ -211,6 +211,7 @@ spells.healer = {
|
|||
target: 'self',
|
||||
notes: t('spellHealerHealNotes'),
|
||||
cast (user) {
|
||||
if (user.stats.hp >= 50) throw new NotAuthorized(t('messageHealthAlreadyMax')(user.language));
|
||||
user.stats.hp += (statsComputed(user).con + statsComputed(user).int + 5) * 0.075;
|
||||
if (user.stats.hp > 50) user.stats.hp = 50;
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue