Skip to content

Commit 888bf8a

Browse files
committed
write integration test for filter task
1 parent 06180a4 commit 888bf8a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

models/tasks.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ const getBuiltTasks = async (tasksSnapshot, searchTerm) => {
104104
if (searchTerm) {
105105
updatedTasks = updatedTasks.filter((task) => task.title.toLowerCase().includes(searchTerm.toLowerCase()));
106106
}
107-
108107
const taskPromises = updatedTasks.map(async (task) => {
109108
task.status = TASK_STATUS[task.status.toUpperCase()] || task.status;
110109
const taskId = task.id;

test/integration/tasks.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,29 @@ describe("Tasks", function () {
264264
});
265265

266266
describe("GET /tasks/:id/details", function () {
267+
it("Should get tasks filtered by search term", function (done) {
268+
const searchTerm = "search";
269+
chai
270+
.request(app)
271+
.get(`/tasks?q=${encodeURIComponent(searchTerm)}`)
272+
.end((err, res) => {
273+
if (err) {
274+
return done(err);
275+
}
276+
277+
expect(res).to.have.status(200);
278+
expect(res.body).to.be.a("object");
279+
expect(res.body.message).to.equal("Filter tasks returned successfully!");
280+
expect(res.body.tasks).to.be.a("array");
281+
282+
const matchingTasks = res.body.tasks;
283+
matchingTasks.forEach((task) => {
284+
expect(task.title.toLowerCase()).to.include(searchTerm.toLowerCase());
285+
});
286+
287+
return done();
288+
});
289+
});
267290
it("should return the task task with the Id that we provide in the route params", function (done) {
268291
chai
269292
.request(app)

0 commit comments

Comments
 (0)