Skip to content

Commit 13c0720

Browse files
committed
Handle the case when the self task status is updated apart from completed
1 parent 823579b commit 13c0720

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

controllers/tasks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ const updateTaskStatus = async (req, res, next) => {
342342
}
343343
}
344344

345-
if (isUserStatusEnabled && req.body.status === TASK_STATUS.COMPLETED && req.body.percentCompleted === 100) {
345+
if (isUserStatusEnabled && req.body.status) {
346346
userStatusUpdate = await updateStatusOnTaskCompletion(userId);
347347
}
348348
return res.json({

test/integration/taskBasedStatusUpdate.test.js

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe("Task Based Status Updates", function () {
8383
expect(res.body.userStatus.data.currentStatus).to.equal(userState.IDLE);
8484
});
8585

86-
it("Should not change the ACTIVE state to IDLE if no other task is assigned to the user.", async function () {
86+
it("Should change the ACTIVE state to IDLE if no other task is assigned to the user.", async function () {
8787
const statusData = generateStatusDataForState(userId, userState.ACTIVE);
8888
await firestore.collection("usersStatus").doc("userStatus").set(statusData);
8989
const res = await chai
@@ -96,6 +96,35 @@ describe("Task Based Status Updates", function () {
9696
expect(res.body.userStatus.data.previousStatus).to.equal(userState.ACTIVE);
9797
expect(res.body.userStatus.data.currentStatus).to.equal(userState.IDLE);
9898
});
99+
100+
it("Should not change the IDLE state if no other task is assigned to the user. & current task status is updated (excluding completed, e.g., in progress).", async function () {
101+
const statusData = generateStatusDataForState(userId, userState.IDLE);
102+
await firestore.collection("usersStatus").doc("userStatus").set(statusData);
103+
reqBody.status = "NEEDS_REVIEW";
104+
const res = await chai
105+
.request(app)
106+
.patch(`/tasks/self/taskid123?userStatusFlag=true`)
107+
.set("cookie", `${cookieName}=${userJwt}`)
108+
.send(reqBody);
109+
expect(res.body.userStatus.status).to.equal("success");
110+
expect(res.body.userStatus.message).to.equal("The status is already IDLE");
111+
expect(res.body.userStatus.data.currentStatus).to.equal(userState.IDLE);
112+
});
113+
114+
it("Should change the ACTIVE state to IDLE if no other task is assigned to the user. & current task status is updated (excluding completed, e.g., in progress).", async function () {
115+
const statusData = generateStatusDataForState(userId, userState.ACTIVE);
116+
await firestore.collection("usersStatus").doc("userStatus").set(statusData);
117+
reqBody.status = "NEEDS_REVIEW";
118+
const res = await chai
119+
.request(app)
120+
.patch(`/tasks/self/taskid123?userStatusFlag=true`)
121+
.set("cookie", `${cookieName}=${userJwt}`)
122+
.send(reqBody);
123+
expect(res.body.userStatus.status).to.equal("success");
124+
expect(res.body.userStatus.message).to.equal("The status has been updated to IDLE");
125+
expect(res.body.userStatus.data.previousStatus).to.equal(userState.ACTIVE);
126+
expect(res.body.userStatus.data.currentStatus).to.equal(userState.IDLE);
127+
});
99128
});
100129

101130
describe("User has an Active Task", function () {
@@ -148,9 +177,38 @@ describe("Task Based Status Updates", function () {
148177
expect(res.body.userStatus.data.currentStatus).to.equal(userState.ACTIVE);
149178
});
150179

151-
it("Should change to ACTIVE state if the user is not ACTIVE.", async function () {
180+
it("Should change to ACTIVE state if the user is not ACTIVE. ", async function () {
181+
const statusData = generateStatusDataForState(userId, userState.IDLE);
182+
await firestore.collection("usersStatus").doc("userStatus").set(statusData);
183+
const res = await chai
184+
.request(app)
185+
.patch(`/tasks/self/taskid123?userStatusFlag=true`)
186+
.set("cookie", `${cookieName}=${userJwt}`)
187+
.send(reqBody);
188+
expect(res.body.userStatus.status).to.equal("success");
189+
expect(res.body.userStatus.message).to.equal("The status has been updated to ACTIVE");
190+
expect(res.body.userStatus.data.previousStatus).to.equal(userState.IDLE);
191+
expect(res.body.userStatus.data.currentStatus).to.equal(userState.ACTIVE);
192+
});
193+
194+
it("Should not change the ACTIVE state if the user is already ACTIVE. & current task status is updated (excluding completed, e.g., in progress).", async function () {
195+
const statusData = generateStatusDataForState(userId, userState.ACTIVE);
196+
await firestore.collection("usersStatus").doc("userStatus").set(statusData);
197+
reqBody.status = "NEEDS_REVIEW";
198+
const res = await chai
199+
.request(app)
200+
.patch(`/tasks/self/taskid123?userStatusFlag=true`)
201+
.set("cookie", `${cookieName}=${userJwt}`)
202+
.send(reqBody);
203+
expect(res.body.userStatus.status).to.equal("success");
204+
expect(res.body.userStatus.message).to.equal("The status is already ACTIVE");
205+
expect(res.body.userStatus.data.currentStatus).to.equal(userState.ACTIVE);
206+
});
207+
208+
it("Should change to ACTIVE state if the user is not ACTIVE. & current task status is updated (excluding completed, e.g., in progress).", async function () {
152209
const statusData = generateStatusDataForState(userId, userState.IDLE);
153210
await firestore.collection("usersStatus").doc("userStatus").set(statusData);
211+
reqBody.status = "NEEDS_REVIEW";
154212
const res = await chai
155213
.request(app)
156214
.patch(`/tasks/self/taskid123?userStatusFlag=true`)

0 commit comments

Comments
 (0)