|
@@ -186,15 +186,6 @@ describe('PageService page operations with only public pages', () => {
|
|
|
isEmpty: true,
|
|
isEmpty: true,
|
|
|
},
|
|
},
|
|
|
]);
|
|
]);
|
|
|
- await Page.insertMany([
|
|
|
|
|
- {
|
|
|
|
|
- path: '/v5_ParentForDuplicate1',
|
|
|
|
|
- grant: Page.GRANT_PUBLIC,
|
|
|
|
|
- creator: dummyUser1,
|
|
|
|
|
- lastUpdateUser: dummyUser1._id,
|
|
|
|
|
- parent: rootPage._id,
|
|
|
|
|
- },
|
|
|
|
|
- ]);
|
|
|
|
|
// Find pages as Parent
|
|
// Find pages as Parent
|
|
|
parentForRename1 = await Page.findOne({ path: '/v5_ParentForRename1' });
|
|
parentForRename1 = await Page.findOne({ path: '/v5_ParentForRename1' });
|
|
|
parentForRename2 = await Page.findOne({ path: '/v5_ParentForRename2' });
|
|
parentForRename2 = await Page.findOne({ path: '/v5_ParentForRename2' });
|
|
@@ -233,8 +224,32 @@ describe('PageService page operations with only public pages', () => {
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
- * Duplicate
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ * Duplicate
|
|
|
|
|
+ */
|
|
|
|
|
+ const idForPage1 = new mongoose.Types.ObjectId();
|
|
|
|
|
+ const idForRevision1 = new mongoose.Types.ObjectId();
|
|
|
|
|
+
|
|
|
|
|
+ await Page.insertMany([
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: idForPage1,
|
|
|
|
|
+ path: '/v5_ParentForDuplicate1',
|
|
|
|
|
+ grant: Page.GRANT_PUBLIC,
|
|
|
|
|
+ creator: dummyUser1,
|
|
|
|
|
+ lastUpdateUser: dummyUser1._id,
|
|
|
|
|
+ parent: rootPage._id,
|
|
|
|
|
+ revision: idForRevision1,
|
|
|
|
|
+ },
|
|
|
|
|
+ ]);
|
|
|
|
|
+ // Revision
|
|
|
|
|
+ await Revision.insertMany([
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: idForRevision1,
|
|
|
|
|
+ body: 'body1',
|
|
|
|
|
+ format: 'markdown',
|
|
|
|
|
+ pageId: idForPage1,
|
|
|
|
|
+ author: dummyUser1,
|
|
|
|
|
+ },
|
|
|
|
|
+ ]);
|
|
|
parentForDuplicate1 = await Page.findOne({ path: '/v5_ParentForDuplicate1' });
|
|
parentForDuplicate1 = await Page.findOne({ path: '/v5_ParentForDuplicate1' });
|
|
|
|
|
|
|
|
});
|
|
});
|
|
@@ -259,112 +274,137 @@ describe('PageService page operations with only public pages', () => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
- describe('Rename', () => {
|
|
|
|
|
- test('Should NOT rename top page', async() => {
|
|
|
|
|
-
|
|
|
|
|
- let isThrown = false;
|
|
|
|
|
- try {
|
|
|
|
|
- await crowi.pageService.renamePage(rootPage, '/new_root', dummyUser1, {});
|
|
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
- isThrown = true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- expect(isThrown).toBe(true);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- test('Should move to under non-empty page', async() => {
|
|
|
|
|
- // rename target page
|
|
|
|
|
- const newPath = '/v5_ParentForRename1/renamedChildForRename1';
|
|
|
|
|
- const renamedPage = await renamePage(childForRename1, newPath, dummyUser1, {});
|
|
|
|
|
-
|
|
|
|
|
- expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
- expect(renamedPage.parent).toStrictEqual(parentForRename1._id);
|
|
|
|
|
-
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- test('Should move to under empty page', async() => {
|
|
|
|
|
- // rename target page
|
|
|
|
|
- const newPath = '/v5_ParentForRename2/renamedChildForRename2';
|
|
|
|
|
- const renamedPage = await renamePage(childForRename2, newPath, dummyUser1, {});
|
|
|
|
|
-
|
|
|
|
|
- expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
- expect(parentForRename2.isEmpty).toBe(true);
|
|
|
|
|
- expect(renamedPage.parent).toStrictEqual(parentForRename2._id);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // describe('Rename', () => {
|
|
|
|
|
+ // test('Should NOT rename top page', async() => {
|
|
|
|
|
+
|
|
|
|
|
+ // let isThrown = false;
|
|
|
|
|
+ // try {
|
|
|
|
|
+ // await crowi.pageService.renamePage(rootPage, '/new_root', dummyUser1, {});
|
|
|
|
|
+ // }
|
|
|
|
|
+ // catch (err) {
|
|
|
|
|
+ // isThrown = true;
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // expect(isThrown).toBe(true);
|
|
|
|
|
+ // });
|
|
|
|
|
+
|
|
|
|
|
+ // test('Should move to under non-empty page', async() => {
|
|
|
|
|
+ // // rename target page
|
|
|
|
|
+ // const newPath = '/v5_ParentForRename1/renamedChildForRename1';
|
|
|
|
|
+ // const renamedPage = await renamePage(childForRename1, newPath, dummyUser1, {});
|
|
|
|
|
+
|
|
|
|
|
+ // expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
+ // expect(renamedPage.parent).toStrictEqual(parentForRename1._id);
|
|
|
|
|
+
|
|
|
|
|
+ // });
|
|
|
|
|
+
|
|
|
|
|
+ // test('Should move to under empty page', async() => {
|
|
|
|
|
+ // // rename target page
|
|
|
|
|
+ // const newPath = '/v5_ParentForRename2/renamedChildForRename2';
|
|
|
|
|
+ // const renamedPage = await renamePage(childForRename2, newPath, dummyUser1, {});
|
|
|
|
|
+
|
|
|
|
|
+ // expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
+ // expect(parentForRename2.isEmpty).toBe(true);
|
|
|
|
|
+ // expect(renamedPage.parent).toStrictEqual(parentForRename2._id);
|
|
|
|
|
+ // });
|
|
|
|
|
+
|
|
|
|
|
+ // test('Should move with option updateMetadata: true', async() => {
|
|
|
|
|
+ // // rename target page
|
|
|
|
|
+ // const newPath = '/v5_ParentForRename3/renamedChildForRename3';
|
|
|
|
|
+ // const oldUdpateAt = childForRename3.updatedAt;
|
|
|
|
|
+ // const renamedPage = await renamePage(childForRename3, newPath, dummyUser2, { updateMetadata: true });
|
|
|
|
|
+
|
|
|
|
|
+ // expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
+ // expect(renamedPage.parent).toStrictEqual(parentForRename3._id);
|
|
|
|
|
+ // expect(renamedPage.lastUpdateUser).toStrictEqual(dummyUser2._id);
|
|
|
|
|
+ // expect(renamedPage.updatedAt.getFullYear()).toBeGreaterThan(oldUdpateAt.getFullYear());
|
|
|
|
|
+ // });
|
|
|
|
|
+
|
|
|
|
|
+ // // ****************** TODO ******************
|
|
|
|
|
+ // // uncomment the next test when working on 88097
|
|
|
|
|
+ // // ******************************************
|
|
|
|
|
+ // // test('Should move with option createRedirectPage: true', async() => {
|
|
|
|
|
+ // // // rename target page
|
|
|
|
|
+ // // const newPath = '/v5_ParentForRename4/renamedChildForRename4';
|
|
|
|
|
+ // // const renamedPage = await renamePage(childForRename4, newPath, dummyUser2, { createRedirectPage: true });
|
|
|
|
|
+ // // const pageRedirect = await PageRedirect.find({ fromPath: childForRename4.path, toPath: renamedPage.path });
|
|
|
|
|
+
|
|
|
|
|
+ // // expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
+ // // expect(renamedPage.parent).toStrictEqual(parentForRename4._id);
|
|
|
|
|
+ // // expect(pageRedirect.length).toBeGreaterThan(0);
|
|
|
|
|
+ // // });
|
|
|
|
|
+
|
|
|
|
|
+ // test('Should move with descendants', async() => {
|
|
|
|
|
+ // // rename target page
|
|
|
|
|
+ // const newPath = '/v5_ParentForRename5/renamedChildForRename5';
|
|
|
|
|
+ // const renamedPage = await renamePage(childForRename5, newPath, dummyUser1, {});
|
|
|
|
|
+ // // find child of renamed page
|
|
|
|
|
+ // const grandchildren = await Page.find({ parent: renamedPage._id });
|
|
|
|
|
+ // const grandchild = grandchildren[0];
|
|
|
|
|
+
|
|
|
|
|
+ // expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
+ // expect(renamedPage.parent).toStrictEqual(parentForRename5._id);
|
|
|
|
|
+ // // grandchild's parent should be renamed page
|
|
|
|
|
+ // expect(grandchild.parent).toStrictEqual(renamedPage._id);
|
|
|
|
|
+ // expect(grandchild.path).toBe('/v5_ParentForRename5/renamedChildForRename5/v5_GrandchildForRename5');
|
|
|
|
|
+ // });
|
|
|
|
|
+
|
|
|
|
|
+ // test('Should move with same grant', async() => {
|
|
|
|
|
+ // // rename target page
|
|
|
|
|
+ // const newPath = '/v5_ParentForRename6/renamedChildForRename6';
|
|
|
|
|
+ // expect(childForRename6.grant).toBe(Page.GRANT_RESTRICTED);
|
|
|
|
|
+ // const renamedPage = await renamePage(childForRename6, newPath, dummyUser1, {});
|
|
|
|
|
+
|
|
|
|
|
+ // expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
+ // expect(renamedPage.parent).toStrictEqual(parentForRename6._id);
|
|
|
|
|
+ // expect(renamedPage.grant).toBe(Page.GRANT_RESTRICTED);
|
|
|
|
|
+ // });
|
|
|
|
|
+
|
|
|
|
|
+ // test('Should move empty page', async() => {
|
|
|
|
|
+ // // rename target page
|
|
|
|
|
+ // const newPath = '/v5_ParentForRename7/renamedChildForRename7';
|
|
|
|
|
+ // const renamedPage = await renamePage(childForRename7, newPath, dummyUser1, {});
|
|
|
|
|
+ // // find child of renamed page
|
|
|
|
|
+ // const grandchildren = await Page.find({ parent: renamedPage._id });
|
|
|
|
|
+ // const grandchild = grandchildren[0];
|
|
|
|
|
+
|
|
|
|
|
+ // expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
+ // expect(renamedPage.isEmpty).toBe(true);
|
|
|
|
|
+ // expect(renamedPage.parent).toStrictEqual(parentForRename7._id);
|
|
|
|
|
+ // // grandchild's parent should be renamed page
|
|
|
|
|
+ // expect(grandchild.parent).toStrictEqual(renamedPage._id);
|
|
|
|
|
+ // expect(grandchild.path).toBe('/v5_ParentForRename7/renamedChildForRename7/v5_GrandchildForRename7');
|
|
|
|
|
+ // });
|
|
|
|
|
+ // });
|
|
|
|
|
|
|
|
- test('Should move with option updateMetadata: true', async() => {
|
|
|
|
|
- // rename target page
|
|
|
|
|
- const newPath = '/v5_ParentForRename3/renamedChildForRename3';
|
|
|
|
|
- const oldUdpateAt = childForRename3.updatedAt;
|
|
|
|
|
- const renamedPage = await renamePage(childForRename3, newPath, dummyUser2, { updateMetadata: true });
|
|
|
|
|
|
|
+ describe('Duplicate', () => {
|
|
|
|
|
|
|
|
- expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
- expect(renamedPage.parent).toStrictEqual(parentForRename3._id);
|
|
|
|
|
- expect(renamedPage.lastUpdateUser).toStrictEqual(dummyUser2._id);
|
|
|
|
|
- expect(renamedPage.updatedAt.getFullYear()).toBeGreaterThan(oldUdpateAt.getFullYear());
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ const duplicate = async(page, newPagePath, user, isRecursively) => {
|
|
|
|
|
+ // mock return value
|
|
|
|
|
+ const mockedResumableDuplicateDescendants = jest.spyOn(crowi.pageService, 'resumableDuplicateDescendants').mockRejectedValue(null);
|
|
|
|
|
+ const mockedCreateAndSendNotifications = jest.spyOn(crowi.pageService, 'createAndSendNotifications').mockReturnValue(null);
|
|
|
|
|
+ const duplicatedPage = await crowi.pageService.duplicate(page, newPagePath, user, isRecursively);
|
|
|
|
|
|
|
|
- // ****************** TODO ******************
|
|
|
|
|
- // uncomment the next test when working on 88097
|
|
|
|
|
- // ******************************************
|
|
|
|
|
- // test('Should move with option createRedirectPage: true', async() => {
|
|
|
|
|
- // // rename target page
|
|
|
|
|
- // const newPath = '/v5_ParentForRename4/renamedChildForRename4';
|
|
|
|
|
- // const renamedPage = await renamePage(childForRename4, newPath, dummyUser2, { createRedirectPage: true });
|
|
|
|
|
- // const pageRedirect = await PageRedirect.find({ fromPath: childForRename4.path, toPath: renamedPage.path });
|
|
|
|
|
-
|
|
|
|
|
- // expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
- // expect(renamedPage.parent).toStrictEqual(parentForRename4._id);
|
|
|
|
|
- // expect(pageRedirect.length).toBeGreaterThan(0);
|
|
|
|
|
- // });
|
|
|
|
|
-
|
|
|
|
|
- test('Should move with descendants', async() => {
|
|
|
|
|
- // rename target page
|
|
|
|
|
- const newPath = '/v5_ParentForRename5/renamedChildForRename5';
|
|
|
|
|
- const renamedPage = await renamePage(childForRename5, newPath, dummyUser1, {});
|
|
|
|
|
- // find child of renamed page
|
|
|
|
|
- const grandchildren = await Page.find({ parent: renamedPage._id });
|
|
|
|
|
- const grandchild = grandchildren[0];
|
|
|
|
|
-
|
|
|
|
|
- expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
- expect(renamedPage.parent).toStrictEqual(parentForRename5._id);
|
|
|
|
|
- // grandchild's parent should be renamed page
|
|
|
|
|
- expect(grandchild.parent).toStrictEqual(renamedPage._id);
|
|
|
|
|
- expect(grandchild.path).toBe('/v5_ParentForRename5/renamedChildForRename5/v5_GrandchildForRename5');
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // retrieve the arguments passed when calling method resumableDuplicateDescendants inside duplicate method
|
|
|
|
|
+ const argsForCreateAndSendNotifications = mockedResumableDuplicateDescendants.mock.calls[0];
|
|
|
|
|
|
|
|
- test('Should move with same grant', async() => {
|
|
|
|
|
- // rename target page
|
|
|
|
|
- const newPath = '/v5_ParentForRename6/renamedChildForRename6';
|
|
|
|
|
- expect(childForRename6.grant).toBe(Page.GRANT_RESTRICTED);
|
|
|
|
|
- const renamedPage = await renamePage(childForRename6, newPath, dummyUser1, {});
|
|
|
|
|
|
|
+ // restores the original implementation
|
|
|
|
|
+ mockedResumableDuplicateDescendants.mockRestore();
|
|
|
|
|
+ mockedCreateAndSendNotifications.mockRestore();
|
|
|
|
|
|
|
|
- expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
- expect(renamedPage.parent).toStrictEqual(parentForRename6._id);
|
|
|
|
|
- expect(renamedPage.grant).toBe(Page.GRANT_RESTRICTED);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // duplicate descendants
|
|
|
|
|
+ await crowi.pageService.resumableRenameDescendants(...argsForCreateAndSendNotifications);
|
|
|
|
|
|
|
|
- test('Should move empty page', async() => {
|
|
|
|
|
- // rename target page
|
|
|
|
|
- const newPath = '/v5_ParentForRename7/renamedChildForRename7';
|
|
|
|
|
- const renamedPage = await renamePage(childForRename7, newPath, dummyUser1, {});
|
|
|
|
|
- // find child of renamed page
|
|
|
|
|
- const grandchildren = await Page.find({ parent: renamedPage._id });
|
|
|
|
|
- const grandchild = grandchildren[0];
|
|
|
|
|
-
|
|
|
|
|
- expect(renamedPage.path).toBe(newPath);
|
|
|
|
|
- expect(renamedPage.isEmpty).toBe(true);
|
|
|
|
|
- expect(renamedPage.parent).toStrictEqual(parentForRename7._id);
|
|
|
|
|
- // grandchild's parent should be renamed page
|
|
|
|
|
- expect(grandchild.parent).toStrictEqual(renamedPage._id);
|
|
|
|
|
- expect(grandchild.path).toBe('/v5_ParentForRename7/renamedChildForRename7/v5_GrandchildForRename7');
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ return duplicatedPage;
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- describe('Duplicate', () => {
|
|
|
|
|
test('Should duplicate single page', async() => {
|
|
test('Should duplicate single page', async() => {
|
|
|
- crowi.pageService.duplicate(/* page, newPagePath, user, isRecursively */);
|
|
|
|
|
|
|
+ const newPagePath = '/duplicatedSinglePage';
|
|
|
|
|
+ const duplicatedPage = await duplicate(parentForDuplicate1, newPagePath, dummyUser1, false);
|
|
|
|
|
+ const basePage = await Page.findOne({ path: '/v5_ParentForDuplicate1' });
|
|
|
|
|
+
|
|
|
|
|
+ expect(duplicatedPage.path).toBe(newPagePath);
|
|
|
|
|
+ expect(basePage).toBe(parentForDuplicate1);
|
|
|
});
|
|
});
|
|
|
test('Should duplicate multiple pages', async() => {
|
|
test('Should duplicate multiple pages', async() => {
|
|
|
// a
|
|
// a
|