Skip to content

Commit c7fe2bd

Browse files
Merge pull request #1723 from Real-Dev-Squad/develop
* feat: task orderBy updatedAt, desc order * test: fix failing tests * test: add test for order
2 parents f5836f9 + e5ff204 commit c7fe2bd

File tree

2 files changed

+61
-37
lines changed

2 files changed

+61
-37
lines changed

models/tasks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ const fetchPaginatedTasks = async ({
159159
}
160160
}
161161
} else {
162-
initialQuery = tasksModel.orderBy("title");
162+
initialQuery = tasksModel.orderBy("updatedAt", "desc");
163163
if (status) {
164164
initialQuery = initialQuery.where("status", "==", status);
165165
}

test/integration/tasks.test.js

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,40 @@ const superUser = userData[4];
2424

2525
let jwt, superUserJwt;
2626

27+
const taskData = [
28+
{
29+
title: "Test task",
30+
type: "feature",
31+
endsOn: 1234,
32+
startedOn: 4567,
33+
status: "IN_PROGRESS",
34+
percentCompleted: 10,
35+
participants: [],
36+
assignee: appOwner.username,
37+
completionAward: { [DINERO]: 3, [NEELAM]: 300 },
38+
lossRate: { [DINERO]: 1 },
39+
isNoteworthy: true,
40+
isCollapsed: true,
41+
},
42+
{
43+
title: "Test task",
44+
purpose: "To Test mocha",
45+
featureUrl: "<testUrl>",
46+
type: "group",
47+
links: ["test1"],
48+
endsOn: 1234,
49+
startedOn: 54321,
50+
status: "completed",
51+
percentCompleted: 10,
52+
dependsOn: ["d12", "d23"],
53+
participants: [appOwner.username],
54+
completionAward: { [DINERO]: 3, [NEELAM]: 300 },
55+
lossRate: { [DINERO]: 1 },
56+
isNoteworthy: false,
57+
assignee: appOwner.username,
58+
},
59+
];
60+
2761
describe("Tasks", function () {
2862
let taskId1, taskId;
2963

@@ -33,40 +67,6 @@ describe("Tasks", function () {
3367
jwt = authService.generateAuthToken({ userId });
3468
superUserJwt = authService.generateAuthToken({ userId: superUserId });
3569

36-
const taskData = [
37-
{
38-
title: "Test task",
39-
type: "feature",
40-
endsOn: 1234,
41-
startedOn: 4567,
42-
status: "IN_PROGRESS",
43-
percentCompleted: 10,
44-
participants: [],
45-
assignee: appOwner.username,
46-
completionAward: { [DINERO]: 3, [NEELAM]: 300 },
47-
lossRate: { [DINERO]: 1 },
48-
isNoteworthy: true,
49-
isCollapsed: true,
50-
},
51-
{
52-
title: "Test task",
53-
purpose: "To Test mocha",
54-
featureUrl: "<testUrl>",
55-
type: "group",
56-
links: ["test1"],
57-
endsOn: 1234,
58-
startedOn: 54321,
59-
status: "completed",
60-
percentCompleted: 10,
61-
dependsOn: ["d12", "d23"],
62-
participants: [appOwner.username],
63-
completionAward: { [DINERO]: 3, [NEELAM]: 300 },
64-
lossRate: { [DINERO]: 1 },
65-
isNoteworthy: false,
66-
assignee: appOwner.username,
67-
},
68-
];
69-
7070
// Add the active task
7171
taskId = (await tasks.updateTask(taskData[0])).taskId;
7272
taskId1 = taskId;
@@ -184,6 +184,11 @@ describe("Tasks", function () {
184184
});
185185

186186
describe("GET /tasks", function () {
187+
before(async function () {
188+
await tasks.updateTask({ ...taskData[0], createdAt: 1621717694, updatedAt: 1700680830 });
189+
await tasks.updateTask({ ...taskData[1], createdAt: 1621717694, updatedAt: 1700775753 });
190+
});
191+
187192
it("Should get all the list of tasks", function (done) {
188193
chai
189194
.request(app)
@@ -348,7 +353,6 @@ describe("Tasks", function () {
348353
if (err) {
349354
return done(err);
350355
}
351-
352356
expect(res).to.have.status(200);
353357
expect(res.body).to.be.a("object");
354358
expect(res.body.message).to.equal("Tasks returned successfully!");
@@ -409,7 +413,7 @@ describe("Tasks", function () {
409413
matchingTasks.forEach((task) => {
410414
expect(task.title.toLowerCase()).to.include(searchTerm.toLowerCase());
411415
});
412-
expect(matchingTasks).to.have.length(4);
416+
expect(matchingTasks).to.have.length(6);
413417

414418
return done();
415419
});
@@ -448,6 +452,26 @@ describe("Tasks", function () {
448452
return done();
449453
});
450454
});
455+
it("Should get paginated tasks ordered by updatedAt in desc order ", function (done) {
456+
chai
457+
.request(app)
458+
.get("/tasks?dev=true&size=5&page=0")
459+
.end((err, res) => {
460+
if (err) {
461+
return done(err);
462+
}
463+
expect(res).to.have.status(200);
464+
expect(res.body).to.be.a("object");
465+
expect(res.body.message).to.equal("Tasks returned successfully!");
466+
expect(res.body.tasks).to.be.a("array");
467+
const tasks = res.body.tasks;
468+
// Check if Tasks are returned in desc order of updatedAt field
469+
for (let i = 0; i < tasks.length - 1; i++) {
470+
expect(tasks[+i].updatedAt).to.be.greaterThanOrEqual(tasks[i + 1].updatedAt);
471+
}
472+
return done();
473+
});
474+
});
451475
});
452476

453477
describe("GET /tasks/:id/details", function () {

0 commit comments

Comments
 (0)