Prechádzať zdrojové kódy

🔧 chore(test): 添加Agora相关测试调试信息

- 在AgoraSTTComponent集成测试中添加配置检查和API响应调试日志
- 在agora-token真实API测试中添加环境变量配置检查日志
- 在AgoraTokenService中添加Token生成参数和结果调试日志
- 修改测试setup文件,加载环境变量并保留console.debug用于调试
yourname 4 mesiacov pred
rodič
commit
da1061c69d

+ 10 - 0
src/client/admin/components/agora-stt/__integration_tests__/AgoraSTTComponent.integration.test.tsx

@@ -75,6 +75,12 @@ const mockUser = {
 // 只在有真实Agora配置时运行这些测试
 const hasRealAgoraConfig = process.env.AGORA_APP_ID && process.env.AGORA_APP_SECRET;
 
+// 调试信息
+console.debug('Agora配置检查:');
+console.debug('AGORA_APP_ID:', process.env.AGORA_APP_ID ? '已设置' : '未设置');
+console.debug('AGORA_APP_SECRET:', process.env.AGORA_APP_SECRET ? '已设置' : '未设置');
+console.debug('hasRealAgoraConfig:', hasRealAgoraConfig);
+
 
 describe('AgoraSTTComponent 真实API集成测试', () => {
   let client: ReturnType<typeof testClient<typeof agoraApiRoutes>>['api']['v1'];
@@ -117,9 +123,13 @@ describe('AgoraSTTComponent 真实API集成测试', () => {
       }
     });
 
+    console.debug('API响应状态:', response.status);
+    console.debug('API响应头:', response.headers);
+
     expect(response.status).toBe(200);
 
     const data = await response.json();
+    console.debug('API响应数据:', data);
 
     // 验证真实Token格式
     if ('token' in data) {

+ 6 - 0
src/server/api/agora/__tests__/agora-token.real-api.test.ts

@@ -6,6 +6,12 @@ import { authMiddleware } from '@/server/middleware/auth.middleware'
 // 只在有真实Agora配置时运行这些测试
 const hasRealAgoraConfig = process.env.AGORA_APP_ID && process.env.AGORA_APP_SECRET
 
+// 调试信息
+console.debug('Agora配置检查:')
+console.debug('AGORA_APP_ID:', process.env.AGORA_APP_ID ? '已设置' : '未设置')
+console.debug('AGORA_APP_SECRET:', process.env.AGORA_APP_SECRET ? '已设置' : '未设置')
+console.debug('hasRealAgoraConfig:', hasRealAgoraConfig)
+
 // Mock用户数据
 const mockUser = {
   id: 1,

+ 11 - 0
src/server/modules/agora/agora-token.service.ts

@@ -25,6 +25,14 @@ export class AgoraTokenService {
       const currentTimestamp = Math.floor(Date.now() / 1000)
       const privilegeExpiredTs = currentTimestamp + this.tokenExpiry
 
+      console.debug('生成RTC Token参数:', {
+        appId: this.appId ? '已设置' : '未设置',
+        appSecret: this.appSecret ? '已设置' : '未设置',
+        channelName,
+        userId,
+        privilegeExpiredTs
+      })
+
       const token = RtcTokenBuilder.buildTokenWithUid(
         this.appId,
         this.appSecret,
@@ -35,8 +43,11 @@ export class AgoraTokenService {
         0
       )
 
+      console.debug('生成的Token:', token)
+
       return token
     } catch (error) {
+      console.error('RTC Token生成错误:', error)
       throw new Error(`RTC Token生成失败: ${error instanceof Error ? error.message : '未知错误'}`)
     }
   }

+ 7 - 1
src/test/setup.ts

@@ -1,6 +1,10 @@
 // 测试环境全局设置
 import { beforeAll, afterAll, afterEach, vi, expect } from 'vitest';
 import * as matchers from '@testing-library/jest-dom/matchers';
+import dotenv from 'dotenv';
+
+// 加载环境变量
+dotenv.config();
 
 // 全局测试超时设置已在 vitest.config.ts 中配置
 
@@ -12,11 +16,13 @@ beforeAll(() => {
   // 设置测试环境变量
   process.env.NODE_ENV = 'test';
 
-  // 抑制控制台输出(测试中)
+  // 抑制控制台输出(测试中),但保留console.debug用于调试
   vi.spyOn(console, 'log').mockImplementation(() => {});
   vi.spyOn(console, 'error').mockImplementation(() => {});
   vi.spyOn(console, 'warn').mockImplementation(() => {});
   vi.spyOn(console, 'info').mockImplementation(() => {});
+
+  // console.debug保持可用,用于调试信息
 });
 
 // 全局测试后置清理