Skip to content

Commit b4f4889

Browse files
authored
Fixing Task Reassignment Status Update Issue (#1351)
* adds the logic to modify the user status of old assignee * Adds integration test * Consolidated Multi-Line Variable Declarations into Single Line
1 parent 2721818 commit b4f4889

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

controllers/tasks.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,12 @@ const updateTask = async (req, res) => {
256256
}
257257
await tasks.updateTask(req.body, req.params.id);
258258
if (isUserStatusEnabled && req.body.assignee) {
259+
// New Assignee Status Update
259260
await updateUserStatusOnTaskUpdate(req.body.assignee);
261+
// Old Assignee Status Update if available
262+
if (task.taskData.assigneeId) {
263+
await updateStatusOnTaskCompletion(task.taskData.assigneeId);
264+
}
260265
}
261266

262267
return res.status(204).send();

test/integration/taskBasedStatusUpdate.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,4 +537,59 @@ describe("Task Based Status Updates", function () {
537537
);
538538
});
539539
});
540+
541+
describe("PATCH Update User Status on Task Assignment by SuperUser", function () {
542+
let userId1, user2Name, superUserId, superUserJwt, taskArr;
543+
const reqBody = {};
544+
545+
beforeEach(async function () {
546+
userId1 = await addUser(userData[6]);
547+
superUserId = await addUser(userData[4]);
548+
superUserJwt = authService.generateAuthToken({ userId: superUserId });
549+
await addUser(userData[0]);
550+
user2Name = userData[0].username;
551+
taskArr = allTasks();
552+
const sampleTask1 = taskArr[0];
553+
sampleTask1.assignee = userId1;
554+
sampleTask1.createdBy = superUserId;
555+
await firestore.collection("tasks").doc("taskid123").set(sampleTask1);
556+
const statusData = generateStatusDataForState(userId1, userState.ACTIVE);
557+
await firestore.collection("usersStatus").doc("userStatusDoc001").set(statusData);
558+
});
559+
560+
afterEach(async function () {
561+
await cleanDb();
562+
});
563+
564+
it("Update the old assignee status to IDLE on task reassignment if no tasks is in progress in their name", async function () {
565+
reqBody.assignee = user2Name;
566+
const res = await chai
567+
.request(app)
568+
.patch(`/tasks/taskid123?userStatusFlag=true`)
569+
.set("cookie", `${cookieName}=${superUserJwt}`)
570+
.send(reqBody);
571+
expect(res.status).to.equal(204);
572+
const userStatus002Data = (await userStatusModel.doc("userStatusDoc001").get()).data();
573+
expect(userStatus002Data).to.have.keys(["userId", "currentStatus"]);
574+
expect(userStatus002Data.currentStatus.state).to.equal(userState.IDLE);
575+
});
576+
577+
it("Should maintain the old assignee status to ACTIVE on task reassignment if another task is in progress in their name", async function () {
578+
const sampleTask2 = taskArr[1];
579+
sampleTask2.assignee = userId1;
580+
sampleTask2.createdBy = superUserId;
581+
await firestore.collection("tasks").doc("taskid234").set(sampleTask2);
582+
583+
reqBody.assignee = user2Name;
584+
const res = await chai
585+
.request(app)
586+
.patch(`/tasks/taskid123?userStatusFlag=true`)
587+
.set("cookie", `${cookieName}=${superUserJwt}`)
588+
.send(reqBody);
589+
expect(res.status).to.equal(204);
590+
const userStatus002Data = (await userStatusModel.doc("userStatusDoc001").get()).data();
591+
expect(userStatus002Data).to.have.keys(["userId", "currentStatus"]);
592+
expect(userStatus002Data.currentStatus.state).to.equal(userState.ACTIVE);
593+
});
594+
});
540595
});

utils/tasks.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,33 @@ const fromFirestoreData = async (task) => {
66
return task;
77
}
88

9-
let { createdBy, assignee, participants, type } = task;
9+
let { createdBy, assignee: assigneeId, participants, type } = task;
10+
let assigneeName;
1011

1112
if (createdBy) {
1213
createdBy = await getUsername(createdBy);
1314
}
1415

15-
if (assignee) {
16-
assignee = await getUsername(assignee);
16+
if (assigneeId) {
17+
assigneeName = await getUsername(assigneeId);
1718
}
1819

1920
if (type === TASK_TYPE.GROUP) {
2021
participants = await getParticipantUsernames(participants);
2122
}
2223

23-
return {
24+
const updatedTask = {
2425
...task,
2526
createdBy,
26-
assignee,
2727
participants,
2828
};
29+
30+
if (assigneeName || assigneeId) {
31+
updatedTask.assignee = assigneeName;
32+
updatedTask.assigneeId = assigneeId;
33+
}
34+
35+
return updatedTask;
2936
};
3037

3138
const toFirestoreData = async (task) => {

0 commit comments

Comments
 (0)