mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
v3: check that tasks are deleted when the user deletes the acocunt and misc fixes
This commit is contained in:
@@ -5,7 +5,12 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../../helpers/api-integration/v3';
|
} from '../../../../helpers/api-integration/v3';
|
||||||
import { find } from 'lodash';
|
import {
|
||||||
|
find,
|
||||||
|
each,
|
||||||
|
map,
|
||||||
|
} from 'lodash';
|
||||||
|
import Q from 'q';
|
||||||
|
|
||||||
describe('DELETE /user', () => {
|
describe('DELETE /user', () => {
|
||||||
let user;
|
let user;
|
||||||
@@ -38,6 +43,24 @@ describe('DELETE /user', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('deletes the user', async () => {
|
it('deletes the user', async () => {
|
||||||
|
// gets the user's tasks ids
|
||||||
|
let ids = [];
|
||||||
|
each(user.tasksOrder, (idsForOrder) => {
|
||||||
|
ids.push(...idsForOrder);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(ids.length).to.be.above(0); // make sure the user has some task to delete
|
||||||
|
|
||||||
|
await user.del('/user', {
|
||||||
|
password,
|
||||||
|
});
|
||||||
|
|
||||||
|
await Q.all(map(ids, id => {
|
||||||
|
return expect(checkExistence('tasks', id)).to.eventually.eql(false);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('delete the user\'s tasks', async () => {
|
||||||
await user.del('/user', {
|
await user.del('/user', {
|
||||||
password,
|
password,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -399,6 +399,7 @@ api.scoreTask = {
|
|||||||
if (direction === 'up') user.fns.randomDrop({task, delta}, req);
|
if (direction === 'up') user.fns.randomDrop({task, delta}, req);
|
||||||
|
|
||||||
// If a todo was completed or uncompleted move it in or out of the user.tasksOrder.todos list
|
// If a todo was completed or uncompleted move it in or out of the user.tasksOrder.todos list
|
||||||
|
// TODO move to common code?
|
||||||
if (task.type === 'todo') {
|
if (task.type === 'todo') {
|
||||||
if (!wasCompleted && task.completed) {
|
if (!wasCompleted && task.completed) {
|
||||||
removeFromArray(user.tasksOrder.todos, task._id);
|
removeFromArray(user.tasksOrder.todos, task._id);
|
||||||
@@ -406,9 +407,7 @@ api.scoreTask = {
|
|||||||
let hasTask = removeFromArray(user.tasksOrder.todos, task._id);
|
let hasTask = removeFromArray(user.tasksOrder.todos, task._id);
|
||||||
if (!hasTask) {
|
if (!hasTask) {
|
||||||
user.tasksOrder.todos.push(task._id); // TODO push at the top?
|
user.tasksOrder.todos.push(task._id); // TODO push at the top?
|
||||||
} else { // If for some reason it hadn't been removed TODO ok?
|
} // If for some reason it hadn't been removed previously don't do anything TODO ok?
|
||||||
user.tasksOrder.push(task._id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -219,6 +219,10 @@ api.deleteUser = {
|
|||||||
|
|
||||||
await Q.all(groupLeavePromises);
|
await Q.all(groupLeavePromises);
|
||||||
|
|
||||||
|
await Tasks.Task.remove({
|
||||||
|
userId: user._id,
|
||||||
|
}).exec();
|
||||||
|
|
||||||
await user.remove();
|
await user.remove();
|
||||||
|
|
||||||
res.respond(200, {});
|
res.respond(200, {});
|
||||||
|
|||||||
@@ -508,7 +508,6 @@ export let schema = new Schema({
|
|||||||
habits: [{type: String, ref: 'Task'}],
|
habits: [{type: String, ref: 'Task'}],
|
||||||
dailys: [{type: String, ref: 'Task'}],
|
dailys: [{type: String, ref: 'Task'}],
|
||||||
todos: [{type: String, ref: 'Task'}],
|
todos: [{type: String, ref: 'Task'}],
|
||||||
completedTodos: [{type: String, ref: 'Task'}],
|
|
||||||
rewards: [{type: String, ref: 'Task'}],
|
rewards: [{type: String, ref: 'Task'}],
|
||||||
},
|
},
|
||||||
extra: {type: Schema.Types.Mixed, default: () => {
|
extra: {type: Schema.Types.Mixed, default: () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user