87f39b4273
* toggle pinned state of items server + client * pin quests / add pin src * add officially pinned items and api to get in app rewards * update schema and get items deatils * update pin actions to the new logic * show countBadge only with a number * extract getPinKey - pin seasonal items * togglePinned in buy-dialogs * add pinKey to shop items * wip * wip * fix path * togglePinnedItem as common.op / use in client * fix linting * pinning: getItemInfo and save in db path and type * make api more consistent, fix bugs * updates * fix bugs * update actions to current api * marketGear * change to pinType * add mystery_set to getItemInfo * fix isPinned * ignore animals * list shopItems (initial) * shopItem now has default popoverconent, itemclass and price / currency - list pinned items as rewards - attributes to gear * show buyModal for the rewards * show mystery_set icon * add info whether item is suggested * write migration, fix style issues * pin potion and armoire * make potion, armoire not unpinnable * show notes for armoire and potion, add default items for new users * show unpin notification * add/remove pinned gear on class-change * remove pinned & add new gear on purchase - refactoring pinning methods - fixes * always allow to purchase armoire * highlight item if suggested
155 lines
4.2 KiB
JavaScript
155 lines
4.2 KiB
JavaScript
/* eslint-disable camelcase */
|
|
|
|
import {
|
|
generateUser,
|
|
} from '../../helpers/common.helper';
|
|
import count from '../../../website/common/script/count';
|
|
import buyArmoire from '../../../website/common/script/ops/buyArmoire';
|
|
import randomVal from '../../../website/common/script/libs/randomVal';
|
|
import content from '../../../website/common/script/content/index';
|
|
import {
|
|
NotAuthorized,
|
|
} from '../../../website/common/script/libs/errors';
|
|
import i18n from '../../../website/common/script/i18n';
|
|
|
|
function getFullArmoire () {
|
|
let fullArmoire = {};
|
|
|
|
_.each(content.gearTypes, (type) => {
|
|
_.each(content.gear.tree[type].armoire, (gearObject) => {
|
|
let armoireKey = gearObject.key;
|
|
|
|
fullArmoire[armoireKey] = true;
|
|
});
|
|
});
|
|
|
|
return fullArmoire;
|
|
}
|
|
|
|
describe('shared.ops.buyArmoire', () => {
|
|
let user;
|
|
let YIELD_EQUIPMENT = 0.5;
|
|
let YIELD_FOOD = 0.7;
|
|
let YIELD_EXP = 0.9;
|
|
|
|
beforeEach(() => {
|
|
user = generateUser({
|
|
stats: { gp: 200 },
|
|
});
|
|
user.items.gear.owned = {
|
|
weapon_warrior_0: true,
|
|
};
|
|
user.achievements.ultimateGearSets = { rogue: true };
|
|
user.flags.armoireOpened = true;
|
|
user.stats.exp = 0;
|
|
user.items.food = {};
|
|
|
|
sandbox.stub(randomVal, 'trueRandom');
|
|
});
|
|
|
|
afterEach(() => {
|
|
randomVal.trueRandom.restore();
|
|
});
|
|
|
|
context('failure conditions', () => {
|
|
it('does not open if user does not have enough gold', (done) => {
|
|
user.stats.gp = 50;
|
|
|
|
try {
|
|
buyArmoire(user);
|
|
} catch (err) {
|
|
expect(err).to.be.an.instanceof(NotAuthorized);
|
|
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
|
expect(user.items.gear.owned).to.eql({
|
|
weapon_warrior_0: true,
|
|
});
|
|
expect(user.items.food).to.be.empty;
|
|
expect(user.stats.exp).to.eql(0);
|
|
done();
|
|
}
|
|
});
|
|
});
|
|
|
|
context('non-gear awards', () => {
|
|
it('gives Experience', () => {
|
|
let previousExp = user.stats.exp;
|
|
randomVal.trueRandom.returns(YIELD_EXP);
|
|
|
|
buyArmoire(user);
|
|
|
|
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
|
expect(user.items.food).to.be.empty;
|
|
expect(user.stats.exp).to.be.greaterThan(previousExp);
|
|
expect(user.stats.gp).to.equal(100);
|
|
});
|
|
|
|
it('gives food', () => {
|
|
let previousExp = user.stats.exp;
|
|
|
|
randomVal.trueRandom.returns(YIELD_FOOD);
|
|
|
|
buyArmoire(user);
|
|
|
|
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
|
expect(user.items.food).to.not.be.empty;
|
|
expect(user.stats.exp).to.equal(previousExp);
|
|
expect(user.stats.gp).to.equal(100);
|
|
});
|
|
|
|
it('does not give equipment if all equipment has been found', () => {
|
|
randomVal.trueRandom.returns(YIELD_EQUIPMENT);
|
|
user.items.gear.owned = getFullArmoire();
|
|
user.stats.gp = 150;
|
|
|
|
buyArmoire(user);
|
|
|
|
expect(user.items.gear.owned).to.eql(getFullArmoire());
|
|
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
|
|
|
expect(armoireCount).to.eql(0);
|
|
|
|
expect(user.stats.gp).to.equal(50);
|
|
});
|
|
});
|
|
|
|
context('gear awards', () => {
|
|
it('always drops equipment the first time', () => {
|
|
delete user.flags.armoireOpened;
|
|
randomVal.trueRandom.returns(YIELD_EXP);
|
|
|
|
expect(_.size(user.items.gear.owned)).to.equal(1);
|
|
|
|
buyArmoire(user);
|
|
|
|
expect(_.size(user.items.gear.owned)).to.equal(2);
|
|
|
|
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
|
|
|
expect(armoireCount).to.eql(_.size(getFullArmoire()) - 1);
|
|
expect(user.items.food).to.be.empty;
|
|
expect(user.stats.exp).to.equal(0);
|
|
expect(user.stats.gp).to.equal(100);
|
|
});
|
|
|
|
it('gives more equipment', () => {
|
|
randomVal.trueRandom.returns(YIELD_EQUIPMENT);
|
|
user.items.gear.owned = {
|
|
weapon_warrior_0: true,
|
|
head_armoire_hornedIronHelm: true,
|
|
};
|
|
user.stats.gp = 200;
|
|
|
|
expect(_.size(user.items.gear.owned)).to.equal(2);
|
|
|
|
buyArmoire(user);
|
|
|
|
expect(_.size(user.items.gear.owned)).to.equal(3);
|
|
|
|
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
|
|
|
expect(armoireCount).to.eql(_.size(getFullArmoire()) - 2);
|
|
expect(user.stats.gp).to.eql(100);
|
|
});
|
|
});
|
|
});
|