Skip to content

Commit 33dbccb

Browse files
test(home): add readiness branch coverage and controller error tests
Cover all getReadinessStatus branches (ok/warning paths for each check category) and the readiness controller error handler to improve patch and project coverage.
1 parent 43d3ad9 commit 33dbccb

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,80 @@ describe('Home integration tests:', () => {
232232
expect(typeof item.message).toBe('string');
233233
});
234234
});
235+
236+
test('should report ok status when config values are properly set', async () => {
237+
const mailer = (await import('../../../lib/helpers/mailer/index.js')).default;
238+
const origDomain = config.domain;
239+
const origJwt = config.jwt.secret;
240+
const origOAuth = config.oAuth;
241+
const origStripe = config.stripe;
242+
const origPosthog = config.posthog;
243+
const origSentry = config.sentry;
244+
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();
269+
});
270+
271+
test('should report warning when JWT secret is the default value', async () => {
272+
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;
279+
});
280+
281+
test('should report warning when domain is a DEVKIT placeholder', async () => {
282+
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+
});
289+
290+
test('should handle only Google OAuth configured', async () => {
291+
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;
299+
});
300+
301+
test('should return 422 when readiness service throws', async () => {
302+
jest.spyOn(HomeService, 'getReadinessStatus').mockImplementationOnce(() => {
303+
throw new Error('config error');
304+
});
305+
const result = await agent.get('/api/admin/readiness').set('Cookie', `TOKEN=${adminToken}`).expect(422);
306+
expect(result.body.type).toBe('error');
307+
expect(result.body.description).toBe('config error.');
308+
});
235309
});
236310

237311
describe('Errors', () => {

0 commit comments

Comments
 (0)