import { describe, it, expect, vi } from 'vitest'; import { OpenAPIHono } from '@hono/zod-openapi'; import { createApiClient } from '../../__test_utils__/api-client'; // 简单的mock测试 describe('Basic API Integration Tests', () => { it('应该创建测试服务器并响应请求', async () => { // 创建简单的测试应用 const app = new OpenAPIHono(); // 添加一个简单的测试路由 app.get('/test', (c) => { return c.json({ message: 'Hello, test!' }); }); // 创建API客户端 const apiClient = createApiClient(app); // 发送请求 const response = await apiClient.get('/test'); // 验证响应 expect(response.status).toBe(200); expect(response.data).toEqual({ message: 'Hello, test!' }); }); it('应该处理404错误', async () => { const app = new OpenAPIHono(); const apiClient = createApiClient(app); const response = await apiClient.get('/non-existent'); expect(response.status).toBe(404); }); it('应该支持POST请求', async () => { const app = new OpenAPIHono(); app.post('/echo', async (c) => { const body = await c.req.json(); return c.json({ echoed: body }); }); const apiClient = createApiClient(app); const testData = { name: 'test', value: 123 }; const response = await apiClient.post('/echo', testData); expect(response.status).toBe(200); expect(response.data).toEqual({ echoed: testData }); }); });