Browse Source

Merge branch 'imprv/refacter-recursively' into imprv/create-duplicate-page-test-(isRecursively-true)

zahmis 5 years ago
parent
commit
5fc860c352
1 changed files with 7 additions and 8 deletions
  1. 7 8
      src/test/service/page.test.js

+ 7 - 8
src/test/service/page.test.js

@@ -296,19 +296,18 @@ describe('PageService', () => {
       const dummyId = '600d395667536503354c9999';
       const dummyId = '600d395667536503354c9999';
       crowi.models.Page.findRelatedTagsById = jest.fn().mockImplementation(() => { return parentTag });
       crowi.models.Page.findRelatedTagsById = jest.fn().mockImplementation(() => { return parentTag });
       const originTagsMock = jest.spyOn(Page, 'findRelatedTagsById').mockImplementation(() => { return parentTag });
       const originTagsMock = jest.spyOn(Page, 'findRelatedTagsById').mockImplementation(() => { return parentTag });
-      jest.spyOn(PageTagRelation, 'updatePageTags').mockImplementation(() => { return [dummyId, originTagsMock().name] });
-      jest.spyOn(PageTagRelation, 'listTagNamesByPage').mockImplementation(() => { return [parentTag].map((tag) => { return tag.name }) });
+      jest.spyOn(PageTagRelation, 'updatePageTags').mockImplementation(() => { return [dummyId, parentTag.name] });
+      jest.spyOn(PageTagRelation, 'listTagNamesByPage').mockImplementation(() => { return [parentTag.name] });
 
 
-      const resultPage = await crowi.pageService.duplicate(parentForDuplicate, '/newParent', testUser1, false);
-      const resultAnotherPage = await crowi.pageService.duplicate(parentForDuplicate, '/newAnotherParent', testUser2, false);
+      const resultPage = await crowi.pageService.duplicate(parentForDuplicate, '/newParentDuplicate', testUser2, false);
+      const duplicatedToPageRevision = await Revision.findOne({ path: '/newParentDuplicate' });
 
 
       expect(xssSpy).toHaveBeenCalled();
       expect(xssSpy).toHaveBeenCalled();
       expect(duplicateDescendantsWithStreamSpy).not.toHaveBeenCalled();
       expect(duplicateDescendantsWithStreamSpy).not.toHaveBeenCalled();
       expect(serializePageSecurely).toHaveBeenCalled();
       expect(serializePageSecurely).toHaveBeenCalled();
-      expect(resultPage.path).toBe('/newParent');
-      expect(resultPage.lastUpdateUser._id).toEqual(testUser1._id);
-      expect(resultAnotherPage.lastUpdateUser._id).toEqual(testUser2._id);
-      expect(resultPage.revision).not.toEqual(parentForDuplicate.revision);
+      expect(resultPage.path).toBe('/newParentDuplicate');
+      expect(resultPage.lastUpdateUser._id).toEqual(testUser2._id);
+      expect(duplicatedToPageRevision._id).not.toEqual(parentForDuplicate.revision._id);
       expect(resultPage.grant).toEqual(parentForDuplicate.grant);
       expect(resultPage.grant).toEqual(parentForDuplicate.grant);
       expect(resultPage.tags).toEqual([originTagsMock().name]);
       expect(resultPage.tags).toEqual([originTagsMock().name]);
     });
     });