Yuki Takei 2 ماه پیش
والد
کامیت
80af51cc5d
1فایلهای تغییر یافته به همراه25 افزوده شده و 12 حذف شده
  1. 25 12
      packages/remark-lsx/src/client/stores/lsx/lsx.spec.ts

+ 25 - 12
packages/remark-lsx/src/client/stores/lsx/lsx.spec.ts

@@ -26,8 +26,10 @@ vi.mock('../../../server/routes/list-pages/generate-base-query', () => ({
 }));
 }));
 
 
 // Mock mongoose model
 // Mock mongoose model
-vi.mock('mongoose', () => ({
-  model: vi.fn().mockReturnValue({
+vi.mock('mongoose', async (importOriginal) => {
+  const actual = await importOriginal<typeof import('mongoose')>();
+
+  const createMockModel = () => ({
     find: vi.fn().mockReturnValue({
     find: vi.fn().mockReturnValue({
       skip: vi.fn().mockReturnThis(),
       skip: vi.fn().mockReturnThis(),
       limit: vi.fn().mockReturnThis(),
       limit: vi.fn().mockReturnThis(),
@@ -39,8 +41,17 @@ vi.mock('mongoose', () => ({
     }),
     }),
     countDocuments: vi.fn().mockResolvedValue(0),
     countDocuments: vi.fn().mockResolvedValue(0),
     aggregate: vi.fn().mockResolvedValue([{ count: 5 }]),
     aggregate: vi.fn().mockResolvedValue([{ count: 5 }]),
-  }),
-}));
+  });
+
+  return {
+    ...actual,
+    default: {
+      ...actual.default,
+      model: createMockModel,
+    },
+    model: createMockModel,
+  };
+});
 
 
 const TEST_PORT = 3001;
 const TEST_PORT = 3001;
 const TEST_SERVER_URL = `http://localhost:${TEST_PORT}`;
 const TEST_SERVER_URL = `http://localhost:${TEST_PORT}`;
@@ -82,8 +93,11 @@ describe('useSWRxLsx integration tests', () => {
 
 
     // Mock minimal GROWI-like structure for the middleware
     // Mock minimal GROWI-like structure for the middleware
     const mockCrowi = {
     const mockCrowi = {
-      require: () => () => (req: any, res: any, next: any) => next(),
-      accessTokenParser: () => (req: any, res: any, next: any) => next(),
+      loginRequiredFactory: () => (req: any, res: any, next: any) => next(),
+      accessTokenParser: () => (req: any, res: any, next: any) => {
+        req.user = { _id: '507f1f77bcf86cd799439012', username: 'testuser' };
+        next();
+      },
     };
     };
 
 
     // Import and setup the LSX middleware
     // Import and setup the LSX middleware
@@ -98,15 +112,14 @@ describe('useSWRxLsx integration tests', () => {
   });
   });
 
 
   afterAll(() => {
   afterAll(() => {
-    return new Promise<void>((resolve) => {
-      if (server) {
+    if (server) {
+      server.closeAllConnections?.();
+      return new Promise<void>((resolve) => {
         server.close(() => {
         server.close(() => {
           resolve();
           resolve();
         });
         });
-      } else {
-        resolve();
-      }
-    });
+      });
+    }
   });
   });
 
 
   it('should make actual server request and receive 2xx response for basic lsx request', async () => {
   it('should make actual server request and receive 2xx response for basic lsx request', async () => {