tests: Use dependency injection to re-enable randomdrop tests

This commit is contained in:
Blade Barringer
2016-06-02 12:57:59 -05:00
parent c33b7273fa
commit c9d8c3ee40
2 changed files with 18 additions and 22 deletions

View File

@@ -3,7 +3,7 @@ import content from '../content/index';
import i18n from '../i18n'; import i18n from '../i18n';
import { daysSince } from '../cron'; import { daysSince } from '../cron';
import { diminishingReturns } from '../statHelpers'; import { diminishingReturns } from '../statHelpers';
import predictableRandom from './predictableRandom'; import _predictableRandom from './predictableRandom';
import randomVal from './randomVal'; import randomVal from './randomVal';
// Clone a drop object maintaining its functions so that we can change it without affecting the original item // Clone a drop object maintaining its functions so that we can change it without affecting the original item
@@ -13,7 +13,7 @@ function cloneDropItem (drop) {
}); });
} }
module.exports = function randomDrop (user, modifiers, req = {}) { module.exports = function randomDrop (user, options, req = {}) {
let acceptableDrops; let acceptableDrops;
let chance; let chance;
let drop; let drop;
@@ -23,7 +23,8 @@ module.exports = function randomDrop (user, modifiers, req = {}) {
let rarity; let rarity;
let task; let task;
task = modifiers.task; let predictableRandom = options.predictableRandom || _predictableRandom;
task = options.task;
chance = _.min([Math.abs(task.value - 21.27), 37.5]) / 150 + 0.02; chance = _.min([Math.abs(task.value - 21.27), 37.5]) / 150 + 0.02;
chance *= task.priority * // Task priority: +50% for Medium, +100% for Hard chance *= task.priority * // Task priority: +50% for Medium, +100% for Hard

View File

@@ -1,7 +1,3 @@
// TODO disable until we can find a way to stub predictableRandom
/* eslint-disable */
import randomDrop from '../../../common/script/fns/randomDrop'; import randomDrop from '../../../common/script/fns/randomDrop';
import { import {
generateUser, generateUser,
@@ -10,10 +6,9 @@ import {
generateDaily, generateDaily,
generateReward, generateReward,
} from '../../helpers/common.helper'; } from '../../helpers/common.helper';
// import predictableRandom from '../../../common/script/fns/predictableRandom'; // eslint-disable
import content from '../../../common/script/content/index'; import content from '../../../common/script/content/index';
xdescribe('common.fns.randomDrop', () => { describe('common.fns.randomDrop', () => {
let user; let user;
let task; let task;
let predictableRandom; let predictableRandom;
@@ -40,9 +35,9 @@ xdescribe('common.fns.randomDrop', () => {
predictableRandom = () => { predictableRandom = () => {
return 0.0001; return 0.0001;
}; };
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user.party.quest.progress.collect[collectWhat]).to.eql(1); expect(user.party.quest.progress.collect[collectWhat]).to.eql(1);
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user.party.quest.progress.collect[collectWhat]).to.eql(2); expect(user.party.quest.progress.collect[collectWhat]).to.eql(2);
}); });
@@ -54,7 +49,7 @@ xdescribe('common.fns.randomDrop', () => {
it('does nothing if user.items.lastDrop.count is exceeded', () => { it('does nothing if user.items.lastDrop.count is exceeded', () => {
user.items.lastDrop.count = 100; user.items.lastDrop.count = 100;
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user._tmp).to.eql({}); expect(user._tmp).to.eql({});
}); });
@@ -64,7 +59,7 @@ xdescribe('common.fns.randomDrop', () => {
predictableRandom = () => { predictableRandom = () => {
return 0.1; return 0.1;
}; };
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user._tmp).to.not.eql({}); expect(user._tmp).to.not.eql({});
}); });
@@ -75,7 +70,7 @@ xdescribe('common.fns.randomDrop', () => {
predictableRandom = () => { predictableRandom = () => {
return 0.1; return 0.1;
}; };
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user._tmp).to.not.eql({}); expect(user._tmp).to.not.eql({});
}); });
@@ -86,7 +81,7 @@ xdescribe('common.fns.randomDrop', () => {
predictableRandom = () => { predictableRandom = () => {
return 0.1; return 0.1;
}; };
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user._tmp).to.not.eql({}); expect(user._tmp).to.not.eql({});
}); });
@@ -97,7 +92,7 @@ xdescribe('common.fns.randomDrop', () => {
predictableRandom = () => { predictableRandom = () => {
return 0.1; return 0.1;
}; };
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user._tmp).to.not.eql({}); expect(user._tmp).to.not.eql({});
}); });
@@ -105,7 +100,7 @@ xdescribe('common.fns.randomDrop', () => {
predictableRandom = () => { predictableRandom = () => {
return 0.65; return 0.65;
}; };
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user._tmp.drop.type).to.eql('Food'); expect(user._tmp.drop.type).to.eql('Food');
}); });
@@ -113,7 +108,7 @@ xdescribe('common.fns.randomDrop', () => {
predictableRandom = () => { predictableRandom = () => {
return 0.35; return 0.35;
}; };
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user._tmp.drop.type).to.eql('Egg'); expect(user._tmp.drop.type).to.eql('Egg');
}); });
@@ -122,7 +117,7 @@ xdescribe('common.fns.randomDrop', () => {
predictableRandom = () => { predictableRandom = () => {
return 0.01; return 0.01;
}; };
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user._tmp.drop.type).to.eql('HatchingPotion'); expect(user._tmp.drop.type).to.eql('HatchingPotion');
expect(user._tmp.drop.value).to.eql(5); expect(user._tmp.drop.value).to.eql(5);
expect(user._tmp.drop.key).to.eql('Golden'); expect(user._tmp.drop.key).to.eql('Golden');
@@ -132,7 +127,7 @@ xdescribe('common.fns.randomDrop', () => {
predictableRandom = () => { predictableRandom = () => {
return 0.08; return 0.08;
}; };
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user._tmp.drop.type).to.eql('HatchingPotion'); expect(user._tmp.drop.type).to.eql('HatchingPotion');
expect(user._tmp.drop.value).to.eql(4); expect(user._tmp.drop.value).to.eql(4);
let acceptableDrops = ['Zombie', 'CottonCandyPink', 'CottonCandyBlue']; let acceptableDrops = ['Zombie', 'CottonCandyPink', 'CottonCandyBlue'];
@@ -143,7 +138,7 @@ xdescribe('common.fns.randomDrop', () => {
predictableRandom = () => { predictableRandom = () => {
return 0.17; return 0.17;
}; };
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user._tmp.drop.type).to.eql('HatchingPotion'); expect(user._tmp.drop.type).to.eql('HatchingPotion');
expect(user._tmp.drop.value).to.eql(3); expect(user._tmp.drop.value).to.eql(3);
let acceptableDrops = ['Red', 'Shade', 'Skeleton']; let acceptableDrops = ['Red', 'Shade', 'Skeleton'];
@@ -154,7 +149,7 @@ xdescribe('common.fns.randomDrop', () => {
predictableRandom = () => { predictableRandom = () => {
return 0.20; return 0.20;
}; };
randomDrop(user, { task }); randomDrop(user, { task, predictableRandom });
expect(user._tmp.drop.type).to.eql('HatchingPotion'); expect(user._tmp.drop.type).to.eql('HatchingPotion');
expect(user._tmp.drop.value).to.eql(2); expect(user._tmp.drop.value).to.eql(2);
let acceptableDrops = ['Base', 'White', 'Desert']; let acceptableDrops = ['Base', 'White', 'Desert'];