v3 adapt v2: lint client only shared ops and enable members integration tests

This commit is contained in:
Matteo Pagliazzi
2016-04-07 11:54:36 +02:00
parent d49847688e
commit 2d3fbe9f13
13 changed files with 121 additions and 108 deletions

View File

@@ -1,14 +1,12 @@
import moment from 'moment';
import _ from 'lodash';
/*
Preen 3-day past-completed To-Dos from Angular & mobile app
*/
// TODO used only in v2 client
module.exports = function(tasks) {
return _.filter(tasks, function(t) {
return !t.completed || (t.challenge && t.challenge.id) || moment(t.dateCompleted).isAfter(moment().subtract({
days: 3
module.exports = function preenTodos (tasks) {
return _.filter(tasks, (t) => {
return !t.completed || t.challenge && t.challenge.id || moment(t.dateCompleted).isAfter(moment().subtract({
days: 3,
}));
});
};

View File

@@ -1,14 +1,17 @@
import uuid from '../libs/uuid';
import _ from 'lodash';
// TODO used only in client, move there?
module.exports = function(user, req, cb) {
if (user.tags == null) {
module.exports = function addTag (user, req = {}) {
if (!user.tags) {
user.tags = [];
}
user.tags.push({
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;
};

View File

@@ -1,28 +1,32 @@
import i18n from '../i18n';
import _ from 'lodash';
import { NotFound } from '../libs/errors';
// TODO used only in client, move there?
module.exports = function(user, req, cb) {
var i, tag, tid;
tid = req.params.id;
i = _.findIndex(user.tags, {
id: tid
module.exports = function deleteTag (user, req = {}) {
let tid = _.get(req, 'params.id');
let index = _.findIndex(user.tags, {
id: tid,
});
if (!~i) {
return typeof cb === "function" ? cb({
code: 404,
message: i18n.t('messageTagNotFound', req.language)
}) : void 0;
if (index === -1) {
throw new NotFound(i18n.t('messageTagNotFound', req.language));
}
tag = user.tags[i];
let tag = user.tags[index];
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];
});
_.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;
};

View File

@@ -1,19 +1,21 @@
import i18n from '../i18n';
import { NotFound } from '../libs/errors';
import _ from 'lodash';
// TODO used only in client, move there?
module.exports = function(user, req, cb) {
var i, ref, task;
task = user.tasks[(ref = req.params) != null ? ref.id : void 0];
module.exports = function deleteTask (user, req = {}) {
let tid = _.get(req, 'params.id');
let task = user.tasks[tid];
if (!task) {
return typeof cb === "function" ? cb({
code: 404,
message: i18n.t('messageTaskNotFound', req.language)
}) : void 0;
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
}
i = user[task.type + "s"].indexOf(task);
if (~i) {
user[task.type + "s"].splice(i, 1);
let index = user[`${task.type}s`].indexOf(task);
if (index !== -1) {
user[`${task.type}s`].splice(index, 1);
}
return typeof cb === "function" ? cb(null, {}) : void 0;
return {};
};

View File

@@ -1,19 +1,18 @@
import _ from 'lodash';
import i18n from '../i18n';
import { NotFound } from '../libs/errors';
// TODO used only in client, move there?
module.exports = function(user, req, cb) {
var i, tid;
tid = req.params.id;
i = _.findIndex(user.tags, {
id: tid
module.exports = function getTag (user, req = {}) {
let tid = _.get(req, 'params.id');
let index = _.findIndex(user.tags, {
id: tid,
});
if (!~i) {
return typeof cb === "function" ? cb({
code: 404,
message: i18n.t('messageTagNotFound', req.language)
}) : void 0;
if (index === -1) {
throw new NotFound(i18n.t('messageTagNotFound', req.language));
}
return typeof cb === "function" ? cb(null, user.tags[i]) : void 0;
return user.tags[index];
};

View File

@@ -1,5 +1,5 @@
// TODO used only in client, move there?
module.exports = function(user, req, cb) {
return typeof cb === "function" ? cb(null, user.tags) : void 0;
module.exports = function getTags (user) {
return user.tags;
};

View File

@@ -1,11 +1,16 @@
import { BadRequest } from '../libs/errors';
import _ from 'lodash';
// TODO used only in client, move there?
module.exports = function(user, req, cb) {
var from, ref, to;
ref = req.query, to = ref.to, from = ref.from;
if (!((to != null) && (from != null))) {
return typeof cb === "function" ? cb('?to=__&from=__ are required') : void 0;
module.exports = function sortTag (user, req = {}) {
let to = _.get(req, 'query.to');
let fromParam = _.get(req, 'query.from');
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;
};

View File

@@ -1,41 +1,50 @@
import i18n from '../i18n';
import preenTodos from '../libs/preenTodos';
import {
NotFound,
BadRequest,
} from '../libs/errors';
import _ from 'lodash';
// TODO used only in client, move there?
module.exports = function(user, req, cb) {
var from, id, movedTask, preenedTasks, ref, task, tasks, to;
id = req.params.id;
ref = req.query, to = ref.to, from = ref.from;
task = user.tasks[id];
module.exports = function sortTag (user, req = {}) {
let id = _.get(req, 'params.id');
let to = _.get(req, 'query.to');
let fromParam = _.get(req, 'query.from');
let task = user.tasks[id];
if (!task) {
return typeof cb === "function" ? cb({
code: 404,
message: i18n.t('messageTaskNotFound', req.language)
}) : void 0;
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
}
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');
}
tasks = user[task.type + "s"];
if (task.type === 'todo' && tasks[from] !== task) {
preenedTasks = preenTodos(tasks);
let tasks = user[`${task.type}s`];
if (task.type === 'todo' && tasks[fromParam] !== task) {
let preenedTasks = preenTodos(tasks);
if (to !== -1) {
to = tasks.indexOf(preenedTasks[to]);
}
from = tasks.indexOf(preenedTasks[from]);
fromParam = tasks.indexOf(preenedTasks[fromParam]);
}
if (tasks[from] !== task) {
return typeof cb === "function" ? cb({
code: 404,
message: i18n.t('messageTaskNotFound', req.language)
}) : void 0;
if (tasks[fromParam] !== task) {
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
}
movedTask = tasks.splice(from, 1)[0];
let movedTask = tasks.splice(fromParam, 1)[0];
if (to === -1) {
tasks.push(movedTask);
} else {
tasks.splice(to, 0, movedTask);
}
return typeof cb === "function" ? cb(null, tasks) : void 0;
return tasks;
};

View File

@@ -1,9 +1,11 @@
import _ from 'lodash';
module.exports = function(user, req, cb) {
_.each(req.body, function(v, k) {
user.fns.dotSet(k, v);
return true;
// TODO used only in client, move there?
module.exports = function updateUser (user, req = {}) {
_.each(req.body, (val, key) => {
_.set(user, key, val);
});
return typeof cb === "function" ? cb(null, user) : void 0;
return user;
};

View File

@@ -1,20 +1,20 @@
import i18n from '../i18n';
import _ from 'lodash';
import { NotFound } from '../libs/errors';
// TODO used only in client, move there?
module.exports = function(user, req, cb) {
var i, tid;
tid = req.params.id;
i = _.findIndex(user.tags, {
id: tid
module.exports = function updateTag (user, req = {}) {
let tid = _.get(req, 'params.id');
let index = _.findIndex(user.tags, {
id: tid,
});
if (!~i) {
return typeof cb === "function" ? cb({
code: 404,
message: i18n.t('messageTagNotFound', req.language)
}) : void 0;
if (index === -1) {
throw new NotFound(i18n.t('messageTagNotFound', req.language));
}
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];
};

View File

@@ -11,16 +11,11 @@ const COMMON_FILES = [
// @TODO remove these negations as the files are converted over.
'!./common/script/content/index.js',
'!./common/script/ops/addPushDevice.js',
'!./common/script/ops/addTag.js',
'!./common/script/ops/addWebhook.js',
'!./common/script/ops/blockUser.js',
'!./common/script/ops/clearPMs.js',
'!./common/script/ops/deletePM.js',
'!./common/script/ops/deleteTag.js',
'!./common/script/ops/deleteTask.js',
'!./common/script/ops/deleteWebhook.js',
'!./common/script/ops/getTag.js',
'!./common/script/ops/getTags.js',
'!./common/script/ops/rebirth.js',
'!./common/script/ops/releaseBoth.js',
'!./common/script/ops/releaseMounts.js',
@@ -29,11 +24,8 @@ const COMMON_FILES = [
'!./common/script/ops/reset.js',
'!./common/script/ops/revive.js',
'!./common/script/ops/sell.js',
'!./common/script/ops/sortTag.js',
'!./common/script/ops/sortTask.js',
'!./common/script/ops/unlock.js',
'!./common/script/ops/update.js',
'!./common/script/ops/updateTag.js',
'!./common/script/ops/updateWebhook.js',
'!./common/script/fns/crit.js',
'!./common/script/fns/cron.js',
@@ -55,7 +47,6 @@ const COMMON_FILES = [
'!./common/script/libs/percent.js',
'!./common/script/libs/planGemLimits.js',
'!./common/script/libs/preenHistory.js',
'!./common/script/libs/preenTodos.js',
'!./common/script/libs/removeWhitespace.js',
'!./common/script/libs/silver.js',
'!./common/script/libs/splitWhitespace.js',

View File

@@ -2,7 +2,7 @@ import {
generateUser,
} from '../../../helpers/api-integration/v2';
xdescribe('POST /members/id/gift', () => {
describe('POST /members/id/gift', () => {
let userWithBalance, userWithoutBalance;
beforeEach(async () => {

View File

@@ -2,7 +2,7 @@ import {
generateUser,
} from '../../../helpers/api-integration/v2';
xdescribe('POST /members/id/message', () => {
describe('POST /members/id/message', () => {
let sender, recipient;
beforeEach(async () => {