mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +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,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import { find } from 'lodash';
|
||||
import {
|
||||
find,
|
||||
each,
|
||||
map,
|
||||
} from 'lodash';
|
||||
import Q from 'q';
|
||||
|
||||
describe('DELETE /user', () => {
|
||||
let user;
|
||||
@@ -38,6 +43,24 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
|
||||
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', {
|
||||
password,
|
||||
});
|
||||
|
||||
@@ -399,6 +399,7 @@ api.scoreTask = {
|
||||
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
|
||||
// TODO move to common code?
|
||||
if (task.type === 'todo') {
|
||||
if (!wasCompleted && task.completed) {
|
||||
removeFromArray(user.tasksOrder.todos, task._id);
|
||||
@@ -406,9 +407,7 @@ api.scoreTask = {
|
||||
let hasTask = removeFromArray(user.tasksOrder.todos, task._id);
|
||||
if (!hasTask) {
|
||||
user.tasksOrder.todos.push(task._id); // TODO push at the top?
|
||||
} else { // If for some reason it hadn't been removed TODO ok?
|
||||
user.tasksOrder.push(task._id);
|
||||
}
|
||||
} // If for some reason it hadn't been removed previously don't do anything TODO ok?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -219,6 +219,10 @@ api.deleteUser = {
|
||||
|
||||
await Q.all(groupLeavePromises);
|
||||
|
||||
await Tasks.Task.remove({
|
||||
userId: user._id,
|
||||
}).exec();
|
||||
|
||||
await user.remove();
|
||||
|
||||
res.respond(200, {});
|
||||
|
||||
@@ -508,7 +508,6 @@ export let schema = new Schema({
|
||||
habits: [{type: String, ref: 'Task'}],
|
||||
dailys: [{type: String, ref: 'Task'}],
|
||||
todos: [{type: String, ref: 'Task'}],
|
||||
completedTodos: [{type: String, ref: 'Task'}],
|
||||
rewards: [{type: String, ref: 'Task'}],
|
||||
},
|
||||
extra: {type: Schema.Types.Mixed, default: () => {
|
||||
|
||||
Reference in New Issue
Block a user