Files
pn-new-crm/tests/integration/health-and-ready.test.ts

34 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

import { describe, it, expect } from 'vitest';
import { GET as healthGet } from '@/app/api/health/route';
import { GET as readyGet } from '@/app/api/ready/route';
describe('GET /api/health (liveness)', () => {
it('returns 200 + status=ok regardless of downstream dependency state', async () => {
const res = await healthGet();
expect(res.status).toBe(200);
const body = await res.json();
expect(body.status).toBe('ok');
expect(body.timestamp).toMatch(/^\d{4}-\d{2}-\d{2}T/);
});
});
describe('GET /api/ready (readiness)', () => {
it('returns ready=200 when postgres + redis + minio all answer', async () => {
// The dev/test environment has all three reachable; this covers the
// happy path. The degraded path is not exercised here because
// simulating a down dep without leaking into other tests is awkward;
// the route's logic is intentionally trivial (Promise.allSettled +
// every-ok check) and worth covering at the unit level only.
const res = await readyGet();
expect(res.status).toBe(200);
const body = await res.json();
expect(body.status).toBe('ready');
expect(body.checks).toEqual({
postgres: 'ok',
redis: 'ok',
minio: 'ok',
});
});
});