fix: fixed findTaskById and tests

This commit is contained in:
Shrey Paharia
2025-05-07 11:17:55 +05:30
parent 07a710d88e
commit e917fd16c0
2 changed files with 16 additions and 16 deletions

View File

@@ -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;

View File

@@ -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);
});
});
});