mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
add new files for clearCompletedTodos functionality
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
import {
|
||||||
|
generateUser,
|
||||||
|
generateGroup,
|
||||||
|
generateChallenge,
|
||||||
|
} from '../../../../helpers/api-integration/v3';
|
||||||
|
|
||||||
|
describe('POST /tasks/clearCompletedTodos', () => {
|
||||||
|
it('deletes all completed todos except the ones from a challenge', async () => {
|
||||||
|
let user = await generateUser({balance: 1});
|
||||||
|
let guild = await generateGroup(user);
|
||||||
|
let challenge = await generateChallenge(user, guild);
|
||||||
|
|
||||||
|
let initialTodoCount = user.tasksOrder.todos.length;
|
||||||
|
await user.post('/tasks/user', [
|
||||||
|
{text: 'todo 1', type: 'todo'},
|
||||||
|
{text: 'todo 2', type: 'todo'},
|
||||||
|
{text: 'todo 3', type: 'todo'},
|
||||||
|
{text: 'todo 4', type: 'todo'},
|
||||||
|
{text: 'todo 5', type: 'todo'},
|
||||||
|
]);
|
||||||
|
|
||||||
|
await user.post(`/tasks/challenge/${challenge._id}`, {
|
||||||
|
text: 'todo 6',
|
||||||
|
type: 'todo',
|
||||||
|
});
|
||||||
|
|
||||||
|
let tasks = await user.get('/tasks/user?type=todo');
|
||||||
|
expect(tasks.length).to.equal(initialTodoCount + 6);
|
||||||
|
|
||||||
|
for (let task of tasks) {
|
||||||
|
if (['todo 2', 'todo 3', 'todo 6'].indexOf(task.text) !== -1) {
|
||||||
|
await user.post(`/tasks/${task._id}/score/up`); // eslint-disable-line babel/no-await-in-loop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await user.post('/tasks/clearCompletedTodos');
|
||||||
|
let tasksUpdated = await user.get('/tasks/user?type=todo&includeCompletedTodos=true');
|
||||||
|
expect(tasksUpdated.length).to.equal(initialTodoCount + 4); // + 6 - 3 completed (but one is from challenge)
|
||||||
|
expect(tasksUpdated[tasksUpdated.length - 1].text).to.equal('todo 6');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user