Skip to content

Commit d87cf8d

Browse files
skv93-coderShubham Sharmaprakashchoudhary07Achintya-Chatterjeeiamitprakash
authored
Enables task status verified and merged (#1937)
* Remove condition for updating task for verified task status and percent bar completion condition * Updated response msg --------- Co-authored-by: Shubham Sharma <[email protected]> Co-authored-by: Prakash Choudhary <[email protected]> Co-authored-by: Achintya Chatterjee <[email protected]> Co-authored-by: Amit Prakash <[email protected]>
1 parent 124a627 commit d87cf8d

File tree

2 files changed

+24
-58
lines changed

2 files changed

+24
-58
lines changed

controllers/tasks.js

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -328,41 +328,32 @@ const updateTaskStatus = async (req, res, next) => {
328328

329329
if (task.taskNotFound) return res.boom.notFound("Task doesn't exist");
330330
if (task.notAssignedToYou) return res.boom.forbidden("This task is not assigned to you");
331-
if (
332-
task.taskData.status === TASK_STATUS.VERIFIED ||
333-
status === TASK_STATUS.MERGED ||
334-
status === TASK_STATUS.BACKLOG
335-
)
331+
if (TASK_STATUS.BACKLOG === status) {
336332
return res.boom.forbidden("Status cannot be updated. Please contact admin.");
337-
333+
}
338334
if (userStatusFlag) {
339-
if (task.taskData.status === TASK_STATUS.DONE && req.body.percentCompleted < 100) {
340-
if (status === TASK_STATUS.DONE || !status) {
341-
return res.boom.badRequest("Task percentCompleted can't updated as status is DONE");
335+
if (task.taskData.status === TASK_STATUS.DONE) {
336+
return res.boom.forbidden("Status cannot be updated. Please contact admin.");
337+
}
338+
} else {
339+
if (task.taskData.status === TASK_STATUS.VERIFIED || TASK_STATUS.MERGED === status) {
340+
return res.boom.forbidden("Status cannot be updated. Please contact admin.");
341+
}
342+
if (task.taskData.status === TASK_STATUS.COMPLETED && req.body.percentCompleted < 100) {
343+
if (status === TASK_STATUS.COMPLETED || !status) {
344+
return res.boom.badRequest("Task percentCompleted can't updated as status is COMPLETED");
342345
}
343346
}
344-
345-
if ((status === TASK_STATUS.DONE || status === TASK_STATUS.VERIFIED) && task.taskData.percentCompleted !== 100) {
347+
if (
348+
(status === TASK_STATUS.COMPLETED || status === TASK_STATUS.VERIFIED) &&
349+
task.taskData.percentCompleted !== 100
350+
) {
346351
if (req.body.percentCompleted !== 100) {
347-
return res.boom.badRequest("Status cannot be updated. Task is not done yet");
352+
return res.boom.badRequest("Status cannot be updated as progress of task is not 100%.");
348353
}
349354
}
350355
}
351356

352-
if (task.taskData.status === TASK_STATUS.COMPLETED && req.body.percentCompleted < 100) {
353-
if (status === TASK_STATUS.COMPLETED || !status) {
354-
return res.boom.badRequest("Task percentCompleted can't updated as status is COMPLETED");
355-
}
356-
}
357-
if (
358-
(status === TASK_STATUS.COMPLETED || status === TASK_STATUS.VERIFIED) &&
359-
task.taskData.percentCompleted !== 100
360-
) {
361-
if (req.body.percentCompleted !== 100) {
362-
return res.boom.badRequest("Status cannot be updated. Task is not completed yet");
363-
}
364-
}
365-
366357
const taskLog = {
367358
type: "task",
368359
meta: {

test/integration/tasks.test.js

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const tasksData = require("../fixtures/tasks/tasks")();
1818
const { DINERO, NEELAM } = require("../../constants/wallets");
1919
const cleanDb = require("../utils/cleanDb");
2020
const { TASK_STATUS, tasksUsersStatus } = require("../../constants/tasks");
21-
const updateTaskStatus = require("../fixtures/tasks/tasks1")();
2221
const userStatusData = require("../fixtures/userStatus/userStatus");
2322
const tasksModel = firestore.collection("tasks");
2423
const discordService = require("../../services/discordService");
@@ -1121,19 +1120,19 @@ describe("Tasks", function () {
11211120
.send({ ...taskStatusData, status: "COMPLETED" });
11221121

11231122
expect(res).to.have.status(400);
1124-
expect(res.body.message).to.be.equal("Status cannot be updated. Task is not completed yet");
1123+
expect(res.body.message).to.be.equal("Status cannot be updated as progress of task is not 100%.");
11251124
});
11261125

1127-
it("Should give 400 if percentCompleted is not 100 and new status is DONE under feature flag ", async function () {
1128-
taskId = (await tasks.updateTask({ ...taskData, status: "REVIEW", assignee: appOwner.username })).taskId;
1126+
it("Should give 403 if current task status is DONE", async function () {
1127+
taskId = (await tasks.updateTask({ ...taskData, status: "DONE", assignee: appOwner.username })).taskId;
11291128
const res = await chai
11301129
.request(app)
11311130
.patch(`/tasks/self/${taskId}?userStatusFlag=true`)
11321131
.set("cookie", `${cookieName}=${jwt}`)
1133-
.send({ ...taskStatusData, status: "DONE" });
1132+
.send({ ...taskStatusData, status: "IN_REVIEW" });
11341133

1135-
expect(res).to.have.status(400);
1136-
expect(res.body.message).to.be.equal("Status cannot be updated. Task is not done yet");
1134+
expect(res.body.message).to.be.equal("Status cannot be updated. Please contact admin.");
1135+
expect(res).to.have.status(403);
11371136
});
11381137

11391138
it("Should give 400 if percentCompleted is not 100 and new status is VERIFIED ", async function () {
@@ -1145,19 +1144,7 @@ describe("Tasks", function () {
11451144
.send({ ...taskStatusData, status: "VERIFIED" });
11461145

11471146
expect(res).to.have.status(400);
1148-
expect(res.body.message).to.be.equal("Status cannot be updated. Task is not completed yet");
1149-
});
1150-
1151-
it("Should give 400 if percentCompleted is not 100 and new status is VERIFIED under feature flag", async function () {
1152-
taskId = (await tasks.updateTask({ ...taskData, status: "REVIEW", assignee: appOwner.username })).taskId;
1153-
const res = await chai
1154-
.request(app)
1155-
.patch(`/tasks/self/${taskId}?userStatusFlag=true`)
1156-
.set("cookie", `${cookieName}=${jwt}`)
1157-
.send({ ...taskStatusData, status: "VERIFIED" });
1158-
1159-
expect(res).to.have.status(400);
1160-
expect(res.body.message).to.be.equal("Status cannot be updated. Task is not done yet");
1147+
expect(res.body.message).to.be.equal("Status cannot be updated as progress of task is not 100%.");
11611148
});
11621149

11631150
it("Should give 400 if status is COMPLETED and newpercent is less than 100", async function () {
@@ -1184,18 +1171,6 @@ describe("Tasks", function () {
11841171
expect(res).to.have.status(400);
11851172
expect(res.body.message).to.be.equal("Task percentCompleted can't updated as status is COMPLETED");
11861173
});
1187-
1188-
it("Should give 400 if status is DONE and newpercent is less than 100 under feature flag", async function () {
1189-
taskId = (await tasks.updateTask(updateTaskStatus[0])).taskId;
1190-
const res = await chai
1191-
.request(app)
1192-
.patch(`/tasks/self/${taskId}?userStatusFlag=true`)
1193-
.set("cookie", `${cookieName}=${jwt}`)
1194-
.send({ percentCompleted: 80 });
1195-
1196-
expect(res).to.have.status(400);
1197-
expect(res.body.message).to.be.equal("Task percentCompleted can't updated as status is DONE");
1198-
});
11991174
});
12001175

12011176
describe("GET /tasks/overdue", function () {

0 commit comments

Comments
 (0)