添加后端集成测试套件
- 实现 82 个集成测试用例覆盖所有 API 端点 - 使用真实数据库连接,无 mock 逻辑 - 修复 PUT 请求只更新提供字段的逻辑 - 配置 Vitest 串行执行避免测试竞态 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6df528f187
commit
697430feed
18 files changed
+4333
-8
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import { beforeAll, afterAll, describe, it, expect } from 'vitest';
|
||||
import { createTestApp } from './helpers/app';
|
||||
import { cleanupDatabase, prisma } from './setup';
|
||||
|
||||
describe('健康检查 API', () => {
|
||||
let app: Awaited<ReturnType<typeof createTestApp>>;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await createTestApp();
|
||||
await cleanupDatabase();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
await cleanupDatabase();
|
||||
});
|
||||
|
||||
describe('GET /api/v1/health', () => {
|
||||
it('应返回健康状态', async () => {
|
||||
const response = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/health',
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
const body = JSON.parse(response.body);
|
||||
expect(body.success).toBe(true);
|
||||
expect(body.data.status).toBe('ok');
|
||||
expect(body.data.timestamp).toBeDefined();
|
||||
expect(body.data.version).toBe('1.0.0');
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /api/v1/health/detailed', () => {
|
||||
it('应返回详细的健康状态包括数据库检查', async () => {
|
||||
const response = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/health/detailed',
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
const body = JSON.parse(response.body);
|
||||
expect(body.success).toBe(true);
|
||||
expect(body.data.status).toBe('ok');
|
||||
expect(body.data.checks).toBeDefined();
|
||||
expect(body.data.checks.server).toBe('ok');
|
||||
expect(body.data.checks.database).toBe('ok');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user