From 8e3284a4e3edf40b75a4e7aeaf8d79f3aa362ced Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Sun, 13 Mar 2016 22:26:32 +0100 Subject: [PATCH] wip(shared): adapt to v3 --- common/script/.eslintrc | 5 + common/script/content/spells.js | 2 +- common/script/index.js | 196 ++++++++-------- common/script/{api-v3 => libs}/errors.js | 2 +- .../{api-v3 => }/libs/extendableBuiltin.js | 0 common/script/ops/index.js | 4 +- common/script/ops/score.js | 221 ------------------ common/script/{api-v3 => ops}/scoreTask.js | 2 +- package.json | 2 +- tasks/gulp-eslint.js | 3 +- tasks/gulp-tests.js | 10 + .../DELETE-challenges_challengeId.test.js | 3 +- test/api/v3/unit/libs/errors.test.js | 2 +- test/{common => common_old}/algos.mocha.js | 0 test/{common => common_old}/count.js | 0 test/{common => common_old}/dailies.js | 0 .../{common => common_old}/preenTodos.test.js | 0 test/{common => common_old}/preening.test.js | 0 .../shared.spells.test.js | 0 .../simulations/autoAllocate.js | 0 .../simulations/passive_active_attrs.js | 0 .../statHelpers.test.js | 0 test/{common => common_old}/test_helper.js | 0 .../user.fns.buy.test.js | 0 .../user.fns.ultimateGear.test.js | 0 .../user.fns.updateStats.test.js | 0 .../user.ops.buyMysterySet.test.js | 0 .../user.ops.equip.test.js | 0 test/{common => common_old}/user.ops.hatch.js | 0 .../user.ops.hourglassPurchase.test.js | 0 test/{common => common_old}/user.ops.test.js | 0 website/src/controllers/api-v3/tasks.js | 2 +- website/src/libs/api-v3/errors.js | 8 +- website/src/middlewares/api-v3/cron.js | 2 +- 34 files changed, 134 insertions(+), 330 deletions(-) create mode 100644 common/script/.eslintrc rename common/script/{api-v3 => libs}/errors.js (94%) rename common/script/{api-v3 => }/libs/extendableBuiltin.js (100%) delete mode 100644 common/script/ops/score.js rename common/script/{api-v3 => ops}/scoreTask.js (99%) rename test/{common => common_old}/algos.mocha.js (100%) rename test/{common => common_old}/count.js (100%) rename test/{common => common_old}/dailies.js (100%) rename test/{common => common_old}/preenTodos.test.js (100%) rename test/{common => common_old}/preening.test.js (100%) rename test/{common => common_old}/shared.spells.test.js (100%) rename test/{common => common_old}/simulations/autoAllocate.js (100%) rename test/{common => common_old}/simulations/passive_active_attrs.js (100%) rename test/{common => common_old}/statHelpers.test.js (100%) rename test/{common => common_old}/test_helper.js (100%) rename test/{common => common_old}/user.fns.buy.test.js (100%) rename test/{common => common_old}/user.fns.ultimateGear.test.js (100%) rename test/{common => common_old}/user.fns.updateStats.test.js (100%) rename test/{common => common_old}/user.ops.buyMysterySet.test.js (100%) rename test/{common => common_old}/user.ops.equip.test.js (100%) rename test/{common => common_old}/user.ops.hatch.js (100%) rename test/{common => common_old}/user.ops.hourglassPurchase.test.js (100%) rename test/{common => common_old}/user.ops.test.js (100%) diff --git a/common/script/.eslintrc b/common/script/.eslintrc new file mode 100644 index 0000000000..596ff03c45 --- /dev/null +++ b/common/script/.eslintrc @@ -0,0 +1,5 @@ +{ + "globals": { + "window": true, + } +} diff --git a/common/script/content/spells.js b/common/script/content/spells.js index b779e5f56b..41a6571dec 100644 --- a/common/script/content/spells.js +++ b/common/script/content/spells.js @@ -1,6 +1,6 @@ import t from './translation'; import _ from 'lodash'; -import { NotAuthorized } from '../api-v3/errors'; +import { NotAuthorized } from '../libs/errors'; /* --------------------------------------------------------------- Spells diff --git a/common/script/index.js b/common/script/index.js index 27377ae422..3eb3a3371b 100644 --- a/common/script/index.js +++ b/common/script/index.js @@ -1,94 +1,110 @@ -import moment from 'moment'; import _ from 'lodash'; -import { - daysSince, - shouldDo, -} from './cron'; +// When using a common module from the website or the server NEVER import the module directly +// but access it through `api` (the main common) module, otherwise you would require the non transpiled version of the file in production. +let api = module.exports = {}; + +import content from './content/index'; +api.content = content; + +import * as errors from './libs/errors'; +api.errors = errors; +import i18n from './i18n'; +api.i18n = i18n; + +// TODO under api.libs.cron? +import { shouldDo, daysSince } from './cron'; +api.shouldDo = shouldDo; +api.daysSince = daysSince; + +// TODO under api.constants? import { MAX_HEALTH, MAX_LEVEL, MAX_STAT_POINTS, } from './constants'; -import * as statHelpers from './statHelpers'; - -import importedLibs from './libs'; - -var $w, preenHistory, sortOrder, - indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - -import content from './content/index'; -import i18n from './i18n'; - -import * as errors from './api-v3/errors'; -import scoreTask from './api-v3/scoreTask'; - -let api = module.exports = {}; - -// Temporary location of API v3 files (soon to be removed) -api.v3 = { - scoreTask, - errors, -}; - -api.i18n = i18n; -api.shouldDo = shouldDo; - api.maxLevel = MAX_LEVEL; -api.capByLevel = statHelpers.capByLevel; api.maxHealth = MAX_HEALTH; +api.maxStatPoints = MAX_STAT_POINTS; + +// TODO under api.libs.statHelpers? +import * as statHelpers from './statHelpers'; +api.capByLevel = statHelpers.capByLevel; api.tnl = statHelpers.toNextLevel; api.diminishingReturns = statHelpers.diminishingReturns; -$w = api.$w = importedLibs.splitWhitespace; -api.dotSet = importedLibs.dotSet; -api.dotGet = importedLibs.dotGet; -api.refPush = importedLibs.refPush; -api.planGemLimits = importedLibs.planGemLimits; +// TODO under api.libs? +import splitWhitespace from './libs/splitWhitespace'; +const $w = api.$w = splitWhitespace; -preenHistory = importedLibs.preenHistory; +import dotSet from './libs/dotSet'; +api.dotSet = dotSet; -api.preenTodos = importedLibs.preenTodos; -api.updateStore = importedLibs.updateStore; +import dotGet from './libs/dotGet'; +api.dotGet = dotGet; +import refPush from './libs/refPush'; +api.refPush = refPush; -/* ------------------------------------------------------- -Content ------------------------------------------------------- - */ +import planGemLimits from './libs/planGemLimits'; +api.planGemLimits = planGemLimits; -api.content = content; +import preenTodos from './libs/preenTodos'; +api.preenTodos = preenTodos; +import updateStore from './libs/updateStore'; +api.updateStore = updateStore; -/* ------------------------------------------------------- -Misc Helpers ------------------------------------------------------- - */ +import uuid from './libs/uuid'; +api.uuid = uuid; -api.uuid = importedLibs.uuid; -api.countExists = importedLibs.countExists; -api.taskDefaults = importedLibs.taskDefaults; -api.percent = importedLibs.percent; -api.removeWhitespace = importedLibs.removeWhitespace; -api.encodeiCalLink = importedLibs.encodeiCalLink; -api.gold = importedLibs.gold; -api.silver = importedLibs.silver; -api.taskClasses = importedLibs.taskClasses; -api.friendlyTimestamp = importedLibs.friendlyTimestamp; -api.newChatMessages = importedLibs.newChatMessages; -api.noTags = importedLibs.appliedTags; -api.appliedTags = importedLibs.appliedTags; +import countExists from './libs/countExists'; +api.countExists = countExists; +import taskDefaults from './libs/taskDefaults'; +api.taskDefaults = taskDefaults; -/* -Various counting functions - */ +import percent from './libs/percent'; +api.percent = percent; + +import removeWhitespace from './libs/removeWhitespace'; +api.removeWhitespace = removeWhitespace; + +import encodeiCalLink from './libs/encodeiCalLink'; +api.encodeiCalLink = encodeiCalLink; + +import gold from './libs/gold'; +api.gold = gold; + +import silver from './libs/silver'; +api.silver = silver; + +import taskClasses from './libs/taskClasses'; +api.taskClasses = taskClasses; + +import friendlyTimestamp from './libs/friendlyTimestamp'; +api.friendlyTimestamp = friendlyTimestamp; + +import newChatMessages from './libs/newChatMessages'; +api.newChatMessages = newChatMessages; + +import noTags from './libs/noTags'; +api.noTags = noTags; + +import appliedTags from './libs/appliedTags'; +api.appliedTags = appliedTags; import count from './count'; api.count = count; +// TODO As ops and fns are ported, exported them through the api object +import scoreTask from './ops/scoreTask'; + +api.ops = { + scoreTask, +}; +api.fns = {}; + /* ------------------------------------------------------ @@ -130,14 +146,11 @@ TODO import importedOps from './ops'; import importedFns from './fns'; -api.wrap = function(user, main) { - if (main == null) { - main = true; - } - if (user._wrapped) { - return; - } +// TODO redo +api.wrap = function wrapUser (user, main = true) { + if (user._wrapped) return; user._wrapped = true; + if (main) { user.ops = { update: _.partial(importedOps.update, user), @@ -184,9 +197,10 @@ api.wrap = function(user, main) { allocate: _.partial(importedOps.allocate, user), readCard: _.partial(importedOps.readCard, user), openMysteryItem: _.partial(importedOps.openMysteryItem, user), - score: _.partial(importedOps.score, user), + scoreTask: _.partial(importedOps.scoreTask, user), }; } + user.fns = { getItem: _.partial(importedFns.getItem, user), handleTwoHanded: _.partial(importedFns.handleTwoHanded, user), @@ -203,32 +217,30 @@ api.wrap = function(user, main) { ultimateGear: _.partial(importedFns.ultimateGear, user), nullify: _.partial(importedFns.nullify, user), }; + Object.defineProperty(user, '_statsComputed', { - get: function() { - var computed; - computed = _.reduce(['per', 'con', 'str', 'int'], (function(_this) { - return function(m, stat) { - m[stat] = _.reduce($w('stats stats.buffs items.gear.equipped.weapon items.gear.equipped.armor items.gear.equipped.head items.gear.equipped.shield'), function(m2, path) { - var item, val; - val = user.fns.dotGet(path); - return m2 + (~path.indexOf('items.gear') ? (item = content.gear.flat[val], (+(item != null ? item[stat] : void 0) || 0) * ((item != null ? item.klass : void 0) === user.stats["class"] || (item != null ? item.specialClass : void 0) === user.stats["class"] ? 1.5 : 1)) : +val[stat] || 0); - }, 0); - m[stat] += Math.floor(api.capByLevel(user.stats.lvl) / 2); - return m; - }; - })(this), {}); + get () { + let computed = _.reduce(['per', 'con', 'str', 'int'], (m, stat) => { + m[stat] = _.reduce($w('stats stats.buffs items.gear.equipped.weapon items.gear.equipped.armor items.gear.equipped.head items.gear.equipped.shield'), (m2, path) => { + let val = user.fns.dotGet(path); + let item; + return m2 + (path.indexOf('items.gear') !== -1 ? (item = content.gear.flat[val], (Number(!item ? item[stat] : undefined) || 0) * ((!item ? item.klass : undefined) === user.stats.class || (!item ? item.specialClass : undefined) === user.stats.class ? 1.5 : 1)) : Number(val[stat]) || 0); + }, 0); + m[stat] += Math.floor(api.capByLevel(user.stats.lvl) / 2); + return m; + }); + computed.maxMP = computed.int * 2 + 30; return computed; - } + }, }); if (typeof window !== 'undefined') { Object.defineProperty(user, 'tasks', { - get: function() { - var tasks; - tasks = user.habits.concat(user.dailys).concat(user.todos).concat(user.rewards); - return _.object(_.pluck(tasks, "id"), tasks); - } + get () { + let tasks = user.habits.concat(user.dailys).concat(user.todos).concat(user.rewards); + return _.object(_.pluck(tasks, 'id'), tasks); + }, }); } }; diff --git a/common/script/api-v3/errors.js b/common/script/libs/errors.js similarity index 94% rename from common/script/api-v3/errors.js rename to common/script/libs/errors.js index 8c758051ab..0aca2efd1f 100644 --- a/common/script/api-v3/errors.js +++ b/common/script/libs/errors.js @@ -1,4 +1,4 @@ -import extendableBuiltin from './libs/extendableBuiltin'; +import extendableBuiltin from './extendableBuiltin'; // Base class for custom application errors // It extends Error and capture the stack trace diff --git a/common/script/api-v3/libs/extendableBuiltin.js b/common/script/libs/extendableBuiltin.js similarity index 100% rename from common/script/api-v3/libs/extendableBuiltin.js rename to common/script/libs/extendableBuiltin.js diff --git a/common/script/ops/index.js b/common/script/ops/index.js index 1bfd3d55f2..a2775f7d2a 100644 --- a/common/script/ops/index.js +++ b/common/script/ops/index.js @@ -42,7 +42,7 @@ import disableClasses from './disableClasses'; import allocate from './allocate'; import readCard from './readCard'; import openMysteryItem from './openMysteryItem'; -import score from './score'; +import scoreTask from './scoreTask'; module.exports = { update, @@ -89,5 +89,5 @@ module.exports = { allocate, readCard, openMysteryItem, - score, + scoreTask, }; diff --git a/common/script/ops/score.js b/common/script/ops/score.js deleted file mode 100644 index ec0d2a70e2..0000000000 --- a/common/script/ops/score.js +++ /dev/null @@ -1,221 +0,0 @@ -import moment from 'moment'; -import _ from 'lodash'; -import i18n from '../i18n'; - -module.exports = function(user, req, cb) { - var addPoints, calculateDelta, calculateReverseDelta, changeTaskValue, delta, direction, gainMP, id, multiplier, num, options, ref, stats, subtractPoints, task, th; - ref = req.params, id = ref.id, direction = ref.direction; - task = user.tasks[id]; - options = req.query || {}; - _.defaults(options, { - times: 1, - cron: false - }); - user._tmp = {}; - stats = { - gp: +user.stats.gp, - hp: +user.stats.hp, - exp: +user.stats.exp - }; - task.value = +task.value; - task.streak = ~~task.streak; - if (task.priority == null) { - task.priority = 1; - } - if (task.value > stats.gp && task.type === 'reward') { - return typeof cb === "function" ? cb({ - code: 401, - message: i18n.t('messageNotEnoughGold', req.language) - }) : void 0; - } - delta = 0; - calculateDelta = function() { - var currVal, nextDelta, ref1; - currVal = task.value < -47.27 ? -47.27 : task.value > 21.27 ? 21.27 : task.value; - nextDelta = Math.pow(0.9747, currVal) * (direction === 'down' ? -1 : 1); - if (((ref1 = task.checklist) != null ? ref1.length : void 0) > 0) { - if (direction === 'down' && task.type === 'daily' && options.cron) { - nextDelta *= 1 - _.reduce(task.checklist, (function(m, i) { - return m + (i.completed ? 1 : 0); - }), 0) / task.checklist.length; - } - if (task.type === 'todo') { - nextDelta *= 1 + _.reduce(task.checklist, (function(m, i) { - return m + (i.completed ? 1 : 0); - }), 0); - } - } - return nextDelta; - }; - calculateReverseDelta = function() { - var calc, closeEnough, currVal, diff, nextDelta, ref1, testVal; - currVal = task.value < -47.27 ? -47.27 : task.value > 21.27 ? 21.27 : task.value; - testVal = currVal + Math.pow(0.9747, currVal) * (direction === 'down' ? -1 : 1); - closeEnough = 0.00001; - while (true) { - calc = testVal + Math.pow(0.9747, testVal); - diff = currVal - calc; - if (Math.abs(diff) < closeEnough) { - break; - } - if (diff > 0) { - testVal -= diff; - } else { - testVal += diff; - } - } - nextDelta = testVal - currVal; - if (((ref1 = task.checklist) != null ? ref1.length : void 0) > 0) { - if (task.type === 'todo') { - nextDelta *= 1 + _.reduce(task.checklist, (function(m, i) { - return m + (i.completed ? 1 : 0); - }), 0); - } - } - return nextDelta; - }; - changeTaskValue = function() { - return _.times(options.times, function() { - var nextDelta, ref1; - nextDelta = !options.cron && direction === 'down' ? calculateReverseDelta() : calculateDelta(); - if (task.type !== 'reward') { - if (user.preferences.automaticAllocation === true && user.preferences.allocationMode === 'taskbased' && !(task.type === 'todo' && direction === 'down')) { - user.stats.training[task.attribute] += nextDelta; - } - if (direction === 'up') { - user.party.quest.progress.up = user.party.quest.progress.up || 0; - if ((ref1 = task.type) === 'daily' || ref1 === 'todo') { - user.party.quest.progress.up += nextDelta * (1 + (user._statsComputed.str / 200)); - } - if (task.type === 'habit') { - user.party.quest.progress.up += nextDelta * (0.5 + (user._statsComputed.str / 400)); - } - } - task.value += nextDelta; - } - return delta += nextDelta; - }); - }; - addPoints = function() { - var _crit, afterStreak, currStreak, gpMod, intBonus, perBonus, streakBonus; - _crit = (delta > 0 ? user.fns.crit() : 1); - if (_crit > 1) { - user._tmp.crit = _crit; - } - intBonus = 1 + (user._statsComputed.int * .025); - stats.exp += Math.round(delta * intBonus * task.priority * _crit * 6); - perBonus = 1 + user._statsComputed.per * .02; - gpMod = delta * task.priority * _crit * perBonus; - return stats.gp += task.streak ? (currStreak = direction === 'down' ? task.streak - 1 : task.streak, streakBonus = currStreak / 100 + 1, afterStreak = gpMod * streakBonus, currStreak > 0 ? gpMod > 0 ? user._tmp.streakBonus = afterStreak - gpMod : void 0 : void 0, afterStreak) : gpMod; - }; - subtractPoints = function() { - var conBonus, hpMod; - conBonus = 1 - (user._statsComputed.con / 250); - if (conBonus < .1) { - conBonus = 0.1; - } - hpMod = delta * conBonus * task.priority * 2; - return stats.hp += Math.round(hpMod * 10) / 10; - }; - gainMP = function(delta) { - delta *= user._tmp.crit || 1; - user.stats.mp += delta; - if (user.stats.mp >= user._statsComputed.maxMP) { - user.stats.mp = user._statsComputed.maxMP; - } - if (user.stats.mp < 0) { - return user.stats.mp = 0; - } - }; - switch (task.type) { - case 'habit': - changeTaskValue(); - if (delta > 0) { - addPoints(); - } else { - subtractPoints(); - } - gainMP(_.max([0.25, .0025 * user._statsComputed.maxMP]) * (direction === 'down' ? -1 : 1)); - th = (task.history != null ? task.history : task.history = []); - if (th[th.length - 1] && moment(th[th.length - 1].date).isSame(new Date, 'day')) { - th[th.length - 1].value = task.value; - } else { - th.push({ - date: +(new Date), - value: task.value - }); - } - if (typeof user.markModified === "function") { - user.markModified("habits." + (_.findIndex(user.habits, { - id: task.id - })) + ".history"); - } - break; - case 'daily': - if (options.cron) { - changeTaskValue(); - subtractPoints(); - if (!user.stats.buffs.streaks) { - task.streak = 0; - } - } else { - changeTaskValue(); - if (direction === 'down') { - delta = calculateDelta(); - } - addPoints(); - gainMP(_.max([1, .01 * user._statsComputed.maxMP]) * (direction === 'down' ? -1 : 1)); - if (direction === 'up') { - task.streak = task.streak ? task.streak + 1 : 1; - if ((task.streak % 21) === 0) { - user.achievements.streak = user.achievements.streak ? user.achievements.streak + 1 : 1; - } - } else { - if ((task.streak % 21) === 0) { - user.achievements.streak = user.achievements.streak ? user.achievements.streak - 1 : 0; - } - task.streak = task.streak ? task.streak - 1 : 0; - } - } - break; - case 'todo': - if (options.cron) { - changeTaskValue(); - } else { - task.dateCompleted = direction === 'up' ? new Date : void 0; - changeTaskValue(); - if (direction === 'down') { - delta = calculateDelta(); - } - addPoints(); - multiplier = _.max([ - _.reduce(task.checklist, (function(m, i) { - return m + (i.completed ? 1 : 0); - }), 1), 1 - ]); - gainMP(_.max([multiplier, .01 * user._statsComputed.maxMP * multiplier]) * (direction === 'down' ? -1 : 1)); - } - break; - case 'reward': - changeTaskValue(); - stats.gp -= Math.abs(task.value); - num = parseFloat(task.value).toFixed(2); - if (stats.gp < 0) { - stats.hp += stats.gp; - stats.gp = 0; - } - } - user.fns.updateStats(stats, req); - if (typeof window === 'undefined') { - if (direction === 'up') { - user.fns.randomDrop({ - task: task, - delta: delta - }, req); - } - } - if (typeof cb === "function") { - cb(null, user); - } - return delta; -}; diff --git a/common/script/api-v3/scoreTask.js b/common/script/ops/scoreTask.js similarity index 99% rename from common/script/api-v3/scoreTask.js rename to common/script/ops/scoreTask.js index 638e89a6a9..5bb8406fd8 100644 --- a/common/script/api-v3/scoreTask.js +++ b/common/script/ops/scoreTask.js @@ -1,7 +1,7 @@ import _ from 'lodash'; import { NotAuthorized, -} from './errors'; +} from '../libs/errors'; import i18n from '../i18n'; const MAX_TASK_VALUE = 21.27; diff --git a/package.json b/package.json index d5dc0f7986..0dcc4968b4 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "npm": "^3.3.10" }, "scripts": { - "test": "gulp test:api-v3", + "test": "gulp test", "test:api-v2:unit": "mocha test/server_side", "test:api-v2:integration": "mocha test/api/v2 --recursive", "test:api-v3": "gulp test:api-v3", diff --git a/tasks/gulp-eslint.js b/tasks/gulp-eslint.js index 1dcf7fb764..40cc528676 100644 --- a/tasks/gulp-eslint.js +++ b/tasks/gulp-eslint.js @@ -14,7 +14,6 @@ const SERVER_FILES = [ 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/ops/**/*.js', '!./common/script/fns/**/*.js', @@ -25,7 +24,7 @@ const TEST_FILES = [ './test/**/*.js', // @TODO remove these negations as the test files are cleaned up. '!./test/api-legacy/**/*', - '!./test/common/simulations/**/*', + '!./test/common_old/simulations/**/*', '!./test/content/**/*', '!./test/server_side/**/*', '!./test/spec/**/*', diff --git a/tasks/gulp-tests.js b/tasks/gulp-tests.js index a842b0a2b6..a517d5a460 100644 --- a/tasks/gulp-tests.js +++ b/tasks/gulp-tests.js @@ -373,6 +373,16 @@ gulp.task('test:api-v3:integration:separate-server', (done) => { pipe(runner); }); +gulp.task('test', (done) => { + runSequence( + 'lint', + 'test:common', + 'test:api-v3:unit', + 'test:api-v3:integration', + done + ); +}); + gulp.task('test:api-v3', (done) => { runSequence( 'lint', diff --git a/test/api/v3/integration/challenges/DELETE-challenges_challengeId.test.js b/test/api/v3/integration/challenges/DELETE-challenges_challengeId.test.js index e8bd7a66d9..115648d435 100644 --- a/test/api/v3/integration/challenges/DELETE-challenges_challengeId.test.js +++ b/test/api/v3/integration/challenges/DELETE-challenges_challengeId.test.js @@ -9,9 +9,8 @@ import { import { v4 as generateUUID } from 'uuid'; describe('DELETE /challenges/:challengeId', () => { - it('returns error when challengeId is not a valid UUID', async () => { + it.only('returns error when challengeId is not a valid UUID', async () => { let user = await generateUser(); - await expect(user.del(`/challenges/test`)).to.eventually.be.rejected.and.eql({ code: 400, error: 'BadRequest', diff --git a/test/api/v3/unit/libs/errors.test.js b/test/api/v3/unit/libs/errors.test.js index 2a96f05443..d36e1615c7 100644 --- a/test/api/v3/unit/libs/errors.test.js +++ b/test/api/v3/unit/libs/errors.test.js @@ -1,6 +1,6 @@ // TODO move to shared tests -import { CustomError } from '../../../../../common/script/api-v3/errors'; import { + CustomError, NotAuthorized, BadRequest, InternalServerError, diff --git a/test/common/algos.mocha.js b/test/common_old/algos.mocha.js similarity index 100% rename from test/common/algos.mocha.js rename to test/common_old/algos.mocha.js diff --git a/test/common/count.js b/test/common_old/count.js similarity index 100% rename from test/common/count.js rename to test/common_old/count.js diff --git a/test/common/dailies.js b/test/common_old/dailies.js similarity index 100% rename from test/common/dailies.js rename to test/common_old/dailies.js diff --git a/test/common/preenTodos.test.js b/test/common_old/preenTodos.test.js similarity index 100% rename from test/common/preenTodos.test.js rename to test/common_old/preenTodos.test.js diff --git a/test/common/preening.test.js b/test/common_old/preening.test.js similarity index 100% rename from test/common/preening.test.js rename to test/common_old/preening.test.js diff --git a/test/common/shared.spells.test.js b/test/common_old/shared.spells.test.js similarity index 100% rename from test/common/shared.spells.test.js rename to test/common_old/shared.spells.test.js diff --git a/test/common/simulations/autoAllocate.js b/test/common_old/simulations/autoAllocate.js similarity index 100% rename from test/common/simulations/autoAllocate.js rename to test/common_old/simulations/autoAllocate.js diff --git a/test/common/simulations/passive_active_attrs.js b/test/common_old/simulations/passive_active_attrs.js similarity index 100% rename from test/common/simulations/passive_active_attrs.js rename to test/common_old/simulations/passive_active_attrs.js diff --git a/test/common/statHelpers.test.js b/test/common_old/statHelpers.test.js similarity index 100% rename from test/common/statHelpers.test.js rename to test/common_old/statHelpers.test.js diff --git a/test/common/test_helper.js b/test/common_old/test_helper.js similarity index 100% rename from test/common/test_helper.js rename to test/common_old/test_helper.js diff --git a/test/common/user.fns.buy.test.js b/test/common_old/user.fns.buy.test.js similarity index 100% rename from test/common/user.fns.buy.test.js rename to test/common_old/user.fns.buy.test.js diff --git a/test/common/user.fns.ultimateGear.test.js b/test/common_old/user.fns.ultimateGear.test.js similarity index 100% rename from test/common/user.fns.ultimateGear.test.js rename to test/common_old/user.fns.ultimateGear.test.js diff --git a/test/common/user.fns.updateStats.test.js b/test/common_old/user.fns.updateStats.test.js similarity index 100% rename from test/common/user.fns.updateStats.test.js rename to test/common_old/user.fns.updateStats.test.js diff --git a/test/common/user.ops.buyMysterySet.test.js b/test/common_old/user.ops.buyMysterySet.test.js similarity index 100% rename from test/common/user.ops.buyMysterySet.test.js rename to test/common_old/user.ops.buyMysterySet.test.js diff --git a/test/common/user.ops.equip.test.js b/test/common_old/user.ops.equip.test.js similarity index 100% rename from test/common/user.ops.equip.test.js rename to test/common_old/user.ops.equip.test.js diff --git a/test/common/user.ops.hatch.js b/test/common_old/user.ops.hatch.js similarity index 100% rename from test/common/user.ops.hatch.js rename to test/common_old/user.ops.hatch.js diff --git a/test/common/user.ops.hourglassPurchase.test.js b/test/common_old/user.ops.hourglassPurchase.test.js similarity index 100% rename from test/common/user.ops.hourglassPurchase.test.js rename to test/common_old/user.ops.hourglassPurchase.test.js diff --git a/test/common/user.ops.test.js b/test/common_old/user.ops.test.js similarity index 100% rename from test/common/user.ops.test.js rename to test/common_old/user.ops.test.js diff --git a/website/src/controllers/api-v3/tasks.js b/website/src/controllers/api-v3/tasks.js index b78615e448..2218aa2e76 100644 --- a/website/src/controllers/api-v3/tasks.js +++ b/website/src/controllers/api-v3/tasks.js @@ -16,7 +16,7 @@ import _ from 'lodash'; import moment from 'moment'; import { preenHistory } from '../../libs/api-v3/preening'; -const scoreTask = common.v3.scoreTask; +const scoreTask = common.ops.scoreTask; let api = {}; diff --git a/website/src/libs/api-v3/errors.js b/website/src/libs/api-v3/errors.js index 10c87befdb..0667dafcd9 100644 --- a/website/src/libs/api-v3/errors.js +++ b/website/src/libs/api-v3/errors.js @@ -1,6 +1,6 @@ import common from '../../../../common/script'; -export const CustomError = common.v3.errors.CustomError; +export const CustomError = common.errors.CustomError; /** * @apiDefine NotAuthorized @@ -13,7 +13,7 @@ export const CustomError = common.v3.errors.CustomError; * "message": "Not authorized." * } */ -export const NotAuthorized = common.v3.errors.NotAuthorized; +export const NotAuthorized = common.errors.NotAuthorized; /** * @apiDefine BadRequest @@ -26,7 +26,7 @@ export const NotAuthorized = common.v3.errors.NotAuthorized; * "message": "Bad request." * } */ -export const BadRequest = common.v3.errors.BadRequest; +export const BadRequest = common.errors.BadRequest; /** * @apiDefine NotFound @@ -39,7 +39,7 @@ export const BadRequest = common.v3.errors.BadRequest; * "message": "Not found." * } */ -export const NotFound = common.v3.errors.NotFound; +export const NotFound = common.errors.NotFound; /** * @apiDefine InternalServerError diff --git a/website/src/middlewares/api-v3/cron.js b/website/src/middlewares/api-v3/cron.js index fecd6b05db..a70dd534a1 100644 --- a/website/src/middlewares/api-v3/cron.js +++ b/website/src/middlewares/api-v3/cron.js @@ -11,7 +11,7 @@ import Group from '../../models/group'; import User from '../../models/user'; import { preenUserHistory } from '../../libs/api-v3/preening'; -const scoreTask = common.v3.scoreTask; +const scoreTask = common.ops.scoreTask; let clearBuffs = { str: 0,