mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
(chore): lint test/common files
This commit is contained in:
@@ -40,7 +40,8 @@ gulp.task('lint:tests', () => {
|
|||||||
'./test/**/*.js',
|
'./test/**/*.js',
|
||||||
// @TODO remove these negations as the test files are cleaned up.
|
// @TODO remove these negations as the test files are cleaned up.
|
||||||
'!./test/api-legacy/**/*',
|
'!./test/api-legacy/**/*',
|
||||||
'!./test/common/**/*',
|
'!./test/api/**/*',
|
||||||
|
'!./test/common/simulations/**/*',
|
||||||
'!./test/content/**/*',
|
'!./test/content/**/*',
|
||||||
'!./test/e2e/**/*',
|
'!./test/e2e/**/*',
|
||||||
'!./test/server_side/**/*',
|
'!./test/server_side/**/*',
|
||||||
@@ -48,6 +49,7 @@ gulp.task('lint:tests', () => {
|
|||||||
])
|
])
|
||||||
.pipe(eslint({
|
.pipe(eslint({
|
||||||
rules: {
|
rules: {
|
||||||
|
'max-nested-callbacks': 0,
|
||||||
'no-unused-expressions': 0,
|
'no-unused-expressions': 0,
|
||||||
'mocha/no-exclusive-tests': 2,
|
'mocha/no-exclusive-tests': 2,
|
||||||
'mocha/no-global-tests': 2,
|
'mocha/no-global-tests': 2,
|
||||||
@@ -55,6 +57,8 @@ gulp.task('lint:tests', () => {
|
|||||||
},
|
},
|
||||||
globals: {
|
globals: {
|
||||||
'expect': true,
|
'expect': true,
|
||||||
|
'_': true,
|
||||||
|
'sinon': true,
|
||||||
},
|
},
|
||||||
plugins: [ 'mocha' ],
|
plugins: [ 'mocha' ],
|
||||||
}))
|
}))
|
||||||
@@ -62,7 +66,7 @@ gulp.task('lint:tests', () => {
|
|||||||
.pipe(eslint.failAfterError());
|
.pipe(eslint.failAfterError());
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('lint', ['lint:server', 'lint:common']);
|
gulp.task('lint', ['lint:server', 'lint:common', 'lint:tests']);
|
||||||
|
|
||||||
gulp.task('lint:watch', () => {
|
gulp.task('lint:watch', () => {
|
||||||
gulp.watch([
|
gulp.watch([
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,191 +1,206 @@
|
|||||||
var sinon = require('sinon');
|
/* eslint-disable camelcase */
|
||||||
var chai = require("chai")
|
let count = require('../../common/script/count');
|
||||||
chai.use(require("sinon-chai"))
|
|
||||||
var expect = chai.expect
|
|
||||||
|
|
||||||
var count = require('../../common/script/count');
|
describe('count', () => {
|
||||||
|
describe('beastMasterProgress', () => {
|
||||||
|
it('returns 0 if no pets', () => {
|
||||||
|
let pets = {};
|
||||||
|
let beastMasterTotal = count.beastMasterProgress(pets);
|
||||||
|
|
||||||
describe('count', function() {
|
|
||||||
describe('beastMasterProgress', function() {
|
|
||||||
it('returns 0 if no pets', function() {
|
|
||||||
var pets = {};
|
|
||||||
var beastMasterTotal = count.beastMasterProgress(pets);
|
|
||||||
expect(beastMasterTotal).to.eql(0);
|
expect(beastMasterTotal).to.eql(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('counts drop pets', function() {
|
it('counts drop pets', () => {
|
||||||
var pets = { "Dragon-Red": 1, "Wolf-Base": 2 };
|
let pets = { 'Dragon-Red': 1, 'Wolf-Base': 2 };
|
||||||
var beastMasterTotal = count.beastMasterProgress(pets);
|
let beastMasterTotal = count.beastMasterProgress(pets);
|
||||||
|
|
||||||
expect(beastMasterTotal).to.eql(2);
|
expect(beastMasterTotal).to.eql(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not count quest pets', function() {
|
it('does not count quest pets', () => {
|
||||||
var pets = { "Dragon-Red": 1, "Gryphon-Base": 1 };
|
let pets = { 'Dragon-Red': 1, 'Gryphon-Base': 1 };
|
||||||
var beastMasterTotal = count.beastMasterProgress(pets);
|
let beastMasterTotal = count.beastMasterProgress(pets);
|
||||||
|
|
||||||
expect(beastMasterTotal).to.eql(1);
|
expect(beastMasterTotal).to.eql(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not count pets hatched with premium potions', function() {
|
it('does not count pets hatched with premium potions', () => {
|
||||||
var pets = {
|
let pets = {
|
||||||
"Wolf-Spooky": 5,
|
'Wolf-Spooky': 5,
|
||||||
"Dragon-Spooky": 5,
|
'Dragon-Spooky': 5,
|
||||||
"FlyingPig-Base": 5
|
'FlyingPig-Base': 5,
|
||||||
}
|
|
||||||
var beastMasterTotal = count.beastMasterProgress(pets);
|
|
||||||
expect(beastMasterTotal).to.eql(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not count special pets', function() {
|
|
||||||
var pets = {
|
|
||||||
"Wolf-Base": 2,
|
|
||||||
"Wolf-Veteran": 1,
|
|
||||||
"Wolf-Cerberus": 1,
|
|
||||||
"Dragon-Hydra": 1
|
|
||||||
};
|
};
|
||||||
var beastMasterTotal = count.beastMasterProgress(pets);
|
let beastMasterTotal = count.beastMasterProgress(pets);
|
||||||
|
|
||||||
expect(beastMasterTotal).to.eql(1);
|
expect(beastMasterTotal).to.eql(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('counts drop pets that have been raised to a mount', function() {
|
it('does not count special pets', () => {
|
||||||
var raisedToMount = -1;
|
let pets = {
|
||||||
var pets = { "Dragon-Red": 1, "Wolf-Base": raisedToMount };
|
'Wolf-Base': 2,
|
||||||
var beastMasterTotal = count.beastMasterProgress(pets);
|
'Wolf-Veteran': 1,
|
||||||
|
'Wolf-Cerberus': 1,
|
||||||
|
'Dragon-Hydra': 1,
|
||||||
|
};
|
||||||
|
let 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);
|
||||||
|
|
||||||
expect(beastMasterTotal).to.eql(2);
|
expect(beastMasterTotal).to.eql(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not counts drop pets that have been released', function() {
|
it('does not counts drop pets that have been released', () => {
|
||||||
var releasedPet = 0;
|
let releasedPet = 0;
|
||||||
var pets = { "Dragon-Red": 1, "Wolf-Base": releasedPet };
|
let pets = { 'Dragon-Red': 1, 'Wolf-Base': releasedPet };
|
||||||
var beastMasterTotal = count.beastMasterProgress(pets);
|
let beastMasterTotal = count.beastMasterProgress(pets);
|
||||||
|
|
||||||
expect(beastMasterTotal).to.eql(1);
|
expect(beastMasterTotal).to.eql(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('mountMasterProgress', function() {
|
describe('mountMasterProgress', () => {
|
||||||
it('returns 0 if no mounts', function() {
|
it('returns 0 if no mounts', () => {
|
||||||
var mounts = {};
|
let mounts = {};
|
||||||
var mountMasterTotal = count.mountMasterProgress(mounts);
|
let mountMasterTotal = count.mountMasterProgress(mounts);
|
||||||
|
|
||||||
expect(mountMasterTotal).to.eql(0);
|
expect(mountMasterTotal).to.eql(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('counts drop mounts', function() {
|
it('counts drop mounts', () => {
|
||||||
var mounts = { "Dragon-Red": true, "Wolf-Base": true };
|
let mounts = { 'Dragon-Red': true, 'Wolf-Base': true };
|
||||||
var mountMasterTotal = count.mountMasterProgress(mounts);
|
let mountMasterTotal = count.mountMasterProgress(mounts);
|
||||||
|
|
||||||
expect(mountMasterTotal).to.eql(2);
|
expect(mountMasterTotal).to.eql(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not count premium mounts', function() {
|
it('does not count premium mounts', () => {
|
||||||
var mounts = {
|
let mounts = {
|
||||||
"Dragon-Red": true,
|
'Dragon-Red': true,
|
||||||
"FlyingPig-Spooky": true
|
'FlyingPig-Spooky': true,
|
||||||
}
|
};
|
||||||
var mountMasterTotal = count.mountMasterProgress(mounts);
|
let mountMasterTotal = count.mountMasterProgress(mounts);
|
||||||
|
|
||||||
expect(mountMasterTotal).to.eql(1);
|
expect(mountMasterTotal).to.eql(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not count quest mounts', function() {
|
it('does not count quest mounts', () => {
|
||||||
var mounts = { "Dragon-Red": true, "Gryphon-Base": true };
|
let mounts = { 'Dragon-Red': true, 'Gryphon-Base': true };
|
||||||
var mountMasterTotal = count.mountMasterProgress(mounts);
|
let mountMasterTotal = count.mountMasterProgress(mounts);
|
||||||
|
|
||||||
expect(mountMasterTotal).to.eql(1);
|
expect(mountMasterTotal).to.eql(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not count special mounts', function() {
|
it('does not count special mounts', () => {
|
||||||
var mounts = { "Wolf-Base": true, "BearCub-Polar": true};
|
let mounts = { 'Wolf-Base': true, 'BearCub-Polar': true};
|
||||||
var mountMasterTotal = count.mountMasterProgress(mounts);
|
let mountMasterTotal = count.mountMasterProgress(mounts);
|
||||||
|
|
||||||
expect(mountMasterTotal).to.eql(1);
|
expect(mountMasterTotal).to.eql(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('only counts drop mounts that are currently owned', function() {
|
it('only counts drop mounts that are currently owned', () => {
|
||||||
var notCurrentlyOwned = false;
|
let notCurrentlyOwned = false;
|
||||||
var mounts = { "Dragon-Red": true, "Wolf-Base": notCurrentlyOwned };
|
let mounts = { 'Dragon-Red': true, 'Wolf-Base': notCurrentlyOwned };
|
||||||
var mountMasterTotal = count.mountMasterProgress(mounts);
|
let mountMasterTotal = count.mountMasterProgress(mounts);
|
||||||
|
|
||||||
expect(mountMasterTotal).to.eql(1);
|
expect(mountMasterTotal).to.eql(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('remainingGearInSet', function() {
|
describe('remainingGearInSet', () => {
|
||||||
it('counts remaining gear based on set', function() {
|
it('counts remaining gear based on set', () => {
|
||||||
var gear = {
|
let gear = {
|
||||||
'weapon_wizard_0':true,
|
weapon_wizard_0: true,
|
||||||
'weapon_wizard_1':true,
|
weapon_wizard_1: true,
|
||||||
'weapon_warrior_0':true,
|
weapon_warrior_0: true,
|
||||||
'weapon_warrior_1':true,
|
weapon_warrior_1: true,
|
||||||
'weapon_armor_0':true,
|
weapon_armor_0: true,
|
||||||
'weapon_armor_1':true
|
weapon_armor_1: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var armoireCount = count.remainingGearInSet(gear, 'warrior');
|
let armoireCount = count.remainingGearInSet(gear, 'warrior');
|
||||||
|
|
||||||
expect(armoireCount).to.eql(20);
|
expect(armoireCount).to.eql(20);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.skip('includes previously owned items in count (https://github.com/HabitRPG/habitrpg/issues/5624#issuecomment-124018717)', function() {
|
it.skip('includes previously owned items in count (https: //github.com/HabitRPG/habitrpg/issues/5624#issuecomment-124018717)', () => {
|
||||||
var gear = {
|
let gear = {
|
||||||
'weapon_warrior_0':false,
|
weapon_warrior_0: false,
|
||||||
'weapon_warrior_1':false,
|
weapon_warrior_1: false,
|
||||||
'weapon_armor_0':true,
|
weapon_armor_0: true,
|
||||||
'weapon_armor_1':true
|
weapon_armor_1: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var armoireCount = count.remainingGearInSet(gear, 'warrior');
|
let armoireCount = count.remainingGearInSet(gear, 'warrior');
|
||||||
|
|
||||||
expect(armoireCount).to.eql(20);
|
expect(armoireCount).to.eql(20);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('dropPetsCurrentlyOwned', function() {
|
describe('dropPetsCurrentlyOwned', () => {
|
||||||
it('counts drop pets owned', function() {
|
it('counts drop pets owned', () => {
|
||||||
var pets = {
|
let pets = {
|
||||||
"Wolf-Base": 2,
|
'Wolf-Base': 2,
|
||||||
"Wolf-Red": 4
|
'Wolf-Red': 4,
|
||||||
};
|
};
|
||||||
var dropPets = count.dropPetsCurrentlyOwned(pets);
|
let dropPets = count.dropPetsCurrentlyOwned(pets);
|
||||||
|
|
||||||
expect(dropPets).to.eql(2);
|
expect(dropPets).to.eql(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not count pets that have been raised to mounts', function() {
|
it('does not count pets that have been raised to mounts', () => {
|
||||||
var pets = {
|
let pets = {
|
||||||
"Wolf-Base": -1,
|
'Wolf-Base': -1,
|
||||||
"Wolf-Red": 4,
|
'Wolf-Red': 4,
|
||||||
"Wolf-Veteran": 1,
|
'Wolf-Veteran': 1,
|
||||||
"Gryphon-Base": 1
|
'Gryphon-Base': 1,
|
||||||
};
|
};
|
||||||
var dropPets = count.dropPetsCurrentlyOwned(pets);
|
let dropPets = count.dropPetsCurrentlyOwned(pets);
|
||||||
|
|
||||||
expect(dropPets).to.eql(1);
|
expect(dropPets).to.eql(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not count quest pets', function() {
|
it('does not count quest pets', () => {
|
||||||
var pets = {
|
let pets = {
|
||||||
"Wolf-Base": 2,
|
'Wolf-Base': 2,
|
||||||
"Wolf-Red": 4,
|
'Wolf-Red': 4,
|
||||||
"Gryphon-Base": 1
|
'Gryphon-Base': 1,
|
||||||
};
|
};
|
||||||
var dropPets = count.dropPetsCurrentlyOwned(pets);
|
let dropPets = count.dropPetsCurrentlyOwned(pets);
|
||||||
|
|
||||||
expect(dropPets).to.eql(2);
|
expect(dropPets).to.eql(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not count special pets', function() {
|
it('does not count special pets', () => {
|
||||||
var pets = {
|
let pets = {
|
||||||
"Wolf-Base": 2,
|
'Wolf-Base': 2,
|
||||||
"Wolf-Red": 4,
|
'Wolf-Red': 4,
|
||||||
"Wolf-Veteran": 1
|
'Wolf-Veteran': 1,
|
||||||
};
|
};
|
||||||
var dropPets = count.dropPetsCurrentlyOwned(pets);
|
let dropPets = count.dropPetsCurrentlyOwned(pets);
|
||||||
|
|
||||||
expect(dropPets).to.eql(2);
|
expect(dropPets).to.eql(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('questsOfCategory', function() {
|
describe('questsOfCategory', () => {
|
||||||
|
it('counts user quest scrolls of a particular category', () => {
|
||||||
it('counts user quest scrolls of a particular category', function() {
|
let quests = {
|
||||||
var quests = {
|
atom1: 2,
|
||||||
"atom1": 2,
|
whale: 4,
|
||||||
"whale": 4,
|
kraken: 2,
|
||||||
"kraken": 2,
|
sheep: 1,
|
||||||
"sheep": 1,
|
goldenknight2: 1,
|
||||||
"goldenknight2": 1
|
|
||||||
};
|
};
|
||||||
var petQuestCount = count.questsOfCategory(quests, 'pet');
|
let petQuestCount = count.questsOfCategory(quests, 'pet');
|
||||||
var unlockableQuestCount = count.questsOfCategory(quests, 'unlockable');
|
let unlockableQuestCount = count.questsOfCategory(quests, 'unlockable');
|
||||||
var goldQuestCount = count.questsOfCategory(quests, 'gold');
|
let goldQuestCount = count.questsOfCategory(quests, 'gold');
|
||||||
|
|
||||||
expect(petQuestCount).to.eql(3);
|
expect(petQuestCount).to.eql(3);
|
||||||
expect(unlockableQuestCount).to.eql(2);
|
expect(unlockableQuestCount).to.eql(2);
|
||||||
expect(goldQuestCount).to.eql(0);
|
expect(goldQuestCount).to.eql(0);
|
||||||
|
|||||||
@@ -1,57 +1,50 @@
|
|||||||
var _, cron, expect, moment, newUser, repeatWithoutLastWeekday, shared, sinon;
|
/* eslint-disable camelcase */
|
||||||
|
|
||||||
_ = require('lodash');
|
let expect = require('expect.js'); // eslint-disable-line no-shadow
|
||||||
|
let moment = require('moment');
|
||||||
expect = require('expect.js');
|
let shared = require('../../common/script/index.js');
|
||||||
|
|
||||||
sinon = require('sinon');
|
|
||||||
|
|
||||||
moment = require('moment');
|
|
||||||
|
|
||||||
shared = require('../../common/script/index.js');
|
|
||||||
|
|
||||||
shared.i18n.translations = require('../../website/src/libs/i18n.js').translations;
|
shared.i18n.translations = require('../../website/src/libs/i18n.js').translations;
|
||||||
|
|
||||||
repeatWithoutLastWeekday = function() {
|
let repeatWithoutLastWeekday = () => { // eslint-disable-line no-unused-vars
|
||||||
var repeat;
|
let repeat = {
|
||||||
repeat = {
|
|
||||||
su: true,
|
su: true,
|
||||||
m: true,
|
m: true,
|
||||||
t: true,
|
t: true,
|
||||||
w: true,
|
w: true,
|
||||||
th: true,
|
th: true,
|
||||||
f: true,
|
f: true,
|
||||||
s: true
|
s: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (shared.startOfWeek(moment().zone(0)).isoWeekday() === 1) {
|
if (shared.startOfWeek(moment().zone(0)).isoWeekday() === 1) {
|
||||||
repeat.su = false;
|
repeat.su = false;
|
||||||
} else {
|
} else {
|
||||||
repeat.s = false;
|
repeat.s = false;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
repeat: repeat
|
repeat,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
|
|
||||||
newUser = function(addTasks) {
|
let newUser = (addTasks = true) => {
|
||||||
var buffs, user;
|
let buffs;
|
||||||
if (addTasks == null) {
|
let user;
|
||||||
addTasks = true;
|
|
||||||
}
|
|
||||||
buffs = {
|
buffs = {
|
||||||
per: 0,
|
per: 0,
|
||||||
int: 0,
|
int: 0,
|
||||||
con: 0,
|
con: 0,
|
||||||
str: 0,
|
str: 0,
|
||||||
stealth: 0,
|
stealth: 0,
|
||||||
streaks: false
|
streaks: false,
|
||||||
};
|
};
|
||||||
user = {
|
user = {
|
||||||
auth: {
|
auth: {
|
||||||
timestamps: {}
|
timestamps: {},
|
||||||
},
|
},
|
||||||
stats: {
|
stats: {
|
||||||
str: 1,
|
str: 1,
|
||||||
@@ -59,27 +52,27 @@ newUser = function(addTasks) {
|
|||||||
per: 1,
|
per: 1,
|
||||||
int: 1,
|
int: 1,
|
||||||
mp: 32,
|
mp: 32,
|
||||||
"class": 'warrior',
|
class: 'warrior',
|
||||||
buffs: buffs
|
buffs,
|
||||||
},
|
},
|
||||||
items: {
|
items: {
|
||||||
lastDrop: {
|
lastDrop: {
|
||||||
count: 0
|
count: 0,
|
||||||
},
|
},
|
||||||
hatchingPotions: {},
|
hatchingPotions: {},
|
||||||
eggs: {},
|
eggs: {},
|
||||||
food: {},
|
food: {},
|
||||||
gear: {
|
gear: {
|
||||||
equipped: {},
|
equipped: {},
|
||||||
costume: {}
|
costume: {},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
party: {
|
party: {
|
||||||
quest: {
|
quest: {
|
||||||
progress: {
|
progress: {
|
||||||
down: 0
|
down: 0,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
preferences: {},
|
preferences: {},
|
||||||
dailys: [],
|
dailys: [],
|
||||||
@@ -88,45 +81,42 @@ newUser = function(addTasks) {
|
|||||||
flags: {},
|
flags: {},
|
||||||
achievements: {},
|
achievements: {},
|
||||||
contributor: {
|
contributor: {
|
||||||
level: 2
|
level: 2,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
shared.wrap(user);
|
shared.wrap(user);
|
||||||
user.ops.reset(null, function() {});
|
user.ops.reset(null, () => {});
|
||||||
if (addTasks) {
|
if (addTasks) {
|
||||||
_.each(['habit', 'todo', 'daily'], function(task) {
|
_.each(['habit', 'todo', 'daily'], (task) => {
|
||||||
return user.ops.addTask({
|
user.ops.addTask({
|
||||||
body: {
|
body: {
|
||||||
type: task,
|
type: task,
|
||||||
id: shared.uuid()
|
id: shared.uuid(),
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return user;
|
return user;
|
||||||
};
|
};
|
||||||
|
|
||||||
cron = function(usr, missedDays) {
|
let cron = (usr, missedDays = 1) => {
|
||||||
if (missedDays == null) {
|
|
||||||
missedDays = 1;
|
|
||||||
}
|
|
||||||
usr.lastCron = moment().subtract(missedDays, 'days');
|
usr.lastCron = moment().subtract(missedDays, 'days');
|
||||||
return usr.fns.cron();
|
usr.fns.cron();
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('daily/weekly that repeats everyday (default)', function() {
|
describe('daily/weekly that repeats everyday (default)', () => {
|
||||||
var daily, user, weekly;
|
let user = null;
|
||||||
user = null;
|
let daily = null;
|
||||||
daily = null;
|
let weekly = null;
|
||||||
weekly = null;
|
|
||||||
describe('when startDate is in the future', function() {
|
describe('when startDate is in the future', () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
user = newUser();
|
user = newUser();
|
||||||
user.dailys = [
|
user.dailys = [
|
||||||
shared.taskDefaults({
|
shared.taskDefaults({
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
startDate: moment().add(7, 'days'),
|
startDate: moment().add(7, 'days'),
|
||||||
frequency: 'daily'
|
frequency: 'daily',
|
||||||
}), shared.taskDefaults({
|
}), shared.taskDefaults({
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
startDate: moment().add(7, 'days'),
|
startDate: moment().add(7, 'days'),
|
||||||
@@ -138,39 +128,39 @@ describe('daily/weekly that repeats everyday (default)', function() {
|
|||||||
w: true,
|
w: true,
|
||||||
th: true,
|
th: true,
|
||||||
f: true,
|
f: true,
|
||||||
s: true
|
s: true,
|
||||||
}
|
},
|
||||||
})
|
}),
|
||||||
];
|
];
|
||||||
daily = user.dailys[0];
|
daily = user.dailys[0];
|
||||||
return weekly = user.dailys[1];
|
weekly = user.dailys[1];
|
||||||
});
|
});
|
||||||
it('does not damage user for not completing it', function() {
|
it('does not damage user for not completing it', () => {
|
||||||
cron(user);
|
cron(user);
|
||||||
return expect(user.stats.hp).to.be(50);
|
expect(user.stats.hp).to.be(50);
|
||||||
});
|
});
|
||||||
it('does not change value on cron if daily is incomplete', function() {
|
it('does not change value on cron if daily is incomplete', () => {
|
||||||
cron(user);
|
cron(user);
|
||||||
expect(daily.value).to.be(0);
|
expect(daily.value).to.be(0);
|
||||||
return expect(weekly.value).to.be(0);
|
expect(weekly.value).to.be(0);
|
||||||
});
|
});
|
||||||
it('does not reset checklists if daily is not marked as complete', function() {
|
it('does not reset checklists if daily is not marked as complete', () => {
|
||||||
var checklist;
|
let checklist = [
|
||||||
checklist = [
|
|
||||||
{
|
{
|
||||||
'text': '1',
|
text: '1',
|
||||||
'id': 'checklist-one',
|
id: 'checklist-one',
|
||||||
'completed': true
|
completed: true,
|
||||||
}, {
|
}, {
|
||||||
'text': '2',
|
text: '2',
|
||||||
'id': 'checklist-two',
|
id: 'checklist-two',
|
||||||
'completed': true
|
completed: true,
|
||||||
}, {
|
}, {
|
||||||
'text': '3',
|
text: '3',
|
||||||
'id': 'checklist-three',
|
id: 'checklist-three',
|
||||||
'completed': false
|
completed: false,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
daily.checklist = checklist;
|
daily.checklist = checklist;
|
||||||
weekly.checklist = checklist;
|
weekly.checklist = checklist;
|
||||||
cron(user);
|
cron(user);
|
||||||
@@ -179,359 +169,369 @@ describe('daily/weekly that repeats everyday (default)', function() {
|
|||||||
expect(daily.checklist[2].completed).to.be(false);
|
expect(daily.checklist[2].completed).to.be(false);
|
||||||
expect(weekly.checklist[0].completed).to.be(true);
|
expect(weekly.checklist[0].completed).to.be(true);
|
||||||
expect(weekly.checklist[1].completed).to.be(true);
|
expect(weekly.checklist[1].completed).to.be(true);
|
||||||
return expect(weekly.checklist[2].completed).to.be(false);
|
expect(weekly.checklist[2].completed).to.be(false);
|
||||||
});
|
});
|
||||||
it('resets checklists if daily is marked as complete', function() {
|
it('resets checklists if daily is marked as complete', () => {
|
||||||
var checklist;
|
let checklist = [
|
||||||
checklist = [
|
|
||||||
{
|
{
|
||||||
'text': '1',
|
text: '1',
|
||||||
'id': 'checklist-one',
|
id: 'checklist-one',
|
||||||
'completed': true
|
completed: true,
|
||||||
}, {
|
}, {
|
||||||
'text': '2',
|
text: '2',
|
||||||
'id': 'checklist-two',
|
id: 'checklist-two',
|
||||||
'completed': true
|
completed: true,
|
||||||
}, {
|
}, {
|
||||||
'text': '3',
|
text: '3',
|
||||||
'id': 'checklist-three',
|
id: 'checklist-three',
|
||||||
'completed': false
|
completed: false,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
daily.checklist = checklist;
|
daily.checklist = checklist;
|
||||||
weekly.checklist = checklist;
|
weekly.checklist = checklist;
|
||||||
daily.completed = true;
|
daily.completed = true;
|
||||||
weekly.completed = true;
|
weekly.completed = true;
|
||||||
cron(user);
|
cron(user);
|
||||||
_.each(daily.checklist, function(box) {
|
_.each(daily.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
return _.each(weekly.checklist, function(box) {
|
_.each(weekly.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return it('is due on startDate', function() {
|
it('is due on startDate', () => {
|
||||||
var daily_due_on_start_date, daily_due_today, weekly_due_on_start_date, weekly_due_today;
|
let daily_due_today = shared.shouldDo(moment(), daily);
|
||||||
daily_due_today = shared.shouldDo(moment(), daily);
|
let daily_due_on_start_date = shared.shouldDo(moment().add(7, 'days'), daily);
|
||||||
daily_due_on_start_date = shared.shouldDo(moment().add(7, 'days'), daily);
|
|
||||||
expect(daily_due_today).to.be(false);
|
expect(daily_due_today).to.be(false);
|
||||||
expect(daily_due_on_start_date).to.be(true);
|
expect(daily_due_on_start_date).to.be(true);
|
||||||
weekly_due_today = shared.shouldDo(moment(), weekly);
|
|
||||||
weekly_due_on_start_date = shared.shouldDo(moment().add(7, 'days'), weekly);
|
let weekly_due_today = shared.shouldDo(moment(), weekly);
|
||||||
|
let weekly_due_on_start_date = shared.shouldDo(moment().add(7, 'days'), weekly);
|
||||||
|
|
||||||
expect(weekly_due_today).to.be(false);
|
expect(weekly_due_today).to.be(false);
|
||||||
return expect(weekly_due_on_start_date).to.be(true);
|
expect(weekly_due_on_start_date).to.be(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when startDate is in the past', function() {
|
describe('when startDate is in the past', () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
user = newUser();
|
user = newUser();
|
||||||
user.dailys = [
|
user.dailys = [
|
||||||
shared.taskDefaults({
|
shared.taskDefaults({
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
startDate: moment().subtract(7, 'days'),
|
startDate: moment().subtract(7, 'days'),
|
||||||
frequency: 'daily'
|
frequency: 'daily',
|
||||||
}), shared.taskDefaults({
|
}), shared.taskDefaults({
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
startDate: moment().subtract(7, 'days'),
|
startDate: moment().subtract(7, 'days'),
|
||||||
frequency: 'weekly'
|
frequency: 'weekly',
|
||||||
})
|
}),
|
||||||
];
|
];
|
||||||
daily = user.dailys[0];
|
daily = user.dailys[0];
|
||||||
return weekly = user.dailys[1];
|
weekly = user.dailys[1];
|
||||||
});
|
});
|
||||||
it('does damage user for not completing it', function() {
|
it('does damage user for not completing it', () => {
|
||||||
cron(user);
|
cron(user);
|
||||||
return expect(user.stats.hp).to.be.lessThan(50);
|
expect(user.stats.hp).to.be.lessThan(50);
|
||||||
});
|
});
|
||||||
it('decreases value on cron if daily is incomplete', function() {
|
it('decreases value on cron if daily is incomplete', () => {
|
||||||
cron(user, 1);
|
cron(user, 1);
|
||||||
expect(daily.value).to.be(-1);
|
expect(daily.value).to.be(-1);
|
||||||
return expect(weekly.value).to.be(-1);
|
expect(weekly.value).to.be(-1);
|
||||||
});
|
});
|
||||||
it('decreases value on cron once only if daily is incomplete and multiple days are missed', function() {
|
it('decreases value on cron once only if daily is incomplete and multiple days are missed', () => {
|
||||||
cron(user, 7);
|
cron(user, 7);
|
||||||
expect(daily.value).to.be(-1);
|
expect(daily.value).to.be(-1);
|
||||||
return expect(weekly.value).to.be(-1);
|
expect(weekly.value).to.be(-1);
|
||||||
});
|
});
|
||||||
it('resets checklists if daily is not marked as complete', function() {
|
it('resets checklists if daily is not marked as complete', () => {
|
||||||
var checklist;
|
let checklist;
|
||||||
|
|
||||||
checklist = [
|
checklist = [
|
||||||
{
|
{
|
||||||
'text': '1',
|
text: '1',
|
||||||
'id': 'checklist-one',
|
id: 'checklist-one',
|
||||||
'completed': true
|
completed: true,
|
||||||
}, {
|
}, {
|
||||||
'text': '2',
|
text: '2',
|
||||||
'id': 'checklist-two',
|
id: 'checklist-two',
|
||||||
'completed': true
|
completed: true,
|
||||||
}, {
|
}, {
|
||||||
'text': '3',
|
text: '3',
|
||||||
'id': 'checklist-three',
|
id: 'checklist-three',
|
||||||
'completed': false
|
completed: false,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
daily.checklist = checklist;
|
daily.checklist = checklist;
|
||||||
weekly.checklist = checklist;
|
weekly.checklist = checklist;
|
||||||
cron(user);
|
cron(user);
|
||||||
_.each(daily.checklist, function(box) {
|
_.each(daily.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
return _.each(weekly.checklist, function(box) {
|
_.each(weekly.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return it('resets checklists if daily is marked as complete', function() {
|
it('resets checklists if daily is marked as complete', () => {
|
||||||
var checklist;
|
let checklist = [
|
||||||
checklist = [
|
|
||||||
{
|
{
|
||||||
'text': '1',
|
text: '1',
|
||||||
'id': 'checklist-one',
|
id: 'checklist-one',
|
||||||
'completed': true
|
completed: true,
|
||||||
}, {
|
}, {
|
||||||
'text': '2',
|
text: '2',
|
||||||
'id': 'checklist-two',
|
id: 'checklist-two',
|
||||||
'completed': true
|
completed: true,
|
||||||
}, {
|
}, {
|
||||||
'text': '3',
|
text: '3',
|
||||||
'id': 'checklist-three',
|
id: 'checklist-three',
|
||||||
'completed': false
|
completed: false,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
daily.checklist = checklist;
|
daily.checklist = checklist;
|
||||||
daily.completed = true;
|
daily.completed = true;
|
||||||
weekly.checklist = checklist;
|
weekly.checklist = checklist;
|
||||||
weekly.completed = true;
|
weekly.completed = true;
|
||||||
cron(user);
|
cron(user);
|
||||||
_.each(daily.checklist, function(box) {
|
_.each(daily.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
return _.each(weekly.checklist, function(box) {
|
_.each(weekly.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return describe('when startDate is today', function() {
|
describe('when startDate is today', () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
user = newUser();
|
user = newUser();
|
||||||
user.dailys = [
|
user.dailys = [
|
||||||
shared.taskDefaults({
|
shared.taskDefaults({
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
startDate: moment().subtract(1, 'days'),
|
startDate: moment().subtract(1, 'days'),
|
||||||
frequency: 'daily'
|
frequency: 'daily',
|
||||||
}), shared.taskDefaults({
|
}), shared.taskDefaults({
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
startDate: moment().subtract(1, 'days'),
|
startDate: moment().subtract(1, 'days'),
|
||||||
frequency: 'weekly'
|
frequency: 'weekly',
|
||||||
})
|
}),
|
||||||
];
|
];
|
||||||
daily = user.dailys[0];
|
daily = user.dailys[0];
|
||||||
return weekly = user.dailys[1];
|
weekly = user.dailys[1];
|
||||||
});
|
});
|
||||||
it('does damage user for not completing it', function() {
|
it('does damage user for not completing it', () => {
|
||||||
cron(user);
|
cron(user);
|
||||||
return expect(user.stats.hp).to.be.lessThan(50);
|
expect(user.stats.hp).to.be.lessThan(50);
|
||||||
});
|
});
|
||||||
it('decreases value on cron if daily is incomplete', function() {
|
it('decreases value on cron if daily is incomplete', () => {
|
||||||
cron(user);
|
cron(user);
|
||||||
expect(daily.value).to.be.lessThan(0);
|
expect(daily.value).to.be.lessThan(0);
|
||||||
return expect(weekly.value).to.be.lessThan(0);
|
expect(weekly.value).to.be.lessThan(0);
|
||||||
});
|
});
|
||||||
it('resets checklists if daily is not marked as complete', function() {
|
it('resets checklists if daily is not marked as complete', () => {
|
||||||
var checklist;
|
let checklist;
|
||||||
|
|
||||||
checklist = [
|
checklist = [
|
||||||
{
|
{
|
||||||
'text': '1',
|
text: '1',
|
||||||
'id': 'checklist-one',
|
id: 'checklist-one',
|
||||||
'completed': true
|
completed: true,
|
||||||
}, {
|
}, {
|
||||||
'text': '2',
|
text: '2',
|
||||||
'id': 'checklist-two',
|
id: 'checklist-two',
|
||||||
'completed': true
|
completed: true,
|
||||||
}, {
|
}, {
|
||||||
'text': '3',
|
text: '3',
|
||||||
'id': 'checklist-three',
|
id: 'checklist-three',
|
||||||
'completed': false
|
completed: false,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
daily.checklist = checklist;
|
daily.checklist = checklist;
|
||||||
weekly.checklist = checklist;
|
weekly.checklist = checklist;
|
||||||
cron(user);
|
cron(user);
|
||||||
_.each(daily.checklist, function(box) {
|
_.each(daily.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
return _.each(weekly.checklist, function(box) {
|
_.each(weekly.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return it('resets checklists if daily is marked as complete', function() {
|
it('resets checklists if daily is marked as complete', () => {
|
||||||
var checklist;
|
let checklist;
|
||||||
|
|
||||||
checklist = [
|
checklist = [
|
||||||
{
|
{
|
||||||
'text': '1',
|
text: '1',
|
||||||
'id': 'checklist-one',
|
id: 'checklist-one',
|
||||||
'completed': true
|
completed: true,
|
||||||
}, {
|
}, {
|
||||||
'text': '2',
|
text: '2',
|
||||||
'id': 'checklist-two',
|
id: 'checklist-two',
|
||||||
'completed': true
|
completed: true,
|
||||||
}, {
|
}, {
|
||||||
'text': '3',
|
text: '3',
|
||||||
'id': 'checklist-three',
|
id: 'checklist-three',
|
||||||
'completed': false
|
completed: false,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
daily.checklist = checklist;
|
daily.checklist = checklist;
|
||||||
daily.completed = true;
|
daily.completed = true;
|
||||||
weekly.checklist = checklist;
|
weekly.checklist = checklist;
|
||||||
weekly.completed = true;
|
weekly.completed = true;
|
||||||
cron(user);
|
cron(user);
|
||||||
_.each(daily.checklist, function(box) {
|
_.each(daily.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
return _.each(weekly.checklist, function(box) {
|
_.each(weekly.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('daily that repeats every x days', function() {
|
describe('daily that repeats every x days', () => {
|
||||||
var daily, user;
|
let user = null;
|
||||||
user = null;
|
let daily = null;
|
||||||
daily = null;
|
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
user = newUser();
|
user = newUser();
|
||||||
user.dailys = [
|
user.dailys = [
|
||||||
shared.taskDefaults({
|
shared.taskDefaults({
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
startDate: moment(),
|
startDate: moment(),
|
||||||
frequency: 'daily'
|
frequency: 'daily',
|
||||||
})
|
}),
|
||||||
];
|
];
|
||||||
return daily = user.dailys[0];
|
daily = user.dailys[0];
|
||||||
});
|
});
|
||||||
return _.times(11, function(due) {
|
_.times(11, (due) => {
|
||||||
return it('where x equals ' + due, function() {
|
it(`where x equals ${due}`, () => {
|
||||||
daily.everyX = due;
|
daily.everyX = due;
|
||||||
return _.times(30, function(day) {
|
_.times(30, (day) => {
|
||||||
var isDue;
|
let isDue;
|
||||||
|
|
||||||
isDue = shared.shouldDo(moment().add(day, 'days'), daily);
|
isDue = shared.shouldDo(moment().add(day, 'days'), daily);
|
||||||
if (day % due === 0) {
|
if (day % due === 0) {
|
||||||
expect(isDue).to.be(true);
|
expect(isDue).to.be(true);
|
||||||
}
|
}
|
||||||
if (day % due !== 0) {
|
if (day % due !== 0) {
|
||||||
return expect(isDue).to.be(false);
|
expect(isDue).to.be(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('daily that repeats every X days when multiple days are missed', function() {
|
describe('daily that repeats every X days when multiple days are missed', () => {
|
||||||
var daily, everyX, startDateDaysAgo, user;
|
let everyX = 3;
|
||||||
everyX = 3;
|
let startDateDaysAgo = everyX * 3;
|
||||||
startDateDaysAgo = everyX * 3;
|
let user = null;
|
||||||
user = null;
|
let daily = null;
|
||||||
daily = null;
|
|
||||||
describe('including missing a due date', function() {
|
describe('including missing a due date', () => {
|
||||||
var missedDays;
|
let missedDays = everyX * 2 + 1;
|
||||||
missedDays = everyX * 2 + 1;
|
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
user = newUser();
|
user = newUser();
|
||||||
user.dailys = [
|
user.dailys = [
|
||||||
shared.taskDefaults({
|
shared.taskDefaults({
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
startDate: moment().subtract(startDateDaysAgo, 'days'),
|
startDate: moment().subtract(startDateDaysAgo, 'days'),
|
||||||
frequency: 'daily',
|
frequency: 'daily',
|
||||||
everyX: everyX
|
everyX,
|
||||||
})
|
}),
|
||||||
];
|
];
|
||||||
return daily = user.dailys[0];
|
daily = user.dailys[0];
|
||||||
});
|
});
|
||||||
it('decreases value on cron once only if daily is incomplete', function() {
|
it('decreases value on cron once only if daily is incomplete', () => {
|
||||||
cron(user, missedDays);
|
cron(user, missedDays);
|
||||||
return expect(daily.value).to.be(-1);
|
expect(daily.value).to.be(-1);
|
||||||
});
|
});
|
||||||
it('resets checklists if daily is incomplete', function() {
|
it('resets checklists if daily is incomplete', () => {
|
||||||
var checklist;
|
let checklist = [
|
||||||
checklist = [
|
|
||||||
{
|
{
|
||||||
'text': '1',
|
text: '1',
|
||||||
'id': 'checklist-one',
|
id: 'checklist-one',
|
||||||
'completed': true
|
completed: true,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
daily.checklist = checklist;
|
daily.checklist = checklist;
|
||||||
cron(user, missedDays);
|
cron(user, missedDays);
|
||||||
return _.each(daily.checklist, function(box) {
|
_.each(daily.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return it('resets checklists if daily is marked as complete', function() {
|
it('resets checklists if daily is marked as complete', () => {
|
||||||
var checklist;
|
let checklist;
|
||||||
|
|
||||||
checklist = [
|
checklist = [
|
||||||
{
|
{
|
||||||
'text': '1',
|
text: '1',
|
||||||
'id': 'checklist-one',
|
id: 'checklist-one',
|
||||||
'completed': true
|
completed: true,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
daily.checklist = checklist;
|
daily.checklist = checklist;
|
||||||
daily.completed = true;
|
daily.completed = true;
|
||||||
cron(user, missedDays);
|
cron(user, missedDays);
|
||||||
return _.each(daily.checklist, function(box) {
|
_.each(daily.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return describe('but not missing a due date', function() {
|
describe('but not missing a due date', () => {
|
||||||
var missedDays;
|
let missedDays;
|
||||||
|
|
||||||
missedDays = everyX - 1;
|
missedDays = everyX - 1;
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
user = newUser();
|
user = newUser();
|
||||||
user.dailys = [
|
user.dailys = [
|
||||||
shared.taskDefaults({
|
shared.taskDefaults({
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
startDate: moment().subtract(startDateDaysAgo, 'days'),
|
startDate: moment().subtract(startDateDaysAgo, 'days'),
|
||||||
frequency: 'daily',
|
frequency: 'daily',
|
||||||
everyX: everyX
|
everyX,
|
||||||
})
|
}),
|
||||||
];
|
];
|
||||||
return daily = user.dailys[0];
|
daily = user.dailys[0];
|
||||||
});
|
});
|
||||||
it('does not decrease value on cron', function() {
|
it('does not decrease value on cron', () => {
|
||||||
cron(user, missedDays);
|
cron(user, missedDays);
|
||||||
return expect(daily.value).to.be(0);
|
expect(daily.value).to.be(0);
|
||||||
});
|
});
|
||||||
it('does not reset checklists if daily is incomplete', function() {
|
it('does not reset checklists if daily is incomplete', () => {
|
||||||
var checklist;
|
let checklist;
|
||||||
|
|
||||||
checklist = [
|
checklist = [
|
||||||
{
|
{
|
||||||
'text': '1',
|
text: '1',
|
||||||
'id': 'checklist-one',
|
id: 'checklist-one',
|
||||||
'completed': true
|
completed: true,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
daily.checklist = checklist;
|
daily.checklist = checklist;
|
||||||
cron(user, missedDays);
|
cron(user, missedDays);
|
||||||
return _.each(daily.checklist, function(box) {
|
_.each(daily.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(true);
|
expect(box.completed).to.be(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return it('resets checklists if daily is marked as complete', function() {
|
it('resets checklists if daily is marked as complete', () => {
|
||||||
var checklist;
|
let checklist;
|
||||||
|
|
||||||
checklist = [
|
checklist = [
|
||||||
{
|
{
|
||||||
'text': '1',
|
text: 1,
|
||||||
'id': 'checklist-one',
|
id: 'checklist-one',
|
||||||
'completed': true
|
completed: true,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
daily.checklist = checklist;
|
daily.checklist = checklist;
|
||||||
daily.completed = true;
|
daily.completed = true;
|
||||||
cron(user, missedDays);
|
cron(user, missedDays);
|
||||||
return _.each(daily.checklist, function(box) {
|
_.each(daily.checklist, (box) => {
|
||||||
return expect(box.completed).to.be(false);
|
expect(box.completed).to.be(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,53 +1,59 @@
|
|||||||
var expect;
|
/* eslint-disable prefer-template, no-shadow, func-names */
|
||||||
|
|
||||||
expect = require('expect.js');
|
let expect = require('expect.js');
|
||||||
|
|
||||||
|
module.exports.addCustomMatchers = function () {
|
||||||
|
let Assertion;
|
||||||
|
|
||||||
module.exports.addCustomMatchers = function() {
|
|
||||||
var Assertion;
|
|
||||||
Assertion = expect.Assertion;
|
Assertion = expect.Assertion;
|
||||||
Assertion.prototype.toHaveGP = function(gp) {
|
Assertion.prototype.toHaveGP = function (gp) {
|
||||||
var actual;
|
let actual;
|
||||||
|
|
||||||
actual = this.obj.stats.gp;
|
actual = this.obj.stats.gp;
|
||||||
return this.assert(actual === gp, function() {
|
return this.assert(actual === gp, () => {
|
||||||
return "expected user to have " + gp + " gp, but got " + actual;
|
return 'expected user to have ' + gp + ' gp, but got ' + actual;
|
||||||
}, function() {
|
}, () => {
|
||||||
return "expected user to not have " + gp + " gp";
|
return 'expected user to not have ' + gp + ' gp';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Assertion.prototype.toHaveHP = function(hp) {
|
Assertion.prototype.toHaveHP = function (hp) {
|
||||||
var actual;
|
let actual;
|
||||||
|
|
||||||
actual = this.obj.stats.hp;
|
actual = this.obj.stats.hp;
|
||||||
return this.assert(actual === hp, function() {
|
return this.assert(actual === hp, () => {
|
||||||
return "expected user to have " + hp + " hp, but got " + actual;
|
return 'expected user to have ' + hp + ' hp, but got ' + actual;
|
||||||
}, function() {
|
}, () => {
|
||||||
return "expected user to not have " + hp + " hp";
|
return 'expected user to not have ' + hp + ' hp';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Assertion.prototype.toHaveExp = function(exp) {
|
Assertion.prototype.toHaveExp = function (exp) {
|
||||||
var actual;
|
let actual;
|
||||||
|
|
||||||
actual = this.obj.stats.exp;
|
actual = this.obj.stats.exp;
|
||||||
return this.assert(actual === exp, function() {
|
return this.assert(actual === exp, () => {
|
||||||
return "expected user to have " + exp + " experience points, but got " + actual;
|
return 'expected user to have ' + exp + ' experience points, but got ' + actual;
|
||||||
}, function() {
|
}, () => {
|
||||||
return "expected user to not have " + exp + " experience points";
|
return 'expected user to not have ' + exp + ' experience points';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Assertion.prototype.toHaveLevel = function(lvl) {
|
Assertion.prototype.toHaveLevel = function (lvl) {
|
||||||
var actual;
|
let actual;
|
||||||
|
|
||||||
actual = this.obj.stats.lvl;
|
actual = this.obj.stats.lvl;
|
||||||
return this.assert(actual === lvl, function() {
|
return this.assert(actual === lvl, () => {
|
||||||
return "expected user to be level " + lvl + ", but got " + actual;
|
return 'expected user to be level ' + lvl + ', but got ' + actual;
|
||||||
}, function() {
|
}, () => {
|
||||||
return "expected user to not be level " + lvl;
|
return 'expected user to not be level ' + lvl;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return Assertion.prototype.toHaveMaxMP = function(mp) {
|
Assertion.prototype.toHaveMaxMP = function (mp) {
|
||||||
var actual;
|
let actual;
|
||||||
|
|
||||||
actual = this.obj._statsComputed.maxMP;
|
actual = this.obj._statsComputed.maxMP;
|
||||||
return this.assert(actual === mp, function() {
|
return this.assert(actual === mp, () => {
|
||||||
return "expected user to have " + mp + " max mp, but got " + actual;
|
return 'expected user to have ' + mp + ' max mp, but got ' + actual;
|
||||||
}, function() {
|
}, () => {
|
||||||
return "expected user to not have " + mp + " max mp";
|
return 'expected user to not have ' + mp + ' max mp';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,30 +1,28 @@
|
|||||||
var sinon = require('sinon');
|
/* eslint-disable camelcase */
|
||||||
var chai = require("chai")
|
|
||||||
chai.use(require("sinon-chai"))
|
|
||||||
var expect = chai.expect
|
|
||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
var shared = require('../../common/script/index.js');
|
import sinon from 'sinon'; // eslint-disable-line no-shadow
|
||||||
|
|
||||||
describe('user.fns.buy', function() {
|
let shared = require('../../common/script/index.js');
|
||||||
var user;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
describe('user.fns.buy', () => {
|
||||||
|
let user;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
user = {
|
user = {
|
||||||
items: {
|
items: {
|
||||||
gear: {
|
gear: {
|
||||||
owned: {
|
owned: {
|
||||||
weapon_warrior_0: true
|
weapon_warrior_0: true,
|
||||||
},
|
},
|
||||||
equipped: {
|
equipped: {
|
||||||
weapon_warrior_0: true
|
weapon_warrior_0: true,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
preferences: {},
|
preferences: {},
|
||||||
stats: { gp: 200 },
|
stats: { gp: 200 },
|
||||||
achievements: { },
|
achievements: { },
|
||||||
flags: { }
|
flags: { },
|
||||||
};
|
};
|
||||||
|
|
||||||
shared.wrap(user);
|
shared.wrap(user);
|
||||||
@@ -33,32 +31,32 @@ describe('user.fns.buy', function() {
|
|||||||
sinon.stub(user.fns, 'predictableRandom');
|
sinon.stub(user.fns, 'predictableRandom');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(() => {
|
||||||
user.fns.randomVal.restore();
|
user.fns.randomVal.restore();
|
||||||
user.fns.predictableRandom.restore();
|
user.fns.predictableRandom.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
context('Potion', function() {
|
context('Potion', () => {
|
||||||
it('recovers 15 hp', function() {
|
it('recovers 15 hp', () => {
|
||||||
user.stats.hp = 30;
|
user.stats.hp = 30;
|
||||||
user.ops.buy({params: {key: 'potion'}});
|
user.ops.buy({params: {key: 'potion'}});
|
||||||
expect(user.stats.hp).to.eql(45);
|
expect(user.stats.hp).to.eql(45);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not increase hp above 50', function() {
|
it('does not increase hp above 50', () => {
|
||||||
user.stats.hp = 45;
|
user.stats.hp = 45;
|
||||||
user.ops.buy({params: {key: 'potion'}});
|
user.ops.buy({params: {key: 'potion'}});
|
||||||
expect(user.stats.hp).to.eql(50);
|
expect(user.stats.hp).to.eql(50);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('deducts 25 gp', function() {
|
it('deducts 25 gp', () => {
|
||||||
user.stats.hp = 45;
|
user.stats.hp = 45;
|
||||||
user.ops.buy({params: {key: 'potion'}});
|
user.ops.buy({params: {key: 'potion'}});
|
||||||
|
|
||||||
expect(user.stats.gp).to.eql(175);
|
expect(user.stats.gp).to.eql(175);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not purchase if not enough gp', function() {
|
it('does not purchase if not enough gp', () => {
|
||||||
user.stats.hp = 45;
|
user.stats.hp = 45;
|
||||||
user.stats.gp = 5;
|
user.stats.gp = 5;
|
||||||
user.ops.buy({params: {key: 'potion'}});
|
user.ops.buy({params: {key: 'potion'}});
|
||||||
@@ -68,8 +66,8 @@ describe('user.fns.buy', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('Gear', function() {
|
context('Gear', () => {
|
||||||
it('adds equipment to inventory', function() {
|
it('adds equipment to inventory', () => {
|
||||||
user.stats.gp = 31;
|
user.stats.gp = 31;
|
||||||
|
|
||||||
user.ops.buy({params: {key: 'armor_warrior_1'}});
|
user.ops.buy({params: {key: 'armor_warrior_1'}});
|
||||||
@@ -77,7 +75,7 @@ describe('user.fns.buy', function() {
|
|||||||
expect(user.items.gear.owned).to.eql({ weapon_warrior_0: true, armor_warrior_1: true });
|
expect(user.items.gear.owned).to.eql({ weapon_warrior_0: true, armor_warrior_1: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('deducts gold from user', function() {
|
it('deducts gold from user', () => {
|
||||||
user.stats.gp = 31;
|
user.stats.gp = 31;
|
||||||
|
|
||||||
user.ops.buy({params: {key: 'armor_warrior_1'}});
|
user.ops.buy({params: {key: 'armor_warrior_1'}});
|
||||||
@@ -85,7 +83,7 @@ describe('user.fns.buy', function() {
|
|||||||
expect(user.stats.gp).to.eql(1);
|
expect(user.stats.gp).to.eql(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('auto equips equipment if user has auto-equip preference turned on', function() {
|
it('auto equips equipment if user has auto-equip preference turned on', () => {
|
||||||
user.stats.gp = 31;
|
user.stats.gp = 31;
|
||||||
user.preferences.autoEquip = true;
|
user.preferences.autoEquip = true;
|
||||||
|
|
||||||
@@ -94,7 +92,7 @@ describe('user.fns.buy', function() {
|
|||||||
expect(user.items.gear.equipped).to.have.property('armor', 'armor_warrior_1');
|
expect(user.items.gear.equipped).to.have.property('armor', 'armor_warrior_1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('buys equipment but does not auto-equip', function() {
|
it('buys equipment but does not auto-equip', () => {
|
||||||
user.stats.gp = 31;
|
user.stats.gp = 31;
|
||||||
user.preferences.autoEquip = false;
|
user.preferences.autoEquip = false;
|
||||||
|
|
||||||
@@ -103,7 +101,7 @@ describe('user.fns.buy', function() {
|
|||||||
expect(user.items.gear.equipped).to.not.have.property('armor');
|
expect(user.items.gear.equipped).to.not.have.property('armor');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not buy equipment without enough Gold', function() {
|
it('does not buy equipment without enough Gold', () => {
|
||||||
user.stats.gp = 20;
|
user.stats.gp = 20;
|
||||||
|
|
||||||
user.ops.buy({params: {key: 'armor_warrior_1'}});
|
user.ops.buy({params: {key: 'armor_warrior_1'}});
|
||||||
@@ -112,7 +110,7 @@ describe('user.fns.buy', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('Quests', function() {
|
context('Quests', () => {
|
||||||
it('buys a Quest scroll');
|
it('buys a Quest scroll');
|
||||||
|
|
||||||
it('does not buy Quests without enough Gold');
|
it('does not buy Quests without enough Gold');
|
||||||
@@ -122,48 +120,49 @@ describe('user.fns.buy', function() {
|
|||||||
it('does not buy Gem-premium Quests');
|
it('does not buy Gem-premium Quests');
|
||||||
});
|
});
|
||||||
|
|
||||||
context('Enchanted Armoire', function() {
|
context('Enchanted Armoire', () => {
|
||||||
var YIELD_EQUIPMENT = .5;
|
let YIELD_EQUIPMENT = 0.5;
|
||||||
var YIELD_FOOD = .7;
|
let YIELD_FOOD = 0.7;
|
||||||
var YIELD_EXP = .9;
|
let YIELD_EXP = 0.9;
|
||||||
|
|
||||||
var fullArmoire = {}
|
let fullArmoire = {};
|
||||||
|
|
||||||
_(shared.content.gearTypes).each(function(type) {
|
_(shared.content.gearTypes).each((type) => {
|
||||||
_(shared.content.gear.tree[type].armoire).each(function(gearObject, gearName) {
|
_(shared.content.gear.tree[type].armoire).each((gearObject) => {
|
||||||
let armoireKey = gearObject.key;
|
let armoireKey = gearObject.key;
|
||||||
|
|
||||||
fullArmoire[armoireKey] = true;
|
fullArmoire[armoireKey] = true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
user.achievements.ultimateGearSets = { rogue: true };
|
user.achievements.ultimateGearSets = { rogue: true };
|
||||||
user.flags.armoireOpened = true;
|
user.flags.armoireOpened = true;
|
||||||
user.stats.exp = 0;
|
user.stats.exp = 0;
|
||||||
user.items.food = {};
|
user.items.food = {};
|
||||||
});
|
});
|
||||||
|
|
||||||
context('failure conditions', function() {
|
context('failure conditions', () => {
|
||||||
it('does not open if user does not have enough gold', function(done) {
|
it('does not open if user does not have enough gold', (done) => {
|
||||||
user.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
user.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||||
user.stats.gp = 50;
|
user.stats.gp = 50;
|
||||||
|
|
||||||
user.ops.buy({params: {key: 'armoire'}}, function(response) {
|
user.ops.buy({params: {key: 'armoire'}}, (response) => {
|
||||||
expect(response.message).to.eql('Not Enough Gold');
|
expect(response.message).to.eql('Not Enough Gold');
|
||||||
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.items.food).to.be.empty;
|
||||||
expect(user.stats.exp).to.eql(0);
|
expect(user.stats.exp).to.eql(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not open without Ultimate Gear achievement',function(done) {
|
it('does not open without Ultimate Gear achievement', (done) => {
|
||||||
user.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
user.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||||
user.achievements.ultimateGearSets = {'healer':false,'wizard':false,'rogue':false,'warrior':false};
|
user.achievements.ultimateGearSets = {healer: false, wizard: false, rogue: false, warrior: false};
|
||||||
|
|
||||||
user.ops.buy({params: {key: 'armoire'}}, function(response) {
|
user.ops.buy({params: {key: 'armoire'}}, (response) => {
|
||||||
expect(response.message).to.eql("You can't buy this item");
|
expect(response.message).to.eql('You can\'t buy this item');
|
||||||
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.items.food).to.be.empty;
|
||||||
expect(user.stats.exp).to.eql(0);
|
expect(user.stats.exp).to.eql(0);
|
||||||
done();
|
done();
|
||||||
@@ -171,32 +170,33 @@ describe('user.fns.buy', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('non-gear awards', function() {
|
context('non-gear awards', () => {
|
||||||
it('gives Experience', function() {
|
it('gives Experience', () => {
|
||||||
user.fns.predictableRandom.returns(YIELD_EXP);
|
user.fns.predictableRandom.returns(YIELD_EXP);
|
||||||
|
|
||||||
user.ops.buy({params: {key: 'armoire'}})
|
user.ops.buy({params: {key: 'armoire'}});
|
||||||
|
|
||||||
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.items.food).to.be.empty;
|
||||||
expect(user.stats.exp).to.eql(46);
|
expect(user.stats.exp).to.eql(46);
|
||||||
expect(user.stats.gp).to.eql(100);
|
expect(user.stats.gp).to.eql(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('gives food', function() {
|
it('gives food', () => {
|
||||||
var honey = shared.content.food.Honey;
|
let honey = shared.content.food.Honey;
|
||||||
|
|
||||||
user.fns.randomVal.returns(honey);
|
user.fns.randomVal.returns(honey);
|
||||||
user.fns.predictableRandom.returns(YIELD_FOOD);
|
user.fns.predictableRandom.returns(YIELD_FOOD);
|
||||||
|
|
||||||
user.ops.buy({params: {key: 'armoire'}})
|
user.ops.buy({params: {key: 'armoire'}});
|
||||||
|
|
||||||
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.eql({'Honey': 1});
|
expect(user.items.food).to.eql({Honey: 1});
|
||||||
expect(user.stats.exp).to.eql(0);
|
expect(user.stats.exp).to.eql(0);
|
||||||
expect(user.stats.gp).to.eql(100);
|
expect(user.stats.gp).to.eql(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not give equipment if all equipment has been found', function() {
|
it('does not give equipment if all equipment has been found', () => {
|
||||||
user.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
user.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||||
user.items.gear.owned = fullArmoire;
|
user.items.gear.owned = fullArmoire;
|
||||||
user.stats.gp = 150;
|
user.stats.gp = 150;
|
||||||
@@ -204,7 +204,8 @@ describe('user.fns.buy', function() {
|
|||||||
user.ops.buy({params: {key: 'armoire'}});
|
user.ops.buy({params: {key: 'armoire'}});
|
||||||
|
|
||||||
expect(user.items.gear.owned).to.eql(fullArmoire);
|
expect(user.items.gear.owned).to.eql(fullArmoire);
|
||||||
var armoireCount = shared.count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
let armoireCount = shared.count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||||
|
|
||||||
expect(armoireCount).to.eql(0);
|
expect(armoireCount).to.eql(0);
|
||||||
|
|
||||||
expect(user.stats.exp).to.eql(30);
|
expect(user.stats.exp).to.eql(30);
|
||||||
@@ -212,43 +213,46 @@ describe('user.fns.buy', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('gear awards', function() {
|
context('gear awards', () => {
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
var shield = shared.content.gear.tree.shield.armoire.gladiatorShield;
|
let shield = shared.content.gear.tree.shield.armoire.gladiatorShield;
|
||||||
|
|
||||||
user.fns.randomVal.returns(shield);
|
user.fns.randomVal.returns(shield);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('always drops equipment the first time', function() {
|
it('always drops equipment the first time', () => {
|
||||||
delete user.flags.armoireOpened;
|
delete user.flags.armoireOpened;
|
||||||
user.fns.predictableRandom.returns(YIELD_EXP);
|
user.fns.predictableRandom.returns(YIELD_EXP);
|
||||||
|
|
||||||
user.ops.buy({params: {key: 'armoire'}});
|
user.ops.buy({params: {key: 'armoire'}});
|
||||||
|
|
||||||
expect(user.items.gear.owned).to.eql({
|
expect(user.items.gear.owned).to.eql({
|
||||||
'weapon_warrior_0': true,
|
weapon_warrior_0: true,
|
||||||
'shield_armoire_gladiatorShield': true
|
shield_armoire_gladiatorShield: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
var armoireCount = shared.count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
let armoireCount = shared.count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||||
expect(armoireCount).to.eql (_.size(fullArmoire) - 1)
|
|
||||||
|
expect(armoireCount).to.eql(_.size(fullArmoire) - 1);
|
||||||
expect(user.items.food).to.be.empty;
|
expect(user.items.food).to.be.empty;
|
||||||
expect(user.stats.exp).to.eql(0);
|
expect(user.stats.exp).to.eql(0);
|
||||||
expect(user.stats.gp).to.eql(100);
|
expect(user.stats.gp).to.eql(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('gives more equipment', function() {
|
it('gives more equipment', () => {
|
||||||
user.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
user.fns.predictableRandom.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,
|
||||||
};
|
};
|
||||||
user.stats.gp = 200;
|
user.stats.gp = 200;
|
||||||
|
|
||||||
user.ops.buy({params: {key: 'armoire'}});
|
user.ops.buy({params: {key: 'armoire'}});
|
||||||
|
|
||||||
expect(user.items.gear.owned).to.eql({'weapon_warrior_0': true, 'shield_armoire_gladiatorShield':true, 'head_armoire_hornedIronHelm':true});
|
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true, shield_armoire_gladiatorShield: true, head_armoire_hornedIronHelm: true});
|
||||||
var armoireCount = shared.count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
let armoireCount = shared.count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||||
expect(armoireCount).to.eql((_.size(fullArmoire) - 2));
|
|
||||||
|
expect(armoireCount).to.eql(_.size(fullArmoire) - 2);
|
||||||
expect(user.stats.gp).to.eql(100);
|
expect(user.stats.gp).to.eql(100);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,25 +1,36 @@
|
|||||||
var shared = require('../../common/script/index.js');
|
/* eslint-disable camelcase */
|
||||||
shared.i18n.translations = require('../../website/src/libs/i18n.js').translations
|
|
||||||
|
let shared = require('../../common/script/index.js');
|
||||||
|
|
||||||
|
shared.i18n.translations = require('../../website/src/libs/i18n.js').translations;
|
||||||
|
|
||||||
require('./test_helper');
|
require('./test_helper');
|
||||||
|
|
||||||
describe('User.fns.ultimateGear', function() {
|
describe('User.fns.ultimateGear', () => {
|
||||||
|
it('sets armoirEnabled when partial achievement already achieved', () => {
|
||||||
it('sets armoirEnabled when partial achievement already achieved', function() {
|
let items = {
|
||||||
var user = shared.wrap({
|
gear: {
|
||||||
items: { gear: { owned: {
|
owned: {
|
||||||
toObject: function() { return {
|
toObject: () => {
|
||||||
armor_warrior_5: true,
|
return {
|
||||||
shield_warrior_5: true,
|
armor_warrior_5: true,
|
||||||
head_warrior_5: true,
|
shield_warrior_5: true,
|
||||||
weapon_warrior_6: true
|
head_warrior_5: true,
|
||||||
}}
|
weapon_warrior_6: true,
|
||||||
}}},
|
};
|
||||||
achievements: {
|
},
|
||||||
ultimateGearSets: {}
|
},
|
||||||
},
|
},
|
||||||
flags: {}
|
};
|
||||||
|
|
||||||
|
let user = shared.wrap({
|
||||||
|
items,
|
||||||
|
achievements: {
|
||||||
|
ultimateGearSets: {},
|
||||||
|
},
|
||||||
|
flags: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
user.fns.ultimateGear();
|
user.fns.ultimateGear();
|
||||||
expect(user.flags.armoireEnabled).to.equal(true);
|
expect(user.flags.armoireEnabled).to.equal(true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,79 +1,73 @@
|
|||||||
var sinon = require('sinon');
|
/* eslint-disable camelcase */
|
||||||
var chai = require("chai")
|
|
||||||
chai.use(require("sinon-chai"))
|
|
||||||
var expect = chai.expect
|
|
||||||
|
|
||||||
var shared = require('../../common/script/index.js');
|
let shared = require('../../common/script/index.js');
|
||||||
var Content = require('../../common/script/content/index.js');
|
|
||||||
|
|
||||||
describe('user.ops.buyMysterySet', function() {
|
describe('user.ops.buyMysterySet', () => {
|
||||||
var user;
|
let user;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(() => {
|
||||||
user = {
|
user = {
|
||||||
items: {
|
items: {
|
||||||
gear: {
|
gear: {
|
||||||
owned: {
|
owned: {
|
||||||
weapon_warrior_0: true
|
weapon_warrior_0: true,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
purchased: {
|
purchased: {
|
||||||
plan: {
|
plan: {
|
||||||
consecutive: {
|
consecutive: {
|
||||||
trinkets: 0
|
trinkets: 0,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
shared.wrap(user);
|
shared.wrap(user);
|
||||||
});
|
});
|
||||||
|
|
||||||
context('Mystery Sets', function() {
|
context('Mystery Sets', () => {
|
||||||
|
context('failure conditions', () => {
|
||||||
context('failure conditions', function() {
|
it('does not grant mystery sets without Mystic Hourglasses', (done) => {
|
||||||
|
user.ops.buyMysterySet({params: {key: '201501'}}, (response) => {
|
||||||
it('does not grant mystery sets without Mystic Hourglasses', function(done) {
|
expect(response.message).to.eql('You don\'t have enough Mystic Hourglasses.');
|
||||||
user.ops.buyMysterySet({params:{key:'201501'}}, function(response) {
|
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||||
expect(response.message).to.eql("You don't have enough Mystic Hourglasses.");
|
|
||||||
expect(user.items.gear.owned).to.eql({'weapon_warrior_0': true});
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not grant mystery set that has already been purchased', function(done) {
|
it('does not grant mystery set that has already been purchased', (done) => {
|
||||||
user.purchased.plan.consecutive.trinkets = 1;
|
user.purchased.plan.consecutive.trinkets = 1;
|
||||||
user.items.gear.owned = {
|
user.items.gear.owned = {
|
||||||
weapon_warrior_0: true,
|
weapon_warrior_0: true,
|
||||||
weapon_mystery_301404: true,
|
weapon_mystery_301404: true,
|
||||||
armor_mystery_301404: true,
|
armor_mystery_301404: true,
|
||||||
head_mystery_301404: true,
|
head_mystery_301404: true,
|
||||||
eyewear_mystery_301404: true
|
eyewear_mystery_301404: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
user.ops.buyMysterySet({params:{key:'301404'}}, function(response) {
|
user.ops.buyMysterySet({params: {key: '301404'}}, (response) => {
|
||||||
expect(response.message).to.eql("Mystery set not found, or set already owned");
|
expect(response.message).to.eql('Mystery set not found, or set already owned');
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('successful purchases', function() {
|
context('successful purchases', () => {
|
||||||
|
it('buys Steampunk Accessories Set', (done) => {
|
||||||
it('buys Steampunk Accessories Set', function(done) {
|
|
||||||
user.purchased.plan.consecutive.trinkets = 1;
|
user.purchased.plan.consecutive.trinkets = 1;
|
||||||
|
|
||||||
user.ops.buyMysterySet({params:{key:'301404'}}, function() {
|
user.ops.buyMysterySet({params: {key: '301404'}}, () => {
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(0);
|
expect(user.purchased.plan.consecutive.trinkets).to.eql(0);
|
||||||
expect(user.items.gear.owned).to.eql({
|
expect(user.items.gear.owned).to.eql({
|
||||||
weapon_warrior_0: true,
|
weapon_warrior_0: true,
|
||||||
weapon_mystery_301404: true,
|
weapon_mystery_301404: true,
|
||||||
armor_mystery_301404: true,
|
armor_mystery_301404: true,
|
||||||
head_mystery_301404: true,
|
head_mystery_301404: true,
|
||||||
eyewear_mystery_301404: true
|
eyewear_mystery_301404: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,135 +1,126 @@
|
|||||||
var sinon = require('sinon');
|
let shared = require('../../common/script/index.js');
|
||||||
var chai = require('chai');
|
|
||||||
chai.use(require('sinon-chai'))
|
|
||||||
var expect = chai.expect
|
|
||||||
|
|
||||||
var shared = require('../../common/script/index.js');
|
describe('user.ops.hatch', () => {
|
||||||
var content = require('../../common/script/content/index.js');
|
let user;
|
||||||
|
|
||||||
describe('user.ops.hatch', function() {
|
beforeEach(() => {
|
||||||
var user;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
user = {
|
user = {
|
||||||
items: {
|
items: {
|
||||||
eggs: {},
|
eggs: {},
|
||||||
hatchingPotions: {},
|
hatchingPotions: {},
|
||||||
pets: {}
|
pets: {},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
shared.wrap(user);
|
shared.wrap(user);
|
||||||
});
|
});
|
||||||
|
|
||||||
context('Pet Hatching', function() {
|
context('Pet Hatching', () => {
|
||||||
|
context('failure conditions', () => {
|
||||||
context('failure conditions', function() {
|
it('does not allow hatching without specifying egg and potion', (done) => {
|
||||||
|
user.ops.hatch({params: {}}, (response) => {
|
||||||
it('does not allow hatching without specifying egg and potion', function(done) {
|
|
||||||
user.ops.hatch({params:{}},function(response) {
|
|
||||||
expect(response.message).to.eql('Please specify query.egg & query.hatchingPotion');
|
expect(response.message).to.eql('Please specify query.egg & query.hatchingPotion');
|
||||||
expect(user.items.pets).to.be.empty;
|
expect(user.items.pets).to.be.empty;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not allow hatching if user lacks specified egg', function(done) {
|
it('does not allow hatching if user lacks specified egg', (done) => {
|
||||||
user.items.eggs = {'Wolf':1};
|
user.items.eggs = {Wolf: 1};
|
||||||
user.items.hatchingPotions = {'Base':1};
|
user.items.hatchingPotions = {Base: 1};
|
||||||
user.ops.hatch({params:{egg:'Dragon',hatchingPotion:'Base'}}, function(response) {
|
user.ops.hatch({params: {egg: 'Dragon', hatchingPotion: 'Base'}}, (response) => {
|
||||||
expect(response.message).to.eql(shared.i18n.t('messageMissingEggPotion'));
|
expect(response.message).to.eql(shared.i18n.t('messageMissingEggPotion'));
|
||||||
expect(user.items.pets).to.be.empty;
|
expect(user.items.pets).to.be.empty;
|
||||||
expect(user.items.eggs).to.eql({'Wolf':1});
|
expect(user.items.eggs).to.eql({Wolf: 1});
|
||||||
expect(user.items.hatchingPotions).to.eql({'Base':1});
|
expect(user.items.hatchingPotions).to.eql({Base: 1});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not allow hatching if user lacks specified hatching potion', function(done) {
|
it('does not allow hatching if user lacks specified hatching potion', (done) => {
|
||||||
user.items.eggs = {'Wolf':1};
|
user.items.eggs = {Wolf: 1};
|
||||||
user.items.hatchingPotions = {'Base':1};
|
user.items.hatchingPotions = {Base: 1};
|
||||||
user.ops.hatch({params:{egg:'Wolf',hatchingPotion:'Golden'}}, function(response) {
|
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Golden'}}, (response) => {
|
||||||
expect(response.message).to.eql(shared.i18n.t('messageMissingEggPotion'));
|
expect(response.message).to.eql(shared.i18n.t('messageMissingEggPotion'));
|
||||||
expect(user.items.pets).to.be.empty;
|
expect(user.items.pets).to.be.empty;
|
||||||
expect(user.items.eggs).to.eql({'Wolf':1});
|
expect(user.items.eggs).to.eql({Wolf: 1});
|
||||||
expect(user.items.hatchingPotions).to.eql({'Base':1});
|
expect(user.items.hatchingPotions).to.eql({Base: 1});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not allow hatching if user already owns target pet', function(done) {
|
it('does not allow hatching if user already owns target pet', (done) => {
|
||||||
user.items.eggs = {'Wolf':1};
|
user.items.eggs = {Wolf: 1};
|
||||||
user.items.hatchingPotions = {'Base':1};
|
user.items.hatchingPotions = {Base: 1};
|
||||||
user.items.pets = {'Wolf-Base':10};
|
user.items.pets = {'Wolf-Base': 10};
|
||||||
user.ops.hatch({params:{egg:'Wolf',hatchingPotion:'Base'}}, function(response) {
|
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Base'}}, (response) => {
|
||||||
expect(response.message).to.eql(shared.i18n.t('messageAlreadyPet'));
|
expect(response.message).to.eql(shared.i18n.t('messageAlreadyPet'));
|
||||||
expect(user.items.pets).to.eql({'Wolf-Base':10});
|
expect(user.items.pets).to.eql({'Wolf-Base': 10});
|
||||||
expect(user.items.eggs).to.eql({'Wolf':1});
|
expect(user.items.eggs).to.eql({Wolf: 1});
|
||||||
expect(user.items.hatchingPotions).to.eql({'Base':1});
|
expect(user.items.hatchingPotions).to.eql({Base: 1});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not allow hatching quest pet egg using premium potion', function(done) {
|
it('does not allow hatching quest pet egg using premium potion', (done) => {
|
||||||
user.items.eggs = {'Cheetah':1};
|
user.items.eggs = {Cheetah: 1};
|
||||||
user.items.hatchingPotions = {'Spooky':1};
|
user.items.hatchingPotions = {Spooky: 1};
|
||||||
user.ops.hatch({params:{egg:'Cheetah',hatchingPotion:'Spooky'}}, function(response) {
|
user.ops.hatch({params: {egg: 'Cheetah', hatchingPotion: 'Spooky'}}, (response) => {
|
||||||
expect(response.message).to.eql(shared.i18n.t('messageInvalidEggPotionCombo'));
|
expect(response.message).to.eql(shared.i18n.t('messageInvalidEggPotionCombo'));
|
||||||
expect(user.items.pets).to.be.empty;
|
expect(user.items.pets).to.be.empty;
|
||||||
expect(user.items.eggs).to.eql({'Cheetah':1});
|
expect(user.items.eggs).to.eql({Cheetah: 1});
|
||||||
expect(user.items.hatchingPotions).to.eql({'Spooky':1});
|
expect(user.items.hatchingPotions).to.eql({Spooky: 1});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('successful hatching', function() {
|
context('successful hatching', () => {
|
||||||
|
it('hatches a basic pet', (done) => {
|
||||||
it('hatches a basic pet', function(done) {
|
user.items.eggs = {Wolf: 1};
|
||||||
user.items.eggs = {'Wolf':1};
|
user.items.hatchingPotions = {Base: 1};
|
||||||
user.items.hatchingPotions = {'Base':1};
|
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Base'}}, (response) => {
|
||||||
user.ops.hatch({params:{egg:'Wolf',hatchingPotion:'Base'}}, function(response) {
|
|
||||||
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
|
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
|
||||||
expect(user.items.pets).to.eql({'Wolf-Base':5});
|
expect(user.items.pets).to.eql({'Wolf-Base': 5});
|
||||||
expect(user.items.eggs).to.eql({'Wolf':0});
|
expect(user.items.eggs).to.eql({Wolf: 0});
|
||||||
expect(user.items.hatchingPotions).to.eql({'Base':0});
|
expect(user.items.hatchingPotions).to.eql({Base: 0});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hatches a quest pet', function(done) {
|
it('hatches a quest pet', (done) => {
|
||||||
user.items.eggs = {'Cheetah':1};
|
user.items.eggs = {Cheetah: 1};
|
||||||
user.items.hatchingPotions = {'Base':1};
|
user.items.hatchingPotions = {Base: 1};
|
||||||
user.ops.hatch({params:{egg:'Cheetah',hatchingPotion:'Base'}}, function(response) {
|
user.ops.hatch({params: {egg: 'Cheetah', hatchingPotion: 'Base'}}, (response) => {
|
||||||
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
|
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
|
||||||
expect(user.items.pets).to.eql({'Cheetah-Base':5});
|
expect(user.items.pets).to.eql({'Cheetah-Base': 5});
|
||||||
expect(user.items.eggs).to.eql({'Cheetah':0});
|
expect(user.items.eggs).to.eql({Cheetah: 0});
|
||||||
expect(user.items.hatchingPotions).to.eql({'Base':0});
|
expect(user.items.hatchingPotions).to.eql({Base: 0});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hatches a premium pet', function(done) {
|
it('hatches a premium pet', (done) => {
|
||||||
user.items.eggs = {'Wolf':1};
|
user.items.eggs = {Wolf: 1};
|
||||||
user.items.hatchingPotions = {'Spooky':1};
|
user.items.hatchingPotions = {Spooky: 1};
|
||||||
user.ops.hatch({params:{egg:'Wolf',hatchingPotion:'Spooky'}}, function(response) {
|
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Spooky'}}, (response) => {
|
||||||
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
|
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
|
||||||
expect(user.items.pets).to.eql({'Wolf-Spooky':5});
|
expect(user.items.pets).to.eql({'Wolf-Spooky': 5});
|
||||||
expect(user.items.eggs).to.eql({'Wolf':0});
|
expect(user.items.eggs).to.eql({Wolf: 0});
|
||||||
expect(user.items.hatchingPotions).to.eql({'Spooky':0});
|
expect(user.items.hatchingPotions).to.eql({Spooky: 0});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hatches a pet previously raised to a mount', function(done) {
|
it('hatches a pet previously raised to a mount', (done) => {
|
||||||
user.items.eggs = {'Wolf':1};
|
user.items.eggs = {Wolf: 1};
|
||||||
user.items.hatchingPotions = {'Base':1};
|
user.items.hatchingPotions = {Base: 1};
|
||||||
user.items.pets = {'Wolf-Base':-1};
|
user.items.pets = {'Wolf-Base': -1};
|
||||||
user.ops.hatch({params:{egg:'Wolf',hatchingPotion:'Base'}}, function(response) {
|
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Base'}}, (response) => {
|
||||||
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
|
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
|
||||||
expect(user.items.pets).to.eql({'Wolf-Base':5});
|
expect(user.items.pets).to.eql({'Wolf-Base': 5});
|
||||||
expect(user.items.eggs).to.eql({'Wolf':0});
|
expect(user.items.eggs).to.eql({Wolf: 0});
|
||||||
expect(user.items.hatchingPotions).to.eql({'Base':0});
|
expect(user.items.hatchingPotions).to.eql({Base: 0});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,101 +1,93 @@
|
|||||||
var sinon = require('sinon');
|
let shared = require('../../common/script/index.js');
|
||||||
var chai = require("chai")
|
|
||||||
chai.use(require("sinon-chai"))
|
|
||||||
var expect = chai.expect
|
|
||||||
|
|
||||||
var shared = require('../../common/script/index.js');
|
describe('user.ops.hourglassPurchase', () => {
|
||||||
var Content = require('../../common/script/content/index.js');
|
let user;
|
||||||
|
|
||||||
describe('user.ops.hourglassPurchase', function() {
|
beforeEach(() => {
|
||||||
var user;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
user = {
|
user = {
|
||||||
items: {
|
items: {
|
||||||
pets: {},
|
pets: {},
|
||||||
mounts: {},
|
mounts: {},
|
||||||
hatchingPotions: {}
|
hatchingPotions: {},
|
||||||
},
|
},
|
||||||
purchased: {
|
purchased: {
|
||||||
plan: {
|
plan: {
|
||||||
consecutive: {
|
consecutive: {
|
||||||
trinkets: 0
|
trinkets: 0,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
shared.wrap(user);
|
shared.wrap(user);
|
||||||
});
|
});
|
||||||
|
|
||||||
context('Time Travel Stable', function() {
|
context('Time Travel Stable', () => {
|
||||||
|
context('failure conditions', () => {
|
||||||
context('failure conditions', function() {
|
it('does not allow purchase of unsupported item types', (done) => {
|
||||||
|
user.ops.hourglassPurchase({params: {type: 'hatchingPotions', key: 'Base'}}, (response) => {
|
||||||
it('does not allow purchase of unsupported item types', function(done) {
|
|
||||||
user.ops.hourglassPurchase({params:{type: 'hatchingPotions', key: 'Base'}}, function(response) {
|
|
||||||
expect(response.message).to.eql('Item type not supported for purchase with Mystic Hourglass. Allowed types: ["pets","mounts"]');
|
expect(response.message).to.eql('Item type not supported for purchase with Mystic Hourglass. Allowed types: ["pets","mounts"]');
|
||||||
expect(user.items.hatchingPotions).to.eql({});
|
expect(user.items.hatchingPotions).to.eql({});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not grant pets without Mystic Hourglasses', function(done) {
|
it('does not grant pets without Mystic Hourglasses', (done) => {
|
||||||
user.ops.hourglassPurchase({params:{type: 'pets', key: 'MantisShrimp-Base'}}, function(response) {
|
user.ops.hourglassPurchase({params: {type: 'pets', key: 'MantisShrimp-Base'}}, (response) => {
|
||||||
expect(response.message).to.eql("You don't have enough Mystic Hourglasses.");
|
expect(response.message).to.eql('You don\'t have enough Mystic Hourglasses.');
|
||||||
expect(user.items.pets).to.eql({});
|
expect(user.items.pets).to.eql({});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not grant mounts without Mystic Hourglasses', function(done) {
|
it('does not grant mounts without Mystic Hourglasses', (done) => {
|
||||||
user.ops.hourglassPurchase({params:{type: 'mounts', key: 'MantisShrimp-Base'}}, function(response) {
|
user.ops.hourglassPurchase({params: {type: 'mounts', key: 'MantisShrimp-Base'}}, (response) => {
|
||||||
expect(response.message).to.eql("You don't have enough Mystic Hourglasses.");
|
expect(response.message).to.eql('You don\'t have enough Mystic Hourglasses.');
|
||||||
expect(user.items.mounts).to.eql({});
|
expect(user.items.mounts).to.eql({});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not grant pet that has already been purchased', function(done) {
|
it('does not grant pet that has already been purchased', (done) => {
|
||||||
user.purchased.plan.consecutive.trinkets = 1;
|
user.purchased.plan.consecutive.trinkets = 1;
|
||||||
user.items.pets = {
|
user.items.pets = {
|
||||||
'MantisShrimp-Base': true
|
'MantisShrimp-Base': true,
|
||||||
};
|
};
|
||||||
|
|
||||||
user.ops.hourglassPurchase({params:{type: 'pets', key: 'MantisShrimp-Base'}}, function(response) {
|
user.ops.hourglassPurchase({params: {type: 'pets', key: 'MantisShrimp-Base'}}, (response) => {
|
||||||
expect(response.message).to.eql("Pet already owned.");
|
expect(response.message).to.eql('Pet already owned.');
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not grant mount that has already been purchased', function(done) {
|
it('does not grant mount that has already been purchased', (done) => {
|
||||||
user.purchased.plan.consecutive.trinkets = 1;
|
user.purchased.plan.consecutive.trinkets = 1;
|
||||||
user.items.mounts = {
|
user.items.mounts = {
|
||||||
'MantisShrimp-Base': true
|
'MantisShrimp-Base': true,
|
||||||
};
|
};
|
||||||
|
|
||||||
user.ops.hourglassPurchase({params:{type: 'mounts', key: 'MantisShrimp-Base'}}, function(response) {
|
user.ops.hourglassPurchase({params: {type: 'mounts', key: 'MantisShrimp-Base'}}, (response) => {
|
||||||
expect(response.message).to.eql("Mount already owned.");
|
expect(response.message).to.eql('Mount already owned.');
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not grant pet that is not part of the Time Travel Stable', function(done) {
|
it('does not grant pet that is not part of the Time Travel Stable', (done) => {
|
||||||
user.purchased.plan.consecutive.trinkets = 1;
|
user.purchased.plan.consecutive.trinkets = 1;
|
||||||
|
|
||||||
user.ops.hourglassPurchase({params: {type: 'pets', key: 'Wolf-Veteran'}}, function(response) {
|
user.ops.hourglassPurchase({params: {type: 'pets', key: 'Wolf-Veteran'}}, (response) => {
|
||||||
expect(response.message).to.eql('Pet not available for purchase with Mystic Hourglass.');
|
expect(response.message).to.eql('Pet not available for purchase with Mystic Hourglass.');
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not grant mount that is not part of the Time Travel Stable', function(done) {
|
it('does not grant mount that is not part of the Time Travel Stable', (done) => {
|
||||||
user.purchased.plan.consecutive.trinkets = 1;
|
user.purchased.plan.consecutive.trinkets = 1;
|
||||||
|
|
||||||
user.ops.hourglassPurchase({params: {type: 'mounts', key: 'Orca-Base'}}, function(response) {
|
user.ops.hourglassPurchase({params: {type: 'mounts', key: 'Orca-Base'}}, (response) => {
|
||||||
expect(response.message).to.eql('Mount not available for purchase with Mystic Hourglass.');
|
expect(response.message).to.eql('Mount not available for purchase with Mystic Hourglass.');
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||||
done();
|
done();
|
||||||
@@ -103,26 +95,25 @@ describe('user.ops.hourglassPurchase', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('successful purchases', function() {
|
context('successful purchases', () => {
|
||||||
|
it('buys a pet', (done) => {
|
||||||
it('buys a pet', function(done) {
|
|
||||||
user.purchased.plan.consecutive.trinkets = 2;
|
user.purchased.plan.consecutive.trinkets = 2;
|
||||||
|
|
||||||
user.ops.hourglassPurchase({params: {type: 'pets', key: 'MantisShrimp-Base'}}, function(response) {
|
user.ops.hourglassPurchase({params: {type: 'pets', key: 'MantisShrimp-Base'}}, (response) => {
|
||||||
expect(response.message).to.eql('Purchased an item using a Mystic Hourglass!');
|
expect(response.message).to.eql('Purchased an item using a Mystic Hourglass!');
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
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});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('buys a mount', function(done) {
|
it('buys a mount', (done) => {
|
||||||
user.purchased.plan.consecutive.trinkets = 2;
|
user.purchased.plan.consecutive.trinkets = 2;
|
||||||
|
|
||||||
user.ops.hourglassPurchase({params: {type: 'mounts', key: 'MantisShrimp-Base'}}, function(response) {
|
user.ops.hourglassPurchase({params: {type: 'mounts', key: 'MantisShrimp-Base'}}, (response) => {
|
||||||
expect(response.message).to.eql('Purchased an item using a Mystic Hourglass!');
|
expect(response.message).to.eql('Purchased an item using a Mystic Hourglass!');
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
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});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,36 +1,30 @@
|
|||||||
var sinon = require('sinon');
|
let shared = require('../../common/script/index.js');
|
||||||
var chai = require("chai")
|
|
||||||
chai.use(require("sinon-chai"))
|
|
||||||
var expect = chai.expect
|
|
||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
var shared = require('../../common/script/index.js');
|
describe('user.ops', () => {
|
||||||
|
let user;
|
||||||
|
|
||||||
describe('user.ops', function() {
|
beforeEach(() => {
|
||||||
var user;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
user = {
|
user = {
|
||||||
items: {
|
items: {
|
||||||
gear: { },
|
gear: { },
|
||||||
special: { }
|
special: { },
|
||||||
},
|
},
|
||||||
achievements: { },
|
achievements: { },
|
||||||
flags: { }
|
flags: { },
|
||||||
};
|
};
|
||||||
|
|
||||||
shared.wrap(user);
|
shared.wrap(user);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('readCard', function() {
|
describe('readCard', () => {
|
||||||
it('removes card from invitation array', function() {
|
it('removes card from invitation array', () => {
|
||||||
user.items.special.valentineReceived = ['Leslie'];
|
user.items.special.valentineReceived = ['Leslie'];
|
||||||
user.ops.readCard({ params: { cardType: 'valentine' } });
|
user.ops.readCard({ params: { cardType: 'valentine' } });
|
||||||
|
|
||||||
expect(user.items.special.valentineReceived).to.be.empty;
|
expect(user.items.special.valentineReceived).to.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes the first card from invitation array', function() {
|
it('removes the first card from invitation array', () => {
|
||||||
user.items.special.valentineReceived = ['Leslie', 'Vicky'];
|
user.items.special.valentineReceived = ['Leslie', 'Vicky'];
|
||||||
user.ops.readCard({ params: { cardType: 'valentine' } });
|
user.ops.readCard({ params: { cardType: 'valentine' } });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user