Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the logic to return 404 instead of 200 when wrong taskRequest Id is sent #2296

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions models/taskRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,16 @@ const fetchTaskRequestById = async (taskRequestId) => {
const taskRequestSnapshot = await taskRequestsCollection.doc(taskRequestId).get();
const taskRequestData = taskRequestSnapshot.data();

if (taskRequestData) {
taskRequestData.id = taskRequestSnapshot.id;
taskRequestData.url = new URL(`/taskRequests/${taskRequestData.id}`, config.get("services.rdsUi.baseUrl"));
if (!taskRequestData) {
return {
taskRequestData,
Akshat187 marked this conversation as resolved.
Show resolved Hide resolved
taskRequestExists: false,
};
}

taskRequestData.id = taskRequestSnapshot.id;
taskRequestData.url = new URL(`/taskRequests/${taskRequestData.id}`, config.get("services.rdsUi.baseUrl"));

return {
taskRequestData,
taskRequestExists: true,
Expand Down
31 changes: 26 additions & 5 deletions test/integration/taskRequests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ describe("Task Requests", function () {
});
});

it("should return 404 if the task request is not found for the given Id", function (done) {
chai
.request(app)
.get(`/taskRequests/1234`)
.set("cookie", `${cookieName}=${jwt}`)
.end((err, res) => {
if (err) {
return done(err);
}

expect(res).to.have.status(404);
expect(res.body.message).to.be.equal("Task request not found");
return done();
});
});

it("should return 404 if the resource is not found", function (done) {
sinon.stub(taskRequestsModel, "fetchTaskRequestById").callsFake(() => []);

Expand All @@ -196,21 +212,26 @@ describe("Task Requests", function () {
});

describe("When the user is not a super user", function () {
let taskrequestid;
vikhyat187 marked this conversation as resolved.
Show resolved Hide resolved

before(async function () {
userId = await addUser(member);
sinon.stub(authService, "verifyAuthToken").callsFake(() => ({ userId }));
jwt = authService.generateAuthToken({ userId });
sinon.stub(authService, "verifyAuthToken").callsFake(() => ({
userId,
}));
jwt = authService.generateAuthToken({
userId,
});

taskId = (await tasksModel.updateTask(taskData[4])).taskId;

await userStatusModel.updateUserStatus(userId, idleUserStatus);
await taskRequestsModel.addOrUpdate(taskId, userId);
taskrequestid = (await taskRequestsModel.addOrUpdate(taskId, userId)).id;
});

it("should be successful when the user is not a super user", function (done) {
chai
.request(app)
.get(`/taskRequests/taskrequstid`)
.get(`/taskRequests/${taskrequestid}`)
.set("cookie", `${cookieName}=${jwt}`)
.end((err, res) => {
if (err) {
Expand Down
Loading