mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
Re-enable armoire tests
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
} from '../../helpers/common.helper';
|
} from '../../helpers/common.helper';
|
||||||
import count from '../../../website/common/script/count';
|
import count from '../../../website/common/script/count';
|
||||||
import buyArmoire from '../../../website/common/script/ops/buyArmoire';
|
import buyArmoire from '../../../website/common/script/ops/buyArmoire';
|
||||||
|
import randomVal from '../../../website/common/script/libs/randomVal';
|
||||||
import content from '../../../website/common/script/content/index';
|
import content from '../../../website/common/script/content/index';
|
||||||
import {
|
import {
|
||||||
NotAuthorized,
|
NotAuthorized,
|
||||||
@@ -25,7 +26,7 @@ function getFullArmoire () {
|
|||||||
return fullArmoire;
|
return fullArmoire;
|
||||||
}
|
}
|
||||||
|
|
||||||
xdescribe('shared.ops.buyArmoire', () => {
|
describe('shared.ops.buyArmoire', () => {
|
||||||
let user;
|
let user;
|
||||||
let YIELD_EQUIPMENT = 0.5;
|
let YIELD_EQUIPMENT = 0.5;
|
||||||
let YIELD_FOOD = 0.7;
|
let YIELD_FOOD = 0.7;
|
||||||
@@ -43,11 +44,11 @@ xdescribe('shared.ops.buyArmoire', () => {
|
|||||||
user.stats.exp = 0;
|
user.stats.exp = 0;
|
||||||
user.items.food = {};
|
user.items.food = {};
|
||||||
|
|
||||||
sandbox.stub(Math, 'random');
|
sandbox.stub(randomVal, 'trueRandom');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
Math.random.restore();
|
randomVal.trueRandom.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
context('failure conditions', () => {
|
context('failure conditions', () => {
|
||||||
@@ -89,7 +90,7 @@ xdescribe('shared.ops.buyArmoire', () => {
|
|||||||
context('non-gear awards', () => {
|
context('non-gear awards', () => {
|
||||||
it('gives Experience', () => {
|
it('gives Experience', () => {
|
||||||
let previousExp = user.stats.exp;
|
let previousExp = user.stats.exp;
|
||||||
Math.random.returns(YIELD_EXP);
|
randomVal.trueRandom.returns(YIELD_EXP);
|
||||||
|
|
||||||
buyArmoire(user);
|
buyArmoire(user);
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ xdescribe('shared.ops.buyArmoire', () => {
|
|||||||
it('gives food', () => {
|
it('gives food', () => {
|
||||||
let previousExp = user.stats.exp;
|
let previousExp = user.stats.exp;
|
||||||
|
|
||||||
Math.random.returns(YIELD_FOOD);
|
randomVal.trueRandom.returns(YIELD_FOOD);
|
||||||
|
|
||||||
buyArmoire(user);
|
buyArmoire(user);
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ xdescribe('shared.ops.buyArmoire', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not give equipment if all equipment has been found', () => {
|
it('does not give equipment if all equipment has been found', () => {
|
||||||
Math.random.returns(YIELD_EQUIPMENT);
|
randomVal.trueRandom.returns(YIELD_EQUIPMENT);
|
||||||
user.items.gear.owned = getFullArmoire();
|
user.items.gear.owned = getFullArmoire();
|
||||||
user.stats.gp = 150;
|
user.stats.gp = 150;
|
||||||
|
|
||||||
@@ -131,7 +132,7 @@ xdescribe('shared.ops.buyArmoire', () => {
|
|||||||
context('gear awards', () => {
|
context('gear awards', () => {
|
||||||
it('always drops equipment the first time', () => {
|
it('always drops equipment the first time', () => {
|
||||||
delete user.flags.armoireOpened;
|
delete user.flags.armoireOpened;
|
||||||
Math.random.returns(YIELD_EXP);
|
randomVal.trueRandom.returns(YIELD_EXP);
|
||||||
|
|
||||||
expect(_.size(user.items.gear.owned)).to.equal(1);
|
expect(_.size(user.items.gear.owned)).to.equal(1);
|
||||||
|
|
||||||
@@ -148,7 +149,7 @@ xdescribe('shared.ops.buyArmoire', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('gives more equipment', () => {
|
it('gives more equipment', () => {
|
||||||
Math.random.returns(YIELD_EQUIPMENT);
|
randomVal.trueRandom.returns(YIELD_EQUIPMENT);
|
||||||
user.items.gear.owned = {
|
user.items.gear.owned = {
|
||||||
weapon_warrior_0: true,
|
weapon_warrior_0: true,
|
||||||
head_armoire_hornedIronHelm: true,
|
head_armoire_hornedIronHelm: true,
|
||||||
|
|||||||
@@ -16,3 +16,5 @@ module.exports = function randomVal (obj, options = {}) {
|
|||||||
|
|
||||||
return array[randomIndex];
|
return array[randomIndex];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.trueRandom = trueRandom;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ module.exports = function buyArmoire (user, req = {}, analytics) {
|
|||||||
let drop;
|
let drop;
|
||||||
let message;
|
let message;
|
||||||
|
|
||||||
let armoireResult = Math.random();
|
let armoireResult = randomVal.trueRandom();
|
||||||
let eligibleEquipment = _.filter(content.gear.flat, (eligible) => {
|
let eligibleEquipment = _.filter(content.gear.flat, (eligible) => {
|
||||||
return eligible.klass === 'armoire' && !user.items.gear.owned[eligible.key];
|
return eligible.klass === 'armoire' && !user.items.gear.owned[eligible.key];
|
||||||
});
|
});
|
||||||
@@ -79,7 +79,7 @@ module.exports = function buyArmoire (user, req = {}, analytics) {
|
|||||||
dropText: drop.text(req.language),
|
dropText: drop.text(req.language),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
let armoireExp = Math.floor(Math.random() * 40 + 10);
|
let armoireExp = Math.floor(randomVal.trueRandom() * 40 + 10);
|
||||||
user.stats.exp += armoireExp;
|
user.stats.exp += armoireExp;
|
||||||
message = i18n.t('armoireExp', req.language);
|
message = i18n.t('armoireExp', req.language);
|
||||||
armoireResp = {
|
armoireResp = {
|
||||||
|
|||||||
Reference in New Issue
Block a user