@@ -26,7 +26,9 @@ describe('Database Status Route', () => {
2626 // Setup mock Fastify instance
2727 mockFastify = {
2828 get : vi . fn ( ( path , options , handler ) => {
29- routeHandlers [ `GET ${ path } ` ] = handler ;
29+ // Extract the actual handler function from the arguments
30+ const actualHandler = typeof options === 'function' ? options : handler ;
31+ routeHandlers [ `GET ${ path } ` ] = actualHandler ;
3032 return mockFastify as FastifyInstance ;
3133 } ) ,
3234 log : {
@@ -51,14 +53,14 @@ describe('Database Status Route', () => {
5153 it ( 'should register database status route' , async ( ) => {
5254 await dbStatusRoute ( mockFastify as FastifyInstance ) ;
5355
54- expect ( mockFastify . get ) . toHaveBeenCalledWith ( '/api/ db/status' , expect . any ( Object ) , expect . any ( Function ) ) ;
56+ expect ( mockFastify . get ) . toHaveBeenCalledWith ( '/db/status' , expect . any ( Object ) , expect . any ( Function ) ) ;
5557 } ) ;
5658
5759 it ( 'should register route with proper schema' , async ( ) => {
5860 await dbStatusRoute ( mockFastify as FastifyInstance ) ;
5961
6062 const [ path , options ] = ( mockFastify . get as any ) . mock . calls [ 0 ] ;
61- expect ( path ) . toBe ( '/api/ db/status' ) ;
63+ expect ( path ) . toBe ( '/db/status' ) ;
6264 expect ( options . schema ) . toBeDefined ( ) ;
6365 expect ( options . schema . tags ) . toEqual ( [ 'Database' ] ) ;
6466 expect ( options . schema . summary ) . toBe ( 'Get database status' ) ;
@@ -69,7 +71,7 @@ describe('Database Status Route', () => {
6971 } ) ;
7072 } ) ;
7173
72- describe ( 'GET /api/ db/status' , ( ) => {
74+ describe ( 'GET /db/status' , ( ) => {
7375 beforeEach ( async ( ) => {
7476 await dbStatusRoute ( mockFastify as FastifyInstance ) ;
7577 } ) ;
@@ -79,10 +81,11 @@ describe('Database Status Route', () => {
7981 configured : true ,
8082 initialized : true ,
8183 dialect : DatabaseType . SQLite ,
84+ type : DatabaseType . SQLite ,
8285 } ;
8386 mockGetDbStatus . mockReturnValue ( mockStatus ) ;
8487
85- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
88+ const handler = routeHandlers [ 'GET /db/status' ] ;
8689 await handler ( mockRequest , mockReply ) ;
8790
8891 expect ( mockGetDbStatus ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -99,10 +102,11 @@ describe('Database Status Route', () => {
99102 configured : false ,
100103 initialized : false ,
101104 dialect : null ,
105+ type : null ,
102106 } ;
103107 mockGetDbStatus . mockReturnValue ( mockStatus ) ;
104108
105- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
109+ const handler = routeHandlers [ 'GET /db/status' ] ;
106110 await handler ( mockRequest , mockReply ) ;
107111
108112 expect ( mockGetDbStatus ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -118,10 +122,11 @@ describe('Database Status Route', () => {
118122 configured : true ,
119123 initialized : false ,
120124 dialect : DatabaseType . SQLite ,
125+ type : DatabaseType . SQLite ,
121126 } ;
122127 mockGetDbStatus . mockReturnValue ( mockStatus ) ;
123128
124- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
129+ const handler = routeHandlers [ 'GET /db/status' ] ;
125130 await handler ( mockRequest , mockReply ) ;
126131
127132 expect ( mockGetDbStatus ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -137,10 +142,11 @@ describe('Database Status Route', () => {
137142 configured : false ,
138143 initialized : false ,
139144 dialect : null ,
145+ type : null ,
140146 } ;
141147 mockGetDbStatus . mockReturnValue ( mockStatus ) ;
142148
143- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
149+ const handler = routeHandlers [ 'GET /db/status' ] ;
144150 await handler ( mockRequest , mockReply ) ;
145151
146152 expect ( mockReply . send ) . toHaveBeenCalledWith ( {
@@ -155,10 +161,11 @@ describe('Database Status Route', () => {
155161 configured : false ,
156162 initialized : false ,
157163 dialect : undefined ,
164+ type : undefined ,
158165 } ;
159166 mockGetDbStatus . mockReturnValue ( mockStatus as any ) ;
160167
161- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
168+ const handler = routeHandlers [ 'GET /db/status' ] ;
162169 await handler ( mockRequest , mockReply ) ;
163170
164171 expect ( mockReply . send ) . toHaveBeenCalledWith ( {
@@ -174,7 +181,7 @@ describe('Database Status Route', () => {
174181 throw error ;
175182 } ) ;
176183
177- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
184+ const handler = routeHandlers [ 'GET /db/status' ] ;
178185 await handler ( mockRequest , mockReply ) ;
179186
180187 expect ( mockFastify . log ! . error ) . toHaveBeenCalledWith ( error , 'Error fetching database status' ) ;
@@ -189,10 +196,11 @@ describe('Database Status Route', () => {
189196 configured : 'true' , // Should be boolean
190197 initialized : 1 , // Should be boolean
191198 dialect : 'postgres' , // Should be sqlite or null
199+ type : 'postgres' ,
192200 } ;
193201 mockGetDbStatus . mockReturnValue ( invalidStatus as any ) ;
194202
195- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
203+ const handler = routeHandlers [ 'GET /db/status' ] ;
196204 await handler ( mockRequest , mockReply ) ;
197205
198206 // Should still process the data as received from getDbStatus
@@ -210,7 +218,7 @@ describe('Database Status Route', () => {
210218 } ;
211219 mockGetDbStatus . mockReturnValue ( partialStatus as any ) ;
212220
213- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
221+ const handler = routeHandlers [ 'GET /db/status' ] ;
214222 await handler ( mockRequest , mockReply ) ;
215223
216224 expect ( mockReply . send ) . toHaveBeenCalledWith ( {
@@ -223,7 +231,7 @@ describe('Database Status Route', () => {
223231 it ( 'should handle getDbStatus returning empty object' , async ( ) => {
224232 mockGetDbStatus . mockReturnValue ( { } as any ) ;
225233
226- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
234+ const handler = routeHandlers [ 'GET /db/status' ] ;
227235 await handler ( mockRequest , mockReply ) ;
228236
229237 expect ( mockReply . send ) . toHaveBeenCalledWith ( {
@@ -239,7 +247,7 @@ describe('Database Status Route', () => {
239247 throw stringError ;
240248 } ) ;
241249
242- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
250+ const handler = routeHandlers [ 'GET /db/status' ] ;
243251 await handler ( mockRequest , mockReply ) ;
244252
245253 expect ( mockFastify . log ! . error ) . toHaveBeenCalledWith ( stringError , 'Error fetching database status' ) ;
@@ -255,17 +263,19 @@ describe('Database Status Route', () => {
255263 configured : true ,
256264 initialized : true ,
257265 dialect : DatabaseType . SQLite ,
266+ type : DatabaseType . SQLite ,
258267 } ;
259268 mockGetDbStatus . mockReturnValue ( originalStatus ) ;
260269
261- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
270+ const handler = routeHandlers [ 'GET /db/status' ] ;
262271 await handler ( mockRequest , mockReply ) ;
263272
264273 // Verify original object is unchanged
265274 expect ( originalStatus ) . toEqual ( {
266275 configured : true ,
267276 initialized : true ,
268277 dialect : 'sqlite' ,
278+ type : 'sqlite' ,
269279 } ) ;
270280
271281 // Verify the response was sent with correct typing
@@ -281,16 +291,18 @@ describe('Database Status Route', () => {
281291 configured : false ,
282292 initialized : false ,
283293 dialect : null ,
294+ type : null ,
284295 } ;
285296 const mockStatus2 = {
286297 configured : true ,
287298 initialized : true ,
288299 dialect : DatabaseType . SQLite ,
300+ type : DatabaseType . SQLite ,
289301 } ;
290302
291303 mockGetDbStatus . mockReturnValueOnce ( mockStatus1 ) . mockReturnValueOnce ( mockStatus2 ) ;
292304
293- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
305+ const handler = routeHandlers [ 'GET /db/status' ] ;
294306
295307 // First call
296308 await handler ( mockRequest , mockReply ) ;
@@ -325,7 +337,7 @@ describe('Database Status Route', () => {
325337 throw error ;
326338 } ) ;
327339
328- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
340+ const handler = routeHandlers [ 'GET /db/status' ] ;
329341 await handler ( mockRequest , mockReply ) ;
330342
331343 expect ( mockReply . status ) . toHaveBeenCalledWith ( 500 ) ;
@@ -340,7 +352,7 @@ describe('Database Status Route', () => {
340352 throw error ;
341353 } ) ;
342354
343- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
355+ const handler = routeHandlers [ 'GET /db/status' ] ;
344356 await handler ( mockRequest , mockReply ) ;
345357
346358 // Error message should be consistent regardless of the actual error
0 commit comments