From 95aff08de3bef7463e28bce98626aa6a4ff48590 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Wed, 11 May 2016 15:59:18 +0200 Subject: [PATCH] v3 fix tests and use coroutines instead of regenerator --- .babelrc | 7 +- .eslintignore | 1 - migrations/api_v3/challenges.js | 2 +- migrations/api_v3/challengesMembers.js | 2 +- migrations/api_v3/coupons.js | 2 +- migrations/api_v3/emailUnsubscriptions.js | 2 +- migrations/api_v3/groups.js | 2 +- migrations/api_v3/users.js | 2 +- package.json | 3 +- .../v3/integration/user/POST-user_buy.test.js | 13 +- .../user/POST-user_buy_gear.test.js | 13 +- test/common/ops/buy.js | 12 +- test/common/ops/buyArmoire.js | 22 +- test/common/ops/buyGear.js | 12 +- test/common_old/algos.mocha.js | 1265 ----------------- test/common_old/dailies.js | 499 ------- test/common_old/preenTodos.test.js | 76 - test/common_old/shared.spells.test.js | 103 -- test/common_old/simulations/autoAllocate.js | 161 --- .../simulations/passive_active_attrs.js | 291 ---- test/common_old/user.fns.updateStats.test.js | 134 -- .../user.ops.hourglassPurchase.test.js | 122 -- test/common_old/user.ops.test.js | 34 - website/src/controllers/api-v3/groups.js | 2 +- 24 files changed, 80 insertions(+), 2702 deletions(-) delete mode 100644 test/common_old/algos.mocha.js delete mode 100644 test/common_old/dailies.js delete mode 100644 test/common_old/preenTodos.test.js delete mode 100644 test/common_old/shared.spells.test.js delete mode 100644 test/common_old/simulations/autoAllocate.js delete mode 100644 test/common_old/simulations/passive_active_attrs.js delete mode 100644 test/common_old/user.fns.updateStats.test.js delete mode 100644 test/common_old/user.ops.hourglassPurchase.test.js delete mode 100644 test/common_old/user.ops.test.js diff --git a/.babelrc b/.babelrc index abdb3b030b..988e0d6f03 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,9 @@ { "presets": ["es2015"], - "plugins": ["syntax-async-functions","transform-regenerator"] + "plugins": [ + ["transform-async-to-module-method", { + "module": "bluebird", + "method": "coroutine" + }] + ] } diff --git a/.eslintignore b/.eslintignore index b4830a328f..6aab3499ed 100644 --- a/.eslintignore +++ b/.eslintignore @@ -30,7 +30,6 @@ newrelic.js test/api-legacy/**/* test/common/simulations/**/* -test/common_old/ test/content/**/* test/server_side/**/* test/spec/**/* diff --git a/migrations/api_v3/challenges.js b/migrations/api_v3/challenges.js index b2ba22f730..a1b9b7d4fa 100644 --- a/migrations/api_v3/challenges.js +++ b/migrations/api_v3/challenges.js @@ -30,7 +30,7 @@ var MONGODB_NEW = nconf.get('MONGODB_NEW'); var MongoClient = MongoDB.MongoClient; -mongoose.Promise = Bluebird.all; // otherwise mongoose models won't work +mongoose.Promise = Bluebird; // otherwise mongoose models won't work // Load new models var NewChallenge = require('../../website/src/models/challenge').model; diff --git a/migrations/api_v3/challengesMembers.js b/migrations/api_v3/challengesMembers.js index d42b4d1e69..7f7b2c99fd 100644 --- a/migrations/api_v3/challengesMembers.js +++ b/migrations/api_v3/challengesMembers.js @@ -30,7 +30,7 @@ var MONGODB_NEW = nconf.get('MONGODB_NEW'); var MongoClient = MongoDB.MongoClient; -mongoose.Promise = Bluebird.all; // otherwise mongoose models won't work +mongoose.Promise = Bluebird; // otherwise mongoose models won't work // To be defined later when MongoClient connects var mongoDbOldInstance; diff --git a/migrations/api_v3/coupons.js b/migrations/api_v3/coupons.js index 9500416c8a..ce7058e3f0 100644 --- a/migrations/api_v3/coupons.js +++ b/migrations/api_v3/coupons.js @@ -29,7 +29,7 @@ var MONGODB_NEW = nconf.get('MONGODB_NEW'); var MongoClient = MongoDB.MongoClient; -mongoose.Promise = Bluebird.all; // otherwise mongoose models won't work +mongoose.Promise = Bluebird; // otherwise mongoose models won't work // Load new models var Coupon = require('../../website/src/models/coupon').model; diff --git a/migrations/api_v3/emailUnsubscriptions.js b/migrations/api_v3/emailUnsubscriptions.js index 14c42623d6..099d23cd27 100644 --- a/migrations/api_v3/emailUnsubscriptions.js +++ b/migrations/api_v3/emailUnsubscriptions.js @@ -29,7 +29,7 @@ var MONGODB_NEW = nconf.get('MONGODB_NEW'); var MongoClient = MongoDB.MongoClient; -mongoose.Promise = Bluebird.all; // otherwise mongoose models won't work +mongoose.Promise = Bluebird; // otherwise mongoose models won't work // Load new models var EmailUnsubscription = require('../../website/src/models/emailUnsubscription').model; diff --git a/migrations/api_v3/groups.js b/migrations/api_v3/groups.js index 5a6365ebd6..9399024c53 100644 --- a/migrations/api_v3/groups.js +++ b/migrations/api_v3/groups.js @@ -37,7 +37,7 @@ var MONGODB_NEW = nconf.get('MONGODB_NEW'); var MongoClient = MongoDB.MongoClient; -mongoose.Promise = Bluebird.all; // otherwise mongoose models won't work +mongoose.Promise = Bluebird; // otherwise mongoose models won't work // Load new models var NewGroup = require('../../website/src/models/group').model; diff --git a/migrations/api_v3/users.js b/migrations/api_v3/users.js index c67b4b5a14..cea6e58d2d 100644 --- a/migrations/api_v3/users.js +++ b/migrations/api_v3/users.js @@ -33,7 +33,7 @@ var MONGODB_NEW = nconf.get('MONGODB_NEW'); var taskDefaults = common.taskDefaults; var MongoClient = MongoDB.MongoClient; -mongoose.Promise = Bluebird.all; // otherwise mongoose models won't work +mongoose.Promise = Bluebird; // otherwise mongoose models won't work // Load new models var NewUser = require('../../website/src/models/user').model; diff --git a/package.json b/package.json index 787504f828..3b13ca318f 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,7 @@ "apidoc": "^0.16.0", "async": "^1.5.0", "aws-sdk": "^2.0.25", - "babel-plugin-syntax-async-functions": "^6.5.0", - "babel-plugin-transform-regenerator": "^6.6.0", + "babel-plugin-transform-async-to-module-method": "^6.8.0", "babel-polyfill": "^6.6.1", "babel-preset-es2015": "^6.6.0", "babel-register": "^6.6.0", diff --git a/test/api/v3/integration/user/POST-user_buy.test.js b/test/api/v3/integration/user/POST-user_buy.test.js index 2478adf7f8..ffad12f2a0 100644 --- a/test/api/v3/integration/user/POST-user_buy.test.js +++ b/test/api/v3/integration/user/POST-user_buy.test.js @@ -1,3 +1,5 @@ +/* eslint-disable camelcase */ + import { generateUser, translate as t, @@ -46,6 +48,15 @@ describe('POST /user/buy/:key', () => { await user.post(`/user/buy/${key}`); await user.sync(); - expect(user.items.gear.owned).to.eql({ armor_warrior_1: true }); // eslint-disable-line camelcase + expect(user.items.gear.owned).to.eql({ + armor_warrior_1: true, + eyewear_special_blackTopFrame: true, + eyewear_special_blueTopFrame: true, + eyewear_special_greenTopFrame: true, + eyewear_special_pinkTopFrame: true, + eyewear_special_redTopFrame: true, + eyewear_special_whiteTopFrame: true, + eyewear_special_yellowTopFrame: true, + }); }); }); diff --git a/test/api/v3/integration/user/POST-user_buy_gear.test.js b/test/api/v3/integration/user/POST-user_buy_gear.test.js index 5347b94da9..f577263d4a 100644 --- a/test/api/v3/integration/user/POST-user_buy_gear.test.js +++ b/test/api/v3/integration/user/POST-user_buy_gear.test.js @@ -1,3 +1,5 @@ +/* eslint-disable camelcase */ + import { generateUser, translate as t, @@ -29,6 +31,15 @@ describe('POST /user/buy-gear/:key', () => { await user.post(`/user/buy-gear/${key}`); await user.sync(); - expect(user.items.gear.owned).to.eql({ armor_warrior_1: true }); // eslint-disable-line camelcase + expect(user.items.gear.owned).to.eql({ + armor_warrior_1: true, + eyewear_special_blackTopFrame: true, + eyewear_special_blueTopFrame: true, + eyewear_special_greenTopFrame: true, + eyewear_special_pinkTopFrame: true, + eyewear_special_redTopFrame: true, + eyewear_special_whiteTopFrame: true, + eyewear_special_yellowTopFrame: true, + }); }); }); diff --git a/test/common/ops/buy.js b/test/common/ops/buy.js index abaf3c849d..9e05cc5225 100644 --- a/test/common/ops/buy.js +++ b/test/common/ops/buy.js @@ -46,6 +46,16 @@ describe('shared.ops.buy', () => { it('adds equipment to inventory', () => { user.stats.gp = 31; buy(user, {params: {key: 'armor_warrior_1'}}); - expect(user.items.gear.owned).to.eql({ weapon_warrior_0: true, armor_warrior_1: true }); + expect(user.items.gear.owned).to.eql({ + weapon_warrior_0: true, + armor_warrior_1: true, + eyewear_special_blackTopFrame: true, + eyewear_special_blueTopFrame: true, + eyewear_special_greenTopFrame: true, + eyewear_special_pinkTopFrame: true, + eyewear_special_redTopFrame: true, + eyewear_special_whiteTopFrame: true, + eyewear_special_yellowTopFrame: true, + }); }); }); diff --git a/test/common/ops/buyArmoire.js b/test/common/ops/buyArmoire.js index 2c71c9b428..cea6d7abde 100644 --- a/test/common/ops/buyArmoire.js +++ b/test/common/ops/buyArmoire.js @@ -69,7 +69,16 @@ describe('shared.ops.buyArmoire', () => { } catch (err) { expect(err).to.be.an.instanceof(NotAuthorized); expect(err.message).to.equal(i18n.t('messageNotEnoughGold')); - expect(user.items.gear.owned).to.eql({weapon_warrior_0: true}); + expect(user.items.gear.owned).to.eql({ + weapon_warrior_0: true, + eyewear_special_blackTopFrame: true, + eyewear_special_blueTopFrame: true, + eyewear_special_greenTopFrame: true, + eyewear_special_pinkTopFrame: true, + eyewear_special_redTopFrame: true, + eyewear_special_whiteTopFrame: true, + eyewear_special_yellowTopFrame: true, + }); expect(user.items.food).to.be.empty; expect(user.stats.exp).to.eql(0); done(); @@ -85,7 +94,16 @@ describe('shared.ops.buyArmoire', () => { } catch (err) { expect(err).to.be.an.instanceof(NotAuthorized); expect(err.message).to.equal(i18n.t('cannotBuyItem')); - expect(user.items.gear.owned).to.eql({weapon_warrior_0: true}); + expect(user.items.gear.owned).to.eql({ + weapon_warrior_0: true, + eyewear_special_blackTopFrame: true, + eyewear_special_blueTopFrame: true, + eyewear_special_greenTopFrame: true, + eyewear_special_pinkTopFrame: true, + eyewear_special_redTopFrame: true, + eyewear_special_whiteTopFrame: true, + eyewear_special_yellowTopFrame: true, + }); expect(user.items.food).to.be.empty; expect(user.stats.exp).to.eql(0); done(); diff --git a/test/common/ops/buyGear.js b/test/common/ops/buyGear.js index fc26057ef8..4d1213e80d 100644 --- a/test/common/ops/buyGear.js +++ b/test/common/ops/buyGear.js @@ -44,7 +44,17 @@ describe('shared.ops.buyGear', () => { buyGear(user, {params: {key: 'armor_warrior_1'}}); - expect(user.items.gear.owned).to.eql({ weapon_warrior_0: true, armor_warrior_1: true }); + expect(user.items.gear.owned).to.eql({ + weapon_warrior_0: true, + armor_warrior_1: true, + eyewear_special_blackTopFrame: true, + eyewear_special_blueTopFrame: true, + eyewear_special_greenTopFrame: true, + eyewear_special_pinkTopFrame: true, + eyewear_special_redTopFrame: true, + eyewear_special_whiteTopFrame: true, + eyewear_special_yellowTopFrame: true, + }); }); it('deducts gold from user', () => { diff --git a/test/common_old/algos.mocha.js b/test/common_old/algos.mocha.js deleted file mode 100644 index dca96880d0..0000000000 --- a/test/common_old/algos.mocha.js +++ /dev/null @@ -1,1265 +0,0 @@ -/* eslint-disable camelcase, func-names, no-shadow */ - -import { - generateUser, - generateDaily, - generateHabit, - generateTodo, -} from '../helpers/common.helper'; - -import { - DAY_MAPPING, - startOfWeek, - startOfDay, - daysSince, -} from '../../common/script/cron'; -import scoreTask from '../../common/script/api-v3/scoreTask'; - -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'); -let $w = (s) => { - return s.split(' '); -}; - -shared.i18n.translations = require('../../website/src/libs/api-v2/i18n').translations; -test_helper.addCustomMatchers(); - -/* Helper Functions */ -let rewrapUser = (user) => { - user._wrapped = false; - shared.wrap(user); - return user; -}; - -let beforeAfter = (options = {}) => { - let lastCron; - let user = generateUser(); - let daily = generateDaily(); - let habit = generateHabit(); - let todo = generateTodo(); - - user.dailys.push(daily); - user.habits.push(habit); - user.todos.push(todo); - - let ref = [user, _.cloneDeep(user)]; - let before = ref[0]; - let 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(); - before.preferences.timezoneOffsetAtLastCron = after.preferences.timezoneOffsetAtLastCron = before.preferences.timezoneOffset; - if (options.limitOne) { - 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 || Number(new Date())).subtract({ - days: options.daysAgo, - }); - } - if (options.daysAgo && options.cronAfterStart) { - lastCron.add({ - hours: options.dayStart, - minutes: 1, - }); - } - if (options.daysAgo) { - lastCron = Number(lastCron); - } - _.each([before, after], (obj) => { - if (options.daysAgo) { - obj.lastCron = lastCron; - } - }); - return { - before, - after, - }; -}; - -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); - } else { - expect(after.history.todos).to.have.length(1); - } - expect(after).toHaveExp(0); - expect(after).toHaveGP(0); - expect(after[`${taskType}s`][0].value).to.be.lessThan(before[`${taskType}s`][0].value); -}; - -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); - if (taskType === 'habit') { - expect(after[`${taskType}s`][0].history).to.have.length(1); - } -}; - -let expectNoChange = (before, after) => { - _.each($w('stats items gear dailys todos rewards preferences'), (attr) => { - expect(after[attr]).to.eql(before[attr]); - }); -}; - -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); - expect(Math.abs(after[taskType + 's'][0].value - before[taskType + 's'][0].value)).to.be.lessThan(0.0001); // eslint-disable-line prefer-template -}; - -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); - expect(task.history).to.have.length(1); - }); - _.each(after.todos, (task, i) => { - expect(task.completed).to.be(false); - expect(before.todos[i].value).to.be.greaterThan(task.value); - }); - expect(after.history.todos).to.have.length(1); - _.each([before, after], (obj) => { - delete obj.stats.buffs; - _.each($w('dailys todos history lastCron'), (path) => { - return delete obj[path]; - }); - }); - delete after._tmp; - expectNoChange(before, after); -}; - -let repeatWithoutLastWeekday = () => { - let repeat = { - su: true, - m: true, - t: true, - w: true, - th: true, - f: true, - s: true, - }; - - if (startOfWeek(moment().zone(0)).isoWeekday() === 1) { - repeat.su = false; - } else { - repeat.s = false; - } - return { - repeat, - }; -}; - -describe('User', () => { - it('calculates max MP', () => { - let user = generateUser(); - - expect(user).toHaveMaxMP(30); - user.stats.int = 10; - expect(user).toHaveMaxMP(50); - user.stats.lvl = 5; - expect(user).toHaveMaxMP(54); - user.stats.class = 'wizard'; - user.items.gear.equipped.weapon = 'weapon_wizard_1'; - expect(user).toHaveMaxMP(63); - }); - - it('handles perfect days', () => { - let user = generateUser(); - - user.dailys = []; - _.times(3, () => { - return user.dailys.push(shared.taskDefaults({ - type: 'daily', - startDate: moment().subtract(7, 'days'), - })); - }); - 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(); - user.dailys[0].completed = true; - cron(); - expect(user.stats.buffs.str).to.be(0); - expect(user.achievements.perfect).to.not.be.ok(); - _.each(user.dailys, (d) => { - d.completed = true; - }); - cron(); - expect(user.stats.buffs.str).to.be(1); - expect(user.achievements.perfect).to.be(1); - - let yesterday = moment().subtract(1, 'days'); - - user.dailys[0].repeat[DAY_MAPPING[yesterday.day()]] = false; - _.each(user.dailys.slice(1), (d) => { - d.completed = true; - }); - cron(); - expect(user.stats.buffs.str).to.be(1); - expect(user.achievements.perfect).to.be(2); - }); - - describe('Resting in the Inn', () => { - let user = null; - let cron = null; - - beforeEach(() => { - user = generateUser(); - user.preferences.sleep = true; - cron = () => { - user.lastCron = moment().subtract(1, 'days'); - return user.fns.cron(); - }; - user.dailys = []; - _.times(2, () => { - return user.dailys.push(shared.taskDefaults({ - type: 'daily', - startDate: moment().subtract(7, 'days'), - })); - }); - }); - - it('remains in the inn on cron', () => { - cron(); - expect(user.preferences.sleep).to.be(true); - }); - - it('resets dailies', () => { - user.dailys[0].completed = true; - cron(); - expect(user.dailys[0].completed).to.be(false); - }); - - it('resets checklist on incomplete dailies', () => { - user.dailys[0].checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, { - text: '2', - id: 'checklist-two', - completed: true, - }, { - text: '3', - id: 'checklist-three', - completed: false, - }, - ]; - cron(); - _.each(user.dailys[0].checklist, (box) => { - expect(box.completed).to.be(false); - }); - }); - - it('resets checklist on complete dailies', () => { - user.dailys[0].checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, { - text: '2', - id: 'checklist-two', - completed: true, - }, { - text: '3', - id: 'checklist-three', - completed: false, - }, - ]; - user.dailys[0].completed = true; - cron(); - _.each(user.dailys[0].checklist, (box) => { - expect(box.completed).to.be(false); - }); - }); - - it('does not reset checklist on grey incomplete dailies', () => { - let yesterday = moment().subtract(1, 'days'); - - user.dailys[0].repeat[DAY_MAPPING[yesterday.day()]] = false; - user.dailys[0].checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, { - text: '2', - id: 'checklist-two', - completed: true, - }, { - text: '3', - id: 'checklist-three', - completed: true, - }, - ]; - cron(); - _.each(user.dailys[0].checklist, (box) => { - expect(box.completed).to.be(true); - }); - }); - - it('resets checklist on complete grey complete dailies', () => { - let yesterday = moment().subtract(1, 'days'); - - user.dailys[0].repeat[DAY_MAPPING[yesterday.day()]] = false; - user.dailys[0].checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, { - text: '2', - id: 'checklist-two', - completed: true, - }, { - text: '3', - id: 'checklist-three', - completed: true, - }, - ]; - user.dailys[0].completed = true; - cron(); - _.each(user.dailys[0].checklist, (box) => { - expect(box.completed).to.be(false); - }); - }); - - it('does not damage user for incomplete dailies', () => { - expect(user).toHaveHP(50); - user.dailys[0].completed = true; - user.dailys[1].completed = false; - cron(); - expect(user).toHaveHP(50); - }); - - it('gives credit for complete dailies', () => { - user.dailys[0].completed = true; - expect(user.dailys[0].history).to.be.empty; - cron(); - expect(user.dailys[0].history).to.not.be.empty; - }); - - 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(); - expect(user.stats.hp).to.be.lessThan(50); - }); - }); - - describe('Death', () => { - let user; - - beforeEach(() => { - user = generateUser(); - }); - - it('revives correctly', () => { - user.stats = { - gp: 10, - exp: 100, - lvl: 2, - hp: 0, - class: 'warrior', - }; - user.items.gear.owned.weapon_warrior_0 = true; - user.ops.revive(); - - expect(user).toHaveGP(0); - expect(user).toHaveExp(0); - expect(user).toHaveLevel(1); - expect(user).toHaveHP(50); - expect(user.items.gear.owned).to.eql({ - weapon_warrior_0: false, - eyewear_special_blackTopFrame: true, - eyewear_special_blueTopFrame: true, - eyewear_special_greenTopFrame: true, - eyewear_special_pinkTopFrame: true, - eyewear_special_redTopFrame: true, - eyewear_special_yellowTopFrame: true, - eyewear_special_whiteTopFrame: true, - }); - }); - - it('doesn\'t break unbreakables', () => { - let ce = shared.countExists; - - user.items.gear.owned = { - weapon_warrior_0: true, - shield_warrior_1: true, - shield_rogue_1: true, - head_special_nye: true, - }; - - expect(ce(user.items.gear.owned)).to.be(4); - - user.stats.hp = 0; - user.ops.revive(); - - expect(ce(user.items.gear.owned)).to.be(3); - - user.stats.hp = 0; - user.ops.revive(); - - expect(ce(user.items.gear.owned)).to.be(2); - - user.stats.hp = 0; - user.ops.revive(); - - expect(ce(user.items.gear.owned)).to.be(2); - expect(user.items.gear.owned).to.eql({ - weapon_warrior_0: false, - shield_warrior_1: false, - shield_rogue_1: true, - head_special_nye: true, - }); - }); - - 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; - 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'); - expect(shared.content.gear.flat.head_special_nye.canOwn(user)).to.be(true); - }); - }); - - describe('Rebirth', () => { - it('removes correct gear', () => { - let user = generateUser(); - - 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, - }; - user.ops.rebirth(); - 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('Gem purchases', () => { - it('does not purchase items without enough Gems', () => { - let user = generateUser(); - - user.items.eggs = {}; - user.items.gear.owned = {}; - - user.ops.purchase({ - params: { - type: 'eggs', - key: 'Cactus', - }, - }); - user.ops.purchase({ - params: { - type: 'gear', - 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', - }, - }); - expect(user.items.eggs).to.eql({}); - expect(user.items.gear.owned).to.eql({}); - }); - - it('purchases an egg', () => { - let user = generateUser(); - - user.balance = 1; - user.ops.purchase({ - params: { - type: 'eggs', - key: 'Cactus', - }, - }); - expect(user.items.eggs).to.eql({ - Cactus: 1, - }); - expect(user.balance).to.eql(0.25); - }); - - it('purchases fox ears', () => { - let user = generateUser(); - - user.balance = 1; - user.ops.purchase({ - params: { - type: 'gear', - key: 'headAccessory_special_foxEars', - }, - }); - - expect(user.items.gear.owned.headAccessory_special_foxEars).to.eql(true); - expect(user.balance).to.eql(0.5); - }); - - it('unlocks all the animal ears at once', () => { - let user = generateUser(); - - 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', - }, - }); - - expect(user.items.gear.owned.headAccessory_special_bearEars).to.eql(true); - expect(user.items.gear.owned.headAccessory_special_cactusEars).to.eql(true); - expect(user.items.gear.owned.headAccessory_special_foxEars).to.eql(true); - expect(user.items.gear.owned.headAccessory_special_lionEars).to.eql(true); - expect(user.items.gear.owned.headAccessory_special_pandaEars).to.eql(true); - expect(user.items.gear.owned.headAccessory_special_pigEars).to.eql(true); - expect(user.items.gear.owned.headAccessory_special_tigerEars).to.eql(true); - expect(user.items.gear.owned.headAccessory_special_wolfEars).to.eql(true); - expect(user.balance).to.eql(0.75); - }); - }); - - 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); - } - expect(spell.cast).to.be.a('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 = generateUser(); - user.flags.dropsEnabled = true; - this.task_id = shared.uuid(); - return user.ops.addTask({ - body: { - type: 'daily', - id: this.task_id, - }, - }); - }); - - 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); - - let delta = scoreTask({task: user.dailys[user.dailys.length - 1], user, direction: 'up'}); - user.fns.randomDrop({task: user.dailys[user.dailys.length - 1], delta}, {}); - expect(user.items.eggs).to.be.empty; - expect(user.items.hatchingPotions).to.not.be.empty; - expect(user.items.food).to.be.empty; - results.push(user.fns.predictableRandom.restore()); - } - return results; - }); - - 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); - let delta = scoreTask({task: user.dailys[user.dailys.length - 1], user, direction: 'up'}); - user.fns.randomDrop({task: user.dailys[user.dailys.length - 1], delta}, {}); - expect(user.items.eggs).to.not.be.empty; - expect(user.items.hatchingPotions).to.be.empty; - expect(user.items.food).to.be.empty; - results.push(user.fns.predictableRandom.restore()); - } - return results; - }); - - 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); - let delta = scoreTask({task: user.dailys[user.dailys.length - 1], user, direction: 'up'}); - user.fns.randomDrop({task: user.dailys[user.dailys.length - 1], delta}, {}); - expect(user.items.eggs).to.be.empty; - expect(user.items.hatchingPotions).to.be.empty; - expect(user.items.food).to.not.be.empty; - results.push(user.fns.predictableRandom.restore()); - } - return results; - }); - - it('does not get a drop', function () { - sinon.stub(user.fns, 'predictableRandom').returns(0.5); - let delta = scoreTask({task: user.dailys[user.dailys.length - 1], user, direction: 'up'}); - user.fns.randomDrop({task: user.dailys[user.dailys.length - 1], delta}, {}); - expect(user.items.eggs).to.eql({}); - expect(user.items.hatchingPotions).to.eql({}); - expect(user.items.food).to.eql({}); - - user.fns.predictableRandom.restore(); - }); - }); - - 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'); - } - if (quest.previous) { - expect(quest.previous).to.be.an('string'); - } - if (quest.canBuy()) { - expect(quest.value).to.be.greaterThan(0); - } - expect(quest.drop.gp).to.not.be.lessThan(0); - expect(quest.drop.exp).to.not.be.lessThan(0); - expect(quest.category).to.match(/pet|unlockable|gold|world/); - if (quest.drop.items) { - expect(quest.drop.items).to.be.an(Array); - } - if (quest.boss) { - expect(quest.boss.name()).to.be.an('string'); - expect(quest.boss.hp).to.be.greaterThan(0); - expect(quest.boss.str).to.be.greaterThan(0); - } else if (quest.collect) { - _.each(quest.collect, (collect) => { - expect(collect.text()).to.be.an('string'); - expect(collect.count).to.be.greaterThan(0); - }); - } - }); - }); - }); - - describe('Achievements', () => { - _.each(shared.content.classes, (klass) => { - let user = generateUser(); - - user.achievements.ultimateGearSets = {}; - - user.stats.gp = 10000; - _.each(shared.content.gearTypes, (type) => { - _.each([1, 2, 3, 4, 5], (i) => { - return user.ops.buy({ - params: `${type}_${klass}_${i}`, - }); - }); - }); - - it(`does not get ultimateGear ${klass}`, () => { - expect(user.achievements.ultimateGearSets[klass]).to.not.be.ok(); - }); - _.each(shared.content.gearTypes, (type) => { - return user.ops.buy({ - params: `${type}_${klass}_6`, - }); - }); - - xit(`gets ultimateGear ${klass}`, () => { - expect(user.achievements.ultimateGearSets[klass]).to.be.ok(); - }); - }); - - it('does not remove existing Ultimate Gear achievements', () => { - let user = generateUser(); - - user.achievements.ultimateGearSets = { - 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', - }); - expect(user.achievements.ultimateGearSets).to.eql({ - healer: true, - wizard: true, - rogue: true, - warrior: true, - }); - }); - }); - - describe('unlocking features', () => { - it('unlocks drops at level 3', () => { - let user = generateUser(); - - user.stats.lvl = 3; - user.fns.updateStats(user.stats); - expect(user.flags.dropsEnabled).to.be.ok(); - }); - - it('unlocks Rebirth at level 50', () => { - let user = generateUser(); - - user.stats.lvl = 50; - user.fns.updateStats(user.stats); - expect(user.flags.rebirthEnabled).to.be.ok(); - }); - - describe('level-awarded Quests', () => { - it('gets Attack of the Mundane at level 15', () => { - let user = generateUser(); - - user.stats.lvl = 15; - user.fns.updateStats(user.stats); - expect(user.flags.levelDrops.atom1).to.be.ok(); - expect(user.items.quests.atom1).to.eql(1); - }); - - it('gets Vice at level 30', () => { - let user = generateUser(); - - user.stats.lvl = 30; - user.fns.updateStats(user.stats); - expect(user.flags.levelDrops.vice1).to.be.ok(); - expect(user.items.quests.vice1).to.eql(1); - }); - - it('gets Golden Knight at level 40', () => { - let user = generateUser(); - - user.stats.lvl = 40; - user.fns.updateStats(user.stats); - expect(user.flags.levelDrops.goldenknight1).to.be.ok(); - expect(user.items.quests.goldenknight1).to.eql(1); - }); - - it('gets Moonstone Chain at level 60', () => { - let user = generateUser(); - - user.stats.lvl = 60; - user.fns.updateStats(user.stats); - expect(user.flags.levelDrops.moonstone1).to.be.ok(); - expect(user.items.quests.moonstone1).to.eql(1); - }); - }); - }); -}); - -describe('Simple Scoring', () => { - beforeEach(function () { - let ref = beforeAfter(); - - this.before = ref.before; - this.after = ref.after; - }); - - it('Habits : Up', function () { - let delta = scoreTask({task: this.after.habits[0], user: this.after, direction: 'down', times: 5}); - this.after.fns.randomDrop({task: this.after.habits[0], delta}, {}); - expectLostPoints(this.before, this.after, 'habit'); - }); - - it('Habits : Down', function () { - let delta = scoreTask({task: this.after.habits[0], user: this.after, direction: 'up', times: 5}); - this.after.fns.randomDrop({task: this.after.habits[0], delta}, {}); - expectGainedPoints(this.before, this.after, 'habit'); - }); - - it('Dailys : Up', function () { - let delta = scoreTask({task: this.after.dailys[0], user: this.after, direction: 'up'}); - this.after.fns.randomDrop({task: this.after.dailys[0], delta}, {}); - expectGainedPoints(this.before, this.after, 'daily'); - }); - - it('Dailys : Up, Down', function () { - let delta = scoreTask({task: this.after.dailys[0], user: this.after, direction: 'up'}); - this.after.fns.randomDrop({task: this.after.dailys[0], delta}, {}); - let delta2 = scoreTask({task: this.after.dailys[0], user: this.after, direction: 'down'}); - this.after.fns.randomDrop({task: this.after.dailys[0], delta2}, {}); - expectClosePoints(this.before, this.after, 'daily'); - }); - - it('Todos : Up', function () { - let delta = scoreTask({task: this.after.todos[0], user: this.after, direction: 'up'}); - this.after.fns.randomDrop({task: this.after.todos[0], delta}, {}); - expectGainedPoints(this.before, this.after, 'todo'); - }); - - it('Todos : Up, Down', function () { - let delta = scoreTask({task: this.after.todos[0], user: this.after, direction: 'up'}); - this.after.fns.randomDrop({task: this.after.todos[0], delta}, {}); - let delta2 = scoreTask({task: this.after.todos[0], user: this.after, direction: 'down'}); - this.after.fns.randomDrop({task: this.after.todos[0], delta2}, {}); - expectClosePoints(this.before, this.after, 'todo'); - }); -}); - -describe('Cron', () => { - let user; - - beforeEach(() => { - user = generateUser(); - }); - - it('computes shouldCron', () => { - let paths = {}; - - user.fns.cron({ - paths, - }); - expect(user.lastCron).to.not.be.ok; - user.lastCron = Number(moment().subtract(1, 'days')); - paths = {}; - user.fns.cron({ - paths, - }); - expect(user.lastCron).to.be.greaterThan(0); - }); - - 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; - expect(after.lastCron).to.not.be(before.lastCron); - delete after.stats.buffs; - delete before.stats.buffs; - expect(before.stats).to.eql(after.stats); - - 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('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); - expect(after).toHaveExp(0); - expect(after).toHaveGP(0); - expect(before.todos[0].value).to.be(0); - expect(after.todos[0].value).to.be(-1); - expect(after.history.todos).to.have.length(1); - }); - - 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); - expect(after.todos[0].value).to.be(-1); - }); - }); - - describe('cron day calculations', () => { - let dayStart = 4; - let fstr = 'YYYY-MM-DD HH: mm: ss'; - - it('startOfDay before dayStart', () => { - let start = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 - 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 - */ - - function runCron (options) { - _.each([480, 240, 0, -120], function (timezoneOffset) { - let now = startOfWeek({ - timezoneOffset, - }).add(options.currentHour || 0, 'hours'); - - let ref = beforeAfter({ - now, - timezoneOffset, - daysAgo: 1, - cronAfterStart: options.cronAfterStart || true, - dayStart: options.dayStart || 0, - limitOne: 'daily', - }); - - let before = ref.before; - let after = ref.after; - - if (options.repeat) { - before.dailys[0].repeat = after.dailys[0].repeat = options.repeat; - } - before.dailys[0].streak = after.dailys[0].streak = 10; - if (options.checked) { - before.dailys[0].completed = after.dailys[0].completed = true; - } - before.dailys[0].startDate = after.dailys[0].startDate = moment().subtract(30, 'days'); - if (options.shouldDo) { - expect(shared.shouldDo(now.toDate(), after.dailys[0], { - timezoneOffset, - dayStart: options.dayStart, - now, - })).to.be.ok(); - } - after.fns.cron({ - now, - }); - before.stats.mp = after.stats.mp; - - 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, - after, - }; - }); - } - - let cronMatrix = { - steps: { - 'due yesterday': { - defaults: { - daysAgo: 1, - cronAfterStart: true, - limitOne: 'daily', - }, - steps: { - '(simple)': { - expect: 'losePoints', - }, - 'due today': { - defaults: { - repeat: { - su: true, - m: true, - t: true, - w: true, - th: true, - f: true, - s: true, - }, - }, - steps: { - 'pre-dayStart': { - defaults: { - currentHour: 3, - dayStart: 4, - shouldDo: true, - }, - steps: { - checked: { - checked: true, - expect: 'noChange', - }, - 'un-checked': { - checked: false, - expect: 'noChange', - }, - }, - }, - 'post-dayStart': { - defaults: { - currentHour: 5, - dayStart: 4, - shouldDo: true, - }, - steps: { - checked: { - checked: true, - expect: 'noDamage', - }, - unchecked: { - checked: false, - expect: 'losePoints', - }, - }, - }, - }, - }, - 'NOT due today': { - defaults: { - repeat: { - su: true, - m: false, - t: true, - w: true, - th: true, - f: true, - s: true, - }, - }, - steps: { - 'pre-dayStart': { - defaults: { - currentHour: 3, - dayStart: 4, - shouldDo: true, - }, - steps: { - checked: { - checked: true, - expect: 'noChange', - }, - 'un-checked': { - checked: false, - expect: 'noChange', - }, - }, - }, - 'post-dayStart': { - defaults: { - currentHour: 5, - dayStart: 4, - shouldDo: false, - }, - steps: { - checked: { - checked: true, - expect: 'noDamage', - }, - unchecked: { - checked: false, - expect: 'losePoints', - }, - }, - }, - }, - }, - }, - }, - 'not due yesterday': { - defaults: repeatWithoutLastWeekday(), - steps: { - '(simple)': { - expect: 'noDamage', - }, - 'post-dayStart': { - currentHour: 5, - dayStart: 4, - expect: 'noDamage', - }, - 'pre-dayStart': { - currentHour: 3, - dayStart: 4, - expect: 'noChange', - }, - }, - }, - }, - }; - - let recurseCronMatrix = (obj, options = {}) => { - if (obj.steps) { - _.each(obj.steps, (step, text) => { - let o = _.cloneDeep(options); - - if (!o.text) { - o.text = ''; - } - o.text += `${text}`; - return recurseCronMatrix(step, _.defaults(o, obj.defaults)); - }); - } else { - it(`${options.text}`, () => { - return runCron(_.defaults(obj, options)); - }); - } - }; - - return recurseCronMatrix(cronMatrix); - }); - }); -}); - -describe('Helper', () => { - it('calculates gold coins', () => { - expect(shared.gold(10)).to.eql(10); - expect(shared.gold(1.957)).to.eql(1); - expect(shared.gold()).to.eql(0); - }); - - 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'); - expect(shared.silver()).to.eql('00'); - }); - - 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); - expect(shared.tnl(99)).to.eql(3580); - }); - - 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(startOfDay({ - now: new Date(2013, 0, 1, 0), - }, { - timezoneOffset: zone, - }).format(fstr)).to.eql(today); - expect(startOfDay({ - now: new Date(2013, 0, 1, 5), - }, { - timezoneOffset: zone, - }).format(fstr)).to.eql(today); - expect(startOfDay({ - now: new Date(2013, 0, 1, 23, 59, 59), - timezoneOffset: zone, - }).format(fstr)).to.eql(today); - }); -}); diff --git a/test/common_old/dailies.js b/test/common_old/dailies.js deleted file mode 100644 index 7757465f2e..0000000000 --- a/test/common_old/dailies.js +++ /dev/null @@ -1,499 +0,0 @@ -/* eslint-disable camelcase */ -import { - startOfWeek, -} from '../../common/script/cron'; - -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/api-v2/i18n.js').translations; - -let repeatWithoutLastWeekday = () => { // eslint-disable-line no-unused-vars - let repeat = { - su: true, - m: true, - t: true, - w: true, - th: true, - f: true, - s: true, - }; - - if (startOfWeek(moment().zone(0)).isoWeekday() === 1) { - repeat.su = false; - } else { - repeat.s = false; - } - return { - repeat, - }; -}; - - -/* Helper Functions */ - -import { - generateUser, -} from '../helpers/common.helper'; - -let cron = (usr, missedDays = 1) => { - usr.lastCron = moment().subtract(missedDays, 'days'); - usr.fns.cron(); -}; - -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 = generateUser(); - user.dailys = [ - shared.taskDefaults({ - type: 'daily', - startDate: moment().add(7, 'days'), - frequency: 'daily', - }), shared.taskDefaults({ - type: 'daily', - startDate: moment().add(7, 'days'), - frequency: 'weekly', - repeat: { - su: true, - m: true, - t: true, - w: true, - th: true, - f: true, - s: true, - }, - }), - ]; - daily = user.dailys[0]; - weekly = user.dailys[1]; - }); - - it('does not damage user for not completing it', () => { - cron(user); - expect(user.stats.hp).to.be(50); - }); - - it('does not change value on cron if daily is incomplete', () => { - cron(user); - expect(daily.value).to.be(0); - expect(weekly.value).to.be(0); - }); - - it('does not reset checklists if daily is not marked as complete', () => { - let checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, { - text: '2', - id: 'checklist-two', - completed: true, - }, { - text: '3', - id: 'checklist-three', - completed: false, - }, - ]; - - daily.checklist = checklist; - weekly.checklist = checklist; - cron(user); - expect(daily.checklist[0].completed).to.be(true); - expect(daily.checklist[1].completed).to.be(true); - expect(daily.checklist[2].completed).to.be(false); - expect(weekly.checklist[0].completed).to.be(true); - expect(weekly.checklist[1].completed).to.be(true); - expect(weekly.checklist[2].completed).to.be(false); - }); - - it('resets checklists if daily is marked as complete', () => { - let checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, { - text: '2', - id: 'checklist-two', - completed: true, - }, { - text: '3', - id: 'checklist-three', - completed: false, - }, - ]; - - daily.checklist = checklist; - weekly.checklist = checklist; - daily.completed = true; - weekly.completed = true; - cron(user); - _.each(daily.checklist, (box) => { - expect(box.completed).to.be(false); - }); - _.each(weekly.checklist, (box) => { - expect(box.completed).to.be(false); - }); - }); - - 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); - - let weekly_due_today = shared.shouldDo(moment(), weekly); - let weekly_due_on_start_date = shared.shouldDo(moment().add(7, 'days'), weekly); - - expect(weekly_due_today).to.be(false); - expect(weekly_due_on_start_date).to.be(true); - }); - }); - - describe('when startDate is in the past', () => { - beforeEach(() => { - user = generateUser(); - user.dailys = [ - shared.taskDefaults({ - type: 'daily', - startDate: moment().subtract(7, 'days'), - frequency: 'daily', - }), shared.taskDefaults({ - type: 'daily', - startDate: moment().subtract(7, 'days'), - frequency: 'weekly', - }), - ]; - daily = user.dailys[0]; - weekly = user.dailys[1]; - }); - - it('does damage user for not completing it', () => { - cron(user); - expect(user.stats.hp).to.be.lessThan(50); - }); - - it('decreases value on cron if daily is incomplete', () => { - cron(user, 1); - expect(daily.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', () => { - cron(user, 7); - expect(daily.value).to.be(-1); - expect(weekly.value).to.be(-1); - }); - - it('resets checklists if daily is not marked as complete', () => { - let checklist; - - checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, { - text: '2', - id: 'checklist-two', - completed: true, - }, { - text: '3', - id: 'checklist-three', - completed: false, - }, - ]; - daily.checklist = checklist; - weekly.checklist = checklist; - cron(user); - _.each(daily.checklist, (box) => { - expect(box.completed).to.be(false); - }); - _.each(weekly.checklist, (box) => { - expect(box.completed).to.be(false); - }); - }); - - it('resets checklists if daily is marked as complete', () => { - let checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, { - text: '2', - id: 'checklist-two', - completed: true, - }, { - text: '3', - id: 'checklist-three', - completed: false, - }, - ]; - - daily.checklist = checklist; - daily.completed = true; - weekly.checklist = checklist; - weekly.completed = true; - cron(user); - _.each(daily.checklist, (box) => { - expect(box.completed).to.be(false); - }); - _.each(weekly.checklist, (box) => { - expect(box.completed).to.be(false); - }); - }); - }); - - describe('when startDate is today', () => { - beforeEach(() => { - user = generateUser(); - user.dailys = [ - shared.taskDefaults({ - type: 'daily', - startDate: moment().subtract(1, 'days'), - frequency: 'daily', - }), shared.taskDefaults({ - type: 'daily', - startDate: moment().subtract(1, 'days'), - frequency: 'weekly', - }), - ]; - daily = user.dailys[0]; - weekly = user.dailys[1]; - }); - - it('does damage user for not completing it', () => { - cron(user); - expect(user.stats.hp).to.be.lessThan(50); - }); - - it('decreases value on cron if daily is incomplete', () => { - cron(user); - expect(daily.value).to.be.lessThan(0); - expect(weekly.value).to.be.lessThan(0); - }); - - it('resets checklists if daily is not marked as complete', () => { - let checklist; - - checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, { - text: '2', - id: 'checklist-two', - completed: true, - }, { - text: '3', - id: 'checklist-three', - completed: false, - }, - ]; - daily.checklist = checklist; - weekly.checklist = checklist; - cron(user); - _.each(daily.checklist, (box) => { - expect(box.completed).to.be(false); - }); - _.each(weekly.checklist, (box) => { - expect(box.completed).to.be(false); - }); - }); - - it('resets checklists if daily is marked as complete', () => { - let checklist; - - checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, { - text: '2', - id: 'checklist-two', - completed: true, - }, { - text: '3', - id: 'checklist-three', - completed: false, - }, - ]; - daily.checklist = checklist; - daily.completed = true; - weekly.checklist = checklist; - weekly.completed = true; - cron(user); - _.each(daily.checklist, (box) => { - expect(box.completed).to.be(false); - }); - _.each(weekly.checklist, (box) => { - expect(box.completed).to.be(false); - }); - }); - }); -}); - -describe('daily that repeats every x days', () => { - let user = null; - let daily = null; - - beforeEach(() => { - user = generateUser(); - user.dailys = [ - shared.taskDefaults({ - type: 'daily', - startDate: moment(), - frequency: 'daily', - }), - ]; - daily = user.dailys[0]; - }); - _.times(11, (due) => { - it(`where x equals ${due}`, () => { - daily.everyX = due; - _.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) { - expect(isDue).to.be(false); - } - }); - }); - }); -}); - -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 = generateUser(); - user.dailys = [ - shared.taskDefaults({ - type: 'daily', - startDate: moment().subtract(startDateDaysAgo, 'days'), - frequency: 'daily', - everyX, - }), - ]; - daily = user.dailys[0]; - }); - - it('decreases value on cron once only if daily is incomplete', () => { - cron(user, missedDays); - expect(daily.value).to.be(-1); - }); - - it('resets checklists if daily is incomplete', () => { - let checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, - ]; - - daily.checklist = checklist; - cron(user, missedDays); - _.each(daily.checklist, (box) => { - expect(box.completed).to.be(false); - }); - }); - - it('resets checklists if daily is marked as complete', () => { - let checklist; - - checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, - ]; - daily.checklist = checklist; - daily.completed = true; - cron(user, missedDays); - _.each(daily.checklist, (box) => { - expect(box.completed).to.be(false); - }); - }); - }); - - describe('but not missing a due date', () => { - let missedDays; - - missedDays = everyX - 1; - beforeEach(() => { - user = generateUser(); - user.dailys = [ - shared.taskDefaults({ - type: 'daily', - startDate: moment().subtract(startDateDaysAgo, 'days'), - frequency: 'daily', - everyX, - }), - ]; - daily = user.dailys[0]; - }); - - it('does not decrease value on cron', () => { - cron(user, missedDays); - expect(daily.value).to.be(0); - }); - - it('does not reset checklists if daily is incomplete', () => { - let checklist; - - checklist = [ - { - text: '1', - id: 'checklist-one', - completed: true, - }, - ]; - daily.checklist = checklist; - cron(user, missedDays); - _.each(daily.checklist, (box) => { - expect(box.completed).to.be(true); - }); - }); - - it('resets checklists if daily is marked as complete', () => { - let checklist; - - checklist = [ - { - text: 1, - id: 'checklist-one', - completed: true, - }, - ]; - daily.checklist = checklist; - daily.completed = true; - cron(user, missedDays); - _.each(daily.checklist, (box) => { - expect(box.completed).to.be(false); - }); - }); - }); -}); diff --git a/test/common_old/preenTodos.test.js b/test/common_old/preenTodos.test.js deleted file mode 100644 index c9f9a45028..0000000000 --- a/test/common_old/preenTodos.test.js +++ /dev/null @@ -1,76 +0,0 @@ -import moment from 'moment'; -import { generateTodo } from '../helpers/common.helper'; -import { preenTodos } from '../../common/script/index.js'; - -describe('#preenTodos', () => { - let todos, uncompletedTodo, completedChallengeTodo, newlyCompletedTodo, completedTodoFromTwoDaysAgo, completedTodoFromThreeDaysAgo, completedTodoFromTenDaysAgo; - - beforeEach(() => { - uncompletedTodo = generateTodo({ completed: false }); - completedChallengeTodo = generateTodo({ - completed: true, - challenge: { id: 'some-challenge' }, - }); - newlyCompletedTodo = generateTodo({ - completed: true, - dateCompleted: moment(), - }); - completedTodoFromTwoDaysAgo = generateTodo({ - completed: true, - dateCompleted: moment().subtract({ days: 2 }), - }); - completedTodoFromThreeDaysAgo = generateTodo({ - completed: true, - dateCompleted: moment().subtract({ days: 3 }), - }); - completedTodoFromTenDaysAgo = generateTodo({ - completed: true, - dateCompleted: moment().subtract({ days: 10 }), - }); - - todos = [ - uncompletedTodo, - completedChallengeTodo, - newlyCompletedTodo, - completedTodoFromTwoDaysAgo, - completedTodoFromThreeDaysAgo, - completedTodoFromTenDaysAgo, - ]; - }); - - it('includes uncompleted todos', () => { - let preenedTodos = preenTodos(todos); - - expect(preenedTodos).to.include(uncompletedTodo); - }); - - it('includes completed challenge todos', () => { - let preenedTodos = preenTodos(todos); - - expect(preenedTodos).to.include(completedChallengeTodo); - }); - - it('includes recently completed todos', () => { - let preenedTodos = preenTodos(todos); - - expect(preenedTodos).to.include(newlyCompletedTodo); - }); - - it('includes todos completed two days ago', () => { - let preenedTodos = preenTodos(todos); - - expect(preenedTodos).to.include(completedTodoFromTwoDaysAgo); - }); - - it('does not include todos completed three days ago', () => { - let preenedTodos = preenTodos(todos); - - expect(preenedTodos).to.not.include(completedTodoFromThreeDaysAgo); - }); - - it('does not include todos completed more than three days ago', () => { - let preenedTodos = preenTodos(todos); - - expect(preenedTodos).to.not.include(completedTodoFromTenDaysAgo); - }); -}); diff --git a/test/common_old/shared.spells.test.js b/test/common_old/shared.spells.test.js deleted file mode 100644 index 931f9b9991..0000000000 --- a/test/common_old/shared.spells.test.js +++ /dev/null @@ -1,103 +0,0 @@ -import shared from '../../common/script/index.js'; -import { - generateUser, - generateTodo, -} from '../helpers/common.helper'; - - -describe('Spells', () => { - let user; - - beforeEach(() => { - let todo = generateTodo(); - - user = generateUser({ - stats: { - int: 20, - str: 20, - con: 20, - per: 20, - lvl: 20, - }, - }); - user.todos.push(todo); - }); - - context('Rogue Spells', () => { - beforeEach(() => { - user.stats.class = 'rogue'; - }); - - describe('#backstab', () => { - it('adds exp to user', () => { - const PREVIOUS_EXP = user.stats.exp; - - shared.content.spells.rogue.backStab.cast(user, user.todos[0]); - - expect(user.stats.exp).to.be.greaterThan(PREVIOUS_EXP); - }); - - it('adds gp to user', () => { - const PREVIOUS_GP = user.stats.gp; - - shared.content.spells.rogue.backStab.cast(user, user.todos[0]); - - expect(user.stats.gp).to.be.greaterThan(PREVIOUS_GP); - }); - - it('levels up user if the gain in experience will level up the user', () => { - user.stats.exp = 399; - user.stats.lvl = 17; - - shared.content.spells.rogue.backStab.cast(user, user.todos[0]); - expect(user.stats.lvl).to.eql(18); - }); - - it('adds quest scroll to inventory when passing level milestone', () => { - user.stats.exp = 329; - user.stats.lvl = 14; - - expect(user.items.quests).to.not.have.property('atom1'); - - shared.content.spells.rogue.backStab.cast(user, user.todos[0]); - - expect(user.items.quests).to.have.property('atom1', 1); - }); - }); - }); - - context('Wizard Spells', () => { - beforeEach(() => { - user.stats.class = 'wizard'; - }); - - describe('#fireball (Burst of flames)', () => { - it('adds exp to user', () => { - const PREVIOUS_EXP = user.stats.exp; - - shared.content.spells.wizard.fireball.cast(user, user.todos[0]); - - expect(user.stats.exp).to.be.greaterThan(PREVIOUS_EXP); - }); - - it('levels up user if the gain in experience will level up the user', () => { - user.stats.exp = 399; - user.stats.lvl = 17; - - shared.content.spells.wizard.fireball.cast(user, user.todos[0]); - expect(user.stats.lvl).to.eql(18); - }); - - it('adds quest scroll to inventory when passing level milestone', () => { - user.stats.exp = 329; - user.stats.lvl = 14; - - expect(user.items.quests).to.not.have.property('atom1'); - - shared.content.spells.wizard.fireball.cast(user, user.todos[0]); - - expect(user.items.quests).to.have.property('atom1', 1); - }); - }); - }); -}); diff --git a/test/common_old/simulations/autoAllocate.js b/test/common_old/simulations/autoAllocate.js deleted file mode 100644 index 0b0348efee..0000000000 --- a/test/common_old/simulations/autoAllocate.js +++ /dev/null @@ -1,161 +0,0 @@ -var $w, _, id, modes, shared, user; - -shared = require('../../../common/script/index.js'); - -_ = require('lodash'); - -$w = function(s) { - return s.split(' '); -}; - -id = shared.uuid(); - -user = { - stats: { - "class": 'warrior', - lvl: 1, - hp: 50, - gp: 0, - exp: 10, - per: 0, - int: 0, - con: 0, - str: 0, - buffs: { - per: 0, - int: 0, - con: 0, - str: 0 - }, - training: { - int: 0, - con: 0, - per: 0, - str: 0 - } - }, - preferences: { - automaticAllocation: false - }, - party: { - quest: { - key: 'evilsanta', - progress: { - up: 0, - down: 0 - } - } - }, - achievements: {}, - items: { - eggs: {}, - hatchingPotions: {}, - food: {}, - gear: { - equipped: { - weapon: 'weapon_warrior_4', - armor: 'armor_warrior_4', - shield: 'shield_warrior_4', - head: 'head_warrior_4' - } - } - }, - habits: [ - { - id: 'a', - value: 1, - type: 'habit', - attribute: 'str' - } - ], - dailys: [ - { - id: 'b', - value: 1, - type: 'daily', - attribute: 'str' - } - ], - todos: [ - { - id: 'c', - value: 1, - type: 'todo', - attribute: 'con' - }, { - id: 'd', - value: 1, - type: 'todo', - attribute: 'per' - }, { - id: 'e', - value: 1, - type: 'todo', - attribute: 'int' - } - ], - rewards: [] -}; - -modes = { - flat: _.cloneDeep(user), - classbased_warrior: _.cloneDeep(user), - classbased_rogue: _.cloneDeep(user), - classbased_wizard: _.cloneDeep(user), - classbased_healer: _.cloneDeep(user), - taskbased: _.cloneDeep(user) -}; - -modes.classbased_warrior.stats["class"] = 'warrior'; - -modes.classbased_rogue.stats["class"] = 'rogue'; - -modes.classbased_wizard.stats["class"] = 'wizard'; - -modes.classbased_healer.stats["class"] = 'healer'; - -_.each($w('flat classbased_warrior classbased_rogue classbased_wizard classbased_healer taskbased'), function(mode) { - _.merge(modes[mode].preferences, { - automaticAllocation: true, - allocationMode: mode.indexOf('classbased') === 0 ? 'classbased' : mode - }); - return shared.wrap(modes[mode]); -}); - -console.log("\n\n================================================"); - -console.log("New Simulation"); - -console.log("================================================\n\n"); - -_.times([20], function(lvl) { - console.log("[lvl " + lvl + "]\n--------------\n"); - return _.each($w('flat classbased_warrior classbased_rogue classbased_wizard classbased_healer taskbased'), function(mode) { - var str, u; - u = modes[mode]; - u.stats.exp = shared.tnl(lvl) + 1; - if (mode === 'taskbased') { - _.merge(u.stats, { - per: 0, - con: 0, - int: 0, - str: 0 - }); - } - u.habits[0].attribute = u.fns.randomVal({ - str: 'str', - int: 'int', - per: 'per', - con: 'con' - }); - u.ops.score({ - params: { - id: u.habits[0].id - }, - direction: 'up' - }); - u.fns.updateStats(u.stats); - str = mode + (mode === 'taskbased' ? " (" + u.habits[0].attribute + ")" : ""); - return console.log(str, _.pick(u.stats, $w('per int con str'))); - }); -}); diff --git a/test/common_old/simulations/passive_active_attrs.js b/test/common_old/simulations/passive_active_attrs.js deleted file mode 100644 index f69a2cafc2..0000000000 --- a/test/common_old/simulations/passive_active_attrs.js +++ /dev/null @@ -1,291 +0,0 @@ -var _, clearUser, id, party, s, shared, task, user; - -shared = require('../../../common/script/index.js'); - -_ = require('lodash'); - -id = shared.uuid(); - -user = { - stats: { - "class": 'warrior', - buffs: { - per: 0, - int: 0, - con: 0, - str: 0 - } - }, - party: { - quest: { - key: 'evilsanta', - progress: { - up: 0, - down: 0 - } - } - }, - preferences: { - automaticAllocation: false - }, - achievements: {}, - flags: { - levelDrops: {} - }, - items: { - eggs: {}, - hatchingPotions: {}, - food: {}, - quests: {}, - gear: { - equipped: { - weapon: 'weapon_warrior_4', - armor: 'armor_warrior_4', - shield: 'shield_warrior_4', - head: 'head_warrior_4' - } - } - }, - habits: [ - shared.taskDefaults({ - id: id, - value: 0 - }) - ], - dailys: [ - { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - }, { - "text": "1" - } - ], - todos: [], - rewards: [] -}; - -shared.wrap(user); - -s = user.stats; - -task = user.tasks[id]; - -party = [user]; - -console.log("\n\n================================================"); - -console.log("New Simulation"); - -console.log("================================================\n\n"); - -clearUser = function(lvl) { - if (lvl == null) { - lvl = 1; - } - _.merge(user.stats, { - exp: 0, - gp: 0, - hp: 50, - lvl: lvl, - str: lvl * 1.5, - con: lvl * 1.5, - per: lvl * 1.5, - int: lvl * 1.5, - mp: 100 - }); - _.merge(s.buffs, { - str: 0, - con: 0, - int: 0, - per: 0 - }); - _.merge(user.party.quest.progress, { - up: 0, - down: 0 - }); - return user.items.lastDrop = { - count: 0 - }; -}; - -_.each([1, 25, 50, 75, 100], function(lvl) { - console.log("[LEVEL " + lvl + "] (" + (lvl * 2) + " points total in every attr)\n\n"); - _.each({ - red: -25, - yellow: 0, - green: 35 - }, function(taskVal, color) { - var _party, b4, str; - console.log("[task.value = " + taskVal + " (" + color + ")]"); - console.log("direction\texpΔ\t\thpΔ\tgpΔ\ttask.valΔ\ttask.valΔ bonus\t\tboss-hit"); - _.each(['up', 'down'], function(direction) { - var b4, delta; - clearUser(lvl); - b4 = { - hp: s.hp, - taskVal: taskVal - }; - task.value = taskVal; - if (direction === 'up') { - task.type = 'daily'; - } - delta = user.ops.score({ - params: { - id: id, - direction: direction - } - }); - return console.log((direction === 'up' ? '↑' : '↓') + "\t\t" + s.exp + "/" + (shared.tnl(s.lvl)) + "\t\t" + ((b4.hp - s.hp).toFixed(1)) + "\t" + (s.gp.toFixed(1)) + "\t" + (delta.toFixed(1)) + "\t\t" + ((task.value - b4.taskVal - delta).toFixed(1)) + "\t\t\t" + (user.party.quest.progress.up.toFixed(1))); - }); - str = '- [Wizard]'; - task.value = taskVal; - clearUser(lvl); - b4 = { - taskVal: taskVal - }; - shared.content.spells.wizard.fireball.cast(user, task); - str += "\tfireball(task.valΔ:" + ((task.value - taskVal).toFixed(1)) + " exp:" + (s.exp.toFixed(1)) + " bossHit:" + (user.party.quest.progress.up.toFixed(2)) + ")"; - task.value = taskVal; - clearUser(lvl); - _party = [ - user, { - stats: { - mp: 0 - } - } - ]; - shared.content.spells.wizard.mpheal.cast(user, _party); - str += "\t| mpheal(mp:" + _party[1].stats.mp + ")"; - task.value = taskVal; - clearUser(lvl); - shared.content.spells.wizard.earth.cast(user, party); - str += "\t\t\t\t| earth(buffs.int:" + s.buffs.int + ")"; - s.buffs.int = 0; - task.value = taskVal; - clearUser(lvl); - shared.content.spells.wizard.frost.cast(user, {}); - str += "\t\t\t| frost(N/A)"; - console.log(str); - str = '- [Warrior]'; - task.value = taskVal; - clearUser(lvl); - shared.content.spells.warrior.smash.cast(user, task); - b4 = { - taskVal: taskVal - }; - str += "\tsmash(task.valΔ:" + ((task.value - taskVal).toFixed(1)) + ")"; - task.value = taskVal; - clearUser(lvl); - shared.content.spells.warrior.defensiveStance.cast(user, {}); - str += "\t\t| defensiveStance(buffs.con:" + s.buffs.con + ")"; - s.buffs.con = 0; - task.value = taskVal; - clearUser(lvl); - shared.content.spells.warrior.valorousPresence.cast(user, party); - str += "\t\t\t| valorousPresence(buffs.str:" + s.buffs.str + ")"; - s.buffs.str = 0; - task.value = taskVal; - clearUser(lvl); - shared.content.spells.warrior.intimidate.cast(user, party); - str += "\t\t| intimidate(buffs.con:" + s.buffs.con + ")"; - s.buffs.con = 0; - console.log(str); - str = '- [Rogue]'; - task.value = taskVal; - clearUser(lvl); - shared.content.spells.rogue.pickPocket.cast(user, task); - str += "\tpickPocket(gp:" + (s.gp.toFixed(1)) + ")"; - task.value = taskVal; - clearUser(lvl); - shared.content.spells.rogue.backStab.cast(user, task); - b4 = { - taskVal: taskVal - }; - str += "\t\t| backStab(task.valΔ:" + ((task.value - b4.taskVal).toFixed(1)) + " exp:" + (s.exp.toFixed(1)) + " gp:" + (s.gp.toFixed(1)) + ")"; - task.value = taskVal; - clearUser(lvl); - shared.content.spells.rogue.toolsOfTrade.cast(user, party); - str += "\t| toolsOfTrade(buffs.per:" + s.buffs.per + ")"; - s.buffs.per = 0; - task.value = taskVal; - clearUser(lvl); - shared.content.spells.rogue.stealth.cast(user, {}); - str += "\t\t| stealth(avoiding " + user.stats.buffs.stealth + " tasks)"; - user.stats.buffs.stealth = 0; - console.log(str); - str = '- [Healer]'; - task.value = taskVal; - clearUser(lvl); - s.hp = 0; - shared.content.spells.healer.heal.cast(user, {}); - str += "\theal(hp:" + (s.hp.toFixed(1)) + ")"; - task.value = taskVal; - clearUser(lvl); - shared.content.spells.healer.brightness.cast(user, {}); - b4 = { - taskVal: taskVal - }; - str += "\t\t\t| brightness(task.valΔ:" + ((task.value - b4.taskVal).toFixed(1)) + ")"; - task.value = taskVal; - clearUser(lvl); - shared.content.spells.healer.protectAura.cast(user, party); - str += "\t\t\t| protectAura(buffs.con:" + s.buffs.con + ")"; - s.buffs.con = 0; - task.value = taskVal; - clearUser(lvl); - s.hp = 0; - shared.content.spells.healer.heallAll.cast(user, party); - str += "\t\t| heallAll(hp:" + (s.hp.toFixed(1)) + ")"; - console.log(str); - return console.log('\n'); - }); - return console.log('------------------------------------------------------------'); -}); - - -/* -_.each [1,25,50,75,100,125], (lvl) -> - console.log "[LEVEL #{lvl}] (#{lvl*2} points in every attr)\n\n" - _.each {red:-25,yellow:0,green:35}, (taskVal, color) -> - console.log "[task.value = #{taskVal} (#{color})]" - console.log "direction\texpΔ\t\thpΔ\tgpΔ\ttask.valΔ\ttask.valΔ bonus\t\tboss-hit" - _.each ['up','down'], (direction) -> - clearUser(lvl) - b4 = {hp:s.hp, taskVal} - task.value = taskVal - task.type = 'daily' if direction is 'up' - delta = user.ops.score params:{id, direction} - console.log "#{if direction is 'up' then '↑' else '↓'}\t\t#{s.exp}/#{shared.tnl(s.lvl)}\t\t#{(b4.hp-s.hp).toFixed(1)}\t#{s.gp.toFixed(1)}\t#{delta.toFixed(1)}\t\t#{(task.value-b4.taskVal-delta).toFixed(1)}\t\t\t#{user.party.quest.progress.up.toFixed(1)}" - - task.value = taskVal;clearUser(lvl) - shared.content.spells.rogue.stealth.cast(user,{}) - console.log "\t\t| stealth(avoiding #{user.stats.buffs.stealth} tasks)" - user.stats.buffs.stealth = 0 - - console.log user.dailys.length - */ diff --git a/test/common_old/user.fns.updateStats.test.js b/test/common_old/user.fns.updateStats.test.js deleted file mode 100644 index fbad57e531..0000000000 --- a/test/common_old/user.fns.updateStats.test.js +++ /dev/null @@ -1,134 +0,0 @@ -import { - generateUser, -} from '../helpers/common.helper'; - -describe('user.fns.updateStats', () => { - let user; - - beforeEach(() => { - user = generateUser({}); - }); - - context('No Hp', () => { - it('returns 0 if user\'s hp is 0', () => { - let stats = { - hp: 0, - }; - - expect(user.fns.updateStats(stats)).to.eql(0); - }); - - it('returns 0 if user\'s hp is less than 0', () => { - let stats = { - hp: -5, - }; - - expect(user.fns.updateStats(stats)).to.eql(0); - }); - - it('sets user\'s hp to 0 if it is less than 0', () => { - let stats = { - hp: -5, - }; - - user.fns.updateStats(stats); - - expect(user.stats.hp).to.eql(0); - }); - }); - - context('Stat Allocation', () => { - it('adds only attribute points up to user\'s level', () => { - let stats = { - exp: 261, - }; - - user.stats.lvl = 10; - - user.fns.updateStats(stats); - - expect(user.stats.points).to.eql(11); - }); - - it('adds an attibute point when user\'s stat points are less than max level', () => { - let stats = { - exp: 3581, - }; - - user.stats.lvl = 99; - user.stats.str = 25; - user.stats.int = 25; - user.stats.con = 25; - user.stats.per = 24; - - user.fns.updateStats(stats); - - expect(user.stats.points).to.eql(1); - }); - - it('does not add an attibute point when user\'s stat points are equal to max level', () => { - let stats = { - exp: 3581, - }; - - user.stats.lvl = 99; - user.stats.str = 25; - user.stats.int = 25; - user.stats.con = 25; - user.stats.per = 25; - - user.fns.updateStats(stats); - - expect(user.stats.points).to.eql(0); - }); - - it('does not add an attibute point when user\'s stat points + unallocated points are equal to max level', () => { - let stats = { - exp: 3581, - }; - - user.stats.lvl = 99; - user.stats.str = 25; - user.stats.int = 25; - user.stats.con = 25; - user.stats.per = 15; - user.stats.points = 10; - - user.fns.updateStats(stats); - - expect(user.stats.points).to.eql(10); - }); - - it('only awards stat points up to level 100 if user is missing unallocated stat points and is over level 100', () => { - let stats = { - exp: 5581, - }; - - user.stats.lvl = 104; - user.stats.str = 25; - user.stats.int = 25; - user.stats.con = 25; - user.stats.per = 15; - user.stats.points = 0; - - user.fns.updateStats(stats); - - expect(user.stats.points).to.eql(10); - }); - - // @TODO: Set up sinon sandbox - xit('auto allocates stats if automaticAllocation is turned on', () => { - sandbox.stub(user.fns, 'autoAllocate'); - - let stats = { - exp: 261, - }; - - user.stats.lvl = 10; - - user.fns.updateStats(stats); - - expect(user.fns.autoAllocate).to.be.calledOnce; - }); - }); -}); diff --git a/test/common_old/user.ops.hourglassPurchase.test.js b/test/common_old/user.ops.hourglassPurchase.test.js deleted file mode 100644 index b9c7369d21..0000000000 --- a/test/common_old/user.ops.hourglassPurchase.test.js +++ /dev/null @@ -1,122 +0,0 @@ -let shared = require('../../common/script/index.js'); - -describe('user.ops.hourglassPurchase', () => { - let user; - - beforeEach(() => { - user = { - items: { - pets: {}, - mounts: {}, - hatchingPotions: {}, - }, - purchased: { - plan: { - consecutive: { - trinkets: 0, - }, - }, - }, - }; - - shared.wrap(user); - }); - - 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', (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', (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', (done) => { - user.purchased.plan.consecutive.trinkets = 1; - user.items.pets = { - 'MantisShrimp-Base': true, - }; - - 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', (done) => { - user.purchased.plan.consecutive.trinkets = 1; - user.items.mounts = { - 'MantisShrimp-Base': true, - }; - - 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', (done) => { - user.purchased.plan.consecutive.trinkets = 1; - - 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', (done) => { - user.purchased.plan.consecutive.trinkets = 1; - - 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(); - }); - }); - }); - - context('successful purchases', () => { - it('buys a pet', (done) => { - user.purchased.plan.consecutive.trinkets = 2; - - 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}); - done(); - }); - }); - - it('buys a mount', (done) => { - user.purchased.plan.consecutive.trinkets = 2; - - 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}); - done(); - }); - }); - }); - }); -}); diff --git a/test/common_old/user.ops.test.js b/test/common_old/user.ops.test.js deleted file mode 100644 index f4e4bb82c9..0000000000 --- a/test/common_old/user.ops.test.js +++ /dev/null @@ -1,34 +0,0 @@ -let shared = require('../../common/script/index.js'); - -describe('user.ops', () => { - let user; - - beforeEach(() => { - user = { - items: { - gear: { }, - special: { }, - }, - achievements: { }, - flags: { }, - }; - - shared.wrap(user); - }); - - 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', () => { - user.items.special.valentineReceived = ['Leslie', 'Vicky']; - user.ops.readCard({ params: { cardType: 'valentine' } }); - - expect(user.items.special.valentineReceived).to.eql(['Vicky']); - }); - }); -}); diff --git a/website/src/controllers/api-v3/groups.js b/website/src/controllers/api-v3/groups.js index 8a8e9eee05..42a6db9cac 100644 --- a/website/src/controllers/api-v3/groups.js +++ b/website/src/controllers/api-v3/groups.js @@ -274,7 +274,7 @@ api.joinGroup = { } } - await Bluebird.all(promises); + promises = await Bluebird.all(promises); let response = Group.toJSONCleanChat(promises[0], user); response.leader = (await User.findById(response.leader).select(nameFields).exec()).toJSON({minimize: true});