test(tracker-web): cover platform health failures
This commit is contained in:
parent
67104b8ebc
commit
5606ccf1f7
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user