50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
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');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|