Browse Source

✅ test(files): 启用文件上传策略无效请求测试用例
- 启用"should return 400 for invalid request data"测试用例,验证空文件名场景的错误处理

♻️ refactor(files): 移除调试日志
- 删除user和result的console.debug调试日志,优化生产环境代码

yourname 2 months ago
parent
commit
662bc173e8

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

@@ -113,23 +113,23 @@ describe('File API Integration Tests', () => {
       });
     });
 
-    // it('should return 400 for invalid request data', async () => {
-    //   const invalidData = {
-    //     name: '', // Empty name
-    //     type: 'text/plain'
-    //   };
+    it('should return 400 for invalid request data', async () => {
+      const invalidData = {
+        name: '', // Empty name
+        type: 'text/plain'
+      };
 
-    //   const response = await client.files['upload-policy'].$post({
-    //     json: invalidData
-    //   },
-    //   {
-    //     headers: {
-    //       'Authorization': 'Bearer test-token'
-    //     }
-    //   });
+      const response = await client.files['upload-policy'].$post({
+        json: invalidData
+      },
+      {
+        headers: {
+          'Authorization': 'Bearer test-token'
+        }
+      });
 
-    //   expect(response.status).toBe(400);
-    // });
+      expect(response.status).toBe(400);
+    });
 
     // it('should handle service errors gracefully', async () => {
     //   const mockFileData = {

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

@@ -61,8 +61,6 @@ const app = new OpenAPIHono<AuthContext>().openapi(createUploadPolicyRoute, asyn
   try {
     const data = await c.req.json();
     const user = c.get('user');
-
-    console.debug('user', user)
     
     // 创建文件服务实例
     const fileService = new FileService(AppDataSource);
@@ -74,7 +72,6 @@ const app = new OpenAPIHono<AuthContext>().openapi(createUploadPolicyRoute, asyn
       uploadTime: new Date()
     };
     const result = await fileService.createFile(fileData);
-    console.debug('result', result)
     const typedResult = await parseWithAwait(CreateFileResponseSchema, result);
     return c.json(typedResult, 200);
   } catch (error) {