Skip to content

Commit 92e85f5

Browse files
Replace 'COMPLETED' with 'DONE' in Backend from 'updateTaskStatus' Function (#1657)
* changes status completd to done * change error message and fix test * change in title of test * added feature flag in controller * test under feature flag * minor changes * comment out assignTask function in middleware * minor change * minor change * use fixture data in test * change comment message for assign task * change fixture file * removed commented code
1 parent 1e56e72 commit 92e85f5

File tree

3 files changed

+104
-8
lines changed

3 files changed

+104
-8
lines changed

controllers/tasks.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ const updateTaskStatus = async (req, res, next) => {
312312
try {
313313
let userStatusUpdate;
314314
const taskId = req.params.id;
315-
const { dev } = req.query;
315+
const { userStatusFlag } = req.query;
316316
const { id: userId, username } = req.userData;
317317
const task = await tasks.fetchSelfTask(taskId, userId);
318318

@@ -321,12 +321,28 @@ const updateTaskStatus = async (req, res, next) => {
321321
if (task.taskData.status === TASK_STATUS.VERIFIED || req.body.status === TASK_STATUS.MERGED)
322322
return res.boom.forbidden("Status cannot be updated. Please contact admin.");
323323

324+
if (userStatusFlag) {
325+
if (task.taskData.status === TASK_STATUS.DONE && req.body.percentCompleted < 100) {
326+
if (req.body.status === TASK_STATUS.DONE || !req.body.status) {
327+
return res.boom.badRequest("Task percentCompleted can't updated as status is DONE");
328+
}
329+
}
330+
331+
if (
332+
(req.body.status === TASK_STATUS.DONE || req.body.status === TASK_STATUS.VERIFIED) &&
333+
task.taskData.percentCompleted !== 100
334+
) {
335+
if (req.body.percentCompleted !== 100) {
336+
return res.boom.badRequest("Status cannot be updated. Task is not done yet");
337+
}
338+
}
339+
}
340+
324341
if (task.taskData.status === TASK_STATUS.COMPLETED && req.body.percentCompleted < 100) {
325342
if (req.body.status === TASK_STATUS.COMPLETED || !req.body.status) {
326343
return res.boom.badRequest("Task percentCompleted can't updated as status is COMPLETED");
327344
}
328345
}
329-
330346
if (
331347
(req.body.status === TASK_STATUS.COMPLETED || req.body.status === TASK_STATUS.VERIFIED) &&
332348
task.taskData.percentCompleted !== 100
@@ -367,12 +383,6 @@ const updateTaskStatus = async (req, res, next) => {
367383
]);
368384
taskLog.id = taskLogResult.id;
369385

370-
if (dev) {
371-
if (req.body.percentCompleted === 100) {
372-
return next();
373-
}
374-
}
375-
376386
if (req.body.status) {
377387
userStatusUpdate = await updateStatusOnTaskCompletion(userId);
378388
}

test/fixtures/tasks/tasks1.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { DINERO, NEELAM } = require("../../../constants/wallets");
2+
const userData = require("../user/user")();
3+
const appOwner = userData[3];
4+
/**
5+
* Sample tasks for tests
6+
* @return {object}
7+
*/
8+
9+
module.exports = () => {
10+
return [
11+
{
12+
title: "Test task",
13+
type: "feature",
14+
endsOn: 1234,
15+
startedOn: 4567,
16+
status: "DONE",
17+
percentCompleted: 100,
18+
participants: [],
19+
assignee: appOwner.username,
20+
completionAward: { [DINERO]: 3, [NEELAM]: 300 },
21+
lossRate: { [DINERO]: 1 },
22+
isNoteworthy: true,
23+
},
24+
];
25+
};

test/integration/tasks.test.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const tasksData = require("../fixtures/tasks/tasks")();
1515
const { DINERO, NEELAM } = require("../../constants/wallets");
1616
const cleanDb = require("../utils/cleanDb");
1717
const { TASK_STATUS } = require("../../constants/tasks");
18+
const updateTaskStatus = require("../fixtures/tasks/tasks1")();
1819
chai.use(chaiHttp);
1920

2021
const appOwner = userData[3];
@@ -836,6 +837,30 @@ describe("Tasks", function () {
836837
return done();
837838
});
838839
});
840+
841+
it("Should update the task status for given self taskid under feature flag", function (done) {
842+
chai
843+
.request(app)
844+
.patch(`/tasks/self/${taskId1}?userStatusFlag=true`)
845+
.set("cookie", `${cookieName}=${jwt}`)
846+
.send({ status: "DONE", percentCompleted: 100 })
847+
.end((err, res) => {
848+
if (err) {
849+
return done(err);
850+
}
851+
expect(res).to.have.status(200);
852+
expect(res.body.taskLog).to.have.property("type");
853+
expect(res.body.taskLog).to.have.property("id");
854+
expect(res.body.taskLog.body).to.be.a("object");
855+
expect(res.body.taskLog.meta).to.be.a("object");
856+
expect(res.body.message).to.equal("Task updated successfully!");
857+
858+
expect(res.body.taskLog.body.new.status).to.equal("DONE");
859+
expect(res.body.taskLog.body.new.percentCompleted).to.equal(100);
860+
return done();
861+
});
862+
});
863+
839864
it("Should return fail response if task data has non-acceptable status value to update the task status for given self taskid", function (done) {
840865
chai
841866
.request(app)
@@ -945,6 +970,18 @@ describe("Tasks", function () {
945970
expect(res.body.message).to.be.equal("Status cannot be updated. Task is not completed yet");
946971
});
947972

973+
it("Should give 400 if percentCompleted is not 100 and new status is DONE under feature flag ", async function () {
974+
taskId = (await tasks.updateTask({ ...taskData, status: "REVIEW", assignee: appOwner.username })).taskId;
975+
const res = await chai
976+
.request(app)
977+
.patch(`/tasks/self/${taskId}?userStatusFlag=true`)
978+
.set("cookie", `${cookieName}=${jwt}`)
979+
.send({ ...taskStatusData, status: "DONE" });
980+
981+
expect(res).to.have.status(400);
982+
expect(res.body.message).to.be.equal("Status cannot be updated. Task is not done yet");
983+
});
984+
948985
it("Should give 400 if percentCompleted is not 100 and new status is VERIFIED ", async function () {
949986
taskId = (await tasks.updateTask({ ...taskData, status: "REVIEW", assignee: appOwner.username })).taskId;
950987
const res = await chai
@@ -957,6 +994,18 @@ describe("Tasks", function () {
957994
expect(res.body.message).to.be.equal("Status cannot be updated. Task is not completed yet");
958995
});
959996

997+
it("Should give 400 if percentCompleted is not 100 and new status is VERIFIED under feature flag", async function () {
998+
taskId = (await tasks.updateTask({ ...taskData, status: "REVIEW", assignee: appOwner.username })).taskId;
999+
const res = await chai
1000+
.request(app)
1001+
.patch(`/tasks/self/${taskId}?userStatusFlag=true`)
1002+
.set("cookie", `${cookieName}=${jwt}`)
1003+
.send({ ...taskStatusData, status: "VERIFIED" });
1004+
1005+
expect(res).to.have.status(400);
1006+
expect(res.body.message).to.be.equal("Status cannot be updated. Task is not done yet");
1007+
});
1008+
9601009
it("Should give 400 if status is COMPLETED and newpercent is less than 100", async function () {
9611010
const taskData = {
9621011
title: "Test task",
@@ -981,6 +1030,18 @@ describe("Tasks", function () {
9811030
expect(res).to.have.status(400);
9821031
expect(res.body.message).to.be.equal("Task percentCompleted can't updated as status is COMPLETED");
9831032
});
1033+
1034+
it("Should give 400 if status is DONE and newpercent is less than 100 under feature flag", async function () {
1035+
taskId = (await tasks.updateTask(updateTaskStatus[0])).taskId;
1036+
const res = await chai
1037+
.request(app)
1038+
.patch(`/tasks/self/${taskId}?userStatusFlag=true`)
1039+
.set("cookie", `${cookieName}=${jwt}`)
1040+
.send({ percentCompleted: 80 });
1041+
1042+
expect(res).to.have.status(400);
1043+
expect(res.body.message).to.be.equal("Task percentCompleted can't updated as status is DONE");
1044+
});
9841045
});
9851046

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

0 commit comments

Comments
 (0)