Browse Source

imprv expect

kaori 3 years ago
parent
commit
ff59610260

+ 1 - 1
packages/app/src/interfaces/page.ts

@@ -35,7 +35,7 @@ export interface IPage {
 export const PageGrant = {
 export const PageGrant = {
   GRANT_PUBLIC: 1,
   GRANT_PUBLIC: 1,
   GRANT_RESTRICTED: 2,
   GRANT_RESTRICTED: 2,
-  GRANT_SPECIFIED: 3,
+  GRANT_SPECIFIED: 3, // DEPRECATED
   GRANT_OWNER: 4,
   GRANT_OWNER: 4,
   GRANT_USER_GROUP: 5,
   GRANT_USER_GROUP: 5,
 };
 };

+ 32 - 2
packages/app/test/integration/service/page-grant.test.js

@@ -1,5 +1,6 @@
 import mongoose from 'mongoose';
 import mongoose from 'mongoose';
 
 
+import { PageGrant } from '~/interfaces/page';
 import UserGroup from '~/server/models/user-group';
 import UserGroup from '~/server/models/user-group';
 
 
 import { getInstance } from '../setup-crowi';
 import { getInstance } from '../setup-crowi';
@@ -38,12 +39,16 @@ describe('PageGrantService', () => {
   const emptyPagePath2 = '/E2';
   const emptyPagePath2 = '/E2';
   const emptyPagePath3 = '/E3';
   const emptyPagePath3 = '/E3';
 
 
+
   const topPagePath = '/';
   const topPagePath = '/';
 
 
   let pageRootPublic;
   let pageRootPublic;
   let pageRootGroupParent;
   let pageRootGroupParent;
   const pageRootPublicPath = '/Public';
   const pageRootPublicPath = '/Public';
   const pageRootGroupParentPath = '/GroupParent';
   const pageRootGroupParentPath = '/GroupParent';
+  const pageRootOnlyMePagePath = '/OnlyMe';
+  const pageRootAnyoneWithTheLinkPagePath = '/AnyoneWithTheLink';
+  const pageRootOnlyInsideTheGroupPagePath = '/OnlyInsideTheGroup';
 
 
   let pageE1Public;
   let pageE1Public;
   let pageE2User1;
   let pageE2User1;
@@ -152,9 +157,27 @@ describe('PageGrantService', () => {
         grantedGroup: groupParent._id,
         grantedGroup: groupParent._id,
         parent: rootPage._id,
         parent: rootPage._id,
       },
       },
+      // Root Page
       {
       {
-        path: topPagePath,
+        path: rootPage,
         grant: Page.GRANT_PUBLIC,
         grant: Page.GRANT_PUBLIC,
+        parent: null,
+      },
+      // OnlyMe
+      {
+        path: pageRootOnlyMePagePath,
+        grant: Page.GRANT_OWNER,
+        parent: rootPage._id,
+      },
+      {
+        path: pageRootAnyoneWithTheLinkPagePath,
+        grant: Page.GRANT_RESTRICTED,
+        parent: rootPage._id,
+      },
+      {
+        path: pageRootOnlyInsideTheGroupPagePath,
+        grant: Page.GRANT_USER_GROUP,
+        parent: rootPage._id,
       },
       },
     ]);
     ]);
 
 
@@ -370,11 +393,18 @@ describe('PageGrantService', () => {
 
 
   describe('Test for calcApplicableGrantData', () => {
   describe('Test for calcApplicableGrantData', () => {
     test('Public is only Applicable in case of top page', async() => {
     test('Public is only Applicable in case of top page', async() => {
+      const result = await pageGrantService.calcApplicableGrantData(rootPage, user1);
+
+      await expect(result[PageGrant.GRANT_PUBLIC]).toBeNull();
+    });
+
+    test('Should any pages Applicable in case that the parent is null', async() => {
       const topPage = await Page.findOne({ path: topPagePath });
       const topPage = await Page.findOne({ path: topPagePath });
       const result = await pageGrantService.calcApplicableGrantData(topPage, user1);
       const result = await pageGrantService.calcApplicableGrantData(topPage, user1);
 
 
-      await expect(result[1]).toBeNull();
+      await expect(result[PageGrant.GRANT_PUBLIC]).toBeNull();
     });
     });
   });
   });
 
 
+
 });
 });