Procházet zdrojové kódy

✅ test(files): enhance file upload policy test cases

- add user1 and user1Response test data objects
- update auth middleware mock to use complete user object
- set uploadUser field to user1Response in mock response
- fix FileService mock type casting issue
- improve test data completeness for file upload policy tests
yourname před 2 měsíci
rodič
revize
7344de727a

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

@@ -14,6 +14,27 @@ describe('File API Integration Tests', () => {
   let client: ReturnType<typeof testClient<typeof fileApiRoutes>>['api']['v1'];
   // let mockFileService: FileService;
   let mockDataSource: DataSource;
+  const user1 = {
+    id: 1,
+    username: 'testuser',
+    password: 'password123',
+    phone: null,
+    email: null,
+    nickname: null,
+    name: null,
+    avatarFileId: null,
+    avatarFile: null,
+    isDisabled: 0,
+    isDeleted: 0,
+    roles: [],
+    createdAt: new Date(),
+    updatedAt: new Date()
+  };
+  const user1Response = {
+    ...user1,
+    createdAt: (user1.createdAt).toISOString(),
+    updatedAt: (user1.updatedAt).toISOString()
+  }
 
   beforeEach(async () => {
     vi.clearAllMocks();
@@ -22,9 +43,7 @@ describe('File API Integration Tests', () => {
 
     // Mock auth middleware to bypass authentication
     vi.mocked(authMiddleware).mockImplementation(async (_, next) => {
-      _.set('user', {
-        id: 1
-      })
+      _.set('user', user1)
       await next();
     });
 
@@ -55,7 +74,7 @@ describe('File API Integration Tests', () => {
           createdAt: (new Date()).toISOString(),
           updatedAt: (new Date()).toISOString(),
           fullUrl: 'https://minio.example.com/d8dai/1/test-uuid-123-test.txt',
-          uploadUser: {} as any,
+          uploadUser: user1Response,
           lastUpdated: null
         },
         uploadPolicy: {
@@ -71,9 +90,10 @@ describe('File API Integration Tests', () => {
         }
       };
 
+
       vi.mocked(FileService).mockImplementation(() => ({
         createFile: vi.fn().mockResolvedValue(mockResponse)
-      }))
+      } as unknown as FileService));
       const response = await client.files['upload-policy'].$post({
         json: mockFileData
       },