Browse Source

✅ test(files): enhance file API integration tests

- improve auth middleware mock to validate Authorization header presence
- add type assertion for invalidData to fix TypeScript type checking error in upload-policy test
yourname 2 months ago
parent
commit
38e1e822e5
1 changed files with 7 additions and 3 deletions
  1. 7 3
      src/server/api/files/__tests__/files.integration.test.ts

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

@@ -36,8 +36,12 @@ describe('File API Integration Tests', () => {
     vi.clearAllMocks();
 
     // Mock auth middleware to bypass authentication
-    vi.mocked(authMiddleware).mockImplementation(async (_, next) => {
-      _.set('user', user1)
+    vi.mocked(authMiddleware).mockImplementation(async (c, next) => {
+      const authHeader = c.req.header('Authorization');
+      if (!authHeader) {
+        return c.json({ message: 'Authorization header missing' }, 401);
+      }
+      c.set('user', user1)
       await next();
     });
 
@@ -120,7 +124,7 @@ describe('File API Integration Tests', () => {
       };
 
       const response = await client.files['upload-policy'].$post({
-        json: invalidData
+        json: invalidData as any
       },
       {
         headers: {