Yuki Takei 6 месяцев назад
Родитель
Сommit
0f0f412a67

+ 6 - 19
apps/app/src/server/service/page-listing/page-listing.integ.ts

@@ -1,4 +1,5 @@
 import type { IPage, IUser } from '@growi/core/dist/interfaces';
+import { isValidObjectId } from '@growi/core/dist/utils/objectid-utils';
 import mongoose from 'mongoose';
 import type { HydratedDocument, Model } from 'mongoose';
 
@@ -44,8 +45,11 @@ describe('page-listing store integration tests', () => {
     expect(page.grant).toBeDefined();
     expect(typeof page.isEmpty).toBe('boolean');
     expect(typeof page.descendantCount).toBe('number');
-    expect(page.createdAt).toBeDefined();
-    expect(page.updatedAt).toBeDefined();
+    // revision is required when isEmpty is false
+    if (page.isEmpty === false) {
+      expect(page.revision).toBeDefined();
+      expect(isValidObjectId(page.revision)).toBe(true);
+    }
     // processData is optional
     if (page.processData !== undefined) {
       expect(page.processData).toBeInstanceOf(Object);
@@ -399,22 +403,5 @@ describe('page-listing store integration tests', () => {
       });
     });
 
-    test('should validate all required IPageForTreeItem fields are present and correctly typed', async() => {
-      const result = await pageListingService.findRootByViewer(testUser);
-
-      // These tests ensure that the 'any' return from exec() contains expected structure
-      const requiredFields = ['_id', 'path', 'grant', 'isEmpty', 'descendantCount', 'createdAt', 'updatedAt'];
-
-      requiredFields.forEach((field) => {
-        expect(result[field]).toBeDefined();
-      });
-
-      // Type-specific validations
-      expect(typeof result.path).toBe('string');
-      expect(typeof result.isEmpty).toBe('boolean');
-      expect(typeof result.descendantCount).toBe('number');
-      expect(result.createdAt instanceof Date || typeof result.createdAt === 'string').toBe(true);
-      expect(result.updatedAt instanceof Date || typeof result.updatedAt === 'string').toBe(true);
-    });
   });
 });

+ 2 - 2
apps/app/src/server/service/page-listing/page-listing.ts

@@ -40,7 +40,7 @@ class PageListingService implements IPageListingService {
     await builder.addViewerCondition(user);
 
     return builder.query
-      .select('_id path parent descendantCount grant isEmpty createdAt updatedAt wip')
+      .select('_id path parent revision descendantCount grant isEmpty wip')
       .lean()
       .exec();
   }
@@ -68,7 +68,7 @@ class PageListingService implements IPageListingService {
     const pages: HydratedDocument<Omit<IPageForTreeItem, 'processData'>>[] = await queryBuilder
       .addConditionToSortPagesByAscPath()
       .query
-      .select('_id path parent descendantCount grant isEmpty createdAt updatedAt wip')
+      .select('_id path parent revision descendantCount grant isEmpty wip')
       .lean()
       .exec();