mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
tests(common): Convert algos tests to use generateUser helper
This commit is contained in:
@@ -1,4 +1,12 @@
|
|||||||
/* eslint-disable camelcase, func-names, no-shadow */
|
/* eslint-disable camelcase, func-names, no-shadow */
|
||||||
|
|
||||||
|
import {
|
||||||
|
generateUser,
|
||||||
|
generateDaily,
|
||||||
|
generateHabit,
|
||||||
|
generateTodo,
|
||||||
|
} from '../helpers/common.helper';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DAY_MAPPING,
|
DAY_MAPPING,
|
||||||
startOfWeek,
|
startOfWeek,
|
||||||
@@ -19,81 +27,6 @@ shared.i18n.translations = require('../../website/src/libs/i18n.js').translation
|
|||||||
test_helper.addCustomMatchers();
|
test_helper.addCustomMatchers();
|
||||||
|
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
|
|
||||||
let newUser = (addTasks = true) => {
|
|
||||||
let buffs = {
|
|
||||||
per: 0,
|
|
||||||
int: 0,
|
|
||||||
con: 0,
|
|
||||||
str: 0,
|
|
||||||
stealth: 0,
|
|
||||||
streaks: false,
|
|
||||||
};
|
|
||||||
let user = {
|
|
||||||
auth: {
|
|
||||||
timestamps: {},
|
|
||||||
},
|
|
||||||
stats: {
|
|
||||||
str: 1,
|
|
||||||
con: 1,
|
|
||||||
per: 1,
|
|
||||||
int: 1,
|
|
||||||
mp: 32,
|
|
||||||
class: 'warrior',
|
|
||||||
buffs,
|
|
||||||
},
|
|
||||||
items: {
|
|
||||||
lastDrop: {
|
|
||||||
count: 0,
|
|
||||||
},
|
|
||||||
hatchingPotions: {},
|
|
||||||
eggs: {},
|
|
||||||
food: {},
|
|
||||||
gear: {
|
|
||||||
equipped: {},
|
|
||||||
costume: {},
|
|
||||||
owned: {},
|
|
||||||
},
|
|
||||||
quests: {},
|
|
||||||
},
|
|
||||||
party: {
|
|
||||||
quest: {
|
|
||||||
progress: {
|
|
||||||
down: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
preferences: {
|
|
||||||
autoEquip: true,
|
|
||||||
},
|
|
||||||
dailys: [],
|
|
||||||
todos: [],
|
|
||||||
rewards: [],
|
|
||||||
flags: {},
|
|
||||||
achievements: {
|
|
||||||
ultimateGearSets: {},
|
|
||||||
},
|
|
||||||
contributor: {
|
|
||||||
level: 2,
|
|
||||||
},
|
|
||||||
_tmp: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
shared.wrap(user);
|
|
||||||
user.ops.reset(null, () => {});
|
|
||||||
if (addTasks) {
|
|
||||||
_.each(['habit', 'todo', 'daily'], (task) => {
|
|
||||||
user.ops.addTask({
|
|
||||||
body: {
|
|
||||||
type: task,
|
|
||||||
id: shared.uuid(),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
};
|
|
||||||
|
|
||||||
let rewrapUser = (user) => {
|
let rewrapUser = (user) => {
|
||||||
user._wrapped = false;
|
user._wrapped = false;
|
||||||
shared.wrap(user);
|
shared.wrap(user);
|
||||||
@@ -102,7 +35,15 @@ let rewrapUser = (user) => {
|
|||||||
|
|
||||||
let beforeAfter = (options = {}) => {
|
let beforeAfter = (options = {}) => {
|
||||||
let lastCron;
|
let lastCron;
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
let daily = generateDaily();
|
||||||
|
let habit = generateHabit();
|
||||||
|
let todo = generateTodo();
|
||||||
|
|
||||||
|
user.dailys.push(daily);
|
||||||
|
user.habits.push(habit);
|
||||||
|
user.todos.push(todo);
|
||||||
|
|
||||||
let ref = [user, _.cloneDeep(user)];
|
let ref = [user, _.cloneDeep(user)];
|
||||||
let before = ref[0];
|
let before = ref[0];
|
||||||
let after = ref[1];
|
let after = ref[1];
|
||||||
@@ -223,52 +164,10 @@ let repeatWithoutLastWeekday = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe('User', () => {
|
describe('User', () => {
|
||||||
it('sets correct user defaults', () => {
|
|
||||||
let user = newUser();
|
|
||||||
let base_gear = {
|
|
||||||
armor: 'armor_base_0',
|
|
||||||
weapon: 'weapon_base_0',
|
|
||||||
head: 'head_base_0',
|
|
||||||
shield: 'shield_base_0',
|
|
||||||
};
|
|
||||||
let buffs = {
|
|
||||||
per: 0,
|
|
||||||
int: 0,
|
|
||||||
con: 0,
|
|
||||||
str: 0,
|
|
||||||
stealth: 0,
|
|
||||||
streaks: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(user.stats).to.eql({
|
|
||||||
str: 1,
|
|
||||||
con: 1,
|
|
||||||
per: 1,
|
|
||||||
int: 1,
|
|
||||||
hp: 50,
|
|
||||||
mp: 32,
|
|
||||||
lvl: 1,
|
|
||||||
exp: 0,
|
|
||||||
gp: 0,
|
|
||||||
class: 'warrior',
|
|
||||||
buffs,
|
|
||||||
});
|
|
||||||
expect(user.items.gear).to.eql({
|
|
||||||
equipped: base_gear,
|
|
||||||
costume: base_gear,
|
|
||||||
owned: {
|
|
||||||
weapon_warrior_0: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(user.preferences).to.eql({
|
|
||||||
autoEquip: true,
|
|
||||||
costume: false,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('calculates max MP', () => {
|
it('calculates max MP', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
expect(user).toHaveMaxMP(32);
|
expect(user).toHaveMaxMP(30);
|
||||||
user.stats.int = 10;
|
user.stats.int = 10;
|
||||||
expect(user).toHaveMaxMP(50);
|
expect(user).toHaveMaxMP(50);
|
||||||
user.stats.lvl = 5;
|
user.stats.lvl = 5;
|
||||||
@@ -277,8 +176,9 @@ describe('User', () => {
|
|||||||
user.items.gear.equipped.weapon = 'weapon_wizard_1';
|
user.items.gear.equipped.weapon = 'weapon_wizard_1';
|
||||||
expect(user).toHaveMaxMP(63);
|
expect(user).toHaveMaxMP(63);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles perfect days', () => {
|
it('handles perfect days', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.dailys = [];
|
user.dailys = [];
|
||||||
_.times(3, () => {
|
_.times(3, () => {
|
||||||
@@ -316,12 +216,13 @@ describe('User', () => {
|
|||||||
expect(user.stats.buffs.str).to.be(1);
|
expect(user.stats.buffs.str).to.be(1);
|
||||||
expect(user.achievements.perfect).to.be(2);
|
expect(user.achievements.perfect).to.be(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Resting in the Inn', () => {
|
describe('Resting in the Inn', () => {
|
||||||
let user = null;
|
let user = null;
|
||||||
let cron = null;
|
let cron = null;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
user = newUser();
|
user = generateUser();
|
||||||
user.preferences.sleep = true;
|
user.preferences.sleep = true;
|
||||||
cron = () => {
|
cron = () => {
|
||||||
user.lastCron = moment().subtract(1, 'days');
|
user.lastCron = moment().subtract(1, 'days');
|
||||||
@@ -335,15 +236,18 @@ describe('User', () => {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('remains in the inn on cron', () => {
|
it('remains in the inn on cron', () => {
|
||||||
cron();
|
cron();
|
||||||
expect(user.preferences.sleep).to.be(true);
|
expect(user.preferences.sleep).to.be(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resets dailies', () => {
|
it('resets dailies', () => {
|
||||||
user.dailys[0].completed = true;
|
user.dailys[0].completed = true;
|
||||||
cron();
|
cron();
|
||||||
expect(user.dailys[0].completed).to.be(false);
|
expect(user.dailys[0].completed).to.be(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resets checklist on incomplete dailies', () => {
|
it('resets checklist on incomplete dailies', () => {
|
||||||
user.dailys[0].checklist = [
|
user.dailys[0].checklist = [
|
||||||
{
|
{
|
||||||
@@ -365,6 +269,7 @@ describe('User', () => {
|
|||||||
expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resets checklist on complete dailies', () => {
|
it('resets checklist on complete dailies', () => {
|
||||||
user.dailys[0].checklist = [
|
user.dailys[0].checklist = [
|
||||||
{
|
{
|
||||||
@@ -387,6 +292,7 @@ describe('User', () => {
|
|||||||
expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not reset checklist on grey incomplete dailies', () => {
|
it('does not reset checklist on grey incomplete dailies', () => {
|
||||||
let yesterday = moment().subtract(1, 'days');
|
let yesterday = moment().subtract(1, 'days');
|
||||||
|
|
||||||
@@ -411,6 +317,7 @@ describe('User', () => {
|
|||||||
expect(box.completed).to.be(true);
|
expect(box.completed).to.be(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resets checklist on complete grey complete dailies', () => {
|
it('resets checklist on complete grey complete dailies', () => {
|
||||||
let yesterday = moment().subtract(1, 'days');
|
let yesterday = moment().subtract(1, 'days');
|
||||||
|
|
||||||
@@ -436,6 +343,7 @@ describe('User', () => {
|
|||||||
expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not damage user for incomplete dailies', () => {
|
it('does not damage user for incomplete dailies', () => {
|
||||||
expect(user).toHaveHP(50);
|
expect(user).toHaveHP(50);
|
||||||
user.dailys[0].completed = true;
|
user.dailys[0].completed = true;
|
||||||
@@ -443,12 +351,14 @@ describe('User', () => {
|
|||||||
cron();
|
cron();
|
||||||
expect(user).toHaveHP(50);
|
expect(user).toHaveHP(50);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('gives credit for complete dailies', () => {
|
it('gives credit for complete dailies', () => {
|
||||||
user.dailys[0].completed = true;
|
user.dailys[0].completed = true;
|
||||||
expect(user.dailys[0].history).to.be.empty;
|
expect(user.dailys[0].history).to.be.empty;
|
||||||
cron();
|
cron();
|
||||||
expect(user.dailys[0].history).to.not.be.empty;
|
expect(user.dailys[0].history).to.not.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('damages user for incomplete dailies after checkout', () => {
|
it('damages user for incomplete dailies after checkout', () => {
|
||||||
expect(user).toHaveHP(50);
|
expect(user).toHaveHP(50);
|
||||||
user.dailys[0].completed = true;
|
user.dailys[0].completed = true;
|
||||||
@@ -458,11 +368,12 @@ describe('User', () => {
|
|||||||
expect(user.stats.hp).to.be.lessThan(50);
|
expect(user.stats.hp).to.be.lessThan(50);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Death', () => {
|
describe('Death', () => {
|
||||||
let user;
|
let user;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
user = newUser();
|
user = generateUser();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('revives correctly', () => {
|
it('revives correctly', () => {
|
||||||
@@ -473,7 +384,9 @@ describe('User', () => {
|
|||||||
hp: 0,
|
hp: 0,
|
||||||
class: 'warrior',
|
class: 'warrior',
|
||||||
};
|
};
|
||||||
|
user.items.gear.owned.weapon_warrior_0 = true;
|
||||||
user.ops.revive();
|
user.ops.revive();
|
||||||
|
|
||||||
expect(user).toHaveGP(0);
|
expect(user).toHaveGP(0);
|
||||||
expect(user).toHaveExp(0);
|
expect(user).toHaveExp(0);
|
||||||
expect(user).toHaveLevel(1);
|
expect(user).toHaveLevel(1);
|
||||||
@@ -484,21 +397,30 @@ describe('User', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('doesn\'t break unbreakables', () => {
|
it('doesn\'t break unbreakables', () => {
|
||||||
let ce;
|
let ce = shared.countExists;
|
||||||
|
|
||||||
|
user.items.gear.owned = {
|
||||||
|
weapon_warrior_0: true,
|
||||||
|
shield_warrior_1: true,
|
||||||
|
shield_rogue_1: true,
|
||||||
|
head_special_nye: true,
|
||||||
|
};
|
||||||
|
|
||||||
ce = shared.countExists;
|
|
||||||
user.items.gear.owned.shield_warrior_1 = true;
|
|
||||||
user.items.gear.owned.shield_rogue_1 = true;
|
|
||||||
user.items.gear.owned.head_special_nye = true;
|
|
||||||
expect(ce(user.items.gear.owned)).to.be(4);
|
expect(ce(user.items.gear.owned)).to.be(4);
|
||||||
|
|
||||||
user.stats.hp = 0;
|
user.stats.hp = 0;
|
||||||
user.ops.revive();
|
user.ops.revive();
|
||||||
|
|
||||||
expect(ce(user.items.gear.owned)).to.be(3);
|
expect(ce(user.items.gear.owned)).to.be(3);
|
||||||
|
|
||||||
user.stats.hp = 0;
|
user.stats.hp = 0;
|
||||||
user.ops.revive();
|
user.ops.revive();
|
||||||
|
|
||||||
expect(ce(user.items.gear.owned)).to.be(2);
|
expect(ce(user.items.gear.owned)).to.be(2);
|
||||||
|
|
||||||
user.stats.hp = 0;
|
user.stats.hp = 0;
|
||||||
user.ops.revive();
|
user.ops.revive();
|
||||||
|
|
||||||
expect(ce(user.items.gear.owned)).to.be(2);
|
expect(ce(user.items.gear.owned)).to.be(2);
|
||||||
expect(user.items.gear.owned).to.eql({
|
expect(user.items.gear.owned).to.eql({
|
||||||
weapon_warrior_0: false,
|
weapon_warrior_0: false,
|
||||||
@@ -521,9 +443,10 @@ describe('User', () => {
|
|||||||
expect(shared.content.gear.flat.head_special_nye.canOwn(user)).to.be(true);
|
expect(shared.content.gear.flat.head_special_nye.canOwn(user)).to.be(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Rebirth', () => {
|
describe('Rebirth', () => {
|
||||||
it('removes correct gear', () => {
|
it('removes correct gear', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.stats.lvl = 100;
|
user.stats.lvl = 100;
|
||||||
user.items.gear.owned = {
|
user.items.gear.owned = {
|
||||||
@@ -547,9 +470,10 @@ describe('User', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('store', () => {
|
describe('store', () => {
|
||||||
it('buys a Quest scroll', () => {
|
it('buys a Quest scroll', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.stats.gp = 205;
|
user.stats.gp = 205;
|
||||||
user.ops.buyQuest({
|
user.ops.buyQuest({
|
||||||
@@ -562,8 +486,9 @@ describe('User', () => {
|
|||||||
});
|
});
|
||||||
expect(user).toHaveGP(5);
|
expect(user).toHaveGP(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not buy Quests without enough Gold', () => {
|
it('does not buy Quests without enough Gold', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.stats.gp = 1;
|
user.stats.gp = 1;
|
||||||
user.ops.buyQuest({
|
user.ops.buyQuest({
|
||||||
@@ -574,8 +499,9 @@ describe('User', () => {
|
|||||||
expect(user.items.quests).to.eql({});
|
expect(user.items.quests).to.eql({});
|
||||||
expect(user).toHaveGP(1);
|
expect(user).toHaveGP(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not buy nonexistent Quests', () => {
|
it('does not buy nonexistent Quests', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.stats.gp = 9999;
|
user.stats.gp = 9999;
|
||||||
user.ops.buyQuest({
|
user.ops.buyQuest({
|
||||||
@@ -586,8 +512,9 @@ describe('User', () => {
|
|||||||
expect(user.items.quests).to.eql({});
|
expect(user.items.quests).to.eql({});
|
||||||
expect(user).toHaveGP(9999);
|
expect(user).toHaveGP(9999);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not buy Gem-premium Quests', () => {
|
it('does not buy Gem-premium Quests', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.stats.gp = 9999;
|
user.stats.gp = 9999;
|
||||||
user.ops.buyQuest({
|
user.ops.buyQuest({
|
||||||
@@ -599,9 +526,13 @@ describe('User', () => {
|
|||||||
expect(user).toHaveGP(9999);
|
expect(user).toHaveGP(9999);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Gem purchases', () => {
|
describe('Gem purchases', () => {
|
||||||
it('does not purchase items without enough Gems', () => {
|
it('does not purchase items without enough Gems', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
|
user.items.eggs = {};
|
||||||
|
user.items.gear.owned = {};
|
||||||
|
|
||||||
user.ops.purchase({
|
user.ops.purchase({
|
||||||
params: {
|
params: {
|
||||||
@@ -621,12 +552,11 @@ describe('User', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(user.items.eggs).to.eql({});
|
expect(user.items.eggs).to.eql({});
|
||||||
expect(user.items.gear.owned).to.eql({
|
expect(user.items.gear.owned).to.eql({});
|
||||||
weapon_warrior_0: true,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('purchases an egg', () => {
|
it('purchases an egg', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.balance = 1;
|
user.balance = 1;
|
||||||
user.ops.purchase({
|
user.ops.purchase({
|
||||||
@@ -640,8 +570,9 @@ describe('User', () => {
|
|||||||
});
|
});
|
||||||
expect(user.balance).to.eql(0.25);
|
expect(user.balance).to.eql(0.25);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('purchases fox ears', () => {
|
it('purchases fox ears', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.balance = 1;
|
user.balance = 1;
|
||||||
user.ops.purchase({
|
user.ops.purchase({
|
||||||
@@ -650,14 +581,13 @@ describe('User', () => {
|
|||||||
key: 'headAccessory_special_foxEars',
|
key: 'headAccessory_special_foxEars',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(user.items.gear.owned).to.eql({
|
|
||||||
weapon_warrior_0: true,
|
expect(user.items.gear.owned.headAccessory_special_foxEars).to.eql(true);
|
||||||
headAccessory_special_foxEars: true,
|
|
||||||
});
|
|
||||||
expect(user.balance).to.eql(0.5);
|
expect(user.balance).to.eql(0.5);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('unlocks all the animal ears at once', () => {
|
it('unlocks all the animal ears at once', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.balance = 2;
|
user.balance = 2;
|
||||||
user.ops.unlock({
|
user.ops.unlock({
|
||||||
@@ -665,20 +595,19 @@ describe('User', () => {
|
|||||||
path: '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',
|
path: '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',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(user.items.gear.owned).to.eql({
|
|
||||||
weapon_warrior_0: true,
|
expect(user.items.gear.owned.headAccessory_special_bearEars).to.eql(true);
|
||||||
headAccessory_special_bearEars: true,
|
expect(user.items.gear.owned.headAccessory_special_cactusEars).to.eql(true);
|
||||||
headAccessory_special_cactusEars: true,
|
expect(user.items.gear.owned.headAccessory_special_foxEars).to.eql(true);
|
||||||
headAccessory_special_foxEars: true,
|
expect(user.items.gear.owned.headAccessory_special_lionEars).to.eql(true);
|
||||||
headAccessory_special_lionEars: true,
|
expect(user.items.gear.owned.headAccessory_special_pandaEars).to.eql(true);
|
||||||
headAccessory_special_pandaEars: true,
|
expect(user.items.gear.owned.headAccessory_special_pigEars).to.eql(true);
|
||||||
headAccessory_special_pigEars: true,
|
expect(user.items.gear.owned.headAccessory_special_tigerEars).to.eql(true);
|
||||||
headAccessory_special_tigerEars: true,
|
expect(user.items.gear.owned.headAccessory_special_wolfEars).to.eql(true);
|
||||||
headAccessory_special_wolfEars: true,
|
|
||||||
});
|
|
||||||
expect(user.balance).to.eql(0.75);
|
expect(user.balance).to.eql(0.75);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('spells', () => {
|
describe('spells', () => {
|
||||||
_.each(shared.content.spells, (spellClass) => {
|
_.each(shared.content.spells, (spellClass) => {
|
||||||
_.each(spellClass, (spell) => {
|
_.each(spellClass, (spell) => {
|
||||||
@@ -694,6 +623,7 @@ describe('User', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('drop system', () => {
|
describe('drop system', () => {
|
||||||
let user = null;
|
let user = null;
|
||||||
const MIN_RANGE_FOR_POTION = 0;
|
const MIN_RANGE_FOR_POTION = 0;
|
||||||
@@ -704,7 +634,7 @@ describe('User', () => {
|
|||||||
const MAX_RANGE_FOR_FOOD = 1;
|
const MAX_RANGE_FOR_FOOD = 1;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
user = newUser();
|
user = generateUser();
|
||||||
user.flags.dropsEnabled = true;
|
user.flags.dropsEnabled = true;
|
||||||
this.task_id = shared.uuid();
|
this.task_id = shared.uuid();
|
||||||
return user.ops.addTask({
|
return user.ops.addTask({
|
||||||
@@ -733,6 +663,7 @@ describe('User', () => {
|
|||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('drops a pet egg', function () {
|
it('drops a pet egg', function () {
|
||||||
let results = [];
|
let results = [];
|
||||||
|
|
||||||
@@ -786,6 +717,7 @@ describe('User', () => {
|
|||||||
user.fns.predictableRandom.restore();
|
user.fns.predictableRandom.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Quests', () => {
|
describe('Quests', () => {
|
||||||
_.each(shared.content.quests, (quest) => {
|
_.each(shared.content.quests, (quest) => {
|
||||||
it(`${ quest.text() } has valid values`, () => {
|
it(`${ quest.text() } has valid values`, () => {
|
||||||
@@ -818,9 +750,12 @@ describe('User', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Achievements', () => {
|
describe('Achievements', () => {
|
||||||
_.each(shared.content.classes, (klass) => {
|
_.each(shared.content.classes, (klass) => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
|
user.achievements.ultimateGearSets = {};
|
||||||
|
|
||||||
user.stats.gp = 10000;
|
user.stats.gp = 10000;
|
||||||
_.each(shared.content.gearTypes, (type) => {
|
_.each(shared.content.gearTypes, (type) => {
|
||||||
@@ -844,8 +779,9 @@ describe('User', () => {
|
|||||||
expect(user.achievements.ultimateGearSets[klass]).to.be.ok();
|
expect(user.achievements.ultimateGearSets[klass]).to.be.ok();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not remove existing Ultimate Gear achievements', () => {
|
it('does not remove existing Ultimate Gear achievements', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.achievements.ultimateGearSets = {
|
user.achievements.ultimateGearSets = {
|
||||||
healer: true,
|
healer: true,
|
||||||
@@ -866,24 +802,27 @@ describe('User', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('unlocking features', () => {
|
describe('unlocking features', () => {
|
||||||
it('unlocks drops at level 3', () => {
|
it('unlocks drops at level 3', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.stats.lvl = 3;
|
user.stats.lvl = 3;
|
||||||
user.fns.updateStats(user.stats);
|
user.fns.updateStats(user.stats);
|
||||||
expect(user.flags.dropsEnabled).to.be.ok();
|
expect(user.flags.dropsEnabled).to.be.ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('unlocks Rebirth at level 50', () => {
|
it('unlocks Rebirth at level 50', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.stats.lvl = 50;
|
user.stats.lvl = 50;
|
||||||
user.fns.updateStats(user.stats);
|
user.fns.updateStats(user.stats);
|
||||||
expect(user.flags.rebirthEnabled).to.be.ok();
|
expect(user.flags.rebirthEnabled).to.be.ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('level-awarded Quests', () => {
|
describe('level-awarded Quests', () => {
|
||||||
it('gets Attack of the Mundane at level 15', () => {
|
it('gets Attack of the Mundane at level 15', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.stats.lvl = 15;
|
user.stats.lvl = 15;
|
||||||
user.fns.updateStats(user.stats);
|
user.fns.updateStats(user.stats);
|
||||||
@@ -892,7 +831,7 @@ describe('User', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('gets Vice at level 30', () => {
|
it('gets Vice at level 30', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.stats.lvl = 30;
|
user.stats.lvl = 30;
|
||||||
user.fns.updateStats(user.stats);
|
user.fns.updateStats(user.stats);
|
||||||
@@ -901,7 +840,7 @@ describe('User', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('gets Golden Knight at level 40', () => {
|
it('gets Golden Knight at level 40', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.stats.lvl = 40;
|
user.stats.lvl = 40;
|
||||||
user.fns.updateStats(user.stats);
|
user.fns.updateStats(user.stats);
|
||||||
@@ -910,7 +849,7 @@ describe('User', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('gets Moonstone Chain at level 60', () => {
|
it('gets Moonstone Chain at level 60', () => {
|
||||||
let user = newUser();
|
let user = generateUser();
|
||||||
|
|
||||||
user.stats.lvl = 60;
|
user.stats.lvl = 60;
|
||||||
user.fns.updateStats(user.stats);
|
user.fns.updateStats(user.stats);
|
||||||
@@ -941,6 +880,7 @@ describe('Simple Scoring', () => {
|
|||||||
});
|
});
|
||||||
expectLostPoints(this.before, this.after, 'habit');
|
expectLostPoints(this.before, this.after, 'habit');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Habits : Down', function () {
|
it('Habits : Down', function () {
|
||||||
this.after.ops.score({
|
this.after.ops.score({
|
||||||
params: {
|
params: {
|
||||||
@@ -953,6 +893,7 @@ describe('Simple Scoring', () => {
|
|||||||
});
|
});
|
||||||
expectGainedPoints(this.before, this.after, 'habit');
|
expectGainedPoints(this.before, this.after, 'habit');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Dailys : Up', function () {
|
it('Dailys : Up', function () {
|
||||||
this.after.ops.score({
|
this.after.ops.score({
|
||||||
params: {
|
params: {
|
||||||
@@ -962,6 +903,7 @@ describe('Simple Scoring', () => {
|
|||||||
});
|
});
|
||||||
expectGainedPoints(this.before, this.after, 'daily');
|
expectGainedPoints(this.before, this.after, 'daily');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Dailys : Up, Down', function () {
|
it('Dailys : Up, Down', function () {
|
||||||
this.after.ops.score({
|
this.after.ops.score({
|
||||||
params: {
|
params: {
|
||||||
@@ -977,6 +919,7 @@ describe('Simple Scoring', () => {
|
|||||||
});
|
});
|
||||||
expectClosePoints(this.before, this.after, 'daily');
|
expectClosePoints(this.before, this.after, 'daily');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Todos : Up', function () {
|
it('Todos : Up', function () {
|
||||||
this.after.ops.score({
|
this.after.ops.score({
|
||||||
params: {
|
params: {
|
||||||
@@ -1005,8 +948,13 @@ describe('Simple Scoring', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Cron', () => {
|
describe('Cron', () => {
|
||||||
|
let user;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
user = generateUser();
|
||||||
|
});
|
||||||
|
|
||||||
it('computes shouldCron', () => {
|
it('computes shouldCron', () => {
|
||||||
let user = newUser();
|
|
||||||
let paths = {};
|
let paths = {};
|
||||||
|
|
||||||
user.fns.cron({
|
user.fns.cron({
|
||||||
@@ -1020,6 +968,7 @@ describe('Cron', () => {
|
|||||||
});
|
});
|
||||||
expect(user.lastCron).to.be.greaterThan(0);
|
expect(user.lastCron).to.be.greaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('only dailies & todos are affected', () => {
|
it('only dailies & todos are affected', () => {
|
||||||
let ref = beforeAfter({
|
let ref = beforeAfter({
|
||||||
daysAgo: 1,
|
daysAgo: 1,
|
||||||
@@ -1040,6 +989,7 @@ describe('Cron', () => {
|
|||||||
|
|
||||||
expect(beforeTasks).to.eql(afterTasks);
|
expect(beforeTasks).to.eql(afterTasks);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('preening', () => {
|
describe('preening', () => {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.clock = sinon.useFakeTimers(Date.parse('2013-11-20'), 'Date');
|
this.clock = sinon.useFakeTimers(Date.parse('2013-11-20'), 'Date');
|
||||||
@@ -1157,6 +1107,7 @@ describe('Cron', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Todos', () => {
|
describe('Todos', () => {
|
||||||
it('1 day missed', () => {
|
it('1 day missed', () => {
|
||||||
let ref = beforeAfter({
|
let ref = beforeAfter({
|
||||||
@@ -1174,6 +1125,7 @@ describe('Cron', () => {
|
|||||||
expect(after.todos[0].value).to.be(-1);
|
expect(after.todos[0].value).to.be(-1);
|
||||||
expect(after.history.todos).to.have.length(1);
|
expect(after.history.todos).to.have.length(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('2 days missed', () => {
|
it('2 days missed', () => {
|
||||||
let ref = beforeAfter({
|
let ref = beforeAfter({
|
||||||
daysAgo: 2,
|
daysAgo: 2,
|
||||||
@@ -1187,6 +1139,7 @@ describe('Cron', () => {
|
|||||||
expect(after.todos[0].value).to.be(-1);
|
expect(after.todos[0].value).to.be(-1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('cron day calculations', () => {
|
describe('cron day calculations', () => {
|
||||||
let dayStart = 4;
|
let dayStart = 4;
|
||||||
let fstr = 'YYYY-MM-DD HH: mm: ss';
|
let fstr = 'YYYY-MM-DD HH: mm: ss';
|
||||||
@@ -1199,6 +1152,7 @@ describe('Cron', () => {
|
|||||||
|
|
||||||
expect(start.format(fstr)).to.eql('2014-10-08 04: 00: 00');
|
expect(start.format(fstr)).to.eql('2014-10-08 04: 00: 00');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('startOfDay after dayStart', () => {
|
it('startOfDay after dayStart', () => {
|
||||||
let start = startOfDay({
|
let start = startOfDay({
|
||||||
now: moment('2014-10-09 05: 30: 00'),
|
now: moment('2014-10-09 05: 30: 00'),
|
||||||
@@ -1207,6 +1161,7 @@ describe('Cron', () => {
|
|||||||
|
|
||||||
expect(start.format(fstr)).to.eql('2014-10-09 04: 00: 00');
|
expect(start.format(fstr)).to.eql('2014-10-09 04: 00: 00');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('daysSince cron before, now after', () => {
|
it('daysSince cron before, now after', () => {
|
||||||
let lastCron = moment('2014-10-09 02: 30: 00');
|
let lastCron = moment('2014-10-09 02: 30: 00');
|
||||||
let days = daysSince(lastCron, {
|
let days = daysSince(lastCron, {
|
||||||
@@ -1216,6 +1171,7 @@ describe('Cron', () => {
|
|||||||
|
|
||||||
expect(days).to.eql(1);
|
expect(days).to.eql(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('daysSince cron before, now before', () => {
|
it('daysSince cron before, now before', () => {
|
||||||
let lastCron = moment('2014-10-09 02: 30: 00');
|
let lastCron = moment('2014-10-09 02: 30: 00');
|
||||||
let days = daysSince(lastCron, {
|
let days = daysSince(lastCron, {
|
||||||
@@ -1225,6 +1181,7 @@ describe('Cron', () => {
|
|||||||
|
|
||||||
expect(days).to.eql(0);
|
expect(days).to.eql(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('daysSince cron after, now after', () => {
|
it('daysSince cron after, now after', () => {
|
||||||
let lastCron = moment('2014-10-09 05: 30: 00');
|
let lastCron = moment('2014-10-09 05: 30: 00');
|
||||||
let days = daysSince(lastCron, {
|
let days = daysSince(lastCron, {
|
||||||
@@ -1234,6 +1191,7 @@ describe('Cron', () => {
|
|||||||
|
|
||||||
expect(days).to.eql(0);
|
expect(days).to.eql(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('daysSince cron after, now tomorrow before', () => {
|
it('daysSince cron after, now tomorrow before', () => {
|
||||||
let lastCron = moment('2014-10-09 12: 30: 00');
|
let lastCron = moment('2014-10-09 12: 30: 00');
|
||||||
let days = daysSince(lastCron, {
|
let days = daysSince(lastCron, {
|
||||||
@@ -1243,6 +1201,7 @@ describe('Cron', () => {
|
|||||||
|
|
||||||
expect(days).to.eql(0);
|
expect(days).to.eql(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('daysSince cron after, now tomorrow after', () => {
|
it('daysSince cron after, now tomorrow after', () => {
|
||||||
let lastCron = moment('2014-10-09 12: 30: 00');
|
let lastCron = moment('2014-10-09 12: 30: 00');
|
||||||
let days = daysSince(lastCron, {
|
let days = daysSince(lastCron, {
|
||||||
@@ -1486,18 +1445,21 @@ describe('Helper', () => {
|
|||||||
expect(shared.gold(1.957)).to.eql(1);
|
expect(shared.gold(1.957)).to.eql(1);
|
||||||
expect(shared.gold()).to.eql(0);
|
expect(shared.gold()).to.eql(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calculates silver coins', () => {
|
it('calculates silver coins', () => {
|
||||||
expect(shared.silver(10)).to.eql(0);
|
expect(shared.silver(10)).to.eql(0);
|
||||||
expect(shared.silver(1.957)).to.eql(95);
|
expect(shared.silver(1.957)).to.eql(95);
|
||||||
expect(shared.silver(0.01)).to.eql('01');
|
expect(shared.silver(0.01)).to.eql('01');
|
||||||
expect(shared.silver()).to.eql('00');
|
expect(shared.silver()).to.eql('00');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calculates experience to next level', () => {
|
it('calculates experience to next level', () => {
|
||||||
expect(shared.tnl(1)).to.eql(150);
|
expect(shared.tnl(1)).to.eql(150);
|
||||||
expect(shared.tnl(2)).to.eql(160);
|
expect(shared.tnl(2)).to.eql(160);
|
||||||
expect(shared.tnl(10)).to.eql(260);
|
expect(shared.tnl(10)).to.eql(260);
|
||||||
expect(shared.tnl(99)).to.eql(3580);
|
expect(shared.tnl(99)).to.eql(3580);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calculates the start of the day', () => {
|
it('calculates the start of the day', () => {
|
||||||
let fstr = 'YYYY-MM-DD HH: mm: ss';
|
let fstr = 'YYYY-MM-DD HH: mm: ss';
|
||||||
let today = '2013-01-01 00: 00: 00';
|
let today = '2013-01-01 00: 00: 00';
|
||||||
|
|||||||
Reference in New Issue
Block a user