Skip to content

Commit de08ced

Browse files
skv93-coderShubham Sharmaiamitprakash
authored
Modified task status flow (#1968)
* Added msg on for user for not allowed task status change * Added test cases for task flow changes * Added spacing in test file * Removed switch case block * Minor text fix * Added correct res msg in test * again added feature flag for new dev * Removed no longer required test case --------- Co-authored-by: Shubham Sharma <[email protected]> Co-authored-by: Amit Prakash <[email protected]>
1 parent d87cf8d commit de08ced

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

controllers/tasks.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,35 @@ const updateTaskStatus = async (req, res, next) => {
335335
if (task.taskData.status === TASK_STATUS.DONE) {
336336
return res.boom.forbidden("Status cannot be updated. Please contact admin.");
337337
}
338+
if (status) {
339+
const isCurrentTaskStatusInProgress = task.taskData.status === TASK_STATUS.IN_PROGRESS;
340+
const isCurrentTaskStatusBlock = task.taskData.status === TASK_STATUS.BLOCKED;
341+
const isNewTaskStatusInProgress = status === TASK_STATUS.IN_PROGRESS;
342+
const isNewTaskStatusBlock = status === TASK_STATUS.BLOCKED;
343+
const isCurrProgress100 = parseInt(task.taskData.percentCompleted || 0) === 100;
344+
const isCurrProgress0 = parseInt(task.taskData.percentCompleted || 0) === 0;
345+
const isNewProgress100 = !!req.body.percentCompleted && parseInt(req.body.percentCompleted) === 100;
346+
const isNewProgress0 = !!req.body.percentCompleted !== undefined && parseInt(req.body.percentCompleted) === 0;
347+
348+
if (
349+
!isCurrProgress100 &&
350+
!isNewProgress100 &&
351+
(isCurrentTaskStatusBlock || isCurrentTaskStatusInProgress) &&
352+
!isNewTaskStatusBlock &&
353+
!isNewTaskStatusInProgress
354+
) {
355+
return res.boom.badRequest(
356+
`The status of task can not be changed from ${
357+
isCurrentTaskStatusInProgress ? "In progress" : "Blocked"
358+
} until progress of task is not 100%.`
359+
);
360+
}
361+
if (isNewTaskStatusInProgress && !isCurrentTaskStatusBlock && !isCurrProgress0 && !isNewProgress0) {
362+
return res.boom.badRequest(
363+
"The status of task can not be changed to In progress until progress of task is not 0%."
364+
);
365+
}
366+
}
338367
} else {
339368
if (task.taskData.status === TASK_STATUS.VERIFIED || TASK_STATUS.MERGED === status) {
340369
return res.boom.forbidden("Status cannot be updated. Please contact admin.");

test/integration/tasks.test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ 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")();
2122
const userStatusData = require("../fixtures/userStatus/userStatus");
2223
const tasksModel = firestore.collection("tasks");
2324
const discordService = require("../../services/discordService");
@@ -1171,6 +1172,77 @@ describe("Tasks", function () {
11711172
expect(res).to.have.status(400);
11721173
expect(res.body.message).to.be.equal("Task percentCompleted can't updated as status is COMPLETED");
11731174
});
1175+
1176+
it("Should give 400 if current status of task is In Progress and new status is not Blocked and both current and new percentCompleted are not 100 ", async function () {
1177+
const newDate = { ...updateTaskStatus[0], status: "IN_PROGRESS", percentCompleted: 80 };
1178+
taskId = (await tasks.updateTask(newDate)).taskId;
1179+
const res = await chai
1180+
.request(app)
1181+
.patch(`/tasks/self/${taskId}?userStatusFlag=true`)
1182+
.set("cookie", `${cookieName}=${jwt}`)
1183+
.send({ status: "NEEDS_REVIEW" });
1184+
1185+
expect(res).to.have.status(400);
1186+
expect(res.body.message).to.be.equal(
1187+
"The status of task can not be changed from In progress until progress of task is not 100%."
1188+
);
1189+
});
1190+
1191+
it("Should give 400 if new status of task is In Progress and current status of task is not Blocked and both current and new percentCompleted are not 0 ", async function () {
1192+
const newDate = { ...updateTaskStatus[0], status: "NEEDS_REVIEW", percentCompleted: 100 };
1193+
taskId = (await tasks.updateTask(newDate)).taskId;
1194+
const res = await chai
1195+
.request(app)
1196+
.patch(`/tasks/self/${taskId}?userStatusFlag=true`)
1197+
.set("cookie", `${cookieName}=${jwt}`)
1198+
.send({ status: "IN_PROGRESS" });
1199+
1200+
expect(res).to.have.status(400);
1201+
expect(res.body.message).to.be.equal(
1202+
"The status of task can not be changed to In progress until progress of task is not 0%."
1203+
);
1204+
});
1205+
1206+
it("Should give 400 if current status of task is Blocked and new status is not In Progress and both current and new percentCompleted are not 100 ", async function () {
1207+
const newDate = { ...updateTaskStatus[0], status: "BLOCKED", percentCompleted: 52 };
1208+
taskId = (await tasks.updateTask(newDate)).taskId;
1209+
const res = await chai
1210+
.request(app)
1211+
.patch(`/tasks/self/${taskId}?userStatusFlag=true`)
1212+
.set("cookie", `${cookieName}=${jwt}`)
1213+
.send({ status: "NEEDS_REVIEW" });
1214+
1215+
expect(res).to.have.status(400);
1216+
expect(res.body.message).to.be.equal(
1217+
"The status of task can not be changed from Blocked until progress of task is not 100%."
1218+
);
1219+
});
1220+
1221+
it("Should give 200 if new status of task is In Progress and current status of task is Blocked", async function () {
1222+
const newDate = { ...updateTaskStatus[0], status: "BLOCKED", percentCompleted: 56 };
1223+
taskId = (await tasks.updateTask(newDate)).taskId;
1224+
const res = await chai
1225+
.request(app)
1226+
.patch(`/tasks/self/${taskId}?userStatusFlag=true`)
1227+
.set("cookie", `${cookieName}=${jwt}`)
1228+
.send({ status: "IN_PROGRESS" });
1229+
1230+
expect(res).to.have.status(200);
1231+
expect(res.body.message).to.be.equal("Task updated successfully!");
1232+
});
1233+
1234+
it("Should give 200 if new status of task is Blocked and current status of task is In Progress", async function () {
1235+
const newDate = { ...updateTaskStatus[0], status: "IN_PROGRESS", percentCompleted: 59 };
1236+
taskId = (await tasks.updateTask(newDate)).taskId;
1237+
const res = await chai
1238+
.request(app)
1239+
.patch(`/tasks/self/${taskId}?userStatusFlag=true`)
1240+
.set("cookie", `${cookieName}=${jwt}`)
1241+
.send({ status: "BLOCKED" });
1242+
1243+
expect(res).to.have.status(200);
1244+
expect(res.body.message).to.be.equal("Task updated successfully!");
1245+
});
11741246
});
11751247

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

0 commit comments

Comments
 (0)