diff --git a/tests/unit/config-manager.test.js b/tests/unit/config-manager.test.js index a0f315a3..a79474a4 100644 --- a/tests/unit/config-manager.test.js +++ b/tests/unit/config-manager.test.js @@ -557,7 +557,8 @@ describe('getConfig Tests', () => { // Assert expect(config).toEqual(DEFAULT_CONFIG); expect(mockFindProjectRoot).not.toHaveBeenCalled(); // Explicit root provided - expect(fsExistsSyncSpy).toHaveBeenCalledWith(MOCK_CONFIG_PATH); + // The implementation checks for .taskmaster directory first + expect(fsExistsSyncSpy).toHaveBeenCalledWith(path.join(MOCK_PROJECT_ROOT, '.taskmaster')); expect(fsReadFileSyncSpy).not.toHaveBeenCalled(); // No read if file doesn't exist expect(consoleWarnSpy).toHaveBeenCalledWith( expect.stringContaining('not found at provided project root') diff --git a/tests/unit/scripts/modules/task-manager/analyze-task-complexity.test.js b/tests/unit/scripts/modules/task-manager/analyze-task-complexity.test.js index 4662126f..4517b188 100644 --- a/tests/unit/scripts/modules/task-manager/analyze-task-complexity.test.js +++ b/tests/unit/scripts/modules/task-manager/analyze-task-complexity.test.js @@ -184,7 +184,7 @@ jest.unstable_mockModule( ); // Import the mocked modules -const { readJSON, writeJSON, log, CONFIG } = await import( +const { readJSON, writeJSON, log, CONFIG, findTaskById } = await import( '../../../../../scripts/modules/utils.js' ); @@ -265,6 +265,13 @@ describe('analyzeTaskComplexity', () => { _rawTaggedData: sampleTasks }; }); + + // Mock findTaskById to return the expected structure + findTaskById.mockImplementation((tasks, taskId) => { + const task = tasks?.find(t => t.id === parseInt(taskId)); + return { task: task || null, originalSubtaskCount: null }; + }); + generateTextService.mockResolvedValue(sampleApiResponse); }); diff --git a/tests/unit/task-master.test.js b/tests/unit/task-master.test.js index 26067d12..37c177ca 100644 --- a/tests/unit/task-master.test.js +++ b/tests/unit/task-master.test.js @@ -248,7 +248,7 @@ describe('initTaskMaster', () => { expect(taskMaster.getTasksPath()).toBeNull(); }); - test('should return null when optional files not specified in overrides', () => { + test('should return default paths when optional files not specified in overrides', () => { // Arrange - Remove all optional files fs.unlinkSync(tasksPath); fs.unlinkSync(configPath); @@ -257,10 +257,10 @@ describe('initTaskMaster', () => { // Act - Don't specify any optional paths const taskMaster = initTaskMaster({}); - // Assert - expect(taskMaster.getTasksPath()).toBeUndefined(); - expect(taskMaster.getConfigPath()).toBeUndefined(); - expect(taskMaster.getStatePath()).toBeUndefined(); + // Assert - Should return absolute paths with default locations + expect(taskMaster.getTasksPath()).toBe(path.join(tempDir, TASKMASTER_TASKS_FILE)); + expect(taskMaster.getConfigPath()).toBe(path.join(tempDir, TASKMASTER_CONFIG_FILE)); + expect(taskMaster.getStatePath()).toBe(path.join(tempDir, TASKMASTER_DIR, 'state.json')); }); }); @@ -415,11 +415,13 @@ describe('initTaskMaster', () => { // Assert expect(taskMaster.getProjectRoot()).toBe(tempDir); expect(taskMaster.getTaskMasterDir()).toBe(taskMasterDir); - expect(taskMaster.getTasksPath()).toBeUndefined(); + // Default paths are always set for tasks, config, and state + expect(taskMaster.getTasksPath()).toBe(path.join(tempDir, TASKMASTER_TASKS_FILE)); + expect(taskMaster.getConfigPath()).toBe(path.join(tempDir, TASKMASTER_CONFIG_FILE)); + expect(taskMaster.getStatePath()).toBe(path.join(taskMasterDir, 'state.json')); + // PRD and complexity report paths are undefined when not provided expect(taskMaster.getPrdPath()).toBeUndefined(); expect(taskMaster.getComplexityReportPath()).toBeUndefined(); - expect(taskMaster.getConfigPath()).toBeUndefined(); - expect(taskMaster.getStatePath()).toBeUndefined(); }); }); });