Taichi Masuyama 4 лет назад
Родитель
Сommit
36148e2f2f

+ 2 - 2
packages/app/src/server/crowi/index.js

@@ -20,6 +20,7 @@ import AppService from '../service/app';
 import AclService from '../service/acl';
 import SearchService from '../service/search';
 import AttachmentService from '../service/attachment';
+import PageService from '../service/page';
 import PageGrantService from '../service/page-grant';
 import { SlackIntegrationService } from '../service/slack-integration';
 import { UserNotificationService } from '../service/user-notification';
@@ -679,9 +680,8 @@ Crowi.prototype.setupImport = async function() {
 };
 
 Crowi.prototype.setupPageService = async function() {
-  const PageEventService = require('../service/page');
   if (this.pageService == null) {
-    this.pageService = new PageEventService(this);
+    this.pageService = new PageService(this);
   }
   if (this.pageGrantService == null) {
     this.pageGrantService = new PageGrantService(this);

+ 71 - 71
packages/app/src/test/integration/service/page.test.js

@@ -407,101 +407,101 @@ describe('PageService', () => {
         expect(redirectedFromPageRevision.body).toBe('redirect /renamed3');
       });
 
-    //   test('rename page with isRecursively', async() => {
+      // test('rename page with isRecursively', async() => {
 
-    //     const resultPage = await crowi.pageService.renamePage(parentForRename4, '/renamed4', testUser2, { }, true);
-    //     const redirectedFromPage = await Page.findOne({ path: '/parentForRename4' });
-    //     const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForRename4' });
+      //   const resultPage = await crowi.pageService.renamePage(parentForRename4, '/renamed4', testUser2, { }, true);
+      //   const redirectedFromPage = await Page.findOne({ path: '/parentForRename4' });
+      //   const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForRename4' });
 
-    //     expect(xssSpy).toHaveBeenCalled();
-    //     expect(renameDescendantsWithStreamSpy).toHaveBeenCalled();
-    //     expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename4, testUser2);
+      //   expect(xssSpy).toHaveBeenCalled();
+      //   expect(renameDescendantsWithStreamSpy).toHaveBeenCalled();
+      //   expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename4, testUser2);
 
-    //     expect(resultPage.path).toBe('/renamed4');
-    //     expect(resultPage.updatedAt).toEqual(parentForRename4.updatedAt);
-    //     expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
+      //   expect(resultPage.path).toBe('/renamed4');
+      //   expect(resultPage.updatedAt).toEqual(parentForRename4.updatedAt);
+      //   expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
 
-    //     expect(redirectedFromPage).toBeNull();
-    //     expect(redirectedFromPageRevision).toBeNull();
-    //   });
+      //   expect(redirectedFromPage).toBeNull();
+      //   expect(redirectedFromPageRevision).toBeNull();
+      // });
 
-    //   test('rename page with different tree with isRecursively', async() => {
+      // test('rename page with different tree with isRecursively', async() => {
 
-    //     const resultPage = await crowi.pageService.renamePage(parentForRename5, '/parentForRename5/renamedChild', testUser1, {}, true);
-    //     const wrongPage = await Page.findOne({ path: '/parentForRename5/renamedChild/renamedChild' });
-    //     const expectPage = await Page.findOne({ path: '/parentForRename5/renamedChild' });
+      //   const resultPage = await crowi.pageService.renamePage(parentForRename5, '/parentForRename5/renamedChild', testUser1, {}, true);
+      //   const wrongPage = await Page.findOne({ path: '/parentForRename5/renamedChild/renamedChild' });
+      //   const expectPage = await Page.findOne({ path: '/parentForRename5/renamedChild' });
 
-    //     expect(resultPage.path).toEqual(expectPage.path);
-    //     expect(wrongPage).toBeNull();
-    //   });
+      //   expect(resultPage.path).toEqual(expectPage.path);
+      //   expect(wrongPage).toBeNull();
+      // });
 
-    // });
+    });
 
-  //   test('renameDescendants without options', async() => {
-  //     const oldPagePathPrefix = new RegExp('^/parentForRename1', 'i');
-  //     const newPagePathPrefix = '/renamed1';
+    // test('renameDescendants without options', async() => {
+    //   const oldPagePathPrefix = new RegExp('^/parentForRename1', 'i');
+    //   const newPagePathPrefix = '/renamed1';
 
-  //     await crowi.pageService.renameDescendants([childForRename1], testUser2, {}, oldPagePathPrefix, newPagePathPrefix);
-  //     const resultPage = await Page.findOne({ path: '/renamed1/child' });
-  //     const redirectedFromPage = await Page.findOne({ path: '/parentForRename1/child' });
-  //     const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForRename1/child' });
+    //   await crowi.pageService.renameDescendants([childForRename1], testUser2, {}, oldPagePathPrefix, newPagePathPrefix);
+    //   const resultPage = await Page.findOne({ path: '/renamed1/child' });
+    //   const redirectedFromPage = await Page.findOne({ path: '/parentForRename1/child' });
+    //   const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForRename1/child' });
 
-  //     expect(resultPage).not.toBeNull();
-  //     expect(pageEventSpy).toHaveBeenCalledWith('updateMany', [childForRename1], testUser2);
+    //   expect(resultPage).not.toBeNull();
+    //   expect(pageEventSpy).toHaveBeenCalledWith('updateMany', [childForRename1], testUser2);
 
-  //     expect(resultPage.path).toBe('/renamed1/child');
-  //     expect(resultPage.updatedAt).toEqual(childForRename1.updatedAt);
-  //     expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
+    //   expect(resultPage.path).toBe('/renamed1/child');
+    //   expect(resultPage.updatedAt).toEqual(childForRename1.updatedAt);
+    //   expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
 
