@@ -26,7 +26,9 @@ describe('Database Status Route', () => {
26
26
// Setup mock Fastify instance
27
27
mockFastify = {
28
28
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 ;
30
32
return mockFastify as FastifyInstance ;
31
33
} ) ,
32
34
log : {
@@ -51,14 +53,14 @@ describe('Database Status Route', () => {
51
53
it ( 'should register database status route' , async ( ) => {
52
54
await dbStatusRoute ( mockFastify as FastifyInstance ) ;
53
55
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 ) ) ;
55
57
} ) ;
56
58
57
59
it ( 'should register route with proper schema' , async ( ) => {
58
60
await dbStatusRoute ( mockFastify as FastifyInstance ) ;
59
61
60
62
const [ path , options ] = ( mockFastify . get as any ) . mock . calls [ 0 ] ;
61
- expect ( path ) . toBe ( '/api/ db/status' ) ;
63
+ expect ( path ) . toBe ( '/db/status' ) ;
62
64
expect ( options . schema ) . toBeDefined ( ) ;
63
65
expect ( options . schema . tags ) . toEqual ( [ 'Database' ] ) ;
64
66
expect ( options . schema . summary ) . toBe ( 'Get database status' ) ;
@@ -69,7 +71,7 @@ describe('Database Status Route', () => {
69
71
} ) ;
70
72
} ) ;
71
73
72
- describe ( 'GET /api/ db/status' , ( ) => {
74
+ describe ( 'GET /db/status' , ( ) => {
73
75
beforeEach ( async ( ) => {
74
76
await dbStatusRoute ( mockFastify as FastifyInstance ) ;
75
77
} ) ;
@@ -79,10 +81,11 @@ describe('Database Status Route', () => {
79
81
configured : true ,
80
82
initialized : true ,
81
83
dialect : DatabaseType . SQLite ,
84
+ type : DatabaseType . SQLite ,
82
85
} ;
83
86
mockGetDbStatus . mockReturnValue ( mockStatus ) ;
84
87
85
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
88
+ const handler = routeHandlers [ 'GET /db/status' ] ;
86
89
await handler ( mockRequest , mockReply ) ;
87
90
88
91
expect ( mockGetDbStatus ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -99,10 +102,11 @@ describe('Database Status Route', () => {
99
102
configured : false ,
100
103
initialized : false ,
101
104
dialect : null ,
105
+ type : null ,
102
106
} ;
103
107
mockGetDbStatus . mockReturnValue ( mockStatus ) ;
104
108
105
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
109
+ const handler = routeHandlers [ 'GET /db/status' ] ;
106
110
await handler ( mockRequest , mockReply ) ;
107
111
108
112
expect ( mockGetDbStatus ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -118,10 +122,11 @@ describe('Database Status Route', () => {
118
122
configured : true ,
119
123
initialized : false ,
120
124
dialect : DatabaseType . SQLite ,
125
+ type : DatabaseType . SQLite ,
121
126
} ;
122
127
mockGetDbStatus . mockReturnValue ( mockStatus ) ;
123
128
124
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
129
+ const handler = routeHandlers [ 'GET /db/status' ] ;
125
130
await handler ( mockRequest , mockReply ) ;
126
131
127
132
expect ( mockGetDbStatus ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -137,10 +142,11 @@ describe('Database Status Route', () => {
137
142
configured : false ,
138
143
initialized : false ,
139
144
dialect : null ,
145
+ type : null ,
140
146
} ;
141
147
mockGetDbStatus . mockReturnValue ( mockStatus ) ;
142
148
143
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
149
+ const handler = routeHandlers [ 'GET /db/status' ] ;
144
150
await handler ( mockRequest , mockReply ) ;
145
151
146
152
expect ( mockReply . send ) . toHaveBeenCalledWith ( {
@@ -155,10 +161,11 @@ describe('Database Status Route', () => {
155
161
configured : false ,
156
162
initialized : false ,
157
163
dialect : undefined ,
164
+ type : undefined ,
158
165
} ;
159
166
mockGetDbStatus . mockReturnValue ( mockStatus as any ) ;
160
167
161
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
168
+ const handler = routeHandlers [ 'GET /db/status' ] ;
162
169
await handler ( mockRequest , mockReply ) ;
163
170
164
171
expect ( mockReply . send ) . toHaveBeenCalledWith ( {
@@ -174,7 +181,7 @@ describe('Database Status Route', () => {
174
181
throw error ;
175
182
} ) ;
176
183
177
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
184
+ const handler = routeHandlers [ 'GET /db/status' ] ;
178
185
await handler ( mockRequest , mockReply ) ;
179
186
180
187
expect ( mockFastify . log ! . error ) . toHaveBeenCalledWith ( error , 'Error fetching database status' ) ;
@@ -189,10 +196,11 @@ describe('Database Status Route', () => {
189
196
configured : 'true' , // Should be boolean
190
197
initialized : 1 , // Should be boolean
191
198
dialect : 'postgres' , // Should be sqlite or null
199
+ type : 'postgres' ,
192
200
} ;
193
201
mockGetDbStatus . mockReturnValue ( invalidStatus as any ) ;
194
202
195
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
203
+ const handler = routeHandlers [ 'GET /db/status' ] ;
196
204
await handler ( mockRequest , mockReply ) ;
197
205
198
206
// Should still process the data as received from getDbStatus
@@ -210,7 +218,7 @@ describe('Database Status Route', () => {
210
218
} ;
211
219
mockGetDbStatus . mockReturnValue ( partialStatus as any ) ;
212
220
213
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
221
+ const handler = routeHandlers [ 'GET /db/status' ] ;
214
222
await handler ( mockRequest , mockReply ) ;
215
223
216
224
expect ( mockReply . send ) . toHaveBeenCalledWith ( {
@@ -223,7 +231,7 @@ describe('Database Status Route', () => {
223
231
it ( 'should handle getDbStatus returning empty object' , async ( ) => {
224
232
mockGetDbStatus . mockReturnValue ( { } as any ) ;
225
233
226
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
234
+ const handler = routeHandlers [ 'GET /db/status' ] ;
227
235
await handler ( mockRequest , mockReply ) ;
228
236
229
237
expect ( mockReply . send ) . toHaveBeenCalledWith ( {
@@ -239,7 +247,7 @@ describe('Database Status Route', () => {
239
247
throw stringError ;
240
248
} ) ;
241
249
242
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
250
+ const handler = routeHandlers [ 'GET /db/status' ] ;
243
251
await handler ( mockRequest , mockReply ) ;
244
252
245
253
expect ( mockFastify . log ! . error ) . toHaveBeenCalledWith ( stringError , 'Error fetching database status' ) ;
@@ -255,17 +263,19 @@ describe('Database Status Route', () => {
255
263
configured : true ,
256
264
initialized : true ,
257
265
dialect : DatabaseType . SQLite ,
266
+ type : DatabaseType . SQLite ,
258
267
} ;
259
268
mockGetDbStatus . mockReturnValue ( originalStatus ) ;
260
269
261
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
270
+ const handler = routeHandlers [ 'GET /db/status' ] ;
262
271
await handler ( mockRequest , mockReply ) ;
263
272
264
273
// Verify original object is unchanged
265
274
expect ( originalStatus ) . toEqual ( {
266
275
configured : true ,
267
276
initialized : true ,
268
277
dialect : 'sqlite' ,
278
+ type : 'sqlite' ,
269
279
} ) ;
270
280
271
281
// Verify the response was sent with correct typing
@@ -281,16 +291,18 @@ describe('Database Status Route', () => {
281
291
configured : false ,
282
292
initialized : false ,
283
293
dialect : null ,
294
+ type : null ,
284
295
} ;
285
296
const mockStatus2 = {
286
297
configured : true ,
287
298
initialized : true ,
288
299
dialect : DatabaseType . SQLite ,
300
+ type : DatabaseType . SQLite ,
289
301
} ;
290
302
291
303
mockGetDbStatus . mockReturnValueOnce ( mockStatus1 ) . mockReturnValueOnce ( mockStatus2 ) ;
292
304
293
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
305
+ const handler = routeHandlers [ 'GET /db/status' ] ;
294
306
295
307
// First call
296
308
await handler ( mockRequest , mockReply ) ;
@@ -325,7 +337,7 @@ describe('Database Status Route', () => {
325
337
throw error ;
326
338
} ) ;
327
339
328
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
340
+ const handler = routeHandlers [ 'GET /db/status' ] ;
329
341
await handler ( mockRequest , mockReply ) ;
330
342
331
343
expect ( mockReply . status ) . toHaveBeenCalledWith ( 500 ) ;
@@ -340,7 +352,7 @@ describe('Database Status Route', () => {
340
352
throw error ;
341
353
} ) ;
342
354
343
- const handler = routeHandlers [ 'GET /api/ db/status' ] ;
355
+ const handler = routeHandlers [ 'GET /db/status' ] ;
344
356
await handler ( mockRequest , mockReply ) ;
345
357
346
358
// Error message should be consistent regardless of the actual error
0 commit comments