From e8116937525185ddfa4d3a013b5a6e48184d15a6 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Mon, 16 Nov 2015 15:11:11 +0100 Subject: [PATCH 1/6] Subscriber benefits changed to be dynamic. Fixed arithmetic of gemGoldCap. --- website/public/js/controllers/settingsCtrl.js | 4 ++-- website/views/options/settings.jade | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/website/public/js/controllers/settingsCtrl.js b/website/public/js/controllers/settingsCtrl.js index ed9ac730f1..97df03b8fb 100644 --- a/website/public/js/controllers/settingsCtrl.js +++ b/website/public/js/controllers/settingsCtrl.js @@ -206,10 +206,10 @@ habitrpg.controller('SettingsCtrl', var baseCap = 25; var gemCapExtra = User.user.purchased.plan.consecutive.gemCapExtra; // @TODO: What are these magic numbers? 3? 5? - var blocks = Content.subscriptionBlocks[subscription.key].months / 3 * 5; + var blocks = Content.subscriptionBlocks[subscription.key].months / 3; var flooredBlocks = Math.floor(blocks); - var userTotalDropCap = baseCap + gemCapExtra + flooredBlocks; + var userTotalDropCap = baseCap + gemCapExtra + flooredBlocks * 5; var maxDropCap = 50; return [userTotalDropCap, maxDropCap]; diff --git a/website/views/options/settings.jade b/website/views/options/settings.jade index 9a0808b2eb..43e1c17608 100644 --- a/website/views/options/settings.jade +++ b/website/views/options/settings.jade @@ -269,7 +269,7 @@ mixin subPerks() tr td span.hint(popover=env.t('buyGemsGoldText', {gemCost: "{{Shared.planGemLimits.convRate}}", gemLimit: "{{Shared.planGemLimits.convCap}}"}),popover-trigger='mouseenter',popover-placement='right') #{env.t('buyGemsGold')}  - span.badge.badge-success(ng-show='_subscription.key!="basic_earned"')=env.t('buyGemsGoldCap', {amount: '{{:: gemGoldCap(_subscription) | min }}'}) + span.badge.badge-success(ng-show='_subscription.key!="basic_earned"')=env.t('buyGemsGoldCap', {amount: '{{gemGoldCap(_subscription) | min }}'}) tr td span.hint(popover=env.t('retainHistoryText'),popover-trigger='mouseenter',popover-placement='right')=env.t('retainHistory') @@ -280,7 +280,7 @@ mixin subPerks() td span.hint(popover=env.t('mysteryItemText'),popover-trigger='mouseenter',popover-placement='right') #{env.t('mysteryItem')}  div(ng-show='_subscription.key!="basic_earned"') - .badge.badge-success=env.t('mysticHourglass', {amount: '+{{:: numberOfMysticHourglasses(_subscription)}}'}) + .badge.badge-success=env.t('mysticHourglass', {amount: '+{{numberOfMysticHourglasses(_subscription)}}'}) .small.muted=env.t('mysticHourglassText') tr td From 53417adda11114d93ffc30a9c2c7ace839cb8a7d Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Tue, 17 Nov 2015 14:07:35 +0100 Subject: [PATCH 2/6] Replaced magic numbers with variables --- website/public/js/controllers/settingsCtrl.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/website/public/js/controllers/settingsCtrl.js b/website/public/js/controllers/settingsCtrl.js index 97df03b8fb..e785c7c02e 100644 --- a/website/public/js/controllers/settingsCtrl.js +++ b/website/public/js/controllers/settingsCtrl.js @@ -204,12 +204,13 @@ habitrpg.controller('SettingsCtrl', $scope.gemGoldCap = function(subscription) { var baseCap = 25; + var gemCapIncrement = 5; + var capIncrementThreshold = 3; var gemCapExtra = User.user.purchased.plan.consecutive.gemCapExtra; - // @TODO: What are these magic numbers? 3? 5? - var blocks = Content.subscriptionBlocks[subscription.key].months / 3; + var blocks = Content.subscriptionBlocks[subscription.key].months / capIncrementThreshold; var flooredBlocks = Math.floor(blocks); - var userTotalDropCap = baseCap + gemCapExtra + flooredBlocks * 5; + var userTotalDropCap = baseCap + gemCapExtra + flooredBlocks * gemCapIncrement; var maxDropCap = 50; return [userTotalDropCap, maxDropCap]; From 5947dcf68b4080f7bcfa7b8cb4d272138d4a5c61 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Wed, 18 Nov 2015 17:23:33 -0600 Subject: [PATCH 3/6] (chore): Add lint:watch task --- tasks/gulp-eslint.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tasks/gulp-eslint.js b/tasks/gulp-eslint.js index 446d9d8324..47b46ea00d 100644 --- a/tasks/gulp-eslint.js +++ b/tasks/gulp-eslint.js @@ -63,3 +63,11 @@ gulp.task('lint:tests', () => { }); gulp.task('lint', ['lint:server', 'lint:common']); + +gulp.task('lint:watch', () => { + gulp.watch([ + './website/src/**/*.js', + './common/script/**/*.js', + './test/**/*.js', + ], ['lint']); +}); From bdf1c82b395e8752307398810c9da69f21486ef7 Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Thu, 19 Nov 2015 21:22:38 -0500 Subject: [PATCH 4/6] chore(news): Misc Bailey --- website/views/shared/new-stuff.jade | 36 +++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/website/views/shared/new-stuff.jade b/website/views/shared/new-stuff.jade index a07d982eca..53cad67402 100644 --- a/website/views/shared/new-stuff.jade +++ b/website/views/shared/new-stuff.jade @@ -1,26 +1,42 @@ -h2 11/16/2015 - HABITICA STICKERS AND COSTUME CONTEST BADGES! +h2 11/19/2015 - SMALL iOS UPDATE AND HABITICA HIRING NEWS! hr tr td - .achievement-costumeContest2x.pull-right - h3 Costume Contest Badges - p We've awarded all the costume contest badges! Over the coming months, we'll be posting the costumes on our blog, so be sure to follow along. + h3 Habitica Hiring News + p Exciting news! Right now, Habitica is looking to add a senior full stack developer to our team, and what better place to look than our awesome community? br - p Important: if you submitted a photo but did NOT receive your badge, it probably means that we were unable to view your entry due to privacy restrictions or other issues. Email your photo to leslie@habitica.com and she will make sure that you get your badge! + p If you’d like to apply, you should have experience as a lead developer, and be a JavaScript whiz who is familiar with MongoDB and Angular. Bonus points for familiarity with our tech stack! Passion for open source is, naturally, a must ;) br - p Thanks again to all the participants. We were very impressed by your creativity! + p Send your resume to jobs@habitica.com with your GitHub handle, Habitica username, and list of favorite online hangouts! Please also let us know whether or not you would be able to move to Los Angeles. We’re looking forward to hearing from you! tr td - .promo_habitica_sticker.pull-right - h3 Habitica Stickers - p In addition to our Habitica T-shirts, we are now also selling Habitica Stickers! Display Melior anywhere for extra motivation. - p.small.muted by Redphoenix and Sara Olson + h3 Small iOS App Update + p We've released a small iOS update, just to fix some bothersome bugs (including crashes), add a nice intro slide for new users, and make it more obvious how to invite your friends to your party. + br + p If you already reviewed the last version of the app, Apple has hidden it for this version, but you can automatically post the same review again by tapping “Write a review” and then just hitting "Send." Thank you very much for taking the time to share your thoughts with us! Posting and reposting reviews really helps us out. + p.small.muted by Viirus and Lemoness if menuItem !== 'oldNews' hr a(href='/static/old-news', target='_blank') Read older news mixin oldNews + h2 11/16/2015 - HABITICA STICKERS AND COSTUME CONTEST BADGES! + tr + td + .achievement-costumeContest2x.pull-right + h3 Costume Contest Badges + p We've awarded all the costume contest badges! Over the coming months, we'll be posting the costumes on our blog, so be sure to follow along. + br + p Important: if you submitted a photo but did NOT receive your badge, it probably means that we were unable to view your entry due to privacy restrictions or other issues. Email your photo to leslie@habitica.com and she will make sure that you get your badge! + br + p Thanks again to all the participants. We were very impressed by your creativity! + tr + td + .promo_habitica_sticker.pull-right + h3 Habitica Stickers + p In addition to our Habitica T-shirts, we are now also selling Habitica Stickers! Display Melior anywhere for extra motivation. + p.small.muted by Redphoenix and Sara Olson h2 11/11/2015 - NOVEMBER PET QUEST, SHARE SUCCESS, AND HABITICA T-SHIRTS tr td From 776faddb3442bf269427dab0f7c3a04caced6e3f Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Thu, 19 Nov 2015 20:27:39 -0600 Subject: [PATCH 5/6] (chore): lint test/common files --- tasks/gulp-eslint.js | 8 +- test/common/algos.mocha.js | 1387 +++++++++-------- test/common/count.js | 251 +-- test/common/dailies.js | 504 +++--- test/common/test_helper.js | 74 +- test/common/user.fns.buy.test.js | 140 +- test/common/user.fns.ultimateGear.test.js | 45 +- test/common/user.ops.buyMysterySet.test.js | 60 +- test/common/user.ops.hatch.js | 141 +- .../common/user.ops.hourglassPurchase.test.js | 85 +- test/common/user.ops.test.js | 24 +- 11 files changed, 1368 insertions(+), 1351 deletions(-) diff --git a/tasks/gulp-eslint.js b/tasks/gulp-eslint.js index 47b46ea00d..6875f27d4c 100644 --- a/tasks/gulp-eslint.js +++ b/tasks/gulp-eslint.js @@ -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([ diff --git a/test/common/algos.mocha.js b/test/common/algos.mocha.js index 06ebd3044d..af902bd46c 100644 --- a/test/common/algos.mocha.js +++ b/test/common/algos.mocha.js @@ -1,44 +1,30 @@ -var $w, _, beforeAfter, cycle, expect, expectClosePoints, expectDayResetNoDamage, expectGainedPoints, expectLostPoints, expectNoChange, expectStrings, moment, newUser, repeatWithoutLastWeekday, rewrapUser, shared, sinon, test_helper; - -_ = require('lodash'); - -expect = require('expect.js'); - -sinon = require('sinon'); - -moment = require('moment'); - -shared = require('../../common/script/index.js'); - -shared.i18n.translations = require('../../website/src/libs/i18n.js').translations; - -test_helper = require('./test_helper'); - -test_helper.addCustomMatchers(); - -$w = function(s) { +/* eslint-disable camelcase, func-names, no-shadow */ +let expect = require('expect.js'); +let sinon = require('sinon'); +let moment = require('moment'); +let test_helper = require('./test_helper'); +let shared = require('../../common/script/index.js'); +let $w = (s) => { return s.split(' '); }; +shared.i18n.translations = require('../../website/src/libs/i18n.js').translations; +test_helper.addCustomMatchers(); /* Helper Functions */ -newUser = function(addTasks) { - var buffs, user; - if (addTasks == null) { - addTasks = true; - } - buffs = { +let newUser = (addTasks = true) => { + let buffs = { per: 0, int: 0, con: 0, str: 0, stealth: 0, - streaks: false + streaks: false, }; - user = { + let user = { auth: { - timestamps: {} + timestamps: {}, }, stats: { str: 1, @@ -46,12 +32,12 @@ newUser = function(addTasks) { per: 1, int: 1, mp: 32, - "class": 'warrior', - buffs: buffs + class: 'warrior', + buffs, }, items: { lastDrop: { - count: 0 + count: 0, }, hatchingPotions: {}, eggs: {}, @@ -59,209 +45,194 @@ newUser = function(addTasks) { gear: { equipped: {}, costume: {}, - owned: {} + owned: {}, }, - quests: {} + quests: {}, }, party: { quest: { progress: { - down: 0 - } - } + down: 0, + }, + }, }, preferences: { - autoEquip: true + autoEquip: true, }, dailys: [], todos: [], rewards: [], flags: {}, achievements: { - ultimateGearSets: {} + ultimateGearSets: {}, }, contributor: { - level: 2 + level: 2, }, - _tmp: {} + _tmp: {}, }; + 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; }; -rewrapUser = function(user) { +let rewrapUser = (user) => { user._wrapped = false; shared.wrap(user); return user; }; -expectStrings = function(obj, paths) { - return _.each(paths, function(path) { - return expect(obj[path]).to.be.ok(); - }); -}; +let beforeAfter = (options = {}) => { + let lastCron; + let user = newUser(); + let ref = [user, _.cloneDeep(user)]; + let before = ref[0]; + let after = ref[1]; -beforeAfter = function(options) { - var after, before, lastCron, ref, user; - if (options == null) { - options = {}; - } - user = newUser(); - ref = [user, _.cloneDeep(user)], before = ref[0], after = ref[1]; rewrapUser(after); if (options.dayStart) { before.preferences.dayStart = after.preferences.dayStart = options.dayStart; } before.preferences.timezoneOffset = after.preferences.timezoneOffset = options.timezoneOffset || moment().zone(); if (options.limitOne) { - before[options.limitOne + "s"] = [before[options.limitOne + "s"][0]]; - after[options.limitOne + "s"] = [after[options.limitOne + "s"][0]]; + before[`${options.limitOne}s`] = [before[`${options.limitOne}s`][0]]; + after[`${options.limitOne}s`] = [after[`${options.limitOne}s`][0]]; } if (options.daysAgo) { - lastCron = moment(options.now || +(new Date)).subtract({ - days: options.daysAgo + lastCron = moment(options.now || Number(new Date())).subtract({ + days: options.daysAgo, }); } if (options.daysAgo && options.cronAfterStart) { lastCron.add({ hours: options.dayStart, - minutes: 1 + minutes: 1, }); } if (options.daysAgo) { - lastCron = +lastCron; + lastCron = Number(lastCron); } - _.each([before, after], function(obj) { + _.each([before, after], (obj) => { if (options.daysAgo) { - return obj.lastCron = lastCron; + obj.lastCron = lastCron; } }); return { - before: before, - after: after + before, + after, }; }; -expectLostPoints = function(before, after, taskType) { +let expectLostPoints = (before, after, taskType) => { if (taskType === 'daily' || taskType === 'habit') { expect(after.stats.hp).to.be.lessThan(before.stats.hp); - expect(after[taskType + "s"][0].history).to.have.length(1); + expect(after[`${taskType}s`][0].history).to.have.length(1); } else { expect(after.history.todos).to.have.length(1); } expect(after).toHaveExp(0); expect(after).toHaveGP(0); - return expect(after[taskType + "s"][0].value).to.be.lessThan(before[taskType + "s"][0].value); + expect(after[`${taskType}s`][0].value).to.be.lessThan(before[`${taskType}s`][0].value); }; -expectGainedPoints = function(before, after, taskType) { +let expectGainedPoints = (before, after, taskType) => { expect(after.stats.hp).to.be(50); expect(after.stats.exp).to.be.greaterThan(before.stats.exp); expect(after.stats.gp).to.be.greaterThan(before.stats.gp); - expect(after[taskType + "s"][0].value).to.be.greaterThan(before[taskType + "s"][0].value); + expect(after[`${taskType}s`][0].value).to.be.greaterThan(before[`${taskType}s`][0].value); if (taskType === 'habit') { - return expect(after[taskType + "s"][0].history).to.have.length(1); + expect(after[`${taskType}s`][0].history).to.have.length(1); } }; -expectNoChange = function(before, after) { - return _.each($w('stats items gear dailys todos rewards preferences'), function(attr) { - return expect(after[attr]).to.eql(before[attr]); +let expectNoChange = (before, after) => { + _.each($w('stats items gear dailys todos rewards preferences'), (attr) => { + expect(after[attr]).to.eql(before[attr]); }); }; -expectClosePoints = function(before, after, taskType) { +let expectClosePoints = (before, after, taskType) => { expect(Math.abs(after.stats.exp - before.stats.exp)).to.be.lessThan(0.0001); expect(Math.abs(after.stats.gp - before.stats.gp)).to.be.lessThan(0.0001); - return expect(Math.abs(after[taskType + "s"][0].value - before[taskType + "s"][0].value)).to.be.lessThan(0.0001); + expect(Math.abs(after[taskType + 's'][0].value - before[taskType + 's'][0].value)).to.be.lessThan(0.0001); // eslint-disable-line prefer-template }; -expectDayResetNoDamage = function(b, a) { - var after, before, ref; - ref = [_.cloneDeep(b), _.cloneDeep(a)], before = ref[0], after = ref[1]; - _.each(after.dailys, function(task, i) { +let expectDayResetNoDamage = (b, a) => { + let ref = [_.cloneDeep(b), _.cloneDeep(a)]; + let before = ref[0]; + let after = ref[1]; + + _.each(after.dailys, (task, i) => { expect(task.completed).to.be(false); expect(before.dailys[i].value).to.be(task.value); expect(before.dailys[i].streak).to.be(task.streak); - return expect(task.history).to.have.length(1); + expect(task.history).to.have.length(1); }); - _.each(after.todos, function(task, i) { + _.each(after.todos, (task, i) => { expect(task.completed).to.be(false); - return expect(before.todos[i].value).to.be.greaterThan(task.value); + expect(before.todos[i].value).to.be.greaterThan(task.value); }); expect(after.history.todos).to.have.length(1); - _.each([before, after], function(obj) { + _.each([before, after], (obj) => { delete obj.stats.buffs; - return _.each($w('dailys todos history lastCron'), function(path) { + _.each($w('dailys todos history lastCron'), (path) => { return delete obj[path]; }); }); delete after._tmp; - return expectNoChange(before, after); + expectNoChange(before, after); }; -cycle = function(array) { - var n; - n = -1; - return function(seed) { - if (seed == null) { - seed = 0; - } - n++; - return array[n % array.length]; - }; -}; - -repeatWithoutLastWeekday = function() { - var repeat; - repeat = { +let repeatWithoutLastWeekday = () => { + 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, }; }; -describe('User', function() { - it('sets correct user defaults', function() { - var base_gear, buffs, user; - user = newUser(); - base_gear = { +describe('User', () => { + it('sets correct user defaults', () => { + let user = newUser(); + let base_gear = { armor: 'armor_base_0', weapon: 'weapon_base_0', head: 'head_base_0', - shield: 'shield_base_0' + shield: 'shield_base_0', }; - buffs = { + let buffs = { per: 0, int: 0, con: 0, str: 0, stealth: 0, - streaks: false + streaks: false, }; + expect(user.stats).to.eql({ str: 1, con: 1, @@ -272,47 +243,48 @@ describe('User', function() { lvl: 1, exp: 0, gp: 0, - "class": 'warrior', - buffs: buffs + class: 'warrior', + buffs, }); expect(user.items.gear).to.eql({ equipped: base_gear, costume: base_gear, owned: { - weapon_warrior_0: true - } + weapon_warrior_0: true, + }, }); - return expect(user.preferences).to.eql({ + expect(user.preferences).to.eql({ autoEquip: true, - costume: false + costume: false, }); }); - it('calculates max MP', function() { - var user; - user = newUser(); + it('calculates max MP', () => { + let user = newUser(); + expect(user).toHaveMaxMP(32); user.stats.int = 10; expect(user).toHaveMaxMP(50); user.stats.lvl = 5; expect(user).toHaveMaxMP(54); - user.stats["class"] = 'wizard'; + user.stats.class = 'wizard'; user.items.gear.equipped.weapon = 'weapon_wizard_1'; - return expect(user).toHaveMaxMP(63); + expect(user).toHaveMaxMP(63); }); - it('handles perfect days', function() { - var cron, user, yesterday; - user = newUser(); + it('handles perfect days', () => { + let user = newUser(); + user.dailys = []; - _.times(3, function() { + _.times(3, () => { return user.dailys.push(shared.taskDefaults({ type: 'daily', - startDate: moment().subtract(7, 'days') + startDate: moment().subtract(7, 'days'), })); }); - cron = function() { + let cron = () => { user.lastCron = moment().subtract(1, 'days'); return user.fns.cron(); }; + cron(); expect(user.stats.buffs.str).to.be(0); expect(user.achievements.perfect).to.not.be.ok(); @@ -320,191 +292,197 @@ describe('User', function() { cron(); expect(user.stats.buffs.str).to.be(0); expect(user.achievements.perfect).to.not.be.ok(); - _.each(user.dailys, function(d) { - return d.completed = true; + _.each(user.dailys, (d) => { + d.completed = true; }); cron(); expect(user.stats.buffs.str).to.be(1); expect(user.achievements.perfect).to.be(1); - yesterday = moment().subtract(1, 'days'); + + let yesterday = moment().subtract(1, 'days'); + user.dailys[0].repeat[shared.dayMapping[yesterday.day()]] = false; - _.each(user.dailys.slice(1), function(d) { - return d.completed = true; + _.each(user.dailys.slice(1), (d) => { + d.completed = true; }); cron(); expect(user.stats.buffs.str).to.be(1); - return expect(user.achievements.perfect).to.be(2); + expect(user.achievements.perfect).to.be(2); }); - describe('Resting in the Inn', function() { - var cron, user; - user = null; - cron = null; - beforeEach(function() { + describe('Resting in the Inn', () => { + let user = null; + let cron = null; + + beforeEach(() => { user = newUser(); user.preferences.sleep = true; - cron = function() { + cron = () => { user.lastCron = moment().subtract(1, 'days'); return user.fns.cron(); }; user.dailys = []; - return _.times(2, function() { + _.times(2, () => { return user.dailys.push(shared.taskDefaults({ type: 'daily', - startDate: moment().subtract(7, 'days') + startDate: moment().subtract(7, 'days'), })); }); }); - it('remains in the inn on cron', function() { + it('remains in the inn on cron', () => { cron(); - return expect(user.preferences.sleep).to.be(true); + expect(user.preferences.sleep).to.be(true); }); - it('resets dailies', function() { + it('resets dailies', () => { user.dailys[0].completed = true; cron(); - return expect(user.dailys[0].completed).to.be(false); + expect(user.dailys[0].completed).to.be(false); }); - it('resets checklist on incomplete dailies', function() { + it('resets checklist on incomplete dailies', () => { user.dailys[0].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, + }, ]; cron(); - return _.each(user.dailys[0].checklist, function(box) { - return expect(box.completed).to.be(false); + _.each(user.dailys[0].checklist, (box) => { + expect(box.completed).to.be(false); }); }); - it('resets checklist on complete dailies', function() { + it('resets checklist on complete dailies', () => { user.dailys[0].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, + }, ]; user.dailys[0].completed = true; cron(); - return _.each(user.dailys[0].checklist, function(box) { - return expect(box.completed).to.be(false); + _.each(user.dailys[0].checklist, (box) => { + expect(box.completed).to.be(false); }); }); - it('does not reset checklist on grey incomplete dailies', function() { - var yesterday; - yesterday = moment().subtract(1, 'days'); + it('does not reset checklist on grey incomplete dailies', () => { + let yesterday = moment().subtract(1, 'days'); + user.dailys[0].repeat[shared.dayMapping[yesterday.day()]] = false; user.dailys[0].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": true - } + text: '3', + id: 'checklist-three', + completed: true, + }, ]; cron(); - return _.each(user.dailys[0].checklist, function(box) { - return expect(box.completed).to.be(true); + _.each(user.dailys[0].checklist, (box) => { + expect(box.completed).to.be(true); }); }); - it('resets checklist on complete grey complete dailies', function() { - var yesterday; - yesterday = moment().subtract(1, 'days'); + it('resets checklist on complete grey complete dailies', () => { + let yesterday = moment().subtract(1, 'days'); + user.dailys[0].repeat[shared.dayMapping[yesterday.day()]] = false; user.dailys[0].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": true - } + text: '3', + id: 'checklist-three', + completed: true, + }, ]; user.dailys[0].completed = true; cron(); - return _.each(user.dailys[0].checklist, function(box) { - return expect(box.completed).to.be(false); + _.each(user.dailys[0].checklist, (box) => { + expect(box.completed).to.be(false); }); }); - it('does not damage user for incomplete dailies', function() { + it('does not damage user for incomplete dailies', () => { expect(user).toHaveHP(50); user.dailys[0].completed = true; user.dailys[1].completed = false; cron(); - return expect(user).toHaveHP(50); + expect(user).toHaveHP(50); }); - it('gives credit for complete dailies', function() { + it('gives credit for complete dailies', () => { user.dailys[0].completed = true; expect(user.dailys[0].history).to.be.empty; cron(); - return expect(user.dailys[0].history).to.not.be.empty; + expect(user.dailys[0].history).to.not.be.empty; }); - return it('damages user for incomplete dailies after checkout', function() { + it('damages user for incomplete dailies after checkout', () => { expect(user).toHaveHP(50); user.dailys[0].completed = true; user.dailys[1].completed = false; user.preferences.sleep = false; cron(); - return expect(user.stats.hp).to.be.lessThan(50); + expect(user.stats.hp).to.be.lessThan(50); }); }); - describe('Death', function() { - var user; - user = void 0; - it('revives correctly', function() { + describe('Death', () => { + let user; + + beforeEach(() => { user = newUser(); + }); + + it('revives correctly', () => { user.stats = { gp: 10, exp: 100, lvl: 2, hp: 0, - "class": 'warrior' + class: 'warrior', }; user.ops.revive(); expect(user).toHaveGP(0); expect(user).toHaveExp(0); expect(user).toHaveLevel(1); expect(user).toHaveHP(50); - return expect(user.items.gear.owned).to.eql({ - weapon_warrior_0: false + expect(user.items.gear.owned).to.eql({ + weapon_warrior_0: false, }); }); - it("doesn't break unbreakables", function() { - var ce; + + it('doesn\'t break unbreakables', () => { + let ce; + ce = shared.countExists; - user = newUser(); - user.items.gear.owned['shield_warrior_1'] = true; - user.items.gear.owned['shield_rogue_1'] = true; - user.items.gear.owned['head_special_nye'] = true; + user.items.gear.owned.shield_warrior_1 = true; + user.items.gear.owned.shield_rogue_1 = true; + user.items.gear.owned.head_special_nye = true; expect(ce(user.items.gear.owned)).to.be(4); user.stats.hp = 0; user.ops.revive(); @@ -515,168 +493,170 @@ describe('User', function() { user.stats.hp = 0; user.ops.revive(); expect(ce(user.items.gear.owned)).to.be(2); - return expect(user.items.gear.owned).to.eql({ + expect(user.items.gear.owned).to.eql({ weapon_warrior_0: false, shield_warrior_1: false, shield_rogue_1: true, - head_special_nye: true + head_special_nye: true, }); }); - return it("handles event items", function() { + + it('handles event items', () => { + user.items.gear.owned.head_special_nye = true; + shared.content.gear.flat.head_special_nye.event.start = '2012-01-01'; shared.content.gear.flat.head_special_nye.event.end = '2012-02-01'; expect(shared.content.gear.flat.head_special_nye.canOwn(user)).to.be(true); - delete user.items.gear.owned['head_special_nye']; + delete user.items.gear.owned.head_special_nye; expect(shared.content.gear.flat.head_special_nye.canOwn(user)).to.be(false); shared.content.gear.flat.head_special_nye.event.start = moment().subtract(5, 'days'); shared.content.gear.flat.head_special_nye.event.end = moment().add(5, 'days'); - return expect(shared.content.gear.flat.head_special_nye.canOwn(user)).to.be(true); + expect(shared.content.gear.flat.head_special_nye.canOwn(user)).to.be(true); }); }); - describe('Rebirth', function() { - var user; - user = void 0; - return it('removes correct gear', function() { - user = newUser(); + describe('Rebirth', () => { + it('removes correct gear', () => { + let user = newUser(); + user.stats.lvl = 100; user.items.gear.owned = { - "weapon_warrior_0": true, - "weapon_warrior_1": true, - "armor_warrior_1": false, - "armor_mystery_201402": true, - "back_mystery_201402": false, - "head_mystery_201402": true, - "weapon_armoire_basicCrossbow": true + weapon_warrior_0: true, + weapon_warrior_1: true, + armor_warrior_1: false, + armor_mystery_201402: true, + back_mystery_201402: false, + head_mystery_201402: true, + weapon_armoire_basicCrossbow: true, }; user.ops.rebirth(); - return expect(user.items.gear.owned).to.eql({ - "weapon_warrior_0": true, - "weapon_warrior_1": false, - "armor_warrior_1": false, - "armor_mystery_201402": true, - "back_mystery_201402": false, - "head_mystery_201402": true, - "weapon_armoire_basicCrossbow": false + expect(user.items.gear.owned).to.eql({ + weapon_warrior_0: true, + weapon_warrior_1: false, + armor_warrior_1: false, + armor_mystery_201402: true, + back_mystery_201402: false, + head_mystery_201402: true, + weapon_armoire_basicCrossbow: false, }); }); }); - describe('store', function() { - it('buys a Quest scroll', function() { - var user; - user = newUser(); + describe('store', () => { + it('buys a Quest scroll', () => { + let user = newUser(); + user.stats.gp = 205; user.ops.buyQuest({ params: { - key: 'dilatoryDistress1' - } + key: 'dilatoryDistress1', + }, }); expect(user.items.quests).to.eql({ - dilatoryDistress1: 1 + dilatoryDistress1: 1, }); - return expect(user).toHaveGP(5); + expect(user).toHaveGP(5); }); - it('does not buy Quests without enough Gold', function() { - var user; - user = newUser(); + it('does not buy Quests without enough Gold', () => { + let user = newUser(); + user.stats.gp = 1; user.ops.buyQuest({ params: { - key: 'dilatoryDistress1' - } + key: 'dilatoryDistress1', + }, }); expect(user.items.quests).to.eql({}); - return expect(user).toHaveGP(1); + expect(user).toHaveGP(1); }); - it('does not buy nonexistent Quests', function() { - var user; - user = newUser(); + it('does not buy nonexistent Quests', () => { + let user = newUser(); + user.stats.gp = 9999; user.ops.buyQuest({ params: { - key: 'snarfblatter' - } + key: 'snarfblatter', + }, }); expect(user.items.quests).to.eql({}); - return expect(user).toHaveGP(9999); + expect(user).toHaveGP(9999); }); - return it('does not buy Gem-premium Quests', function() { - var user; - user = newUser(); + it('does not buy Gem-premium Quests', () => { + let user = newUser(); + user.stats.gp = 9999; user.ops.buyQuest({ params: { - key: 'kraken' - } + key: 'kraken', + }, }); expect(user.items.quests).to.eql({}); - return expect(user).toHaveGP(9999); + expect(user).toHaveGP(9999); }); }); - describe('Gem purchases', function() { - it('does not purchase items without enough Gems', function() { - var user; - user = newUser(); + describe('Gem purchases', () => { + it('does not purchase items without enough Gems', () => { + let user = newUser(); + user.ops.purchase({ params: { type: 'eggs', - key: 'Cactus' - } + key: 'Cactus', + }, }); user.ops.purchase({ params: { type: 'gear', - key: 'headAccessory_special_foxEars' - } + key: 'headAccessory_special_foxEars', + }, }); user.ops.unlock({ query: { - path: 'items.gear.owned.headAccessory_special_bearEars,items.gear.owned.headAccessory_special_cactusEars,items.gear.owned.headAccessory_special_foxEars,items.gear.owned.headAccessory_special_lionEars,items.gear.owned.headAccessory_special_pandaEars,items.gear.owned.headAccessory_special_pigEars,items.gear.owned.headAccessory_special_tigerEars,items.gear.owned.headAccessory_special_wolfEars' - } + path: 'items.gear.owned.headAccessory_special_bearEars,items.gear.owned.headAccessory_special_cactusEars,items.gear.owned.headAccessory_special_foxEars,items.gear.owned.headAccessory_special_lionEars,items.gear.owned.headAccessory_special_pandaEars,items.gear.owned.headAccessory_special_pigEars,items.gear.owned.headAccessory_special_tigerEars,items.gear.owned.headAccessory_special_wolfEars', + }, }); expect(user.items.eggs).to.eql({}); - return expect(user.items.gear.owned).to.eql({ - weapon_warrior_0: true + expect(user.items.gear.owned).to.eql({ + weapon_warrior_0: true, }); }); - it('purchases an egg', function() { - var user; - user = newUser(); + it('purchases an egg', () => { + let user = newUser(); + user.balance = 1; user.ops.purchase({ params: { type: 'eggs', - key: 'Cactus' - } + key: 'Cactus', + }, }); expect(user.items.eggs).to.eql({ - Cactus: 1 + Cactus: 1, }); - return expect(user.balance).to.eql(0.25); + expect(user.balance).to.eql(0.25); }); - it('purchases fox ears', function() { - var user; - user = newUser(); + it('purchases fox ears', () => { + let user = newUser(); + user.balance = 1; user.ops.purchase({ params: { type: 'gear', - key: 'headAccessory_special_foxEars' - } + key: 'headAccessory_special_foxEars', + }, }); expect(user.items.gear.owned).to.eql({ weapon_warrior_0: true, - headAccessory_special_foxEars: true + headAccessory_special_foxEars: true, }); - return expect(user.balance).to.eql(0.5); + expect(user.balance).to.eql(0.5); }); - return it('unlocks all the animal ears at once', function() { - var user; - user = newUser(); + it('unlocks all the animal ears at once', () => { + let user = newUser(); + user.balance = 2; user.ops.unlock({ query: { - path: 'items.gear.owned.headAccessory_special_bearEars,items.gear.owned.headAccessory_special_cactusEars,items.gear.owned.headAccessory_special_foxEars,items.gear.owned.headAccessory_special_lionEars,items.gear.owned.headAccessory_special_pandaEars,items.gear.owned.headAccessory_special_pigEars,items.gear.owned.headAccessory_special_tigerEars,items.gear.owned.headAccessory_special_wolfEars' - } + path: 'items.gear.owned.headAccessory_special_bearEars,items.gear.owned.headAccessory_special_cactusEars,items.gear.owned.headAccessory_special_foxEars,items.gear.owned.headAccessory_special_lionEars,items.gear.owned.headAccessory_special_pandaEars,items.gear.owned.headAccessory_special_pigEars,items.gear.owned.headAccessory_special_tigerEars,items.gear.owned.headAccessory_special_wolfEars', + }, }); expect(user.items.gear.owned).to.eql({ weapon_warrior_0: true, @@ -687,56 +667,57 @@ describe('User', function() { headAccessory_special_pandaEars: true, headAccessory_special_pigEars: true, headAccessory_special_tigerEars: true, - headAccessory_special_wolfEars: true + headAccessory_special_wolfEars: true, }); - return expect(user.balance).to.eql(0.75); + expect(user.balance).to.eql(0.75); }); }); - describe('spells', function() { - return _.each(shared.content.spells, function(spellClass) { - return _.each(spellClass, function(spell) { - return it(spell.text + " has valid values", function() { + describe('spells', () => { + _.each(shared.content.spells, (spellClass) => { + _.each(spellClass, (spell) => { + it(`${spell.text} has valid values`, () => { expect(spell.target).to.match(/^(task|self|party|user)$/); expect(spell.mana).to.be.an('number'); if (spell.lvl) { expect(spell.lvl).to.be.an('number'); expect(spell.lvl).to.be.above(0); } - return expect(spell.cast).to.be.a('function'); + expect(spell.cast).to.be.a('function'); }); }); }); }); - describe('drop system', function() { - var MAX_RANGE_FOR_EGG, MAX_RANGE_FOR_FOOD, MAX_RANGE_FOR_POTION, MIN_RANGE_FOR_EGG, MIN_RANGE_FOR_FOOD, MIN_RANGE_FOR_POTION, user; - user = null; - MIN_RANGE_FOR_POTION = 0; - MAX_RANGE_FOR_POTION = .3; - MIN_RANGE_FOR_EGG = .4; - MAX_RANGE_FOR_EGG = .6; - MIN_RANGE_FOR_FOOD = .7; - MAX_RANGE_FOR_FOOD = 1; - beforeEach(function() { + describe('drop system', () => { + let user = null; + const MIN_RANGE_FOR_POTION = 0; + const MAX_RANGE_FOR_POTION = 0.3; + const MIN_RANGE_FOR_EGG = 0.4; + const MAX_RANGE_FOR_EGG = 0.6; + const MIN_RANGE_FOR_FOOD = 0.7; + const MAX_RANGE_FOR_FOOD = 1; + + beforeEach(function () { user = newUser(); user.flags.dropsEnabled = true; this.task_id = shared.uuid(); return user.ops.addTask({ body: { type: 'daily', - id: this.task_id - } + id: this.task_id, + }, }); }); - it('drops a hatching potion', function() { - var j, random, ref, ref1, results; - results = []; - for (random = j = ref = MIN_RANGE_FOR_POTION, ref1 = MAX_RANGE_FOR_POTION; j <= ref1; random = j += .1) { + + it('drops a hatching potion', function () { + let results = []; + + for (let random = MIN_RANGE_FOR_POTION; random <= MAX_RANGE_FOR_POTION; random += 0.1) { sinon.stub(user.fns, 'predictableRandom').returns(random); user.ops.score({ params: { id: this.task_id, - direction: 'up' - } + direction: 'up', + }, }); expect(user.items.eggs).to.be.empty; expect(user.items.hatchingPotions).to.not.be.empty; @@ -745,16 +726,16 @@ describe('User', function() { } return results; }); - it('drops a pet egg', function() { - var j, random, ref, ref1, results; - results = []; - for (random = j = ref = MIN_RANGE_FOR_EGG, ref1 = MAX_RANGE_FOR_EGG; j <= ref1; random = j += .1) { + it('drops a pet egg', function () { + let results = []; + + for (let random = MIN_RANGE_FOR_EGG; random <= MAX_RANGE_FOR_EGG; random += 0.1) { sinon.stub(user.fns, 'predictableRandom').returns(random); user.ops.score({ params: { id: this.task_id, - direction: 'up' - } + direction: 'up', + }, }); expect(user.items.eggs).to.not.be.empty; expect(user.items.hatchingPotions).to.be.empty; @@ -763,16 +744,17 @@ describe('User', function() { } return results; }); - it('drops food', function() { - var j, random, ref, ref1, results; - results = []; - for (random = j = ref = MIN_RANGE_FOR_FOOD, ref1 = MAX_RANGE_FOR_FOOD; j <= ref1; random = j += .1) { + + it('drops food', function () { + let results = []; + + for (let random = MIN_RANGE_FOR_FOOD; random <= MAX_RANGE_FOR_FOOD; random += 0.1) { sinon.stub(user.fns, 'predictableRandom').returns(random); user.ops.score({ params: { id: this.task_id, - direction: 'up' - } + direction: 'up', + }, }); expect(user.items.eggs).to.be.empty; expect(user.items.hatchingPotions).to.be.empty; @@ -781,23 +763,25 @@ describe('User', function() { } return results; }); - return it('does not get a drop', function() { + + it('does not get a drop', function () { sinon.stub(user.fns, 'predictableRandom').returns(0.5); user.ops.score({ params: { id: this.task_id, - direction: 'up' - } + direction: 'up', + }, }); expect(user.items.eggs).to.eql({}); expect(user.items.hatchingPotions).to.eql({}); expect(user.items.food).to.eql({}); - return user.fns.predictableRandom.restore(); + + user.fns.predictableRandom.restore(); }); }); - describe('Quests', function() { - return _.each(shared.content.quests, function(quest) { - return it((quest.text()) + " has valid values", function() { + describe('Quests', () => { + _.each(shared.content.quests, (quest) => { + it(`${ quest.text() } has valid values`, () => { expect(quest.notes()).to.be.an('string'); if (quest.completion) { expect(quest.completion()).to.be.an('string'); @@ -817,214 +801,225 @@ describe('User', function() { if (quest.boss) { expect(quest.boss.name()).to.be.an('string'); expect(quest.boss.hp).to.be.greaterThan(0); - return expect(quest.boss.str).to.be.greaterThan(0); + expect(quest.boss.str).to.be.greaterThan(0); } else if (quest.collect) { - return _.each(quest.collect, function(collect) { + _.each(quest.collect, (collect) => { expect(collect.text()).to.be.an('string'); - return expect(collect.count).to.be.greaterThan(0); + expect(collect.count).to.be.greaterThan(0); }); } }); }); }); - describe('Achievements', function() { - _.each(shared.content.classes, function(klass) { - var user; - user = newUser(); + describe('Achievements', () => { + _.each(shared.content.classes, (klass) => { + let user = newUser(); + user.stats.gp = 10000; - _.each(shared.content.gearTypes, function(type) { - return _.each([1, 2, 3, 4, 5], function(i) { + _.each(shared.content.gearTypes, (type) => { + _.each([1, 2, 3, 4, 5], (i) => { return user.ops.buy({ - params: '#{type}_#{klass}_#{i}' + params: `${type}_${klass}_${i}`, }); }); }); - it('does not get ultimateGear ' + klass, function() { - return expect(user.achievements.ultimateGearSets[klass]).to.not.be.ok(); + + it(`does not get ultimateGear ${klass}`, () => { + expect(user.achievements.ultimateGearSets[klass]).to.not.be.ok(); }); - _.each(shared.content.gearTypes, function(type) { + _.each(shared.content.gearTypes, (type) => { return user.ops.buy({ - params: '#{type}_#{klass}_6' + params: `${type}_${klass}_6`, }); }); - return xit('gets ultimateGear ' + klass, function() { - return expect(user.achievements.ultimateGearSets[klass]).to.be.ok(); + + xit(`gets ultimateGear ${klass}`, () => { + expect(user.achievements.ultimateGearSets[klass]).to.be.ok(); }); }); - return it('does not remove existing Ultimate Gear achievements', function() { - var user; - user = newUser(); + it('does not remove existing Ultimate Gear achievements', () => { + let user = newUser(); + user.achievements.ultimateGearSets = { - 'healer': true, - 'wizard': true, - 'rogue': true, - 'warrior': true + healer: true, + wizard: true, + rogue: true, + warrior: true, }; user.items.gear.owned.shield_warrior_5 = false; user.items.gear.owned.weapon_rogue_6 = false; user.ops.buy({ - params: 'shield_warrior_5' + params: 'shield_warrior_5', }); - return expect(user.achievements.ultimateGearSets).to.eql({ - 'healer': true, - 'wizard': true, - 'rogue': true, - 'warrior': true + expect(user.achievements.ultimateGearSets).to.eql({ + healer: true, + wizard: true, + rogue: true, + warrior: true, }); }); }); - return describe('unlocking features', function() { - it('unlocks drops at level 3', function() { - var user; - user = newUser(); + describe('unlocking features', () => { + it('unlocks drops at level 3', () => { + let user = newUser(); + user.stats.lvl = 3; user.fns.updateStats(user.stats); - return expect(user.flags.dropsEnabled).to.be.ok(); + expect(user.flags.dropsEnabled).to.be.ok(); }); - it('unlocks Rebirth at level 50', function() { - var user; - user = newUser(); + it('unlocks Rebirth at level 50', () => { + let user = newUser(); + user.stats.lvl = 50; user.fns.updateStats(user.stats); - return expect(user.flags.rebirthEnabled).to.be.ok(); + expect(user.flags.rebirthEnabled).to.be.ok(); }); - return describe('level-awarded Quests', function() { - it('gets Attack of the Mundane at level 15', function() { - var user; - user = newUser(); + describe('level-awarded Quests', () => { + it('gets Attack of the Mundane at level 15', () => { + let user = newUser(); + user.stats.lvl = 15; user.fns.updateStats(user.stats); expect(user.flags.levelDrops.atom1).to.be.ok(); - return expect(user.items.quests.atom1).to.eql(1); + expect(user.items.quests.atom1).to.eql(1); }); - it('gets Vice at level 30', function() { - var user; - user = newUser(); + + it('gets Vice at level 30', () => { + let user = newUser(); + user.stats.lvl = 30; user.fns.updateStats(user.stats); expect(user.flags.levelDrops.vice1).to.be.ok(); - return expect(user.items.quests.vice1).to.eql(1); + expect(user.items.quests.vice1).to.eql(1); }); - it('gets Golden Knight at level 40', function() { - var user; - user = newUser(); + + it('gets Golden Knight at level 40', () => { + let user = newUser(); + user.stats.lvl = 40; user.fns.updateStats(user.stats); expect(user.flags.levelDrops.goldenknight1).to.be.ok(); - return expect(user.items.quests.goldenknight1).to.eql(1); + expect(user.items.quests.goldenknight1).to.eql(1); }); - return it('gets Moonstone Chain at level 60', function() { - var user; - user = newUser(); + + it('gets Moonstone Chain at level 60', () => { + let user = newUser(); + user.stats.lvl = 60; user.fns.updateStats(user.stats); expect(user.flags.levelDrops.moonstone1).to.be.ok(); - return expect(user.items.quests.moonstone1).to.eql(1); + expect(user.items.quests.moonstone1).to.eql(1); }); }); }); }); -describe('Simple Scoring', function() { - beforeEach(function() { - var ref; - return ref = beforeAfter(), this.before = ref.before, this.after = ref.after, ref; +describe('Simple Scoring', () => { + beforeEach(function () { + let ref = beforeAfter(); + + this.before = ref.before; + this.after = ref.after; }); - it('Habits : Up', function() { + + it('Habits : Up', function () { this.after.ops.score({ params: { id: this.after.habits[0].id, - direction: 'down' + direction: 'down', }, query: { - times: 5 - } + times: 5, + }, }); - return expectLostPoints(this.before, this.after, 'habit'); + expectLostPoints(this.before, this.after, 'habit'); }); - it('Habits : Down', function() { + it('Habits : Down', function () { this.after.ops.score({ params: { id: this.after.habits[0].id, - direction: 'up' + direction: 'up', }, query: { - times: 5 - } + times: 5, + }, }); - return expectGainedPoints(this.before, this.after, 'habit'); + expectGainedPoints(this.before, this.after, 'habit'); }); - it('Dailys : Up', function() { + it('Dailys : Up', function () { this.after.ops.score({ params: { id: this.after.dailys[0].id, - direction: 'up' - } + direction: 'up', + }, }); - return expectGainedPoints(this.before, this.after, 'daily'); + expectGainedPoints(this.before, this.after, 'daily'); }); - it('Dailys : Up, Down', function() { + it('Dailys : Up, Down', function () { this.after.ops.score({ params: { id: this.after.dailys[0].id, - direction: 'up' - } + direction: 'up', + }, }); this.after.ops.score({ params: { id: this.after.dailys[0].id, - direction: 'down' - } + direction: 'down', + }, }); - return expectClosePoints(this.before, this.after, 'daily'); + expectClosePoints(this.before, this.after, 'daily'); }); - it('Todos : Up', function() { + it('Todos : Up', function () { this.after.ops.score({ params: { id: this.after.todos[0].id, - direction: 'up' - } + direction: 'up', + }, }); - return expectGainedPoints(this.before, this.after, 'todo'); + expectGainedPoints(this.before, this.after, 'todo'); }); - return it('Todos : Up, Down', function() { + + it('Todos : Up, Down', function () { this.after.ops.score({ params: { id: this.after.todos[0].id, - direction: 'up' - } + direction: 'up', + }, }); this.after.ops.score({ params: { id: this.after.todos[0].id, - direction: 'down' - } + direction: 'down', + }, }); - return expectClosePoints(this.before, this.after, 'todo'); + expectClosePoints(this.before, this.after, 'todo'); }); }); -describe('Cron', function() { - it('computes shouldCron', function() { - var paths, user; - user = newUser(); - paths = {}; +describe('Cron', () => { + it('computes shouldCron', () => { + let user = newUser(); + let paths = {}; + user.fns.cron({ - paths: paths + paths, }); expect(user.lastCron).to.not.be.ok; - user.lastCron = +moment().subtract(1, 'days'); + user.lastCron = Number(moment().subtract(1, 'days')); paths = {}; user.fns.cron({ - paths: paths + paths, }); - return expect(user.lastCron).to.be.greaterThan(0); + expect(user.lastCron).to.be.greaterThan(0); }); - it('only dailies & todos are affected', function() { - var after, afterTasks, before, beforeTasks, ref; - ref = beforeAfter({ - daysAgo: 1 - }), before = ref.before, after = ref.after; + it('only dailies & todos are affected', () => { + let ref = beforeAfter({ + daysAgo: 1, + }); + let before = ref.before; + let after = ref.after; + before.dailys = before.todos = after.dailys = after.todos = []; after.fns.cron(); before.stats.mp = after.stats.mp; @@ -1032,130 +1027,137 @@ describe('Cron', function() { delete after.stats.buffs; delete before.stats.buffs; expect(before.stats).to.eql(after.stats); - beforeTasks = before.habits.concat(before.dailys).concat(before.todos).concat(before.rewards); - afterTasks = after.habits.concat(after.dailys).concat(after.todos).concat(after.rewards); - return expect(beforeTasks).to.eql(afterTasks); + + let beforeTasks = before.habits.concat(before.dailys).concat(before.todos).concat(before.rewards); + let afterTasks = after.habits.concat(after.dailys).concat(after.todos).concat(after.rewards); + + expect(beforeTasks).to.eql(afterTasks); }); - describe('preening', function() { - beforeEach(function() { - return this.clock = sinon.useFakeTimers(Date.parse("2013-11-20"), "Date"); + describe('preening', () => { + beforeEach(function () { + this.clock = sinon.useFakeTimers(Date.parse('2013-11-20'), 'Date'); }); - afterEach(function() { + afterEach(function () { return this.clock.restore(); }); - return it('should preen user history', function() { - var after, before, history, ref; - ref = beforeAfter({ - daysAgo: 1 - }), before = ref.before, after = ref.after; - history = [ + + it('should preen user history', function () { + let ref = beforeAfter({ + daysAgo: 1, + }); + let after = ref.after; + + let history = [ { date: '09/01/2012', - value: 0 + value: 0, }, { date: '10/01/2012', - value: 0 + value: 0, }, { date: '11/01/2012', - value: 2 + value: 2, }, { date: '12/01/2012', - value: 2 + value: 2, }, { date: '01/01/2013', - value: 1 + value: 1, }, { date: '01/15/2013', - value: 3 + value: 3, }, { date: '02/01/2013', - value: 2 + value: 2, }, { date: '02/15/2013', - value: 4 + value: 4, }, { date: '03/01/2013', - value: 3 + value: 3, }, { date: '03/15/2013', - value: 5 + value: 5, }, { date: '04/01/2013', - value: 4 + value: 4, }, { date: '04/15/2013', - value: 6 + value: 6, }, { date: '05/01/2013', - value: 5 + value: 5, }, { date: '05/15/2013', - value: 7 + value: 7, }, { date: '06/01/2013', - value: 6 + value: 6, }, { date: '06/15/2013', - value: 8 + value: 8, }, { date: '07/01/2013', - value: 7 + value: 7, }, { date: '07/15/2013', - value: 9 + value: 9, }, { date: '08/01/2013', - value: 8 + value: 8, }, { date: '08/15/2013', - value: 10 + value: 10, }, { date: '09/01/2013', - value: 9 + value: 9, }, { date: '09/15/2013', - value: 11 + value: 11, }, { date: '010/01/2013', - value: 10 + value: 10, }, { date: '010/15/2013', - value: 12 + value: 12, }, { date: '011/01/2013', - value: 12 + value: 12, }, { date: '011/02/2013', - value: 13 + value: 13, }, { date: '011/03/2013', - value: 14 + value: 14, }, { date: '011/04/2013', - value: 15 - } + value: 15, + }, ]; + after.history = { exp: _.cloneDeep(history), - todos: _.cloneDeep(history) + todos: _.cloneDeep(history), }; after.habits[0].history = _.cloneDeep(history); after.fns.cron(); after.history.exp.pop(); after.history.todos.pop(); - return _.each([after.history.exp, after.history.todos, after.habits[0].history], function(arr) { - return expect(_.map(arr, function(x) { + _.each([after.history.exp, after.history.todos, after.habits[0].history], function (arr) { + expect(_.map(arr, (x) => { return x.value; })).to.eql([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]); }); }); }); - describe('Todos', function() { - it('1 day missed', function() { - var after, before, ref; - ref = beforeAfter({ - daysAgo: 1 - }), before = ref.before, after = ref.after; + describe('Todos', () => { + it('1 day missed', () => { + let ref = beforeAfter({ + daysAgo: 1, + }); + let before = ref.before; + let after = ref.after; + before.dailys = after.dailys = []; after.fns.cron(); expect(after).toHaveHP(50); @@ -1163,117 +1165,123 @@ describe('Cron', function() { expect(after).toHaveGP(0); expect(before.todos[0].value).to.be(0); expect(after.todos[0].value).to.be(-1); - return expect(after.history.todos).to.have.length(1); + expect(after.history.todos).to.have.length(1); }); - return it('2 days missed', function() { - var after, before, ref; - ref = beforeAfter({ - daysAgo: 2 - }), before = ref.before, after = ref.after; + it('2 days missed', () => { + let ref = beforeAfter({ + daysAgo: 2, + }); + let before = ref.before; + let after = ref.after; + before.dailys = after.dailys = []; after.fns.cron(); expect(before.todos[0].value).to.be(0); - return expect(after.todos[0].value).to.be(-1); + expect(after.todos[0].value).to.be(-1); }); }); - describe('cron day calculations', function() { - var dayStart, fstr; - dayStart = 4; - fstr = "YYYY-MM-DD HH:mm:ss"; - it('startOfDay before dayStart', function() { - var start; - start = shared.startOfDay({ - now: moment('2014-10-09 02:30:00'), - dayStart: dayStart - }); - return expect(start.format(fstr)).to.eql('2014-10-08 04:00:00'); - }); - it('startOfDay after dayStart', function() { - var start; - start = shared.startOfDay({ - now: moment('2014-10-09 05:30:00'), - dayStart: dayStart - }); - return expect(start.format(fstr)).to.eql('2014-10-09 04:00:00'); - }); - it('daysSince cron before, now after', function() { - var days, lastCron; - lastCron = moment('2014-10-09 02:30:00'); - days = shared.daysSince(lastCron, { - now: moment('2014-10-09 11:30:00'), - dayStart: dayStart - }); - return expect(days).to.eql(1); - }); - it('daysSince cron before, now before', function() { - var days, lastCron; - lastCron = moment('2014-10-09 02:30:00'); - days = shared.daysSince(lastCron, { - now: moment('2014-10-09 03:30:00'), - dayStart: dayStart - }); - return expect(days).to.eql(0); - }); - it('daysSince cron after, now after', function() { - var days, lastCron; - lastCron = moment('2014-10-09 05:30:00'); - days = shared.daysSince(lastCron, { - now: moment('2014-10-09 06:30:00'), - dayStart: dayStart - }); - return expect(days).to.eql(0); - }); - it('daysSince cron after, now tomorrow before', function() { - var days, lastCron; - lastCron = moment('2014-10-09 12:30:00'); - days = shared.daysSince(lastCron, { - now: moment('2014-10-10 01:30:00'), - dayStart: dayStart - }); - return expect(days).to.eql(0); - }); - it('daysSince cron after, now tomorrow after', function() { - var days, lastCron; - lastCron = moment('2014-10-09 12:30:00'); - days = shared.daysSince(lastCron, { - now: moment('2014-10-10 10:30:00'), - dayStart: dayStart - }); - return expect(days).to.eql(1); - }); - return xit('daysSince, last cron before new dayStart', function() { - var days, lastCron; - lastCron = moment('2014-10-09 01:00:00'); - days = shared.daysSince(lastCron, { - now: moment('2014-10-09 05:00:00'), - dayStart: dayStart - }); - return expect(days).to.eql(0); - }); - }); - return describe('dailies', function() { - return describe('new day', function() { + describe('cron day calculations', () => { + let dayStart = 4; + let fstr = 'YYYY-MM-DD HH: mm: ss'; + it('startOfDay before dayStart', () => { + let start = shared.startOfDay({ + now: moment('2014-10-09 02: 30: 00'), + dayStart, + }); + + expect(start.format(fstr)).to.eql('2014-10-08 04: 00: 00'); + }); + it('startOfDay after dayStart', () => { + let start = shared.startOfDay({ + now: moment('2014-10-09 05: 30: 00'), + dayStart, + }); + + expect(start.format(fstr)).to.eql('2014-10-09 04: 00: 00'); + }); + it('daysSince cron before, now after', () => { + let lastCron = moment('2014-10-09 02: 30: 00'); + let days = shared.daysSince(lastCron, { + now: moment('2014-10-09 11: 30: 00'), + dayStart, + }); + + expect(days).to.eql(1); + }); + it('daysSince cron before, now before', () => { + let lastCron = moment('2014-10-09 02: 30: 00'); + let days = shared.daysSince(lastCron, { + now: moment('2014-10-09 03: 30: 00'), + dayStart, + }); + + expect(days).to.eql(0); + }); + it('daysSince cron after, now after', () => { + let lastCron = moment('2014-10-09 05: 30: 00'); + let days = shared.daysSince(lastCron, { + now: moment('2014-10-09 06: 30: 00'), + dayStart, + }); + + expect(days).to.eql(0); + }); + it('daysSince cron after, now tomorrow before', () => { + let lastCron = moment('2014-10-09 12: 30: 00'); + let days = shared.daysSince(lastCron, { + now: moment('2014-10-10 01: 30: 00'), + dayStart, + }); + + expect(days).to.eql(0); + }); + it('daysSince cron after, now tomorrow after', () => { + let lastCron = moment('2014-10-09 12: 30: 00'); + let days = shared.daysSince(lastCron, { + now: moment('2014-10-10 10: 30: 00'), + dayStart, + }); + + expect(days).to.eql(1); + }); + xit('daysSince, last cron before new dayStart', () => { + let lastCron = moment('2014-10-09 01: 00: 00'); + let days = shared.daysSince(lastCron, { + now: moment('2014-10-09 05: 00: 00'), + dayStart, + }); + + expect(days).to.eql(0); + }); + }); + + describe('dailies', () => { + describe('new day', () => { /* - This section runs through a "cron matrix" of all permutations (that I can easily account for). It sets + This section runs through a 'cron matrix' of all permutations (that I can easily account for). It sets task due days, user custom day start, timezoneOffset, etc - then runs cron, jumps to tomorrow and runs cron, and so on - testing each possible outcome along the way */ - var cronMatrix, recurseCronMatrix, runCron; - runCron = function(options) { - return _.each([480, 240, 0, -120], function(timezoneOffset) { - var after, before, now, ref; - now = shared.startOfWeek({ - timezoneOffset: timezoneOffset + + function runCron (options) { + _.each([480, 240, 0, -120], function (timezoneOffset) { + let now = shared.startOfWeek({ + timezoneOffset, }).add(options.currentHour || 0, 'hours'); - ref = beforeAfter({ - now: now, - timezoneOffset: timezoneOffset, + + let ref = beforeAfter({ + now, + timezoneOffset, daysAgo: 1, cronAfterStart: options.cronAfterStart || true, dayStart: options.dayStart || 0, - limitOne: 'daily' - }), before = ref.before, after = ref.after; + limitOne: 'daily', + }); + + let before = ref.before; + let after = ref.after; + if (options.repeat) { before.dailys[0].repeat = after.dailys[0].repeat = options.repeat; } @@ -1284,42 +1292,42 @@ describe('Cron', function() { before.dailys[0].startDate = after.dailys[0].startDate = moment().subtract(30, 'days'); if (options.shouldDo) { expect(shared.shouldDo(now.toDate(), after.dailys[0], { - timezoneOffset: timezoneOffset, + timezoneOffset, dayStart: options.dayStart, - now: now + now, })).to.be.ok(); } after.fns.cron({ - now: now + now, }); before.stats.mp = after.stats.mp; - switch (options.expect) { - case 'losePoints': - expectLostPoints(before, after, 'daily'); - break; - case 'noChange': - expectNoChange(before, after); - break; - case 'noDamage': - expectDayResetNoDamage(before, after); + + if (options.expect === 'losePoints') { + expectLostPoints(before, after, 'daily'); + } else if (options.expect === 'noChange') { + expectNoChange(before, after); + } else if (options.expect === 'noDamage') { + expectDayResetNoDamage(before, after); } + return { - before: before, - after: after + before, + after, }; }); - }; - cronMatrix = { + } + + let cronMatrix = { steps: { 'due yesterday': { defaults: { daysAgo: 1, cronAfterStart: true, - limitOne: 'daily' + limitOne: 'daily', }, steps: { '(simple)': { - expect: 'losePoints' + expect: 'losePoints', }, 'due today': { defaults: { @@ -1330,45 +1338,45 @@ describe('Cron', function() { w: true, th: true, f: true, - s: true - } + s: true, + }, }, steps: { 'pre-dayStart': { defaults: { currentHour: 3, dayStart: 4, - shouldDo: true + shouldDo: true, }, steps: { - 'checked': { + checked: { checked: true, - expect: 'noChange' + expect: 'noChange', }, 'un-checked': { checked: false, - expect: 'noChange' - } - } + expect: 'noChange', + }, + }, }, 'post-dayStart': { defaults: { currentHour: 5, dayStart: 4, - shouldDo: true + shouldDo: true, }, steps: { - 'checked': { + checked: { checked: true, - expect: 'noDamage' + expect: 'noDamage', }, - 'unchecked': { + unchecked: { checked: false, - expect: 'losePoints' - } - } - } - } + expect: 'losePoints', + }, + }, + }, + }, }, 'NOT due today': { defaults: { @@ -1379,129 +1387,128 @@ describe('Cron', function() { w: true, th: true, f: true, - s: true - } + s: true, + }, }, steps: { 'pre-dayStart': { defaults: { currentHour: 3, dayStart: 4, - shouldDo: true + shouldDo: true, }, steps: { - 'checked': { + checked: { checked: true, - expect: 'noChange' + expect: 'noChange', }, 'un-checked': { checked: false, - expect: 'noChange' - } - } + expect: 'noChange', + }, + }, }, 'post-dayStart': { defaults: { currentHour: 5, dayStart: 4, - shouldDo: false + shouldDo: false, }, steps: { - 'checked': { + checked: { checked: true, - expect: 'noDamage' + expect: 'noDamage', }, - 'unchecked': { + unchecked: { checked: false, - expect: 'losePoints' - } - } - } - } - } - } + expect: 'losePoints', + }, + }, + }, + }, + }, + }, }, 'not due yesterday': { defaults: repeatWithoutLastWeekday(), steps: { '(simple)': { - expect: 'noDamage' + expect: 'noDamage', }, 'post-dayStart': { currentHour: 5, dayStart: 4, - expect: 'noDamage' + expect: 'noDamage', }, 'pre-dayStart': { currentHour: 3, dayStart: 4, - expect: 'noChange' - } - } - } - } + expect: 'noChange', + }, + }, + }, + }, }; - recurseCronMatrix = function(obj, options) { - if (options == null) { - options = {}; - } + + let recurseCronMatrix = (obj, options = {}) => { if (obj.steps) { - return _.each(obj.steps, function(step, text) { - var o; - o = _.cloneDeep(options); - if (o.text == null) { + _.each(obj.steps, (step, text) => { + let o = _.cloneDeep(options); + + if (!o.text) { o.text = ''; } - o.text += " " + text + " "; + o.text += `${text}`; return recurseCronMatrix(step, _.defaults(o, obj.defaults)); }); } else { - return it("" + options.text, function() { + it(`${options.text}`, () => { return runCron(_.defaults(obj, options)); }); } }; + return recurseCronMatrix(cronMatrix); }); }); }); -describe('Helper', function() { - it('calculates gold coins', function() { +describe('Helper', () => { + it('calculates gold coins', () => { expect(shared.gold(10)).to.eql(10); expect(shared.gold(1.957)).to.eql(1); - return expect(shared.gold()).to.eql(0); + expect(shared.gold()).to.eql(0); }); - it('calculates silver coins', function() { + it('calculates silver coins', () => { expect(shared.silver(10)).to.eql(0); expect(shared.silver(1.957)).to.eql(95); - expect(shared.silver(0.01)).to.eql("01"); - return expect(shared.silver()).to.eql("00"); + expect(shared.silver(0.01)).to.eql('01'); + expect(shared.silver()).to.eql('00'); }); - it('calculates experience to next level', function() { + it('calculates experience to next level', () => { expect(shared.tnl(1)).to.eql(150); expect(shared.tnl(2)).to.eql(160); expect(shared.tnl(10)).to.eql(260); - return expect(shared.tnl(99)).to.eql(3580); + expect(shared.tnl(99)).to.eql(3580); }); - return it('calculates the start of the day', function() { - var fstr, today, zone; - fstr = 'YYYY-MM-DD HH:mm:ss'; - today = '2013-01-01 00:00:00'; - zone = moment(today).zone(); + it('calculates the start of the day', () => { + let fstr = 'YYYY-MM-DD HH: mm: ss'; + let today = '2013-01-01 00: 00: 00'; + let zone = moment(today).zone(); + expect(shared.startOfDay({ - now: new Date(2013, 0, 1, 0) + now: new Date(2013, 0, 1, 0), }, { - timezoneOffset: zone + timezoneOffset: zone, }).format(fstr)).to.eql(today); expect(shared.startOfDay({ - now: new Date(2013, 0, 1, 5) + now: new Date(2013, 0, 1, 5), }, { - timezoneOffset: zone + timezoneOffset: zone, }).format(fstr)).to.eql(today); - return expect(shared.startOfDay({ + expect(shared.startOfDay({ now: new Date(2013, 0, 1, 23, 59, 59), - timezoneOffset: zone + timezoneOffset: zone, }).format(fstr)).to.eql(today); }); }); diff --git a/test/common/count.js b/test/common/count.js index 86d746d3ff..a19d648267 100644 --- a/test/common/count.js +++ b/test/common/count.js @@ -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); diff --git a/test/common/dailies.js b/test/common/dailies.js index 92d80ee5ad..d9c1621904 100644 --- a/test/common/dailies.js +++ b/test/common/dailies.js @@ -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); }); }); }); diff --git a/test/common/test_helper.js b/test/common/test_helper.js index 3c482b44d3..7b9ba2beff 100644 --- a/test/common/test_helper.js +++ b/test/common/test_helper.js @@ -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'; }); }; }; diff --git a/test/common/user.fns.buy.test.js b/test/common/user.fns.buy.test.js index f756ce0c83..e04c395533 100644 --- a/test/common/user.fns.buy.test.js +++ b/test/common/user.fns.buy.test.js @@ -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); }); }); diff --git a/test/common/user.fns.ultimateGear.test.js b/test/common/user.fns.ultimateGear.test.js index 9dc80eaea5..a95cb403d9 100644 --- a/test/common/user.fns.ultimateGear.test.js +++ b/test/common/user.fns.ultimateGear.test.js @@ -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 { - armor_warrior_5: true, - shield_warrior_5: true, - head_warrior_5: true, - weapon_warrior_6: true - }} - }}}, - achievements: { - ultimateGearSets: {} +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, + }; + }, + }, }, - flags: {} + }; + + let user = shared.wrap({ + items, + achievements: { + ultimateGearSets: {}, + }, + flags: {}, }); + user.fns.ultimateGear(); expect(user.flags.armoireEnabled).to.equal(true); }); diff --git a/test/common/user.ops.buyMysterySet.test.js b/test/common/user.ops.buyMysterySet.test.js index 1f88b45802..8c7899cf50 100644 --- a/test/common/user.ops.buyMysterySet.test.js +++ b/test/common/user.ops.buyMysterySet.test.js @@ -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(); }); }); diff --git a/test/common/user.ops.hatch.js b/test/common/user.ops.hatch.js index b5cf174ff9..573103a360 100644 --- a/test/common/user.ops.hatch.js +++ b/test/common/user.ops.hatch.js @@ -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(); }); }); diff --git a/test/common/user.ops.hourglassPurchase.test.js b/test/common/user.ops.hourglassPurchase.test.js index 76e3f98c9c..b9c7369d21 100644 --- a/test/common/user.ops.hourglassPurchase.test.js +++ b/test/common/user.ops.hourglassPurchase.test.js @@ -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(); }); }); diff --git a/test/common/user.ops.test.js b/test/common/user.ops.test.js index aee5b795f7..f4e4bb82c9 100644 --- a/test/common/user.ops.test.js +++ b/test/common/user.ops.test.js @@ -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' } }); From a6fb5790e5924b9192d7e195f42a79df979df789 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Fri, 20 Nov 2015 07:56:59 -0600 Subject: [PATCH 6/6] refactor(gulp): Dry out linting task --- tasks/gulp-eslint.js | 110 ++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/tasks/gulp-eslint.js b/tasks/gulp-eslint.js index 6875f27d4c..83930556c7 100644 --- a/tasks/gulp-eslint.js +++ b/tasks/gulp-eslint.js @@ -1,77 +1,79 @@ import gulp from 'gulp'; import eslint from 'gulp-eslint'; +const SERVER_FILES = [ + './website/src/**/api-v3/**/*.js', + // Comment these out in develop, uncomment them in api-v3 + // './website/src/models/user.js', + // './website/src/server.js' +]; +const COMMON_FILES = [ + './common/script/**/*.js', + // @TODO remove these negations as the files are converted over. + '!./common/script/index.js', + '!./common/script/content/index.js', + '!./common/script/src/**/*.js', + '!./common/script/public/**/*.js', +]; +const TEST_FILES = [ + './test/**/*.js', + // @TODO remove these negations as the test files are cleaned up. + '!./test/api-legacy/**/*', + '!./test/api/**/*', + '!./test/common/simulations/**/*', + '!./test/content/**/*', + '!./test/e2e/**/*', + '!./test/server_side/**/*', + '!./test/spec/**/*', +]; + +let linter = (src, options) => { + return gulp + .src(src) + .pipe(eslint(options)) + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); +} + // TODO lint client // TDOO separate linting cong between // TODO lint gulp tasks, tests, ...? // TODO what about prefer-const rule? // TODO remove estraverse dependency once https://github.com/adametry/gulp-eslint/issues/117 sorted out gulp.task('lint:server', () => { - return gulp - .src([ - './website/src/**/api-v3/**/*.js', - // Comment these out in develop, uncomment them in api-v3 - // './website/src/models/user.js', - // './website/src/server.js' - ]) - .pipe(eslint()) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()); + return linter(SERVER_FILES); }); gulp.task('lint:common', () => { - return gulp - .src([ - './common/script/**/*.js', - // @TODO remove these negations as the files are converted over. - '!./common/script/index.js', - '!./common/script/content/index.js', - '!./common/script/src/**/*.js', - '!./common/script/public/**/*.js', - ]) - .pipe(eslint()) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()); + return linter(COMMON_FILES); }); gulp.task('lint:tests', () => { - return gulp - .src([ - './test/**/*.js', - // @TODO remove these negations as the test files are cleaned up. - '!./test/api-legacy/**/*', - '!./test/api/**/*', - '!./test/common/simulations/**/*', - '!./test/content/**/*', - '!./test/e2e/**/*', - '!./test/server_side/**/*', - '!./test/spec/**/*', - ]) - .pipe(eslint({ - rules: { - 'max-nested-callbacks': 0, - 'no-unused-expressions': 0, - 'mocha/no-exclusive-tests': 2, - 'mocha/no-global-tests': 2, - 'mocha/handle-done-callback': 2, - }, - globals: { - 'expect': true, - '_': true, - 'sinon': true, - }, - plugins: [ 'mocha' ], - })) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()); + let options = { + rules: { + 'max-nested-callbacks': 0, + 'no-unused-expressions': 0, + 'mocha/no-exclusive-tests': 2, + 'mocha/no-global-tests': 2, + 'mocha/handle-done-callback': 2, + }, + globals: { + 'expect': true, + '_': true, + 'sinon': true, + }, + plugins: [ 'mocha' ], + }; + + return linter(TEST_FILES, options); }); gulp.task('lint', ['lint:server', 'lint:common', 'lint:tests']); gulp.task('lint:watch', () => { gulp.watch([ - './website/src/**/*.js', - './common/script/**/*.js', - './test/**/*.js', + SERVER_FILES, + COMMON_FILES, + TEST_FILES, ], ['lint']); });