- root: bun workspaces via package.json, packageManager bun@1.4.0, scripts use bun --filter - backend: Bun.serve, bun test (vitest removed), bun --watch dev script, tsconfig types bun - tests: migrate 6 test files from vitest to bun:test (mock.module) - validate: replace @hono/zod-validator with hono validator + zod safeParse (fixes TS2589) - lockfile: bunfig.toml saveTextLockfile, regenerated bun.lock (text) for turbo - docs: AGENTS.md, README.md, stack.md updated to Bun stack
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { beforeEach, describe, expect, it, mock, vi } from 'bun:test';
|
|
import { Hono } from 'hono';
|
|
|
|
mock.module('@/lib/prisma', () => ({
|
|
default: {
|
|
$queryRaw: mock(),
|
|
},
|
|
getPrismaClient: mock(),
|
|
UnitOfWork: class {},
|
|
}));
|
|
|
|
import prisma from '@/lib/prisma';
|
|
import { healthCheckRoutes } from '@/modules/health-check';
|
|
|
|
const app = new Hono();
|
|
app.route('/health', healthCheckRoutes);
|
|
|
|
describe('health check routes', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('reports ok when the database answers', async () => {
|
|
prisma.$queryRaw.mockResolvedValue([{ '?column?': 1 }]);
|
|
|
|
const res = await app.request('/health');
|
|
|
|
expect(res.status).toBe(200);
|
|
const body = await res.json();
|
|
expect(body).toMatchObject({ status: 'ok', checks: { database: 'ok' } });
|
|
expect(typeof body.timestamp).toBe('string');
|
|
});
|
|
|
|
it('reports degraded when the database is unreachable', async () => {
|
|
prisma.$queryRaw.mockRejectedValue(new Error('connection refused'));
|
|
|
|
const res = await app.request('/health');
|
|
|
|
expect(res.status).toBe(503);
|
|
expect(await res.json()).toMatchObject({
|
|
code: 'database_unavailable',
|
|
status: 503,
|
|
});
|
|
});
|
|
}); |