test: fix findTaskById complexity report testcases
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user