@@ -4,6 +4,7 @@ import * as fs from 'fs';
44import MarkdownIt from 'markdown-it' ;
55import path from 'path' ;
66import { outlineRouter } from '../../../../src/server/routes/outline' ;
7+ import { logger } from '../../../../src/utils/logger' ;
78
89// Mock the fs module
910jest . mock ( 'fs' , ( ) => {
@@ -24,13 +25,19 @@ jest.mock('markdown-it', () => {
2425 } ) ,
2526 } ) ) ;
2627} ) ;
28+ jest . mock ( '../../../../src/utils/logger' , ( ) => ( {
29+ logger : {
30+ error : jest . fn ( ) ,
31+ } ,
32+ } ) ) ;
2733describe ( 'outline.ts' , ( ) => {
2834 beforeEach ( ( ) => {
2935 const mockedFs = fs as jest . Mocked < typeof import ( 'fs' ) > ;
3036 mockedFs . readFileSync . mockReset ( ) ;
3137 mockedFs . existsSync . mockReset ( ) ;
3238 mockedFs . existsSync . mockReturnValue ( true ) ;
3339 ( MarkdownIt as jest . Mock ) . mockClear ( ) ;
40+ jest . mocked ( logger . error ) . mockReset ( ) ;
3441 } ) ;
3542
3643 describe ( 'outlineRouter' , ( ) => {
@@ -89,5 +96,19 @@ describe('outline.ts', () => {
8996
9097 consoleErrorSpy . mockRestore ( ) ;
9198 } ) ;
99+
100+ it ( 'should return 500 when outline generation fails' , async ( ) => {
101+ const error = new Error ( 'Failed to read markdown' ) ;
102+ const mockedFs = fs as jest . Mocked < typeof import ( 'fs' ) > ;
103+ mockedFs . readFileSync . mockImplementationOnce ( ( ) => {
104+ throw error ;
105+ } ) ;
106+
107+ const response = await request ( app ) . get ( '/api/outline?filePath=broken.md' ) ;
108+
109+ expect ( response . statusCode ) . toBe ( 500 ) ;
110+ expect ( response . text ) . toBe ( 'Error getting outline.' ) ;
111+ expect ( logger . error ) . toHaveBeenCalledWith ( 'Error getting outline for broken.md:' , error ) ;
112+ } ) ;
92113 } ) ;
93114} ) ;
0 commit comments