Files
habitica/test/common/ops/buyHealthPotion.js
Blade Barringer 81b7eeeb71 Common reorg (#8025)
* Re-organize common folder

* fix: Correct paths in tests

* fix: move new content to proper folder

* chore: Move audio folder to assets

* Move sprites to sprites assets directory

* Move css sprites to assets directory

* Split out readmes for common code and sprites

* Move images to assets directory

* Move destinatin of shared browserified file

* remove unused file

* move compiled js to client-old

* Fix karma tests

* fix: Correct paths for sprites
2016-09-16 17:18:07 +02:00

81 lines
1.9 KiB
JavaScript

/* eslint-disable camelcase */
import {
generateUser,
} from '../../helpers/common.helper';
import buyHealthPotion from '../../../website/common/script/ops/buyHealthPotion';
import {
NotAuthorized,
} from '../../../website/common/script/libs/errors';
import i18n from '../../../website/common/script/i18n';
describe('shared.ops.buyHealthPotion', () => {
let user;
beforeEach(() => {
user = generateUser({
items: {
gear: {
owned: {
weapon_warrior_0: true,
},
equipped: {
weapon_warrior_0: true,
},
},
},
stats: { gp: 200 },
});
});
context('Potion', () => {
it('recovers 15 hp', () => {
user.stats.hp = 30;
buyHealthPotion(user);
expect(user.stats.hp).to.eql(45);
});
it('does not increase hp above 50', () => {
user.stats.hp = 45;
buyHealthPotion(user);
expect(user.stats.hp).to.eql(50);
});
it('deducts 25 gp', () => {
user.stats.hp = 45;
buyHealthPotion(user);
expect(user.stats.gp).to.eql(175);
});
it('does not purchase if not enough gp', (done) => {
user.stats.hp = 45;
user.stats.gp = 5;
try {
buyHealthPotion(user);
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
expect(user.stats.hp).to.eql(45);
expect(user.stats.gp).to.eql(5);
done();
}
});
it('does not purchase if hp is full', (done) => {
user.stats.hp = 50;
user.stats.gp = 40;
try {
buyHealthPotion(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.gp).to.eql(40);
done();
}
});
});
});