浏览代码

✅ test(files): enhance file API integration tests

- update multipart policy test to include fileKey, totalSize and partSize parameters
- add missing fields to mock response object: description, uploadUser, lastUpdated, fullUrl
- improve error messages by specifying missing required fields
- fix getList mock return value to match service response format [array with data and total count]
- remove redundant partCount parameter from test request data
yourname 2 月之前
父节点
当前提交
4bd2d18dfa
共有 1 个文件被更改,包括 13 次插入8 次删除
  1. 13 8
      src/server/api/files/__tests__/files.integration.test.ts

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

@@ -258,11 +258,12 @@ describe('File API Integration Tests', () => {
   describe('POST /api/v1/files/multipart-policy', () => {
     it('should generate multipart upload policy successfully', async () => {
       const mockRequestData = {
+        fileKey: 'large-file.zip',
+        totalSize: 1024 * 1024 * 100, // 100MB
+        partSize: 1024 * 1024 * 20, // 20MB
         name: 'large-file.zip',
         type: 'application/zip',
-        size: 1024 * 1024 * 100, // 100MB
-        uploadUserId: 1,
-        partCount: 5
+        uploadUserId: 1
       };
 
       const mockResponse = {
@@ -270,9 +271,13 @@ describe('File API Integration Tests', () => {
           id: 1,
           ...mockRequestData,
           path: '1/test-uuid-123-large-file.zip',
+          description: null,
+          uploadUser: {} as any,
           uploadTime: new Date(),
+          lastUpdated: null,
           createdAt: new Date(),
-          updatedAt: new Date()
+          updatedAt: new Date(),
+          fullUrl: Promise.resolve('https://minio.example.com/d8dai/1/test-uuid-123-large-file.zip')
         },
         uploadId: 'upload-123',
         uploadUrls: ['url1', 'url2', 'url3', 'url4', 'url5'],
@@ -308,7 +313,7 @@ describe('File API Integration Tests', () => {
     it('should validate multipart policy request data', async () => {
       const invalidData = {
         name: 'test.zip',
-        // Missing required fields
+        // Missing required fields: fileKey, totalSize, partSize
       };
 
       const response = await client.files['multipart-policy'].$post({
@@ -363,7 +368,7 @@ describe('File API Integration Tests', () => {
     it('should validate complete multipart request data', async () => {
       const invalidData = {
         uploadId: 'upload-123',
-        // Missing required fields
+        // Missing required fields: bucket, key, parts
       };
 
       const response = await client.files['multipart-complete'].$post({
@@ -420,7 +425,7 @@ describe('File API Integration Tests', () => {
         }
       ];
 
-      vi.spyOn(mockFileService, 'getList').mockResolvedValue(mockFiles as File[]);
+      vi.spyOn(mockFileService, 'getList').mockResolvedValue([mockFiles as File[], mockFiles.length]);
 
       const response = await client.files.$get({
         query: {}
@@ -472,7 +477,7 @@ describe('File API Integration Tests', () => {
         }
       ];
 
-      vi.spyOn(mockFileService, 'getList').mockResolvedValue(mockFiles as File[]);
+      vi.spyOn(mockFileService, 'getList').mockResolvedValue([mockFiles as File[], mockFiles.length]);
 
       const response = await client.files.$get({
         query: { keyword: 'document' }