Skip to content

Commit 72c9f26

Browse files
Revert "remove feature flag (#1703)" (#1716)
This reverts commit 6d31b55. Co-authored-by: Prakash Choudhary <[email protected]>
1 parent 0a663a2 commit 72c9f26

File tree

2 files changed

+74
-8
lines changed

2 files changed

+74
-8
lines changed

controllers/tasks.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ const updateTaskStatus = async (req, res, next) => {
317317
req.body.updatedAt = Math.round(new Date().getTime() / 1000);
318318
let userStatusUpdate;
319319
const taskId = req.params.id;
320+
const { userStatusFlag } = req.query;
320321
const { id: userId, username } = req.userData;
321322
const task = await tasks.fetchSelfTask(taskId, userId);
322323

@@ -325,18 +326,34 @@ const updateTaskStatus = async (req, res, next) => {
325326
if (task.taskData.status === TASK_STATUS.VERIFIED || req.body.status === TASK_STATUS.MERGED)
326327
return res.boom.forbidden("Status cannot be updated. Please contact admin.");
327328

328-
if (task.taskData.status === TASK_STATUS.DONE && req.body.percentCompleted < 100) {
329-
if (req.body.status === TASK_STATUS.DONE || !req.body.status) {
330-
return res.boom.badRequest("Task percentCompleted can't updated as status is DONE");
329+
if (userStatusFlag) {
330+
if (task.taskData.status === TASK_STATUS.DONE && req.body.percentCompleted < 100) {
331+
if (req.body.status === TASK_STATUS.DONE || !req.body.status) {
332+
return res.boom.badRequest("Task percentCompleted can't updated as status is DONE");
333+
}
334+
}
335+
336+
if (
337+
(req.body.status === TASK_STATUS.DONE || req.body.status === TASK_STATUS.VERIFIED) &&
338+
task.taskData.percentCompleted !== 100
339+
) {
340+
if (req.body.percentCompleted !== 100) {
341+
return res.boom.badRequest("Status cannot be updated. Task is not done yet");
342+
}
331343
}
332344
}
333345

346+
if (task.taskData.status === TASK_STATUS.COMPLETED && req.body.percentCompleted < 100) {
347+
if (req.body.status === TASK_STATUS.COMPLETED || !req.body.status) {
348+
return res.boom.badRequest("Task percentCompleted can't updated as status is COMPLETED");
349+
}
350+
}
334351
if (
335-
(req.body.status === TASK_STATUS.DONE || req.body.status === TASK_STATUS.VERIFIED) &&
352+
(req.body.status === TASK_STATUS.COMPLETED || req.body.status === TASK_STATUS.VERIFIED) &&
336353
task.taskData.percentCompleted !== 100
337354
) {
338355
if (req.body.percentCompleted !== 100) {
339-
return res.boom.badRequest("Status cannot be updated. Task is not done yet");
356+
return res.boom.badRequest("Status cannot be updated. Task is not completed yet");
340357
}
341358
}
342359

test/integration/tasks.test.js

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,19 @@ describe("Tasks", function () {
10291029
expect(res.body.message).to.be.equal("Status cannot be updated. Please contact admin.");
10301030
});
10311031

1032-
it("Should give 400 if percentCompleted is not 100 and new status is DONE", async function () {
1032+
it("Should give 400 if percentCompleted is not 100 and new status is COMPLETED ", async function () {
1033+
taskId = (await tasks.updateTask({ ...taskData, status: "REVIEW", assignee: appOwner.username })).taskId;
1034+
const res = await chai
1035+
.request(app)
1036+
.patch(`/tasks/self/${taskId}`)
1037+
.set("cookie", `${cookieName}=${jwt}`)
1038+
.send({ ...taskStatusData, status: "COMPLETED" });
1039+
1040+
expect(res).to.have.status(400);
1041+
expect(res.body.message).to.be.equal("Status cannot be updated. Task is not completed yet");
1042+
});
1043+
1044+
it("Should give 400 if percentCompleted is not 100 and new status is DONE under feature flag ", async function () {
10331045
taskId = (await tasks.updateTask({ ...taskData, status: "REVIEW", assignee: appOwner.username })).taskId;
10341046
const res = await chai
10351047
.request(app)
@@ -1041,7 +1053,19 @@ describe("Tasks", function () {
10411053
expect(res.body.message).to.be.equal("Status cannot be updated. Task is not done yet");
10421054
});
10431055

1044-
it("Should give 400 if percentCompleted is not 100 and new status is VERIFIED", async function () {
1056+
it("Should give 400 if percentCompleted is not 100 and new status is VERIFIED ", async function () {
1057+
taskId = (await tasks.updateTask({ ...taskData, status: "REVIEW", assignee: appOwner.username })).taskId;
1058+
const res = await chai
1059+
.request(app)
1060+
.patch(`/tasks/self/${taskId}`)
1061+
.set("cookie", `${cookieName}=${jwt}`)
1062+
.send({ ...taskStatusData, status: "VERIFIED" });
1063+
1064+
expect(res).to.have.status(400);
1065+
expect(res.body.message).to.be.equal("Status cannot be updated. Task is not completed yet");
1066+
});
1067+
1068+
it("Should give 400 if percentCompleted is not 100 and new status is VERIFIED under feature flag", async function () {
10451069
taskId = (await tasks.updateTask({ ...taskData, status: "REVIEW", assignee: appOwner.username })).taskId;
10461070
const res = await chai
10471071
.request(app)
@@ -1053,7 +1077,32 @@ describe("Tasks", function () {
10531077
expect(res.body.message).to.be.equal("Status cannot be updated. Task is not done yet");
10541078
});
10551079

1056-
it("Should give 400 if status is DONE and newpercent is less than 100", async function () {
1080+
it("Should give 400 if status is COMPLETED and newpercent is less than 100", async function () {
1081+
const taskData = {
1082+
title: "Test task",
1083+
type: "feature",
1084+
endsOn: 1234,
1085+
startedOn: 4567,
1086+
status: "completed",
1087+
percentCompleted: 100,
1088+
participants: [],
1089+
assignee: appOwner.username,
1090+
completionAward: { [DINERO]: 3, [NEELAM]: 300 },
1091+
lossRate: { [DINERO]: 1 },
1092+
isNoteworthy: true,
1093+
};
1094+
taskId = (await tasks.updateTask(taskData)).taskId;
1095+
const res = await chai
1096+
.request(app)
1097+
.patch(`/tasks/self/${taskId}`)
1098+
.set("cookie", `${cookieName}=${jwt}`)
1099+
.send({ percentCompleted: 80 });
1100+
1101+
expect(res).to.have.status(400);
1102+
expect(res.body.message).to.be.equal("Task percentCompleted can't updated as status is COMPLETED");
1103+
});
1104+
1105+
it("Should give 400 if status is DONE and newpercent is less than 100 under feature flag", async function () {
10571106
taskId = (await tasks.updateTask(updateTaskStatus[0])).taskId;
10581107
const res = await chai
10591108
.request(app)

0 commit comments

Comments
 (0)