Skip to content

Commit

Permalink
remove ff from task API and fix tests (#2058)
Browse files Browse the repository at this point in the history
  • Loading branch information
sahsisunny authored Jul 24, 2024
1 parent a33e9ea commit f73f04e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 165 deletions.
23 changes: 4 additions & 19 deletions controllers/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,8 @@ const fetchPaginatedTasks = async (query) => {

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

if (dev) {
const paginatedTasks = await fetchPaginatedTasks({ ...transformedQuery, prev, next, userFeatureFlag });
return res.json({
message: "Tasks returned successfully!",
...paginatedTasks,
});
}
const { status, page, size, prev, next, q: queryString, assignee, title, userFeatureFlag } = req.query;
const transformedQuery = transformQuery(status, size, page, assignee, title);

if (queryString !== undefined) {
const searchParams = parseSearchQuery(queryString);
Expand All @@ -167,17 +159,10 @@ const fetchTasks = async (req, res) => {
});
}

const allTasks = await tasks.fetchTasks();
const tasksWithRdsAssigneeInfo = await fetchTasksWithRdsAssigneeInfo(allTasks);
if (tasksWithRdsAssigneeInfo.length === 0) {
return res.status(404).json({
message: "No tasks found",
tasks: [],
});
}
const paginatedTasks = await fetchPaginatedTasks({ ...transformedQuery, prev, next, userFeatureFlag });
return res.json({
message: "Tasks returned successfully!",
tasks: tasksWithRdsAssigneeInfo,
...paginatedTasks,
});
} catch (err) {
logger.error(`Error while fetching tasks ${err}`);
Expand Down
1 change: 0 additions & 1 deletion models/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ const fetchPaginatedTasks = async ({
page,
next,
prev,
dev = false,
assignee,
title,
userFeatureFlag,
Expand Down
31 changes: 17 additions & 14 deletions test/integration/tasks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,25 +239,28 @@ describe("Tasks", function () {
});
});

it("Should call paginated tasks when dev flag passed to GET /tasks is true", function (done) {
const fetchPaginatedUserStub = sinon.stub(tasks, "fetchPaginatedTasks");
it("Should return paginated tasks", function (done) {
chai
.request(app)
.get("/tasks?dev=true")
.get("/tasks")
.end((err, res) => {
if (err) {
return done(err);
}
expect(fetchPaginatedUserStub.calledOnce).to.be.equal(true);

expect(res).to.have.status(200);
expect(res.body).to.be.a("object");
expect(res.body.message).to.equal("Tasks returned successfully!");
expect(res.body.tasks).to.be.a("array");
expect(res.body).to.have.property("next");
expect(res.body).to.have.property("prev");
return done();
});
});

it("Should get all tasks filtered with status when passed to GET /tasks", function (done) {
chai
.request(app)
.get(`/tasks?dev=true&status=${TASK_STATUS.IN_PROGRESS}`)
.get(`/tasks?status=${TASK_STATUS.IN_PROGRESS}`)
.end((err, res) => {
if (err) {
return done(err);
Expand All @@ -281,7 +284,7 @@ describe("Tasks", function () {
it("Should get all tasks filtered with status ,assignee, title when passed to GET /tasks", function (done) {
chai
.request(app)
.get(`/tasks?status=${TASK_STATUS.IN_PROGRESS}&userFeatureFlag=true&dev=true&assignee=sagar&title=Test`)
.get(`/tasks?status=${TASK_STATUS.IN_PROGRESS}&userFeatureFlag=true&assignee=sagar&title=Test`)
.end((err, res) => {
if (err) {
return done(err);
Expand All @@ -307,7 +310,7 @@ describe("Tasks", function () {
it("Should get all tasks filtered with status, multiple assignees, title when passed to GET /tasks", function (done) {
chai
.request(app)
.get(`/tasks?status=${TASK_STATUS.IN_PROGRESS}&dev=true&assignee=sagar,ankur&title=Test`)
.get(`/tasks?status=${TASK_STATUS.IN_PROGRESS}&assignee=sagar,ankur&title=Test`)
.end((err, res) => {
if (err) {
return done(err);
Expand All @@ -333,7 +336,7 @@ describe("Tasks", function () {
it("Should get all overdue tasks GET /tasks", function (done) {
chai
.request(app)
.get(`/tasks?dev=true&status=overdue`)
.get(`/tasks?status=overdue`)
.end((err, res) => {
if (err) {
return done(err);
Expand All @@ -348,7 +351,7 @@ describe("Tasks", function () {
it("Should get all overdue tasks filtered with assignee when passed to GET /tasks", function (done) {
chai
.request(app)
.get(`/tasks?dev=true&status=overdue&assignee=${appOwner.username}`)
.get(`/tasks?status=overdue&assignee=${appOwner.username}`)
.end((err, res) => {
if (err) {
return done(err);
Expand All @@ -373,7 +376,7 @@ describe("Tasks", function () {
it("Should get tasks when correct query parameters are passed", function (done) {
chai
.request(app)
.get("/tasks?dev=true&size=1&page=0")
.get("/tasks?size=1&page=0")
.end((err, res) => {
if (err) {
return done(err);
Expand All @@ -391,7 +394,7 @@ describe("Tasks", function () {
});

it("Should get next and previous page results based returned by the links in the response", async function () {
const initialReq = `/tasks?size=1&dev=true`;
const initialReq = `/tasks?size=1`;
const response = await chai.request(app).get(initialReq);
expect(response).to.have.status(200);
expect(response.body).to.be.a("object");
Expand Down Expand Up @@ -484,7 +487,7 @@ describe("Tasks", function () {
it("Should get paginated tasks ordered by updatedAt in desc order ", function (done) {
chai
.request(app)
.get("/tasks?dev=true&size=5&page=0")
.get("/tasks?size=5&page=0")
.end((err, res) => {
if (err) {
return done(err);
Expand All @@ -509,7 +512,7 @@ describe("Tasks", function () {
},
taskId2
);
const res = await chai.request(app).get(`/tasks?dev=true&status=DONE&userFeatureFlag=true`);
const res = await chai.request(app).get(`/tasks?status=DONE&userFeatureFlag=true`);

expect(res).to.have.status(200);
expect(res.body).to.be.a("object");
Expand Down
Loading

0 comments on commit f73f04e

Please sign in to comment.