fix test lint

This commit is contained in:
Matteo Pagliazzi
2019-10-08 20:45:38 +02:00
parent e37f4467f8
commit 85fb5f33aa
367 changed files with 6635 additions and 6080 deletions
+46 -46
View File
@@ -1,64 +1,64 @@
/* eslint-disable camelcase */
let count = require('../../website/common/script/count');
const count = require('../../website/common/script/count');
describe('count', () => {
describe('beastMasterProgress', () => {
it('returns 0 if no pets', () => {
let pets = {};
let beastMasterTotal = count.beastMasterProgress(pets);
const pets = {};
const beastMasterTotal = count.beastMasterProgress(pets);
expect(beastMasterTotal).to.eql(0);
});
it('counts drop pets', () => {
let pets = { 'Dragon-Red': 1, 'Wolf-Base': 2 };
let beastMasterTotal = count.beastMasterProgress(pets);
const pets = { 'Dragon-Red': 1, 'Wolf-Base': 2 };
const beastMasterTotal = count.beastMasterProgress(pets);
expect(beastMasterTotal).to.eql(2);
});
it('does not count quest pets', () => {
let pets = { 'Dragon-Red': 1, 'Gryphon-Base': 1 };
let beastMasterTotal = count.beastMasterProgress(pets);
const pets = { 'Dragon-Red': 1, 'Gryphon-Base': 1 };
const beastMasterTotal = count.beastMasterProgress(pets);
expect(beastMasterTotal).to.eql(1);
});
it('does not count pets hatched with premium potions', () => {
let pets = {
const pets = {
'Wolf-Spooky': 5,
'Dragon-Spooky': 5,
'FlyingPig-Base': 5,
};
let beastMasterTotal = count.beastMasterProgress(pets);
const beastMasterTotal = count.beastMasterProgress(pets);
expect(beastMasterTotal).to.eql(1);
});
it('does not count special pets', () => {
let pets = {
const pets = {
'Wolf-Base': 2,
'Wolf-Veteran': 1,
'Wolf-Cerberus': 1,
'Dragon-Hydra': 1,
};
let beastMasterTotal = count.beastMasterProgress(pets);
const beastMasterTotal = count.beastMasterProgress(pets);
expect(beastMasterTotal).to.eql(1);
});
it('counts drop pets that have been raised to a mount', () => {
let raisedToMount = -1;
let pets = { 'Dragon-Red': 1, 'Wolf-Base': raisedToMount };
let beastMasterTotal = count.beastMasterProgress(pets);
const raisedToMount = -1;
const pets = { 'Dragon-Red': 1, 'Wolf-Base': raisedToMount };
const beastMasterTotal = count.beastMasterProgress(pets);
expect(beastMasterTotal).to.eql(2);
});
it('does not counts drop pets that have been released', () => {
let releasedPet = 0;
let pets = { 'Dragon-Red': 1, 'Wolf-Base': releasedPet };
let beastMasterTotal = count.beastMasterProgress(pets);
const releasedPet = 0;
const pets = { 'Dragon-Red': 1, 'Wolf-Base': releasedPet };
const beastMasterTotal = count.beastMasterProgress(pets);
expect(beastMasterTotal).to.eql(1);
});
@@ -66,47 +66,47 @@ describe('count', () => {
describe('mountMasterProgress', () => {
it('returns 0 if no mounts', () => {
let mounts = {};
let mountMasterTotal = count.mountMasterProgress(mounts);
const mounts = {};
const mountMasterTotal = count.mountMasterProgress(mounts);
expect(mountMasterTotal).to.eql(0);
});
it('counts drop mounts', () => {
let mounts = { 'Dragon-Red': true, 'Wolf-Base': true };
let mountMasterTotal = count.mountMasterProgress(mounts);
const mounts = { 'Dragon-Red': true, 'Wolf-Base': true };
const mountMasterTotal = count.mountMasterProgress(mounts);
expect(mountMasterTotal).to.eql(2);
});
it('does not count premium mounts', () => {
let mounts = {
const mounts = {
'Dragon-Red': true,
'FlyingPig-Spooky': true,
};
let mountMasterTotal = count.mountMasterProgress(mounts);
const mountMasterTotal = count.mountMasterProgress(mounts);
expect(mountMasterTotal).to.eql(1);
});
it('does not count quest mounts', () => {
let mounts = { 'Dragon-Red': true, 'Gryphon-Base': true };
let mountMasterTotal = count.mountMasterProgress(mounts);
const mounts = { 'Dragon-Red': true, 'Gryphon-Base': true };
const mountMasterTotal = count.mountMasterProgress(mounts);
expect(mountMasterTotal).to.eql(1);
});
it('does not count special mounts', () => {
let mounts = { 'Wolf-Base': true, 'BearCub-Polar': true};
let mountMasterTotal = count.mountMasterProgress(mounts);
const mounts = { 'Wolf-Base': true, 'BearCub-Polar': true };
const mountMasterTotal = count.mountMasterProgress(mounts);
expect(mountMasterTotal).to.eql(1);
});
it('only counts drop mounts that are currently owned', () => {
let notCurrentlyOwned = false;
let mounts = { 'Dragon-Red': true, 'Wolf-Base': notCurrentlyOwned };
let mountMasterTotal = count.mountMasterProgress(mounts);
const notCurrentlyOwned = false;
const mounts = { 'Dragon-Red': true, 'Wolf-Base': notCurrentlyOwned };
const mountMasterTotal = count.mountMasterProgress(mounts);
expect(mountMasterTotal).to.eql(1);
});
@@ -114,7 +114,7 @@ describe('count', () => {
describe('remainingGearInSet', () => {
it('counts remaining gear based on set', () => {
let gear = {
const gear = {
weapon_wizard_0: true,
weapon_wizard_1: true,
weapon_warrior_0: true,
@@ -123,20 +123,20 @@ describe('count', () => {
weapon_armor_1: true,
};
let armoireCount = count.remainingGearInSet(gear, 'warrior');
const armoireCount = count.remainingGearInSet(gear, 'warrior');
expect(armoireCount).to.eql(20);
});
it.skip('includes previously owned items in count (https: //github.com/HabitRPG/habitrpg/issues/5624#issuecomment-124018717)', () => {
let gear = {
const gear = {
weapon_warrior_0: false,
weapon_warrior_1: false,
weapon_armor_0: true,
weapon_armor_1: true,
};
let armoireCount = count.remainingGearInSet(gear, 'warrior');
const armoireCount = count.remainingGearInSet(gear, 'warrior');
expect(armoireCount).to.eql(20);
});
@@ -144,45 +144,45 @@ describe('count', () => {
describe('dropPetsCurrentlyOwned', () => {
it('counts drop pets owned', () => {
let pets = {
const pets = {
'Wolf-Base': 2,
'Wolf-Red': 4,
};
let dropPets = count.dropPetsCurrentlyOwned(pets);
const dropPets = count.dropPetsCurrentlyOwned(pets);
expect(dropPets).to.eql(2);
});
it('does not count pets that have been raised to mounts', () => {
let pets = {
const pets = {
'Wolf-Base': -1,
'Wolf-Red': 4,
'Wolf-Veteran': 1,
'Gryphon-Base': 1,
};
let dropPets = count.dropPetsCurrentlyOwned(pets);
const dropPets = count.dropPetsCurrentlyOwned(pets);
expect(dropPets).to.eql(1);
});
it('does not count quest pets', () => {
let pets = {
const pets = {
'Wolf-Base': 2,
'Wolf-Red': 4,
'Gryphon-Base': 1,
};
let dropPets = count.dropPetsCurrentlyOwned(pets);
const dropPets = count.dropPetsCurrentlyOwned(pets);
expect(dropPets).to.eql(2);
});
it('does not count special pets', () => {
let pets = {
const pets = {
'Wolf-Base': 2,
'Wolf-Red': 4,
'Wolf-Veteran': 1,
};
let dropPets = count.dropPetsCurrentlyOwned(pets);
const dropPets = count.dropPetsCurrentlyOwned(pets);
expect(dropPets).to.eql(2);
});
@@ -190,16 +190,16 @@ describe('count', () => {
describe('questsOfCategory', () => {
it('counts user quest scrolls of a particular category', () => {
let quests = {
const quests = {
atom1: 2,
whale: 4,
kraken: 2,
sheep: 1,
goldenknight2: 1,
};
let petQuestCount = count.questsOfCategory(quests, 'pet');
let unlockableQuestCount = count.questsOfCategory(quests, 'unlockable');
let goldQuestCount = count.questsOfCategory(quests, 'gold');
const petQuestCount = count.questsOfCategory(quests, 'pet');
const unlockableQuestCount = count.questsOfCategory(quests, 'unlockable');
const goldQuestCount = count.questsOfCategory(quests, 'gold');
expect(petQuestCount).to.eql(3);
expect(unlockableQuestCount).to.eql(2);
+2 -2
View File
@@ -9,8 +9,8 @@ describe('shared.fns.autoAllocate', () => {
beforeEach(() => {
user = generateUser();
// necessary to test task training reset behavior
user.stats.toObject = function () {
let obj = JSON.parse(JSON.stringify(this));
user.stats.toObject = function toObject () {
const obj = JSON.parse(JSON.stringify(this));
return obj;
};
+1 -1
View File
@@ -11,7 +11,7 @@ describe('crit', () => {
});
it('computes', () => {
let result = crit.crit(user);
const result = crit.crit(user);
expect(result).to.eql(1);
});
});
+6 -6
View File
@@ -13,11 +13,11 @@ describe('shared.fns.handleTwoHanded', () => {
});
it('uses "messageTwoHandedUnequip" message if item is a shield and current weapon is two handed (and sets the user\'s weapon to the base one)', () => {
let item = content.gear.tree.shield.warrior['2'];
let currentWeapon = content.gear.tree.weapon.armoire.rancherLasso;
const item = content.gear.tree.shield.warrior['2'];
const currentWeapon = content.gear.tree.weapon.armoire.rancherLasso;
user.items.gear.equipped.weapon = 'weapon_armoire_rancherLasso';
let message = handleTwoHanded(user, item);
const message = handleTwoHanded(user, item);
expect(message).to.equal(i18n.t('messageTwoHandedUnequip', {
twoHandedText: currentWeapon.text(), offHandedText: item.text(),
}));
@@ -25,11 +25,11 @@ describe('shared.fns.handleTwoHanded', () => {
});
it('uses "messageTwoHandedEquip" message if item is two handed and currentShield exists but is not "shield_base_0" (and sets the user\'s shield to the base one)', () => {
let item = content.gear.tree.weapon.armoire.rancherLasso;
let currentShield = content.gear.tree.shield.armoire.gladiatorShield;
const item = content.gear.tree.weapon.armoire.rancherLasso;
const currentShield = content.gear.tree.shield.armoire.gladiatorShield;
user.items.gear.equipped.shield = 'shield_armoire_gladiatorShield';
let message = handleTwoHanded(user, item);
const message = handleTwoHanded(user, item);
expect(message).to.equal(i18n.t('messageTwoHandedEquip', {
twoHandedText: item.text(), offHandedText: currentShield.text(),
}));
+8 -8
View File
@@ -18,8 +18,8 @@ describe('shared.fns.predictableRandom', () => {
user.stats.hp = 43;
user.stats.gp = 34;
let val1 = predictableRandom(user);
let val2 = predictableRandom(user);
const val1 = predictableRandom(user);
const val2 = predictableRandom(user);
expect(val2).to.equal(val1);
});
@@ -27,24 +27,24 @@ describe('shared.fns.predictableRandom', () => {
it('returns a different value when user.stats is not the same and no seed is passed', () => {
user.stats.hp = 43;
user.stats.gp = 34;
let val1 = predictableRandom(user);
const val1 = predictableRandom(user);
user.stats.gp = 35;
let val2 = predictableRandom(user);
const val2 = predictableRandom(user);
expect(val2).to.not.equal(val1);
});
it('returns the same value when the same seed is passed', () => {
let val1 = predictableRandom(user, 4452673762);
let val2 = predictableRandom(user, 4452673762);
const val1 = predictableRandom(user, 4452673762);
const val2 = predictableRandom(user, 4452673762);
expect(val2).to.equal(val1);
});
it('returns a different value when a different seed is passed', () => {
let val1 = predictableRandom(user, 4452673761);
let val2 = predictableRandom(user, 4452673762);
const val1 = predictableRandom(user, 4452673761);
const val2 = predictableRandom(user, 4452673762);
expect(val2).to.not.equal(val1);
});
+5 -4
View File
@@ -113,8 +113,9 @@ describe('common.fns.randomDrop', () => {
randomDrop(user, { task, predictableRandom });
expect(user._tmp.drop.type).to.eql('HatchingPotion');
expect(user._tmp.drop.value).to.eql(4);
let acceptableDrops = ['Zombie', 'CottonCandyPink', 'CottonCandyBlue'];
expect(acceptableDrops).to.contain(user._tmp.drop.key); // deterministically 'CottonCandyBlue'
const acceptableDrops = ['Zombie', 'CottonCandyPink', 'CottonCandyBlue'];
// deterministically 'CottonCandyBlue'
expect(acceptableDrops).to.contain(user._tmp.drop.key);
});
it('drops an uncommon potion', () => {
@@ -123,7 +124,7 @@ describe('common.fns.randomDrop', () => {
randomDrop(user, { task, predictableRandom });
expect(user._tmp.drop.type).to.eql('HatchingPotion');
expect(user._tmp.drop.value).to.eql(3);
let acceptableDrops = ['Red', 'Shade', 'Skeleton'];
const acceptableDrops = ['Red', 'Shade', 'Skeleton'];
expect(acceptableDrops).to.contain(user._tmp.drop.key); // always skeleton
});
@@ -133,7 +134,7 @@ describe('common.fns.randomDrop', () => {
randomDrop(user, { task, predictableRandom });
expect(user._tmp.drop.type).to.eql('HatchingPotion');
expect(user._tmp.drop.value).to.eql(2);
let acceptableDrops = ['Base', 'White', 'Desert'];
const acceptableDrops = ['Base', 'White', 'Desert'];
expect(acceptableDrops).to.contain(user._tmp.drop.key); // always Desert
});
});
+9 -9
View File
@@ -11,7 +11,7 @@ describe('common.fns.statsComputed', () => {
});
it('returns default values', () => {
let result = statsComputed(user);
const result = statsComputed(user);
expect(result.per).to.eql(0);
expect(result.con).to.eql(0);
expect(result.str).to.eql(0);
@@ -20,7 +20,7 @@ describe('common.fns.statsComputed', () => {
it('calculates stat bonuses for equipment', () => {
user.items.gear.equipped.weapon = 'weapon_rogue_1';
let result = statsComputed(user);
const result = statsComputed(user);
expect(result.str).to.eql(2);
expect(result.gearBonus.str).to.eql(2);
@@ -28,7 +28,7 @@ describe('common.fns.statsComputed', () => {
it('calculates stat bonuses for class', () => {
user.items.gear.equipped.weapon = 'weapon_warrior_1';
let result = statsComputed(user);
const result = statsComputed(user);
expect(result.str).to.eql(4.5);
expect(result.gearBonus.str).to.eql(3);
@@ -37,7 +37,7 @@ describe('common.fns.statsComputed', () => {
it('calculates stat bonuses for level', () => {
user.stats.lvl = 25;
let result = statsComputed(user);
const result = statsComputed(user);
expect(result.str).to.eql(12);
expect(result.levelBonus.str).to.eql(12);
@@ -45,7 +45,7 @@ describe('common.fns.statsComputed', () => {
it('correctly caps level stat bonuses', () => {
user.stats.lvl = 150;
let result = statsComputed(user);
const result = statsComputed(user);
expect(result.str).to.eql(50);
expect(result.levelBonus.str).to.eql(50);
@@ -53,7 +53,7 @@ describe('common.fns.statsComputed', () => {
it('sets baseStat field', () => {
user.stats.str = 20;
let result = statsComputed(user);
const result = statsComputed(user);
expect(result.str).to.eql(20);
expect(result.baseStat.str).to.eql(20);
@@ -61,7 +61,7 @@ describe('common.fns.statsComputed', () => {
it('sets buffs field', () => {
user.stats.buffs.str = 150;
let result = statsComputed(user);
const result = statsComputed(user);
expect(result.str).to.eql(150);
expect(result.buff.str).to.eql(150);
@@ -70,14 +70,14 @@ describe('common.fns.statsComputed', () => {
it('calculates mp from intelligence', () => {
user.stats.int = 150;
user.stats.buffs.int = 50;
let result = statsComputed(user);
const result = statsComputed(user);
expect(result.maxMP).to.eql(430);
});
it('calculates stat bonuses for back equipment', () => {
user.items.gear.equipped.back = 'back_special_takeThis';
let result = statsComputed(user);
const result = statsComputed(user);
expect(result.int).to.eql(1);
expect(result.per).to.eql(1);
+15 -19
View File
@@ -8,24 +8,22 @@ describe('shared.fns.ultimateGear', () => {
beforeEach(() => {
user = generateUser();
user.achievements.ultimateGearSets.toObject = function () {
user.achievements.ultimateGearSets.toObject = function toIbject () {
return this;
};
user.addNotification = sinon.spy();
});
it('sets armoirEnabled when partial achievement already achieved', () => {
let items = {
const items = {
gear: {
owned: {
toObject: () => {
return {
armor_warrior_5: true, // eslint-disable-line camelcase
shield_warrior_5: true, // eslint-disable-line camelcase
head_warrior_5: true, // eslint-disable-line camelcase
weapon_warrior_6: true, // eslint-disable-line camelcase
};
},
toObject: () => ({
armor_warrior_5: true, // eslint-disable-line camelcase
shield_warrior_5: true, // eslint-disable-line camelcase
head_warrior_5: true, // eslint-disable-line camelcase
weapon_warrior_6: true, // eslint-disable-line camelcase
}),
},
},
};
@@ -40,17 +38,15 @@ describe('shared.fns.ultimateGear', () => {
it('does not set armoireEnabled when gear is not owned', () => {
user.flags.armoireEnabled = false;
let items = {
const items = {
gear: {
owned: {
toObject: () => {
return {
armor_warrior_5: true, // eslint-disable-line camelcase
shield_warrior_5: true, // eslint-disable-line camelcase
head_warrior_5: true, // eslint-disable-line camelcase
weapon_warrior_6: false, // eslint-disable-line camelcase
};
},
toObject: () => ({
armor_warrior_5: true, // eslint-disable-line camelcase
shield_warrior_5: true, // eslint-disable-line camelcase
head_warrior_5: true, // eslint-disable-line camelcase
weapon_warrior_6: false, // eslint-disable-line camelcase
}),
},
},
};
+9 -9
View File
@@ -12,8 +12,8 @@ describe('common.fns.updateStats', () => {
});
context('No Hp', () => {
it('updates user\s hp', () => {
let stats = { hp: 0 };
it('updates user\'s hp', () => {
const stats = { hp: 0 };
expect(user.stats.hp).to.not.eql(0);
updateStats(user, stats);
expect(user.stats.hp).to.eql(0);
@@ -22,7 +22,7 @@ describe('common.fns.updateStats', () => {
});
it('does not lower hp below 0', () => {
let stats = {
const stats = {
hp: -5,
};
updateStats(user, stats);
@@ -32,7 +32,7 @@ describe('common.fns.updateStats', () => {
context('Stat Allocation', () => {
it('adds only attribute points up to user\'s level', () => {
let stats = {
const stats = {
exp: 261,
};
expect(user.stats.points).to.eql(0);
@@ -45,7 +45,7 @@ describe('common.fns.updateStats', () => {
});
it('adds an attibute point when user\'s stat points are less than max level', () => {
let stats = {
const stats = {
exp: 3581,
};
@@ -61,7 +61,7 @@ describe('common.fns.updateStats', () => {
});
it('does not add an attibute point when user\'s stat points are equal to max level', () => {
let stats = {
const stats = {
exp: 3581,
};
@@ -77,7 +77,7 @@ describe('common.fns.updateStats', () => {
});
it('does not add an attibute point when user\'s stat points + unallocated points are equal to max level', () => {
let stats = {
const stats = {
exp: 3581,
};
@@ -94,7 +94,7 @@ describe('common.fns.updateStats', () => {
});
it('only awards stat points up to level 100 if user is missing unallocated stat points and is over level 100', () => {
let stats = {
const stats = {
exp: 5581,
};
@@ -182,7 +182,7 @@ describe('common.fns.updateStats', () => {
xit('auto allocates stats if automaticAllocation is turned on', () => {
sandbox.stub(user.fns, 'autoAllocate');
let stats = {
const stats = {
exp: 261,
};
+89 -87
View File
@@ -5,11 +5,11 @@ import {
describe('achievements', () => {
describe('general well-formedness', () => {
let user = generateUser();
let achievements = shared.achievements.getAchievementsForProfile(user);
const user = generateUser();
const achievements = shared.achievements.getAchievementsForProfile(user);
it('each category has \'label\' and \'achievements\' fields', () => {
_.each(achievements, (category) => {
_.each(achievements, category => {
expect(category).to.have.property('label')
.that.is.a('string');
expect(category).to.have.property('achievements')
@@ -18,8 +18,8 @@ describe('achievements', () => {
});
it('each achievement has all required fields of correct types', () => {
_.each(achievements, (category) => {
_.each(category.achievements, (achiev) => {
_.each(achievements, category => {
_.each(category.achievements, achiev => {
// May have additional fields (such as 'value' and 'optionalCount').
expect(achiev).to.contain.all.keys(['title', 'text', 'icon', 'earned', 'index']);
expect(achiev.title).to.be.a('string');
@@ -32,18 +32,18 @@ describe('achievements', () => {
});
it('categories have unique labels', () => {
let achievementsArray = _.values(achievements).map(cat => cat.label);
let labels = _.uniq(achievementsArray);
const achievementsArray = _.values(achievements).map(cat => cat.label);
const labels = _.uniq(achievementsArray);
expect(labels.length).to.be.greaterThan(0);
expect(labels.length).to.eql(_.size(achievements));
});
it('achievements have unique keys', () => {
let keysSoFar = {};
const keysSoFar = {};
_.each(achievements, (category) => {
_.keys(category.achievements).forEach((key) => {
_.each(achievements, category => {
_.keys(category.achievements).forEach(key => {
expect(keysSoFar[key]).to.be.undefined;
keysSoFar[key] = key;
});
@@ -51,11 +51,11 @@ describe('achievements', () => {
});
it('achievements have unique indices', () => {
let indicesSoFar = {};
const indicesSoFar = {};
_.each(achievements, (category) => {
_.each(category.achievements, (achiev) => {
let i = achiev.index;
_.each(achievements, category => {
_.each(category.achievements, achiev => {
const i = achiev.index;
expect(indicesSoFar[i]).to.be.undefined;
indicesSoFar[i] = i;
});
@@ -63,19 +63,19 @@ describe('achievements', () => {
});
it('all categories have at least 1 achievement', () => {
_.each(achievements, (category) => {
_.each(achievements, category => {
expect(_.size(category.achievements)).to.be.greaterThan(0);
});
});
});
describe('unearned basic achievements', () => {
let user = generateUser();
let basicAchievs = shared.achievements.getAchievementsForProfile(user).basic.achievements;
const user = generateUser();
const basicAchievs = shared.achievements.getAchievementsForProfile(user).basic.achievements;
it('streak and perfect day achievements exist with counts', () => {
let streak = basicAchievs.streak;
let perfect = basicAchievs.perfect;
const { streak } = basicAchievs;
const { perfect } = basicAchievs;
expect(streak).to.exist;
expect(streak).to.have.property('optionalCount')
@@ -86,8 +86,8 @@ describe('achievements', () => {
});
it('party up/on achievements exist with no counts', () => {
let partyUp = basicAchievs.partyUp;
let partyOn = basicAchievs.partyOn;
const { partyUp } = basicAchievs;
const { partyOn } = basicAchievs;
expect(partyUp).to.exist;
expect(partyUp.optionalCount).to.be.undefined;
@@ -96,9 +96,9 @@ describe('achievements', () => {
});
it('pet/mount master and triad bingo achievements exist with counts', () => {
let beastMaster = basicAchievs.beastMaster;
let mountMaster = basicAchievs.mountMaster;
let triadBingo = basicAchievs.triadBingo;
const { beastMaster } = basicAchievs;
const { mountMaster } = basicAchievs;
const { triadBingo } = basicAchievs;
expect(beastMaster).to.exist;
expect(beastMaster).to.have.property('optionalCount')
@@ -112,9 +112,9 @@ describe('achievements', () => {
});
it('ultimate gear achievements exist with no counts', () => {
let gearTypes = ['healer', 'rogue', 'warrior', 'mage'];
gearTypes.forEach((gear) => {
let gearAchiev = basicAchievs[`${gear}UltimateGear`];
const gearTypes = ['healer', 'rogue', 'warrior', 'mage'];
gearTypes.forEach(gear => {
const gearAchiev = basicAchievs[`${gear}UltimateGear`];
expect(gearAchiev).to.exist;
expect(gearAchiev.optionalCount).to.be.undefined;
@@ -122,9 +122,9 @@ describe('achievements', () => {
});
it('card achievements exist with counts', () => {
let cardTypes = ['greeting', 'thankyou', 'birthday', 'congrats', 'getwell', 'goodluck'];
cardTypes.forEach((card) => {
let cardAchiev = basicAchievs[`${card}Cards`];
const cardTypes = ['greeting', 'thankyou', 'birthday', 'congrats', 'getwell', 'goodluck'];
cardTypes.forEach(card => {
const cardAchiev = basicAchievs[`${card}Cards`];
expect(cardAchiev).to.exist;
expect(cardAchiev).to.have.property('optionalCount')
@@ -133,7 +133,7 @@ describe('achievements', () => {
});
it('rebirth achievement exists with no count', () => {
let rebirth = basicAchievs.rebirth;
const { rebirth } = basicAchievs;
expect(rebirth).to.exist;
expect(rebirth.optionalCount).to.be.undefined;
@@ -141,12 +141,13 @@ describe('achievements', () => {
});
describe('unearned seasonal achievements', () => {
let user = generateUser();
let seasonalAchievs = shared.achievements.getAchievementsForProfile(user).seasonal.achievements;
const user = generateUser();
const userAchievements = shared.achievements.getAchievementsForProfile(user);
const seasonalAchievs = userAchievements.seasonal.achievements;
it('habiticaDays and habitBirthdays achievements exist with counts', () => {
let habiticaDays = seasonalAchievs.habiticaDays;
let habitBirthdays = seasonalAchievs.habitBirthdays;
const { habiticaDays } = seasonalAchievs;
const { habitBirthdays } = seasonalAchievs;
expect(habiticaDays).to.exist;
expect(habiticaDays).to.have.property('optionalCount')
@@ -157,9 +158,9 @@ describe('achievements', () => {
});
it('spell achievements exist with counts', () => {
let spellTypes = ['snowball', 'spookySparkles', 'shinySeed', 'seafoam'];
spellTypes.forEach((spell) => {
let spellAchiev = seasonalAchievs[spell];
const spellTypes = ['snowball', 'spookySparkles', 'shinySeed', 'seafoam'];
spellTypes.forEach(spell => {
const spellAchiev = seasonalAchievs[spell];
expect(spellAchiev).to.exist;
expect(spellAchiev).to.have.property('optionalCount')
@@ -168,16 +169,16 @@ describe('achievements', () => {
});
it('quest achievements do not exist', () => {
let quests = ['dilatory', 'stressbeast', 'burnout', 'bewilder'];
quests.forEach((quest) => {
let questAchiev = seasonalAchievs[`${quest}Quest`];
const quests = ['dilatory', 'stressbeast', 'burnout', 'bewilder'];
quests.forEach(quest => {
const questAchiev = seasonalAchievs[`${quest}Quest`];
expect(questAchiev).to.not.exist;
});
});
it('costumeContests achievement exists with count', () => {
let costumeContests = seasonalAchievs.costumeContests;
const { costumeContests } = seasonalAchievs;
expect(costumeContests).to.exist;
expect(costumeContests).to.have.property('optionalCount')
@@ -185,9 +186,9 @@ describe('achievements', () => {
});
it('card achievements exist with counts', () => {
let cardTypes = ['nye', 'valentine'];
cardTypes.forEach((card) => {
let cardAchiev = seasonalAchievs[`${card}Cards`];
const cardTypes = ['nye', 'valentine'];
cardTypes.forEach(card => {
const cardAchiev = seasonalAchievs[`${card}Cards`];
expect(cardAchiev).to.exist;
expect(cardAchiev).to.have.property('optionalCount')
@@ -197,11 +198,11 @@ describe('achievements', () => {
});
describe('unearned special achievements', () => {
let user = generateUser();
let specialAchievs = shared.achievements.getAchievementsForProfile(user).special.achievements;
const user = generateUser();
const specialAchievs = shared.achievements.getAchievementsForProfile(user).special.achievements;
it('habitSurveys achievement exists with count', () => {
let habitSurveys = specialAchievs.habitSurveys;
const { habitSurveys } = specialAchievs;
expect(habitSurveys).to.exist;
expect(habitSurveys).to.have.property('optionalCount')
@@ -209,7 +210,7 @@ describe('achievements', () => {
});
it('contributor achievement exists with value and no count', () => {
let contributor = specialAchievs.contributor;
const { contributor } = specialAchievs;
expect(contributor).to.exist;
expect(contributor).to.have.property('value')
@@ -218,37 +219,38 @@ describe('achievements', () => {
});
it('npc achievement is hidden if unachieved', () => {
let npc = specialAchievs.npc;
const { npc } = specialAchievs;
expect(npc).to.not.exist;
});
it('kickstarter achievement is hidden if unachieved', () => {
let kickstarter = specialAchievs.kickstarter;
const { kickstarter } = specialAchievs;
expect(kickstarter).to.not.exist;
});
it('veteran achievement is hidden if unachieved', () => {
let veteran = specialAchievs.veteran;
const { veteran } = specialAchievs;
expect(veteran).to.not.exist;
});
it('originalUser achievement is hidden if unachieved', () => {
let originalUser = specialAchievs.originalUser;
const { originalUser } = specialAchievs;
expect(originalUser).to.not.exist;
});
});
describe('earned seasonal achievements', () => {
let user = generateUser();
let quests = ['dilatory', 'stressbeast', 'burnout', 'bewilder'];
quests.forEach((quest) => {
const user = generateUser();
const quests = ['dilatory', 'stressbeast', 'burnout', 'bewilder'];
quests.forEach(quest => {
user.achievements.quests[quest] = 1;
});
let seasonalAchievs = shared.achievements.getAchievementsForProfile(user).seasonal.achievements;
const userAchievements = shared.achievements.getAchievementsForProfile(user);
const seasonalAchievs = userAchievements.seasonal.achievements;
it('quest achievements exist', () => {
quests.forEach((quest) => {
let questAchiev = seasonalAchievs[`${quest}Quest`];
quests.forEach(quest => {
const questAchiev = seasonalAchievs[`${quest}Quest`];
expect(questAchiev).to.exist;
expect(questAchiev.optionalCount).to.be.undefined;
@@ -257,19 +259,19 @@ describe('achievements', () => {
});
describe('earned special achievements', () => {
let user = generateUser({
const user = generateUser({
achievements: {
habitSurveys: 2,
veteran: true,
originalUser: true,
},
backer: {tier: 3},
contributor: {level: 1},
backer: { tier: 3 },
contributor: { level: 1 },
});
let specialAchievs = shared.achievements.getAchievementsForProfile(user).special.achievements;
const specialAchievs = shared.achievements.getAchievementsForProfile(user).special.achievements;
it('habitSurveys achievement is earned with correct value', () => {
let habitSurveys = specialAchievs.habitSurveys;
const { habitSurveys } = specialAchievs;
expect(habitSurveys).to.exist;
expect(habitSurveys.earned).to.eql(true);
@@ -277,7 +279,7 @@ describe('achievements', () => {
});
it('contributor achievement is earned with correct value', () => {
let contributor = specialAchievs.contributor;
const { contributor } = specialAchievs;
expect(contributor).to.exist;
expect(contributor.earned).to.eql(true);
@@ -285,10 +287,10 @@ describe('achievements', () => {
});
it('npc achievement is earned with correct value', () => {
let npcUser = generateUser({
backer: {npc: 'test'},
const npcUser = generateUser({
backer: { npc: 'test' },
});
let npc = shared.achievements.getAchievementsForProfile(npcUser).special.achievements.npc;
const { npc } = shared.achievements.getAchievementsForProfile(npcUser).special.achievements;
expect(npc).to.exist;
expect(npc.earned).to.eql(true);
@@ -296,7 +298,7 @@ describe('achievements', () => {
});
it('kickstarter achievement is earned with correct value', () => {
let kickstarter = specialAchievs.kickstarter;
const { kickstarter } = specialAchievs;
expect(kickstarter).to.exist;
expect(kickstarter.earned).to.eql(true);
@@ -304,14 +306,14 @@ describe('achievements', () => {
});
it('veteran achievement is earned', () => {
let veteran = specialAchievs.veteran;
const { veteran } = specialAchievs;
expect(veteran).to.exist;
expect(veteran.earned).to.eql(true);
});
it('originalUser achievement is earned', () => {
let originalUser = specialAchievs.originalUser;
const { originalUser } = specialAchievs;
expect(originalUser).to.exist;
expect(originalUser.earned).to.eql(true);
@@ -320,12 +322,12 @@ describe('achievements', () => {
describe('mountMaster, beastMaster, and triadBingo achievements', () => {
it('master and triad bingo achievements do not include *Text2 strings if no keys have been used', () => {
let user = generateUser();
let basicAchievs = shared.achievements.getAchievementsForProfile(user).basic.achievements;
const user = generateUser();
const basicAchievs = shared.achievements.getAchievementsForProfile(user).basic.achievements;
let beastMaster = basicAchievs.beastMaster;
let mountMaster = basicAchievs.mountMaster;
let triadBingo = basicAchievs.triadBingo;
const { beastMaster } = basicAchievs;
const { mountMaster } = basicAchievs;
const { triadBingo } = basicAchievs;
expect(beastMaster.text).to.not.match(/released/);
expect(beastMaster.text).to.not.match(/0 time\(s\)/);
@@ -336,18 +338,18 @@ describe('achievements', () => {
});
it('master and triad bingo achievements includes *Text2 strings if keys have been used', () => {
let user = generateUser({
const user = generateUser({
achievements: {
beastMasterCount: 1,
mountMasterCount: 2,
triadBingoCount: 3,
},
});
let basicAchievs = shared.achievements.getAchievementsForProfile(user).basic.achievements;
const basicAchievs = shared.achievements.getAchievementsForProfile(user).basic.achievements;
let beastMaster = basicAchievs.beastMaster;
let mountMaster = basicAchievs.mountMaster;
let triadBingo = basicAchievs.triadBingo;
const { beastMaster } = basicAchievs;
const { mountMaster } = basicAchievs;
const { triadBingo } = basicAchievs;
expect(beastMaster.text).to.match(/released/);
expect(beastMaster.text).to.match(/1 time\(s\)/);
@@ -360,13 +362,13 @@ describe('achievements', () => {
describe('ultimateGear achievements', () => {
it('title and text contain localized class info', () => {
let user = generateUser();
let basicAchievs = shared.achievements.getAchievementsForProfile(user).basic.achievements;
let gearTypes = ['healer', 'rogue', 'warrior', 'mage'];
const user = generateUser();
const basicAchievs = shared.achievements.getAchievementsForProfile(user).basic.achievements;
const gearTypes = ['healer', 'rogue', 'warrior', 'mage'];
gearTypes.forEach((gear) => {
let gearAchiev = basicAchievs[`${gear}UltimateGear`];
let classNameRegex = new RegExp(gear.charAt(0).toUpperCase() + gear.slice(1));
gearTypes.forEach(gear => {
const gearAchiev = basicAchievs[`${gear}UltimateGear`];
const classNameRegex = new RegExp(gear.charAt(0).toUpperCase() + gear.slice(1));
expect(gearAchiev.title).to.match(classNameRegex);
expect(gearAchiev.text).to.match(classNameRegex);
+3 -3
View File
@@ -2,9 +2,9 @@ import appliedTags from '../../../website/common/script/libs/appliedTags';
describe('appliedTags', () => {
it('returns the tasks', () => {
let userTags = [{ id: 'tag1', name: 'tag 1' }, { id: 'tag2', name: 'tag 2' }, { id: 'tag3', name: 'tag 3' }];
let taskTags = ['tag2', 'tag3'];
let result = appliedTags(userTags, taskTags);
const userTags = [{ id: 'tag1', name: 'tag 1' }, { id: 'tag2', name: 'tag 2' }, { id: 'tag3', name: 'tag 3' }];
const taskTags = ['tag2', 'tag3'];
const result = appliedTags(userTags, taskTags);
expect(result).to.eql('tag 2, tag 3');
});
});
+8 -8
View File
@@ -3,49 +3,49 @@ import { generateUser } from '../../helpers/common.helper';
describe('hasClass', () => {
it('returns false for user with level below 10', () => {
let userLvl9 = generateUser({
const userLvl9 = generateUser({
'stats.lvl': 9,
'flags.classSelected': true,
'preferences.disableClasses': false,
});
let result = hasClass(userLvl9);
const result = hasClass(userLvl9);
expect(result).to.eql(false);
});
it('returns false for user with class not selected', () => {
let userClassNotSelected = generateUser({
const userClassNotSelected = generateUser({
'stats.lvl': 10,
'flags.classSelected': false,
'preferences.disableClasses': false,
});
let result = hasClass(userClassNotSelected);
const result = hasClass(userClassNotSelected);
expect(result).to.eql(false);
});
it('returns false for user with classes disabled', () => {
let userClassesDisabled = generateUser({
const userClassesDisabled = generateUser({
'stats.lvl': 10,
'flags.classSelected': true,
'preferences.disableClasses': true,
});
let result = hasClass(userClassesDisabled);
const result = hasClass(userClassesDisabled);
expect(result).to.eql(false);
});
it('returns true for user with class', () => {
let userClassSelected = generateUser({
const userClassSelected = generateUser({
'stats.lvl': 10,
'flags.classSelected': true,
'preferences.disableClasses': false,
});
let result = hasClass(userClassSelected);
const result = hasClass(userClassSelected);
expect(result).to.eql(true);
});
+11 -10
View File
@@ -1,7 +1,7 @@
import {
generateUser,
} from '../../helpers/common.helper';
import getOfficialPinnedItems from '../../../website/common/script/libs/getOfficialPinnedItems.js';
import getOfficialPinnedItems from '../../../website/common/script/libs/getOfficialPinnedItems';
import inAppRewards from '../../../website/common/script/libs/inAppRewards';
describe('inAppRewards', () => {
@@ -16,7 +16,8 @@ describe('inAppRewards', () => {
officialPinnedItems = getOfficialPinnedItems(user);
officialPinnedItemPaths = [];
// officialPinnedItems are returned in { type: ..., path:... } format but we just need the paths for testPinnedItemsOrder
// officialPinnedItems are returned in { type: ..., path:... } format
// but we just need the paths for testPinnedItemsOrder
if (officialPinnedItems.length > 0) {
officialPinnedItemPaths = officialPinnedItems.map(item => item.path);
}
@@ -56,7 +57,7 @@ describe('inAppRewards', () => {
user.pinnedItems = testPinnedItems;
user.pinnedItemsOrder = testPinnedItemsOrder;
let result = inAppRewards(user);
const result = inAppRewards(user);
expect(result[2].path).to.eql('armoire');
expect(result[9].path).to.eql('potion');
@@ -68,7 +69,7 @@ describe('inAppRewards', () => {
user.pinnedItems.push(undefined);
user.pinnedItemsOrder = testPinnedItemsOrder;
let result = inAppRewards(user);
const result = inAppRewards(user);
expect(result[2].path).to.eql('armoire');
expect(result[9].path).to.eql('potion');
@@ -79,18 +80,18 @@ describe('inAppRewards', () => {
return; // if no seasonal items, this test is not applicable
}
let testUnpinnedItem = officialPinnedItems[0];
let testUnpinnedPath = testUnpinnedItem.path;
let testUnpinnedItems = [
{ type: testUnpinnedItem.type, path: testUnpinnedPath},
const testUnpinnedItem = officialPinnedItems[0];
const testUnpinnedPath = testUnpinnedItem.path;
const testUnpinnedItems = [
{ type: testUnpinnedItem.type, path: testUnpinnedPath },
];
user.pinnedItems = testPinnedItems;
user.pinnedItemsOrder = testPinnedItemsOrder;
user.unpinnedItems = testUnpinnedItems;
let result = inAppRewards(user);
let itemPaths = result.map(item => item.path);
const result = inAppRewards(user);
const itemPaths = result.map(item => item.path);
expect(itemPaths).to.not.include(testUnpinnedPath);
});
});
+2 -2
View File
@@ -2,12 +2,12 @@ import noTags from '../../../website/common/script/libs/noTags';
describe('noTags', () => {
it('returns true for no tags', () => {
let result = noTags([]);
const result = noTags([]);
expect(result).to.eql(true);
});
it('returns false for some tags', () => {
let result = noTags(['a', 'b', 'c']);
const result = noTags(['a', 'b', 'c']);
expect(result).to.eql(false);
});
});
+2 -2
View File
@@ -6,7 +6,7 @@ describe('pickDeep', () => {
});
it('returns an object of properties taken from the input object', () => {
let obj = {
const obj = {
a: true,
b: [1, 2, 3],
c: {
@@ -19,7 +19,7 @@ describe('pickDeep', () => {
d: false,
};
let res = pickDeep(obj, ['a', 'b[0]', 'c.nested.two.times']);
const res = pickDeep(obj, ['a', 'b[0]', 'c.nested.two.times']);
expect(res.a).to.be.true;
expect(res.b).to.eql([1]);
expect(res.c).to.eql({
+3 -3
View File
@@ -1,5 +1,5 @@
import { times } from 'lodash';
import randomVal from '../../../website/common/script/libs/randomVal';
import {times} from 'lodash';
describe('randomVal', () => {
let obj;
@@ -18,7 +18,7 @@ describe('randomVal', () => {
});
it('returns a random value from an object', () => {
let result = randomVal(obj);
const result = randomVal(obj);
expect(result).to.be.oneOf([1, 2, 3, 4]);
});
@@ -31,7 +31,7 @@ describe('randomVal', () => {
});
it('returns a random key when the key option is passed in', () => {
let result = randomVal(obj, { key: true });
const result = randomVal(obj, { key: true });
expect(result).to.be.oneOf(['a', 'b', 'c', 'd']);
});
});
+9 -13
View File
@@ -1,10 +1,10 @@
import shared from '../../../website/common';
import { v4 as generateUUID } from 'uuid';
import shared from '../../../website/common';
describe('refPush', () => {
it('it hashes one object into another by its id', () => {
let referenceObject = {};
let objectToHash = {
const referenceObject = {};
const objectToHash = {
a: 1,
id: generateUUID(),
};
@@ -17,16 +17,14 @@ describe('refPush', () => {
});
it('it hashes one object into another by a uuid when object does not have an id', () => {
let referenceObject = {};
let objectToHash = {
const referenceObject = {};
const objectToHash = {
a: 1,
};
shared.refPush(referenceObject, objectToHash);
let hashedObject = _.find(referenceObject, (hashedItem) => {
return objectToHash.a === hashedItem.a;
});
const hashedObject = _.find(referenceObject, hashedItem => objectToHash.a === hashedItem.a);
expect(hashedObject.a).to.equal(objectToHash.a);
expect(hashedObject.id).to.equal(objectToHash.id);
@@ -34,17 +32,15 @@ describe('refPush', () => {
});
it('it hashes one object into another by a id and gives it the highest sort value', () => {
let referenceObject = {};
const referenceObject = {};
referenceObject[generateUUID()] = { b: 2, sort: 1 };
let objectToHash = {
const objectToHash = {
a: 1,
};
shared.refPush(referenceObject, objectToHash);
let hashedObject = _.find(referenceObject, (hashedItem) => {
return objectToHash.a === hashedItem.a;
});
const hashedObject = _.find(referenceObject, hashedItem => objectToHash.a === hashedItem.a);
expect(hashedObject.a).to.equal(objectToHash.a);
expect(hashedObject.id).to.equal(objectToHash.id);
+40 -40
View File
@@ -4,31 +4,31 @@ import {
} from '../../helpers/common.helper';
describe('shops', () => {
let user = generateUser();
const user = generateUser();
describe('market', () => {
let shopCategories = shared.shops.getMarketCategories(user);
const shopCategories = shared.shops.getMarketCategories(user);
it('contains at least the 3 default categories', () => {
expect(shopCategories.length).to.be.greaterThan(2);
});
it('does not contain an empty category', () => {
_.each(shopCategories, (category) => {
_.each(shopCategories, category => {
expect(category.items.length).to.be.greaterThan(0);
});
});
it('does not duplicate identifiers', () => {
let identifiers = Array.from(new Set(shopCategories.map(cat => cat.identifier)));
const identifiers = Array.from(new Set(shopCategories.map(cat => cat.identifier)));
expect(identifiers.length).to.eql(shopCategories.length);
});
it('items contain required fields', () => {
_.each(shopCategories, (category) => {
_.each(category.items, (item) => {
_.each(['key', 'text', 'notes', 'value', 'currency', 'locked', 'purchaseType', 'class'], (key) => {
_.each(shopCategories, category => {
_.each(category.items, item => {
_.each(['key', 'text', 'notes', 'value', 'currency', 'locked', 'purchaseType', 'class'], key => {
expect(_.has(item, key)).to.eql(true);
});
});
@@ -36,7 +36,7 @@ describe('shops', () => {
});
it('shows relevant non class gear in special category', () => {
let contributor = generateUser({
const contributor = generateUser({
contributor: {
level: 7,
critical: true,
@@ -50,18 +50,18 @@ describe('shops', () => {
},
});
let gearCategories = shared.shops.getMarketGearCategories(contributor);
let specialCategory = gearCategories.find(o => o.identifier === 'none');
expect(specialCategory.items.find((item) => item.key === 'weapon_special_1'));
expect(specialCategory.items.find((item) => item.key === 'armor_special_1'));
expect(specialCategory.items.find((item) => item.key === 'head_special_1'));
expect(specialCategory.items.find((item) => item.key === 'shield_special_1'));
expect(specialCategory.items.find((item) => item.key === 'weapon_special_critical'));
expect(specialCategory.items.find((item) => item.key === 'weapon_armoire_basicCrossbow'));// eslint-disable-line camelcase
const gearCategories = shared.shops.getMarketGearCategories(contributor);
const specialCategory = gearCategories.find(o => o.identifier === 'none');
expect(specialCategory.items.find(item => item.key === 'weapon_special_1'));
expect(specialCategory.items.find(item => item.key === 'armor_special_1'));
expect(specialCategory.items.find(item => item.key === 'head_special_1'));
expect(specialCategory.items.find(item => item.key === 'shield_special_1'));
expect(specialCategory.items.find(item => item.key === 'weapon_special_critical'));
expect(specialCategory.items.find(item => item.key === 'weapon_armoire_basicCrossbow'));// eslint-disable-line camelcase
});
it('does not show gear when it is all owned', () => {
let userWithItems = generateUser({
const userWithItems = generateUser({
stats: {
class: 'wizard',
},
@@ -91,12 +91,12 @@ describe('shops', () => {
});
let shopWizardItems = shared.shops.getMarketGearCategories(userWithItems).find(x => x.identifier === 'wizard').items.filter(x => x.klass === 'wizard' && (x.owned === false || x.owned === undefined));
const shopWizardItems = shared.shops.getMarketGearCategories(userWithItems).find(x => x.identifier === 'wizard').items.filter(x => x.klass === 'wizard' && (x.owned === false || x.owned === undefined));
expect(shopWizardItems.length).to.eql(0);
});
it('shows available gear not yet purchased and previously owned', () => {
let userWithItems = generateUser({
const userWithItems = generateUser({
stats: {
class: 'wizard',
},
@@ -123,7 +123,7 @@ describe('shops', () => {
});
let shopWizardItems = shared.shops.getMarketGearCategories(userWithItems).find(x => x.identifier === 'wizard').items.filter(x => x.klass === 'wizard' && (x.owned === false || x.owned === undefined));
const shopWizardItems = shared.shops.getMarketGearCategories(userWithItems).find(x => x.identifier === 'wizard').items.filter(x => x.klass === 'wizard' && (x.owned === false || x.owned === undefined));
expect(shopWizardItems.find(item => item.key === 'weapon_wizard_5').locked).to.eql(false);
expect(shopWizardItems.find(item => item.key === 'weapon_wizard_6').locked).to.eql(true);
expect(shopWizardItems.find(item => item.key === 'armor_wizard_3').locked).to.eql(false);
@@ -134,31 +134,31 @@ describe('shops', () => {
});
describe('questShop', () => {
let shopCategories = shared.shops.getQuestShopCategories(user);
const shopCategories = shared.shops.getQuestShopCategories(user);
it('does not contain an empty category', () => {
_.each(shopCategories, (category) => {
_.each(shopCategories, category => {
expect(category.items.length).to.be.greaterThan(0);
});
});
it('does not duplicate identifiers', () => {
let identifiers = Array.from(new Set(shopCategories.map(cat => cat.identifier)));
const identifiers = Array.from(new Set(shopCategories.map(cat => cat.identifier)));
expect(identifiers.length).to.eql(shopCategories.length);
});
it('items contain required fields', () => {
_.each(shopCategories, (category) => {
_.each(shopCategories, category => {
if (category.identifier === 'bundle') {
_.each(category.items, (item) => {
_.each(['key', 'text', 'notes', 'value', 'currency', 'purchaseType', 'class'], (key) => {
_.each(category.items, item => {
_.each(['key', 'text', 'notes', 'value', 'currency', 'purchaseType', 'class'], key => {
expect(_.has(item, key)).to.eql(true);
});
});
} else {
_.each(category.items, (item) => {
_.each(['key', 'text', 'notes', 'value', 'currency', 'locked', 'purchaseType', 'boss', 'class', 'collect', 'drop', 'unlockCondition', 'lvl'], (key) => {
_.each(category.items, item => {
_.each(['key', 'text', 'notes', 'value', 'currency', 'locked', 'purchaseType', 'boss', 'class', 'collect', 'drop', 'unlockCondition', 'lvl'], key => {
expect(_.has(item, key)).to.eql(true);
});
});
@@ -168,24 +168,24 @@ describe('shops', () => {
});
describe('timeTravelers', () => {
let shopCategories = shared.shops.getTimeTravelersCategories(user);
const shopCategories = shared.shops.getTimeTravelersCategories(user);
it('does not contain an empty category', () => {
_.each(shopCategories, (category) => {
_.each(shopCategories, category => {
expect(category.items.length).to.be.greaterThan(0);
});
});
it('does not duplicate identifiers', () => {
let identifiers = Array.from(new Set(shopCategories.map(cat => cat.identifier)));
const identifiers = Array.from(new Set(shopCategories.map(cat => cat.identifier)));
expect(identifiers.length).to.eql(shopCategories.length);
});
it('items contain required fields', () => {
_.each(shopCategories, (category) => {
_.each(category.items, (item) => {
_.each(['key', 'text', 'value', 'currency', 'locked', 'purchaseType', 'class', 'notes', 'class'], (key) => {
_.each(shopCategories, category => {
_.each(category.items, item => {
_.each(['key', 'text', 'value', 'currency', 'locked', 'purchaseType', 'class', 'notes', 'class'], key => {
expect(_.has(item, key)).to.eql(true);
});
});
@@ -194,24 +194,24 @@ describe('shops', () => {
});
describe('seasonalShop', () => {
let shopCategories = shared.shops.getSeasonalShopCategories(user);
const shopCategories = shared.shops.getSeasonalShopCategories(user);
it('does not contain an empty category', () => {
_.each(shopCategories, (category) => {
_.each(shopCategories, category => {
expect(category.items.length).to.be.greaterThan(0);
});
});
it('does not duplicate identifiers', () => {
let identifiers = Array.from(new Set(shopCategories.map(cat => cat.identifier)));
const identifiers = Array.from(new Set(shopCategories.map(cat => cat.identifier)));
expect(identifiers.length).to.eql(shopCategories.length);
});
it('items contain required fields', () => {
_.each(shopCategories, (category) => {
_.each(category.items, (item) => {
_.each(['key', 'text', 'notes', 'value', 'currency', 'locked', 'purchaseType', 'type'], (key) => {
_.each(shopCategories, category => {
_.each(category.items, item => {
_.each(['key', 'text', 'notes', 'value', 'currency', 'locked', 'purchaseType', 'type'], key => {
expect(_.has(item, key)).to.eql(true);
});
});
+7 -7
View File
@@ -5,7 +5,7 @@ import { generateUser } from '../../helpers/common.helper';
describe('taskDefaults', () => {
it('applies defaults to undefined type or habit', () => {
let task = taskDefaults({}, generateUser());
const task = taskDefaults({}, generateUser());
expect(task.type).to.eql('habit');
expect(task._id).to.exist;
expect(task.text).to.eql(task._id);
@@ -21,7 +21,7 @@ describe('taskDefaults', () => {
});
it('applies defaults to a daily', () => {
let task = taskDefaults({ type: 'daily' }, generateUser());
const task = taskDefaults({ type: 'daily' }, generateUser());
expect(task.type).to.eql('daily');
expect(task._id).to.exist;
expect(task.text).to.eql(task._id);
@@ -45,7 +45,7 @@ describe('taskDefaults', () => {
});
it('applies defaults a reward', () => {
let task = taskDefaults({ type: 'reward' }, generateUser());
const task = taskDefaults({ type: 'reward' }, generateUser());
expect(task.type).to.eql('reward');
expect(task._id).to.exist;
expect(task.text).to.eql(task._id);
@@ -55,7 +55,7 @@ describe('taskDefaults', () => {
});
it('applies defaults a todo', () => {
let task = taskDefaults({ type: 'todo' }, generateUser());
const task = taskDefaults({ type: 'todo' }, generateUser());
expect(task.type).to.eql('todo');
expect(task._id).to.exist;
expect(task.text).to.eql(task._id);
@@ -67,15 +67,15 @@ describe('taskDefaults', () => {
it('starts a task yesterday if user cron is later today', () => {
// Configure to have a day start that's *always* tomorrow.
let user = generateUser({'preferences.dayStart': 25});
let task = taskDefaults({ type: 'daily' }, user);
const user = generateUser({ 'preferences.dayStart': 25 });
const task = taskDefaults({ type: 'daily' }, user);
expect(task.startDate).to.eql(
moment()
.zone(user.preferences.timezoneOffset, 'hour')
.startOf('day')
.subtract(1, 'day')
.toDate()
.toDate(),
);
});
});
+10 -26
View File
@@ -6,52 +6,36 @@ import i18n from '../../../website/common/script/i18n';
describe('updateStore', () => {
context('returns a list of gear items available for purchase', () => {
let user = generateUser();
const user = generateUser();
user.items.gear.owned.armor_armoire_lunarArmor = false; // eslint-disable-line camelcase
user.contributor.level = 2;
user.purchased.plan.mysteryItems = ['armor_mystery_201402'];
user.items.gear.owned.armor_mystery_201402 = false; // eslint-disable-line camelcase
let list = shared.updateStore(user);
const list = shared.updateStore(user);
it('contains the first item not purchased for each gear type', () => {
expect(_.find(list, item => {
return item.text() === i18n.t('armorWarrior1Text');
})).to.exist;
expect(_.find(list, item => item.text() === i18n.t('armorWarrior1Text'))).to.exist;
expect(_.find(list, item => {
return item.text() === i18n.t('armorWarrior2Text');
})).to.not.exist;
expect(_.find(list, item => item.text() === i18n.t('armorWarrior2Text'))).to.not.exist;
});
it('contains mystery items the user can own', () => {
expect(_.find(list, item => {
return item.text() === i18n.t('armorMystery201402Text');
})).to.exist;
expect(_.find(list, item => item.text() === i18n.t('armorMystery201402Text'))).to.exist;
expect(_.find(list, item => {
return item.text() === i18n.t('armorMystery201403Text');
})).to.not.exist;
expect(_.find(list, item => item.text() === i18n.t('armorMystery201403Text'))).to.not.exist;
});
it('contains special items the user can own', () => {
expect(_.find(list, item => {
return item.text() === i18n.t('armorSpecial1Text');
})).to.exist;
expect(_.find(list, item => item.text() === i18n.t('armorSpecial1Text'))).to.exist;
expect(_.find(list, item => {
return item.text() === i18n.t('headSpecial1Text');
})).to.not.exist;
expect(_.find(list, item => item.text() === i18n.t('headSpecial1Text'))).to.not.exist;
});
it('contains armoire items the user can own', () => {
expect(_.find(list, item => {
return item.text() === i18n.t('armorArmoireLunarArmorText');
})).to.exist;
expect(_.find(list, item => item.text() === i18n.t('armorArmoireLunarArmorText'))).to.exist;
expect(_.find(list, item => {
return item.text() === i18n.t('armorArmoireGladiatorArmorText');
})).to.not.exist;
expect(_.find(list, item => item.text() === i18n.t('armorArmoireGladiatorArmorText'))).to.not.exist;
});
});
});
+5 -5
View File
@@ -15,7 +15,7 @@ describe('shared.ops.addTask', () => {
});
it('adds an habit', () => {
let habit = addTask(user, {
const habit = addTask(user, {
body: {
type: 'habit',
text: 'habit',
@@ -39,7 +39,7 @@ describe('shared.ops.addTask', () => {
});
it('adds a habit when type is invalid', () => {
let habit = addTask(user, {
const habit = addTask(user, {
body: {
type: 'invalid',
text: 'habit',
@@ -60,7 +60,7 @@ describe('shared.ops.addTask', () => {
});
it('adds a daily', () => {
let daily = addTask(user, {
const daily = addTask(user, {
body: {
type: 'daily',
text: 'daily',
@@ -80,7 +80,7 @@ describe('shared.ops.addTask', () => {
});
it('adds a todo', () => {
let todo = addTask(user, {
const todo = addTask(user, {
body: {
type: 'todo',
text: 'todo',
@@ -99,7 +99,7 @@ describe('shared.ops.addTask', () => {
});
it('adds a reward', () => {
let reward = addTask(user, {
const reward = addTask(user, {
body: {
type: 'reward',
text: 'reward',
+4 -4
View File
@@ -2,8 +2,8 @@ import * as armoireSet from '../../../website/common/script/content/gear/sets/ar
describe('armoireSet items', () => {
it('checks if canOwn has the same id', () => {
for (const type of Object.keys(armoireSet)) {
for (const itemKey of Object.keys(armoireSet[type])) {
Object.keys(armoireSet).forEach(type => {
Object.keys(armoireSet[type]).forEach(itemKey => {
const ownedKey = `${type}_armoire_${itemKey}`;
expect(armoireSet[type][itemKey].canOwn({
@@ -15,7 +15,7 @@ describe('armoireSet items', () => {
},
},
}), `${ownedKey} canOwn is broken`).to.eq(true);
}
}
});
});
});
});
+3 -3
View File
@@ -16,7 +16,7 @@ describe('shared.ops.blockUser', () => {
expect(user.inbox.blocks).to.eql([]);
});
it('validates uuid', (done) => {
it('validates uuid', done => {
try {
blockUser(user, { params: { uuid: '1' } });
} catch (error) {
@@ -25,7 +25,7 @@ describe('shared.ops.blockUser', () => {
}
});
it('validates user can\'t block himself', (done) => {
it('validates user can\'t block himself', done => {
try {
blockUser(user, { params: { uuid: user._id } });
} catch (error) {
@@ -46,7 +46,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 } });
const [result] = blockUser(user, { params: { uuid: blockedUser._id } });
expect(user.inbox.blocks).to.eql([]);
expect(result).to.eql([]);
});
+12 -12
View File
@@ -1,4 +1,5 @@
/* eslint-disable camelcase */
import { defaultsDeep } from 'lodash';
import {
generateUser,
} from '../../../helpers/common.helper';
@@ -9,11 +10,10 @@ import {
import i18n from '../../../../website/common/script/i18n';
import content from '../../../../website/common/script/content/index';
import errorMessage from '../../../../website/common/script/libs/errorMessage';
import { defaultsDeep } from 'lodash';
describe('shared.ops.buy', () => {
let user;
let analytics = {track () {}};
const analytics = { track () {} };
beforeEach(() => {
user = generateUser({
@@ -40,7 +40,7 @@ describe('shared.ops.buy', () => {
analytics.track.restore();
});
it('returns error when key is not provided', (done) => {
it('returns error when key is not provided', done => {
try {
buy(user);
} catch (err) {
@@ -52,7 +52,7 @@ describe('shared.ops.buy', () => {
it('recovers 15 hp', () => {
user.stats.hp = 30;
buy(user, {params: {key: 'potion'}}, analytics);
buy(user, { params: { key: 'potion' } }, analytics);
expect(user.stats.hp).to.eql(45);
expect(analytics.track).to.be.calledOnce;
@@ -61,7 +61,7 @@ describe('shared.ops.buy', () => {
it('adds equipment to inventory', () => {
user.stats.gp = 31;
buy(user, {params: {key: 'armor_warrior_1'}});
buy(user, { params: { key: 'armor_warrior_1' } });
expect(user.items.gear.owned).to.eql({
weapon_warrior_0: true,
@@ -118,15 +118,15 @@ describe('shared.ops.buy', () => {
type: 'quest',
});
expect(user.items.quests).to.eql({dilatoryDistress1: 1});
expect(user.items.quests).to.eql({ dilatoryDistress1: 1 });
expect(user.stats.gp).to.equal(5);
});
it('buys a special item', () => {
user.stats.gp = 11;
let item = content.special.thankyou;
const item = content.special.thankyou;
let [data, message] = buy(user, {
const [data, message] = buy(user, {
params: {
key: 'thankyou',
},
@@ -146,11 +146,11 @@ describe('shared.ops.buy', () => {
it('allows for bulk purchases', () => {
user.stats.hp = 30;
buy(user, {params: {key: 'potion'}, quantity: 2});
buy(user, { params: { key: 'potion' }, quantity: 2 });
expect(user.stats.hp).to.eql(50);
});
it('errors if user supplies a non-numeric quantity', (done) => {
it('errors if user supplies a non-numeric quantity', done => {
try {
buy(user, {
params: {
@@ -166,7 +166,7 @@ describe('shared.ops.buy', () => {
}
});
it('errors if user supplies a negative quantity', (done) => {
it('errors if user supplies a negative quantity', done => {
try {
buy(user, {
params: {
@@ -182,7 +182,7 @@ describe('shared.ops.buy', () => {
}
});
it('errors if user supplies a decimal quantity', (done) => {
it('errors if user supplies a decimal quantity', done => {
try {
buy(user, {
params: {
+17 -17
View File
@@ -4,7 +4,7 @@ import {
generateUser,
} from '../../../helpers/common.helper';
import * as count from '../../../../website/common/script/count';
import {BuyArmoireOperation} from '../../../../website/common/script/ops/buy/buyArmoire';
import { BuyArmoireOperation } from '../../../../website/common/script/ops/buy/buyArmoire';
import * as randomValFns from '../../../../website/common/script/libs/randomVal';
import content from '../../../../website/common/script/content/index';
import {
@@ -13,11 +13,11 @@ import {
import i18n from '../../../../website/common/script/i18n';
function getFullArmoire () {
let fullArmoire = {};
const fullArmoire = {};
_.each(content.gearTypes, (type) => {
_.each(content.gear.tree[type].armoire, (gearObject) => {
let armoireKey = gearObject.key;
_.each(content.gearTypes, type => {
_.each(content.gear.tree[type].armoire, gearObject => {
const armoireKey = gearObject.key;
fullArmoire[armoireKey] = true;
});
@@ -28,10 +28,10 @@ function getFullArmoire () {
describe('shared.ops.buyArmoire', () => {
let user;
let YIELD_EQUIPMENT = 0.5;
let YIELD_FOOD = 0.7;
let YIELD_EXP = 0.9;
let analytics = {track () {}};
const YIELD_EQUIPMENT = 0.5;
const YIELD_FOOD = 0.7;
const YIELD_EXP = 0.9;
const analytics = { track () {} };
function buyArmoire (_user, _req, _analytics) {
const buyOp = new BuyArmoireOperation(_user, _req, _analytics);
@@ -61,7 +61,7 @@ describe('shared.ops.buyArmoire', () => {
});
context('failure conditions', () => {
it('does not open if user does not have enough gold', (done) => {
it('does not open if user does not have enough gold', done => {
user.stats.gp = 50;
try {
@@ -81,25 +81,25 @@ describe('shared.ops.buyArmoire', () => {
context('non-gear awards', () => {
it('gives Experience', () => {
let previousExp = user.stats.exp;
const previousExp = user.stats.exp;
randomValFns.trueRandom.returns(YIELD_EXP);
buyArmoire(user);
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
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;
const previousExp = user.stats.exp;
randomValFns.trueRandom.returns(YIELD_FOOD);
buyArmoire(user);
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
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);
@@ -113,7 +113,7 @@ describe('shared.ops.buyArmoire', () => {
buyArmoire(user);
expect(user.items.gear.owned).to.eql(getFullArmoire());
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
const armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
expect(armoireCount).to.eql(0);
@@ -132,7 +132,7 @@ describe('shared.ops.buyArmoire', () => {
expect(_.size(user.items.gear.owned)).to.equal(2);
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
const armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
expect(armoireCount).to.eql(_.size(getFullArmoire()) - 1);
expect(user.items.food).to.be.empty;
@@ -154,7 +154,7 @@ describe('shared.ops.buyArmoire', () => {
expect(_.size(user.items.gear.owned)).to.equal(3);
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
const armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
expect(armoireCount).to.eql(_.size(getFullArmoire()) - 2);
expect(user.stats.gp).to.eql(100);
+24 -24
View File
@@ -8,21 +8,21 @@ import {
BadRequest, NotAuthorized,
} from '../../../../website/common/script/libs/errors';
import i18n from '../../../../website/common/script/i18n';
import {BuyGemOperation} from '../../../../website/common/script/ops/buy/buyGem';
import { BuyGemOperation } from '../../../../website/common/script/ops/buy/buyGem';
import planGemLimits from '../../../../website/common/script/libs/planGemLimits';
function buyGem (user, req, analytics) {
let buyOp = new BuyGemOperation(user, req, analytics);
const buyOp = new BuyGemOperation(user, req, analytics);
return buyOp.purchase();
}
describe('shared.ops.buyGem', () => {
let user;
let analytics = {track () {}};
let goldPoints = 40;
let gemsBought = 40;
let userGemAmount = 10;
const analytics = { track () {} };
const goldPoints = 40;
const gemsBought = 40;
const userGemAmount = 10;
beforeEach(() => {
user = generateUser({
@@ -45,9 +45,9 @@ describe('shared.ops.buyGem', () => {
context('Gems', () => {
it('purchases gems', () => {
let [, message] = buyGem(user, {params: {type: 'gems', key: 'gem'}}, analytics);
const [, message] = buyGem(user, { params: { type: 'gems', key: 'gem' } }, analytics);
expect(message).to.equal(i18n.t('plusGem', {count: 1}));
expect(message).to.equal(i18n.t('plusGem', { count: 1 }));
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);
@@ -55,21 +55,21 @@ describe('shared.ops.buyGem', () => {
});
it('purchases gems with a different language than the default', () => {
let [, message] = buyGem(user, {params: {type: 'gems', key: 'gem'}, language: 'de'});
const [, message] = buyGem(user, { params: { type: 'gems', key: 'gem' }, language: 'de' });
expect(message).to.equal(i18n.t('plusGem', {count: 1}, 'de'));
expect(message).to.equal(i18n.t('plusGem', { count: 1 }, 'de'));
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);
});
it('makes bulk purchases of gems', () => {
let [, message] = buyGem(user, {
params: {type: 'gems', key: 'gem'},
const [, message] = buyGem(user, {
params: { type: 'gems', key: 'gem' },
quantity: 2,
});
expect(message).to.equal(i18n.t('plusGem', {count: 2}));
expect(message).to.equal(i18n.t('plusGem', { count: 2 }));
expect(user.balance).to.equal(userGemAmount + 0.50);
expect(user.purchased.plan.gemsBought).to.equal(2);
expect(user.stats.gp).to.equal(goldPoints - planGemLimits.convRate * 2);
@@ -77,9 +77,9 @@ describe('shared.ops.buyGem', () => {
context('Failure conditions', () => {
it('returns an error when key is not provided', (done) => {
it('returns an error when key is not provided', done => {
try {
buyGem(user, {params: {type: 'gems'}});
buyGem(user, { params: { type: 'gems' } });
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('missingKeyParam'));
@@ -87,11 +87,11 @@ describe('shared.ops.buyGem', () => {
}
});
it('prevents unsubscribed user from buying gems', (done) => {
it('prevents unsubscribed user from buying gems', done => {
delete user.purchased.plan.customerId;
try {
buyGem(user, {params: {type: 'gems', key: 'gem'}});
buyGem(user, { params: { type: 'gems', key: 'gem' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('mustSubscribeToPurchaseGems'));
@@ -99,11 +99,11 @@ describe('shared.ops.buyGem', () => {
}
});
it('prevents user with not enough gold from buying gems', (done) => {
it('prevents user with not enough gold from buying gems', done => {
user.stats.gp = 15;
try {
buyGem(user, {params: {type: 'gems', key: 'gem'}});
buyGem(user, { params: { type: 'gems', key: 'gem' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
@@ -111,25 +111,25 @@ describe('shared.ops.buyGem', () => {
}
});
it('prevents user that have reached the conversion cap from buying gems', (done) => {
it('prevents user that have reached the conversion cap from buying gems', done => {
user.stats.gp = goldPoints;
user.purchased.plan.gemsBought = gemsBought;
try {
buyGem(user, {params: {type: 'gems', key: 'gem'}});
buyGem(user, { params: { type: 'gems', key: 'gem' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('reachedGoldToGemCap', {convCap: planGemLimits.convCap}));
expect(err.message).to.equal(i18n.t('reachedGoldToGemCap', { convCap: planGemLimits.convCap }));
done();
}
});
it('prevents user from buying an invalid quantity', (done) => {
it('prevents user from buying an invalid quantity', done => {
user.stats.gp = goldPoints;
user.purchased.plan.gemsBought = gemsBought;
try {
buyGem(user, {params: {type: 'gems', key: 'gem'}, quantity: 'a'});
buyGem(user, { params: { type: 'gems', key: 'gem' }, quantity: 'a' });
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('invalidQuantity'));
+5 -5
View File
@@ -10,7 +10,7 @@ import i18n from '../../../../website/common/script/i18n';
describe('shared.ops.buyHealthPotion', () => {
let user;
let analytics = {track () {}};
const analytics = { track () {} };
function buyHealthPotion (_user, _req, _analytics) {
const buyOp = new BuyHealthPotionOperation(_user, _req, _analytics);
@@ -60,7 +60,7 @@ describe('shared.ops.buyHealthPotion', () => {
expect(user.stats.gp).to.eql(175);
});
it('does not purchase if not enough gp', (done) => {
it('does not purchase if not enough gp', done => {
user.stats.hp = 45;
user.stats.gp = 5;
try {
@@ -75,7 +75,7 @@ describe('shared.ops.buyHealthPotion', () => {
}
});
it('does not purchase if hp is full', (done) => {
it('does not purchase if hp is full', done => {
user.stats.hp = 50;
user.stats.gp = 40;
try {
@@ -90,7 +90,7 @@ describe('shared.ops.buyHealthPotion', () => {
}
});
it('does not allow potion purchases when hp is zero', (done) => {
it('does not allow potion purchases when hp is zero', done => {
user.stats.hp = 0;
user.stats.gp = 40;
try {
@@ -105,7 +105,7 @@ describe('shared.ops.buyHealthPotion', () => {
}
});
it('does not allow potion purchases when hp is negative', (done) => {
it('does not allow potion purchases when hp is negative', done => {
user.stats.hp = -8;
user.stats.gp = 40;
try {
+38 -38
View File
@@ -1,27 +1,27 @@
/* eslint-disable camelcase */
import sinon from 'sinon'; // eslint-disable-line no-shadow
import { defaultsDeep } from 'lodash';
import {
generateUser,
} from '../../../helpers/common.helper';
import {BuyMarketGearOperation} from '../../../../website/common/script/ops/buy/buyMarketGear';
import { BuyMarketGearOperation } from '../../../../website/common/script/ops/buy/buyMarketGear';
import shared from '../../../../website/common/script';
import {
BadRequest, NotAuthorized, NotFound,
} from '../../../../website/common/script/libs/errors';
import i18n from '../../../../website/common/script/i18n';
import errorMessage from '../../../../website/common/script/libs/errorMessage';
import { defaultsDeep } from 'lodash';
function buyGear (user, req, analytics) {
let buyOp = new BuyMarketGearOperation(user, req, analytics);
const buyOp = new BuyMarketGearOperation(user, req, analytics);
return buyOp.purchase();
}
describe('shared.ops.buyMarketGear', () => {
let user;
let analytics = {track () {}};
const analytics = { track () {} };
beforeEach(() => {
user = generateUser({
@@ -56,7 +56,7 @@ describe('shared.ops.buyMarketGear', () => {
it('adds equipment to inventory', () => {
user.stats.gp = 31;
buyGear(user, {params: {key: 'armor_warrior_1'}}, analytics);
buyGear(user, { params: { key: 'armor_warrior_1' } }, analytics);
expect(user.items.gear.owned).to.eql({
weapon_warrior_0: true,
@@ -89,7 +89,7 @@ describe('shared.ops.buyMarketGear', () => {
it('deducts gold from user', () => {
user.stats.gp = 31;
buyGear(user, {params: {key: 'armor_warrior_1'}});
buyGear(user, { params: { key: 'armor_warrior_1' } });
expect(user.stats.gp).to.eql(1);
});
@@ -98,7 +98,7 @@ describe('shared.ops.buyMarketGear', () => {
user.stats.gp = 31;
user.preferences.autoEquip = true;
buyGear(user, {params: {key: 'armor_warrior_1'}});
buyGear(user, { params: { key: 'armor_warrior_1' } });
expect(user.items.gear.equipped).to.have.property('armor', 'armor_warrior_1');
});
@@ -106,7 +106,7 @@ describe('shared.ops.buyMarketGear', () => {
it('updates the pinnedItems to the next item in the set if one exists', () => {
user.stats.gp = 31;
buyGear(user, {params: {key: 'armor_warrior_1'}});
buyGear(user, { params: { key: 'armor_warrior_1' } });
expect(user.pinnedItems).to.deep.include({
type: 'marketGear',
@@ -118,17 +118,17 @@ describe('shared.ops.buyMarketGear', () => {
user.stats.gp = 31;
user.preferences.autoEquip = false;
buyGear(user, {params: {key: 'armor_warrior_1'}});
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) => {
it('does not buyGear equipment twice', done => {
user.stats.gp = 62;
buyGear(user, {params: {key: 'armor_warrior_1'}});
buyGear(user, { params: { key: 'armor_warrior_1' } });
try {
buyGear(user, {params: {key: 'armor_warrior_1'}});
buyGear(user, { params: { key: 'armor_warrior_1' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('equipmentAlreadyOwned'));
@@ -136,12 +136,12 @@ describe('shared.ops.buyMarketGear', () => {
}
});
it('does not buy equipment of different class', (done) => {
it('does not buy equipment of different class', done => {
user.stats.gp = 82;
user.stats.class = 'warrior';
try {
buyGear(user, {params: {key: 'weapon_special_winter2018Rogue'}});
buyGear(user, { params: { key: 'weapon_special_winter2018Rogue' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('cannotBuyItem'));
@@ -149,11 +149,11 @@ describe('shared.ops.buyMarketGear', () => {
}
});
it('does not buy equipment in bulk', (done) => {
it('does not buy equipment in bulk', done => {
user.stats.gp = 82;
try {
buyGear(user, {params: {key: 'armor_warrior_1'}, quantity: 3});
buyGear(user, { params: { key: 'armor_warrior_1' }, quantity: 3 });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('messageNotAbleToBuyInBulk'));
@@ -165,12 +165,12 @@ describe('shared.ops.buyMarketGear', () => {
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: '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'}});
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');
@@ -180,22 +180,22 @@ describe('shared.ops.buyMarketGear', () => {
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: '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'}});
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) => {
it('does not buyGear equipment without enough Gold', done => {
user.stats.gp = 20;
try {
buyGear(user, {params: {key: 'armor_warrior_1'}});
buyGear(user, { params: { key: 'armor_warrior_1' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
@@ -204,7 +204,7 @@ describe('shared.ops.buyMarketGear', () => {
}
});
it('returns error when key is not provided', (done) => {
it('returns error when key is not provided', done => {
try {
buyGear(user);
} catch (err) {
@@ -214,11 +214,11 @@ describe('shared.ops.buyMarketGear', () => {
}
});
it('returns error when item is not found', (done) => {
let params = {key: 'armor_warrior_notExisting'};
it('returns error when item is not found', done => {
const params = { key: 'armor_warrior_notExisting' };
try {
buyGear(user, {params});
buyGear(user, { params });
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(errorMessage('itemNotFound', params));
@@ -226,9 +226,9 @@ describe('shared.ops.buyMarketGear', () => {
}
});
it('does not buyGear equipment without the previous equipment', (done) => {
it('does not buyGear equipment without the previous equipment', done => {
try {
buyGear(user, {params: {key: 'armor_warrior_2'}});
buyGear(user, { params: { key: 'armor_warrior_2' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('previousGearNotOwned'));
@@ -236,11 +236,11 @@ describe('shared.ops.buyMarketGear', () => {
}
});
it('does not buyGear equipment if user does not own prior item in sequence', (done) => {
it('does not buyGear equipment if user does not own prior item in sequence', done => {
user.stats.gp = 200;
try {
buyGear(user, {params: {key: 'armor_warrior_2'}});
buyGear(user, { params: { key: 'armor_warrior_2' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('previousGearNotOwned'));
@@ -253,7 +253,7 @@ describe('shared.ops.buyMarketGear', () => {
user.stats.gp = 200;
user.items.gear.owned.head_special_2 = false;
buyGear(user, {params: {key: 'head_special_2'}});
buyGear(user, { params: { key: 'head_special_2' } });
expect(user.items.gear.owned).to.have.property('head_special_2', true);
});
@@ -262,7 +262,7 @@ describe('shared.ops.buyMarketGear', () => {
user.stats.gp = 200;
user.items.gear.owned.shield_armoire_ramHornShield = false;
buyGear(user, {params: {key: 'shield_armoire_ramHornShield'}});
buyGear(user, { params: { key: 'shield_armoire_ramHornShield' } });
expect(user.items.gear.owned).to.have.property('shield_armoire_ramHornShield', true);
});
+7 -7
View File
@@ -14,7 +14,7 @@ import errorMessage from '../../../../website/common/script/libs/errorMessage';
describe('shared.ops.buyMysterySet', () => {
let user;
let analytics = {track () {}};
const analytics = { track () {} };
beforeEach(() => {
user = generateUser({
@@ -35,9 +35,9 @@ describe('shared.ops.buyMysterySet', () => {
context('Mystery Sets', () => {
context('failure conditions', () => {
it('does not grant mystery sets without Mystic Hourglasses', (done) => {
it('does not grant mystery sets without Mystic Hourglasses', done => {
try {
buyMysterySet(user, {params: {key: '201501'}});
buyMysterySet(user, { params: { key: '201501' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.eql(i18n.t('notEnoughHourglasses'));
@@ -46,7 +46,7 @@ describe('shared.ops.buyMysterySet', () => {
}
});
it('does not grant mystery set that has already been purchased', (done) => {
it('does not grant mystery set that has already been purchased', done => {
user.purchased.plan.consecutive.trinkets = 1;
user.items.gear.owned = {
weapon_warrior_0: true,
@@ -57,7 +57,7 @@ describe('shared.ops.buyMysterySet', () => {
};
try {
buyMysterySet(user, {params: {key: '301404'}});
buyMysterySet(user, { params: { key: '301404' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.eql(i18n.t('mysterySetNotFound'));
@@ -66,7 +66,7 @@ describe('shared.ops.buyMysterySet', () => {
}
});
it('returns error when key is not provided', (done) => {
it('returns error when key is not provided', done => {
try {
buyMysterySet(user);
} catch (err) {
@@ -80,7 +80,7 @@ describe('shared.ops.buyMysterySet', () => {
context('successful purchases', () => {
it('buys Steampunk Accessories Set', () => {
user.purchased.plan.consecutive.trinkets = 1;
buyMysterySet(user, {params: {key: '301404'}}, analytics);
buyMysterySet(user, { params: { key: '301404' } }, analytics);
expect(user.purchased.plan.consecutive.trinkets).to.eql(0);
expect(user.items.gear.owned).to.have.property('weapon_warrior_0', true);
+16 -16
View File
@@ -6,12 +6,12 @@ import i18n from '../../../../website/common/script/i18n';
import {
generateUser,
} from '../../../helpers/common.helper';
import {BuyQuestWithGemOperation} from '../../../../website/common/script/ops/buy/buyQuestGem';
import { BuyQuestWithGemOperation } from '../../../../website/common/script/ops/buy/buyQuestGem';
describe('shared.ops.buyQuestGems', () => {
let user;
let goldPoints = 40;
let analytics = {track () {}};
const goldPoints = 40;
const analytics = { track () {} };
function buyQuest (_user, _req, _analytics) {
const buyOp = new BuyQuestWithGemOperation(_user, _req, _analytics);
@@ -20,7 +20,7 @@ describe('shared.ops.buyQuestGems', () => {
}
before(() => {
user = generateUser({'stats.class': 'rogue'});
user = generateUser({ 'stats.class': 'rogue' });
});
beforeEach(() => {
@@ -34,29 +34,29 @@ describe('shared.ops.buyQuestGems', () => {
});
context('successful purchase', () => {
let userGemAmount = 10;
const userGemAmount = 10;
before(() => {
user.balance = userGemAmount;
user.stats.gp = goldPoints;
user.purchased.plan.gemsBought = 0;
user.purchased.plan.customerId = 'customer-id';
user.pinnedItems.push({type: 'quests', key: 'gryphon'});
user.pinnedItems.push({ type: 'quests', key: 'gryphon' });
});
it('purchases quests', () => {
let key = 'gryphon';
const key = 'gryphon';
buyQuest(user, {params: {key}});
buyQuest(user, { params: { key } });
expect(user.items.quests[key]).to.equal(1);
expect(pinnedGearUtils.removeItemByPath.notCalled).to.equal(true);
});
it('if a user\'s count of a quest scroll is negative, it will be reset to 0 before incrementing when they buy a new one.', () => {
let key = 'dustbunnies';
const key = 'dustbunnies';
user.items.quests[key] = -1;
buyQuest(user, {params: {key}});
buyQuest(user, { params: { key } });
expect(user.items.quests[key]).to.equal(1);
expect(pinnedGearUtils.removeItemByPath.notCalled).to.equal(true);
@@ -64,7 +64,7 @@ describe('shared.ops.buyQuestGems', () => {
});
context('bulk purchase', () => {
let userGemAmount = 10;
const userGemAmount = 10;
beforeEach(() => {
user.balance = userGemAmount;
@@ -73,13 +73,13 @@ describe('shared.ops.buyQuestGems', () => {
user.purchased.plan.customerId = 'customer-id';
});
it('errors when user does not have enough gems', (done) => {
it('errors when user does not have enough gems', done => {
user.balance = 1;
let key = 'gryphon';
const key = 'gryphon';
try {
buyQuest(user, {
params: {key},
params: { key },
quantity: 2,
});
} catch (err) {
@@ -90,10 +90,10 @@ describe('shared.ops.buyQuestGems', () => {
});
it('makes bulk purchases of quests', () => {
let key = 'gryphon';
const key = 'gryphon';
buyQuest(user, {
params: {key},
params: { key },
quantity: 3,
});
+14 -14
View File
@@ -1,7 +1,7 @@
import {
generateUser,
} from '../../../helpers/common.helper';
import {BuyQuestWithGoldOperation} from '../../../../website/common/script/ops/buy/buyQuestGold';
import { BuyQuestWithGoldOperation } from '../../../../website/common/script/ops/buy/buyQuestGold';
import {
BadRequest,
NotAuthorized,
@@ -12,7 +12,7 @@ import errorMessage from '../../../../website/common/script/libs/errorMessage';
describe('shared.ops.buyQuest', () => {
let user;
let analytics = {track () {}};
const analytics = { track () {} };
function buyQuest (_user, _req, _analytics) {
const buyOp = new BuyQuestWithGoldOperation(_user, _req, _analytics);
@@ -45,10 +45,10 @@ describe('shared.ops.buyQuest', () => {
it('if a user\'s count of a quest scroll is negative, it will be reset to 0 before incrementing when they buy a new one.', () => {
user.stats.gp = 205;
let key = 'dilatoryDistress1';
const key = 'dilatoryDistress1';
user.items.quests[key] = -1;
buyQuest(user, {
params: {key},
params: { key },
}, analytics);
expect(user.items.quests[key]).to.equal(1);
expect(user.stats.gp).to.equal(5);
@@ -74,7 +74,7 @@ describe('shared.ops.buyQuest', () => {
});
});
it('does not buy a Quest scroll when an invalid quantity is passed', (done) => {
it('does not buy a Quest scroll when an invalid quantity is passed', done => {
user.stats.gp = 1000;
try {
buyQuest(user, {
@@ -92,7 +92,7 @@ describe('shared.ops.buyQuest', () => {
}
});
it('does not buy Quests without enough Gold', (done) => {
it('does not buy Quests without enough Gold', done => {
user.stats.gp = 1;
try {
buyQuest(user, {
@@ -109,7 +109,7 @@ describe('shared.ops.buyQuest', () => {
}
});
it('does not buy nonexistent Quests', (done) => {
it('does not buy nonexistent Quests', done => {
user.stats.gp = 9999;
try {
buyQuest(user, {
@@ -119,14 +119,14 @@ describe('shared.ops.buyQuest', () => {
});
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(errorMessage('questNotFound', {key: 'snarfblatter'}));
expect(err.message).to.equal(errorMessage('questNotFound', { key: 'snarfblatter' }));
expect(user.items.quests).to.eql({});
expect(user.stats.gp).to.equal(9999);
done();
}
});
it('does not buy the Mystery of the Masterclassers', (done) => {
it('does not buy the Mystery of the Masterclassers', done => {
try {
buyQuest(user, {
params: {
@@ -142,7 +142,7 @@ describe('shared.ops.buyQuest', () => {
});
it('does not buy Gem-premium Quests', (done) => {
it('does not buy Gem-premium Quests', done => {
user.stats.gp = 9999;
try {
buyQuest(user, {
@@ -152,14 +152,14 @@ describe('shared.ops.buyQuest', () => {
});
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('questNotGoldPurchasable', {key: 'kraken'}));
expect(err.message).to.equal(i18n.t('questNotGoldPurchasable', { key: 'kraken' }));
expect(user.items.quests).to.eql({});
expect(user.stats.gp).to.equal(9999);
done();
}
});
it('returns error when key is not provided', (done) => {
it('returns error when key is not provided', done => {
try {
buyQuest(user);
} catch (err) {
@@ -169,7 +169,7 @@ describe('shared.ops.buyQuest', () => {
}
});
it('does not buy a quest without completing previous quests', (done) => {
it('does not buy a quest without completing previous quests', done => {
try {
buyQuest(user, {
params: {
@@ -178,7 +178,7 @@ describe('shared.ops.buyQuest', () => {
});
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('mustComplete', {quest: 'dilatoryDistress2'}));
expect(err.message).to.equal(i18n.t('mustComplete', { quest: 'dilatoryDistress2' }));
expect(user.items.quests).to.eql({});
done();
}
+8 -8
View File
@@ -1,4 +1,4 @@
import {BuySpellOperation} from '../../../../website/common/script/ops/buy/buySpell';
import { BuySpellOperation } from '../../../../website/common/script/ops/buy/buySpell';
import {
BadRequest,
NotFound,
@@ -13,7 +13,7 @@ import errorMessage from '../../../../website/common/script/libs/errorMessage';
describe('shared.ops.buySpecialSpell', () => {
let user;
let analytics = {track () {}};
const analytics = { track () {} };
function buySpecialSpell (_user, _req, _analytics) {
const buyOp = new BuySpellOperation(_user, _req, _analytics);
@@ -29,7 +29,7 @@ describe('shared.ops.buySpecialSpell', () => {
analytics.track.restore();
});
it('throws an error if params.key is missing', (done) => {
it('throws an error if params.key is missing', done => {
try {
buySpecialSpell(user);
} catch (err) {
@@ -39,7 +39,7 @@ describe('shared.ops.buySpecialSpell', () => {
}
});
it('throws an error if the spell doesn\'t exists', (done) => {
it('throws an error if the spell doesn\'t exists', done => {
try {
buySpecialSpell(user, {
params: {
@@ -48,12 +48,12 @@ describe('shared.ops.buySpecialSpell', () => {
});
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(errorMessage('spellNotFound', {spellId: 'notExisting'}));
expect(err.message).to.equal(errorMessage('spellNotFound', { spellId: 'notExisting' }));
done();
}
});
it('throws an error if the user doesn\'t have enough gold', (done) => {
it('throws an error if the user doesn\'t have enough gold', done => {
user.stats.gp = 1;
try {
buySpecialSpell(user, {
@@ -70,9 +70,9 @@ describe('shared.ops.buySpecialSpell', () => {
it('buys an item', () => {
user.stats.gp = 11;
let item = content.special.thankyou;
const item = content.special.thankyou;
let [data, message] = buySpecialSpell(user, {
const [data, message] = buySpecialSpell(user, {
params: {
key: 'thankyou',
},
+25 -25
View File
@@ -9,11 +9,11 @@ import {
generateUser,
} from '../../../helpers/common.helper';
import errorMessage from '../../../../website/common/script/libs/errorMessage';
import {BuyHourglassMountOperation} from '../../../../website/common/script/ops/buy/buyMount';
import { BuyHourglassMountOperation } from '../../../../website/common/script/ops/buy/buyMount';
describe('common.ops.hourglassPurchase', () => {
let user;
let analytics = {track () {}};
const analytics = { track () {} };
function buyMount (_user, _req, _analytics) {
const buyOp = new BuyHourglassMountOperation(_user, _req, _analytics);
@@ -31,9 +31,9 @@ describe('common.ops.hourglassPurchase', () => {
});
context('failure conditions', () => {
it('return error when key is not provided', (done) => {
it('return error when key is not provided', done => {
try {
hourglassPurchase(user, {params: {}});
hourglassPurchase(user, { params: {} });
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.eql(errorMessage('missingKeyParam'));
@@ -41,9 +41,9 @@ describe('common.ops.hourglassPurchase', () => {
}
});
it('returns error when type is not provided', (done) => {
it('returns error when type is not provided', done => {
try {
hourglassPurchase(user, {params: {key: 'Base'}});
hourglassPurchase(user, { params: { key: 'Base' } });
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.eql(errorMessage('missingTypeParam'));
@@ -51,19 +51,19 @@ describe('common.ops.hourglassPurchase', () => {
}
});
it('returns error when inccorect type is provided', (done) => {
it('returns error when inccorect type is provided', done => {
try {
hourglassPurchase(user, {params: {type: 'notAType', key: 'MantisShrimp-Base'}});
hourglassPurchase(user, { params: { type: 'notAType', key: 'MantisShrimp-Base' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.eql(i18n.t('typeNotAllowedHourglass', {allowedTypes: _.keys(content.timeTravelStable).toString()}));
expect(err.message).to.eql(i18n.t('typeNotAllowedHourglass', { allowedTypes: _.keys(content.timeTravelStable).toString() }));
done();
}
});
it('does not grant to pets without Mystic Hourglasses', (done) => {
it('does not grant to pets without Mystic Hourglasses', done => {
try {
hourglassPurchase(user, {params: {type: 'pets', key: 'MantisShrimp-Base'}});
hourglassPurchase(user, { params: { type: 'pets', key: 'MantisShrimp-Base' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.eql(i18n.t('notEnoughHourglasses'));
@@ -71,9 +71,9 @@ describe('common.ops.hourglassPurchase', () => {
}
});
it('does not grant to mounts without Mystic Hourglasses', (done) => {
it('does not grant to mounts without Mystic Hourglasses', done => {
try {
buyMount(user, {params: {key: 'MantisShrimp-Base'}});
buyMount(user, { params: { key: 'MantisShrimp-Base' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.eql(i18n.t('notEnoughHourglasses'));
@@ -81,11 +81,11 @@ describe('common.ops.hourglassPurchase', () => {
}
});
it('does not grant pet that is not part of the Time Travel Stable', (done) => {
it('does not grant pet that is not part of the Time Travel Stable', done => {
user.purchased.plan.consecutive.trinkets = 1;
try {
hourglassPurchase(user, {params: {type: 'pets', key: 'Wolf-Veteran'}});
hourglassPurchase(user, { params: { type: 'pets', key: 'Wolf-Veteran' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.eql(i18n.t('notAllowedHourglass'));
@@ -93,11 +93,11 @@ describe('common.ops.hourglassPurchase', () => {
}
});
it('does not grant mount that is not part of the Time Travel Stable', (done) => {
it('does not grant mount that is not part of the Time Travel Stable', done => {
user.purchased.plan.consecutive.trinkets = 1;
try {
buyMount(user, {params: {key: 'Orca-Base'}});
buyMount(user, { params: { key: 'Orca-Base' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.eql(i18n.t('notAllowedHourglass'));
@@ -105,14 +105,14 @@ describe('common.ops.hourglassPurchase', () => {
}
});
it('does not grant pet that has already been purchased', (done) => {
it('does not grant pet that has already been purchased', done => {
user.purchased.plan.consecutive.trinkets = 1;
user.items.pets = {
'MantisShrimp-Base': true,
};
try {
hourglassPurchase(user, {params: {type: 'pets', key: 'MantisShrimp-Base'}});
hourglassPurchase(user, { params: { type: 'pets', key: 'MantisShrimp-Base' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.eql(i18n.t('petsAlreadyOwned'));
@@ -120,14 +120,14 @@ describe('common.ops.hourglassPurchase', () => {
}
});
it('does not grant mount that has already been purchased', (done) => {
it('does not grant mount that has already been purchased', done => {
user.purchased.plan.consecutive.trinkets = 1;
user.items.mounts = {
'MantisShrimp-Base': true,
};
try {
buyMount(user, {params: {key: 'MantisShrimp-Base'}});
buyMount(user, { params: { key: 'MantisShrimp-Base' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.eql(i18n.t('mountsAlreadyOwned'));
@@ -140,21 +140,21 @@ describe('common.ops.hourglassPurchase', () => {
it('buys a pet', () => {
user.purchased.plan.consecutive.trinkets = 2;
let [, message] = hourglassPurchase(user, {params: {type: 'pets', key: 'MantisShrimp-Base'}}, analytics);
const [, message] = hourglassPurchase(user, { params: { type: 'pets', key: 'MantisShrimp-Base' } }, analytics);
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});
expect(user.items.pets).to.eql({ 'MantisShrimp-Base': 5 });
expect(analytics.track).to.be.calledOnce;
});
it('buys a mount', () => {
user.purchased.plan.consecutive.trinkets = 2;
let [, message] = buyMount(user, {params: {key: 'MantisShrimp-Base'}});
const [, message] = buyMount(user, { params: { 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});
expect(user.items.mounts).to.eql({ 'MantisShrimp-Base': true });
});
});
});
+67 -67
View File
@@ -1,3 +1,5 @@
import forEach from 'lodash/forEach';
import moment from 'moment';
import purchase from '../../../../website/common/script/ops/buy/purchase';
import * as pinnedGearUtils from '../../../../website/common/script/ops/pinnedGearUtils';
import {
@@ -9,17 +11,15 @@ import i18n from '../../../../website/common/script/i18n';
import {
generateUser,
} from '../../../helpers/common.helper';
import forEach from 'lodash/forEach';
import moment from 'moment';
describe('shared.ops.purchase', () => {
const SEASONAL_FOOD = 'Meat';
let user;
let goldPoints = 40;
let analytics = {track () {}};
const goldPoints = 40;
const analytics = { track () {} };
before(() => {
user = generateUser({'stats.class': 'rogue'});
user = generateUser({ 'stats.class': 'rogue' });
});
beforeEach(() => {
@@ -33,9 +33,9 @@ describe('shared.ops.purchase', () => {
});
context('failure conditions', () => {
it('returns an error when type is not provided', (done) => {
it('returns an error when type is not provided', done => {
try {
purchase(user, {params: {}});
purchase(user, { params: {} });
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('typeRequired'));
@@ -44,9 +44,9 @@ describe('shared.ops.purchase', () => {
});
it('returns error when unknown type is provided', (done) => {
it('returns error when unknown type is provided', done => {
try {
purchase(user, {params: {type: 'randomType', key: 'gem'}});
purchase(user, { params: { type: 'randomType', key: 'gem' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('notAccteptedType'));
@@ -54,11 +54,11 @@ describe('shared.ops.purchase', () => {
}
});
it('returns error when user attempts to purchase a piece of gear they own', (done) => {
it('returns error when user attempts to purchase a piece of gear they own', done => {
user.items.gear.owned['shield_rogue_1'] = true; // eslint-disable-line dot-notation
try {
purchase(user, {params: {type: 'gear', key: 'shield_rogue_1'}});
purchase(user, { params: { type: 'gear', key: 'shield_rogue_1' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('alreadyHave'));
@@ -66,19 +66,19 @@ describe('shared.ops.purchase', () => {
}
});
it('returns error when unknown item is requested', (done) => {
it('returns error when unknown item is requested', done => {
try {
purchase(user, {params: {type: 'gear', key: 'randomKey'}});
purchase(user, { params: { type: 'gear', key: 'randomKey' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('contentKeyNotFound', {type: 'gear'}));
expect(err.message).to.equal(i18n.t('contentKeyNotFound', { type: 'gear' }));
done();
}
});
it('returns error when user does not have permission to buy an item', (done) => {
it('returns error when user does not have permission to buy an item', done => {
try {
purchase(user, {params: {type: 'gear', key: 'eyewear_mystery_301405'}});
purchase(user, { params: { type: 'gear', key: 'eyewear_mystery_301405' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('messageNotAvailable'));
@@ -86,9 +86,9 @@ describe('shared.ops.purchase', () => {
}
});
it('returns error when user does not have enough gems to buy an item', (done) => {
it('returns error when user does not have enough gems to buy an item', done => {
try {
purchase(user, {params: {type: 'gear', key: 'headAccessory_special_wolfEars'}});
purchase(user, { params: { type: 'gear', key: 'headAccessory_special_wolfEars' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('notEnoughGems'));
@@ -97,11 +97,11 @@ describe('shared.ops.purchase', () => {
});
it('returns error when item is not found', (done) => {
let params = {key: 'notExisting', type: 'food'};
it('returns error when item is not found', done => {
const params = { key: 'notExisting', type: 'food' };
try {
purchase(user, {params});
purchase(user, { params });
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('contentKeyNotFound', params));
@@ -109,12 +109,12 @@ describe('shared.ops.purchase', () => {
}
});
it('returns error when user supplies a non-numeric quantity', (done) => {
let type = 'eggs';
let key = 'Wolf';
it('returns error when user supplies a non-numeric quantity', done => {
const type = 'eggs';
const key = 'Wolf';
try {
purchase(user, {params: {type, key}, quantity: 'jamboree'}, analytics);
purchase(user, { params: { type, key }, quantity: 'jamboree' }, analytics);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('invalidQuantity'));
@@ -122,13 +122,13 @@ describe('shared.ops.purchase', () => {
}
});
it('returns error when user supplies a negative quantity', (done) => {
let type = 'eggs';
let key = 'Wolf';
it('returns error when user supplies a negative quantity', done => {
const type = 'eggs';
const key = 'Wolf';
user.balance = 10;
try {
purchase(user, {params: {type, key}, quantity: -2}, analytics);
purchase(user, { params: { type, key }, quantity: -2 }, analytics);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('invalidQuantity'));
@@ -136,13 +136,13 @@ describe('shared.ops.purchase', () => {
}
});
it('returns error when user supplies a decimal quantity', (done) => {
let type = 'eggs';
let key = 'Wolf';
it('returns error when user supplies a decimal quantity', done => {
const type = 'eggs';
const key = 'Wolf';
user.balance = 10;
try {
purchase(user, {params: {type, key}, quantity: 2.9}, analytics);
purchase(user, { params: { type, key }, quantity: 2.9 }, analytics);
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('invalidQuantity'));
@@ -152,25 +152,25 @@ describe('shared.ops.purchase', () => {
});
context('successful purchase', () => {
let userGemAmount = 10;
const userGemAmount = 10;
before(() => {
user.balance = userGemAmount;
user.stats.gp = goldPoints;
user.purchased.plan.gemsBought = 0;
user.purchased.plan.customerId = 'customer-id';
user.pinnedItems.push({type: 'eggs', key: 'Wolf'});
user.pinnedItems.push({type: 'hatchingPotions', key: 'Base'});
user.pinnedItems.push({type: 'food', key: SEASONAL_FOOD});
user.pinnedItems.push({type: 'gear', key: 'headAccessory_special_tigerEars'});
user.pinnedItems.push({type: 'bundles', key: 'featheredFriends'});
user.pinnedItems.push({ type: 'eggs', key: 'Wolf' });
user.pinnedItems.push({ type: 'hatchingPotions', key: 'Base' });
user.pinnedItems.push({ type: 'food', key: SEASONAL_FOOD });
user.pinnedItems.push({ type: 'gear', key: 'headAccessory_special_tigerEars' });
user.pinnedItems.push({ type: 'bundles', key: 'featheredFriends' });
});
it('purchases eggs', () => {
let type = 'eggs';
let key = 'Wolf';
const type = 'eggs';
const key = 'Wolf';
purchase(user, {params: {type, key}}, analytics);
purchase(user, { params: { type, key } }, analytics);
expect(user.items[type][key]).to.equal(1);
expect(pinnedGearUtils.removeItemByPath.notCalled).to.equal(true);
@@ -178,50 +178,50 @@ describe('shared.ops.purchase', () => {
});
it('purchases hatchingPotions', () => {
let type = 'hatchingPotions';
let key = 'Base';
const type = 'hatchingPotions';
const key = 'Base';
purchase(user, {params: {type, key}});
purchase(user, { params: { type, key } });
expect(user.items[type][key]).to.equal(1);
expect(pinnedGearUtils.removeItemByPath.notCalled).to.equal(true);
});
it('purchases food', () => {
let type = 'food';
let key = SEASONAL_FOOD;
const type = 'food';
const key = SEASONAL_FOOD;
purchase(user, {params: {type, key}});
purchase(user, { params: { type, key } });
expect(user.items[type][key]).to.equal(1);
expect(pinnedGearUtils.removeItemByPath.notCalled).to.equal(true);
});
it('purchases gear', () => {
let type = 'gear';
let key = 'headAccessory_special_tigerEars';
const type = 'gear';
const key = 'headAccessory_special_tigerEars';
purchase(user, {params: {type, key}});
purchase(user, { params: { type, key } });
expect(user.items.gear.owned[key]).to.be.true;
expect(pinnedGearUtils.removeItemByPath.calledOnce).to.equal(true);
});
it('purchases quest bundles', () => {
let startingBalance = user.balance;
let clock = sandbox.useFakeTimers(moment('2019-05-20').valueOf());
let type = 'bundles';
let key = 'featheredFriends';
let price = 1.75;
let questList = [
const startingBalance = user.balance;
const clock = sandbox.useFakeTimers(moment('2019-05-20').valueOf());
const type = 'bundles';
const key = 'featheredFriends';
const price = 1.75;
const questList = [
'falcon',
'harpy',
'owl',
];
purchase(user, {params: {type, key}});
purchase(user, { params: { type, key } });
forEach(questList, (bundledKey) => {
forEach(questList, bundledKey => {
expect(user.items.quests[bundledKey]).to.equal(1);
});
@@ -233,7 +233,7 @@ describe('shared.ops.purchase', () => {
});
context('bulk purchase', () => {
let userGemAmount = 10;
const userGemAmount = 10;
beforeEach(() => {
user.balance = userGemAmount;
@@ -242,14 +242,14 @@ describe('shared.ops.purchase', () => {
user.purchased.plan.customerId = 'customer-id';
});
it('errors when user does not have enough gems', (done) => {
it('errors when user does not have enough gems', done => {
user.balance = 1;
let type = 'eggs';
let key = 'TigerCub';
const type = 'eggs';
const key = 'TigerCub';
try {
purchase(user, {
params: {type, key},
params: { type, key },
quantity: 2,
});
} catch (err) {
@@ -260,11 +260,11 @@ describe('shared.ops.purchase', () => {
});
it('makes bulk purchases of eggs', () => {
let type = 'eggs';
let key = 'TigerCub';
const type = 'eggs';
const key = 'TigerCub';
purchase(user, {
params: {type, key},
params: { type, key },
quantity: 2,
});
+10 -10
View File
@@ -19,10 +19,10 @@ describe('shared.ops.changeClass', () => {
user.stats.flagSelected = false;
});
it('user is not level 10', (done) => {
it('user is not level 10', done => {
user.stats.lvl = 9;
try {
changeClass(user, {query: {class: 'rogue'}});
changeClass(user, { query: { class: 'rogue' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('lvl10ChangeClass'));
@@ -30,12 +30,12 @@ describe('shared.ops.changeClass', () => {
}
});
it('req.query.class is an invalid class', (done) => {
it('req.query.class is an invalid class', done => {
user.flags.classSelected = false;
user.preferences.disableClasses = false;
try {
changeClass(user, {query: {class: 'cellist'}});
changeClass(user, { query: { class: 'cellist' } });
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('invalidClass'));
@@ -44,13 +44,13 @@ describe('shared.ops.changeClass', () => {
});
context('req.query.class is a valid class', () => {
it('errors if user.stats.flagSelected is true and user.balance < 0.75', (done) => {
it('errors if user.stats.flagSelected is true and user.balance < 0.75', done => {
user.flags.classSelected = true;
user.preferences.disableClasses = false;
user.balance = 0;
try {
changeClass(user, {query: {class: 'rogue'}});
changeClass(user, { query: { class: 'rogue' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('notEnoughGems'));
@@ -63,7 +63,7 @@ describe('shared.ops.changeClass', () => {
user.items.gear.owned.weapon_healer_3 = true;
user.items.gear.equipped.weapon = 'weapon_healer_3';
let [data] = changeClass(user, {query: {class: 'rogue'}});
const [data] = changeClass(user, { query: { class: 'rogue' } });
expect(data).to.eql({
preferences: user.preferences,
stats: user.stats,
@@ -92,7 +92,7 @@ describe('shared.ops.changeClass', () => {
user.stats.int = 4;
user.flags.classSelected = true;
let [data] = changeClass(user);
const [data] = changeClass(user);
expect(data).to.eql({
preferences: user.preferences,
stats: user.stats,
@@ -112,7 +112,7 @@ describe('shared.ops.changeClass', () => {
});
context('has user.preferences.disableClasses !== true', () => {
it('and less than 3 gems', (done) => {
it('and less than 3 gems', done => {
user.balance = 0.5;
try {
changeClass(user);
@@ -132,7 +132,7 @@ describe('shared.ops.changeClass', () => {
user.stats.int = 4;
user.flags.classSelected = true;
let [data] = changeClass(user);
const [data] = changeClass(user);
expect(data).to.eql({
preferences: user.preferences,
stats: user.stats,
+1 -1
View File
@@ -18,7 +18,7 @@ describe('shared.ops.disableClasses', () => {
user.preferences.autoAllocate = false;
user.stats.points = 2;
let [data] = disableClasses(user);
const [data] = disableClasses(user);
expect(data).to.eql({
preferences: user.preferences,
stats: user.stats,
+19 -19
View File
@@ -28,58 +28,58 @@ describe('shared.ops.equip', () => {
},
},
},
stats: {gp: 200},
stats: { gp: 200 },
});
});
context('Gear', () => {
it('should not send a message if a weapon is equipped while only having zero or one weapons equipped', () => {
equip(user, {params: {key: 'weapon_warrior_1'}});
equip(user, { params: { key: 'weapon_warrior_1' } });
// one-handed to one-handed
let [, message] = equip(user, {params: {key: 'weapon_warrior_2'}});
let [, message] = equip(user, { params: { key: 'weapon_warrior_2' } });
expect(message).to.not.exist;
// one-handed to two-handed
[, message] = equip(user, {params: {key: 'weapon_wizard_1'}});
[, message] = equip(user, { params: { key: 'weapon_wizard_1' } });
expect(message).to.not.exist;
// two-handed to two-handed
[, message] = equip(user, {params: {key: 'weapon_wizard_2'}});
[, message] = equip(user, { params: { key: 'weapon_wizard_2' } });
expect(message).to.not.exist;
// two-handed to one-handed
[, message] = equip(user, {params: {key: 'weapon_warrior_2'}});
[, message] = equip(user, { params: { key: 'weapon_warrior_2' } });
expect(message).to.not.exist;
});
it('should send messages if equipping a two-hander causes the off-hander to be unequipped', () => {
equip(user, {params: {key: 'weapon_warrior_1'}});
equip(user, {params: {key: 'shield_warrior_1'}});
equip(user, { params: { key: 'weapon_warrior_1' } });
equip(user, { params: { key: 'shield_warrior_1' } });
// equipping two-hander
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;
const [data, message] = equip(user, { params: { key: 'weapon_wizard_1' } });
const weapon = content.gear.flat.weapon_wizard_1;
const item = content.gear.flat.shield_warrior_1;
let res = {data, message};
const res = { data, message };
expect(res).to.eql({
message: i18n.t('messageTwoHandedEquip', {twoHandedText: weapon.text(), offHandedText: item.text()}),
message: i18n.t('messageTwoHandedEquip', { twoHandedText: weapon.text(), offHandedText: item.text() }),
data: user.items,
});
});
it('should send messages if equipping an off-hand item causes a two-handed weapon to be unequipped', () => {
// equipping two-hander
equip(user, {params: {key: 'weapon_wizard_1'}});
let weapon = content.gear.flat.weapon_wizard_1;
let shield = content.gear.flat.shield_warrior_1;
equip(user, { params: { key: 'weapon_wizard_1' } });
const weapon = content.gear.flat.weapon_wizard_1;
const shield = content.gear.flat.shield_warrior_1;
let [data, message] = equip(user, {params: {key: 'shield_warrior_1'}});
const [data, message] = equip(user, { params: { key: 'shield_warrior_1' } });
let res = {data, message};
const res = { data, message };
expect(res).to.eql({
message: i18n.t('messageTwoHandedUnequip', {twoHandedText: weapon.text(), offHandedText: shield.text()}),
message: i18n.t('messageTwoHandedUnequip', { twoHandedText: weapon.text(), offHandedText: shield.text() }),
data: user.items,
});
});
+28 -28
View File
@@ -19,7 +19,7 @@ describe('shared.ops.feed', () => {
});
context('failure conditions', () => {
it('does not allow feeding without specifying pet and food', (done) => {
it('does not allow feeding without specifying pet and food', done => {
try {
feed(user);
} catch (err) {
@@ -29,9 +29,9 @@ describe('shared.ops.feed', () => {
}
});
it('does not allow feeding if pet name format is invalid', (done) => {
it('does not allow feeding if pet name format is invalid', done => {
try {
feed(user, {params: {pet: 'invalid', food: 'food'}});
feed(user, { params: { pet: 'invalid', food: 'food' } });
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(errorMessage('invalidPetName'));
@@ -39,9 +39,9 @@ describe('shared.ops.feed', () => {
}
});
it('does not allow feeding if food does not exist', (done) => {
it('does not allow feeding if food does not exist', done => {
try {
feed(user, {params: {pet: 'Wolf-Red', food: 'invalid food name'}});
feed(user, { params: { pet: 'Wolf-Red', food: 'invalid food name' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(errorMessage('invalidFoodName'));
@@ -49,9 +49,9 @@ describe('shared.ops.feed', () => {
}
});
it('does not allow feeding if pet is not owned', (done) => {
it('does not allow feeding if pet is not owned', done => {
try {
feed(user, {params: {pet: 'Wolf-Red', food: 'Meat'}});
feed(user, { params: { pet: 'Wolf-Red', food: 'Meat' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('messagePetNotFound'));
@@ -59,10 +59,10 @@ describe('shared.ops.feed', () => {
}
});
it('does not allow feeding if food is not owned', (done) => {
it('does not allow feeding if food is not owned', done => {
user.items.pets['Wolf-Base'] = 5;
try {
feed(user, {params: {pet: 'Wolf-Base', food: 'Meat'}});
feed(user, { params: { pet: 'Wolf-Base', food: 'Meat' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('messageFoodNotFound'));
@@ -70,11 +70,11 @@ describe('shared.ops.feed', () => {
}
});
it('does not allow feeding of special pets', (done) => {
it('does not allow feeding of special pets', done => {
user.items.pets['Wolf-Veteran'] = 5;
user.items.food.Meat = 1;
try {
feed(user, {params: {pet: 'Wolf-Veteran', food: 'Meat'}});
feed(user, { params: { pet: 'Wolf-Veteran', food: 'Meat' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('messageCannotFeedPet'));
@@ -82,12 +82,12 @@ describe('shared.ops.feed', () => {
}
});
it('does not allow feeding of mounts', (done) => {
it('does not allow feeding of mounts', done => {
user.items.pets['Wolf-Base'] = -1;
user.items.mounts['Wolf-Base'] = true;
user.items.food.Meat = 1;
try {
feed(user, {params: {pet: 'Wolf-Base', food: 'Meat'}});
feed(user, { params: { pet: 'Wolf-Base', food: 'Meat' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('messageAlreadyMount'));
@@ -101,9 +101,9 @@ describe('shared.ops.feed', () => {
user.items.pets['Wolf-Base'] = 5;
user.items.food.Saddle = 2;
user.items.currentPet = 'Wolf-Base';
let pet = content.petInfo['Wolf-Base'];
const pet = content.petInfo['Wolf-Base'];
let [data, message] = feed(user, {params: {pet: 'Wolf-Base', food: 'Saddle'}});
const [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: pet.text(),
@@ -119,10 +119,10 @@ describe('shared.ops.feed', () => {
user.items.pets['Wolf-Base'] = 5;
user.items.food.Meat = 2;
let food = content.food.Meat;
let pet = content.petInfo['Wolf-Base'];
const food = content.food.Meat;
const pet = content.petInfo['Wolf-Base'];
let [data, message] = feed(user, {params: {pet: 'Wolf-Base', food: 'Meat'}});
const [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: pet.text(),
@@ -137,10 +137,10 @@ describe('shared.ops.feed', () => {
user.items.pets['Wolf-Spooky'] = 5;
user.items.food.Milk = 2;
let food = content.food.Milk;
let pet = content.petInfo['Wolf-Spooky'];
const food = content.food.Milk;
const pet = content.petInfo['Wolf-Spooky'];
let [data, message] = feed(user, {params: {pet: 'Wolf-Spooky', food: 'Milk'}});
const [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: pet.text(),
@@ -155,10 +155,10 @@ describe('shared.ops.feed', () => {
user.items.pets['Wolf-Base'] = 5;
user.items.food.Milk = 2;
let food = content.food.Milk;
let pet = content.petInfo['Wolf-Base'];
const food = content.food.Milk;
const pet = content.petInfo['Wolf-Base'];
let [data, message] = feed(user, {params: {pet: 'Wolf-Base', food: 'Milk'}});
const [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: pet.text(),
@@ -183,7 +183,7 @@ describe('shared.ops.feed', () => {
'Cactus-Base': true,
'BearCub-Base': true,
};
feed(user, {params: {pet: 'Wolf-Spooky', food: 'Milk'}});
feed(user, { params: { pet: 'Wolf-Spooky', food: 'Milk' } });
expect(user.achievements.allYourBase).to.eql(true);
});
@@ -201,7 +201,7 @@ describe('shared.ops.feed', () => {
'Cactus-Desert': true,
'BearCub-Desert': true,
};
feed(user, {params: {pet: 'Wolf-Spooky', food: 'Milk'}});
feed(user, { params: { pet: 'Wolf-Spooky', food: 'Milk' } });
expect(user.achievements.aridAuthority).to.eql(true);
});
@@ -210,9 +210,9 @@ describe('shared.ops.feed', () => {
user.items.food.Milk = 2;
user.items.currentPet = 'Wolf-Base';
let pet = content.petInfo['Wolf-Base'];
const pet = content.petInfo['Wolf-Base'];
let [data, message] = feed(user, {params: {pet: 'Wolf-Base', food: 'Milk'}});
const [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: pet.text(),
+55 -55
View File
@@ -30,12 +30,12 @@ describe('shared.ops.hatch', () => {
}
});
it('does not allow hatching if user lacks specified egg', (done) => {
it('does not allow hatching if user lacks specified egg', done => {
user.items.eggs.Wolf = 1;
user.items.hatchingPotions.Base = 1;
user.items.pets = {};
try {
hatch(user, {params: {egg: 'Dragon', hatchingPotion: 'Base'}});
hatch(user, { params: { egg: 'Dragon', hatchingPotion: 'Base' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('messageMissingEggPotion'));
@@ -46,12 +46,12 @@ describe('shared.ops.hatch', () => {
}
});
it('does not allow hatching if user lacks specified hatching potion', (done) => {
it('does not allow hatching if user lacks specified hatching potion', done => {
user.items.eggs.Wolf = 1;
user.items.hatchingPotions.Base = 1;
user.items.pets = {};
try {
hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Golden'}});
hatch(user, { params: { egg: 'Wolf', hatchingPotion: 'Golden' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('messageMissingEggPotion'));
@@ -62,50 +62,50 @@ describe('shared.ops.hatch', () => {
}
});
it('does not allow hatching if user already owns target pet', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.items.pets = {'Wolf-Base': 10};
it('does not allow hatching if user already owns target pet', done => {
user.items.eggs = { Wolf: 1 };
user.items.hatchingPotions = { Base: 1 };
user.items.pets = { 'Wolf-Base': 10 };
try {
hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Base'}});
hatch(user, { params: { egg: 'Wolf', hatchingPotion: 'Base' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('messageAlreadyPet'));
expect(user.items.pets).to.eql({'Wolf-Base': 10});
expect(user.items.eggs).to.eql({Wolf: 1});
expect(user.items.hatchingPotions).to.eql({Base: 1});
expect(user.items.pets).to.eql({ 'Wolf-Base': 10 });
expect(user.items.eggs).to.eql({ Wolf: 1 });
expect(user.items.hatchingPotions).to.eql({ Base: 1 });
done();
}
});
it('does not allow hatching quest pet egg using premium potion', (done) => {
user.items.eggs = {Cheetah: 1};
user.items.hatchingPotions = {Spooky: 1};
it('does not allow hatching quest pet egg using premium potion', done => {
user.items.eggs = { Cheetah: 1 };
user.items.hatchingPotions = { Spooky: 1 };
user.items.pets = {};
try {
hatch(user, {params: {egg: 'Cheetah', hatchingPotion: 'Spooky'}});
hatch(user, { params: { egg: 'Cheetah', hatchingPotion: 'Spooky' } });
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('messageInvalidEggPotionCombo'));
expect(user.items.pets).to.be.empty;
expect(user.items.eggs).to.eql({Cheetah: 1});
expect(user.items.hatchingPotions).to.eql({Spooky: 1});
expect(user.items.eggs).to.eql({ Cheetah: 1 });
expect(user.items.hatchingPotions).to.eql({ Spooky: 1 });
done();
}
});
it('does not allow hatching quest pet egg using wacky potion', (done) => {
user.items.eggs = {Bunny: 1};
user.items.hatchingPotions = {Veggie: 1};
it('does not allow hatching quest pet egg using wacky potion', done => {
user.items.eggs = { Bunny: 1 };
user.items.hatchingPotions = { Veggie: 1 };
user.items.pets = {};
try {
hatch(user, {params: {egg: 'Bunny', hatchingPotion: 'Veggie'}});
hatch(user, { params: { egg: 'Bunny', hatchingPotion: 'Veggie' } });
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('messageInvalidEggPotionCombo'));
expect(user.items.pets).to.be.empty;
expect(user.items.eggs).to.eql({Bunny: 1});
expect(user.items.hatchingPotions).to.eql({Veggie: 1});
expect(user.items.eggs).to.eql({ Bunny: 1 });
expect(user.items.hatchingPotions).to.eql({ Veggie: 1 });
done();
}
});
@@ -113,51 +113,51 @@ describe('shared.ops.hatch', () => {
context('successful hatching', () => {
it('hatches a basic pet', () => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.items.eggs = { Wolf: 1 };
user.items.hatchingPotions = { Base: 1 };
user.items.pets = {};
let [data, message] = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Base'}});
const [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});
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 });
});
it('hatches a quest pet', () => {
user.items.eggs = {Cheetah: 1};
user.items.hatchingPotions = {Base: 1};
user.items.eggs = { Cheetah: 1 };
user.items.hatchingPotions = { Base: 1 };
user.items.pets = {};
let [data, message] = hatch(user, {params: {egg: 'Cheetah', hatchingPotion: 'Base'}});
const [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});
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 });
});
it('hatches a premium pet', () => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Spooky: 1};
user.items.eggs = { Wolf: 1 };
user.items.hatchingPotions = { Spooky: 1 };
user.items.pets = {};
let [data, message] = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Spooky'}});
const [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});
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 });
});
it('hatches a pet previously raised to a mount', () => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.items.pets = {'Wolf-Base': -1};
let [data, message] = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Base'}});
user.items.eggs = { Wolf: 1 };
user.items.hatchingPotions = { Base: 1 };
user.items.pets = { 'Wolf-Base': -1 };
const [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});
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 });
});
it('awards Back to Basics achievement', () => {
@@ -172,9 +172,9 @@ describe('shared.ops.hatch', () => {
'Cactus-Base': 15,
'BearCub-Base': 5,
};
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Spooky: 1};
hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Spooky'}});
user.items.eggs = { Wolf: 1 };
user.items.hatchingPotions = { Spooky: 1 };
hatch(user, { params: { egg: 'Wolf', hatchingPotion: 'Spooky' } });
expect(user.achievements.backToBasics).to.eql(true);
});
@@ -190,9 +190,9 @@ describe('shared.ops.hatch', () => {
'Cactus-Desert': 15,
'BearCub-Desert': 5,
};
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Spooky: 1};
hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Spooky'}});
user.items.eggs = { Wolf: 1 };
user.items.hatchingPotions = { Spooky: 1 };
hatch(user, { params: { egg: 'Wolf', hatchingPotion: 'Spooky' } });
expect(user.achievements.dustDevil).to.eql(true);
});
});
+5 -5
View File
@@ -15,7 +15,7 @@ describe('shared.ops.openMysteryItem', () => {
user = generateUser();
});
it('returns error when item key is empty', (done) => {
it('returns error when item key is empty', done => {
try {
openMysteryItem(user);
} catch (err) {
@@ -26,17 +26,17 @@ describe('shared.ops.openMysteryItem', () => {
});
it('opens mystery item', () => {
let mysteryItemKey = 'eyewear_special_summerRogue';
const mysteryItemKey = 'eyewear_special_summerRogue';
user.purchased.plan.mysteryItems = [mysteryItemKey];
user.notifications.push({type: 'NEW_MYSTERY_ITEMS', data: {items: [mysteryItemKey]}});
user.notifications.push({ type: 'NEW_MYSTERY_ITEMS', data: { items: [mysteryItemKey] } });
expect(user.notifications.length).to.equal(1);
let [data, message] = openMysteryItem(user);
const [data, message] = openMysteryItem(user);
expect(user.items.gear.owned[mysteryItemKey]).to.be.true;
expect(message).to.equal(i18n.t('mysteryItemOpened'));
let item = _.cloneDeep(content.gear.flat[mysteryItemKey]);
const item = _.cloneDeep(content.gear.flat[mysteryItemKey]);
item.text = content.gear.flat[mysteryItemKey].text();
expect(data).to.eql(item);
expect(user.notifications.length).to.equal(0);
+1 -1
View File
@@ -1,7 +1,7 @@
import {
generateUser,
} from '../../helpers/common.helper';
import {addPinnedGear} from '../../../website/common/script/ops/pinnedGearUtils';
import { addPinnedGear } from '../../../website/common/script/ops/pinnedGearUtils';
describe('shared.ops.pinnedGearUtils.addPinnedGear', () => {
let user;
+7 -7
View File
@@ -10,7 +10,7 @@ import {
describe('shared.ops.readCard', () => {
let user;
let cardType = 'greeting';
const cardType = 'greeting';
beforeEach(() => {
user = generateUser();
@@ -18,7 +18,7 @@ describe('shared.ops.readCard', () => {
user.flags.cardReceived = true;
});
it('returns an error when cardType is not provided', (done) => {
it('returns an error when cardType is not provided', done => {
try {
readCard(user);
} catch (err) {
@@ -28,9 +28,9 @@ describe('shared.ops.readCard', () => {
}
});
it('returns an error when unknown cardType is provided', (done) => {
it('returns an error when unknown cardType is provided', done => {
try {
readCard(user, {params: {cardType: 'randomCardType'}});
readCard(user, { params: { cardType: 'randomCardType' } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('cardTypeNotAllowed'));
@@ -41,13 +41,13 @@ describe('shared.ops.readCard', () => {
it('reads a card', () => {
user.notifications.push({
type: 'CARD_RECEIVED',
data: {card: cardType},
data: { card: cardType },
});
const initialNotificationNuber = user.notifications.length;
let [, message] = readCard(user, {params: {cardType: 'greeting'}});
const [, message] = readCard(user, { params: { cardType: 'greeting' } });
expect(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;
expect(user.notifications.length).to.equal(initialNotificationNuber - 1);
+19 -17
View File
@@ -14,8 +14,8 @@ import {
describe('shared.ops.rebirth', () => {
let user;
let animal = 'Wolf-Base';
let userStats = ['per', 'int', 'con', 'str', 'points', 'gp', 'exp', 'mp'];
const animal = 'Wolf-Base';
const userStats = ['per', 'int', 'con', 'str', 'points', 'gp', 'exp', 'mp'];
let tasks = [];
beforeEach(() => {
@@ -24,7 +24,7 @@ describe('shared.ops.rebirth', () => {
tasks = [generateHabit(), generateDaily(), generateTodo(), generateReward()];
});
it('returns an error when user balance is too low and user is less than max level', (done) => {
it('returns an error when user balance is too low and user is less than max level', done => {
user.balance = 0;
try {
@@ -37,7 +37,7 @@ describe('shared.ops.rebirth', () => {
});
it('rebirths a user with enough gems', () => {
let [, message] = rebirth(user);
const [, message] = rebirth(user);
expect(message).to.equal(i18n.t('rebirthComplete'));
});
@@ -46,7 +46,7 @@ describe('shared.ops.rebirth', () => {
user.balance = 0;
user.stats.lvl = MAX_LEVEL;
let [, message] = rebirth(user);
const [, message] = rebirth(user);
expect(message).to.equal(i18n.t('rebirthComplete'));
expect(user.flags.lastFreeRebirth).to.exist;
@@ -56,7 +56,7 @@ describe('shared.ops.rebirth', () => {
user.balance = 0;
user.stats.lvl = MAX_LEVEL + 1;
let [, message] = rebirth(user);
const [, message] = rebirth(user);
expect(message).to.equal(i18n.t('rebirthComplete'));
});
@@ -65,7 +65,7 @@ describe('shared.ops.rebirth', () => {
user.stats.lvl = MAX_LEVEL + 1;
user.flags.lastFreeRebirth = new Date();
let [, message] = rebirth(user);
const [, message] = rebirth(user);
expect(message).to.equal(i18n.t('rebirthComplete'));
expect(user.balance).to.equal(0);
@@ -98,7 +98,7 @@ describe('shared.ops.rebirth', () => {
});
it('resets a user\'s buffs', () => {
user.stats.buffs = {test: 'test'};
user.stats.buffs = { test: 'test' };
rebirth(user);
@@ -123,21 +123,21 @@ describe('shared.ops.rebirth', () => {
it('resets a user\'s stats', () => {
user.stats.class = 'rouge';
_.each(userStats, function setUsersStats (value) {
_.each(userStats, value => {
user.stats[value] = 10;
});
rebirth(user);
_.each(userStats, function resetUserStats (value) {
_.each(userStats, value => {
user.stats[value] = 0;
});
});
it('retains a user\'s gear', () => {
let prevGearEquipped = user.items.gear.equipped;
let prevGearCostume = user.items.gear.costume;
let prevPrefCostume = user.preferences.costume;
const prevGearEquipped = user.items.gear.equipped;
const prevGearCostume = user.items.gear.costume;
const prevPrefCostume = user.preferences.costume;
rebirth(user);
@@ -148,7 +148,7 @@ describe('shared.ops.rebirth', () => {
it('retains a user\'s gear owned', () => {
user.items.gear.owned.weapon_warrior_1 = true; // eslint-disable-line camelcase
let prevGearOwned = user.items.gear.owned;
const prevGearOwned = user.items.gear.owned;
rebirth(user);
@@ -176,7 +176,7 @@ describe('shared.ops.rebirth', () => {
user.flags.dropsEnabled = true;
user.flags.classSelected = true;
user.flags.rebirthEnabled = true;
user.flags.levelDrops = {test: 'test'};
user.flags.levelDrops = { test: 'test' };
rebirth(user);
@@ -228,7 +228,8 @@ describe('shared.ops.rebirth', () => {
it('always increments rebirth achievements when level is MAX_LEVEL', () => {
user.stats.lvl = MAX_LEVEL;
user.achievements.rebirths = 1;
user.achievements.rebirthLevel = MAX_LEVEL + 1; // this value is not actually possible (actually capped at MAX_LEVEL) but makes a good test
// this value is not actually possible (actually capped at MAX_LEVEL) but makes a good test
user.achievements.rebirthLevel = MAX_LEVEL + 1;
rebirth(user);
@@ -239,7 +240,8 @@ describe('shared.ops.rebirth', () => {
it('always increments rebirth achievements when level is greater than MAX_LEVEL', () => {
user.stats.lvl = MAX_LEVEL + 1;
user.achievements.rebirths = 1;
user.achievements.rebirthLevel = MAX_LEVEL + 2; // this value is not actually possible (actually capped at MAX_LEVEL) but makes a good test
// this value is not actually possible (actually capped at MAX_LEVEL) but makes a good test
user.achievements.rebirthLevel = MAX_LEVEL + 2;
rebirth(user);
+23 -23
View File
@@ -10,19 +10,19 @@ import {
describe('shared.ops.releaseBoth', () => {
let user;
let animal = 'Wolf-Base';
const animal = 'Wolf-Base';
beforeEach(() => {
user = generateUser();
for (let p in content.pets) {
Object.keys(content.pets).forEach(p => {
user.items.pets[p] = content.pets[p];
user.items.pets[p] = 5;
}
});
for (let m in content.pets) {
Object.keys(content.pets).forEach(m => {
user.items.mounts[m] = content.pets[m];
user.items.mounts[m] = true;
}
});
user.items.currentMount = animal;
user.items.currentPet = animal;
@@ -30,7 +30,7 @@ describe('shared.ops.releaseBoth', () => {
user.achievements.triadBingo = true;
});
xit('returns an error when user balance is too low and user does not have triadBingo', (done) => {
xit('returns an error when user balance is too low and user does not have triadBingo', done => {
user.balance = 0;
try {
@@ -42,7 +42,7 @@ describe('shared.ops.releaseBoth', () => {
}
});
it('returns an error when user does not have all pets', (done) => {
it('returns an error when user does not have all pets', done => {
const petKeys = Object.keys(user.items.pets);
delete user.items.pets[petKeys[0]];
@@ -59,7 +59,7 @@ describe('shared.ops.releaseBoth', () => {
});
it('grants triad bingo with gems', () => {
let message = releaseBoth(user)[1];
const message = releaseBoth(user)[1];
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
expect(user.achievements.triadBingoCount).to.equal(1);
@@ -70,23 +70,23 @@ describe('shared.ops.releaseBoth', () => {
user.achievements.triadBingo = 1;
user.achievements.triadBingoCount = 1;
let message = releaseBoth(user)[1];
const message = releaseBoth(user)[1];
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
expect(user.achievements.triadBingoCount).to.equal(2);
});
it('does not grant triad bingo if any pet has not been previously found', () => {
let triadBingoCountBeforeRelease = user.achievements.triadBingoCount;
const triadBingoCountBeforeRelease = user.achievements.triadBingoCount;
user.items.pets[animal] = -1;
let message = releaseBoth(user)[1];
const message = releaseBoth(user)[1];
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
expect(user.achievements.triadBingoCount).to.equal(triadBingoCountBeforeRelease);
});
it('releases pets', () => {
let message = releaseBoth(user)[1];
const message = releaseBoth(user)[1];
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
expect(user.items.pets[animal]).to.equal(0);
@@ -94,7 +94,7 @@ describe('shared.ops.releaseBoth', () => {
});
it('does not increment beastMasterCount if any pet is level 0 (released)', () => {
let beastMasterCountBeforeRelease = user.achievements.beastMasterCount;
const beastMasterCountBeforeRelease = user.achievements.beastMasterCount;
user.items.pets[animal] = 0;
try {
releaseBoth(user);
@@ -104,7 +104,7 @@ describe('shared.ops.releaseBoth', () => {
});
it('does not increment beastMasterCount if any pet is missing (null)', () => {
let beastMasterCountBeforeRelease = user.achievements.beastMasterCount;
const beastMasterCountBeforeRelease = user.achievements.beastMasterCount;
user.items.pets[animal] = null;
try {
@@ -115,7 +115,7 @@ describe('shared.ops.releaseBoth', () => {
});
it('does not increment beastMasterCount if any pet is missing (undefined)', () => {
let beastMasterCountBeforeRelease = user.achievements.beastMasterCount;
const beastMasterCountBeforeRelease = user.achievements.beastMasterCount;
delete user.items.pets[animal];
try {
@@ -126,14 +126,14 @@ describe('shared.ops.releaseBoth', () => {
});
it('releases mounts', () => {
let message = releaseBoth(user)[1];
const message = releaseBoth(user)[1];
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
expect(user.items.mounts[animal]).to.equal(null);
});
it('does not increase mountMasterCount achievement if mount is missing (null)', () => {
let mountMasterCountBeforeRelease = user.achievements.mountMasterCount;
const mountMasterCountBeforeRelease = user.achievements.mountMasterCount;
user.items.mounts[animal] = null;
try {
@@ -144,7 +144,7 @@ describe('shared.ops.releaseBoth', () => {
});
it('does not increase mountMasterCount achievement if mount is missing (undefined)', () => {
let mountMasterCountBeforeRelease = user.achievements.mountMasterCount;
const mountMasterCountBeforeRelease = user.achievements.mountMasterCount;
delete user.items.mounts[animal];
try {
@@ -155,7 +155,7 @@ describe('shared.ops.releaseBoth', () => {
});
it('removes drop currentPet', () => {
let petInfo = content.petInfo[user.items.currentPet];
const petInfo = content.petInfo[user.items.currentPet];
expect(petInfo.type).to.equal('drop');
releaseBoth(user);
@@ -164,7 +164,7 @@ describe('shared.ops.releaseBoth', () => {
});
it('removes drop currentMount', () => {
let mountInfo = content.mountInfo[user.items.currentMount];
const mountInfo = content.mountInfo[user.items.currentMount];
expect(mountInfo.type).to.equal('drop');
releaseBoth(user);
@@ -172,15 +172,15 @@ describe('shared.ops.releaseBoth', () => {
});
it('leaves non-drop pets and mounts equipped', () => {
let questAnimal = 'Gryphon-Base';
const questAnimal = 'Gryphon-Base';
user.items.currentMount = questAnimal;
user.items.currentPet = questAnimal;
user.items.pets[questAnimal] = 5;
user.items.mounts[questAnimal] = true;
let petInfo = content.petInfo[user.items.currentPet];
const petInfo = content.petInfo[user.items.currentPet];
expect(petInfo.type).to.not.equal('drop');
let mountInfo = content.mountInfo[user.items.currentMount];
const mountInfo = content.mountInfo[user.items.currentMount];
expect(mountInfo.type).to.not.equal('drop');
releaseBoth(user);
+11 -11
View File
@@ -10,20 +10,20 @@ import {
describe('shared.ops.releaseMounts', () => {
let user;
let animal = 'Wolf-Base';
const animal = 'Wolf-Base';
beforeEach(() => {
user = generateUser();
for (let k in content.pets) {
Object.keys(content.pets).forEach(k => {
user.items.mounts[k] = content.pets[k];
user.items.mounts[k] = true;
}
});
user.items.currentMount = animal;
user.balance = 1;
});
it('returns an error when user balance is too low', (done) => {
it('returns an error when user balance is too low', done => {
user.balance = 0;
try {
@@ -35,7 +35,7 @@ describe('shared.ops.releaseMounts', () => {
}
});
it('returns an error when user does not have all pets', (done) => {
it('returns an error when user does not have all pets', done => {
const mountsKeys = Object.keys(user.items.mounts);
delete user.items.mounts[mountsKeys[0]];
@@ -49,14 +49,14 @@ describe('shared.ops.releaseMounts', () => {
});
it('releases mounts', () => {
let message = releaseMounts(user)[1];
const message = releaseMounts(user)[1];
expect(message).to.equal(i18n.t('mountsReleased'));
expect(user.items.mounts[animal]).to.equal(null);
});
it('removes drop currentMount', () => {
let mountInfo = content.mountInfo[user.items.currentMount];
const mountInfo = content.mountInfo[user.items.currentMount];
expect(mountInfo.type).to.equal('drop');
releaseMounts(user);
@@ -64,11 +64,11 @@ describe('shared.ops.releaseMounts', () => {
});
it('leaves non-drop mount equipped', () => {
let questAnimal = 'Gryphon-Base';
const questAnimal = 'Gryphon-Base';
user.items.currentMount = questAnimal;
user.items.mounts[questAnimal] = true;
let mountInfo = content.mountInfo[user.items.currentMount];
const mountInfo = content.mountInfo[user.items.currentMount];
expect(mountInfo.type).to.not.equal('drop');
releaseMounts(user);
@@ -81,7 +81,7 @@ describe('shared.ops.releaseMounts', () => {
});
it('does not increase mountMasterCount achievement if mount is missing (null)', () => {
let mountMasterCountBeforeRelease = user.achievements.mountMasterCount;
const mountMasterCountBeforeRelease = user.achievements.mountMasterCount;
user.items.mounts[animal] = null;
try {
@@ -92,7 +92,7 @@ describe('shared.ops.releaseMounts', () => {
});
it('does not increase mountMasterCount achievement if mount is missing (undefined)', () => {
let mountMasterCountBeforeRelease = user.achievements.mountMasterCount;
const mountMasterCountBeforeRelease = user.achievements.mountMasterCount;
delete user.items.mounts[animal];
try {
+11 -11
View File
@@ -10,20 +10,20 @@ import {
describe('shared.ops.releasePets', () => {
let user;
let animal = 'Wolf-Base';
const animal = 'Wolf-Base';
beforeEach(() => {
user = generateUser();
for (let k in content.pets) {
Object.keys(content.pets).forEach(k => {
user.items.pets[k] = content.pets[k];
user.items.pets[k] = 5;
}
});
user.items.currentPet = animal;
user.balance = 1;
});
it('returns an error when user balance is too low', (done) => {
it('returns an error when user balance is too low', done => {
user.balance = 0;
try {
@@ -35,7 +35,7 @@ describe('shared.ops.releasePets', () => {
}
});
it('returns an error when user does not have all pets', (done) => {
it('returns an error when user does not have all pets', done => {
const petKeys = Object.keys(user.items.pets);
delete user.items.pets[petKeys[0]];
@@ -49,14 +49,14 @@ describe('shared.ops.releasePets', () => {
});
it('releases pets', () => {
let message = releasePets(user)[1];
const message = releasePets(user)[1];
expect(message).to.equal(i18n.t('petsReleased'));
expect(user.items.pets[animal]).to.equal(0);
});
it('removes drop currentPet', () => {
let petInfo = content.petInfo[user.items.currentPet];
const petInfo = content.petInfo[user.items.currentPet];
expect(petInfo.type).to.equal('drop');
releasePets(user);
@@ -64,11 +64,11 @@ describe('shared.ops.releasePets', () => {
});
it('leaves non-drop pets equipped', () => {
let questAnimal = 'Gryphon-Base';
const questAnimal = 'Gryphon-Base';
user.items.currentPet = questAnimal;
user.items.pets[questAnimal] = 5;
let petInfo = content.petInfo[user.items.currentPet];
const petInfo = content.petInfo[user.items.currentPet];
expect(petInfo.type).to.not.equal('drop');
releasePets(user);
@@ -99,7 +99,7 @@ describe('shared.ops.releasePets', () => {
});
it('does not increment beastMasterCount if any pet is missing (null)', () => {
let beastMasterCountBeforeRelease = user.achievements.beastMasterCount;
const beastMasterCountBeforeRelease = user.achievements.beastMasterCount;
user.items.pets[animal] = null;
try {
@@ -110,7 +110,7 @@ describe('shared.ops.releasePets', () => {
});
it('does not increment beastMasterCount if any pet is missing (undefined)', () => {
let beastMasterCountBeforeRelease = user.achievements.beastMasterCount;
const beastMasterCountBeforeRelease = user.achievements.beastMasterCount;
delete user.items.pets[animal];
try {
+2 -2
View File
@@ -19,7 +19,7 @@ describe('shared.ops.reroll', () => {
tasks = [generateDaily(), generateReward()];
});
it('returns an error when user balance is too low', (done) => {
it('returns an error when user balance is too low', done => {
user.balance = 0;
try {
@@ -32,7 +32,7 @@ describe('shared.ops.reroll', () => {
});
it('rerolls a user with enough gems', () => {
let [, message] = reroll(user);
const [, message] = reroll(user);
expect(message).to.equal(i18n.t('fortifyComplete'));
});
+5 -5
View File
@@ -16,10 +16,10 @@ describe('shared.ops.reset', () => {
user = generateUser();
user.balance = 2;
let habit = generateHabit();
let todo = generateTodo();
let daily = generateDaily();
let reward = generateReward();
const habit = generateHabit();
const todo = generateTodo();
const daily = generateDaily();
const reward = generateReward();
user.tasksOrder.habits = [habit._id];
user.tasksOrder.todos = [todo._id];
@@ -31,7 +31,7 @@ describe('shared.ops.reset', () => {
it('resets a user', () => {
let [, message] = reset(user);
const [, message] = reset(user);
expect(message).to.equal(i18n.t('resetComplete'));
});
+26 -28
View File
@@ -18,7 +18,7 @@ describe('shared.ops.revive', () => {
user.stats.hp = 0;
});
it('returns an error when user is not dead', (done) => {
it('returns an error when user is not dead', done => {
user.stats.hp = 10;
try {
@@ -56,28 +56,26 @@ describe('shared.ops.revive', () => {
});
it('it decreases a random stat from str, con, per, int by one', () => {
let stats = ['str', 'con', 'per', 'int'];
const stats = ['str', 'con', 'per', 'int'];
_.each(stats, (s) => {
_.each(stats, s => {
user.stats[s] = 1;
});
revive(user);
let statSum = _.reduce(stats, (m, k) => {
return m + user.stats[k];
}, 0);
const statSum = _.reduce(stats, (m, k) => m + user.stats[k], 0);
expect(statSum).to.equal(3);
});
it('removes a random item from user gear owned', () => {
let weaponKey = 'weapon_warrior_0';
const weaponKey = 'weapon_warrior_0';
user.items.gear.owned[weaponKey] = true;
let [, message] = revive(user);
const [, message] = revive(user);
expect(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;
});
@@ -96,67 +94,67 @@ describe('shared.ops.revive', () => {
weapon_warrior_0: true,
};
let weaponKey = 'weapon_warrior_0';
const weaponKey = 'weapon_warrior_0';
let [, message] = revive(user);
const [, message] = revive(user);
expect(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;
});
it('does not remove items of a different class', () => {
let weaponKey = 'weapon_wizard_1';
const weaponKey = 'weapon_wizard_1';
user.items.gear.owned[weaponKey] = true;
let [, message] = revive(user);
const [, message] = revive(user);
expect(message).to.equal('');
expect(user.items.gear.owned[weaponKey]).to.be.true;
});
it('removes "special" items', () => {
let weaponKey = 'weapon_special_1';
const weaponKey = 'weapon_special_1';
user.items.gear.owned[weaponKey] = true;
let [, message] = revive(user);
const [, message] = revive(user);
expect(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;
});
it('removes "armoire" items', () => {
let weaponKey = 'armor_armoire_goldenToga';
const weaponKey = 'armor_armoire_goldenToga';
user.items.gear.owned[weaponKey] = true;
let [, message] = revive(user);
const [, message] = revive(user);
expect(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;
});
it('dequips lost item from user if user had it equipped', () => {
let weaponKey = 'weapon_warrior_0';
let itemToLose = content.gear.flat[weaponKey];
const weaponKey = 'weapon_warrior_0';
const itemToLose = content.gear.flat[weaponKey];
user.items.gear.owned[weaponKey] = true;
user.items.gear.equipped[itemToLose.type] = itemToLose.key;
let [, message] = revive(user);
const [, message] = revive(user);
expect(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`);
});
it('dequips lost item from user costume if user was using it in costume', () => {
let weaponKey = 'weapon_warrior_0';
let itemToLose = content.gear.flat[weaponKey];
const weaponKey = 'weapon_warrior_0';
const itemToLose = content.gear.flat[weaponKey];
user.items.gear.owned[weaponKey] = true;
user.items.gear.costume[itemToLose.type] = itemToLose.key;
let [, message] = revive(user);
const [, message] = revive(user);
expect(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`);
});
});
+82 -56
View File
@@ -13,11 +13,11 @@ import {
} from '../../../website/common/script/libs/errors';
import crit from '../../../website/common/script/fns/crit';
let EPSILON = 0.0001; // negligible distance between datapoints
const EPSILON = 0.0001; // negligible distance between datapoints
let beforeAfter = () => {
let beforeUser = generateUser();
let afterUser = _.cloneDeep(beforeUser);
const beforeAfter = () => {
const beforeUser = generateUser();
const afterUser = _.cloneDeep(beforeUser);
return {
beforeUser,
@@ -25,7 +25,7 @@ let beforeAfter = () => {
};
};
let expectGainedPoints = (beforeUser, afterUser, beforeTask, afterTask) => {
const expectGainedPoints = (beforeUser, afterUser, beforeTask, afterTask) => {
expect(afterUser.stats.hp).to.eql(50);
expect(afterUser.stats.exp).to.be.greaterThan(beforeUser.stats.exp);
expect(afterUser.stats.gp).to.be.greaterThan(beforeUser.stats.gp);
@@ -35,15 +35,15 @@ let expectGainedPoints = (beforeUser, afterUser, beforeTask, afterTask) => {
}
};
let expectClosePoints = (beforeUser, afterUser, beforeTask, task) => {
const expectClosePoints = (beforeUser, afterUser, beforeTask, task) => {
expect(Math.abs(afterUser.stats.exp - beforeUser.stats.exp)).to.be.lessThan(EPSILON);
expect(Math.abs(afterUser.stats.gp - beforeUser.stats.gp)).to.be.lessThan(EPSILON);
expect(Math.abs(task.value - beforeTask.value)).to.be.lessThan(EPSILON);
};
function expectRoughlyEqualDates (date1, date2) {
date1 = date1.valueOf();
date2 = date2.valueOf();
date1 = date1.valueOf(); // eslint-disable-line no-param-reassign
date2 = date2.valueOf(); // eslint-disable-line no-param-reassign
expect(date1).to.be.within(date2 - 100, date2 + 100);
}
@@ -54,8 +54,8 @@ describe('shared.ops.scoreTask', () => {
ref = beforeAfter();
});
it('throws an error when scoring a reward if user does not have enough gold', (done) => {
let reward = generateReward({ userId: ref.afterUser._id, text: 'some reward', value: 100 });
it('throws an error when scoring a reward if user does not have enough gold', done => {
const reward = generateReward({ userId: ref.afterUser._id, text: 'some reward', value: 100 });
try {
scoreTask({ user: ref.afterUser, task: reward });
} catch (err) {
@@ -66,14 +66,14 @@ describe('shared.ops.scoreTask', () => {
});
it('completes when the task direction is up', () => {
let task = generateTodo({ userId: ref.afterUser._id, text: 'todo to complete', cron: false });
const task = generateTodo({ userId: ref.afterUser._id, text: 'todo to complete', cron: false });
scoreTask({ user: ref.afterUser, task, direction: 'up' });
expect(task.completed).to.eql(true);
expectRoughlyEqualDates(task.dateCompleted, new Date());
});
it('uncompletes when the task direction is down', () => {
let task = generateTodo({ userId: ref.afterUser._id, text: 'todo to complete', cron: false });
const task = generateTodo({ userId: ref.afterUser._id, text: 'todo to complete', cron: false });
scoreTask({ user: ref.afterUser, task, direction: 'down' });
expect(task.completed).to.eql(false);
expect(task.dateCompleted).to.not.exist;
@@ -88,19 +88,23 @@ describe('shared.ops.scoreTask', () => {
});
it('works', () => {
let delta1, delta2, delta3;
delta1 = scoreTask({ user: ref.afterUser, task: habit, direction: 'up', times: 5, cron: false });
const delta1 = scoreTask({
user: ref.afterUser, task: habit, direction: 'up', times: 5, cron: false,
});
ref = beforeAfter();
habit = generateHabit({ userId: ref.afterUser._id, text: 'some habit' });
delta2 = scoreTask({ user: ref.afterUser, task: habit, direction: 'up', times: 4, cron: false });
const delta2 = scoreTask({
user: ref.afterUser, task: habit, direction: 'up', times: 4, cron: false,
});
ref = beforeAfter();
habit = generateHabit({ userId: ref.afterUser._id, text: 'some habit' });
delta3 = scoreTask({ user: ref.afterUser, task: habit, direction: 'up', times: 5, cron: false });
const delta3 = scoreTask({
user: ref.afterUser, task: habit, direction: 'up', times: 5, cron: false,
});
expect(Math.abs(delta1 - delta2)).to.be.greaterThan(EPSILON);
expect(Math.abs(delta1 - delta3)).to.be.lessThan(EPSILON);
@@ -108,58 +112,62 @@ describe('shared.ops.scoreTask', () => {
});
it('checks that the streak parameters affects the score', () => {
let task = generateDaily({ userId: ref.afterUser._id, text: 'task to check streak' });
scoreTask({ user: ref.afterUser, task, direction: 'up', cron: false });
scoreTask({ user: ref.afterUser, task, direction: 'up', cron: false });
const task = generateDaily({ userId: ref.afterUser._id, text: 'task to check streak' });
scoreTask({
user: ref.afterUser, task, direction: 'up', cron: false,
});
scoreTask({
user: ref.afterUser, task, direction: 'up', cron: false,
});
expect(task.streak).to.eql(2);
});
describe('verifies that 21-day streak achievements are given/removed correctly', () => {
let initialStreakCount = 20; // 1 before the streak achievement is awarded
const initialStreakCount = 20; // 1 before the streak achievement is awarded
beforeEach(() => {
ref = beforeAfter();
});
it('awards the first streak achievement', () => {
let task = generateDaily({ userId: ref.afterUser._id, text: 'some daily', streak: initialStreakCount });
const task = generateDaily({ userId: ref.afterUser._id, text: 'some daily', streak: initialStreakCount });
scoreTask({ user: ref.afterUser, task, direction: 'up' });
expect(ref.afterUser.achievements.streak).to.equal(1);
});
it('increments the streak achievement for a second streak', () => {
let task1 = generateDaily({ userId: ref.afterUser._id, text: 'first daily', streak: initialStreakCount });
const task1 = generateDaily({ userId: ref.afterUser._id, text: 'first daily', streak: initialStreakCount });
scoreTask({ user: ref.afterUser, task: task1, direction: 'up' });
let task2 = generateDaily({ userId: ref.afterUser._id, text: 'second daily', streak: initialStreakCount });
const task2 = generateDaily({ userId: ref.afterUser._id, text: 'second daily', streak: initialStreakCount });
scoreTask({ user: ref.afterUser, task: task2, direction: 'up' });
expect(ref.afterUser.achievements.streak).to.equal(2);
});
it('removes the first streak achievement when unticking a Daily', () => {
let task = generateDaily({ userId: ref.afterUser._id, text: 'some daily', streak: initialStreakCount });
const task = generateDaily({ userId: ref.afterUser._id, text: 'some daily', streak: initialStreakCount });
scoreTask({ user: ref.afterUser, task, direction: 'up' });
scoreTask({ user: ref.afterUser, task, direction: 'down' });
expect(ref.afterUser.achievements.streak).to.equal(0);
});
it('decrements a multiple streak achievement when unticking a Daily', () => {
let task1 = generateDaily({ userId: ref.afterUser._id, text: 'first daily', streak: initialStreakCount });
const task1 = generateDaily({ userId: ref.afterUser._id, text: 'first daily', streak: initialStreakCount });
scoreTask({ user: ref.afterUser, task: task1, direction: 'up' });
let task2 = generateDaily({ userId: ref.afterUser._id, text: 'second daily', streak: initialStreakCount });
const task2 = generateDaily({ userId: ref.afterUser._id, text: 'second daily', streak: initialStreakCount });
scoreTask({ user: ref.afterUser, task: task2, direction: 'up' });
scoreTask({ user: ref.afterUser, task: task2, direction: 'down' });
expect(ref.afterUser.achievements.streak).to.equal(1);
});
it('does not give a streak achievement for a streak of zero', () => {
let task = generateDaily({ userId: ref.afterUser._id, text: 'some daily', streak: -1 });
const task = generateDaily({ userId: ref.afterUser._id, text: 'some daily', streak: -1 });
scoreTask({ user: ref.afterUser, task, direction: 'up' });
expect(ref.afterUser.achievements.streak).to.equal(0);
});
it('does not remove a streak achievement when unticking a Daily gives a streak of zero', () => {
let task1 = generateDaily({ userId: ref.afterUser._id, text: 'first daily', streak: initialStreakCount });
const task1 = generateDaily({ userId: ref.afterUser._id, text: 'first daily', streak: initialStreakCount });
scoreTask({ user: ref.afterUser, task: task1, direction: 'up' });
let task2 = generateDaily({ userId: ref.afterUser._id, text: 'second daily', streak: 1 });
const task2 = generateDaily({ userId: ref.afterUser._id, text: 'second daily', streak: 1 });
scoreTask({ user: ref.afterUser, task: task2, direction: 'down' });
expect(ref.afterUser.achievements.streak).to.equal(1);
});
@@ -168,8 +176,10 @@ describe('shared.ops.scoreTask', () => {
describe('scores', () => {
let options = {};
let habit;
let freshDaily, daily;
let freshTodo, todo;
let freshDaily; let
daily;
let freshTodo; let
todo;
beforeEach(() => {
ref = beforeAfter(options);
@@ -190,21 +200,25 @@ describe('shared.ops.scoreTask', () => {
});
it('critical hits', () => {
let normalUser = ref.beforeUser;
const normalUser = ref.beforeUser;
expect(normalUser.party.quest.progress.up).to.eql(0);
normalUser.party.quest.key = 'gryphon';
let critUser = ref.afterUser;
const critUser = ref.afterUser;
expect(critUser.party.quest.progress.up).to.eql(0);
critUser.party.quest.key = 'gryphon';
let normalTask = todo;
let critTask = freshTodo;
const normalTask = todo;
const critTask = freshTodo;
scoreTask({ user: normalUser, task: normalTask, direction: 'up', cron: false });
let normalTaskDelta = normalUser.party.quest.progress.up;
scoreTask({
user: normalUser, task: normalTask, direction: 'up', cron: false,
});
const normalTaskDelta = normalUser.party.quest.progress.up;
sandbox.stub(crit, 'crit').returns(1.5);
scoreTask({ user: critUser, task: critTask, direction: 'up', cron: false });
let critTaskDelta = critUser.party.quest.progress.up;
scoreTask({
user: critUser, task: critTask, direction: 'up', cron: false,
});
const critTaskDelta = critUser.party.quest.progress.up;
crit.crit.restore();
expect(critUser.stats.hp).to.eql(normalUser.stats.hp);
@@ -219,20 +233,26 @@ describe('shared.ops.scoreTask', () => {
expect(ref.afterUser.party.quest.progress.up).to.eql(0);
ref.afterUser.party.quest.key = 'gryphon';
scoreTask({ user: ref.afterUser, task: habit, direction: 'up', cron: false });
let firstTaskDelta = ref.afterUser.party.quest.progress.up;
scoreTask({
user: ref.afterUser, task: habit, direction: 'up', cron: false,
});
const firstTaskDelta = ref.afterUser.party.quest.progress.up;
expect(firstTaskDelta).to.be.greaterThan(0);
expect(ref.afterUser._tmp.quest.progressDelta).to.eql(firstTaskDelta);
scoreTask({ user: ref.afterUser, task: habit, direction: 'up', cron: false });
let secondTaskDelta = ref.afterUser.party.quest.progress.up - firstTaskDelta;
scoreTask({
user: ref.afterUser, task: habit, direction: 'up', cron: false,
});
const secondTaskDelta = ref.afterUser.party.quest.progress.up - firstTaskDelta;
expect(secondTaskDelta).to.be.greaterThan(0);
expect(ref.afterUser._tmp.quest.progressDelta).to.eql(secondTaskDelta);
});
it('does not modify stats when task need approval', () => {
todo.group.approval.required = true;
options = { user: ref.afterUser, task: todo, direction: 'up', times: 5, cron: false };
options = {
user: ref.afterUser, task: todo, direction: 'up', times: 5, cron: false,
};
scoreTask(options);
expect(ref.afterUser.stats.hp).to.eql(50);
@@ -242,7 +262,9 @@ describe('shared.ops.scoreTask', () => {
context('habits', () => {
it('up', () => {
options = { user: ref.afterUser, task: habit, direction: 'up', times: 5, cron: false };
options = {
user: ref.afterUser, task: habit, direction: 'up', times: 5, cron: false,
};
scoreTask(options);
expect(habit.history.length).to.eql(1);
@@ -256,16 +278,20 @@ describe('shared.ops.scoreTask', () => {
// not supported anymore
it('does not add score notes to task', () => {
let scoreNotesString = 'scoreNotes';
const scoreNotesString = 'scoreNotes';
habit.scoreNotes = scoreNotesString;
options = { user: ref.afterUser, task: habit, direction: 'up', times: 5, cron: false };
options = {
user: ref.afterUser, task: habit, direction: 'up', times: 5, cron: false,
};
scoreTask(options);
expect(habit.history[0].scoreNotes).to.eql(undefined);
});
it('down', () => {
scoreTask({user: ref.afterUser, task: habit, direction: 'down', times: 5, cron: false}, {});
scoreTask({
user: ref.afterUser, task: habit, direction: 'down', times: 5, cron: false,
}, {});
expect(habit.history.length).to.eql(1);
expect(habit.value).to.be.lessThan(0);
@@ -280,16 +306,16 @@ describe('shared.ops.scoreTask', () => {
context('dailys', () => {
it('up', () => {
expect(daily.completed).to.not.eql(true);
scoreTask({user: ref.afterUser, task: daily, direction: 'up'});
scoreTask({ user: ref.afterUser, task: daily, direction: 'up' });
expectGainedPoints(ref.beforeUser, ref.afterUser, freshDaily, daily);
expect(daily.completed).to.eql(true);
expect(daily.history.length).to.eql(1);
});
it('up, down', () => {
scoreTask({user: ref.afterUser, task: daily, direction: 'up'});
scoreTask({ user: ref.afterUser, task: daily, direction: 'up' });
expect(daily.history.length).to.eql(1);
scoreTask({user: ref.afterUser, task: daily, direction: 'down'});
scoreTask({ user: ref.afterUser, task: daily, direction: 'down' });
expect(daily.history.length).to.eql(0);
expectClosePoints(ref.beforeUser, ref.afterUser, freshDaily, daily);
});
@@ -297,20 +323,20 @@ describe('shared.ops.scoreTask', () => {
it('sets completed = false on direction = down', () => {
daily.completed = true;
expect(daily.completed).to.not.eql(false);
scoreTask({user: ref.afterUser, task: daily, direction: 'down'});
scoreTask({ user: ref.afterUser, task: daily, direction: 'down' });
expect(daily.completed).to.eql(false);
});
});
context('todos', () => {
it('up', () => {
scoreTask({user: ref.afterUser, task: todo, direction: 'up'});
scoreTask({ user: ref.afterUser, task: todo, direction: 'up' });
expectGainedPoints(ref.beforeUser, ref.afterUser, freshTodo, todo);
});
it('up, down', () => {
scoreTask({user: ref.afterUser, task: todo, direction: 'up'});
scoreTask({user: ref.afterUser, task: todo, direction: 'down'});
scoreTask({ user: ref.afterUser, task: todo, direction: 'up' });
scoreTask({ user: ref.afterUser, task: todo, direction: 'down' });
expectClosePoints(ref.beforeUser, ref.afterUser, freshTodo, todo);
});
});
+24 -24
View File
@@ -12,16 +12,16 @@ import content from '../../../website/common/script/content/index';
describe('shared.ops.sell', () => {
let user;
let type = 'eggs';
let key = 'Wolf';
let acceptedTypes = ['eggs', 'hatchingPotions', 'food'];
const type = 'eggs';
const key = 'Wolf';
const acceptedTypes = ['eggs', 'hatchingPotions', 'food'];
beforeEach(() => {
user = generateUser();
user.items[type][key] = 1;
});
it('returns an error when type is not provided', (done) => {
it('returns an error when type is not provided', done => {
try {
sell(user);
} catch (err) {
@@ -31,9 +31,9 @@ describe('shared.ops.sell', () => {
}
});
it('returns an error when key is not provided', (done) => {
it('returns an error when key is not provided', done => {
try {
sell(user, {params: { type } });
sell(user, { params: { type } });
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('missingKeyParam'));
@@ -41,56 +41,56 @@ describe('shared.ops.sell', () => {
}
});
it('returns an error when non-sellable type is provided', (done) => {
let nonSellableType = 'nonSellableType';
it('returns an error when non-sellable type is provided', done => {
const nonSellableType = 'nonSellableType';
try {
sell(user, {params: { type: nonSellableType, key } });
sell(user, { params: { type: nonSellableType, key } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('typeNotSellable', {acceptedTypes: acceptedTypes.join(', ')}));
expect(err.message).to.equal(i18n.t('typeNotSellable', { acceptedTypes: acceptedTypes.join(', ') }));
done();
}
});
it('returns an error when key is not found with type provided', (done) => {
let fakeKey = 'fakeKey';
it('returns an error when key is not found with type provided', done => {
const fakeKey = 'fakeKey';
try {
sell(user, {params: { type, key: fakeKey } });
sell(user, { params: { type, key: fakeKey } });
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('userItemsKeyNotFound', {type}));
expect(err.message).to.equal(i18n.t('userItemsKeyNotFound', { type }));
done();
}
});
it('returns an error when the requested amount is above the available amount', (done) => {
it('returns an error when the requested amount is above the available amount', done => {
try {
sell(user, {params: { type, key }, query: {amount: 2} });
sell(user, { params: { type, key }, query: { amount: 2 } });
} catch (err) {
expect(err).to.be.an.instanceof(NotFound);
expect(err.message).to.equal(i18n.t('userItemsNotEnough', {type}));
expect(err.message).to.equal(i18n.t('userItemsNotEnough', { type }));
done();
}
});
it('returns an error when the requested amount is negative', (done) => {
it('returns an error when the requested amount is negative', done => {
try {
sell(user, {params: { type, key }, query: {amount: -42} });
sell(user, { params: { type, key }, query: { amount: -42 } });
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(i18n.t('positiveAmountRequired', {type}));
expect(err.message).to.equal(i18n.t('positiveAmountRequired', { type }));
done();
}
});
it('returns error when trying to sell Saddle', (done) => {
it('returns error when trying to sell Saddle', done => {
const foodType = 'food';
const saddleKey = 'Saddle';
user.items[foodType][saddleKey] = 1;
try {
sell(user, {params: {type: foodType, key: saddleKey}});
sell(user, { params: { type: foodType, key: saddleKey } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('foodSaddleSellWarningNote'));
@@ -99,13 +99,13 @@ describe('shared.ops.sell', () => {
});
it('reduces item count from user', () => {
sell(user, {params: { type, key } });
sell(user, { params: { type, key } });
expect(user.items[type][key]).to.equal(0);
});
it('increases user\'s gold', () => {
sell(user, {params: { type, key } });
sell(user, { params: { type, key } });
expect(user.stats.gp).to.equal(content[type][key].value);
});
+3 -3
View File
@@ -5,13 +5,13 @@ import {
describe('shared.ops.sleep', () => {
it('toggles user.preferences.sleep', () => {
let user = generateUser();
const user = generateUser();
let [res] = sleep(user);
const [res] = sleep(user);
expect(res).to.eql(true);
expect(user.preferences.sleep).to.equal(true);
let [res2] = sleep(user);
const [res2] = sleep(user);
expect(res2).to.eql(false);
expect(user.preferences.sleep).to.equal(false);
});
+3 -3
View File
@@ -16,13 +16,13 @@ describe('shared.ops.spells', () => {
user = generateUser();
});
it('returns an error when healer tries to cast Healing Light with full health', (done) => {
it('returns an error when healer tries to cast Healing Light with full health', done => {
user.stats.class = 'healer';
user.stats.lvl = 11;
user.stats.hp = 50;
user.stats.mp = 200;
let spell = spells.healer.heal;
const spell = spells.healer.heal;
try {
spell.cast(user);
@@ -35,4 +35,4 @@ describe('shared.ops.spells', () => {
done();
}
});
});
});
+9 -9
View File
@@ -20,19 +20,19 @@ describe('shared.ops.allocate', () => {
});
});
it('throws an error if an invalid attribute is supplied', (done) => {
it('throws an error if an invalid attribute is supplied', done => {
try {
allocate(user, {
query: {stat: 'notValid'},
query: { stat: 'notValid' },
});
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(errorMessage('invalidAttribute', {attr: 'notValid'}));
expect(err.message).to.equal(errorMessage('invalidAttribute', { attr: 'notValid' }));
done();
}
});
it('throws an error if the user is below lvl 10', (done) => {
it('throws an error if the user is below lvl 10', done => {
user.stats.lvl = 9;
try {
allocate(user);
@@ -43,7 +43,7 @@ describe('shared.ops.allocate', () => {
}
});
it('throws an error if the user hasn\'t selected class', (done) => {
it('throws an error if the user hasn\'t selected class', done => {
user.flags.classSelected = false;
try {
allocate(user);
@@ -54,7 +54,7 @@ describe('shared.ops.allocate', () => {
}
});
it('throws an error if the user has disabled classes', (done) => {
it('throws an error if the user has disabled classes', done => {
user.preferences.disableClasses = true;
try {
allocate(user);
@@ -65,7 +65,7 @@ describe('shared.ops.allocate', () => {
}
});
it('throws an error if the user doesn\'t have attribute points', (done) => {
it('throws an error if the user doesn\'t have attribute points', done => {
try {
allocate(user);
} catch (err) {
@@ -85,7 +85,7 @@ describe('shared.ops.allocate', () => {
it('allocates attribute points', () => {
expect(user.stats.con).to.equal(0);
user.stats.points = 1;
allocate(user, {query: {stat: 'con'}});
allocate(user, { query: { stat: 'con' } });
expect(user.stats.con).to.equal(1);
expect(user.stats.points).to.equal(0);
});
@@ -94,7 +94,7 @@ describe('shared.ops.allocate', () => {
expect(user.stats.int).to.equal(0);
expect(user.stats.mp).to.equal(10);
user.stats.points = 1;
allocate(user, {query: {stat: 'int'}});
allocate(user, { query: { stat: 'int' } });
expect(user.stats.int).to.equal(1);
expect(user.stats.mp).to.equal(11);
});
+8 -8
View File
@@ -20,7 +20,7 @@ describe('shared.ops.allocateBulk', () => {
});
});
it('throws an error if an invalid attribute is supplied', (done) => {
it('throws an error if an invalid attribute is supplied', done => {
try {
allocateBulk(user, {
body: {
@@ -32,12 +32,12 @@ describe('shared.ops.allocateBulk', () => {
});
} catch (err) {
expect(err).to.be.an.instanceof(BadRequest);
expect(err.message).to.equal(errorMessage('invalidAttribute', {attr: 'invalid'}));
expect(err.message).to.equal(errorMessage('invalidAttribute', { attr: 'invalid' }));
done();
}
});
it('throws an error if the stats are not supplied', (done) => {
it('throws an error if the stats are not supplied', done => {
try {
allocateBulk(user);
} catch (err) {
@@ -47,7 +47,7 @@ describe('shared.ops.allocateBulk', () => {
}
});
it('throws an error if the user is below lvl 10', (done) => {
it('throws an error if the user is below lvl 10', done => {
user.stats.lvl = 9;
try {
allocateBulk(user, {
@@ -65,7 +65,7 @@ describe('shared.ops.allocateBulk', () => {
}
});
it('throws an error if the user hasn\'t selected class', (done) => {
it('throws an error if the user hasn\'t selected class', done => {
user.flags.classSelected = false;
try {
allocateBulk(user, {
@@ -83,7 +83,7 @@ describe('shared.ops.allocateBulk', () => {
}
});
it('throws an error if the user has disabled classes', (done) => {
it('throws an error if the user has disabled classes', done => {
user.preferences.disableClasses = true;
try {
allocateBulk(user, {
@@ -101,7 +101,7 @@ describe('shared.ops.allocateBulk', () => {
}
});
it('throws an error if the user doesn\'t have attribute points', (done) => {
it('throws an error if the user doesn\'t have attribute points', done => {
try {
allocateBulk(user, {
body: {
@@ -118,7 +118,7 @@ describe('shared.ops.allocateBulk', () => {
}
});
it('throws an error if the user doesn\'t have enough attribute points', (done) => {
it('throws an error if the user doesn\'t have enough attribute points', done => {
user.stats.points = 1;
try {
allocateBulk(user, {
+1 -1
View File
@@ -18,7 +18,7 @@ describe('shared.ops.allocateNow', () => {
user.stats.str = 9;
user.preferences.allocationMode = 'flat';
let [data] = allocateNow(user);
const [data] = allocateNow(user);
expect(user.stats.points).to.equal(0);
expect(user.stats.con).to.equal(9);
+25 -25
View File
@@ -10,18 +10,18 @@ import {
describe('shared.ops.unlock', () => {
let user;
let unlockPath = 'shirt.convict,shirt.cross,shirt.fire,shirt.horizon,shirt.ocean,shirt.purple,shirt.rainbow,shirt.redblue,shirt.thunder,shirt.tropical,shirt.zombie';
let unlockGearSetPath = 'items.gear.owned.headAccessory_special_bearEars,items.gear.owned.headAccessory_special_cactusEars,items.gear.owned.headAccessory_special_foxEars,items.gear.owned.headAccessory_special_lionEars,items.gear.owned.headAccessory_special_pandaEars,items.gear.owned.headAccessory_special_pigEars,items.gear.owned.headAccessory_special_tigerEars,items.gear.owned.headAccessory_special_wolfEars';
let backgroundUnlockPath = 'background.giant_florals';
let unlockCost = 1.25;
let usersStartingGems = 5;
const unlockPath = 'shirt.convict,shirt.cross,shirt.fire,shirt.horizon,shirt.ocean,shirt.purple,shirt.rainbow,shirt.redblue,shirt.thunder,shirt.tropical,shirt.zombie';
const unlockGearSetPath = 'items.gear.owned.headAccessory_special_bearEars,items.gear.owned.headAccessory_special_cactusEars,items.gear.owned.headAccessory_special_foxEars,items.gear.owned.headAccessory_special_lionEars,items.gear.owned.headAccessory_special_pandaEars,items.gear.owned.headAccessory_special_pigEars,items.gear.owned.headAccessory_special_tigerEars,items.gear.owned.headAccessory_special_wolfEars';
const backgroundUnlockPath = 'background.giant_florals';
const unlockCost = 1.25;
const usersStartingGems = 5;
beforeEach(() => {
user = generateUser();
user.balance = usersStartingGems;
});
it('returns an error when path is not provided', (done) => {
it('returns an error when path is not provided', done => {
try {
unlock(user);
} catch (err) {
@@ -31,11 +31,11 @@ describe('shared.ops.unlock', () => {
}
});
it('returns an error when user balance is too low', (done) => {
it('returns an error when user balance is too low', done => {
user.balance = 0;
try {
unlock(user, {query: {path: unlockPath}});
unlock(user, { query: { path: unlockPath } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('notEnoughGems'));
@@ -43,10 +43,10 @@ describe('shared.ops.unlock', () => {
}
});
it('returns an error when user already owns a full set', (done) => {
it('returns an error when user already owns a full set', done => {
try {
unlock(user, {query: {path: unlockPath}});
unlock(user, {query: {path: unlockPath}});
unlock(user, { query: { path: unlockPath } });
unlock(user, { query: { path: unlockPath } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('alreadyUnlocked'));
@@ -55,10 +55,10 @@ describe('shared.ops.unlock', () => {
});
// disabled untill fully implemente
xit('returns an error when user already owns items in a full set', (done) => {
xit('returns an error when user already owns items in a full set', done => {
try {
unlock(user, {query: {path: unlockPath}});
unlock(user, {query: {path: unlockPath}});
unlock(user, { query: { path: unlockPath } });
unlock(user, { query: { path: unlockPath } });
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('alreadyUnlocked'));
@@ -69,9 +69,9 @@ describe('shared.ops.unlock', () => {
it('equips an item already owned', () => {
expect(user.purchased.background.giant_florals).to.not.exist;
unlock(user, {query: {path: backgroundUnlockPath}});
let afterBalance = user.balance;
let response = unlock(user, {query: {path: backgroundUnlockPath}});
unlock(user, { query: { path: backgroundUnlockPath } });
const afterBalance = user.balance;
const response = unlock(user, { query: { path: backgroundUnlockPath } });
expect(user.balance).to.equal(afterBalance); // do not bill twice
expect(response.message).to.not.exist;
@@ -81,10 +81,10 @@ describe('shared.ops.unlock', () => {
it('un-equips an item already equipped', () => {
expect(user.purchased.background.giant_florals).to.not.exist;
unlock(user, {query: {path: backgroundUnlockPath}}); // unlock
let afterBalance = user.balance;
unlock(user, {query: {path: backgroundUnlockPath}}); // equip
let response = unlock(user, {query: {path: backgroundUnlockPath}});
unlock(user, { query: { path: backgroundUnlockPath } }); // unlock
const afterBalance = user.balance;
unlock(user, { query: { path: backgroundUnlockPath } }); // equip
const response = unlock(user, { query: { path: backgroundUnlockPath } });
expect(user.balance).to.equal(afterBalance); // do not bill twice
expect(response.message).to.not.exist;
@@ -92,28 +92,28 @@ describe('shared.ops.unlock', () => {
});
it('unlocks a full set', () => {
let [, message] = unlock(user, {query: {path: unlockPath}});
const [, message] = unlock(user, { query: { path: unlockPath } });
expect(message).to.equal(i18n.t('unlocked'));
expect(user.purchased.shirt.convict).to.be.true;
});
it('unlocks a full set of gear', () => {
let [, message] = unlock(user, {query: {path: unlockGearSetPath}});
const [, message] = unlock(user, { query: { path: unlockGearSetPath } });
expect(message).to.equal(i18n.t('unlocked'));
expect(user.items.gear.owned.headAccessory_special_wolfEars).to.be.true;
});
it('unlocks a an item', () => {
let [, message] = unlock(user, {query: {path: backgroundUnlockPath}});
const [, message] = unlock(user, { query: { path: backgroundUnlockPath } });
expect(message).to.equal(i18n.t('unlocked'));
expect(user.purchased.background.giant_florals).to.be.true;
});
it('reduces a user\'s balance', () => {
let [, message] = unlock(user, {query: {path: unlockPath}});
const [, message] = unlock(user, { query: { path: unlockPath } });
expect(message).to.equal(i18n.t('unlocked'));
expect(user.balance).to.equal(usersStartingGems - unlockCost);
+3 -3
View File
@@ -5,8 +5,8 @@ import {
describe('shared.ops.updateTask', () => {
it('updates a task', () => {
let now = new Date();
let habit = generateHabit({
const now = new Date();
const habit = generateHabit({
tags: [
'123',
'456',
@@ -19,7 +19,7 @@ describe('shared.ops.updateTask', () => {
}],
});
let [res] = updateTask(habit, {
const [res] = updateTask(habit, {
body: {
text: 'updated',
id: '123',
+51 -45
View File
@@ -1,9 +1,10 @@
import { shouldDo, DAY_MAPPING } from '../../website/common/script/cron';
import moment from 'moment';
import { shouldDo, DAY_MAPPING } from '../../website/common/script/cron';
import 'moment-recur';
describe('shouldDo', () => {
let day, dailyTask;
let day; let
dailyTask;
let options = {};
let nextDue = [];
@@ -29,9 +30,9 @@ describe('shouldDo', () => {
});
it('returns false if task type is not a daily', () => {
expect(shouldDo(day, {type: 'todo'})).to.equal(false);
expect(shouldDo(day, {type: 'habit'})).to.equal(false);
expect(shouldDo(day, {type: 'reward'})).to.equal(false);
expect(shouldDo(day, { type: 'todo' })).to.equal(false);
expect(shouldDo(day, { type: 'habit' })).to.equal(false);
expect(shouldDo(day, { type: 'reward' })).to.equal(false);
});
it('returns false if startDate is in the future', () => {
@@ -51,12 +52,12 @@ describe('shouldDo', () => {
expect(shouldDo(day, dailyTask, options)).to.equal(true);
});
it('returns true if Start Date is today', () => {
it('returns true if Start Date is today', () => {
dailyTask.startDate = moment().toDate();
expect(shouldDo(day, dailyTask, options)).to.equal(true);
});
it('returns false if Start Date is after today', () => {
it('returns false if Start Date is after today', () => {
dailyTask.startDate = moment().add(1, 'days').toDate();
expect(shouldDo(day, dailyTask, options)).to.equal(false);
});
@@ -79,14 +80,16 @@ describe('shouldDo', () => {
it('returns true if the user\'s current time is after start date and Custom Day Start', () => {
options.dayStart = 4;
day = moment().zone(options.timezoneOffset).startOf('day').add(6, 'hours').toDate();
day = moment().zone(options.timezoneOffset).startOf('day').add(6, 'hours')
.toDate();
dailyTask.startDate = moment().zone(options.timezoneOffset).startOf('day').toDate();
expect(shouldDo(day, dailyTask, options)).to.equal(true);
});
it('returns false if the user\'s current time is before Custom Day Start', () => {
options.dayStart = 8;
day = moment().zone(options.timezoneOffset).startOf('day').add(2, 'hours').toDate();
day = moment().zone(options.timezoneOffset).startOf('day').add(2, 'hours')
.toDate();
dailyTask.startDate = moment().zone(options.timezoneOffset).startOf('day').toDate();
expect(shouldDo(day, dailyTask, options)).to.equal(false);
});
@@ -102,20 +105,22 @@ describe('shouldDo', () => {
expect(shouldDo(day, dailyTask, options)).to.equal(true);
});
it('returns true if Start Date is today', () => {
it('returns true if Start Date is today', () => {
dailyTask.startDate = moment().startOf('day').toDate();
expect(shouldDo(day, dailyTask, options)).to.equal(true);
});
it('returns true if the user\'s current time is after Custom Day Start', () => {
options.dayStart = 4;
day = moment().zone(options.timezoneOffset).startOf('day').add(6, 'hours').toDate();
day = moment().zone(options.timezoneOffset).startOf('day').add(6, 'hours')
.toDate();
expect(shouldDo(day, dailyTask, options)).to.equal(true);
});
it('returns false if the user\'s current time is before Custom Day Start', () => {
options.dayStart = 8;
day = moment().zone(options.timezoneOffset).startOf('day').add(2, 'hours').toDate();
day = moment().zone(options.timezoneOffset).startOf('day').add(2, 'hours')
.toDate();
expect(shouldDo(day, dailyTask, options)).to.equal(false);
});
});
@@ -335,11 +340,11 @@ describe('shouldDo', () => {
m: false,
};
for (let weekday of [0, 1, 2, 3, 4, 5, 6]) {
[0, 1, 2, 3, 4, 5, 6].forEach(weekday => {
day = moment().day(weekday).toDate();
expect(shouldDo(day, dailyTask, options)).to.equal(false);
}
});
});
it('returns false and ignore malformed repeat object', () => {
@@ -354,11 +359,11 @@ describe('shouldDo', () => {
errors: 'errors',
};
for (let weekday of [0, 1, 2, 3, 4, 5, 6]) {
[0, 1, 2, 3, 4, 5, 6].forEach(weekday => {
day = moment().day(weekday).toDate();
expect(shouldDo(day, dailyTask, options)).to.equal(false);
}
});
});
it('returns false if day of the week does not match and active on the day it matches', () => {
@@ -372,7 +377,8 @@ describe('shouldDo', () => {
m: false,
};
for (let weekday of [0, 1, 2, 3, 4, 5, 6]) {
[0, 1, 2, 3, 4, 5, 6].forEach(weekday => {
day = moment().add(1, 'weeks').day(weekday).toDate();
if (weekday === 4) {
@@ -380,7 +386,7 @@ describe('shouldDo', () => {
} else {
expect(shouldDo(day, dailyTask, options)).to.equal(false);
}
}
});
});
it('returns true if Daily on matching days of the week', () => {
@@ -599,7 +605,7 @@ describe('shouldDo', () => {
day = moment();
dailyTask.repeat[DAY_MAPPING[day.day()]] = true;
dailyTask.everyX = 3;
let tomorrow = day.add(2, 'weeks').day(day.day()).toDate();
const tomorrow = day.add(2, 'weeks').day(day.day()).toDate();
expect(shouldDo(tomorrow, dailyTask, options)).to.equal(false);
});
@@ -618,14 +624,14 @@ describe('shouldDo', () => {
day = moment();
dailyTask.repeat[DAY_MAPPING[day.day()]] = true;
dailyTask.everyX = 3;
let threeWeeksFromTodayPlusOne = day.add(1, 'day').add(3, 'weeks').toDate();
const threeWeeksFromTodayPlusOne = day.add(1, 'day').add(3, 'weeks').toDate();
expect(shouldDo(threeWeeksFromTodayPlusOne, dailyTask, options)).to.equal(false);
});
it('activates Daily on matching week', () => {
dailyTask.everyX = 3;
let threeWeeksFromToday = moment().add(3, 'weeks').toDate();
const threeWeeksFromToday = moment().add(3, 'weeks').toDate();
expect(shouldDo(threeWeeksFromToday, dailyTask, options)).to.equal(true);
});
@@ -733,9 +739,9 @@ describe('shouldDo', () => {
it('leaves daily inactive if not day of the month', () => {
dailyTask.everyX = 1;
dailyTask.frequency = 'monthly';
let today = moment();
const today = moment();
dailyTask.daysOfMonth = [today.date()];
let tomorrow = today.add(1, 'day').toDate();
const tomorrow = today.add(1, 'day').toDate();
expect(shouldDo(tomorrow, dailyTask, options)).to.equal(false);
});
@@ -753,9 +759,9 @@ describe('shouldDo', () => {
it('leaves daily inactive if not on date of the x month', () => {
dailyTask.everyX = 2;
dailyTask.frequency = 'monthly';
let today = moment();
const today = moment();
dailyTask.daysOfMonth = [today.date()];
let tomorrow = today.add(2, 'months').add(1, 'day').toDate();
const tomorrow = today.add(2, 'months').add(1, 'day').toDate();
expect(shouldDo(tomorrow, dailyTask, options)).to.equal(false);
});
@@ -920,9 +926,9 @@ describe('shouldDo', () => {
m: false,
};
let today = moment('2017-01-27');
let week = today.monthWeek();
let dayOfWeek = today.day();
const today = moment('2017-01-27');
const week = today.monthWeek();
const dayOfWeek = today.day();
dailyTask.startDate = today.toDate();
dailyTask.weeksOfMonth = [week];
dailyTask.repeat[DAY_MAPPING[dayOfWeek]] = true;
@@ -944,8 +950,8 @@ describe('shouldDo', () => {
m: false,
};
let today = moment('2017-05-27T17:34:40.000Z');
let week = today.monthWeek();
const today = moment('2017-05-27T17:34:40.000Z');
const week = today.monthWeek();
dailyTask.startDate = today.toDate();
dailyTask.weeksOfMonth = [week];
dailyTask.everyX = 1;
@@ -966,9 +972,9 @@ describe('shouldDo', () => {
m: false,
};
let today = moment('2017-01-27:00:00.000-00:00');
let week = today.monthWeek();
let dayOfWeek = today.day();
const today = moment('2017-01-27:00:00.000-00:00');
const week = today.monthWeek();
const dayOfWeek = today.day();
dailyTask.startDate = today.toDate();
dailyTask.weeksOfMonth = [week];
dailyTask.repeat[DAY_MAPPING[dayOfWeek]] = true;
@@ -990,9 +996,9 @@ describe('shouldDo', () => {
m: false,
};
let today = moment('2017-01-26:00:00.000-00:00');
let week = today.monthWeek();
let dayOfWeek = today.day();
const today = moment('2017-01-26:00:00.000-00:00');
const week = today.monthWeek();
const dayOfWeek = today.day();
dailyTask.startDate = today.toDate();
dailyTask.weeksOfMonth = [week];
dailyTask.repeat[DAY_MAPPING[dayOfWeek]] = true;
@@ -1015,9 +1021,9 @@ describe('shouldDo', () => {
m: false,
};
let today = moment('2017-01-27:00:00.000-00:00');
let week = today.monthWeek();
let dayOfWeek = today.day();
const today = moment('2017-01-27:00:00.000-00:00');
const week = today.monthWeek();
const dayOfWeek = today.day();
dailyTask.startDate = today.toDate();
dailyTask.weeksOfMonth = [week];
dailyTask.repeat[DAY_MAPPING[dayOfWeek]] = true;
@@ -1040,9 +1046,9 @@ describe('shouldDo', () => {
m: false,
};
let today = moment('2017-01-27:00:00.000-00:00');
let week = today.monthWeek();
let dayOfWeek = today.day();
const today = moment('2017-01-27:00:00.000-00:00');
const week = today.monthWeek();
const dayOfWeek = today.day();
dailyTask.startDate = today.toDate();
dailyTask.weeksOfMonth = [week];
dailyTask.repeat[DAY_MAPPING[dayOfWeek]] = true;
@@ -1066,9 +1072,9 @@ describe('shouldDo', () => {
m: false,
};
let today = moment('2017-01-27');
let week = today.monthWeek();
let dayOfWeek = today.day();
const today = moment('2017-01-27');
const week = today.monthWeek();
const dayOfWeek = today.day();
dailyTask.startDate = today.toDate();
dailyTask.weeksOfMonth = [week];
dailyTask.repeat[DAY_MAPPING[dayOfWeek]] = true;
+3 -2
View File
@@ -42,7 +42,7 @@ describe('helper functions used in stat calculations', () => {
describe('toNextLevel', () => {
it('increases Experience target from one level to the next', () => {
_.times(110, (level) => {
_.times(110, level => {
expect(tnl(level + 1)).to.be.greaterThan(tnl(level));
});
});
@@ -62,7 +62,8 @@ describe('helper functions used in stat calculations', () => {
});
it('provides a different curve if a halfway point is defined', () => {
expect(diminishingReturns(BONUS, MAXIMUM, HALFWAY)).to.not.eql(diminishingReturns(BONUS, MAXIMUM));
expect(diminishingReturns(BONUS, MAXIMUM, HALFWAY))
.to.not.eql(diminishingReturns(BONUS, MAXIMUM));
});
});
});
+12 -44
View File
@@ -1,59 +1,27 @@
/* eslint-disable prefer-template, no-shadow, func-names */
let expect = require('expect.js');
const expect = require('expect.js');
module.exports.addCustomMatchers = function () {
let Assertion;
Assertion = expect.Assertion;
const { Assertion } = expect;
Assertion.prototype.toHaveGP = function (gp) {
let actual;
actual = this.obj.stats.gp;
return this.assert(actual === gp, () => {
return 'expected user to have ' + gp + ' gp, but got ' + actual;
}, () => {
return 'expected user to not have ' + gp + ' gp';
});
const actual = this.obj.stats.gp;
return this.assert(actual === gp, () => 'expected user to have ' + gp + ' gp, but got ' + actual, () => 'expected user to not have ' + gp + ' gp');
};
Assertion.prototype.toHaveHP = function (hp) {
let actual;
actual = this.obj.stats.hp;
return this.assert(actual === hp, () => {
return 'expected user to have ' + hp + ' hp, but got ' + actual;
}, () => {
return 'expected user to not have ' + hp + ' hp';
});
const actual = this.obj.stats.hp;
return this.assert(actual === hp, () => 'expected user to have ' + hp + ' hp, but got ' + actual, () => 'expected user to not have ' + hp + ' hp');
};
Assertion.prototype.toHaveExp = function (exp) {
let actual;
actual = this.obj.stats.exp;
return this.assert(actual === exp, () => {
return 'expected user to have ' + exp + ' experience points, but got ' + actual;
}, () => {
return 'expected user to not have ' + exp + ' experience points';
});
const actual = this.obj.stats.exp;
return this.assert(actual === exp, () => 'expected user to have ' + exp + ' experience points, but got ' + actual, () => 'expected user to not have ' + exp + ' experience points');
};
Assertion.prototype.toHaveLevel = function (lvl) {
let actual;
actual = this.obj.stats.lvl;
return this.assert(actual === lvl, () => {
return 'expected user to be level ' + lvl + ', but got ' + actual;
}, () => {
return 'expected user to not be level ' + lvl;
});
const actual = this.obj.stats.lvl;
return this.assert(actual === lvl, () => 'expected user to be level ' + lvl + ', but got ' + actual, () => 'expected user to not be level ' + lvl);
};
Assertion.prototype.toHaveMaxMP = function (mp) {
let actual;
actual = this.obj._statsComputed.maxMP;
return this.assert(actual === mp, () => {
return 'expected user to have ' + mp + ' max mp, but got ' + actual;
}, () => {
return 'expected user to not have ' + mp + ' max mp';
});
const actual = this.obj._statsComputed.maxMP;
return this.assert(actual === mp, () => 'expected user to have ' + mp + ' max mp, but got ' + actual, () => 'expected user to not have ' + mp + ' max mp');
};
};