yuken 3 лет назад
Родитель
Сommit
105f7a97fc

+ 12 - 0
packages/app/test/integration/service/v5.non-public-page.test.ts

@@ -732,6 +732,7 @@ describe('PageService page operations with non-public pages', () => {
 
 
     describe('Creating a page using existing path', () => {
     describe('Creating a page using existing path', () => {
       test('with grant RESTRICTED should only create the page and change nothing else', async() => {
       test('with grant RESTRICTED should only create the page and change nothing else', async() => {
+        const isGrantNormalizedSpy = jest.spyOn(crowi.pageGrantService, 'isGrantNormalized');
         const pathT = '/mc4_top';
         const pathT = '/mc4_top';
         const path1 = '/mc4_top/mc1_emp';
         const path1 = '/mc4_top/mc1_emp';
         const path2 = '/mc4_top/mc1_emp/mc2_pub';
         const path2 = '/mc4_top/mc1_emp/mc2_pub';
@@ -756,10 +757,13 @@ describe('PageService page operations with non-public pages', () => {
         expect(_page2).toBeTruthy();
         expect(_page2).toBeTruthy();
         expect(_page3).toBeTruthy();
         expect(_page3).toBeTruthy();
         expect(_pageT.descendantCount).toBe(1);
         expect(_pageT.descendantCount).toBe(1);
+        // isGrantNormalized is called when GRANT RESTRICTED
+        expect(isGrantNormalizedSpy).toBeCalledTimes(0);
       });
       });
     });
     });
     describe('Creating a page under a page with grant RESTRICTED', () => {
     describe('Creating a page under a page with grant RESTRICTED', () => {
       test('will create a new empty page with the same path as the grant RESTRECTED page and become a parent', async() => {
       test('will create a new empty page with the same path as the grant RESTRECTED page and become a parent', async() => {
+        const isGrantNormalizedSpy = jest.spyOn(crowi.pageGrantService, 'isGrantNormalized');
         const pathT = '/mc5_top';
         const pathT = '/mc5_top';
         const path1 = '/mc5_top/mc3_awl';
         const path1 = '/mc5_top/mc3_awl';
         const pathN = '/mc5_top/mc3_awl/mc4_pub'; // used to create
         const pathN = '/mc5_top/mc3_awl/mc4_pub'; // used to create
@@ -782,6 +786,8 @@ describe('PageService page operations with non-public pages', () => {
         expect(_pageN).toBeTruthy();
         expect(_pageN).toBeTruthy();
         expect(_pageN.parent).toStrictEqual(_page2._id);
         expect(_pageN.parent).toStrictEqual(_page2._id);
         expect(_pageT.descendantCount).toStrictEqual(1);
         expect(_pageT.descendantCount).toStrictEqual(1);
+        // isGrantNormalized is called when GRANT PUBLIC
+        expect(isGrantNormalizedSpy).toBeCalledTimes(0);
       });
       });
     });
     });
 
 
@@ -791,6 +797,7 @@ describe('PageService page operations with non-public pages', () => {
 
 
     describe('Creating a page using existing path', () => {
     describe('Creating a page using existing path', () => {
       test('with grant RESTRICTED should only create the page and change nothing else', async() => {
       test('with grant RESTRICTED should only create the page and change nothing else', async() => {
+        const isGrantNormalizedSpy = jest.spyOn(crowi.pageGrantService, 'isGrantNormalized');
         const pathT = '/mc4_top_by_system';
         const pathT = '/mc4_top_by_system';
         const path1 = '/mc4_top_by_system/mc1_emp_by_system';
         const path1 = '/mc4_top_by_system/mc1_emp_by_system';
         const path2 = '/mc4_top_by_system/mc1_emp_by_system/mc2_pub_by_system';
         const path2 = '/mc4_top_by_system/mc1_emp_by_system/mc2_pub_by_system';
@@ -815,10 +822,13 @@ describe('PageService page operations with non-public pages', () => {
         expect(_page2).toBeTruthy();
         expect(_page2).toBeTruthy();
         expect(_page3).toBeTruthy();
         expect(_page3).toBeTruthy();
         expect(_pageT.descendantCount).toBe(1);
         expect(_pageT.descendantCount).toBe(1);
+        // isGrantNormalized is not called when create by ststem
+        expect(isGrantNormalizedSpy).toBeCalledTimes(0);
       });
       });
     });
     });
     describe('Creating a page under a page with grant RESTRICTED', () => {
     describe('Creating a page under a page with grant RESTRICTED', () => {
       test('will create a new empty page with the same path as the grant RESTRECTED page and become a parent', async() => {
       test('will create a new empty page with the same path as the grant RESTRECTED page and become a parent', async() => {
+        const isGrantNormalizedSpy = jest.spyOn(crowi.pageGrantService, 'isGrantNormalized');
         const pathT = '/mc5_top_by_system';
         const pathT = '/mc5_top_by_system';
         const path1 = '/mc5_top_by_system/mc3_awl_by_system';
         const path1 = '/mc5_top_by_system/mc3_awl_by_system';
         const pathN = '/mc5_top_by_system/mc3_awl_by_system/mc4_pub_by_system'; // used to create
         const pathN = '/mc5_top_by_system/mc3_awl_by_system/mc4_pub_by_system'; // used to create
@@ -841,6 +851,8 @@ describe('PageService page operations with non-public pages', () => {
         expect(_pageN).toBeTruthy();
         expect(_pageN).toBeTruthy();
         expect(_pageN.parent).toStrictEqual(_page2._id);
         expect(_pageN.parent).toStrictEqual(_page2._id);
         expect(_pageT.descendantCount).toStrictEqual(1);
         expect(_pageT.descendantCount).toStrictEqual(1);
+        // isGrantNormalized is not called when create by ststem
+        expect(isGrantNormalizedSpy).toBeCalledTimes(0);
       });
       });
     });
     });
 
 

+ 18 - 0
packages/app/test/integration/service/v5.public-page.test.ts

@@ -938,12 +938,16 @@ describe('PageService page operations with only public pages', () => {
   describe('create', () => {
   describe('create', () => {
 
 
     test('Should create single page', async() => {
     test('Should create single page', async() => {
+      const isGrantNormalizedSpy = jest.spyOn(crowi.pageGrantService, 'isGrantNormalized');
       const page = await crowi.pageService.create('/v5_create1', 'create1', dummyUser1, {});
       const page = await crowi.pageService.create('/v5_create1', 'create1', dummyUser1, {});
       expect(page).toBeTruthy();
       expect(page).toBeTruthy();
       expect(page.parent).toStrictEqual(rootPage._id);
       expect(page.parent).toStrictEqual(rootPage._id);
+      // isGrantNormalized is called when GRANT PUBLIC
+      expect(isGrantNormalizedSpy).toBeCalledTimes(1);
     });
     });
 
 
     test('Should create empty-child and non-empty grandchild', async() => {
     test('Should create empty-child and non-empty grandchild', async() => {
+      const isGrantNormalizedSpy = jest.spyOn(crowi.pageGrantService, 'isGrantNormalized');
       const grandchildPage = await crowi.pageService.create('/v5_empty_create2/v5_create_3', 'grandchild', dummyUser1, {});
       const grandchildPage = await crowi.pageService.create('/v5_empty_create2/v5_create_3', 'grandchild', dummyUser1, {});
       const childPage = await Page.findOne({ path: '/v5_empty_create2' });
       const childPage = await Page.findOne({ path: '/v5_empty_create2' });
 
 
@@ -952,9 +956,12 @@ describe('PageService page operations with only public pages', () => {
       expect(childPage).toBeTruthy();
       expect(childPage).toBeTruthy();
       expect(childPage.parent).toStrictEqual(rootPage._id);
       expect(childPage.parent).toStrictEqual(rootPage._id);
       expect(grandchildPage.parent).toStrictEqual(childPage._id);
       expect(grandchildPage.parent).toStrictEqual(childPage._id);
+      // isGrantNormalized is called when GRANT PUBLIC
+      expect(isGrantNormalizedSpy).toBeCalledTimes(1);
     });
     });
 
 
     test('Should create on empty page', async() => {
     test('Should create on empty page', async() => {
+      const isGrantNormalizedSpy = jest.spyOn(crowi.pageGrantService, 'isGrantNormalized');
       const beforeCreatePage = await Page.findOne({ path: '/v5_empty_create_4' });
       const beforeCreatePage = await Page.findOne({ path: '/v5_empty_create_4' });
       expect(beforeCreatePage.isEmpty).toBe(true);
       expect(beforeCreatePage.isEmpty).toBe(true);
 
 
@@ -967,6 +974,8 @@ describe('PageService page operations with only public pages', () => {
       expect(grandchildPage).toBeTruthy();
       expect(grandchildPage).toBeTruthy();
       expect(childPage.parent).toStrictEqual(rootPage._id);
       expect(childPage.parent).toStrictEqual(rootPage._id);
       expect(grandchildPage.parent).toStrictEqual(childPage._id);
       expect(grandchildPage.parent).toStrictEqual(childPage._id);
+      // isGrantNormalized is called when GRANT PUBLIC
+      expect(isGrantNormalizedSpy).toBeCalledTimes(1);
     });
     });
 
 
   });
   });
@@ -974,12 +983,16 @@ describe('PageService page operations with only public pages', () => {
   describe('create by system', () => {
   describe('create by system', () => {
 
 
     test('Should create single page by system', async() => {
     test('Should create single page by system', async() => {
+      const isGrantNormalizedSpy = jest.spyOn(crowi.pageGrantService, 'isGrantNormalized');
       const page = await crowi.pageService.forceCreateBySystem('/v5_create_by_system1', 'create_by_system1', {});
       const page = await crowi.pageService.forceCreateBySystem('/v5_create_by_system1', 'create_by_system1', {});
       expect(page).toBeTruthy();
       expect(page).toBeTruthy();
       expect(page.parent).toStrictEqual(rootPage._id);
       expect(page.parent).toStrictEqual(rootPage._id);
+      // isGrantNormalized is not called when create by system
+      expect(isGrantNormalizedSpy).toBeCalledTimes(0);
     });
     });
 
 
     test('Should create empty-child and non-empty grandchild', async() => {
     test('Should create empty-child and non-empty grandchild', async() => {
+      const isGrantNormalizedSpy = jest.spyOn(crowi.pageGrantService, 'isGrantNormalized');
       const grandchildPage = await crowi.pageService.forceCreateBySystem('/v5_empty_create_by_system2/v5_create_by_system3', 'grandchild', {});
       const grandchildPage = await crowi.pageService.forceCreateBySystem('/v5_empty_create_by_system2/v5_create_by_system3', 'grandchild', {});
       const childPage = await Page.findOne({ path: '/v5_empty_create_by_system2' });
       const childPage = await Page.findOne({ path: '/v5_empty_create_by_system2' });
 
 
@@ -988,9 +1001,12 @@ describe('PageService page operations with only public pages', () => {
       expect(childPage).toBeTruthy();
       expect(childPage).toBeTruthy();
       expect(childPage.parent).toStrictEqual(rootPage._id);
       expect(childPage.parent).toStrictEqual(rootPage._id);
       expect(grandchildPage.parent).toStrictEqual(childPage._id);
       expect(grandchildPage.parent).toStrictEqual(childPage._id);
+      // isGrantNormalized is not called when create by system
+      expect(isGrantNormalizedSpy).toBeCalledTimes(0);
     });
     });
 
 
     test('Should create on empty page', async() => {
     test('Should create on empty page', async() => {
+      const isGrantNormalizedSpy = jest.spyOn(crowi.pageGrantService, 'isGrantNormalized');
       const beforeCreatePage = await Page.findOne({ path: '/v5_empty_create_by_system4' });
       const beforeCreatePage = await Page.findOne({ path: '/v5_empty_create_by_system4' });
       expect(beforeCreatePage.isEmpty).toBe(true);
       expect(beforeCreatePage.isEmpty).toBe(true);
 
 
@@ -1003,6 +1019,8 @@ describe('PageService page operations with only public pages', () => {
       expect(grandchildPage).toBeTruthy();
       expect(grandchildPage).toBeTruthy();
       expect(childPage.parent).toStrictEqual(rootPage._id);
       expect(childPage.parent).toStrictEqual(rootPage._id);
       expect(grandchildPage.parent).toStrictEqual(childPage._id);
       expect(grandchildPage.parent).toStrictEqual(childPage._id);
+      // isGrantNormalized is not called when create by system
+      expect(isGrantNormalizedSpy).toBeCalledTimes(0);
     });
     });
 
 
   });
   });