Merge branch 'api-v3' into api-v3-unlock-fix
This commit is contained in:
@@ -39,9 +39,9 @@ describe('shared.ops.addPushDevice', () => {
|
||||
});
|
||||
|
||||
it('adds a push device', () => {
|
||||
let response = addPushDevice(user, {body: {regId, type}});
|
||||
let [, message] = addPushDevice(user, {body: {regId, type}});
|
||||
|
||||
expect(response.message).to.equal(i18n.t('pushDeviceAdded'));
|
||||
expect(message).to.equal(i18n.t('pushDeviceAdded'));
|
||||
expect(user.pushDevices[0].type).to.equal(type);
|
||||
expect(user.pushDevices[0].regId).to.equal(regId);
|
||||
});
|
||||
|
||||
@@ -18,17 +18,13 @@ describe('shared.ops.allocateNow', () => {
|
||||
user.stats.str = 9;
|
||||
user.preferences.allocationMode = 'flat';
|
||||
|
||||
let res = allocateNow(user);
|
||||
let [data] = allocateNow(user);
|
||||
|
||||
expect(user.stats.points).to.equal(0);
|
||||
expect(user.stats.con).to.equal(9);
|
||||
expect(user.stats.int).to.equal(8);
|
||||
expect(user.stats.per).to.equal(9);
|
||||
expect(user.stats.str).to.equal(9);
|
||||
expect(res).to.eql({
|
||||
data: {
|
||||
stats: user.stats,
|
||||
},
|
||||
});
|
||||
expect(data).to.eql(user.stats);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,10 +26,10 @@ describe('shared.ops.blockUser', () => {
|
||||
});
|
||||
|
||||
it('blocks user', () => {
|
||||
let result = blockUser(user, { params: { uuid: blockedUser._id } });
|
||||
let [result] = blockUser(user, { params: { uuid: blockedUser._id } });
|
||||
expect(user.inbox.blocks).to.eql([blockedUser._id]);
|
||||
expect(result).to.eql([blockedUser._id]);
|
||||
result = blockUser(user, { params: { uuid: blockedUser2._id } });
|
||||
[result] = blockUser(user, { params: { uuid: blockedUser2._id } });
|
||||
expect(user.inbox.blocks).to.eql([blockedUser._id, blockedUser2._id]);
|
||||
expect(result).to.eql([blockedUser._id, blockedUser2._id]);
|
||||
});
|
||||
@@ -37,7 +37,7 @@ describe('shared.ops.blockUser', () => {
|
||||
it('blocks, then unblocks user', () => {
|
||||
blockUser(user, { params: { uuid: blockedUser._id } });
|
||||
expect(user.inbox.blocks).to.eql([blockedUser._id]);
|
||||
let result = blockUser(user, { params: { uuid: blockedUser._id } });
|
||||
let [result] = blockUser(user, { params: { uuid: blockedUser._id } });
|
||||
expect(user.inbox.blocks).to.eql([]);
|
||||
expect(result).to.eql([]);
|
||||
});
|
||||
|
||||
+17
-272
@@ -1,15 +1,10 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import sinon from 'sinon'; // eslint-disable-line no-shadow
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
import count from '../../../common/script/count';
|
||||
import buy from '../../../common/script/ops/buy';
|
||||
import shared from '../../../common/script';
|
||||
import content from '../../../common/script/content/index';
|
||||
import {
|
||||
NotAuthorized,
|
||||
BadRequest,
|
||||
} from '../../../common/script/libs/errors';
|
||||
import i18n from '../../../common/script/i18n';
|
||||
|
||||
@@ -30,277 +25,27 @@ describe('shared.ops.buy', () => {
|
||||
},
|
||||
stats: { gp: 200 },
|
||||
});
|
||||
|
||||
sinon.stub(shared.fns, 'randomVal');
|
||||
sinon.stub(shared.fns, 'predictableRandom');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
shared.fns.randomVal.restore();
|
||||
shared.fns.predictableRandom.restore();
|
||||
it('returns error when key is not provided', (done) => {
|
||||
try {
|
||||
buy(user);
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(BadRequest);
|
||||
expect(err.message).to.equal(i18n.t('missingKeyParam'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
context('Potion', () => {
|
||||
it('recovers 15 hp', () => {
|
||||
user.stats.hp = 30;
|
||||
buy(user, {params: {key: 'potion'}});
|
||||
expect(user.stats.hp).to.eql(45);
|
||||
});
|
||||
|
||||
it('does not increase hp above 50', () => {
|
||||
user.stats.hp = 45;
|
||||
buy(user, {params: {key: 'potion'}});
|
||||
expect(user.stats.hp).to.eql(50);
|
||||
});
|
||||
|
||||
it('deducts 25 gp', () => {
|
||||
user.stats.hp = 45;
|
||||
buy(user, {params: {key: 'potion'}});
|
||||
|
||||
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 {
|
||||
buy(user, {params: {key: 'potion'}});
|
||||
} 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('recovers 15 hp', () => {
|
||||
user.stats.hp = 30;
|
||||
buy(user, {params: {key: 'potion'}});
|
||||
expect(user.stats.hp).to.eql(45);
|
||||
});
|
||||
|
||||
context('Gear', () => {
|
||||
it('adds equipment to inventory', () => {
|
||||
user.stats.gp = 31;
|
||||
|
||||
buy(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql({ weapon_warrior_0: true, armor_warrior_1: true });
|
||||
});
|
||||
|
||||
it('deducts gold from user', () => {
|
||||
user.stats.gp = 31;
|
||||
|
||||
buy(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.stats.gp).to.eql(1);
|
||||
});
|
||||
|
||||
it('auto equips equipment if user has auto-equip preference turned on', () => {
|
||||
user.stats.gp = 31;
|
||||
user.preferences.autoEquip = true;
|
||||
|
||||
buy(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('armor', 'armor_warrior_1');
|
||||
});
|
||||
|
||||
it('buys equipment but does not auto-equip', () => {
|
||||
user.stats.gp = 31;
|
||||
user.preferences.autoEquip = false;
|
||||
|
||||
buy(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.items.gear.equipped.property).to.not.equal('armor_warrior_1');
|
||||
});
|
||||
|
||||
// TODO after user.ops.equip is done
|
||||
xit('removes one-handed weapon and shield if auto-equip is on and a two-hander is bought', () => {
|
||||
user.stats.gp = 100;
|
||||
user.preferences.autoEquip = true;
|
||||
buy(user, {params: {key: 'shield_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'shield_warrior_1'}});
|
||||
buy(user, {params: {key: 'weapon_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'weapon_warrior_1'}});
|
||||
|
||||
buy(user, {params: {key: 'weapon_wizard_1'}});
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('shield', 'shield_base_0');
|
||||
expect(user.items.gear.equipped).to.have.property('weapon', 'weapon_wizard_1');
|
||||
});
|
||||
|
||||
// TODO after user.ops.equip is done
|
||||
xit('buys two-handed equipment but does not automatically remove sword or shield', () => {
|
||||
user.stats.gp = 100;
|
||||
user.preferences.autoEquip = false;
|
||||
buy(user, {params: {key: 'shield_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'shield_warrior_1'}});
|
||||
buy(user, {params: {key: 'weapon_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'weapon_warrior_1'}});
|
||||
|
||||
buy(user, {params: {key: 'weapon_wizard_1'}});
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('shield', 'shield_warrior_1');
|
||||
expect(user.items.gear.equipped).to.have.property('weapon', 'weapon_warrior_1');
|
||||
});
|
||||
|
||||
it('does not buy equipment without enough Gold', (done) => {
|
||||
user.stats.gp = 20;
|
||||
|
||||
try {
|
||||
buy(user, {params: {key: 'armor_warrior_1'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
||||
expect(user.items.gear.owned).to.not.have.property('armor_warrior_1');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
context('Enchanted Armoire', () => {
|
||||
let YIELD_EQUIPMENT = 0.5;
|
||||
let YIELD_FOOD = 0.7;
|
||||
let YIELD_EXP = 0.9;
|
||||
|
||||
let fullArmoire = {};
|
||||
|
||||
_(content.gearTypes).each((type) => {
|
||||
_(content.gear.tree[type].armoire).each((gearObject) => {
|
||||
let armoireKey = gearObject.key;
|
||||
|
||||
fullArmoire[armoireKey] = true;
|
||||
}).value();
|
||||
}).value();
|
||||
|
||||
beforeEach(() => {
|
||||
user.achievements.ultimateGearSets = { rogue: true };
|
||||
user.flags.armoireOpened = true;
|
||||
user.stats.exp = 0;
|
||||
user.items.food = {};
|
||||
});
|
||||
|
||||
context('failure conditions', () => {
|
||||
it('does not open if user does not have enough gold', (done) => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.stats.gp = 50;
|
||||
|
||||
try {
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
} 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();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not open without Ultimate Gear achievement', (done) => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.achievements.ultimateGearSets = {healer: false, wizard: false, rogue: false, warrior: false};
|
||||
|
||||
try {
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('cannoyBuyItem'));
|
||||
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', () => {
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('gives Experience', () => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EXP);
|
||||
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(46);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('gives food', () => {
|
||||
let honey = content.food.Honey;
|
||||
|
||||
shared.fns.randomVal.returns(honey);
|
||||
shared.fns.predictableRandom.returns(YIELD_FOOD);
|
||||
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.eql({Honey: 1});
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('does not give equipment if all equipment has been found', () => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.items.gear.owned = fullArmoire;
|
||||
user.stats.gp = 150;
|
||||
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql(fullArmoire);
|
||||
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||
|
||||
expect(armoireCount).to.eql(0);
|
||||
|
||||
expect(user.stats.exp).to.eql(30);
|
||||
expect(user.stats.gp).to.eql(50);
|
||||
});
|
||||
});
|
||||
|
||||
context('gear awards', () => {
|
||||
beforeEach(() => {
|
||||
let shield = content.gear.tree.shield.armoire.gladiatorShield;
|
||||
|
||||
shared.fns.randomVal.returns(shield);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('always drops equipment the first time', () => {
|
||||
delete user.flags.armoireOpened;
|
||||
shared.fns.predictableRandom.returns(YIELD_EXP);
|
||||
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql({
|
||||
weapon_warrior_0: true,
|
||||
shield_armoire_gladiatorShield: true,
|
||||
});
|
||||
|
||||
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||
|
||||
expect(armoireCount).to.eql(_.size(fullArmoire) - 1);
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('gives more equipment', () => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.items.gear.owned = {
|
||||
weapon_warrior_0: true,
|
||||
head_armoire_hornedIronHelm: true,
|
||||
};
|
||||
user.stats.gp = 200;
|
||||
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true, shield_armoire_gladiatorShield: true, head_armoire_hornedIronHelm: true});
|
||||
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||
|
||||
expect(armoireCount).to.eql(_.size(fullArmoire) - 2);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
});
|
||||
it('adds equipment to inventory', () => {
|
||||
user.stats.gp = 31;
|
||||
buy(user, {params: {key: 'armor_warrior_1'}});
|
||||
expect(user.items.gear.owned).to.eql({ weapon_warrior_0: true, armor_warrior_1: true });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import sinon from 'sinon'; // eslint-disable-line no-shadow
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
import count from '../../../common/script/count';
|
||||
import buyArmoire from '../../../common/script/ops/buyArmoire';
|
||||
import shared from '../../../common/script';
|
||||
import content from '../../../common/script/content/index';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../../../common/script/libs/errors';
|
||||
import i18n from '../../../common/script/i18n';
|
||||
|
||||
describe('shared.ops.buyArmoire', () => {
|
||||
let user;
|
||||
let YIELD_EQUIPMENT = 0.5;
|
||||
let YIELD_FOOD = 0.7;
|
||||
let YIELD_EXP = 0.9;
|
||||
|
||||
let fullArmoire = {};
|
||||
|
||||
_(content.gearTypes).each((type) => {
|
||||
_(content.gear.tree[type].armoire).each((gearObject) => {
|
||||
let armoireKey = gearObject.key;
|
||||
|
||||
fullArmoire[armoireKey] = true;
|
||||
}).value();
|
||||
}).value();
|
||||
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser({
|
||||
items: {
|
||||
gear: {
|
||||
owned: {
|
||||
weapon_warrior_0: true,
|
||||
},
|
||||
equipped: {
|
||||
weapon_warrior_0: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
stats: { gp: 200 },
|
||||
});
|
||||
|
||||
user.achievements.ultimateGearSets = { rogue: true };
|
||||
user.flags.armoireOpened = true;
|
||||
user.stats.exp = 0;
|
||||
user.items.food = {};
|
||||
|
||||
sinon.stub(shared.fns, 'randomVal');
|
||||
sinon.stub(shared.fns, 'predictableRandom');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
shared.fns.randomVal.restore();
|
||||
shared.fns.predictableRandom.restore();
|
||||
});
|
||||
|
||||
context('failure conditions', () => {
|
||||
it('does not open if user does not have enough gold', (done) => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not open without Ultimate Gear achievement', (done) => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.achievements.ultimateGearSets = {healer: false, wizard: false, rogue: false, warrior: false};
|
||||
|
||||
try {
|
||||
buyArmoire(user);
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('cannotBuyItem'));
|
||||
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', () => {
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('gives Experience', () => {
|
||||
shared.fns.predictableRandom.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.eql(46);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('gives food', () => {
|
||||
let honey = content.food.Honey;
|
||||
|
||||
shared.fns.randomVal.returns(honey);
|
||||
shared.fns.predictableRandom.returns(YIELD_FOOD);
|
||||
|
||||
buyArmoire(user);
|
||||
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.eql({Honey: 1});
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('does not give equipment if all equipment has been found', () => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.items.gear.owned = fullArmoire;
|
||||
user.stats.gp = 150;
|
||||
|
||||
buyArmoire(user);
|
||||
|
||||
expect(user.items.gear.owned).to.eql(fullArmoire);
|
||||
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||
|
||||
expect(armoireCount).to.eql(0);
|
||||
|
||||
expect(user.stats.exp).to.eql(30);
|
||||
expect(user.stats.gp).to.eql(50);
|
||||
});
|
||||
});
|
||||
|
||||
context('gear awards', () => {
|
||||
beforeEach(() => {
|
||||
let shield = content.gear.tree.shield.armoire.gladiatorShield;
|
||||
|
||||
shared.fns.randomVal.returns(shield);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('always drops equipment the first time', () => {
|
||||
delete user.flags.armoireOpened;
|
||||
shared.fns.predictableRandom.returns(YIELD_EXP);
|
||||
|
||||
buyArmoire(user);
|
||||
|
||||
expect(user.items.gear.owned).to.eql({
|
||||
weapon_warrior_0: true,
|
||||
shield_armoire_gladiatorShield: true,
|
||||
});
|
||||
|
||||
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||
|
||||
expect(armoireCount).to.eql(_.size(fullArmoire) - 1);
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('gives more equipment', () => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.items.gear.owned = {
|
||||
weapon_warrior_0: true,
|
||||
head_armoire_hornedIronHelm: true,
|
||||
};
|
||||
user.stats.gp = 200;
|
||||
|
||||
buyArmoire(user);
|
||||
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true, shield_armoire_gladiatorShield: true, head_armoire_hornedIronHelm: true});
|
||||
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||
|
||||
expect(armoireCount).to.eql(_.size(fullArmoire) - 2);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import sinon from 'sinon'; // eslint-disable-line no-shadow
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
import buyGear from '../../../common/script/ops/buyGear';
|
||||
import shared from '../../../common/script';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../../../common/script/libs/errors';
|
||||
import i18n from '../../../common/script/i18n';
|
||||
|
||||
describe('shared.ops.buyGear', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser({
|
||||
items: {
|
||||
gear: {
|
||||
owned: {
|
||||
weapon_warrior_0: true,
|
||||
},
|
||||
equipped: {
|
||||
weapon_warrior_0: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
stats: { gp: 200 },
|
||||
});
|
||||
|
||||
sinon.stub(shared.fns, 'randomVal');
|
||||
sinon.stub(shared.fns, 'predictableRandom');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
shared.fns.randomVal.restore();
|
||||
shared.fns.predictableRandom.restore();
|
||||
});
|
||||
|
||||
context('Gear', () => {
|
||||
it('adds equipment to inventory', () => {
|
||||
user.stats.gp = 31;
|
||||
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql({ weapon_warrior_0: true, armor_warrior_1: true });
|
||||
});
|
||||
|
||||
it('deducts gold from user', () => {
|
||||
user.stats.gp = 31;
|
||||
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.stats.gp).to.eql(1);
|
||||
});
|
||||
|
||||
it('auto equips equipment if user has auto-equip preference turned on', () => {
|
||||
user.stats.gp = 31;
|
||||
user.preferences.autoEquip = true;
|
||||
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('armor', 'armor_warrior_1');
|
||||
});
|
||||
|
||||
it('buyGears equipment but does not auto-equip', () => {
|
||||
user.stats.gp = 31;
|
||||
user.preferences.autoEquip = false;
|
||||
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.items.gear.equipped.property).to.not.equal('armor_warrior_1');
|
||||
});
|
||||
|
||||
it('does not buyGear equipment twice', (done) => {
|
||||
user.stats.gp = 62;
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
try {
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('equipmentAlreadyOwned'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
// TODO after user.ops.equip is done
|
||||
xit('removes one-handed weapon and shield if auto-equip is on and a two-hander is bought', () => {
|
||||
user.stats.gp = 100;
|
||||
user.preferences.autoEquip = true;
|
||||
buyGear(user, {params: {key: 'shield_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'shield_warrior_1'}});
|
||||
buyGear(user, {params: {key: 'weapon_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'weapon_warrior_1'}});
|
||||
|
||||
buyGear(user, {params: {key: 'weapon_wizard_1'}});
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('shield', 'shield_base_0');
|
||||
expect(user.items.gear.equipped).to.have.property('weapon', 'weapon_wizard_1');
|
||||
});
|
||||
|
||||
// TODO after user.ops.equip is done
|
||||
xit('buyGears two-handed equipment but does not automatically remove sword or shield', () => {
|
||||
user.stats.gp = 100;
|
||||
user.preferences.autoEquip = false;
|
||||
buyGear(user, {params: {key: 'shield_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'shield_warrior_1'}});
|
||||
buyGear(user, {params: {key: 'weapon_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'weapon_warrior_1'}});
|
||||
|
||||
buyGear(user, {params: {key: 'weapon_wizard_1'}});
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('shield', 'shield_warrior_1');
|
||||
expect(user.items.gear.equipped).to.have.property('weapon', 'weapon_warrior_1');
|
||||
});
|
||||
|
||||
it('does not buyGear equipment without enough Gold', (done) => {
|
||||
user.stats.gp = 20;
|
||||
|
||||
try {
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
||||
expect(user.items.gear.owned).to.not.have.property('armor_warrior_1');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
/* eslint-disable camelcase */
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
import buyPotion from '../../../common/script/ops/buyPotion';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../../../common/script/libs/errors';
|
||||
import i18n from '../../../common/script/i18n';
|
||||
|
||||
describe('shared.ops.buyPotion', () => {
|
||||
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;
|
||||
buyPotion(user);
|
||||
expect(user.stats.hp).to.eql(45);
|
||||
});
|
||||
|
||||
it('does not increase hp above 50', () => {
|
||||
user.stats.hp = 45;
|
||||
buyPotion(user);
|
||||
expect(user.stats.hp).to.eql(50);
|
||||
});
|
||||
|
||||
it('deducts 25 gp', () => {
|
||||
user.stats.hp = 45;
|
||||
buyPotion(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 {
|
||||
buyPotion(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();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -60,7 +60,7 @@ describe('shared.ops.buySpecialSpell', () => {
|
||||
user.stats.gp = 11;
|
||||
let item = content.special.thankyou;
|
||||
|
||||
let res = buySpecialSpell(user, {
|
||||
let [data, message] = buySpecialSpell(user, {
|
||||
params: {
|
||||
key: 'thankyou',
|
||||
},
|
||||
@@ -68,11 +68,11 @@ describe('shared.ops.buySpecialSpell', () => {
|
||||
|
||||
expect(user.stats.gp).to.equal(1);
|
||||
expect(user.items.special.thankyou).to.equal(1);
|
||||
expect(res.data).to.eql({
|
||||
expect(data).to.eql({
|
||||
items: user.items,
|
||||
stats: user.stats,
|
||||
});
|
||||
expect(res.message).to.equal(i18n.t('messageBought', {
|
||||
expect(message).to.equal(i18n.t('messageBought', {
|
||||
itemText: item.text(),
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -46,14 +46,12 @@ describe('shared.ops.changeClass', () => {
|
||||
user.stats.class = 'healer';
|
||||
user.items.gear.owned.armor_rogue_1 = true; // eslint-disable-line camelcase
|
||||
|
||||
let res = changeClass(user, {query: {class: 'rogue'}});
|
||||
expect(res).to.eql({
|
||||
data: {
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
},
|
||||
let [data] = changeClass(user, {query: {class: 'rogue'}});
|
||||
expect(data).to.eql({
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
});
|
||||
|
||||
expect(user.stats.class).to.equal('rogue');
|
||||
@@ -80,14 +78,12 @@ describe('shared.ops.changeClass', () => {
|
||||
user.stats.int = 4;
|
||||
user.flags.classSelected = true;
|
||||
|
||||
let res = changeClass(user);
|
||||
expect(res).to.eql({
|
||||
data: {
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
},
|
||||
let [data] = changeClass(user);
|
||||
expect(data).to.eql({
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
});
|
||||
|
||||
expect(user.preferences.disableClasses).to.be.false;
|
||||
@@ -122,14 +118,12 @@ describe('shared.ops.changeClass', () => {
|
||||
user.stats.int = 4;
|
||||
user.flags.classSelected = true;
|
||||
|
||||
let res = changeClass(user);
|
||||
expect(res).to.eql({
|
||||
data: {
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
},
|
||||
let [data] = changeClass(user);
|
||||
expect(data).to.eql({
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
});
|
||||
|
||||
expect(user.balance).to.equal(0.25);
|
||||
|
||||
@@ -13,7 +13,7 @@ describe('shared.ops.clearPMs', () => {
|
||||
|
||||
it('clears messages', () => {
|
||||
expect(user.inbox.messages).to.not.eql({});
|
||||
let result = clearPMs(user);
|
||||
let [result] = clearPMs(user);
|
||||
expect(user.inbox.messages).to.eql({});
|
||||
expect(result).to.eql({});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
|
||||
describe('shared.ops.clearPMs', () => {
|
||||
describe('shared.ops.deletePM', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -13,7 +13,7 @@ describe('shared.ops.clearPMs', () => {
|
||||
|
||||
it('delete message', () => {
|
||||
expect(user.inbox.messages).to.not.eql({ second: 'message' });
|
||||
let response = deletePM(user, { params: { id: 'first' } });
|
||||
let [response] = deletePM(user, { params: { id: 'first' } });
|
||||
expect(user.inbox.messages).to.eql({ second: 'message' });
|
||||
expect(response).to.eql({ second: 'message' });
|
||||
});
|
||||
|
||||
@@ -14,8 +14,8 @@ describe('shared.ops.deleteWebhook', () => {
|
||||
|
||||
it('succeeds', () => {
|
||||
user.preferences.webhooks = { 'some-id': {}, 'another-id': {} };
|
||||
let res = deleteWebhook(user, req);
|
||||
let [data] = deleteWebhook(user, req);
|
||||
expect(user.preferences.webhooks).to.eql({'another-id': {}});
|
||||
expect(res).to.equal(user.preferences.webhooks);
|
||||
expect(data).to.equal(user.preferences.webhooks);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,13 +18,11 @@ describe('shared.ops.disableClasses', () => {
|
||||
user.preferences.autoAllocate = false;
|
||||
user.stats.points = 2;
|
||||
|
||||
let res = disableClasses(user);
|
||||
expect(res).to.eql({
|
||||
data: {
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
},
|
||||
let [data] = disableClasses(user);
|
||||
expect(data).to.eql({
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
});
|
||||
|
||||
expect(user.stats.class).to.equal('warrior');
|
||||
|
||||
+12
-10
@@ -37,20 +37,20 @@ describe('shared.ops.equip', () => {
|
||||
equip(user, {params: {key: 'weapon_warrior_1'}});
|
||||
|
||||
// one-handed to one-handed
|
||||
let res = equip(user, {params: {key: 'weapon_warrior_2'}});
|
||||
expect(res.message).to.not.exists;
|
||||
let [, message] = equip(user, {params: {key: 'weapon_warrior_2'}});
|
||||
expect(message).to.not.exists;
|
||||
|
||||
// one-handed to two-handed
|
||||
res = equip(user, {params: {key: 'weapon_wizard_1'}});
|
||||
expect(res.message).to.not.exists;
|
||||
[, message] = equip(user, {params: {key: 'weapon_wizard_1'}});
|
||||
expect(message).to.not.exists;
|
||||
|
||||
// two-handed to two-handed
|
||||
res = equip(user, {params: {key: 'weapon_wizard_2'}});
|
||||
expect(res.message).to.not.exists;
|
||||
[, message] = equip(user, {params: {key: 'weapon_wizard_2'}});
|
||||
expect(message).to.not.exists;
|
||||
|
||||
// two-handed to one-handed
|
||||
res = equip(user, {params: {key: 'weapon_warrior_2'}});
|
||||
expect(res.message).to.not.exists;
|
||||
[, message] = equip(user, {params: {key: 'weapon_warrior_2'}});
|
||||
expect(message).to.not.exists;
|
||||
});
|
||||
|
||||
it('should send messages if equipping a two-hander causes the off-hander to be unequipped', () => {
|
||||
@@ -58,10 +58,11 @@ describe('shared.ops.equip', () => {
|
||||
equip(user, {params: {key: 'shield_warrior_1'}});
|
||||
|
||||
// equipping two-hander
|
||||
let res = equip(user, {params: {key: 'weapon_wizard_1'}});
|
||||
let [data, message] = equip(user, {params: {key: 'weapon_wizard_1'}});
|
||||
let weapon = content.gear.flat.weapon_wizard_1;
|
||||
let item = content.gear.flat.shield_warrior_1;
|
||||
|
||||
let res = {data, message};
|
||||
expect(res).to.eql({
|
||||
message: i18n.t('messageTwoHandedEquip', {twoHandedText: weapon.text(), offHandedText: item.text()}),
|
||||
data: user.items,
|
||||
@@ -74,8 +75,9 @@ describe('shared.ops.equip', () => {
|
||||
let weapon = content.gear.flat.weapon_wizard_1;
|
||||
let shield = content.gear.flat.shield_warrior_1;
|
||||
|
||||
let res = equip(user, {params: {key: 'shield_warrior_1'}});
|
||||
let [data, message] = equip(user, {params: {key: 'shield_warrior_1'}});
|
||||
|
||||
let res = {data, message};
|
||||
expect(res).to.eql({
|
||||
message: i18n.t('messageTwoHandedUnequip', {twoHandedText: weapon.text(), offHandedText: shield.text()}),
|
||||
data: user.items,
|
||||
|
||||
+38
-48
@@ -105,16 +105,14 @@ describe('shared.ops.feed', () => {
|
||||
let potionText = content.hatchingPotions[potion] ? content.hatchingPotions[potion].text() : potion;
|
||||
let eggText = content.eggs[egg] ? content.eggs[egg].text() : egg;
|
||||
|
||||
let res = feed(user, {params: {pet: 'Wolf-Base', food: 'Saddle'}});
|
||||
expect(res).to.eql({
|
||||
data: user.items.pets['Wolf-Base'],
|
||||
message: i18n.t('messageEvolve', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
let [data, message] = feed(user, {params: {pet: 'Wolf-Base', food: 'Saddle'}});
|
||||
expect(data).to.eql(user.items.pets['Wolf-Base']);
|
||||
expect(message).to.eql(i18n.t('messageEvolve', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
});
|
||||
}));
|
||||
|
||||
expect(user.items.food.Saddle).to.equal(1);
|
||||
expect(user.items.pets['Wolf-Base']).to.equal(-1);
|
||||
@@ -131,17 +129,15 @@ describe('shared.ops.feed', () => {
|
||||
let potionText = content.hatchingPotions[potion] ? content.hatchingPotions[potion].text() : potion;
|
||||
let eggText = content.eggs[egg] ? content.eggs[egg].text() : egg;
|
||||
|
||||
let res = feed(user, {params: {pet: 'Wolf-Base', food: 'Meat'}});
|
||||
expect(res).to.eql({
|
||||
data: user.items.pets['Wolf-Base'],
|
||||
message: i18n.t('messageLikesFood', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
foodText: food.text(),
|
||||
let [data, message] = feed(user, {params: {pet: 'Wolf-Base', food: 'Meat'}});
|
||||
expect(data).to.eql(user.items.pets['Wolf-Base']);
|
||||
expect(message).to.eql(i18n.t('messageLikesFood', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
});
|
||||
foodText: food.text(),
|
||||
}));
|
||||
|
||||
expect(user.items.food.Meat).to.equal(1);
|
||||
expect(user.items.pets['Wolf-Base']).to.equal(10);
|
||||
@@ -156,17 +152,15 @@ describe('shared.ops.feed', () => {
|
||||
let potionText = content.hatchingPotions[potion] ? content.hatchingPotions[potion].text() : potion;
|
||||
let eggText = content.eggs[egg] ? content.eggs[egg].text() : egg;
|
||||
|
||||
let res = feed(user, {params: {pet: 'Wolf-Spooky', food: 'Milk'}});
|
||||
expect(res).to.eql({
|
||||
data: user.items.pets['Wolf-Spooky'],
|
||||
message: i18n.t('messageLikesFood', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
foodText: food.text(),
|
||||
let [data, message] = feed(user, {params: {pet: 'Wolf-Spooky', food: 'Milk'}});
|
||||
expect(data).to.eql(user.items.pets['Wolf-Spooky']);
|
||||
expect(message).to.eql(i18n.t('messageLikesFood', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
});
|
||||
foodText: food.text(),
|
||||
}));
|
||||
|
||||
expect(user.items.food.Milk).to.equal(1);
|
||||
expect(user.items.pets['Wolf-Spooky']).to.equal(10);
|
||||
@@ -181,17 +175,15 @@ describe('shared.ops.feed', () => {
|
||||
let potionText = content.hatchingPotions[potion] ? content.hatchingPotions[potion].text() : potion;
|
||||
let eggText = content.eggs[egg] ? content.eggs[egg].text() : egg;
|
||||
|
||||
let res = feed(user, {params: {pet: 'Wolf-Base', food: 'Milk'}});
|
||||
expect(res).to.eql({
|
||||
data: user.items.pets['Wolf-Base'],
|
||||
message: i18n.t('messageDontEnjoyFood', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
foodText: food.text(),
|
||||
let [data, message] = feed(user, {params: {pet: 'Wolf-Base', food: 'Milk'}});
|
||||
expect(data).to.eql(user.items.pets['Wolf-Base']);
|
||||
expect(message).to.eql(i18n.t('messageDontEnjoyFood', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
});
|
||||
foodText: food.text(),
|
||||
}));
|
||||
|
||||
expect(user.items.food.Milk).to.equal(1);
|
||||
expect(user.items.pets['Wolf-Base']).to.equal(7);
|
||||
@@ -206,16 +198,14 @@ describe('shared.ops.feed', () => {
|
||||
let potionText = content.hatchingPotions[potion] ? content.hatchingPotions[potion].text() : potion;
|
||||
let eggText = content.eggs[egg] ? content.eggs[egg].text() : egg;
|
||||
|
||||
let res = feed(user, {params: {pet: 'Wolf-Base', food: 'Milk'}});
|
||||
expect(res).to.eql({
|
||||
data: user.items.pets['Wolf-Base'],
|
||||
message: i18n.t('messageEvolve', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
let [data, message] = feed(user, {params: {pet: 'Wolf-Base', food: 'Milk'}});
|
||||
expect(data).to.eql(user.items.pets['Wolf-Base']);
|
||||
expect(message).to.eql(i18n.t('messageEvolve', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
});
|
||||
}));
|
||||
|
||||
expect(user.items.food.Milk).to.equal(1);
|
||||
expect(user.items.pets['Wolf-Base']).to.equal(-1);
|
||||
|
||||
+12
-12
@@ -99,9 +99,9 @@ describe('shared.ops.hatch', () => {
|
||||
user.items.eggs = {Wolf: 1};
|
||||
user.items.hatchingPotions = {Base: 1};
|
||||
user.items.pets = {};
|
||||
let res = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Base'}});
|
||||
expect(res.message).to.equal(i18n.t('messageHatched'));
|
||||
expect(res.data).to.eql(user.items);
|
||||
let [data, message] = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Base'}});
|
||||
expect(message).to.equal(i18n.t('messageHatched'));
|
||||
expect(data).to.eql(user.items);
|
||||
expect(user.items.pets).to.eql({'Wolf-Base': 5});
|
||||
expect(user.items.eggs).to.eql({Wolf: 0});
|
||||
expect(user.items.hatchingPotions).to.eql({Base: 0});
|
||||
@@ -111,9 +111,9 @@ describe('shared.ops.hatch', () => {
|
||||
user.items.eggs = {Cheetah: 1};
|
||||
user.items.hatchingPotions = {Base: 1};
|
||||
user.items.pets = {};
|
||||
let res = hatch(user, {params: {egg: 'Cheetah', hatchingPotion: 'Base'}});
|
||||
expect(res.message).to.equal(i18n.t('messageHatched'));
|
||||
expect(res.data).to.eql(user.items);
|
||||
let [data, message] = hatch(user, {params: {egg: 'Cheetah', hatchingPotion: 'Base'}});
|
||||
expect(message).to.equal(i18n.t('messageHatched'));
|
||||
expect(data).to.eql(user.items);
|
||||
expect(user.items.pets).to.eql({'Cheetah-Base': 5});
|
||||
expect(user.items.eggs).to.eql({Cheetah: 0});
|
||||
expect(user.items.hatchingPotions).to.eql({Base: 0});
|
||||
@@ -123,9 +123,9 @@ describe('shared.ops.hatch', () => {
|
||||
user.items.eggs = {Wolf: 1};
|
||||
user.items.hatchingPotions = {Spooky: 1};
|
||||
user.items.pets = {};
|
||||
let res = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Spooky'}});
|
||||
expect(res.message).to.equal(i18n.t('messageHatched'));
|
||||
expect(res.data).to.eql(user.items);
|
||||
let [data, message] = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Spooky'}});
|
||||
expect(message).to.equal(i18n.t('messageHatched'));
|
||||
expect(data).to.eql(user.items);
|
||||
expect(user.items.pets).to.eql({'Wolf-Spooky': 5});
|
||||
expect(user.items.eggs).to.eql({Wolf: 0});
|
||||
expect(user.items.hatchingPotions).to.eql({Spooky: 0});
|
||||
@@ -135,9 +135,9 @@ describe('shared.ops.hatch', () => {
|
||||
user.items.eggs = {Wolf: 1};
|
||||
user.items.hatchingPotions = {Base: 1};
|
||||
user.items.pets = {'Wolf-Base': -1};
|
||||
let res = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Base'}});
|
||||
expect(res.message).to.eql(i18n.t('messageHatched'));
|
||||
expect(res.data).to.eql(user.items);
|
||||
let [data, message] = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Base'}});
|
||||
expect(message).to.eql(i18n.t('messageHatched'));
|
||||
expect(data).to.eql(user.items);
|
||||
expect(user.items.pets).to.eql({'Wolf-Base': 5});
|
||||
expect(user.items.eggs).to.eql({Wolf: 0});
|
||||
expect(user.items.hatchingPotions).to.eql({Base: 0});
|
||||
|
||||
@@ -126,9 +126,9 @@ describe('user.ops.hourglassPurchase', () => {
|
||||
it('buys a pet', () => {
|
||||
user.purchased.plan.consecutive.trinkets = 2;
|
||||
|
||||
let response = hourglassPurchase(user, {params: {type: 'pets', key: 'MantisShrimp-Base'}});
|
||||
let [, message] = hourglassPurchase(user, {params: {type: 'pets', key: 'MantisShrimp-Base'}});
|
||||
|
||||
expect(response.message).to.eql(i18n.t('hourglassPurchase'));
|
||||
expect(message).to.eql(i18n.t('hourglassPurchase'));
|
||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||
expect(user.items.pets).to.eql({'MantisShrimp-Base': 5});
|
||||
});
|
||||
@@ -136,8 +136,8 @@ describe('user.ops.hourglassPurchase', () => {
|
||||
it('buys a mount', () => {
|
||||
user.purchased.plan.consecutive.trinkets = 2;
|
||||
|
||||
let response = hourglassPurchase(user, {params: {type: 'mounts', key: 'MantisShrimp-Base'}});
|
||||
expect(response.message).to.eql(i18n.t('hourglassPurchase'));
|
||||
let [, message] = hourglassPurchase(user, {params: {type: 'mounts', key: 'MantisShrimp-Base'}});
|
||||
expect(message).to.eql(i18n.t('hourglassPurchase'));
|
||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||
expect(user.items.mounts).to.eql({'MantisShrimp-Base': true});
|
||||
});
|
||||
|
||||
@@ -29,10 +29,10 @@ describe('shared.ops.openMysteryItem', () => {
|
||||
|
||||
user.purchased.plan.mysteryItems = [mysteryItemKey];
|
||||
|
||||
let response = openMysteryItem(user);
|
||||
let [data, message] = openMysteryItem(user);
|
||||
|
||||
expect(user.items.gear.owned[mysteryItemKey]).to.be.true;
|
||||
expect(response.message).to.equal(i18n.t('mysteryItemOpened'));
|
||||
expect(response.data).to.equal(user.items.gear.owned);
|
||||
expect(message).to.equal(i18n.t('mysteryItemOpened'));
|
||||
expect(data).to.equal(user.items.gear.owned);
|
||||
});
|
||||
});
|
||||
|
||||
+14
-14
@@ -10,7 +10,7 @@ import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
|
||||
describe('shared.ops.feed', () => {
|
||||
describe('shared.ops.purchase', () => {
|
||||
let user;
|
||||
let goldPoints = 40;
|
||||
let gemsBought = 40;
|
||||
@@ -128,7 +128,7 @@ describe('shared.ops.feed', () => {
|
||||
});
|
||||
});
|
||||
|
||||
context('successful feeding', () => {
|
||||
context('successful purchase', () => {
|
||||
let userGemAmount = 10;
|
||||
|
||||
before(() => {
|
||||
@@ -138,9 +138,9 @@ describe('shared.ops.feed', () => {
|
||||
});
|
||||
|
||||
it('purchases gems', () => {
|
||||
let purchaseResponse = purchase(user, {params: {type: 'gems', key: 'gem'}});
|
||||
let [, message] = purchase(user, {params: {type: 'gems', key: 'gem'}});
|
||||
|
||||
expect(purchaseResponse.message).to.equal(i18n.t('plusOneGem'));
|
||||
expect(message).to.equal(i18n.t('plusOneGem'));
|
||||
expect(user.balance).to.equal(userGemAmount + 0.25);
|
||||
expect(user.purchased.plan.gemsBought).to.equal(1);
|
||||
expect(user.stats.gp).to.equal(goldPoints - planGemLimits.convRate);
|
||||
@@ -150,9 +150,9 @@ describe('shared.ops.feed', () => {
|
||||
let type = 'eggs';
|
||||
let key = 'Wolf';
|
||||
|
||||
let purchaseResponse = purchase(user, {params: {type, key}});
|
||||
let [, message] = purchase(user, {params: {type, key}});
|
||||
|
||||
expect(purchaseResponse.message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(user.items[type][key]).to.equal(1);
|
||||
});
|
||||
|
||||
@@ -160,9 +160,9 @@ describe('shared.ops.feed', () => {
|
||||
let type = 'hatchingPotions';
|
||||
let key = 'Base';
|
||||
|
||||
let purchaseResponse = purchase(user, {params: {type, key}});
|
||||
let [, message] = purchase(user, {params: {type, key}});
|
||||
|
||||
expect(purchaseResponse.message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(user.items[type][key]).to.equal(1);
|
||||
});
|
||||
|
||||
@@ -170,9 +170,9 @@ describe('shared.ops.feed', () => {
|
||||
let type = 'food';
|
||||
let key = 'Meat';
|
||||
|
||||
let purchaseResponse = purchase(user, {params: {type, key}});
|
||||
let [, message] = purchase(user, {params: {type, key}});
|
||||
|
||||
expect(purchaseResponse.message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(user.items[type][key]).to.equal(1);
|
||||
});
|
||||
|
||||
@@ -180,9 +180,9 @@ describe('shared.ops.feed', () => {
|
||||
let type = 'quests';
|
||||
let key = 'gryphon';
|
||||
|
||||
let purchaseResponse = purchase(user, {params: {type, key}});
|
||||
let [, message] = purchase(user, {params: {type, key}});
|
||||
|
||||
expect(purchaseResponse.message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(user.items[type][key]).to.equal(1);
|
||||
});
|
||||
|
||||
@@ -190,9 +190,9 @@ describe('shared.ops.feed', () => {
|
||||
let type = 'gear';
|
||||
let key = 'headAccessory_special_tigerEars';
|
||||
|
||||
let purchaseResponse = purchase(user, {params: {type, key}});
|
||||
let [, message] = purchase(user, {params: {type, key}});
|
||||
|
||||
expect(purchaseResponse.message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(user.items.gear.owned[key]).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -39,9 +39,9 @@ describe('shared.ops.readCard', () => {
|
||||
});
|
||||
|
||||
it('reads a card', () => {
|
||||
let response = readCard(user, {params: {cardType: 'greeting'}});
|
||||
let [, message] = readCard(user, {params: {cardType: 'greeting'}});
|
||||
|
||||
expect(response.message).to.equal(i18n.t('readCard', {cardType}));
|
||||
expect(message).to.equal(i18n.t('readCard', {cardType}));
|
||||
expect(user.items.special[`${cardType}Received`]).to.be.empty;
|
||||
expect(user.flags.cardReceived).to.be.false;
|
||||
});
|
||||
|
||||
@@ -35,18 +35,18 @@ describe('shared.ops.rebirth', () => {
|
||||
});
|
||||
|
||||
it('rebirths a user with enough gems', () => {
|
||||
let response = rebirth(user);
|
||||
let [, message] = rebirth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('rebirthComplete'));
|
||||
expect(message).to.equal(i18n.t('rebirthComplete'));
|
||||
});
|
||||
|
||||
it('rebirths a user with not enough gems but max level', () => {
|
||||
user.balance = 0;
|
||||
user.stats.lvl = MAX_LEVEL;
|
||||
|
||||
let response = rebirth(user);
|
||||
let [, message] = rebirth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('rebirthComplete'));
|
||||
expect(message).to.equal(i18n.t('rebirthComplete'));
|
||||
});
|
||||
|
||||
it('resets user\'s taks values except for rewards to 0', () => {
|
||||
|
||||
@@ -33,9 +33,9 @@ describe('shared.ops.releaseBoth', () => {
|
||||
});
|
||||
|
||||
it('grants triad bingo with gems', () => {
|
||||
let response = releaseBoth(user);
|
||||
let [, message] = releaseBoth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(user.achievements.triadBingoCount).to.equal(1);
|
||||
});
|
||||
|
||||
@@ -44,24 +44,24 @@ describe('shared.ops.releaseBoth', () => {
|
||||
user.achievements.triadBingo = 1;
|
||||
user.achievements.triadBingoCount = 1;
|
||||
|
||||
let response = releaseBoth(user);
|
||||
let [, message] = releaseBoth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(user.achievements.triadBingoCount).to.equal(2);
|
||||
});
|
||||
|
||||
it('releases pets', () => {
|
||||
let response = releaseBoth(user);
|
||||
let [, message] = releaseBoth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(user.items.pets[animal]).to.be.empty;
|
||||
expect(user.items.mounts[animal]).to.equal(null);
|
||||
});
|
||||
|
||||
it('releases mounts', () => {
|
||||
let response = releaseBoth(user);
|
||||
let [, message] = releaseBoth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(user.items.mounts[animal]).to.equal(null);
|
||||
});
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ describe('shared.ops.releaseMounts', () => {
|
||||
});
|
||||
|
||||
it('releases mounts', () => {
|
||||
let response = releaseMounts(user);
|
||||
let [, message] = releaseMounts(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsReleased'));
|
||||
expect(message).to.equal(i18n.t('mountsReleased'));
|
||||
expect(user.items.mounts[animal]).to.equal(null);
|
||||
});
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ describe('shared.ops.releasePets', () => {
|
||||
});
|
||||
|
||||
it('releases pets', () => {
|
||||
let response = releasePets(user);
|
||||
let [, message] = releasePets(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('petsReleased'));
|
||||
expect(message).to.equal(i18n.t('petsReleased'));
|
||||
expect(user.items.pets[animal]).to.equal(0);
|
||||
});
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ describe('shared.ops.reroll', () => {
|
||||
});
|
||||
|
||||
it('rerolls a user with enough gems', () => {
|
||||
let response = reroll(user);
|
||||
let [, message] = reroll(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('rerollComplete'));
|
||||
expect(message).to.equal(i18n.t('rerollComplete'));
|
||||
});
|
||||
|
||||
it('reduces a user\'s balance', () => {
|
||||
|
||||
@@ -31,9 +31,9 @@ describe('shared.ops.reset', () => {
|
||||
|
||||
|
||||
it('resets a user', () => {
|
||||
let response = reset(user);
|
||||
let [, message] = reset(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('resetComplete'));
|
||||
expect(message).to.equal(i18n.t('resetComplete'));
|
||||
});
|
||||
|
||||
it('resets user\'s health', () => {
|
||||
|
||||
@@ -57,9 +57,9 @@ describe('shared.ops.revive', () => {
|
||||
let weaponKey = 'weapon_warrior_0';
|
||||
user.items.gear.owned[weaponKey] = true;
|
||||
|
||||
let reviveRequest = revive(user);
|
||||
let [, message] = revive(user);
|
||||
|
||||
expect(reviveRequest.message).to.equal(i18n.t('messageLostItem', { itemText: content.gear.flat[weaponKey].text()}));
|
||||
expect(message).to.equal(i18n.t('messageLostItem', { itemText: content.gear.flat[weaponKey].text()}));
|
||||
expect(user.items.gear.owned[weaponKey]).to.be.false;
|
||||
});
|
||||
|
||||
@@ -70,9 +70,9 @@ describe('shared.ops.revive', () => {
|
||||
user.items.gear.owned[weaponKey] = true;
|
||||
user.items.gear.equipped[itemToLose.type] = itemToLose.key;
|
||||
|
||||
let reviveRequest = revive(user);
|
||||
let [, message] = revive(user);
|
||||
|
||||
expect(reviveRequest.message).to.equal(i18n.t('messageLostItem', { itemText: itemToLose.text()}));
|
||||
expect(message).to.equal(i18n.t('messageLostItem', { itemText: itemToLose.text()}));
|
||||
expect(user.items.gear.equipped[itemToLose.type]).to.equal(`${itemToLose.type}_base_0`);
|
||||
});
|
||||
|
||||
@@ -83,9 +83,9 @@ describe('shared.ops.revive', () => {
|
||||
user.items.gear.owned[weaponKey] = true;
|
||||
user.items.gear.costume[itemToLose.type] = itemToLose.key;
|
||||
|
||||
let reviveRequest = revive(user);
|
||||
let [, message] = revive(user);
|
||||
|
||||
expect(reviveRequest.message).to.equal(i18n.t('messageLostItem', { itemText: itemToLose.text()}));
|
||||
expect(message).to.equal(i18n.t('messageLostItem', { itemText: itemToLose.text()}));
|
||||
expect(user.items.gear.costume[itemToLose.type]).to.equal(`${itemToLose.type}_base_0`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -66,16 +66,16 @@ describe('shared.ops.sell', () => {
|
||||
});
|
||||
|
||||
it('reduces item count from user', () => {
|
||||
let response = sell(user, {params: { type, key } });
|
||||
let [, message] = sell(user, {params: { type, key } });
|
||||
|
||||
expect(response.message).to.equal(i18n.t('sold', {type, key}));
|
||||
expect(message).to.equal(i18n.t('sold', {type, key}));
|
||||
expect(user.items[type][key]).to.equal(0);
|
||||
});
|
||||
|
||||
it('increases user\'s gold', () => {
|
||||
let response = sell(user, {params: { type, key } });
|
||||
let [, message] = sell(user, {params: { type, key } });
|
||||
|
||||
expect(response.message).to.equal(i18n.t('sold', {type, key}));
|
||||
expect(message).to.equal(i18n.t('sold', {type, key}));
|
||||
expect(user.stats.gp).to.equal(content[type][key].value);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,12 +7,12 @@ describe('shared.ops.sleep', () => {
|
||||
it('toggles user.preferences.sleep', () => {
|
||||
let user = generateUser();
|
||||
|
||||
let res = sleep(user);
|
||||
expect(res).to.eql({preferences: {sleep: true}});
|
||||
let [res] = sleep(user);
|
||||
expect(res).to.eql(true);
|
||||
expect(user.preferences.sleep).to.equal(true);
|
||||
|
||||
let res2 = sleep(user);
|
||||
expect(res2).to.eql({preferences: {sleep: false}});
|
||||
let [res2] = sleep(user);
|
||||
expect(res2).to.eql(false);
|
||||
expect(user.preferences.sleep).to.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -91,30 +91,30 @@ describe('shared.ops.unlock', () => {
|
||||
});
|
||||
|
||||
it('unlocks a full set', () => {
|
||||
let response = unlock(user, {query: {path: unlockPath}});
|
||||
let [, message] = unlock(user, {query: {path: unlockPath}});
|
||||
|
||||
expect(response.message).to.equal(i18n.t('unlocked'));
|
||||
expect(message).to.equal(i18n.t('unlocked'));
|
||||
expect(user.purchased.shirt.convict).to.be.true;
|
||||
});
|
||||
|
||||
it('unlocks a full set of gear', () => {
|
||||
let response = unlock(user, {query: {path: unlockGearSetPath}});
|
||||
let [, message] = unlock(user, {query: {path: unlockGearSetPath}});
|
||||
|
||||
expect(response.message).to.equal(i18n.t('unlocked'));
|
||||
expect(message).to.equal(i18n.t('unlocked'));
|
||||
expect(user.items.gear.owned.headAccessory_special_wolfEars).to.be.true;
|
||||
});
|
||||
|
||||
it('unlocks a an item', () => {
|
||||
let response = unlock(user, {query: {path: backgroundUnlockPath}});
|
||||
let [, message] = unlock(user, {query: {path: backgroundUnlockPath}});
|
||||
|
||||
expect(response.message).to.equal(i18n.t('unlocked'));
|
||||
expect(message).to.equal(i18n.t('unlocked'));
|
||||
expect(user.purchased.background.giant_florals).to.be.true;
|
||||
});
|
||||
|
||||
it('reduces a user\'s balance', () => {
|
||||
let response = unlock(user, {query: {path: unlockPath}});
|
||||
let [, message] = unlock(user, {query: {path: unlockPath}});
|
||||
|
||||
expect(response.message).to.equal(i18n.t('unlocked'));
|
||||
expect(message).to.equal(i18n.t('unlocked'));
|
||||
expect(user.balance).to.equal(usersStartingGems - unlockCost);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('shared.ops.updateTask', () => {
|
||||
}],
|
||||
});
|
||||
|
||||
let res = updateTask(habit, {
|
||||
let [res] = updateTask(habit, {
|
||||
body: {
|
||||
text: 'updated',
|
||||
id: '123',
|
||||
|
||||
Reference in New Issue
Block a user