mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
v3 adapt v2: lint client only shared ops and enable members integration tests
This commit is contained in:
@@ -1,14 +1,12 @@
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
/*
|
// TODO used only in v2 client
|
||||||
Preen 3-day past-completed To-Dos from Angular & mobile app
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = function(tasks) {
|
module.exports = function preenTodos (tasks) {
|
||||||
return _.filter(tasks, function(t) {
|
return _.filter(tasks, (t) => {
|
||||||
return !t.completed || (t.challenge && t.challenge.id) || moment(t.dateCompleted).isAfter(moment().subtract({
|
return !t.completed || t.challenge && t.challenge.id || moment(t.dateCompleted).isAfter(moment().subtract({
|
||||||
days: 3
|
days: 3,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
import uuid from '../libs/uuid';
|
import uuid from '../libs/uuid';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
// TODO used only in client, move there?
|
// TODO used only in client, move there?
|
||||||
|
|
||||||
module.exports = function(user, req, cb) {
|
module.exports = function addTag (user, req = {}) {
|
||||||
if (user.tags == null) {
|
if (!user.tags) {
|
||||||
user.tags = [];
|
user.tags = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
user.tags.push({
|
user.tags.push({
|
||||||
name: req.body.name,
|
name: req.body.name,
|
||||||
id: req.body.id || uuid()
|
id: _.get(req, 'body.id') || uuid(),
|
||||||
});
|
});
|
||||||
return typeof cb === "function" ? cb(null, user.tags) : void 0;
|
|
||||||
|
return user.tags;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,28 +1,32 @@
|
|||||||
import i18n from '../i18n';
|
import i18n from '../i18n';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { NotFound } from '../libs/errors';
|
||||||
|
|
||||||
// TODO used only in client, move there?
|
// TODO used only in client, move there?
|
||||||
|
|
||||||
module.exports = function(user, req, cb) {
|
module.exports = function deleteTag (user, req = {}) {
|
||||||
var i, tag, tid;
|
let tid = _.get(req, 'params.id');
|
||||||
tid = req.params.id;
|
|
||||||
i = _.findIndex(user.tags, {
|
let index = _.findIndex(user.tags, {
|
||||||
id: tid
|
id: tid,
|
||||||
});
|
});
|
||||||
if (!~i) {
|
|
||||||
return typeof cb === "function" ? cb({
|
if (index === -1) {
|
||||||
code: 404,
|
throw new NotFound(i18n.t('messageTagNotFound', req.language));
|
||||||
message: i18n.t('messageTagNotFound', req.language)
|
|
||||||
}) : void 0;
|
|
||||||
}
|
}
|
||||||
tag = user.tags[i];
|
|
||||||
|
let tag = user.tags[index];
|
||||||
delete user.filters[tag.id];
|
delete user.filters[tag.id];
|
||||||
user.tags.splice(i, 1);
|
|
||||||
_.each(user.tasks, function(task) {
|
user.tags.splice(index, 1);
|
||||||
|
|
||||||
|
_.each(user.tasks, (task) => {
|
||||||
return delete task.tags[tag.id];
|
return delete task.tags[tag.id];
|
||||||
});
|
});
|
||||||
_.each(['habits', 'dailys', 'todos', 'rewards'], function(type) {
|
|
||||||
return typeof user.markModified === "function" ? user.markModified(type) : void 0;
|
_.each(['habits', 'dailys', 'todos', 'rewards'], (type) => {
|
||||||
|
user.markModified(type);
|
||||||
});
|
});
|
||||||
return typeof cb === "function" ? cb(null, user.tags) : void 0;
|
|
||||||
|
return user.tags;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
import i18n from '../i18n';
|
import i18n from '../i18n';
|
||||||
|
import { NotFound } from '../libs/errors';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
// TODO used only in client, move there?
|
// TODO used only in client, move there?
|
||||||
|
|
||||||
module.exports = function(user, req, cb) {
|
module.exports = function deleteTask (user, req = {}) {
|
||||||
var i, ref, task;
|
let tid = _.get(req, 'params.id');
|
||||||
task = user.tasks[(ref = req.params) != null ? ref.id : void 0];
|
let task = user.tasks[tid];
|
||||||
|
|
||||||
if (!task) {
|
if (!task) {
|
||||||
return typeof cb === "function" ? cb({
|
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
|
||||||
code: 404,
|
|
||||||
message: i18n.t('messageTaskNotFound', req.language)
|
|
||||||
}) : void 0;
|
|
||||||
}
|
}
|
||||||
i = user[task.type + "s"].indexOf(task);
|
|
||||||
if (~i) {
|
let index = user[`${task.type}s`].indexOf(task);
|
||||||
user[task.type + "s"].splice(i, 1);
|
if (index !== -1) {
|
||||||
|
user[`${task.type}s`].splice(index, 1);
|
||||||
}
|
}
|
||||||
return typeof cb === "function" ? cb(null, {}) : void 0;
|
|
||||||
|
return {};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import i18n from '../i18n';
|
import i18n from '../i18n';
|
||||||
|
import { NotFound } from '../libs/errors';
|
||||||
|
|
||||||
// TODO used only in client, move there?
|
// TODO used only in client, move there?
|
||||||
|
|
||||||
module.exports = function(user, req, cb) {
|
module.exports = function getTag (user, req = {}) {
|
||||||
var i, tid;
|
let tid = _.get(req, 'params.id');
|
||||||
tid = req.params.id;
|
|
||||||
i = _.findIndex(user.tags, {
|
let index = _.findIndex(user.tags, {
|
||||||
id: tid
|
id: tid,
|
||||||
});
|
});
|
||||||
if (!~i) {
|
if (index === -1) {
|
||||||
return typeof cb === "function" ? cb({
|
throw new NotFound(i18n.t('messageTagNotFound', req.language));
|
||||||
code: 404,
|
|
||||||
message: i18n.t('messageTagNotFound', req.language)
|
|
||||||
}) : void 0;
|
|
||||||
}
|
}
|
||||||
return typeof cb === "function" ? cb(null, user.tags[i]) : void 0;
|
|
||||||
|
return user.tags[index];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// TODO used only in client, move there?
|
// TODO used only in client, move there?
|
||||||
|
|
||||||
module.exports = function(user, req, cb) {
|
module.exports = function getTags (user) {
|
||||||
return typeof cb === "function" ? cb(null, user.tags) : void 0;
|
return user.tags;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
|
import { BadRequest } from '../libs/errors';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
// TODO used only in client, move there?
|
// TODO used only in client, move there?
|
||||||
|
|
||||||
module.exports = function(user, req, cb) {
|
module.exports = function sortTag (user, req = {}) {
|
||||||
var from, ref, to;
|
let to = _.get(req, 'query.to');
|
||||||
ref = req.query, to = ref.to, from = ref.from;
|
let fromParam = _.get(req, 'query.from');
|
||||||
if (!((to != null) && (from != null))) {
|
|
||||||
return typeof cb === "function" ? cb('?to=__&from=__ are required') : void 0;
|
if (!to || !fromParam) {
|
||||||
|
throw new BadRequest('?to=__&from=__ are required');
|
||||||
}
|
}
|
||||||
user.tags.splice(to, 0, user.tags.splice(from, 1)[0]);
|
|
||||||
return typeof cb === "function" ? cb(null, user.tags) : void 0;
|
user.tags.splice(to, 0, user.tags.splice(fromParam, 1)[0]);
|
||||||
|
return user.tags;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,41 +1,50 @@
|
|||||||
import i18n from '../i18n';
|
import i18n from '../i18n';
|
||||||
import preenTodos from '../libs/preenTodos';
|
import preenTodos from '../libs/preenTodos';
|
||||||
|
import {
|
||||||
|
NotFound,
|
||||||
|
BadRequest,
|
||||||
|
} from '../libs/errors';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
// TODO used only in client, move there?
|
// TODO used only in client, move there?
|
||||||
|
|
||||||
module.exports = function(user, req, cb) {
|
module.exports = function sortTag (user, req = {}) {
|
||||||
var from, id, movedTask, preenedTasks, ref, task, tasks, to;
|
let id = _.get(req, 'params.id');
|
||||||
id = req.params.id;
|
let to = _.get(req, 'query.to');
|
||||||
ref = req.query, to = ref.to, from = ref.from;
|
let fromParam = _.get(req, 'query.from');
|
||||||
task = user.tasks[id];
|
|
||||||
|
let task = user.tasks[id];
|
||||||
|
|
||||||
if (!task) {
|
if (!task) {
|
||||||
return typeof cb === "function" ? cb({
|
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
|
||||||
code: 404,
|
|
||||||
message: i18n.t('messageTaskNotFound', req.language)
|
|
||||||
}) : void 0;
|
|
||||||
}
|
}
|
||||||
if (!((to != null) && (from != null))) {
|
if (!to && !fromParam) {
|
||||||
return typeof cb === "function" ? cb('?to=__&from=__ are required') : void 0;
|
throw new BadRequest('?to=__&from=__ are required');
|
||||||
}
|
}
|
||||||
tasks = user[task.type + "s"];
|
|
||||||
if (task.type === 'todo' && tasks[from] !== task) {
|
let tasks = user[`${task.type}s`];
|
||||||
preenedTasks = preenTodos(tasks);
|
|
||||||
|
if (task.type === 'todo' && tasks[fromParam] !== task) {
|
||||||
|
let preenedTasks = preenTodos(tasks);
|
||||||
|
|
||||||
if (to !== -1) {
|
if (to !== -1) {
|
||||||
to = tasks.indexOf(preenedTasks[to]);
|
to = tasks.indexOf(preenedTasks[to]);
|
||||||
}
|
}
|
||||||
from = tasks.indexOf(preenedTasks[from]);
|
|
||||||
|
fromParam = tasks.indexOf(preenedTasks[fromParam]);
|
||||||
}
|
}
|
||||||
if (tasks[from] !== task) {
|
|
||||||
return typeof cb === "function" ? cb({
|
if (tasks[fromParam] !== task) {
|
||||||
code: 404,
|
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
|
||||||
message: i18n.t('messageTaskNotFound', req.language)
|
|
||||||
}) : void 0;
|
|
||||||
}
|
}
|
||||||
movedTask = tasks.splice(from, 1)[0];
|
|
||||||
|
let movedTask = tasks.splice(fromParam, 1)[0];
|
||||||
|
|
||||||
if (to === -1) {
|
if (to === -1) {
|
||||||
tasks.push(movedTask);
|
tasks.push(movedTask);
|
||||||
} else {
|
} else {
|
||||||
tasks.splice(to, 0, movedTask);
|
tasks.splice(to, 0, movedTask);
|
||||||
}
|
}
|
||||||
return typeof cb === "function" ? cb(null, tasks) : void 0;
|
|
||||||
|
return tasks;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
module.exports = function(user, req, cb) {
|
// TODO used only in client, move there?
|
||||||
_.each(req.body, function(v, k) {
|
|
||||||
user.fns.dotSet(k, v);
|
module.exports = function updateUser (user, req = {}) {
|
||||||
return true;
|
_.each(req.body, (val, key) => {
|
||||||
|
_.set(user, key, val);
|
||||||
});
|
});
|
||||||
return typeof cb === "function" ? cb(null, user) : void 0;
|
|
||||||
|
return user;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
import i18n from '../i18n';
|
import i18n from '../i18n';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { NotFound } from '../libs/errors';
|
||||||
|
|
||||||
// TODO used only in client, move there?
|
// TODO used only in client, move there?
|
||||||
|
|
||||||
module.exports = function(user, req, cb) {
|
module.exports = function updateTag (user, req = {}) {
|
||||||
var i, tid;
|
let tid = _.get(req, 'params.id');
|
||||||
tid = req.params.id;
|
|
||||||
i = _.findIndex(user.tags, {
|
let index = _.findIndex(user.tags, {
|
||||||
id: tid
|
id: tid,
|
||||||
});
|
});
|
||||||
if (!~i) {
|
|
||||||
return typeof cb === "function" ? cb({
|
if (index === -1) {
|
||||||
code: 404,
|
throw new NotFound(i18n.t('messageTagNotFound', req.language));
|
||||||
message: i18n.t('messageTagNotFound', req.language)
|
|
||||||
}) : void 0;
|
|
||||||
}
|
}
|
||||||
user.tags[i].name = req.body.name;
|
|
||||||
return typeof cb === "function" ? cb(null, user.tags[i]) : void 0;
|
user.tags[index].name = _.get(req, 'body.name');
|
||||||
|
return user.tags[index];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,16 +11,11 @@ const COMMON_FILES = [
|
|||||||
// @TODO remove these negations as the files are converted over.
|
// @TODO remove these negations as the files are converted over.
|
||||||
'!./common/script/content/index.js',
|
'!./common/script/content/index.js',
|
||||||
'!./common/script/ops/addPushDevice.js',
|
'!./common/script/ops/addPushDevice.js',
|
||||||
'!./common/script/ops/addTag.js',
|
|
||||||
'!./common/script/ops/addWebhook.js',
|
'!./common/script/ops/addWebhook.js',
|
||||||
'!./common/script/ops/blockUser.js',
|
'!./common/script/ops/blockUser.js',
|
||||||
'!./common/script/ops/clearPMs.js',
|
'!./common/script/ops/clearPMs.js',
|
||||||
'!./common/script/ops/deletePM.js',
|
'!./common/script/ops/deletePM.js',
|
||||||
'!./common/script/ops/deleteTag.js',
|
|
||||||
'!./common/script/ops/deleteTask.js',
|
|
||||||
'!./common/script/ops/deleteWebhook.js',
|
'!./common/script/ops/deleteWebhook.js',
|
||||||
'!./common/script/ops/getTag.js',
|
|
||||||
'!./common/script/ops/getTags.js',
|
|
||||||
'!./common/script/ops/rebirth.js',
|
'!./common/script/ops/rebirth.js',
|
||||||
'!./common/script/ops/releaseBoth.js',
|
'!./common/script/ops/releaseBoth.js',
|
||||||
'!./common/script/ops/releaseMounts.js',
|
'!./common/script/ops/releaseMounts.js',
|
||||||
@@ -29,11 +24,8 @@ const COMMON_FILES = [
|
|||||||
'!./common/script/ops/reset.js',
|
'!./common/script/ops/reset.js',
|
||||||
'!./common/script/ops/revive.js',
|
'!./common/script/ops/revive.js',
|
||||||
'!./common/script/ops/sell.js',
|
'!./common/script/ops/sell.js',
|
||||||
'!./common/script/ops/sortTag.js',
|
|
||||||
'!./common/script/ops/sortTask.js',
|
|
||||||
'!./common/script/ops/unlock.js',
|
'!./common/script/ops/unlock.js',
|
||||||
'!./common/script/ops/update.js',
|
'!./common/script/ops/update.js',
|
||||||
'!./common/script/ops/updateTag.js',
|
|
||||||
'!./common/script/ops/updateWebhook.js',
|
'!./common/script/ops/updateWebhook.js',
|
||||||
'!./common/script/fns/crit.js',
|
'!./common/script/fns/crit.js',
|
||||||
'!./common/script/fns/cron.js',
|
'!./common/script/fns/cron.js',
|
||||||
@@ -55,7 +47,6 @@ const COMMON_FILES = [
|
|||||||
'!./common/script/libs/percent.js',
|
'!./common/script/libs/percent.js',
|
||||||
'!./common/script/libs/planGemLimits.js',
|
'!./common/script/libs/planGemLimits.js',
|
||||||
'!./common/script/libs/preenHistory.js',
|
'!./common/script/libs/preenHistory.js',
|
||||||
'!./common/script/libs/preenTodos.js',
|
|
||||||
'!./common/script/libs/removeWhitespace.js',
|
'!./common/script/libs/removeWhitespace.js',
|
||||||
'!./common/script/libs/silver.js',
|
'!./common/script/libs/silver.js',
|
||||||
'!./common/script/libs/splitWhitespace.js',
|
'!./common/script/libs/splitWhitespace.js',
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
} from '../../../helpers/api-integration/v2';
|
} from '../../../helpers/api-integration/v2';
|
||||||
|
|
||||||
xdescribe('POST /members/id/gift', () => {
|
describe('POST /members/id/gift', () => {
|
||||||
let userWithBalance, userWithoutBalance;
|
let userWithBalance, userWithoutBalance;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
} from '../../../helpers/api-integration/v2';
|
} from '../../../helpers/api-integration/v2';
|
||||||
|
|
||||||
xdescribe('POST /members/id/message', () => {
|
describe('POST /members/id/message', () => {
|
||||||
let sender, recipient;
|
let sender, recipient;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user