Skip to content

Commit ea46745

Browse files
fix(home): address CodeRabbit review — try/finally guards, 401 assertion
- Wrap config mutation tests with try/finally to prevent state leakage - Strengthen 401 assertion with status check - Clarify isSet JSDoc wording
1 parent 2b84b1a commit ea46745

1 file changed

Lines changed: 73 additions & 56 deletions

File tree

modules/home/tests/home.integration.tests.js

Lines changed: 73 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ describe('Home integration tests:', () => {
202202
test('should return 401 for unauthenticated user', async () => {
203203
const result = await agent.get('/api/admin/readiness').expect(401);
204204
expect(result.body).toBeDefined();
205+
expect(result.status).toBe(401);
205206
});
206207

207208
test('should return 403 for regular user', async () => {
@@ -240,83 +241,99 @@ describe('Home integration tests:', () => {
240241
const origPosthog = config.posthog;
241242
const origSentry = config.sentry;
242243
const mailerSpy = jest.spyOn(mailer, 'isConfigured').mockReturnValue(true);
243-
244-
config.domain = 'example.com';
245-
config.jwt.secret = 'a-real-custom-secret-key';
246-
config.oAuth = { google: { clientID: 'google-id' }, apple: { clientID: 'apple-id' } };
247-
config.stripe = { secretKey: 'sk_test_123' };
248-
config.posthog = { apiKey: 'phk_123' };
249-
config.sentry = { dsn: 'https://sentry.io/123' };
250-
251-
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(200);
252-
result.body.data.forEach((item) => {
253-
expect(item.status).toBe('ok');
254-
});
255-
// Verify OAuth message includes both providers
256-
const authCheck = result.body.data.find((c) => c.category === 'auth');
257-
expect(authCheck.message).toContain('Google');
258-
expect(authCheck.message).toContain('Apple');
259-
260-
config.domain = origDomain;
261-
config.jwt.secret = origJwt;
262-
config.oAuth = origOAuth;
263-
config.stripe = origStripe;
264-
config.posthog = origPosthog;
265-
config.sentry = origSentry;
266-
mailerSpy.mockRestore();
244+
try {
245+
config.domain = 'example.com';
246+
config.jwt.secret = 'a-real-custom-secret-key';
247+
config.oAuth = { google: { clientID: 'google-id' }, apple: { clientID: 'apple-id' } };
248+
config.stripe = { secretKey: 'sk_test_123' };
249+
config.posthog = { apiKey: 'phk_123' };
250+
config.sentry = { dsn: 'https://sentry.io/123' };
251+
252+
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(200);
253+
result.body.data.forEach((item) => {
254+
expect(item.status).toBe('ok');
255+
});
256+
// Verify OAuth message includes both providers
257+
const authCheck = result.body.data.find((c) => c.category === 'auth');
258+
expect(authCheck.message).toContain('Google');
259+
expect(authCheck.message).toContain('Apple');
260+
} finally {
261+
config.domain = origDomain;
262+
config.jwt.secret = origJwt;
263+
config.oAuth = origOAuth;
264+
config.stripe = origStripe;
265+
config.posthog = origPosthog;
266+
config.sentry = origSentry;
267+
mailerSpy.mockRestore();
268+
}
267269
});
268270

269271
test('should report warning when JWT secret is the default value', async () => {
270272
const origJwt = config.jwt.secret;
271-
config.jwt.secret = 'WaosSecretKeyExampleToChnageAbsolutely';
272-
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(200);
273-
const secCheck = result.body.data.find((c) => c.category === 'security');
274-
expect(secCheck.status).toBe('warning');
275-
expect(secCheck.message).toContain('default');
276-
config.jwt.secret = origJwt;
273+
try {
274+
config.jwt.secret = 'WaosSecretKeyExampleToChnageAbsolutely';
275+
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(200);
276+
const secCheck = result.body.data.find((c) => c.category === 'security');
277+
expect(secCheck.status).toBe('warning');
278+
expect(secCheck.message).toContain('default');
279+
} finally {
280+
config.jwt.secret = origJwt;
281+
}
277282
});
278283

279284
test('should report warning when domain is a DEVKIT placeholder', async () => {
280285
const origDomain = config.domain;
281-
config.domain = 'DEVKIT_NODE_DOMAIN';
282-
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(200);
283-
const cfgCheck = result.body.data.find((c) => c.category === 'config');
284-
expect(cfgCheck.status).toBe('warning');
285-
config.domain = origDomain;
286+
try {
287+
config.domain = 'DEVKIT_NODE_DOMAIN';
288+
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(200);
289+
const cfgCheck = result.body.data.find((c) => c.category === 'config');
290+
expect(cfgCheck.status).toBe('warning');
291+
} finally {
292+
config.domain = origDomain;
293+
}
286294
});
287295

288296
test('should handle only Google OAuth configured', async () => {
289297
const origOAuth = config.oAuth;
290-
config.oAuth = { google: { clientID: 'google-id' }, apple: {} };
291-
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(200);
292-
const authCheck = result.body.data.find((c) => c.category === 'auth');
293-
expect(authCheck.status).toBe('ok');
294-
expect(authCheck.message).toContain('Google');
295-
expect(authCheck.message).not.toContain('Apple');
296-
config.oAuth = origOAuth;
298+
try {
299+
config.oAuth = { google: { clientID: 'google-id' }, apple: {} };
300+
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(200);
301+
const authCheck = result.body.data.find((c) => c.category === 'auth');
302+
expect(authCheck.status).toBe('ok');
303+
expect(authCheck.message).toContain('Google');
304+
expect(authCheck.message).not.toContain('Apple');
305+
} finally {
306+
config.oAuth = origOAuth;
307+
}
297308
});
298309

299310
test('should report warning when config values are empty strings or whitespace', async () => {
300311
const origDomain = config.domain;
301312
const origStripe = config.stripe;
302-
config.domain = ' ';
303-
config.stripe = { secretKey: '' };
304-
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(200);
305-
const cfgCheck = result.body.data.find((c) => c.category === 'config');
306-
const billingCheck = result.body.data.find((c) => c.category === 'billing');
307-
expect(cfgCheck.status).toBe('warning');
308-
expect(billingCheck.status).toBe('warning');
309-
config.domain = origDomain;
310-
config.stripe = origStripe;
313+
try {
314+
config.domain = ' ';
315+
config.stripe = { secretKey: '' };
316+
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(200);
317+
const cfgCheck = result.body.data.find((c) => c.category === 'config');
318+
const billingCheck = result.body.data.find((c) => c.category === 'billing');
319+
expect(cfgCheck.status).toBe('warning');
320+
expect(billingCheck.status).toBe('warning');
321+
} finally {
322+
config.domain = origDomain;
323+
config.stripe = origStripe;
324+
}
311325
});
312326

313327
test('should report warning when JWT secret is empty', async () => {
314328
const origJwt = config.jwt.secret;
315-
config.jwt.secret = '';
316-
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(200);
317-
const secCheck = result.body.data.find((c) => c.category === 'security');
318-
expect(secCheck.status).toBe('warning');
319-
config.jwt.secret = origJwt;
329+
try {
330+
config.jwt.secret = '';
331+
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(200);
332+
const secCheck = result.body.data.find((c) => c.category === 'security');
333+
expect(secCheck.status).toBe('warning');
334+
} finally {
335+
config.jwt.secret = origJwt;
336+
}
320337
});
321338

322339
test('should return 422 when readiness service throws', async () => {

0 commit comments

Comments
 (0)