@@ -204,6 +204,7 @@ describe('Home integration tests:', () => {
204204 test ( 'should return 401 for unauthenticated user' , async ( ) => {
205205 const result = await agent . get ( '/api/admin/readiness' ) . expect ( 401 ) ;
206206 expect ( result . body ) . toBeDefined ( ) ;
207+ expect ( result . status ) . toBe ( 401 ) ;
207208 } ) ;
208209
209210 test ( 'should return 403 for regular user' , async ( ) => {
@@ -242,83 +243,99 @@ describe('Home integration tests:', () => {
242243 const origPosthog = config . posthog ;
243244 const origSentry = config . sentry ;
244245 const mailerSpy = jest . spyOn ( mailer , 'isConfigured' ) . mockReturnValue ( true ) ;
245-
246- config . domain = 'example.com' ;
247- config . jwt . secret = 'a-real-custom-secret-key' ;
248- config . oAuth = { google : { clientID : 'google-id' } , apple : { clientID : 'apple-id' } } ;
249- config . stripe = { secretKey : 'sk_test_123' } ;
250- config . posthog = { apiKey : 'phk_123' } ;
251- config . sentry = { dsn : 'https://sentry.io/123' } ;
252-
253- const result = await agent . get ( '/api/admin/readiness' ) . set ( 'Cookie' , `TOKEN=${ adminToken } ` ) . expect ( 200 ) ;
254- result . body . data . forEach ( ( item ) => {
255- expect ( item . status ) . toBe ( 'ok' ) ;
256- } ) ;
257- // Verify OAuth message includes both providers
258- const authCheck = result . body . data . find ( ( c ) => c . category === 'auth' ) ;
259- expect ( authCheck . message ) . toContain ( 'Google' ) ;
260- expect ( authCheck . message ) . toContain ( 'Apple' ) ;
261-
262- config . domain = origDomain ;
263- config . jwt . secret = origJwt ;
264- config . oAuth = origOAuth ;
265- config . stripe = origStripe ;
266- config . posthog = origPosthog ;
267- config . sentry = origSentry ;
268- mailerSpy . mockRestore ( ) ;
246+ try {
247+ config . domain = 'example.com' ;
248+ config . jwt . secret = 'a-real-custom-secret-key' ;
249+ config . oAuth = { google : { clientID : 'google-id' } , apple : { clientID : 'apple-id' } } ;
250+ config . stripe = { secretKey : 'sk_test_123' } ;
251+ config . posthog = { apiKey : 'phk_123' } ;
252+ config . sentry = { dsn : 'https://sentry.io/123' } ;
253+
254+ const result = await agent . get ( '/api/admin/readiness' ) . set ( 'Cookie' , `TOKEN=${ adminToken } ` ) . expect ( 200 ) ;
255+ result . body . data . forEach ( ( item ) => {
256+ expect ( item . status ) . toBe ( 'ok' ) ;
257+ } ) ;
258+ // Verify OAuth message includes both providers
259+ const authCheck = result . body . data . find ( ( c ) => c . category === 'auth' ) ;
260+ expect ( authCheck . message ) . toContain ( 'Google' ) ;
261+ expect ( authCheck . message ) . toContain ( 'Apple' ) ;
262+ } finally {
263+ config . domain = origDomain ;
264+ config . jwt . secret = origJwt ;
265+ config . oAuth = origOAuth ;
266+ config . stripe = origStripe ;
267+ config . posthog = origPosthog ;
268+ config . sentry = origSentry ;
269+ mailerSpy . mockRestore ( ) ;
270+ }
269271 } ) ;
270272
271273 test ( 'should report warning when JWT secret is the default value' , async ( ) => {
272274 const origJwt = config . jwt . secret ;
273- config . jwt . secret = 'WaosSecretKeyExampleToChnageAbsolutely' ;
274- const result = await agent . get ( '/api/admin/readiness' ) . set ( 'Cookie' , `TOKEN=${ adminToken } ` ) . expect ( 200 ) ;
275- const secCheck = result . body . data . find ( ( c ) => c . category === 'security' ) ;
276- expect ( secCheck . status ) . toBe ( 'warning' ) ;
277- expect ( secCheck . message ) . toContain ( 'default' ) ;
278- config . jwt . secret = origJwt ;
275+ try {
276+ config . jwt . secret = 'WaosSecretKeyExampleToChnageAbsolutely' ;
277+ const result = await agent . get ( '/api/admin/readiness' ) . set ( 'Cookie' , `TOKEN=${ adminToken } ` ) . expect ( 200 ) ;
278+ const secCheck = result . body . data . find ( ( c ) => c . category === 'security' ) ;
279+ expect ( secCheck . status ) . toBe ( 'warning' ) ;
280+ expect ( secCheck . message ) . toContain ( 'default' ) ;
281+ } finally {
282+ config . jwt . secret = origJwt ;
283+ }
279284 } ) ;
280285
281286 test ( 'should report warning when domain is a DEVKIT placeholder' , async ( ) => {
282287 const origDomain = config . domain ;
283- config . domain = 'DEVKIT_NODE_DOMAIN' ;
284- const result = await agent . get ( '/api/admin/readiness' ) . set ( 'Cookie' , `TOKEN=${ adminToken } ` ) . expect ( 200 ) ;
285- const cfgCheck = result . body . data . find ( ( c ) => c . category === 'config' ) ;
286- expect ( cfgCheck . status ) . toBe ( 'warning' ) ;
287- config . domain = origDomain ;
288+ try {
289+ config . domain = 'DEVKIT_NODE_DOMAIN' ;
290+ const result = await agent . get ( '/api/admin/readiness' ) . set ( 'Cookie' , `TOKEN=${ adminToken } ` ) . expect ( 200 ) ;
291+ const cfgCheck = result . body . data . find ( ( c ) => c . category === 'config' ) ;
292+ expect ( cfgCheck . status ) . toBe ( 'warning' ) ;
293+ } finally {
294+ config . domain = origDomain ;
295+ }
288296 } ) ;
289297
290298 test ( 'should handle only Google OAuth configured' , async ( ) => {
291299 const origOAuth = config . oAuth ;
292- config . oAuth = { google : { clientID : 'google-id' } , apple : { } } ;
293- const result = await agent . get ( '/api/admin/readiness' ) . set ( 'Cookie' , `TOKEN=${ adminToken } ` ) . expect ( 200 ) ;
294- const authCheck = result . body . data . find ( ( c ) => c . category === 'auth' ) ;
295- expect ( authCheck . status ) . toBe ( 'ok' ) ;
296- expect ( authCheck . message ) . toContain ( 'Google' ) ;
297- expect ( authCheck . message ) . not . toContain ( 'Apple' ) ;
298- config . oAuth = origOAuth ;
300+ try {
301+ config . oAuth = { google : { clientID : 'google-id' } , apple : { } } ;
302+ const result = await agent . get ( '/api/admin/readiness' ) . set ( 'Cookie' , `TOKEN=${ adminToken } ` ) . expect ( 200 ) ;
303+ const authCheck = result . body . data . find ( ( c ) => c . category === 'auth' ) ;
304+ expect ( authCheck . status ) . toBe ( 'ok' ) ;
305+ expect ( authCheck . message ) . toContain ( 'Google' ) ;
306+ expect ( authCheck . message ) . not . toContain ( 'Apple' ) ;
307+ } finally {
308+ config . oAuth = origOAuth ;
309+ }
299310 } ) ;
300311
301312 test ( 'should report warning when config values are empty strings or whitespace' , async ( ) => {
302313 const origDomain = config . domain ;
303314 const origStripe = config . stripe ;
304- config . domain = ' ' ;
305- config . stripe = { secretKey : '' } ;
306- const result = await agent . get ( '/api/admin/readiness' ) . set ( 'Cookie' , `TOKEN=${ adminToken } ` ) . expect ( 200 ) ;
307- const cfgCheck = result . body . data . find ( ( c ) => c . category === 'config' ) ;
308- const billingCheck = result . body . data . find ( ( c ) => c . category === 'billing' ) ;
309- expect ( cfgCheck . status ) . toBe ( 'warning' ) ;
310- expect ( billingCheck . status ) . toBe ( 'warning' ) ;
311- config . domain = origDomain ;
312- config . stripe = origStripe ;
315+ try {
316+ config . domain = ' ' ;
317+ config . stripe = { secretKey : '' } ;
318+ const result = await agent . get ( '/api/admin/readiness' ) . set ( 'Cookie' , `TOKEN=${ adminToken } ` ) . expect ( 200 ) ;
319+ const cfgCheck = result . body . data . find ( ( c ) => c . category === 'config' ) ;
320+ const billingCheck = result . body . data . find ( ( c ) => c . category === 'billing' ) ;
321+ expect ( cfgCheck . status ) . toBe ( 'warning' ) ;
322+ expect ( billingCheck . status ) . toBe ( 'warning' ) ;
323+ } finally {
324+ config . domain = origDomain ;
325+ config . stripe = origStripe ;
326+ }
313327 } ) ;
314328
315329 test ( 'should report warning when JWT secret is empty' , async ( ) => {
316330 const origJwt = config . jwt . secret ;
317- config . jwt . secret = '' ;
318- const result = await agent . get ( '/api/admin/readiness' ) . set ( 'Cookie' , `TOKEN=${ adminToken } ` ) . expect ( 200 ) ;
319- const secCheck = result . body . data . find ( ( c ) => c . category === 'security' ) ;
320- expect ( secCheck . status ) . toBe ( 'warning' ) ;
321- config . jwt . secret = origJwt ;
331+ try {
332+ config . jwt . secret = '' ;
333+ const result = await agent . get ( '/api/admin/readiness' ) . set ( 'Cookie' , `TOKEN=${ adminToken } ` ) . expect ( 200 ) ;
334+ const secCheck = result . body . data . find ( ( c ) => c . category === 'security' ) ;
335+ expect ( secCheck . status ) . toBe ( 'warning' ) ;
336+ } finally {
337+ config . jwt . secret = origJwt ;
338+ }
322339 } ) ;
323340
324341 test ( 'should return 422 when readiness service throws' , async ( ) => {
0 commit comments