7fe2504906
* Moved buy tests * Added mystery buy to buy.js * Added quest purchasing to buy * Added buy special * Moved integration tests to buy folder * Removed buyGear dependency * Removed buyArmoire dependency * Removed buyHealthPotion dependency * Removed myster, quest and special dependency * Replaced functions with factory * Added bulk purchasing to common * Added bulk purchasing to the api * Added bulk purchasing to client * Refactored purchasing function to reduce long method * Added bulk purchase to gem purchases * Added bulk purchasing to api * Added bulk purchasing to gem items on client * Removed bulk from equipment * Removed recentlyPurchased * Fixed style issues and prevented puchasing more gems than are left * Fixed lint * Fixed missing keys * Fixed gem amount notice * Added quest modal to pinned item * Added bulk purchase to gem modal * Fixed styles * Fixed bulk purchase for spells * Fixed modal size * Hid autofill
111 lines
2.8 KiB
JavaScript
111 lines
2.8 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();
|
|
}
|
|
});
|
|
|
|
it('does not allow potion purchases when hp is zero', (done) => {
|
|
user.stats.hp = 0;
|
|
user.stats.gp = 40;
|
|
try {
|
|
buyHealthPotion(user);
|
|
} catch (err) {
|
|
expect(err).to.be.an.instanceof(NotAuthorized);
|
|
expect(err.message).to.equal(i18n.t('messageHealthAlreadyMin'));
|
|
expect(user.stats.hp).to.eql(0);
|
|
expect(user.stats.gp).to.eql(40);
|
|
|
|
done();
|
|
}
|
|
});
|
|
|
|
it('does not allow potion purchases when hp is negative', (done) => {
|
|
user.stats.hp = -8;
|
|
user.stats.gp = 40;
|
|
try {
|
|
buyHealthPotion(user);
|
|
} catch (err) {
|
|
expect(err).to.be.an.instanceof(NotAuthorized);
|
|
expect(err.message).to.equal(i18n.t('messageHealthAlreadyMin'));
|
|
expect(user.stats.hp).to.eql(-8);
|
|
expect(user.stats.gp).to.eql(40);
|
|
|
|
done();
|
|
}
|
|
});
|
|
});
|
|
});
|