From 6b2805419564e0acbb3d9a4ea9c249c822869d54 Mon Sep 17 00:00:00 2001 From: Akshat187 Date: Fri, 27 Dec 2024 23:45:38 +0530 Subject: [PATCH] wrote a test case for taskRequestById --- test/unit/models/task-requests.test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/unit/models/task-requests.test.js b/test/unit/models/task-requests.test.js index 092ff67fe..97e9e7d1f 100644 --- a/test/unit/models/task-requests.test.js +++ b/test/unit/models/task-requests.test.js @@ -6,6 +6,7 @@ const { fetchTaskRequests, approveTaskRequest, fetchPaginatedTaskRequests, + fetchTaskRequestById, addNewFields, removeOldField, addUsersCountAndCreatedAt, @@ -197,6 +198,31 @@ describe("Task requests | models", function () { }); }); + describe("fetchTaskRequestById", function () { + afterEach(async function () { + await cleanDb(); + }); + + it("should return task request data when task request exists", async function () { + const requestData = mockData.taskRequestData; + const addedTaskRequest = await createRequest(requestData, "testUser"); + const result = await fetchTaskRequestById(addedTaskRequest.id); + const assert = require("chai").assert; + assert.isTrue(result.taskRequestExists, "Task request should exist"); + + expect(result.taskRequestExists).to.be.equal(true); + expect(result.taskRequestData.id).to.equal(addedTaskRequest.id); + }); + + it("should return taskRequestExists as false when task request does not exist", async function () { + const mockTaskRequestId = "taskRequest1234"; + const requestData = mockData.taskRequestData; + await createRequest(requestData, "testUser"); + const result = await fetchTaskRequestById(mockTaskRequestId); + expect(result.taskRequestExists).to.be.equal(false); + }); + }); + describe("fetchTaskRequests", function () { beforeEach(async function () { const approvedTaskRequest = {