fix: resolve test failures and add remaining eslint-disable comments

- Fix TaskService test mocks to use mockImplementation instead of mockRejectedValue
  since updateTaskInfoInCache is now synchronous (no longer async)
- Add eslint-disable no-console comments to remaining console statements in TaskService
- Tests now pass successfully with proper error handling validation
This commit is contained in:
callumalpass 2025-09-28 13:30:04 +10:00
parent d9853c58a2
commit 7dbc414200
2 changed files with 14 additions and 2 deletions

View file

@ -489,6 +489,7 @@ export class TaskService {
return { file, taskInfo };
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
// eslint-disable-next-line no-console
console.error("Error creating task:", {
error: errorMessage,
stack: error instanceof Error ? error.stack : undefined,
@ -546,6 +547,7 @@ export class TaskService {
return processTemplate(templateContent, templateTaskData);
} else {
// Template file not found, log error and return details as-is
// eslint-disable-next-line no-console
console.warn(`Task body template not found: ${templatePath}`);
new Notice(
this.translate("services.task.notices.templateNotFound", { path: templatePath })
@ -681,6 +683,7 @@ export class TaskService {
);
} catch (cacheError) {
// Cache errors shouldn't break the operation, just log them
// eslint-disable-next-line no-console
console.error("Error updating task cache:", {
error: cacheError instanceof Error ? cacheError.message : String(cacheError),
taskPath: task.path,
@ -728,6 +731,7 @@ export class TaskService {
}
}
} catch (eventError) {
// eslint-disable-next-line no-console
console.error("Error emitting task update event:", {
error: eventError instanceof Error ? eventError.message : String(eventError),
taskPath: task.path,
@ -790,6 +794,7 @@ export class TaskService {
return updatedTask as TaskInfo;
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
// eslint-disable-next-line no-console
console.error("Error updating task property:", {
error: errorMessage,
stack: error instanceof Error ? error.stack : undefined,
@ -1418,6 +1423,7 @@ export class TaskService {
this.plugin.cacheManager.updateTaskInfoInCache(newPath, updatedTask);
} catch (cacheError) {
// Cache errors shouldn't break the operation, just log them
// eslint-disable-next-line no-console
console.error("Error updating task cache:", {
error: cacheError instanceof Error ? cacheError.message : String(cacheError),
taskPath: newPath,
@ -1432,6 +1438,7 @@ export class TaskService {
updatedTask: updatedTask,
});
} catch (eventError) {
// eslint-disable-next-line no-console
console.error("Error emitting task update event:", {
error: eventError instanceof Error ? eventError.message : String(eventError),
taskPath: newPath,
@ -1644,6 +1651,7 @@ export class TaskService {
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
// eslint-disable-next-line no-console
console.error("Error deleting task:", {
error: errorMessage,
stack: error instanceof Error ? error.stack : undefined,

View file

@ -646,7 +646,9 @@ describe('TaskService', () => {
});
it('should handle cache errors gracefully', async () => {
mockPlugin.cacheManager.updateTaskInfoInCache.mockRejectedValue(new Error('Cache error'));
mockPlugin.cacheManager.updateTaskInfoInCache.mockImplementation(() => {
throw new Error('Cache error');
});
// Should not throw, just log error
const result = await taskService.updateProperty(task, 'priority', 'high');
@ -872,7 +874,9 @@ describe('TaskService', () => {
});
it('should handle cache and event errors gracefully', async () => {
mockPlugin.cacheManager.updateTaskInfoInCache.mockRejectedValue(new Error('Cache error'));
mockPlugin.cacheManager.updateTaskInfoInCache.mockImplementation(() => {
throw new Error('Cache error');
});
mockPlugin.emitter.trigger.mockImplementation(() => {
throw new Error('Event error');
});