diff --git a/test/api/v3/integration/user/POST-user_class_cast_spellId.test.js b/test/api/v3/integration/user/POST-user_class_cast_spellId.test.js index 0700122c15..379d04a9ec 100644 --- a/test/api/v3/integration/user/POST-user_class_cast_spellId.test.js +++ b/test/api/v3/integration/user/POST-user_class_cast_spellId.test.js @@ -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')) diff --git a/test/common/ops/spells.js b/test/common/ops/spells.js new file mode 100644 index 0000000000..58d3965a7f --- /dev/null +++ b/test/common/ops/spells.js @@ -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(); + } + }); +}); \ No newline at end of file diff --git a/website/client/mixins/spells.js b/website/client/mixins/spells.js index f1d776c95d..405ef1a11d 100644 --- a/website/client/mixins/spells.js +++ b/website/client/mixins/spells.js @@ -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; diff --git a/website/common/script/content/spells.js b/website/common/script/content/spells.js index d04bddd8e6..58d69d3755 100644 --- a/website/common/script/content/spells.js +++ b/website/common/script/content/spells.js @@ -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; },