Skip to content

Commit 77048ad

Browse files
skv93-coderShubham Sharmasahsisunny
authored
Added support for done completed status in get tasks API, (#2036)
* Added support for done completed status in get tasks API, Added support for completed status in update API * fixed test case * Added newline space * Added spaceing * Fixed test case failing issue * Added line breaks * Remove unwanted code --------- Co-authored-by: Shubham Sharma <[email protected]> Co-authored-by: Sunny Sahsi <[email protected]>
1 parent 4906fbb commit 77048ad

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

controllers/tasks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ const fetchPaginatedTasks = async (query) => {
134134

135135
const fetchTasks = async (req, res) => {
136136
try {
137-
const { dev, status, page, size, prev, next, q: queryString, assignee, title } = req.query;
137+
const { dev, status, page, size, prev, next, q: queryString, assignee, title, userFeatureFlag } = req.query;
138138
const transformedQuery = transformQuery(dev, status, size, page, assignee, title);
139139

140140
if (dev) {
141-
const paginatedTasks = await fetchPaginatedTasks({ ...transformedQuery, prev, next });
141+
const paginatedTasks = await fetchPaginatedTasks({ ...transformedQuery, prev, next, userFeatureFlag });
142142
return res.json({
143143
message: "Tasks returned successfully!",
144144
...paginatedTasks,

middlewares/validators/tasks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ const getTasksValidator = async (req, res, next) => {
192192
}
193193
return value;
194194
}, "Invalid query format"),
195+
userFeatureFlag: joi.string().optional(),
195196
});
196197

197198
try {

models/tasks.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ const fetchPaginatedTasks = async ({
147147
dev = false,
148148
assignee,
149149
title,
150+
userFeatureFlag,
150151
}) => {
151152
try {
152153
let initialQuery = tasksModel;
@@ -196,7 +197,11 @@ const fetchPaginatedTasks = async ({
196197
*/
197198
title = undefined;
198199
} else if (status) {
199-
initialQuery = initialQuery.where("status", "==", status);
200+
if (userFeatureFlag === "true" && [DONE, COMPLETED].includes(status)) {
201+
initialQuery = initialQuery.where("status", "in", [DONE, COMPLETED]);
202+
} else {
203+
initialQuery = initialQuery.where("status", "==", status);
204+
}
200205
}
201206

202207
if (title) {

test/integration/tasks.test.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ describe("Tasks", function () {
207207
taskId3 = (await tasks.updateTask({ ...taskData[1], createdAt: 1621717694, updatedAt: 1700775753 })).taskId;
208208
});
209209

210+
after(async function () {
211+
await tasks.updateTask(
212+
{ ...taskData[1], createdAt: 1621717694, updatedAt: 1700775753, dependsOn: [], status: "IN_PROGRESS" },
213+
taskId2
214+
);
215+
});
216+
210217
it("Should get all the list of tasks", function (done) {
211218
chai
212219
.request(app)
@@ -274,7 +281,7 @@ describe("Tasks", function () {
274281
it("Should get all tasks filtered with status ,assignee, title when passed to GET /tasks", function (done) {
275282
chai
276283
.request(app)
277-
.get(`/tasks?status=${TASK_STATUS.IN_PROGRESS}&dev=true&assignee=sagar&title=Test`)
284+
.get(`/tasks?status=${TASK_STATUS.IN_PROGRESS}&userFeatureFlag=true&dev=true&assignee=sagar&title=Test`)
278285
.end((err, res) => {
279286
if (err) {
280287
return done(err);
@@ -494,6 +501,31 @@ describe("Tasks", function () {
494501
return done();
495502
});
496503
});
504+
505+
it("Should get tasks with COMPLETED status task when fetching task of status Done", async function () {
506+
await tasks.updateTask(
507+
{
508+
status: "COMPLETED",
509+
},
510+
taskId2
511+
);
512+
const res = await chai.request(app).get(`/tasks?dev=true&status=DONE&userFeatureFlag=true`);
513+
514+
expect(res).to.have.status(200);
515+
expect(res.body).to.be.a("object");
516+
expect(res.body.message).to.equal("Tasks returned successfully!");
517+
expect(res.body.tasks).to.be.a("array");
518+
expect(res.body).to.have.property("next");
519+
expect(res.body).to.have.property("prev");
520+
const tasksData = res.body.tasks ?? [];
521+
let countCompletedTask = 0;
522+
tasksData.forEach((task, i) => {
523+
if (task.status === "COMPLETED") {
524+
countCompletedTask += 1;
525+
}
526+
});
527+
expect(countCompletedTask).to.be.not.equal(0);
528+
});
497529
});
498530

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

utils/tasks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ const transformTasksUsersQuery = (queries) => {
147147
}
148148
return { dateGap: transformedDateGap, status: transformedStatus, size: transformedSize, weekdayList, dateList };
149149
};
150+
150151
module.exports = {
151152
fromFirestoreData,
152153
toFirestoreData,

0 commit comments

Comments
 (0)