yohei0125 4 лет назад
Родитель
Сommit
e0d5197baa
1 измененных файлов с 47 добавлено и 30 удалено
  1. 47 30
      packages/app/test/integration/service/v5.non-public-page.test.ts

+ 47 - 30
packages/app/test/integration/service/v5.non-public-page.test.ts

@@ -32,14 +32,6 @@ describe('PageService page operations with non-public pages', () => {
 
 
   let rootPage;
   let rootPage;
 
 
-  // pass unless the data is one of [false, 0, '', null, undefined, NaN]
-  const expectAllToBeTruthy = (dataList) => {
-    dataList.forEach((data, i) => {
-      if (data == null) { console.log(`index: ${i}`) }
-      expect(data).toBeTruthy();
-    });
-  };
-
   /**
   /**
    * Rename
    * Rename
    */
    */
@@ -432,7 +424,9 @@ describe('PageService page operations with non-public pages', () => {
       const page3 = await Page.findOne({
       const page3 = await Page.findOne({
         path: path3BR, grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdC, parent: page2._id,
         path: path3BR, grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdC, parent: page2._id,
       });
       });
-      expectAllToBeTruthy([page1, page2, page3]);
+      expect(page1).toBeTruthy();
+      expect(page2).toBeTruthy();
+      expect(page3).toBeTruthy();
 
 
       const newPathForChild = '/np_rename1_destination/np_rename2';
       const newPathForChild = '/np_rename1_destination/np_rename2';
       const newPathForGrandchild = '/np_rename1_destination/np_rename2/np_rename3';
       const newPathForGrandchild = '/np_rename1_destination/np_rename2/np_rename3';
@@ -440,17 +434,15 @@ describe('PageService page operations with non-public pages', () => {
 
 
       const renamedPage = await Page.findOne({ path: newPathForChild });
       const renamedPage = await Page.findOne({ path: newPathForChild });
       const renamedGrandchild = await Page.findOne({ path: newPathForGrandchild });
       const renamedGrandchild = await Page.findOne({ path: newPathForGrandchild });
-
       const childPageBR = await Page.findOne({ path: path2BR });
       const childPageBR = await Page.findOne({ path: path2BR });
       const grandchildBR = await Page.findOne({ path: path3BR });
       const grandchildBR = await Page.findOne({ path: path3BR });
-      expectAllToBeTruthy([renamedPage, renamedGrandchild]);
+      expect(renamedPage).toBeTruthy();
+      expect(renamedGrandchild).toBeTruthy();
       expect(childPageBR).toBeNull();
       expect(childPageBR).toBeNull();
       expect(grandchildBR).toBeNull();
       expect(grandchildBR).toBeNull();
-
       expect(xssSpy).toHaveBeenCalled();
       expect(xssSpy).toHaveBeenCalled();
       expect(renamedPage.parent).toStrictEqual(page1._id);
       expect(renamedPage.parent).toStrictEqual(page1._id);
       expect(renamedGrandchild.parent).toStrictEqual(renamedPage._id);
       expect(renamedGrandchild.parent).toStrictEqual(renamedPage._id);
-
       expect(renamedPage.grantedGroup).toStrictEqual(page2.grantedGroup);
       expect(renamedPage.grantedGroup).toStrictEqual(page2.grantedGroup);
       expect(renamedGrandchild.grantedGroup).toStrictEqual(page3.grantedGroup);
       expect(renamedGrandchild.grantedGroup).toStrictEqual(page3.grantedGroup);
     });
     });
@@ -464,7 +456,9 @@ describe('PageService page operations with non-public pages', () => {
       const grandchildPage = await Page.findOne({
       const grandchildPage = await Page.findOne({
         parent: childPage._id, path: path3BR, grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdB, // groupIdB
         parent: childPage._id, path: path3BR, grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdB, // groupIdB
       });
       });
-      expectAllToBeTruthy([page1, childPage, grandchildPage]);
+      expect(page1).toBeTruthy();
+      expect(childPage).toBeTruthy();
+      expect(grandchildPage).toBeTruthy();
 
 
       const newPath1 = '/np_rename4_destination/np_rename5';
       const newPath1 = '/np_rename4_destination/np_rename5';
       const newPath2 = '/np_rename4_destination/np_rename5/np_rename6';
       const newPath2 = '/np_rename4_destination/np_rename5/np_rename6';
@@ -483,7 +477,8 @@ describe('PageService page operations with non-public pages', () => {
       const grandChildPageBR = await Page.findOne({ path: path3BR });
       const grandChildPageBR = await Page.findOne({ path: path3BR });
       const renamedChildPage = await Page.findOne({ path: newPath1 });
       const renamedChildPage = await Page.findOne({ path: newPath1 });
       const renamedGrandchildPage = await Page.findOne({ path: newPath2 });
       const renamedGrandchildPage = await Page.findOne({ path: newPath2 });
-      expectAllToBeTruthy([childPageBR, grandChildPageBR]);
+      expect(childPageBR).toBeTruthy();
+      expect(grandChildPageBR).toBeTruthy();
       expect(renamedChildPage).toBeNull();
       expect(renamedChildPage).toBeNull();
       expect(renamedGrandchildPage).toBeNull();
       expect(renamedGrandchildPage).toBeNull();
 
 
@@ -497,7 +492,9 @@ describe('PageService page operations with non-public pages', () => {
       const childPage = await Page.findOne({ path: path2BR, grant: Page.GRANT_RESTRICTED });
       const childPage = await Page.findOne({ path: path2BR, grant: Page.GRANT_RESTRICTED });
       const grandchild = await Page.findOne({ path: path3BR, grant: Page.GRANT_RESTRICTED });
       const grandchild = await Page.findOne({ path: path3BR, grant: Page.GRANT_RESTRICTED });
 
 
-      expectAllToBeTruthy([destinationPage, childPage, grandchild]);
+      expect(destinationPage).toBeTruthy();
+      expect(childPage).toBeTruthy();
+      expect(grandchild).toBeTruthy();
 
 
       const newPathForChild = '/np_rename7_destination/np_rename8';
       const newPathForChild = '/np_rename7_destination/np_rename8';
       const newPathForGrandchild = '/np_rename7_destination/np_rename8/np_rename9';
       const newPathForGrandchild = '/np_rename7_destination/np_rename8/np_rename9';
@@ -507,7 +504,8 @@ describe('PageService page operations with non-public pages', () => {
       const renamedGrandChild = await Page.findOne({ path: newPathForGrandchild });
       const renamedGrandChild = await Page.findOne({ path: newPathForGrandchild });
       const childPageBeforeRename = await Page.findOne({ path: path2BR });
       const childPageBeforeRename = await Page.findOne({ path: path2BR });
       const grandchildBeforeRename = await Page.findOne({ path: path3BR });
       const grandchildBeforeRename = await Page.findOne({ path: path3BR });
-      expectAllToBeTruthy([renamedChildPage, grandchildBeforeRename]);
+      expect(renamedChildPage).toBeTruthy();
+      expect(grandchildBeforeRename).toBeTruthy();
       expect(renamedGrandChild).toBeNull();
       expect(renamedGrandChild).toBeNull();
       expect(childPageBeforeRename).toBeNull();
       expect(childPageBeforeRename).toBeNull();
 
 
@@ -552,14 +550,18 @@ describe('PageService page operations with non-public pages', () => {
       const revision = await Revision.findOne({ pageId: trashedPage._id });
       const revision = await Revision.findOne({ pageId: trashedPage._id });
       const tag = await Tag.findOne({ name: 'np_revertTag1' });
       const tag = await Tag.findOne({ name: 'np_revertTag1' });
       const deletedPageTagRelation = await PageTagRelation.findOne({ relatedPage: trashedPage._id, relatedTag: tag._id, isPageTrashed: true });
       const deletedPageTagRelation = await PageTagRelation.findOne({ relatedPage: trashedPage._id, relatedTag: tag._id, isPageTrashed: true });
-      expectAllToBeTruthy([trashedPage, revision, tag, deletedPageTagRelation]);
+      expect(trashedPage).toBeTruthy();
+      expect(revision).toBeTruthy();
+      expect(tag).toBeTruthy();
+      expect(deletedPageTagRelation).toBeTruthy();
 
 
       await revertDeletedPage(trashedPage, dummyUser1, {}, false);
       await revertDeletedPage(trashedPage, dummyUser1, {}, false);
+
       const revertedPage = await Page.findOne({ path: '/np_revert1' });
       const revertedPage = await Page.findOne({ path: '/np_revert1' });
       const deltedPageBeforeRevert = await Page.findOne({ path: '/trash/np_revert1' });
       const deltedPageBeforeRevert = await Page.findOne({ path: '/trash/np_revert1' });
       const pageTagRelation = await PageTagRelation.findOne({ relatedPage: revertedPage._id, relatedTag: tag._id });
       const pageTagRelation = await PageTagRelation.findOne({ relatedPage: revertedPage._id, relatedTag: tag._id });
-      expectAllToBeTruthy([revertedPage, pageTagRelation]);
-
+      expect(revertedPage).toBeTruthy();
+      expect(pageTagRelation).toBeTruthy();
       expect(deltedPageBeforeRevert).toBeNull();
       expect(deltedPageBeforeRevert).toBeNull();
 
 
       // page with GRANT_RESTRICTED does not have parent
       // page with GRANT_RESTRICTED does not have parent
@@ -575,13 +577,18 @@ describe('PageService page operations with non-public pages', () => {
       const revision = await Revision.findOne({ pageId: trashedPage._id });
       const revision = await Revision.findOne({ pageId: trashedPage._id });
       const tag = await Tag.findOne({ name: 'np_revertTag2' });
       const tag = await Tag.findOne({ name: 'np_revertTag2' });
       const deletedPageTagRelation = await PageTagRelation.findOne({ relatedPage: trashedPage._id, relatedTag: tag._id, isPageTrashed: true });
       const deletedPageTagRelation = await PageTagRelation.findOne({ relatedPage: trashedPage._id, relatedTag: tag._id, isPageTrashed: true });
-      expectAllToBeTruthy([trashedPage, revision, tag, deletedPageTagRelation]);
+      expect(trashedPage).toBeTruthy();
+      expect(revision).toBeTruthy();
+      expect(tag).toBeTruthy();
+      expect(deletedPageTagRelation).toBeTruthy();
 
 
       await revertDeletedPage(trashedPage, user1, {}, false);
       await revertDeletedPage(trashedPage, user1, {}, false);
+
       const revertedPage = await Page.findOne({ path: '/np_revert2' });
       const revertedPage = await Page.findOne({ path: '/np_revert2' });
       const trashedPageBR = await Page.findOne({ path: beforeRevertPath });
       const trashedPageBR = await Page.findOne({ path: beforeRevertPath });
       const pageTagRelation = await PageTagRelation.findOne({ relatedPage: revertedPage._id, relatedTag: tag._id });
       const pageTagRelation = await PageTagRelation.findOne({ relatedPage: revertedPage._id, relatedTag: tag._id });
-      expectAllToBeTruthy([revertedPage, pageTagRelation]);
+      expect(revertedPage).toBeTruthy();
+      expect(pageTagRelation).toBeTruthy();
       expect(trashedPageBR).toBeNull();
       expect(trashedPageBR).toBeNull();
 
 
       expect(revertedPage.parent).toStrictEqual(rootPage._id);
       expect(revertedPage.parent).toStrictEqual(rootPage._id);
@@ -598,9 +605,13 @@ describe('PageService page operations with non-public pages', () => {
       const trashedPage2 = await Page.findOne({ path: beforeRevertPath2, status: Page.STATUS_DELETED, grant: Page.GRANT_RESTRICTED });
       const trashedPage2 = await Page.findOne({ path: beforeRevertPath2, status: Page.STATUS_DELETED, grant: Page.GRANT_RESTRICTED });
       const revision1 = await Revision.findOne({ pageId: trashedPage1._id });
       const revision1 = await Revision.findOne({ pageId: trashedPage1._id });
       const revision2 = await Revision.findOne({ pageId: trashedPage2._id });
       const revision2 = await Revision.findOne({ pageId: trashedPage2._id });
-      expectAllToBeTruthy([trashedPage1, trashedPage2, revision1, revision2]);
+      expect(trashedPage1).toBeTruthy();
+      expect(trashedPage2).toBeTruthy();
+      expect(revision1).toBeTruthy();
+      expect(revision2).toBeTruthy();
 
 
       await revertDeletedPage(trashedPage1, npDummyUser2, {}, true);
       await revertDeletedPage(trashedPage1, npDummyUser2, {}, true);
+
       const revertedPage = await Page.findOne({ path: '/np_revert3' });
       const revertedPage = await Page.findOne({ path: '/np_revert3' });
       const middlePage = await Page.findOne({ path: '/np_revert3/middle' });
       const middlePage = await Page.findOne({ path: '/np_revert3/middle' });
       const notRestrictedPage = await Page.findOne({ path: '/np_revert3/middle/np_revert4' });
       const notRestrictedPage = await Page.findOne({ path: '/np_revert3/middle/np_revert4' });
@@ -609,11 +620,14 @@ describe('PageService page operations with non-public pages', () => {
       const trashedPage2AR = await Page.findOne({ path: beforeRevertPath2 });
       const trashedPage2AR = await Page.findOne({ path: beforeRevertPath2 });
       const revision1AR = await Revision.findOne({ pageId: revertedPage._id });
       const revision1AR = await Revision.findOne({ pageId: revertedPage._id });
       const revision2AR = await Revision.findOne({ pageId: trashedPage2AR._id });
       const revision2AR = await Revision.findOne({ pageId: trashedPage2AR._id });
-      expectAllToBeTruthy([revertedPage, trashedPage2AR, revision1AR, revision2AR]);
+
+      expect(revertedPage).toBeTruthy();
+      expect(trashedPage2AR).toBeTruthy();
+      expect(revision1AR).toBeTruthy();
+      expect(revision2AR).toBeTruthy();
       expect(trashedPage1AR).toBeNull();
       expect(trashedPage1AR).toBeNull();
       expect(notRestrictedPage).toBeNull();
       expect(notRestrictedPage).toBeNull();
       expect(middlePage).toBeNull();
       expect(middlePage).toBeNull();
-
       expect(revertedPage.parent).toStrictEqual(rootPage._id);
       expect(revertedPage.parent).toStrictEqual(rootPage._id);
       expect(revertedPage.status).toBe(Page.STATUS_PUBLISHED);
       expect(revertedPage.status).toBe(Page.STATUS_PUBLISHED);
       expect(revertedPage.grant).toBe(Page.GRANT_PUBLIC);
       expect(revertedPage.grant).toBe(Page.GRANT_PUBLIC);
@@ -628,7 +642,11 @@ describe('PageService page operations with non-public pages', () => {
       const nonExistantPage3 = await Page.findOne({ path: beforeRevertPath3 }); // not exist
       const nonExistantPage3 = await Page.findOne({ path: beforeRevertPath3 }); // not exist
       const revision1 = await Revision.findOne({ pageId: trashedPage1._id });
       const revision1 = await Revision.findOne({ pageId: trashedPage1._id });
       const revision2 = await Revision.findOne({ pageId: trashedPage2._id });
       const revision2 = await Revision.findOne({ pageId: trashedPage2._id });
-      expectAllToBeTruthy([trashedPage1, trashedPage2, revision1, revision2, user]);
+      expect(trashedPage1).toBeTruthy();
+      expect(trashedPage2).toBeTruthy();
+      expect(revision1).toBeTruthy();
+      expect(revision2).toBeTruthy();
+      expect(user).toBeTruthy();
       expect(nonExistantPage3).toBeNull();
       expect(nonExistantPage3).toBeNull();
 
 
       await revertDeletedPage(trashedPage1, user, {}, true);
       await revertDeletedPage(trashedPage1, user, {}, true);
@@ -639,20 +657,19 @@ describe('PageService page operations with non-public pages', () => {
       // // AR => After Revert
       // // AR => After Revert
       const trashedPage1AR = await Page.findOne({ path: beforeRevertPath1 });
       const trashedPage1AR = await Page.findOne({ path: beforeRevertPath1 });
       const trashedPage2AR = await Page.findOne({ path: beforeRevertPath2 });
       const trashedPage2AR = await Page.findOne({ path: beforeRevertPath2 });
-      expectAllToBeTruthy([revertedPage1, newlyCreatedPage, revertedPage2]);
+      expect(revertedPage1).toBeTruthy();
+      expect(newlyCreatedPage).toBeTruthy();
+      expect(revertedPage2).toBeTruthy();
       expect(trashedPage1AR).toBeNull();
       expect(trashedPage1AR).toBeNull();
       expect(trashedPage2AR).toBeNull();
       expect(trashedPage2AR).toBeNull();
 
 
       expect(newlyCreatedPage.isEmpty).toBe(true);
       expect(newlyCreatedPage.isEmpty).toBe(true);
-
       expect(revertedPage1.parent).toStrictEqual(rootPage._id);
       expect(revertedPage1.parent).toStrictEqual(rootPage._id);
       expect(revertedPage2.parent).toStrictEqual(newlyCreatedPage._id);
       expect(revertedPage2.parent).toStrictEqual(newlyCreatedPage._id);
       expect(newlyCreatedPage.parent).toStrictEqual(revertedPage1._id);
       expect(newlyCreatedPage.parent).toStrictEqual(revertedPage1._id);
-
       expect(revertedPage1.status).toBe(Page.STATUS_PUBLISHED);
       expect(revertedPage1.status).toBe(Page.STATUS_PUBLISHED);
       expect(revertedPage2.status).toBe(Page.STATUS_PUBLISHED);
       expect(revertedPage2.status).toBe(Page.STATUS_PUBLISHED);
       expect(newlyCreatedPage.status).toBe(Page.STATUS_PUBLISHED);
       expect(newlyCreatedPage.status).toBe(Page.STATUS_PUBLISHED);
-
       expect(revertedPage1.grantedGroup).toStrictEqual(groupIdA);
       expect(revertedPage1.grantedGroup).toStrictEqual(groupIdA);
       expect(revertedPage2.grantedGroup).toStrictEqual(groupIdB);
       expect(revertedPage2.grantedGroup).toStrictEqual(groupIdB);
       expect(newlyCreatedPage.grant).toBe(Page.GRANT_PUBLIC);
       expect(newlyCreatedPage.grant).toBe(Page.GRANT_PUBLIC);