mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
added tests: if collapseChecklist is allowed and all others are still blocked (#12337)
* tests: test if collapseChecklist is allowed and all others are still blocked * fix lint
This commit is contained in:
@@ -4,8 +4,12 @@ import {
|
|||||||
} from '../../../../../helpers/api-integration/v3';
|
} from '../../../../../helpers/api-integration/v3';
|
||||||
|
|
||||||
describe('PUT /tasks/:id', () => {
|
describe('PUT /tasks/:id', () => {
|
||||||
let user; let guild; let member; let member2; let
|
let user;
|
||||||
task;
|
let guild;
|
||||||
|
let member;
|
||||||
|
let member2;
|
||||||
|
let habit;
|
||||||
|
let todo;
|
||||||
|
|
||||||
function findAssignedTask (memberTask) {
|
function findAssignedTask (memberTask) {
|
||||||
return memberTask.group.id === guild._id;
|
return memberTask.group.id === guild._id;
|
||||||
@@ -25,7 +29,7 @@ describe('PUT /tasks/:id', () => {
|
|||||||
member = members[0]; // eslint-disable-line prefer-destructuring
|
member = members[0]; // eslint-disable-line prefer-destructuring
|
||||||
member2 = members[1]; // eslint-disable-line prefer-destructuring
|
member2 = members[1]; // eslint-disable-line prefer-destructuring
|
||||||
|
|
||||||
task = await user.post(`/tasks/group/${guild._id}`, {
|
habit = await user.post(`/tasks/group/${guild._id}`, {
|
||||||
text: 'test habit',
|
text: 'test habit',
|
||||||
type: 'habit',
|
type: 'habit',
|
||||||
up: false,
|
up: false,
|
||||||
@@ -33,12 +37,18 @@ describe('PUT /tasks/:id', () => {
|
|||||||
notes: 1976,
|
notes: 1976,
|
||||||
});
|
});
|
||||||
|
|
||||||
await user.post(`/tasks/${task._id}/assign/${member._id}`);
|
todo = await user.post(`/tasks/group/${guild._id}`, {
|
||||||
await user.post(`/tasks/${task._id}/assign/${member2._id}`);
|
text: 'test todo',
|
||||||
|
type: 'todo',
|
||||||
|
notes: 1976,
|
||||||
|
});
|
||||||
|
|
||||||
|
await user.post(`/tasks/${habit._id}/assign/${member._id}`);
|
||||||
|
await user.post(`/tasks/${habit._id}/assign/${member2._id}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates a group task', async () => {
|
it('updates a group task', async () => {
|
||||||
const savedHabit = await user.put(`/tasks/${task._id}`, {
|
const savedHabit = await user.put(`/tasks/${habit._id}`, {
|
||||||
notes: 'some new notes',
|
notes: 'some new notes',
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -51,14 +61,14 @@ describe('PUT /tasks/:id', () => {
|
|||||||
managerId: member._id,
|
managerId: member._id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// change the todo
|
// change the habit
|
||||||
task = await member.put(`/tasks/${task._id}`, {
|
habit = await member.put(`/tasks/${habit._id}`, {
|
||||||
text: 'new text!',
|
text: 'new text!',
|
||||||
requiresApproval: true,
|
requiresApproval: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const memberTasks = await member2.get('/tasks/user');
|
const memberTasks = await member2.get('/tasks/user');
|
||||||
const syncedTask = find(memberTasks, memberTask => memberTask.group.taskId === task._id);
|
const syncedTask = find(memberTasks, memberTask => memberTask.group.taskId === habit._id);
|
||||||
|
|
||||||
// score up to trigger approval
|
// score up to trigger approval
|
||||||
await expect(member2.post(`/tasks/${syncedTask._id}/score/up`))
|
await expect(member2.post(`/tasks/${syncedTask._id}/score/up`))
|
||||||
@@ -69,9 +79,39 @@ describe('PUT /tasks/:id', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('member updates a group task value - not allowed', async () => {
|
||||||
|
// change the todo
|
||||||
|
await expect(member.put(`/tasks/${habit._id}`, {
|
||||||
|
text: 'new text!',
|
||||||
|
})).to.eventually.be.rejected.and.to.eql({
|
||||||
|
code: 401,
|
||||||
|
error: 'NotAuthorized',
|
||||||
|
message: t('onlyGroupLeaderCanEditTasks'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('member updates the collapseChecklist property - change is allowed', async () => {
|
||||||
|
// change the todo
|
||||||
|
await member.put(`/tasks/${todo._id}`, {
|
||||||
|
collapseChecklist: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('member updates the collapseChecklist and another property - change not allowed', async () => {
|
||||||
|
// change the todo
|
||||||
|
await expect(member.put(`/tasks/${todo._id}`, {
|
||||||
|
collapseChecklist: true,
|
||||||
|
title: 'test',
|
||||||
|
})).to.eventually.be.rejected.and.to.eql({
|
||||||
|
code: 401,
|
||||||
|
error: 'NotAuthorized',
|
||||||
|
message: t('onlyGroupLeaderCanEditTasks'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('updates a group task with checklist', async () => {
|
it('updates a group task with checklist', async () => {
|
||||||
// add a new todo
|
// add a new todo
|
||||||
task = await user.post(`/tasks/group/${guild._id}`, {
|
habit = await user.post(`/tasks/group/${guild._id}`, {
|
||||||
text: 'todo',
|
text: 'todo',
|
||||||
type: 'todo',
|
type: 'todo',
|
||||||
checklist: [
|
checklist: [
|
||||||
@@ -81,13 +121,13 @@ describe('PUT /tasks/:id', () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
await user.post(`/tasks/${task._id}/assign/${member._id}`);
|
await user.post(`/tasks/${habit._id}/assign/${member._id}`);
|
||||||
|
|
||||||
// change the checklist text
|
// change the checklist text
|
||||||
task = await user.put(`/tasks/${task._id}`, {
|
habit = await user.put(`/tasks/${habit._id}`, {
|
||||||
checklist: [
|
checklist: [
|
||||||
{
|
{
|
||||||
id: task.checklist[0].id,
|
id: habit.checklist[0].id,
|
||||||
text: 'checklist 1 - edit',
|
text: 'checklist 1 - edit',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -96,11 +136,11 @@ describe('PUT /tasks/:id', () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(task.checklist.length).to.eql(2);
|
expect(habit.checklist.length).to.eql(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates the linked tasks', async () => {
|
it('updates the linked tasks', async () => {
|
||||||
await user.put(`/tasks/${task._id}`, {
|
await user.put(`/tasks/${habit._id}`, {
|
||||||
text: 'some new text',
|
text: 'some new text',
|
||||||
up: false,
|
up: false,
|
||||||
down: false,
|
down: false,
|
||||||
@@ -117,7 +157,7 @@ describe('PUT /tasks/:id', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('updates the linked tasks for all assigned users', async () => {
|
it('updates the linked tasks for all assigned users', async () => {
|
||||||
await user.put(`/tasks/${task._id}`, {
|
await user.put(`/tasks/${habit._id}`, {
|
||||||
text: 'some new text',
|
text: 'some new text',
|
||||||
up: false,
|
up: false,
|
||||||
down: false,
|
down: false,
|
||||||
@@ -144,7 +184,7 @@ describe('PUT /tasks/:id', () => {
|
|||||||
managerId: member2._id,
|
managerId: member2._id,
|
||||||
});
|
});
|
||||||
|
|
||||||
await member2.put(`/tasks/${task._id}`, {
|
await member2.put(`/tasks/${habit._id}`, {
|
||||||
text: 'some new text',
|
text: 'some new text',
|
||||||
up: false,
|
up: false,
|
||||||
down: false,
|
down: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user