Przeglądaj źródła

♻️ refactor(test): 清理集成测试工具文件中未使用的代码

- 删除大量注释掉的未使用接口和函数定义
- 移除未使用的OpenAPIHono和testClient相关导入
- 删除未使用的setupIntegrationTestEnvironment和相关辅助函数
- 清理空行和格式,保持文件简洁
yourname 2 miesięcy temu
rodzic
commit
5cc5d4d437
1 zmienionych plików z 2 dodań i 113 usunięć
  1. 2 113
      src/server/__test_utils__/integration-test-utils.ts

+ 2 - 113
src/server/__test_utils__/integration-test-utils.ts

@@ -1,102 +1,8 @@
-import { OpenAPIHono } from '@hono/zod-openapi';
-import { testClient } from 'hono/testing';
+
 import { IntegrationTestDatabase } from './integration-test-db';
-import { DataSource } from 'typeorm';
 import { UserEntity } from '../modules/users/user.entity';
-import { Role } from '../modules/users/role.entity';
-import apiApp from '../api';
-
-// /**
-//  * 集成测试配置选项
-//  */
-// export interface IntegrationTestOptions {
-//   setupDatabase?: boolean;
-//   setupAuth?: boolean;
-//   setupMiddlewares?: boolean;
-// }
-
-// /**
-//  * 集成测试上下文
-//  */
-// export interface IntegrationTestContext {
-//   app: OpenAPIHono;
-//   client: ReturnType<typeof testClient<typeof apiApp>>;
-//   dataSource: DataSource | null;
-// }
-
-// // /**
-// //  * 创建集成测试应用实例
-// //  */
-// // export async function createIntegrationTestApp(
-// //   routes: any[],
-// //   options: IntegrationTestOptions = {}
-// // ): Promise<OpenAPIHono> {
-// //   // 使用主API应用,确保所有路由已注册
-// //   return apiApp;
-// // }
-
-// /**
-//  * 创建集成测试客户端(使用hono/testing的testClient)
-//  */
-// export function createIntegrationTestClient(
-//   app: OpenAPIHono,
-//   options: IntegrationTestOptions = {}
-// ): ReturnType<typeof testClient<typeof apiApp>> {
-//   const client = testClient(app);
-
-//   // 设置默认认证头(如果需要)
-//   if (options.setupAuth !== false) {
-//     // testClient会自动处理header,这里不需要额外设置
-//   }
-
-//   return client;
-// }
-
-// /**
-//  * 设置集成测试环境
-//  */
-// export async function setupIntegrationTestEnvironment(
-//   routes: any[],
-//   options: IntegrationTestOptions = {}
-// ): Promise<IntegrationTestContext> {
-//   const {
-//     setupDatabase = true,
-//     setupAuth = true,
-//     setupMiddlewares = true
-//   } = options;
 
-//   // 创建测试应用
-//   // const app = await createIntegrationTestApp(routes, options);
 
-//   // 初始化数据库(如果需要)
-//   let dataSource: DataSource | null = null;
-//   if (setupDatabase) {
-//     dataSource = await IntegrationTestDatabase.initialize();
-//   }
-
-//   // 创建API客户端
-//   const client = createIntegrationTestClient(app, { setupAuth });
-
-//   return {
-//     app,
-//     client,
-//     dataSource
-//   };
-// }
-
-// /**
-//  * 清理集成测试环境
-//  */
-// export async function cleanupIntegrationTestEnvironment(): Promise<void> {
-//   await IntegrationTestDatabase.clearAllData();
-//   await IntegrationTestDatabase.cleanup();
-// }
-
-// /**
-//  * 测试数据工厂函数
-//  * 使用integration-test-db.ts中的TestDataFactory
-//  */
-// export { TestDataFactory } from './integration-test-db';
 
 /**
  * 集成测试断言工具
@@ -166,21 +72,4 @@ export class IntegrationTestAssertions {
       throw new Error(`Expected user ${username} not to exist in database`);
     }
   }
-}
-
-// /**
-//  * 集成测试生命周期钩子
-//  */
-// export function setupIntegrationTestHooks() {
-//   beforeEach(async () => {
-//     await IntegrationTestDatabase.initialize();
-//   });
-
-//   afterEach(async () => {
-//     await IntegrationTestDatabase.clearAllData();
-//   });
-
-//   afterAll(async () => {
-//     await IntegrationTestDatabase.cleanup();
-//   });
-// }
+}