From dcb3f2f9f99c9276c7833bf4fe047796fab59725 Mon Sep 17 00:00:00 2001 From: Shrey Paharia Date: Sat, 19 Apr 2025 13:24:50 +0530 Subject: [PATCH] test: fix findTaskById complexity report testcases --- tests/unit/task-finder.test.js | 74 ++++++++++++---------------------- 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/tests/unit/task-finder.test.js b/tests/unit/task-finder.test.js index 922100d6..4b0ef0a6 100644 --- a/tests/unit/task-finder.test.js +++ b/tests/unit/task-finder.test.js @@ -2,24 +2,7 @@ * Task finder tests */ -import { jest } from '@jest/globals'; - -// Set up mock before imports -const mockReadComplexityReport = jest.fn().mockReturnValue(null); - -// Mock utils module to control readComplexityReport behavior -jest.mock('../../scripts/modules/utils.js', () => { - // Get the original module - const originalModule = jest.requireActual('../../scripts/modules/utils.js'); - - // Return a modified version - return { - ...originalModule, - readComplexityReport: mockReadComplexityReport - }; -}); - -// Import after mocks are set up +// Import after mocks are set up - No mocks needed for readComplexityReport anymore import { findTaskById } from '../../scripts/modules/utils.js'; import { emptySampleTasks, sampleTasks } from '../fixtures/sample-tasks.js'; @@ -64,11 +47,30 @@ describe('Task Finder', () => { const task = findTaskById(emptySampleTasks.tasks, 1); expect(task).toBeNull(); }); + test('should work correctly when no complexity report is provided', () => { + // Pass null as the complexity report + const task = findTaskById(sampleTasks.tasks, 2, null); - test('should include complexity score when report exists', () => { - // call readComplexityReport - // Set up mock implementation for this test - mockReadComplexityReport.mockReturnValue({ + expect(task).toBeDefined(); + expect(task.id).toBe(2); + expect(task.complexityScore).toBeUndefined(); + }); + test('should work correctly when task has no complexity data in the provided report', () => { + // Define a complexity report that doesn't include task 2 + const complexityReport = { + complexityAnalysis: [{ taskId: 999, complexityScore: 5 }] + }; + + const task = findTaskById(sampleTasks.tasks, 2, complexityReport); + + expect(task).toBeDefined(); + expect(task.id).toBe(2); + expect(task.complexityScore).toBeUndefined(); + }); + + test('should include complexity score when report is provided', () => { + // Define the complexity report for this test + const complexityReport = { meta: { generatedAt: '2023-01-01T00:00:00.000Z', tasksAnalyzed: 3, @@ -94,37 +96,13 @@ describe('Task Finder', () => { recommendedSubtasks: 4 } ] - }); + }; - const task = findTaskById(sampleTasks.tasks, 2); + const task = findTaskById(sampleTasks.tasks, 2, complexityReport); expect(task).toBeDefined(); expect(task.id).toBe(2); expect(task.complexityScore).toBe(8); }); - - test('should work correctly when task has no complexity data', () => { - // Set up mock implementation for this test - mockReadComplexityReport.mockReturnValue({ - complexityAnalysis: [{ taskId: 999, complexityScore: 5 }] - }); - - const task = findTaskById(sampleTasks.tasks, 2); - - expect(task).toBeDefined(); - expect(task.id).toBe(2); - expect(task.complexityScore).toBeUndefined(); - }); - - test('should work correctly when no complexity report exists', () => { - // Set up mock implementation for this test - mockReadComplexityReport.mockReturnValue(null); - - const task = findTaskById(sampleTasks.tasks, 2); - - expect(task).toBeDefined(); - expect(task.id).toBe(2); - expect(task.complexityScore).toBeUndefined(); - }); }); });