Procházet zdrojové kódy

✅ test(files): 完善文件上传策略测试并添加调试日志

- 为文件上传策略测试添加完整的uploadPolicy模拟数据,包括AWS签名相关字段
- 修复测试中mockFileService.createFile的调用方式
- 在文件上传策略API中添加调试日志,便于追踪fileService实例信息
yourname před 2 měsíci
rodič
revize
982a500324

+ 10 - 2
src/server/api/files/__tests__/files.integration.test.ts

@@ -57,16 +57,24 @@ describe('File API Integration Tests', () => {
           path: '1/test-uuid-123-test.txt',
           uploadTime: new Date(),
           createdAt: new Date(),
-          updatedAt: new Date()
+          updatedAt: new Date(),
+          fullUrl: Promise.resolve('https://minio.example.com/d8dai/1/test-uuid-123-test.txt'),
+          uploadUser: {} as any,
+          lastUpdated: null
         },
         uploadPolicy: {
+          'x-amz-algorithm': 'AWS4-HMAC-SHA256',
+          'x-amz-credential': 'test-credential',
+          'x-amz-date': '20250101T120000Z',
+          'x-amz-security-token': 'test-token',
+          policy: 'test-policy',
+          'x-amz-signature': 'test-signature',
           host: 'https://minio.example.com',
           key: '1/test-uuid-123-test.txt',
           bucket: 'd8dai'
         }
       };
 
-      // mockFileService.createFile = vi.fn().mockResolvedValue(mockResponse);
       vi.mocked(mockFileService.createFile).mockResolvedValue(mockResponse)
 
       const response = await client.files['upload-policy'].$post({

+ 1 - 0
src/server/api/files/upload-policy/post.ts

@@ -62,6 +62,7 @@ const app = new OpenAPIHono<AuthContext>().openapi(createUploadPolicyRoute, asyn
     
     // 创建文件服务实例
     const fileService = new FileService(AppDataSource);
+    console.debug('fileService', fileService)
     
     // 添加用户ID到文件数据
     const fileData = {