feat: added handling for complexity score in find task by id

This commit is contained in:
Shrey Paharia
2025-04-19 03:45:22 +05:30
parent b98af1541e
commit 3162ac49ec
2 changed files with 110 additions and 25 deletions

View File

@@ -2,8 +2,26 @@
* 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 { findTaskById } from '../../scripts/modules/utils.js';
import { sampleTasks, emptySampleTasks } from '../fixtures/sample-tasks.js';
import { emptySampleTasks, sampleTasks } from '../fixtures/sample-tasks.js';
describe('Task Finder', () => {
describe('findTaskById function', () => {
@@ -46,5 +64,67 @@ describe('Task Finder', () => {
const task = findTaskById(emptySampleTasks.tasks, 1);
expect(task).toBeNull();
});
test('should include complexity score when report exists', () => {
// call readComplexityReport
// Set up mock implementation for this test
mockReadComplexityReport.mockReturnValue({
meta: {
generatedAt: '2023-01-01T00:00:00.000Z',
tasksAnalyzed: 3,
thresholdScore: 5
},
complexityAnalysis: [
{
taskId: 1,
taskTitle: 'Initialize Project',
complexityScore: 3,
recommendedSubtasks: 2
},
{
taskId: 2,
taskTitle: 'Create Core Functionality',
complexityScore: 8,
recommendedSubtasks: 5
},
{
taskId: 3,
taskTitle: 'Implement UI Components',
complexityScore: 6,
recommendedSubtasks: 4
}
]
});
const task = findTaskById(sampleTasks.tasks, 2);
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();
});
});
});