Skip to content

Commit c5fed60

Browse files
fix: return correct users with overdue tasks in APPROVED status (#2423)
* fix: return correct users with overdue tasks in APPROVED status * refactor : add mock data in task fixture --------- Co-authored-by: Achintya Chatterjee <[email protected]>
1 parent 72d59ef commit c5fed60

File tree

5 files changed

+138
-20
lines changed

5 files changed

+138
-20
lines changed

models/tasks.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const userUtils = require("../utils/users");
77
const { chunks } = require("../utils/array");
88
const { DOCUMENT_WRITE_SIZE } = require("../constants/constants");
99
const { fromFirestoreData, toFirestoreData, buildTasks } = require("../utils/tasks");
10-
const { TASK_TYPE, TASK_STATUS, TASK_STATUS_OLD, TASK_SIZE } = require("../constants/tasks");
10+
const { TASK_TYPE, TASK_STATUS, TASK_STATUS_OLD, TASK_SIZE, COMPLETED_TASK_STATUS } = require("../constants/tasks");
1111
const {
1212
IN_PROGRESS,
1313
NEEDS_REVIEW,
@@ -19,6 +19,7 @@ const {
1919
SANITY_CHECK,
2020
BACKLOG,
2121
DONE,
22+
AVAILABLE,
2223
} = TASK_STATUS;
2324
const { OLD_ACTIVE, OLD_BLOCKED, OLD_PENDING, OLD_COMPLETED } = TASK_STATUS_OLD;
2425
const { INTERNAL_SERVER_ERROR } = require("../constants/errorMessages");
@@ -597,17 +598,11 @@ const getOverdueTasks = async (days = 0) => {
597598
const currentTime = Math.floor(Date.now() / 1000);
598599
const targetTime = days > 0 ? currentTime + days * 24 * 60 * 60 : currentTime;
599600

600-
const OVERDUE_TASK_STATUSES = [
601-
IN_PROGRESS,
602-
ASSIGNED,
603-
NEEDS_REVIEW,
604-
IN_REVIEW,
605-
SMOKE_TESTING,
606-
BLOCKED,
607-
SANITY_CHECK,
608-
];
609-
610-
const query = tasksModel.where("endsOn", "<", targetTime).where("status", "in", OVERDUE_TASK_STATUSES);
601+
const completeTaskStatuses = Object.values(COMPLETED_TASK_STATUS);
602+
603+
const query = tasksModel
604+
.where("endsOn", "<", targetTime)
605+
.where("status", "not-in", [...completeTaskStatuses, BACKLOG, AVAILABLE]);
611606
const snapshot = await query.get();
612607

613608
if (snapshot.empty) {

test/fixtures/tasks/tasks.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,83 @@ module.exports = () => {
158158
createdAt: 1644753600,
159159
updatedAt: 1644753600,
160160
},
161+
{
162+
title: "Overdue task",
163+
purpose: "testing for tasks tests",
164+
type: "feature",
165+
assignee: "anuj-chhikara",
166+
createdBy: "ankush",
167+
createdAt: 1644753600,
168+
updatedAt: 1644753600,
169+
status: "COMPLETED",
170+
percentCompleted: 100,
171+
endsOn: 1647172800,
172+
startedOn: 1644753600,
173+
},
174+
{
175+
title: "Overdue task",
176+
purpose: "testing for tasks tests",
177+
type: "feature",
178+
assignee: "anuj-chhikara",
179+
createdBy: "ankush",
180+
createdAt: 1644753600,
181+
updatedAt: 1644753600,
182+
status: "DONE",
183+
percentCompleted: 100,
184+
endsOn: 1647172800,
185+
startedOn: 1644753600,
186+
},
187+
{
188+
title: "Overdue task",
189+
purpose: "testing for tasks tests",
190+
type: "feature",
191+
assignee: "anuj-chhikara",
192+
createdBy: "ankush",
193+
createdAt: 1644753600,
194+
updatedAt: 1644753600,
195+
status: "VERIFIED",
196+
percentCompleted: 100,
197+
endsOn: 1647172800,
198+
startedOn: 1644753600,
199+
},
200+
{
201+
title: "Overdue task",
202+
purpose: "testing for tasks tests",
203+
type: "feature",
204+
assignee: "anuj-chhikara",
205+
createdBy: "ankush",
206+
createdAt: 1644753600,
207+
updatedAt: 1644753600,
208+
status: "BACKLOG",
209+
percentCompleted: 20,
210+
endsOn: 1647172800,
211+
startedOn: 1644753600,
212+
},
213+
{
214+
title: "Overdue task",
215+
purpose: "testing for tasks tests",
216+
type: "feature",
217+
assignee: "anuj-chhikara",
218+
createdBy: "ankush",
219+
createdAt: 1644753600,
220+
updatedAt: 1644753600,
221+
status: "AVAILABLE",
222+
percentCompleted: 0,
223+
endsOn: 1647172800,
224+
startedOn: 1644753600,
225+
},
226+
{
227+
title: "Overdue task",
228+
purpose: "testing for tasks tests",
229+
type: "feature",
230+
assignee: "anuj-chhikara",
231+
createdBy: "ankush",
232+
createdAt: 1644753600,
233+
updatedAt: 1644753600,
234+
status: "APPROVED",
235+
percentCompleted: 80,
236+
endsOn: 1647172800,
237+
startedOn: 1644753600,
238+
},
161239
];
162240
};

test/integration/users.test.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const profileDiffs = require("../../models/profileDiffs");
1010
const cleanDb = require("../utils/cleanDb");
1111
// Import fixtures
1212
const userData = require("../fixtures/user/user")();
13+
const tasksData = require("../fixtures/tasks/tasks")();
1314
const profileDiffData = require("../fixtures/profileDiffs/profileDiffs")();
1415
const superUser = userData[4];
1516
const searchParamValues = require("../fixtures/user/search")();
@@ -26,7 +27,7 @@ const {
2627
const { addJoinData, addOrUpdate } = require("../../models/users");
2728
const userStatusModel = require("../../models/userStatus");
2829
const { MAX_USERNAME_LENGTH } = require("../../constants/users.ts");
29-
30+
const { TASK_STATUS } = require("../../constants/tasks");
3031
const userRoleUpdate = userData[4];
3132
const userRoleUnArchived = userData[13];
3233
const userAlreadyMember = userData[0];
@@ -35,7 +36,6 @@ const userAlreadyArchived = userData[5];
3536
const userAlreadyUnArchived = userData[4];
3637
const nonSuperUser = userData[0];
3738
const newUser = userData[18];
38-
3939
const cookieName = config.get("userToken.cookieName");
4040
const { userPhotoVerificationData } = require("../fixtures/user/photo-verification");
4141
const Sinon = require("sinon");
@@ -497,12 +497,18 @@ describe("Users", function () {
497497
});
498498

499499
describe("GET /users", function () {
500+
let userWithOverdueApprovedTask;
501+
500502
beforeEach(async function () {
501503
const { userId } = await addOrUpdate(userData[0]);
502504
await userStatusModel.updateUserStatus(userId, userStatusDataForNewUser);
503505
await addOrUpdate(userData[1]);
504506
await addOrUpdate(userData[2]);
505507
await addOrUpdate(userData[3]);
508+
509+
const assigneeData = { ...userData[6], discordId: getDiscordMembers[0].user.id };
510+
userWithOverdueApprovedTask = await addUser(assigneeData);
511+
await taskModel.add({ ...tasksData[0], assignee: userWithOverdueApprovedTask, status: TASK_STATUS.APPROVED });
506512
});
507513

508514
afterEach(async function () {
@@ -878,6 +884,24 @@ describe("Users", function () {
878884
expect(res.body.message).to.equal("User not found");
879885
});
880886

887+
it("should return users who have overdue tasks with APPROVED status", function (done) {
888+
chai
889+
.request(app)
890+
.get("/users?query=filterBy:overdue_tasks")
891+
.end((err, res) => {
892+
if (err) {
893+
return done(err);
894+
}
895+
expect(res).to.have.status(200);
896+
expect(res.body).to.be.an("object");
897+
expect(res.body.users).to.be.an("array");
898+
expect(res.body.users.length).to.equal(1);
899+
expect(res.body.users[0].id).to.equal(userWithOverdueApprovedTask);
900+
901+
return done();
902+
});
903+
});
904+
881905
it("Should return user ID(s) with overdue tasks within the last 1 day", function (done) {
882906
chai
883907
.request(app)

test/unit/models/tasks.test.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,18 +301,39 @@ describe("tasks", function () {
301301
await cleanDb();
302302
});
303303

304+
it("should exclude overdue tasks with COMPLETED, DONE, VERIFIED, BACKLOG, and AVAILABLE statuses", async function () {
305+
await tasks.updateTask(tasksData[8]);
306+
await tasks.updateTask(tasksData[11]);
307+
await tasks.updateTask(tasksData[12]);
308+
await tasks.updateTask(tasksData[9]);
309+
await tasks.updateTask(tasksData[10]);
310+
311+
const result = await tasks.getOverdueTasks();
312+
313+
const statuses = result.map((task) => task.status);
314+
expect(statuses).to.not.include.members([
315+
TASK_STATUS.COMPLETED,
316+
TASK_STATUS.BACKLOG,
317+
TASK_STATUS.AVAILABLE,
318+
TASK_STATUS.DONE,
319+
TASK_STATUS.VERIFIED,
320+
]);
321+
});
322+
304323
it("should return the overdue tasks for the given days", async function () {
305324
const days = 10;
306325
const overdueTask = { ...tasksData[0] };
307326
overdueTask.endsOn = Date.now() / 1000 + 24 * 60 * 60 * 7;
308327
await tasks.updateTask(overdueTask);
309328
const usersWithOverdueTasks = await tasks.getOverdueTasks(days);
310-
expect(usersWithOverdueTasks.length).to.be.equal(5);
329+
expect(usersWithOverdueTasks.length).to.be.equal(6);
311330
});
312331

313332
it("should return all users which have overdue tasks if days is not passed", async function () {
333+
await tasks.updateTask(tasksData[12]);
334+
314335
const usersWithOverdueTasks = await tasks.getOverdueTasks();
315-
expect(usersWithOverdueTasks.length).to.be.equal(4);
336+
expect(usersWithOverdueTasks.length).to.be.equal(5);
316337
});
317338
});
318339

@@ -336,8 +357,8 @@ describe("tasks", function () {
336357

337358
it("Should update task status COMPLETED to DONE", async function () {
338359
const res = await tasks.updateTaskStatus();
339-
expect(res.totalTasks).to.be.equal(9);
340-
expect(res.totalUpdatedStatus).to.be.equal(9);
360+
expect(res.totalTasks).to.be.equal(15);
361+
expect(res.totalUpdatedStatus).to.be.equal(15);
341362
});
342363

343364
it("should throw an error if firebase batch operation fails", async function () {

test/unit/services/tasks.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe("Tasks services", function () {
5353
const res = await updateTaskStatusToDone(tasks);
5454

5555
expect(res).to.deep.equal({
56-
totalUpdatedStatus: 9,
56+
totalUpdatedStatus: 15,
5757
totalOperationsFailed: 0,
5858
updatedTaskDetails: taskDetails,
5959
failedTaskDetails: [],
@@ -73,7 +73,7 @@ describe("Tasks services", function () {
7373

7474
expect(res).to.deep.equal({
7575
totalUpdatedStatus: 0,
76-
totalOperationsFailed: 9,
76+
totalOperationsFailed: 15,
7777
updatedTaskDetails: [],
7878
failedTaskDetails: taskDetails,
7979
});

0 commit comments

Comments
 (0)