소스 검색

✅ test(files): implement integration tests for multipart upload completion endpoint

- 取消注释并完善multipart-complete接口的测试套件
- 添加成功完成分片上传的测试用例
- 添加请求数据验证的测试用例
- 添加错误处理的测试用例
- 修复FileService的模拟实现方式,确保正确注入依赖
yourname 2 달 전
부모
커밋
5b8b9f7813
1개의 변경된 파일71개의 추가작업 그리고 65개의 파일을 삭제
  1. 71 65
      src/server/api/files/__tests__/files.integration.test.ts

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

@@ -392,82 +392,88 @@ describe('File API Integration Tests', () => {
     });
   });
 
-  // describe('POST /api/v1/files/multipart-complete', () => {
-  //   it('should complete multipart upload successfully', async () => {
-  //     const mockCompleteData = {
-  //       uploadId: 'upload-123',
-  //       bucket: 'd8dai',
-  //       key: '1/test-file.zip',
-  //       parts: [
-  //         { partNumber: 1, etag: 'etag1' },
-  //         { partNumber: 2, etag: 'etag2' }
-  //       ]
-  //     };
+  describe('POST /api/v1/files/multipart-complete', () => {
+    it('should complete multipart upload successfully', async () => {
+      const mockCompleteData = {
+        uploadId: 'upload-123',
+        bucket: 'd8dai',
+        key: '1/test-file.zip',
+        parts: [
+          { partNumber: 1, etag: 'etag1' },
+          { partNumber: 2, etag: 'etag2' }
+        ]
+      };
 
-  //     const mockResponse = {
-  //       fileId: 1,
-  //       url: 'https://minio.example.com/file.zip',
-  //       key: '1/test-file.zip',
-  //       size: 2048
-  //     };
+      const mockResponse = {
+        fileId: 1,
+        url: 'https://minio.example.com/file.zip',
+        key: '1/test-file.zip',
+        size: 2048
+      };
 
-  //     vi.mocked(mockFileService.completeMultipartUpload).mockResolvedValue(mockResponse);
+      const mockCompleteMultipartUpload = vi.fn().mockResolvedValue(mockResponse);
+      vi.mocked(FileService).mockImplementation(() => ({
+        completeMultipartUpload: mockCompleteMultipartUpload
+      } as unknown as FileService));
 
-  //     const response = await client.files['multipart-complete'].$post({
-  //       json: mockCompleteData
-  //     },
-  //     {
-  //       headers: {
-  //         'Authorization': 'Bearer test-token'
-  //       }
-  //     });
+      const response = await client.files['multipart-complete'].$post({
+        json: mockCompleteData
+      },
+      {
+        headers: {
+          'Authorization': 'Bearer test-token'
+        }
+      });
 
-  //     expect(response.status).toBe(200);
-  //     const result = await response.json();
-  //     expect(result).toEqual(mockResponse);
-  //     expect(mockFileService.completeMultipartUpload).toHaveBeenCalledWith(mockCompleteData);
-  //   });
+      expect(response.status).toBe(200);
+      const result = await response.json();
+      expect(result).toEqual(mockResponse);
+      expect(mockCompleteMultipartUpload).toHaveBeenCalledWith(mockCompleteData);
+    });
 
-  //   it('should validate complete multipart request data', async () => {
-  //     const invalidData = {
-  //       uploadId: 'upload-123',
-  //       // Missing required fields: bucket, key, parts
-  //     };
+    it('should validate complete multipart request data', async () => {
+      const invalidData = {
+        uploadId: 'upload-123',
+        // Missing required fields: bucket, key, parts
+      };
 
-  //     const response = await client.files['multipart-complete'].$post({
-  //       json: invalidData
-  //     },
-  //     {
-  //       headers: {
-  //         'Authorization': 'Bearer test-token'
-  //       }
-  //     });
+      const response = await client.files['multipart-complete'].$post({
+        json: invalidData as any
+      },
+      {
+        headers: {
+          'Authorization': 'Bearer test-token'
+        }
+      });
 
-  //     expect(response.status).toBe(400);
-  //   });
+      expect(response.status).toBe(400);
+    });
 
-  //   it('should handle completion errors', async () => {
-  //     const completeData = {
-  //       uploadId: 'upload-123',
-  //       bucket: 'd8dai',
-  //       key: '1/test-file.zip',
-  //       parts: [{ partNumber: 1, etag: 'etag1' }]
-  //     };
+    it('should handle completion errors', async () => {
+      const completeData = {
+        uploadId: 'upload-123',
+        bucket: 'd8dai',
+        key: '1/test-file.zip',
+        parts: [{ partNumber: 1, etag: 'etag1' }]
+      };
 
-  //     vi.mocked(mockFileService.completeMultipartUpload).mockRejectedValue(new Error('Completion failed'));
+      const mockCompleteMultipartUpload = vi.fn().mockRejectedValue(new Error('Completion failed'));
+      vi.mocked(FileService).mockImplementation(() => ({
+        completeMultipartUpload: mockCompleteMultipartUpload
+      } as unknown as FileService));
 
-  //     const response = await client.files['multipart-complete'].$post({
-  //       json: completeData
-  //     },
-  //     {
-  //       headers: {
-  //         'Authorization': 'Bearer test-token'
-  //       }
-  //     });
+      const response = await client.files['multipart-complete'].$post({
+        json: completeData
+      },
+      {
+        headers: {
+          'Authorization': 'Bearer test-token'
+        }
+      });
 
-  //     expect(response.status).toBe(500);
-  //   });
-  // });
+      expect(response.status).toBe(500);
+    });
+  });
 
   // describe('CRUD Operations', () => {
   //   it('should list files successfully', async () => {