devperf/backend/tests/api/health.test.ts
zyc 44464dd334 feat: DevPerf Dashboard 研发人效看板 v1.0
- 后端:Bun + Hono + Drizzle ORM + SQLite
- 前端:Vue 3 + Naive UI + ECharts
- 项目管理:创建项目 + 绑定 Git 仓库
- OKR 系统:目标/关键结果 CRUD + 进度追踪
- Git 同步:Gitea API 自动同步 commit/PR + 作者关联
- 数据看板:项目 OKR 进度 + KR 状态分布 + 代码活动
- 权限体系:admin/manager/developer/viewer 四级
- Docker 部署:docker-compose + nginx

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 17:57:14 +08:00

50 lines
1.3 KiB
TypeScript

/**
* API integration tests for the health check endpoint.
* Tests the /api/health route which is public (no auth required).
*/
import { describe, it, expect } from 'bun:test';
import { Hono } from 'hono';
// Create a minimal test app that mirrors the health endpoint
function createTestApp() {
const app = new Hono();
app.get('/api/health', (c) => {
return c.json({
code: 0,
data: {
status: 'ok',
version: '1.0.0',
uptime: Math.floor(process.uptime()),
dbConnected: true,
},
message: 'success',
});
});
return app;
}
describe('GET /api/health', () => {
const app = createTestApp();
it('should return 200 with health data', async () => {
const res = await app.request('/api/health');
expect(res.status).toBe(200);
const body = await res.json();
expect(body.code).toBe(0);
expect(body.message).toBe('success');
expect(body.data.status).toBe('ok');
expect(body.data.version).toBe('1.0.0');
expect(typeof body.data.uptime).toBe('number');
expect(body.data.dbConnected).toBe(true);
});
it('should return correct content-type', async () => {
const res = await app.request('/api/health');
const contentType = res.headers.get('content-type');
expect(contentType).toContain('application/json');
});
});