test(01-01): add failing health test (RED gate)

- Tests GET /health returns 200 { ok, db } on success and 503 on DB error
- Fails because src/index.ts and src/routes/health.ts don't exist yet
This commit is contained in:
Lucas Berger
2026-06-04 09:50:43 -04:00
parent 3f591566d1
commit f31711af27
+41 -7
View File
@@ -1,16 +1,50 @@
/**
* Wave 0 stub — GET /health: 200 + real DB round-trip
* GET /health — end-to-end skeleton test
*
* This test is a RED stub. Implementation lives in:
* apps/api/src/routes/health.ts (Task 2)
* TDD RED: Tests written before implementation.
* These will fail until Task 2 creates apps/api/src/routes/health.ts
* and apps/api/src/index.ts.
*
* The test will be filled GREEN in Task 2 when the health route is implemented.
* Behavior (from plan):
* - GET /health returns 200 with { ok: true, db: "up" } after a real DB round-trip
* - GET /health returns 503 if the DB round-trip throws
*/
import { describe, it } from 'vitest'
import { describe, it, expect, vi, beforeEach } from 'vitest'
// We test the health route by importing the Hono app and calling it directly
// (no real DB needed — we mock the db module)
describe('GET /health', () => {
it.todo('returns 200 with { ok: true, db: "up" } after a real DB round-trip (Task 2)')
beforeEach(() => {
vi.resetModules()
})
it.todo('returns 503 if the DB round-trip throws (Task 2)')
it('returns 200 with { ok: true, db: "up" } when DB round-trip succeeds', async () => {
// Mock the db module so no real MariaDB is needed
vi.mock('../src/db/client.js', () => ({
db: {
execute: vi.fn().mockResolvedValue([[]]),
},
}))
const { app } = await import('../src/index.js')
const res = await app.request('/health')
expect(res.status).toBe(200)
const body = await res.json()
expect(body.ok).toBe(true)
expect(body.db).toBe('up')
})
it('returns 503 when DB round-trip throws', async () => {
vi.mock('../src/db/client.js', () => ({
db: {
execute: vi.fn().mockRejectedValue(new Error('DB connection failed')),
},
}))
const { app } = await import('../src/index.js')
const res = await app.request('/health')
expect(res.status).toBe(503)
})
})