diff --git a/scripts/modules/utils.js b/scripts/modules/utils.js index d8819a5a..47c7a117 100644 --- a/scripts/modules/utils.js +++ b/scripts/modules/utils.js @@ -349,9 +349,6 @@ function findTaskById( return { task: null, originalSubtaskCount: null }; } - let taskResult = null; - let originalSubtaskCount = null; - // Check if it's a subtask ID (e.g., "1.2") if (typeof taskId === 'string' && taskId.includes('.')) { // If looking for a subtask, statusFilter doesn't apply directly here. @@ -380,9 +377,12 @@ function findTaskById( addComplexityToTask(subtask, complexityReport); } - taskResult = subtask; + return { task: subtask || null, originalSubtaskCount: null }; } + let taskResult = null; + let originalSubtaskCount = null; + // Find the main task const id = parseInt(taskId, 10); const task = tasks.find((t) => t.id === id) || null; diff --git a/tests/unit/task-finder.test.js b/tests/unit/task-finder.test.js index a965ddd9..b480a2a2 100644 --- a/tests/unit/task-finder.test.js +++ b/tests/unit/task-finder.test.js @@ -58,11 +58,11 @@ describe('Task Finder', () => { }); test('should work correctly when no complexity report is provided', () => { // Pass null as the complexity report - const task = findTaskById(sampleTasks.tasks, 2, null); + const result = findTaskById(sampleTasks.tasks, 2, null); - expect(task).toBeDefined(); - expect(task.id).toBe(2); - expect(task.complexityScore).toBeUndefined(); + expect(result.task).toBeDefined(); + expect(result.task.id).toBe(2); + expect(result.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 @@ -70,11 +70,11 @@ describe('Task Finder', () => { complexityAnalysis: [{ taskId: 999, complexityScore: 5 }] }; - const task = findTaskById(sampleTasks.tasks, 2, complexityReport); + const result = findTaskById(sampleTasks.tasks, 2, complexityReport); - expect(task).toBeDefined(); - expect(task.id).toBe(2); - expect(task.complexityScore).toBeUndefined(); + expect(result.task).toBeDefined(); + expect(result.task.id).toBe(2); + expect(result.task.complexityScore).toBeUndefined(); }); test('should include complexity score when report is provided', () => { @@ -107,11 +107,11 @@ describe('Task Finder', () => { ] }; - const task = findTaskById(sampleTasks.tasks, 2, complexityReport); + const result = findTaskById(sampleTasks.tasks, 2, complexityReport); - expect(task).toBeDefined(); - expect(task.id).toBe(2); - expect(task.complexityScore).toBe(8); + expect(result.task).toBeDefined(); + expect(result.task.id).toBe(2); + expect(result.task.complexityScore).toBe(8); }); }); });