test(tracker-web): cover platform health failures
Some checks failed
Publish @bytelyst/* packages / publish (push) Failing after 17s
CI — Common Platform / Build, Test & Typecheck (push) Successful in 49s

This commit is contained in:
Saravana Kumar 2026-05-30 19:38:49 +00:00
parent 67104b8ebc
commit 5606ccf1f7

View File

@ -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;