yohei0125 4 лет назад
Родитель
Сommit
473fa79773
1 измененных файлов с 22 добавлено и 8 удалено
  1. 22 8
      packages/app/test/integration/models/v5.page.test.js

+ 22 - 8
packages/app/test/integration/models/v5.page.test.js

@@ -108,18 +108,19 @@ describe('Page', () => {
     const pageIdUpd6 = new mongoose.Types.ObjectId();
     const pageIdUpd6 = new mongoose.Types.ObjectId();
     const pageIdUpd7 = new mongoose.Types.ObjectId();
     const pageIdUpd7 = new mongoose.Types.ObjectId();
     const pageIdUpd8 = new mongoose.Types.ObjectId();
     const pageIdUpd8 = new mongoose.Types.ObjectId();
+    const pageIdUpd9 = new mongoose.Types.ObjectId();
 
 
     await Page.insertMany([
     await Page.insertMany([
       {
       {
         _id: pageIdUpd1,
         _id: pageIdUpd1,
-        path: '/mup1_emp',
+        path: '/mup13_top/mup1_emp',
         grant: Page.GRANT_PUBLIC,
         grant: Page.GRANT_PUBLIC,
-        parent: rootPage._id,
+        parent: pageIdUpd9._id,
         isEmpty: true,
         isEmpty: true,
       },
       },
       {
       {
         _id: pageIdUpd2,
         _id: pageIdUpd2,
-        path: '/mup1_emp/mup2_pub',
+        path: '/mup13_top/mup1_emp/mup2_pub',
         grant: Page.GRANT_PUBLIC,
         grant: Page.GRANT_PUBLIC,
         parent: pageIdUpd1._id,
         parent: pageIdUpd1._id,
         creator: dummyUser1,
         creator: dummyUser1,
@@ -183,6 +184,16 @@ describe('Page', () => {
         lastUpdateUser: dummyUser1._id,
         lastUpdateUser: dummyUser1._id,
         isEmpty: false,
         isEmpty: false,
       },
       },
+      {
+        _id: pageIdUpd9,
+        path: '/mup13_top',
+        grant: Page.GRANT_PUBLIC,
+        creator: dummyUser1,
+        lastUpdateUser: dummyUser1._id,
+        isEmpty: false,
+        parent: rootPage._id,
+        descendantCount: 2,
+      },
     ]);
     ]);
 
 
   });
   });
@@ -269,18 +280,21 @@ describe('Page', () => {
 
 
     describe('Changing grant from PUBLIC to RESTRICTED of', () => {
     describe('Changing grant from PUBLIC to RESTRICTED of', () => {
       test('an only-child page will delete its empty parent page', async() => {
       test('an only-child page will delete its empty parent page', async() => {
-        const page1 = await Page.findOne({ path: '/mup1_emp', isEmpty: true });
-        const page2 = await Page.findOne({ path: '/mup1_emp/mup2_pub' });
+        const top = await Page.findOne({ path: '/mup13_top', descendantCount: 2 });
+        const page1 = await Page.findOne({ path: '/mup13_top/mup1_emp', isEmpty: true });
+        const page2 = await Page.findOne({ path: '/mup13_top/mup1_emp/mup2_pub' });
         const options = { grant: 2, grantUserGroupId: null };
         const options = { grant: 2, grantUserGroupId: null };
-        expectAllToBeTruthy([page1, page2]);
+        expectAllToBeTruthy([top, page1, page2]);
 
 
         await Page.updatePage(page2, 'newRevisionBody', 'oldRevisionBody', dummyUser1, options);
         await Page.updatePage(page2, 'newRevisionBody', 'oldRevisionBody', dummyUser1, options);
         // AU => After Update
         // AU => After Update
-        const page1AU = await Page.findOne({ path: '/mup1_emp', isEmpty: true });
-        const page2AU = await Page.findOne({ path: '/mup1_emp/mup2_pub' });
+        const topAF = await Page.findOne({ _id: top._id });
+        const page1AU = await Page.findOne({ _id: page1._id });
+        const page2AU = await Page.findOne({ _id: page2._id });
 
 
         expect(page2AU).toBeTruthy();
         expect(page2AU).toBeTruthy();
         expect(page1AU).toBeNull();
         expect(page1AU).toBeNull();
+        expect(topAF.descendantCount).toBe(1);
       });
       });
       test('a page that has children will create an empty page with the same path and it becomes a new parent', async() => {
       test('a page that has children will create an empty page with the same path and it becomes a new parent', async() => {
         const page1 = await Page.findOne({ path: '/mup6_pub', grant: Page.GRANT_PUBLIC });
         const page1 = await Page.findOne({ path: '/mup6_pub', grant: Page.GRANT_PUBLIC });