diff --git a/dashboards/tracker-web/src/__tests__/health.test.ts b/dashboards/tracker-web/src/__tests__/health.test.ts index 165d885d..19bb805f 100644 --- a/dashboards/tracker-web/src/__tests__/health.test.ts +++ b/dashboards/tracker-web/src/__tests__/health.test.ts @@ -64,6 +64,49 @@ describe('GET /api/health', () => { }); }); + it('returns degraded when platform-service health check throws', async () => { + process.env.PLATFORM_API_URL = 'http://localhost:4003'; + process.env.JWT_SECRET = 'test-secret'; + process.env.DEFAULT_PRODUCT_ID = 'test-product'; + vi.stubGlobal( + 'fetch', + vi.fn(async () => { + throw new Error('connection refused'); + }) + ); + + const res = await GET(); + expect(res.status).toBe(503); + const data = await res.json(); + expect(data.status).toBe('degraded'); + expect(data.checks).toContainEqual({ + name: 'platform-service', + status: 'fail', + message: 'connection refused', + }); + }); + + it('returns a generic degraded message for non-Error platform failures', async () => { + process.env.PLATFORM_API_URL = 'http://localhost:4003'; + process.env.JWT_SECRET = 'test-secret'; + process.env.DEFAULT_PRODUCT_ID = 'test-product'; + vi.stubGlobal( + 'fetch', + vi.fn(async () => { + throw 'boom'; + }) + ); + + const res = await GET(); + expect(res.status).toBe(503); + const data = await res.json(); + expect(data.checks).toContainEqual({ + name: 'platform-service', + status: 'fail', + message: 'health check failed', + }); + }); + it('returns degraded when env vars are missing', async () => { delete process.env.PLATFORM_API_URL; delete process.env.JWT_SECRET;