54153ec299
* move to shops/purchase * move files to /buy/ instead of /purchase/ * refactor buy.js - add more itemtypes * revert moving special purchases to buy * only use buyOp from api-routes * fix buying potion client-side * undo import buy instead of purchase * enable potion bulk purchase - use buyGear as fallback (as before) * move quantity purchase inside buyHealthPotion * move quantity purchase inside buyQuest * move quantity purchase inside buySpecialSpell + add analytics * remove unused quantity variable - set req.type on specialKeys * fix `buyKnownKeys` on buy api * test buy-special-spell if not enough gold * more buy ops coverage * fix lint * buyMysterySet: test for window.confirm, buyQuest: check for Masterclassers unlock * fix test & lint * re-create package-lock.json to travis build ? * use global.window instead of method argument * add back canOwn checks * remove buyMysterySet confirm request
118 lines
3.0 KiB
JavaScript
118 lines
3.0 KiB
JavaScript
/* eslint-disable camelcase */
|
|
import {
|
|
generateUser,
|
|
} from '../../../helpers/common.helper';
|
|
import buyHealthPotion from '../../../../website/common/script/ops/buy/buyHealthPotion';
|
|
import {
|
|
NotAuthorized,
|
|
} from '../../../../website/common/script/libs/errors';
|
|
import i18n from '../../../../website/common/script/i18n';
|
|
|
|
describe('shared.ops.buyHealthPotion', () => {
|
|
let user;
|
|
let analytics = {track () {}};
|
|
|
|
beforeEach(() => {
|
|
user = generateUser({
|
|
items: {
|
|
gear: {
|
|
owned: {
|
|
weapon_warrior_0: true,
|
|
},
|
|
equipped: {
|
|
weapon_warrior_0: true,
|
|
},
|
|
},
|
|
},
|
|
stats: { gp: 200 },
|
|
});
|
|
sinon.stub(analytics, 'track');
|
|
});
|
|
|
|
afterEach(() => {
|
|
analytics.track.restore();
|
|
});
|
|
|
|
context('Potion', () => {
|
|
it('recovers 15 hp', () => {
|
|
user.stats.hp = 30;
|
|
buyHealthPotion(user, {}, analytics);
|
|
expect(user.stats.hp).to.eql(45);
|
|
expect(analytics.track).to.be.calledOnce;
|
|
});
|
|
|
|
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();
|
|
}
|
|
});
|
|
});
|
|
});
|