|
|
@@ -26,8 +26,10 @@ vi.mock('../../../server/routes/list-pages/generate-base-query', () => ({
|
|
|
}));
|
|
|
|
|
|
// 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({
|
|
|
skip: vi.fn().mockReturnThis(),
|
|
|
limit: vi.fn().mockReturnThis(),
|
|
|
@@ -39,8 +41,17 @@ vi.mock('mongoose', () => ({
|
|
|
}),
|
|
|
countDocuments: vi.fn().mockResolvedValue(0),
|
|
|
aggregate: vi.fn().mockResolvedValue([{ count: 5 }]),
|
|
|
- }),
|
|
|
-}));
|
|
|
+ });
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...actual,
|
|
|
+ default: {
|
|
|
+ ...actual.default,
|
|
|
+ model: createMockModel,
|
|
|
+ },
|
|
|
+ model: createMockModel,
|
|
|
+ };
|
|
|
+});
|
|
|
|
|
|
const TEST_PORT = 3001;
|
|
|
const TEST_SERVER_URL = `http://localhost:${TEST_PORT}`;
|
|
|
@@ -82,8 +93,11 @@ describe('useSWRxLsx integration tests', () => {
|
|
|
|
|
|
// Mock minimal GROWI-like structure for the middleware
|
|
|
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
|
|
|
@@ -98,15 +112,14 @@ describe('useSWRxLsx integration tests', () => {
|
|
|
});
|
|
|
|
|
|
afterAll(() => {
|
|
|
- return new Promise<void>((resolve) => {
|
|
|
- if (server) {
|
|
|
+ if (server) {
|
|
|
+ server.closeAllConnections?.();
|
|
|
+ return new Promise<void>((resolve) => {
|
|
|
server.close(() => {
|
|
|
resolve();
|
|
|
});
|
|
|
- } else {
|
|
|
- resolve();
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
it('should make actual server request and receive 2xx response for basic lsx request', async () => {
|