-  //     expect(redirectedFromPage).toBeNull();
-  //     expect(redirectedFromPageRevision).toBeNull();
-  //   });
+    //   expect(redirectedFromPage).toBeNull();
+    //   expect(redirectedFromPageRevision).toBeNull();
+    // });
 
-  //   test('renameDescendants with updateMetadata option', async() => {
-  //     const oldPagePathPrefix = new RegExp('^/parentForRename2', 'i');
-  //     const newPagePathPrefix = '/renamed2';
+    // test('renameDescendants with updateMetadata option', async() => {
+    //   const oldPagePathPrefix = new RegExp('^/parentForRename2', 'i');
+    //   const newPagePathPrefix = '/renamed2';
 
-  //     await crowi.pageService.renameDescendants([childForRename2], testUser2, { updateMetadata: true }, oldPagePathPrefix, newPagePathPrefix);
-  //     const resultPage = await Page.findOne({ path: '/renamed2/child' });
-  //     const redirectedFromPage = await Page.findOne({ path: '/parentForRename2/child' });
-  //     const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForRename2/child' });
+    //   await crowi.pageService.renameDescendants([childForRename2], testUser2, { updateMetadata: true }, oldPagePathPrefix, newPagePathPrefix);
+    //   const resultPage = await Page.findOne({ path: '/renamed2/child' });
+    //   const redirectedFromPage = await Page.findOne({ path: '/parentForRename2/child' });
+    //   const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForRename2/child' });
 
-  //     expect(resultPage).not.toBeNull();
-  //     expect(pageEventSpy).toHaveBeenCalledWith('updateMany', [childForRename2], testUser2);
+    //   expect(resultPage).not.toBeNull();
+    //   expect(pageEventSpy).toHaveBeenCalledWith('updateMany', [childForRename2], testUser2);
 
-  //     expect(resultPage.path).toBe('/renamed2/child');
-  //     expect(resultPage.updatedAt).toEqual(dateToUse);
-  //     expect(resultPage.lastUpdateUser).toEqual(testUser2._id);
+    //   expect(resultPage.path).toBe('/renamed2/child');
+    //   expect(resultPage.updatedAt).toEqual(dateToUse);
+    //   expect(resultPage.lastUpdateUser).toEqual(testUser2._id);
 
-  //     expect(redirectedFromPage).toBeNull();
-  //     expect(redirectedFromPageRevision).toBeNull();
-  //   });
+    //   expect(redirectedFromPage).toBeNull();
+    //   expect(redirectedFromPageRevision).toBeNull();
+    // });
 
-  //   test('renameDescendants with createRedirectPage option', async() => {
-  //     const oldPagePathPrefix = new RegExp('^/parentForRename3', 'i');
-  //     const newPagePathPrefix = '/renamed3';
+    // test('renameDescendants with createRedirectPage option', async() => {
+    //   const oldPagePathPrefix = new RegExp('^/parentForRename3', 'i');
+    //   const newPagePathPrefix = '/renamed3';
 
-  //     await crowi.pageService.renameDescendants([childForRename3], testUser2, { createRedirectPage: true }, oldPagePathPrefix, newPagePathPrefix);
-  //     const resultPage = await Page.findOne({ path: '/renamed3/child' });
-  //     const redirectedFromPage = await Page.findOne({ path: '/parentForRename3/child' });
-  //     const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForRename3/child' });
+    //   await crowi.pageService.renameDescendants([childForRename3], testUser2, { createRedirectPage: true }, oldPagePathPrefix, newPagePathPrefix);
+    //   const resultPage = await Page.findOne({ path: '/renamed3/child' });
+    //   const redirectedFromPage = await Page.findOne({ path: '/parentForRename3/child' });
+    //   const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForRename3/child' });
 
-  //     expect(resultPage).not.toBeNull();
-  //     expect(pageEventSpy).toHaveBeenCalledWith('updateMany', [childForRename3], testUser2);
+    //   expect(resultPage).not.toBeNull();
+    //   expect(pageEventSpy).toHaveBeenCalledWith('updateMany', [childForRename3], testUser2);
 
-  //     expect(resultPage.path).toBe('/renamed3/child');
-  //     expect(resultPage.updatedAt).toEqual(childForRename3.updatedAt);
-  //     expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
+    //   expect(resultPage.path).toBe('/renamed3/child');
+    //   expect(resultPage.updatedAt).toEqual(childForRename3.updatedAt);
+    //   expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
 
-  //     expect(redirectedFromPage).not.toBeNull();
-  //     expect(redirectedFromPage.path).toBe('/parentForRename3/child');
-  //     expect(redirectedFromPage.redirectTo).toBe('/renamed3/child');
+    //   expect(redirectedFromPage).not.toBeNull();
+    //   expect(redirectedFromPage.path).toBe('/parentForRename3/child');
+    //   expect(redirectedFromPage.redirectTo).toBe('/renamed3/child');
 
-  //     expect(redirectedFromPageRevision).not.toBeNull();
-  //     expect(redirectedFromPageRevision.path).toBe('/parentForRename3/child');
-  //     expect(redirectedFromPageRevision.body).toBe('redirect /renamed3/child');
-  //   });
-  // });
+    //   expect(redirectedFromPageRevision).not.toBeNull();
+    //   expect(redirectedFromPageRevision.path).toBe('/parentForRename3/child');
+    //   expect(redirectedFromPageRevision.body).toBe('redirect /renamed3/child');
+    // });
+  });
 
   describe('duplicate page', () => {
     let duplicateDescendantsWithStreamSpy;