(chore): lint test/common files

This commit is contained in:
Blade Barringer
2015-11-19 20:27:39 -06:00
parent bdf1c82b39
commit 776faddb34
11 changed files with 1368 additions and 1351 deletions

View File

@@ -40,7 +40,8 @@ gulp.task('lint:tests', () => {
'./test/**/*.js',
// @TODO remove these negations as the test files are cleaned up.
'!./test/api-legacy/**/*',
'!./test/common/**/*',
'!./test/api/**/*',
'!./test/common/simulations/**/*',
'!./test/content/**/*',
'!./test/e2e/**/*',
'!./test/server_side/**/*',
@@ -48,6 +49,7 @@ gulp.task('lint:tests', () => {
])
.pipe(eslint({
rules: {
'max-nested-callbacks': 0,
'no-unused-expressions': 0,
'mocha/no-exclusive-tests': 2,
'mocha/no-global-tests': 2,
@@ -55,6 +57,8 @@ gulp.task('lint:tests', () => {
},
globals: {
'expect': true,
'_': true,
'sinon': true,
},
plugins: [ 'mocha' ],
}))
@@ -62,7 +66,7 @@ gulp.task('lint:tests', () => {
.pipe(eslint.failAfterError());
});
gulp.task('lint', ['lint:server', 'lint:common']);
gulp.task('lint', ['lint:server', 'lint:common', 'lint:tests']);
gulp.task('lint:watch', () => {
gulp.watch([

File diff suppressed because it is too large Load Diff

View File

@@ -1,191 +1,206 @@
var sinon = require('sinon');
var chai = require("chai")
chai.use(require("sinon-chai"))
var expect = chai.expect
/* eslint-disable camelcase */
let count = require('../../common/script/count');
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);
});
it('counts drop pets', function() {
var pets = { "Dragon-Red": 1, "Wolf-Base": 2 };
var beastMasterTotal = count.beastMasterProgress(pets);
it('counts drop pets', () => {
let pets = { 'Dragon-Red': 1, 'Wolf-Base': 2 };
let beastMasterTotal = count.beastMasterProgress(pets);
expect(beastMasterTotal).to.eql(2);
});
it('does not count quest pets', function() {
var pets = { "Dragon-Red": 1, "Gryphon-Base": 1 };
var beastMasterTotal = count.beastMasterProgress(pets);
it('does not count quest pets', () => {
let pets = { 'Dragon-Red': 1, 'Gryphon-Base': 1 };
let beastMasterTotal = count.beastMasterProgress(pets);
expect(beastMasterTotal).to.eql(1);
});
it('does not count pets hatched with premium potions', function() {
var pets = {
"Wolf-Spooky": 5,
"Dragon-Spooky": 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
it('does not count pets hatched with premium potions', () => {
let pets = {
'Wolf-Spooky': 5,
'Dragon-Spooky': 5,
'FlyingPig-Base': 5,
};
var beastMasterTotal = count.beastMasterProgress(pets);
let beastMasterTotal = count.beastMasterProgress(pets);
expect(beastMasterTotal).to.eql(1);
});
it('counts drop pets that have been raised to a mount', function() {
var raisedToMount = -1;
var pets = { "Dragon-Red": 1, "Wolf-Base": raisedToMount };
var beastMasterTotal = count.beastMasterProgress(pets);
it('does not count special pets', () => {
let pets = {
'Wolf-Base': 2,
'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);
});
it('does not counts drop pets that have been released', function() {
var releasedPet = 0;
var pets = { "Dragon-Red": 1, "Wolf-Base": releasedPet };
var beastMasterTotal = count.beastMasterProgress(pets);
it('does not counts drop pets that have been released', () => {
let releasedPet = 0;
let pets = { 'Dragon-Red': 1, 'Wolf-Base': releasedPet };
let beastMasterTotal = count.beastMasterProgress(pets);
expect(beastMasterTotal).to.eql(1);
});
});
describe('mountMasterProgress', function() {
it('returns 0 if no mounts', function() {
var mounts = {};
var mountMasterTotal = count.mountMasterProgress(mounts);
describe('mountMasterProgress', () => {
it('returns 0 if no mounts', () => {
let mounts = {};
let mountMasterTotal = count.mountMasterProgress(mounts);
expect(mountMasterTotal).to.eql(0);
});
it('counts drop mounts', function() {
var mounts = { "Dragon-Red": true, "Wolf-Base": true };
var mountMasterTotal = count.mountMasterProgress(mounts);
it('counts drop mounts', () => {
let mounts = { 'Dragon-Red': true, 'Wolf-Base': true };
let mountMasterTotal = count.mountMasterProgress(mounts);
expect(mountMasterTotal).to.eql(2);
});
it('does not count premium mounts', function() {
var mounts = {
"Dragon-Red": true,
"FlyingPig-Spooky": true
}
var mountMasterTotal = count.mountMasterProgress(mounts);
it('does not count premium mounts', () => {
let mounts = {
'Dragon-Red': true,
'FlyingPig-Spooky': true,
};
let mountMasterTotal = count.mountMasterProgress(mounts);
expect(mountMasterTotal).to.eql(1);
});
it('does not count quest mounts', function() {
var mounts = { "Dragon-Red": true, "Gryphon-Base": true };
var mountMasterTotal = count.mountMasterProgress(mounts);
it('does not count quest mounts', () => {
let mounts = { 'Dragon-Red': true, 'Gryphon-Base': true };
let mountMasterTotal = count.mountMasterProgress(mounts);
expect(mountMasterTotal).to.eql(1);
});
it('does not count special mounts', function() {
var mounts = { "Wolf-Base": true, "BearCub-Polar": true};
var mountMasterTotal = count.mountMasterProgress(mounts);
it('does not count special mounts', () => {
let mounts = { 'Wolf-Base': true, 'BearCub-Polar': true};
let mountMasterTotal = count.mountMasterProgress(mounts);
expect(mountMasterTotal).to.eql(1);
});
it('only counts drop mounts that are currently owned', function() {
var notCurrentlyOwned = false;
var mounts = { "Dragon-Red": true, "Wolf-Base": notCurrentlyOwned };
var mountMasterTotal = count.mountMasterProgress(mounts);
it('only counts drop mounts that are currently owned', () => {
let notCurrentlyOwned = false;
let mounts = { 'Dragon-Red': true, 'Wolf-Base': notCurrentlyOwned };
let mountMasterTotal = count.mountMasterProgress(mounts);
expect(mountMasterTotal).to.eql(1);
});
});
describe('remainingGearInSet', function() {
it('counts remaining gear based on set', function() {
var gear = {
'weapon_wizard_0':true,
'weapon_wizard_1':true,
'weapon_warrior_0':true,
'weapon_warrior_1':true,
'weapon_armor_0':true,
'weapon_armor_1':true
describe('remainingGearInSet', () => {
it('counts remaining gear based on set', () => {
let gear = {
weapon_wizard_0: true,
weapon_wizard_1: true,
weapon_warrior_0: true,
weapon_warrior_1: true,
weapon_armor_0: true,
weapon_armor_1: true,
};
var armoireCount = count.remainingGearInSet(gear, 'warrior');
let armoireCount = count.remainingGearInSet(gear, 'warrior');
expect(armoireCount).to.eql(20);
});
it.skip('includes previously owned items in count (https://github.com/HabitRPG/habitrpg/issues/5624#issuecomment-124018717)', function() {
var gear = {
'weapon_warrior_0':false,
'weapon_warrior_1':false,
'weapon_armor_0':true,
'weapon_armor_1':true
it.skip('includes previously owned items in count (https: //github.com/HabitRPG/habitrpg/issues/5624#issuecomment-124018717)', () => {
let gear = {
weapon_warrior_0: false,
weapon_warrior_1: false,
weapon_armor_0: true,
weapon_armor_1: true,
};
var armoireCount = count.remainingGearInSet(gear, 'warrior');
let armoireCount = count.remainingGearInSet(gear, 'warrior');
expect(armoireCount).to.eql(20);
});
});
describe('dropPetsCurrentlyOwned', function() {
it('counts drop pets owned', function() {
var pets = {
"Wolf-Base": 2,
"Wolf-Red": 4
describe('dropPetsCurrentlyOwned', () => {
it('counts drop pets owned', () => {
let pets = {
'Wolf-Base': 2,
'Wolf-Red': 4,
};
var dropPets = count.dropPetsCurrentlyOwned(pets);
let dropPets = count.dropPetsCurrentlyOwned(pets);
expect(dropPets).to.eql(2);
});
it('does not count pets that have been raised to mounts', function() {
var pets = {
"Wolf-Base": -1,
"Wolf-Red": 4,
"Wolf-Veteran": 1,
"Gryphon-Base": 1
it('does not count pets that have been raised to mounts', () => {
let pets = {
'Wolf-Base': -1,
'Wolf-Red': 4,
'Wolf-Veteran': 1,
'Gryphon-Base': 1,
};
var dropPets = count.dropPetsCurrentlyOwned(pets);
let dropPets = count.dropPetsCurrentlyOwned(pets);
expect(dropPets).to.eql(1);
});
it('does not count quest pets', function() {
var pets = {
"Wolf-Base": 2,
"Wolf-Red": 4,
"Gryphon-Base": 1
it('does not count quest pets', () => {
let pets = {
'Wolf-Base': 2,
'Wolf-Red': 4,
'Gryphon-Base': 1,
};
var dropPets = count.dropPetsCurrentlyOwned(pets);
let dropPets = count.dropPetsCurrentlyOwned(pets);
expect(dropPets).to.eql(2);
});
it('does not count special pets', function() {
var pets = {
"Wolf-Base": 2,
"Wolf-Red": 4,
"Wolf-Veteran": 1
it('does not count special pets', () => {
let pets = {
'Wolf-Base': 2,
'Wolf-Red': 4,
'Wolf-Veteran': 1,
};
var dropPets = count.dropPetsCurrentlyOwned(pets);
let dropPets = count.dropPetsCurrentlyOwned(pets);
expect(dropPets).to.eql(2);
});
});
describe('questsOfCategory', function() {
it('counts user quest scrolls of a particular category', function() {
var quests = {
"atom1": 2,
"whale": 4,
"kraken": 2,
"sheep": 1,
"goldenknight2": 1
describe('questsOfCategory', () => {
it('counts user quest scrolls of a particular category', () => {
let quests = {
atom1: 2,
whale: 4,
kraken: 2,
sheep: 1,
goldenknight2: 1,
};
var petQuestCount = count.questsOfCategory(quests, 'pet');
var unlockableQuestCount = count.questsOfCategory(quests, 'unlockable');
var goldQuestCount = count.questsOfCategory(quests, 'gold');
let petQuestCount = count.questsOfCategory(quests, 'pet');
let unlockableQuestCount = count.questsOfCategory(quests, 'unlockable');
let goldQuestCount = count.questsOfCategory(quests, 'gold');
expect(petQuestCount).to.eql(3);
expect(unlockableQuestCount).to.eql(2);
expect(goldQuestCount).to.eql(0);

View File

@@ -1,57 +1,50 @@
var _, cron, expect, moment, newUser, repeatWithoutLastWeekday, shared, sinon;
/* eslint-disable camelcase */
_ = require('lodash');
expect = require('expect.js');
sinon = require('sinon');
moment = require('moment');
shared = require('../../common/script/index.js');
let expect = require('expect.js'); // eslint-disable-line no-shadow
let moment = require('moment');
let shared = require('../../common/script/index.js');
shared.i18n.translations = require('../../website/src/libs/i18n.js').translations;
repeatWithoutLastWeekday = function() {
var repeat;
repeat = {
let repeatWithoutLastWeekday = () => { // eslint-disable-line no-unused-vars
let repeat = {
su: true,
m: true,
t: true,
w: true,
th: true,
f: true,
s: true
s: true,
};
if (shared.startOfWeek(moment().zone(0)).isoWeekday() === 1) {
repeat.su = false;
} else {
repeat.s = false;
}
return {
repeat: repeat
repeat,
};
};
/* Helper Functions */
newUser = function(addTasks) {
var buffs, user;
if (addTasks == null) {
addTasks = true;
}
let newUser = (addTasks = true) => {
let buffs;
let user;
buffs = {
per: 0,
int: 0,
con: 0,
str: 0,
stealth: 0,
streaks: false
streaks: false,
};
user = {
auth: {
timestamps: {}
timestamps: {},
},
stats: {
str: 1,
@@ -59,27 +52,27 @@ newUser = function(addTasks) {
per: 1,
int: 1,
mp: 32,
"class": 'warrior',
buffs: buffs
class: 'warrior',
buffs,
},
items: {
lastDrop: {
count: 0
count: 0,
},
hatchingPotions: {},
eggs: {},
food: {},
gear: {
equipped: {},
costume: {}
}
costume: {},
},
},
party: {
quest: {
progress: {
down: 0
}
}
down: 0,
},
},
},
preferences: {},
dailys: [],
@@ -88,45 +81,42 @@ newUser = function(addTasks) {
flags: {},
achievements: {},
contributor: {
level: 2
}
level: 2,
},
};
shared.wrap(user);
user.ops.reset(null, function() {});
user.ops.reset(null, () => {});
if (addTasks) {
_.each(['habit', 'todo', 'daily'], function(task) {
return user.ops.addTask({
_.each(['habit', 'todo', 'daily'], (task) => {
user.ops.addTask({
body: {
type: task,
id: shared.uuid()
}
id: shared.uuid(),
},
});
});
}
return user;
};
cron = function(usr, missedDays) {
if (missedDays == null) {
missedDays = 1;
}
let cron = (usr, missedDays = 1) => {
usr.lastCron = moment().subtract(missedDays, 'days');
return usr.fns.cron();
usr.fns.cron();
};
describe('daily/weekly that repeats everyday (default)', function() {
var daily, user, weekly;
user = null;
daily = null;
weekly = null;
describe('when startDate is in the future', function() {
beforeEach(function() {
describe('daily/weekly that repeats everyday (default)', () => {
let user = null;
let daily = null;
let weekly = null;
describe('when startDate is in the future', () => {
beforeEach(() => {
user = newUser();
user.dailys = [
shared.taskDefaults({
type: 'daily',
startDate: moment().add(7, 'days'),
frequency: 'daily'
frequency: 'daily',
}), shared.taskDefaults({
type: 'daily',
startDate: moment().add(7, 'days'),
@@ -138,39 +128,39 @@ describe('daily/weekly that repeats everyday (default)', function() {
w: true,
th: true,
f: true,
s: true
}
})
s: true,
},
}),
];
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);
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);
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() {
var checklist;
checklist = [
it('does not reset checklists if daily is not marked as complete', () => {
let checklist = [
{
'text': '1',
'id': 'checklist-one',
'completed': true
text: '1',
id: 'checklist-one',
completed: true,
}, {
'text': '2',
'id': 'checklist-two',
'completed': true
text: '2',
id: 'checklist-two',
completed: true,
}, {
'text': '3',
'id': 'checklist-three',
'completed': false
}
text: '3',
id: 'checklist-three',
completed: false,
},
];
daily.checklist = checklist;
weekly.checklist = checklist;
cron(user);
@@ -179,359 +169,369 @@ describe('daily/weekly that repeats everyday (default)', function() {
expect(daily.checklist[2].completed).to.be(false);
expect(weekly.checklist[0].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() {
var checklist;
checklist = [
it('resets checklists if daily is marked as complete', () => {
let checklist = [
{
'text': '1',
'id': 'checklist-one',
'completed': true
text: '1',
id: 'checklist-one',
completed: true,
}, {
'text': '2',
'id': 'checklist-two',
'completed': true
text: '2',
id: 'checklist-two',
completed: true,
}, {
'text': '3',
'id': 'checklist-three',
'completed': false
}
text: '3',
id: 'checklist-three',
completed: false,
},
];
daily.checklist = checklist;
weekly.checklist = checklist;
daily.completed = true;
weekly.completed = true;
cron(user);
_.each(daily.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(daily.checklist, (box) => {
expect(box.completed).to.be(false);
});
return _.each(weekly.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(weekly.checklist, (box) => {
expect(box.completed).to.be(false);
});
});
return it('is due on startDate', function() {
var daily_due_on_start_date, daily_due_today, weekly_due_on_start_date, weekly_due_today;
daily_due_today = shared.shouldDo(moment(), daily);
daily_due_on_start_date = shared.shouldDo(moment().add(7, 'days'), daily);
it('is due on startDate', () => {
let daily_due_today = shared.shouldDo(moment(), daily);
let daily_due_on_start_date = shared.shouldDo(moment().add(7, 'days'), daily);
expect(daily_due_today).to.be(false);
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);
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() {
beforeEach(function() {
describe('when startDate is in the past', () => {
beforeEach(() => {
user = newUser();
user.dailys = [
shared.taskDefaults({
type: 'daily',
startDate: moment().subtract(7, 'days'),
frequency: 'daily'
frequency: 'daily',
}), shared.taskDefaults({
type: 'daily',
startDate: moment().subtract(7, 'days'),
frequency: 'weekly'
})
frequency: 'weekly',
}),
];
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);
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);
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);
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() {
var checklist;
it('resets checklists if daily is not marked as complete', () => {
let checklist;
checklist = [
{
'text': '1',
'id': 'checklist-one',
'completed': true
text: '1',
id: 'checklist-one',
completed: true,
}, {
'text': '2',
'id': 'checklist-two',
'completed': true
text: '2',
id: 'checklist-two',
completed: true,
}, {
'text': '3',
'id': 'checklist-three',
'completed': false
}
text: '3',
id: 'checklist-three',
completed: false,
},
];
daily.checklist = checklist;
weekly.checklist = checklist;
cron(user);
_.each(daily.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(daily.checklist, (box) => {
expect(box.completed).to.be(false);
});
return _.each(weekly.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(weekly.checklist, (box) => {
expect(box.completed).to.be(false);
});
});
return it('resets checklists if daily is marked as complete', function() {
var checklist;
checklist = [
it('resets checklists if daily is marked as complete', () => {
let checklist = [
{
'text': '1',
'id': 'checklist-one',
'completed': true
text: '1',
id: 'checklist-one',
completed: true,
}, {
'text': '2',
'id': 'checklist-two',
'completed': true
text: '2',
id: 'checklist-two',
completed: true,
}, {
'text': '3',
'id': 'checklist-three',
'completed': false
}
text: '3',
id: 'checklist-three',
completed: false,
},
];
daily.checklist = checklist;
daily.completed = true;
weekly.checklist = checklist;
weekly.completed = true;
cron(user);
_.each(daily.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(daily.checklist, (box) => {
expect(box.completed).to.be(false);
});
return _.each(weekly.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(weekly.checklist, (box) => {
expect(box.completed).to.be(false);
});
});
});
return describe('when startDate is today', function() {
beforeEach(function() {
describe('when startDate is today', () => {
beforeEach(() => {
user = newUser();
user.dailys = [
shared.taskDefaults({
type: 'daily',
startDate: moment().subtract(1, 'days'),
frequency: 'daily'
frequency: 'daily',
}), shared.taskDefaults({
type: 'daily',
startDate: moment().subtract(1, 'days'),
frequency: 'weekly'
})
frequency: 'weekly',
}),
];
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);
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);
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() {
var checklist;
it('resets checklists if daily is not marked as complete', () => {
let checklist;
checklist = [
{
'text': '1',
'id': 'checklist-one',
'completed': true
text: '1',
id: 'checklist-one',
completed: true,
}, {
'text': '2',
'id': 'checklist-two',
'completed': true
text: '2',
id: 'checklist-two',
completed: true,
}, {
'text': '3',
'id': 'checklist-three',
'completed': false
}
text: '3',
id: 'checklist-three',
completed: false,
},
];
daily.checklist = checklist;
weekly.checklist = checklist;
cron(user);
_.each(daily.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(daily.checklist, (box) => {
expect(box.completed).to.be(false);
});
return _.each(weekly.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(weekly.checklist, (box) => {
expect(box.completed).to.be(false);
});
});
return it('resets checklists if daily is marked as complete', function() {
var checklist;
it('resets checklists if daily is marked as complete', () => {
let checklist;
checklist = [
{
'text': '1',
'id': 'checklist-one',
'completed': true
text: '1',
id: 'checklist-one',
completed: true,
}, {
'text': '2',
'id': 'checklist-two',
'completed': true
text: '2',
id: 'checklist-two',
completed: true,
}, {
'text': '3',
'id': 'checklist-three',
'completed': false
}
text: '3',
id: 'checklist-three',
completed: false,
},
];
daily.checklist = checklist;
daily.completed = true;
weekly.checklist = checklist;
weekly.completed = true;
cron(user);
_.each(daily.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(daily.checklist, (box) => {
expect(box.completed).to.be(false);
});
return _.each(weekly.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(weekly.checklist, (box) => {
expect(box.completed).to.be(false);
});
});
});
});
describe('daily that repeats every x days', function() {
var daily, user;
user = null;
daily = null;
beforeEach(function() {
describe('daily that repeats every x days', () => {
let user = null;
let daily = null;
beforeEach(() => {
user = newUser();
user.dailys = [
shared.taskDefaults({
type: 'daily',
startDate: moment(),
frequency: 'daily'
})
frequency: 'daily',
}),
];
return daily = user.dailys[0];
daily = user.dailys[0];
});
return _.times(11, function(due) {
return it('where x equals ' + due, function() {
_.times(11, (due) => {
it(`where x equals ${due}`, () => {
daily.everyX = due;
return _.times(30, function(day) {
var isDue;
_.times(30, (day) => {
let isDue;
isDue = shared.shouldDo(moment().add(day, 'days'), daily);
if (day % due === 0) {
expect(isDue).to.be(true);
}
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() {
var daily, everyX, startDateDaysAgo, user;
everyX = 3;
startDateDaysAgo = everyX * 3;
user = null;
daily = null;
describe('including missing a due date', function() {
var missedDays;
missedDays = everyX * 2 + 1;
beforeEach(function() {
describe('daily that repeats every X days when multiple days are missed', () => {
let everyX = 3;
let startDateDaysAgo = everyX * 3;
let user = null;
let daily = null;
describe('including missing a due date', () => {
let missedDays = everyX * 2 + 1;
beforeEach(() => {
user = newUser();
user.dailys = [
shared.taskDefaults({
type: 'daily',
startDate: moment().subtract(startDateDaysAgo, 'days'),
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);
return expect(daily.value).to.be(-1);
expect(daily.value).to.be(-1);
});
it('resets checklists if daily is incomplete', function() {
var checklist;
checklist = [
it('resets checklists if daily is incomplete', () => {
let checklist = [
{
'text': '1',
'id': 'checklist-one',
'completed': true
}
text: '1',
id: 'checklist-one',
completed: true,
},
];
daily.checklist = checklist;
cron(user, missedDays);
return _.each(daily.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(daily.checklist, (box) => {
expect(box.completed).to.be(false);
});
});
return it('resets checklists if daily is marked as complete', function() {
var checklist;
it('resets checklists if daily is marked as complete', () => {
let checklist;
checklist = [
{
'text': '1',
'id': 'checklist-one',
'completed': true
}
text: '1',
id: 'checklist-one',
completed: true,
},
];
daily.checklist = checklist;
daily.completed = true;
cron(user, missedDays);
return _.each(daily.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(daily.checklist, (box) => {
expect(box.completed).to.be(false);
});
});
});
return describe('but not missing a due date', function() {
var missedDays;
describe('but not missing a due date', () => {
let missedDays;
missedDays = everyX - 1;
beforeEach(function() {
beforeEach(() => {
user = newUser();
user.dailys = [
shared.taskDefaults({
type: 'daily',
startDate: moment().subtract(startDateDaysAgo, 'days'),
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);
return expect(daily.value).to.be(0);
expect(daily.value).to.be(0);
});
it('does not reset checklists if daily is incomplete', function() {
var checklist;
it('does not reset checklists if daily is incomplete', () => {
let checklist;
checklist = [
{
'text': '1',
'id': 'checklist-one',
'completed': true
}
text: '1',
id: 'checklist-one',
completed: true,
},
];
daily.checklist = checklist;
cron(user, missedDays);
return _.each(daily.checklist, function(box) {
return expect(box.completed).to.be(true);
_.each(daily.checklist, (box) => {
expect(box.completed).to.be(true);
});
});
return it('resets checklists if daily is marked as complete', function() {
var checklist;
it('resets checklists if daily is marked as complete', () => {
let checklist;
checklist = [
{
'text': '1',
'id': 'checklist-one',
'completed': true
}
text: 1,
id: 'checklist-one',
completed: true,
},
];
daily.checklist = checklist;
daily.completed = true;
cron(user, missedDays);
return _.each(daily.checklist, function(box) {
return expect(box.completed).to.be(false);
_.each(daily.checklist, (box) => {
expect(box.completed).to.be(false);
});
});
});

View File

@@ -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.prototype.toHaveGP = function(gp) {
var actual;
Assertion.prototype.toHaveGP = function (gp) {
let actual;
actual = this.obj.stats.gp;
return this.assert(actual === gp, function() {
return "expected user to have " + gp + " gp, but got " + actual;
}, function() {
return "expected user to not have " + gp + " gp";
return this.assert(actual === gp, () => {
return 'expected user to have ' + gp + ' gp, but got ' + actual;
}, () => {
return 'expected user to not have ' + gp + ' gp';
});
};
Assertion.prototype.toHaveHP = function(hp) {
var actual;
Assertion.prototype.toHaveHP = function (hp) {
let actual;
actual = this.obj.stats.hp;
return this.assert(actual === hp, function() {
return "expected user to have " + hp + " hp, but got " + actual;
}, function() {
return "expected user to not have " + hp + " hp";
return this.assert(actual === hp, () => {
return 'expected user to have ' + hp + ' hp, but got ' + actual;
}, () => {
return 'expected user to not have ' + hp + ' hp';
});
};
Assertion.prototype.toHaveExp = function(exp) {
var actual;
Assertion.prototype.toHaveExp = function (exp) {
let actual;
actual = this.obj.stats.exp;
return this.assert(actual === exp, function() {
return "expected user to have " + exp + " experience points, but got " + actual;
}, function() {
return "expected user to not have " + exp + " experience points";
return this.assert(actual === exp, () => {
return 'expected user to have ' + exp + ' experience points, but got ' + actual;
}, () => {
return 'expected user to not have ' + exp + ' experience points';
});
};
Assertion.prototype.toHaveLevel = function(lvl) {
var actual;
Assertion.prototype.toHaveLevel = function (lvl) {
let actual;
actual = this.obj.stats.lvl;
return this.assert(actual === lvl, function() {
return "expected user to be level " + lvl + ", but got " + actual;
}, function() {
return "expected user to not be level " + lvl;
return this.assert(actual === lvl, () => {
return 'expected user to be level ' + lvl + ', but got ' + actual;
}, () => {
return 'expected user to not be level ' + lvl;
});
};
return Assertion.prototype.toHaveMaxMP = function(mp) {
var actual;
Assertion.prototype.toHaveMaxMP = function (mp) {
let actual;
actual = this.obj._statsComputed.maxMP;
return this.assert(actual === mp, function() {
return "expected user to have " + mp + " max mp, but got " + actual;
}, function() {
return "expected user to not have " + mp + " max mp";
return this.assert(actual === mp, () => {
return 'expected user to have ' + mp + ' max mp, but got ' + actual;
}, () => {
return 'expected user to not have ' + mp + ' max mp';
});
};
};

View File

@@ -1,30 +1,28 @@
var sinon = require('sinon');
var chai = require("chai")
chai.use(require("sinon-chai"))
var expect = chai.expect
var _ = require('lodash');
/* eslint-disable camelcase */
var shared = require('../../common/script/index.js');
import sinon from 'sinon'; // eslint-disable-line no-shadow
describe('user.fns.buy', function() {
var user;
let shared = require('../../common/script/index.js');
beforeEach(function() {
describe('user.fns.buy', () => {
let user;
beforeEach(() => {
user = {
items: {
gear: {
owned: {
weapon_warrior_0: true
weapon_warrior_0: true,
},
equipped: {
weapon_warrior_0: true
}
}
weapon_warrior_0: true,
},
},
},
preferences: {},
stats: { gp: 200 },
achievements: { },
flags: { }
flags: { },
};
shared.wrap(user);
@@ -33,32 +31,32 @@ describe('user.fns.buy', function() {
sinon.stub(user.fns, 'predictableRandom');
});
afterEach(function() {
afterEach(() => {
user.fns.randomVal.restore();
user.fns.predictableRandom.restore();
});
context('Potion', function() {
it('recovers 15 hp', function() {
context('Potion', () => {
it('recovers 15 hp', () => {
user.stats.hp = 30;
user.ops.buy({params: {key: 'potion'}});
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.ops.buy({params: {key: 'potion'}});
expect(user.stats.hp).to.eql(50);
});
it('deducts 25 gp', function() {
it('deducts 25 gp', () => {
user.stats.hp = 45;
user.ops.buy({params: {key: 'potion'}});
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.gp = 5;
user.ops.buy({params: {key: 'potion'}});
@@ -68,8 +66,8 @@ describe('user.fns.buy', function() {
});
});
context('Gear', function() {
it('adds equipment to inventory', function() {
context('Gear', () => {
it('adds equipment to inventory', () => {
user.stats.gp = 31;
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 });
});
it('deducts gold from user', function() {
it('deducts gold from user', () => {
user.stats.gp = 31;
user.ops.buy({params: {key: 'armor_warrior_1'}});
@@ -85,7 +83,7 @@ describe('user.fns.buy', function() {
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.preferences.autoEquip = true;
@@ -94,7 +92,7 @@ describe('user.fns.buy', function() {
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.preferences.autoEquip = false;
@@ -103,7 +101,7 @@ describe('user.fns.buy', function() {
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.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('does not buy Quests without enough Gold');
@@ -122,48 +120,49 @@ describe('user.fns.buy', function() {
it('does not buy Gem-premium Quests');
});
context('Enchanted Armoire', function() {
var YIELD_EQUIPMENT = .5;
var YIELD_FOOD = .7;
var YIELD_EXP = .9;
context('Enchanted Armoire', () => {
let YIELD_EQUIPMENT = 0.5;
let YIELD_FOOD = 0.7;
let YIELD_EXP = 0.9;
var fullArmoire = {}
let fullArmoire = {};
_(shared.content.gearTypes).each(function(type) {
_(shared.content.gear.tree[type].armoire).each(function(gearObject, gearName) {
_(shared.content.gearTypes).each((type) => {
_(shared.content.gear.tree[type].armoire).each((gearObject) => {
let armoireKey = gearObject.key;
fullArmoire[armoireKey] = true;
});
});
beforeEach(function() {
beforeEach(() => {
user.achievements.ultimateGearSets = { rogue: true };
user.flags.armoireOpened = true;
user.stats.exp = 0;
user.items.food = {};
});
context('failure conditions', function() {
it('does not open if user does not have enough gold', function(done) {
context('failure conditions', () => {
it('does not open if user does not have enough gold', (done) => {
user.fns.predictableRandom.returns(YIELD_EQUIPMENT);
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(user.items.gear.owned).to.eql({'weapon_warrior_0': true});
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
expect(user.items.food).to.be.empty;
expect(user.stats.exp).to.eql(0);
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.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) {
expect(response.message).to.eql("You can't buy this item");
expect(user.items.gear.owned).to.eql({'weapon_warrior_0': true});
user.ops.buy({params: {key: 'armoire'}}, (response) => {
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.food).to.be.empty;
expect(user.stats.exp).to.eql(0);
done();
@@ -171,32 +170,33 @@ describe('user.fns.buy', function() {
});
});
context('non-gear awards', function() {
it('gives Experience', function() {
context('non-gear awards', () => {
it('gives Experience', () => {
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.stats.exp).to.eql(46);
expect(user.stats.gp).to.eql(100);
});
it('gives food', function() {
var honey = shared.content.food.Honey;
it('gives food', () => {
let honey = shared.content.food.Honey;
user.fns.randomVal.returns(honey);
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.food).to.eql({'Honey': 1});
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
expect(user.items.food).to.eql({Honey: 1});
expect(user.stats.exp).to.eql(0);
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.items.gear.owned = fullArmoire;
user.stats.gp = 150;
@@ -204,7 +204,8 @@ describe('user.fns.buy', function() {
user.ops.buy({params: {key: 'armoire'}});
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(user.stats.exp).to.eql(30);
@@ -212,43 +213,46 @@ describe('user.fns.buy', function() {
});
});
context('gear awards', function() {
beforeEach(function() {
var shield = shared.content.gear.tree.shield.armoire.gladiatorShield;
context('gear awards', () => {
beforeEach(() => {
let shield = shared.content.gear.tree.shield.armoire.gladiatorShield;
user.fns.randomVal.returns(shield);
});
it('always drops equipment the first time', function() {
it('always drops equipment the first time', () => {
delete user.flags.armoireOpened;
user.fns.predictableRandom.returns(YIELD_EXP);
user.ops.buy({params: {key: 'armoire'}});
expect(user.items.gear.owned).to.eql({
'weapon_warrior_0': true,
'shield_armoire_gladiatorShield': true
weapon_warrior_0: true,
shield_armoire_gladiatorShield: true,
});
var armoireCount = shared.count.remainingGearInSet(user.items.gear.owned, 'armoire');
expect(armoireCount).to.eql (_.size(fullArmoire) - 1)
let armoireCount = shared.count.remainingGearInSet(user.items.gear.owned, 'armoire');
expect(armoireCount).to.eql(_.size(fullArmoire) - 1);
expect(user.items.food).to.be.empty;
expect(user.stats.exp).to.eql(0);
expect(user.stats.gp).to.eql(100);
});
it('gives more equipment', function() {
it('gives more equipment', () => {
user.fns.predictableRandom.returns(YIELD_EQUIPMENT);
user.items.gear.owned = {
weapon_warrior_0: true,
head_armoire_hornedIronHelm: true
head_armoire_hornedIronHelm: true,
};
user.stats.gp = 200;
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});
var armoireCount = shared.count.remainingGearInSet(user.items.gear.owned, 'armoire');
expect(armoireCount).to.eql((_.size(fullArmoire) - 2));
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true, shield_armoire_gladiatorShield: true, head_armoire_hornedIronHelm: true});
let armoireCount = shared.count.remainingGearInSet(user.items.gear.owned, 'armoire');
expect(armoireCount).to.eql(_.size(fullArmoire) - 2);
expect(user.stats.gp).to.eql(100);
});
});

View File

@@ -1,25 +1,36 @@
var shared = require('../../common/script/index.js');
shared.i18n.translations = require('../../website/src/libs/i18n.js').translations
/* eslint-disable camelcase */
let shared = require('../../common/script/index.js');
shared.i18n.translations = require('../../website/src/libs/i18n.js').translations;
require('./test_helper');
describe('User.fns.ultimateGear', function() {
it('sets armoirEnabled when partial achievement already achieved', function() {
var user = shared.wrap({
items: { gear: { owned: {
toObject: function() { return {
describe('User.fns.ultimateGear', () => {
it('sets armoirEnabled when partial achievement already achieved', () => {
let items = {
gear: {
owned: {
toObject: () => {
return {
armor_warrior_5: true,
shield_warrior_5: true,
head_warrior_5: true,
weapon_warrior_6: true
}}
}}},
achievements: {
ultimateGearSets: {}
weapon_warrior_6: true,
};
},
flags: {}
},
},
};
let user = shared.wrap({
items,
achievements: {
ultimateGearSets: {},
},
flags: {},
});
user.fns.ultimateGear();
expect(user.flags.armoireEnabled).to.equal(true);
});

View File

@@ -1,79 +1,73 @@
var sinon = require('sinon');
var chai = require("chai")
chai.use(require("sinon-chai"))
var expect = chai.expect
/* eslint-disable camelcase */
var shared = require('../../common/script/index.js');
var Content = require('../../common/script/content/index.js');
let shared = require('../../common/script/index.js');
describe('user.ops.buyMysterySet', function() {
var user;
describe('user.ops.buyMysterySet', () => {
let user;
beforeEach(function() {
beforeEach(() => {
user = {
items: {
gear: {
owned: {
weapon_warrior_0: true
}
}
weapon_warrior_0: true,
},
},
},
purchased: {
plan: {
consecutive: {
trinkets: 0
}
}
}
trinkets: 0,
},
},
},
};
shared.wrap(user);
});
context('Mystery Sets', function() {
context('failure conditions', function() {
it('does not grant mystery sets without Mystic Hourglasses', function(done) {
user.ops.buyMysterySet({params:{key:'201501'}}, function(response) {
expect(response.message).to.eql("You don't have enough Mystic Hourglasses.");
expect(user.items.gear.owned).to.eql({'weapon_warrior_0': true});
context('Mystery Sets', () => {
context('failure conditions', () => {
it('does not grant mystery sets without Mystic Hourglasses', (done) => {
user.ops.buyMysterySet({params: {key: '201501'}}, (response) => {
expect(response.message).to.eql('You don\'t have enough Mystic Hourglasses.');
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
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.items.gear.owned = {
weapon_warrior_0: true,
weapon_mystery_301404: true,
armor_mystery_301404: true,
head_mystery_301404: true,
eyewear_mystery_301404: true
eyewear_mystery_301404: true,
};
user.ops.buyMysterySet({params:{key:'301404'}}, function(response) {
expect(response.message).to.eql("Mystery set not found, or set already owned");
user.ops.buyMysterySet({params: {key: '301404'}}, (response) => {
expect(response.message).to.eql('Mystery set not found, or set already owned');
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
done();
});
});
});
context('successful purchases', function() {
it('buys Steampunk Accessories Set', function(done) {
context('successful purchases', () => {
it('buys Steampunk Accessories Set', (done) => {
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.items.gear.owned).to.eql({
weapon_warrior_0: true,
weapon_mystery_301404: true,
armor_mystery_301404: true,
head_mystery_301404: true,
eyewear_mystery_301404: true
eyewear_mystery_301404: true,
});
done();
});
});

View File

@@ -1,135 +1,126 @@
var sinon = require('sinon');
var chai = require('chai');
chai.use(require('sinon-chai'))
var expect = chai.expect
let shared = require('../../common/script/index.js');
var shared = require('../../common/script/index.js');
var content = require('../../common/script/content/index.js');
describe('user.ops.hatch', () => {
let user;
describe('user.ops.hatch', function() {
var user;
beforeEach(function() {
beforeEach(() => {
user = {
items: {
eggs: {},
hatchingPotions: {},
pets: {}
}
pets: {},
},
};
shared.wrap(user);
});
context('Pet Hatching', function() {
context('failure conditions', function() {
it('does not allow hatching without specifying egg and potion', function(done) {
user.ops.hatch({params:{}},function(response) {
context('Pet Hatching', () => {
context('failure conditions', () => {
it('does not allow hatching without specifying egg and potion', (done) => {
user.ops.hatch({params: {}}, (response) => {
expect(response.message).to.eql('Please specify query.egg & query.hatchingPotion');
expect(user.items.pets).to.be.empty;
done();
});
});
it('does not allow hatching if user lacks specified egg', function(done) {
user.items.eggs = {'Wolf':1};
user.items.hatchingPotions = {'Base':1};
user.ops.hatch({params:{egg:'Dragon',hatchingPotion:'Base'}}, function(response) {
it('does not allow hatching if user lacks specified egg', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.ops.hatch({params: {egg: 'Dragon', hatchingPotion: 'Base'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageMissingEggPotion'));
expect(user.items.pets).to.be.empty;
expect(user.items.eggs).to.eql({'Wolf':1});
expect(user.items.hatchingPotions).to.eql({'Base':1});
expect(user.items.eggs).to.eql({Wolf: 1});
expect(user.items.hatchingPotions).to.eql({Base: 1});
done();
});
});
it('does not allow hatching if user lacks specified hatching potion', function(done) {
user.items.eggs = {'Wolf':1};
user.items.hatchingPotions = {'Base':1};
user.ops.hatch({params:{egg:'Wolf',hatchingPotion:'Golden'}}, function(response) {
it('does not allow hatching if user lacks specified hatching potion', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Golden'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageMissingEggPotion'));
expect(user.items.pets).to.be.empty;
expect(user.items.eggs).to.eql({'Wolf':1});
expect(user.items.hatchingPotions).to.eql({'Base':1});
expect(user.items.eggs).to.eql({Wolf: 1});
expect(user.items.hatchingPotions).to.eql({Base: 1});
done();
});
});
it('does not allow hatching if user already owns target pet', function(done) {
user.items.eggs = {'Wolf':1};
user.items.hatchingPotions = {'Base':1};
user.items.pets = {'Wolf-Base':10};
user.ops.hatch({params:{egg:'Wolf',hatchingPotion:'Base'}}, function(response) {
it('does not allow hatching if user already owns target pet', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.items.pets = {'Wolf-Base': 10};
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Base'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageAlreadyPet'));
expect(user.items.pets).to.eql({'Wolf-Base':10});
expect(user.items.eggs).to.eql({'Wolf':1});
expect(user.items.hatchingPotions).to.eql({'Base':1});
expect(user.items.pets).to.eql({'Wolf-Base': 10});
expect(user.items.eggs).to.eql({Wolf: 1});
expect(user.items.hatchingPotions).to.eql({Base: 1});
done();
});
});
it('does not allow hatching quest pet egg using premium potion', function(done) {
user.items.eggs = {'Cheetah':1};
user.items.hatchingPotions = {'Spooky':1};
user.ops.hatch({params:{egg:'Cheetah',hatchingPotion:'Spooky'}}, function(response) {
it('does not allow hatching quest pet egg using premium potion', (done) => {
user.items.eggs = {Cheetah: 1};
user.items.hatchingPotions = {Spooky: 1};
user.ops.hatch({params: {egg: 'Cheetah', hatchingPotion: 'Spooky'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageInvalidEggPotionCombo'));
expect(user.items.pets).to.be.empty;
expect(user.items.eggs).to.eql({'Cheetah':1});
expect(user.items.hatchingPotions).to.eql({'Spooky':1});
expect(user.items.eggs).to.eql({Cheetah: 1});
expect(user.items.hatchingPotions).to.eql({Spooky: 1});
done();
});
});
});
context('successful hatching', function() {
it('hatches a basic pet', function(done) {
user.items.eggs = {'Wolf':1};
user.items.hatchingPotions = {'Base':1};
user.ops.hatch({params:{egg:'Wolf',hatchingPotion:'Base'}}, function(response) {
context('successful hatching', () => {
it('hatches a basic pet', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Base'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
expect(user.items.pets).to.eql({'Wolf-Base':5});
expect(user.items.eggs).to.eql({'Wolf':0});
expect(user.items.hatchingPotions).to.eql({'Base':0});
expect(user.items.pets).to.eql({'Wolf-Base': 5});
expect(user.items.eggs).to.eql({Wolf: 0});
expect(user.items.hatchingPotions).to.eql({Base: 0});
done();
});
});
it('hatches a quest pet', function(done) {
user.items.eggs = {'Cheetah':1};
user.items.hatchingPotions = {'Base':1};
user.ops.hatch({params:{egg:'Cheetah',hatchingPotion:'Base'}}, function(response) {
it('hatches a quest pet', (done) => {
user.items.eggs = {Cheetah: 1};
user.items.hatchingPotions = {Base: 1};
user.ops.hatch({params: {egg: 'Cheetah', hatchingPotion: 'Base'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
expect(user.items.pets).to.eql({'Cheetah-Base':5});
expect(user.items.eggs).to.eql({'Cheetah':0});
expect(user.items.hatchingPotions).to.eql({'Base':0});
expect(user.items.pets).to.eql({'Cheetah-Base': 5});
expect(user.items.eggs).to.eql({Cheetah: 0});
expect(user.items.hatchingPotions).to.eql({Base: 0});
done();
});
});
it('hatches a premium pet', function(done) {
user.items.eggs = {'Wolf':1};
user.items.hatchingPotions = {'Spooky':1};
user.ops.hatch({params:{egg:'Wolf',hatchingPotion:'Spooky'}}, function(response) {
it('hatches a premium pet', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Spooky: 1};
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Spooky'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
expect(user.items.pets).to.eql({'Wolf-Spooky':5});
expect(user.items.eggs).to.eql({'Wolf':0});
expect(user.items.hatchingPotions).to.eql({'Spooky':0});
expect(user.items.pets).to.eql({'Wolf-Spooky': 5});
expect(user.items.eggs).to.eql({Wolf: 0});
expect(user.items.hatchingPotions).to.eql({Spooky: 0});
done();
});
});
it('hatches a pet previously raised to a mount', function(done) {
user.items.eggs = {'Wolf':1};
user.items.hatchingPotions = {'Base':1};
user.items.pets = {'Wolf-Base':-1};
user.ops.hatch({params:{egg:'Wolf',hatchingPotion:'Base'}}, function(response) {
it('hatches a pet previously raised to a mount', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.items.pets = {'Wolf-Base': -1};
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Base'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
expect(user.items.pets).to.eql({'Wolf-Base':5});
expect(user.items.eggs).to.eql({'Wolf':0});
expect(user.items.hatchingPotions).to.eql({'Base':0});
expect(user.items.pets).to.eql({'Wolf-Base': 5});
expect(user.items.eggs).to.eql({Wolf: 0});
expect(user.items.hatchingPotions).to.eql({Base: 0});
done();
});
});

View File

@@ -1,101 +1,93 @@
var sinon = require('sinon');
var chai = require("chai")
chai.use(require("sinon-chai"))
var expect = chai.expect
let shared = require('../../common/script/index.js');
var shared = require('../../common/script/index.js');
var Content = require('../../common/script/content/index.js');
describe('user.ops.hourglassPurchase', () => {
let user;
describe('user.ops.hourglassPurchase', function() {
var user;
beforeEach(function() {
beforeEach(() => {
user = {
items: {
pets: {},
mounts: {},
hatchingPotions: {}
hatchingPotions: {},
},
purchased: {
plan: {
consecutive: {
trinkets: 0
}
}
}
trinkets: 0,
},
},
},
};
shared.wrap(user);
});
context('Time Travel Stable', function() {
context('failure conditions', function() {
it('does not allow purchase of unsupported item types', function(done) {
user.ops.hourglassPurchase({params:{type: 'hatchingPotions', key: 'Base'}}, function(response) {
context('Time Travel Stable', () => {
context('failure conditions', () => {
it('does not allow purchase of unsupported item types', (done) => {
user.ops.hourglassPurchase({params: {type: 'hatchingPotions', key: 'Base'}}, (response) => {
expect(response.message).to.eql('Item type not supported for purchase with Mystic Hourglass. Allowed types: ["pets","mounts"]');
expect(user.items.hatchingPotions).to.eql({});
done();
});
});
it('does not grant pets without Mystic Hourglasses', function(done) {
user.ops.hourglassPurchase({params:{type: 'pets', key: 'MantisShrimp-Base'}}, function(response) {
expect(response.message).to.eql("You don't have enough Mystic Hourglasses.");
it('does not grant pets without Mystic Hourglasses', (done) => {
user.ops.hourglassPurchase({params: {type: 'pets', key: 'MantisShrimp-Base'}}, (response) => {
expect(response.message).to.eql('You don\'t have enough Mystic Hourglasses.');
expect(user.items.pets).to.eql({});
done();
});
});
it('does not grant mounts without Mystic Hourglasses', function(done) {
user.ops.hourglassPurchase({params:{type: 'mounts', key: 'MantisShrimp-Base'}}, function(response) {
expect(response.message).to.eql("You don't have enough Mystic Hourglasses.");
it('does not grant mounts without Mystic Hourglasses', (done) => {
user.ops.hourglassPurchase({params: {type: 'mounts', key: 'MantisShrimp-Base'}}, (response) => {
expect(response.message).to.eql('You don\'t have enough Mystic Hourglasses.');
expect(user.items.mounts).to.eql({});
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.items.pets = {
'MantisShrimp-Base': true
'MantisShrimp-Base': true,
};
user.ops.hourglassPurchase({params:{type: 'pets', key: 'MantisShrimp-Base'}}, function(response) {
expect(response.message).to.eql("Pet already owned.");
user.ops.hourglassPurchase({params: {type: 'pets', key: 'MantisShrimp-Base'}}, (response) => {
expect(response.message).to.eql('Pet already owned.');
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
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.items.mounts = {
'MantisShrimp-Base': true
'MantisShrimp-Base': true,
};
user.ops.hourglassPurchase({params:{type: 'mounts', key: 'MantisShrimp-Base'}}, function(response) {
expect(response.message).to.eql("Mount already owned.");
user.ops.hourglassPurchase({params: {type: 'mounts', key: 'MantisShrimp-Base'}}, (response) => {
expect(response.message).to.eql('Mount already owned.');
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
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.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(user.purchased.plan.consecutive.trinkets).to.eql(1);
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.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(user.purchased.plan.consecutive.trinkets).to.eql(1);
done();
@@ -103,26 +95,25 @@ describe('user.ops.hourglassPurchase', function() {
});
});
context('successful purchases', function() {
it('buys a pet', function(done) {
context('successful purchases', () => {
it('buys a pet', (done) => {
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(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();
});
});
it('buys a mount', function(done) {
it('buys a mount', (done) => {
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(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();
});
});

View File

@@ -1,36 +1,30 @@
var sinon = require('sinon');
var chai = require("chai")
chai.use(require("sinon-chai"))
var expect = chai.expect
var _ = require('lodash');
let shared = require('../../common/script/index.js');
var shared = require('../../common/script/index.js');
describe('user.ops', () => {
let user;
describe('user.ops', function() {
var user;
beforeEach(function() {
beforeEach(() => {
user = {
items: {
gear: { },
special: { }
special: { },
},
achievements: { },
flags: { }
flags: { },
};
shared.wrap(user);
});
describe('readCard', function() {
it('removes card from invitation array', function() {
describe('readCard', () => {
it('removes card from invitation array', () => {
user.items.special.valentineReceived = ['Leslie'];
user.ops.readCard({ params: { cardType: 'valentine' } });
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.ops.readCard({ params: { cardType: 'valentine' } });