|
@@ -58,8 +58,12 @@ describe('PageService page operations with non-public pages', () => {
|
|
|
*/
|
|
*/
|
|
|
// page id
|
|
// page id
|
|
|
const pageIdDuplicate1 = new mongoose.Types.ObjectId();
|
|
const pageIdDuplicate1 = new mongoose.Types.ObjectId();
|
|
|
|
|
+ const pageIdDuplicate2 = new mongoose.Types.ObjectId();
|
|
|
|
|
+ const pageIdDuplicate3 = new mongoose.Types.ObjectId();
|
|
|
// revision id
|
|
// revision id
|
|
|
const revisionIdDuplicate1 = new mongoose.Types.ObjectId();
|
|
const revisionIdDuplicate1 = new mongoose.Types.ObjectId();
|
|
|
|
|
+ const revisionIdDuplicate2 = new mongoose.Types.ObjectId();
|
|
|
|
|
+ const revisionIdDuplicate3 = new mongoose.Types.ObjectId();
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -296,6 +300,26 @@ describe('PageService page operations with non-public pages', () => {
|
|
|
lastUpdateUser: dummyUser1._id,
|
|
lastUpdateUser: dummyUser1._id,
|
|
|
revision: revisionIdDuplicate1,
|
|
revision: revisionIdDuplicate1,
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: pageIdDuplicate2,
|
|
|
|
|
+ path: '/np_duplicate2',
|
|
|
|
|
+ grant: Page.GRANT_USER_GROUP,
|
|
|
|
|
+ grantedGroup: groupIdA,
|
|
|
|
|
+ creator: npDummyUser1._id,
|
|
|
|
|
+ lastUpdateUser: npDummyUser1._id,
|
|
|
|
|
+ revision: revisionIdDuplicate2,
|
|
|
|
|
+ parent: rootPage._id,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: pageIdDuplicate3,
|
|
|
|
|
+ path: '/np_duplicate2/np_duplicate3',
|
|
|
|
|
+ grant: Page.GRANT_USER_GROUP,
|
|
|
|
|
+ grantedGroup: groupIdB,
|
|
|
|
|
+ creator: npDummyUser2._id,
|
|
|
|
|
+ lastUpdateUser: npDummyUser2._id,
|
|
|
|
|
+ revision: revisionIdDuplicate3,
|
|
|
|
|
+ parent: pageIdDuplicate2,
|
|
|
|
|
+ },
|
|
|
]);
|
|
]);
|
|
|
await Revision.insertMany([
|
|
await Revision.insertMany([
|
|
|
{
|
|
{
|
|
@@ -305,6 +329,20 @@ describe('PageService page operations with non-public pages', () => {
|
|
|
pageId: pageIdDuplicate1,
|
|
pageId: pageIdDuplicate1,
|
|
|
author: npDummyUser1._id,
|
|
author: npDummyUser1._id,
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: revisionIdDuplicate2,
|
|
|
|
|
+ body: 'np_duplicate2',
|
|
|
|
|
+ format: 'markdown',
|
|
|
|
|
+ pageId: pageIdDuplicate2,
|
|
|
|
|
+ author: npDummyUser2._id,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: revisionIdDuplicate3,
|
|
|
|
|
+ body: 'np_duplicate3',
|
|
|
|
|
+ format: 'markdown',
|
|
|
|
|
+ pageId: pageIdDuplicate3,
|
|
|
|
|
+ author: npDummyUser2._id,
|
|
|
|
|
+ },
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -587,8 +625,40 @@ describe('PageService page operations with non-public pages', () => {
|
|
|
expect(duplicatedPage.parent).toStrictEqual(basePage.parent);
|
|
expect(duplicatedPage.parent).toStrictEqual(basePage.parent);
|
|
|
expect(duplicatedPage.revision).toStrictEqual(duplicatedRevision._id);
|
|
expect(duplicatedPage.revision).toStrictEqual(duplicatedRevision._id);
|
|
|
|
|
|
|
|
- expect(duplicatedRevision.body).toEqual(baseRevision.body);
|
|
|
|
|
|
|
+ expect(duplicatedRevision.body).toBe(baseRevision.body);
|
|
|
});
|
|
});
|
|
|
|
|
+ test('Should duplicate multiple pages with GRANT_USER_GROUP', async() => {
|
|
|
|
|
+ const basePath1 = '/np_duplicate2';
|
|
|
|
|
+ const basePath2 = '/np_duplicate2/np_duplicate3';
|
|
|
|
|
+ const basePage1 = await Page.findOne({ path: basePath1, parent: rootPage._id })
|
|
|
|
|
+ .populate({ path: 'revision', model: 'Revision', grantedPage: groupIdA._id });
|
|
|
|
|
+ const basePage2 = await Page.findOne({ path: basePath2, parent: basePage1._id })
|
|
|
|
|
+ .populate({ path: 'revision', model: 'Revision', grantedPage: groupIdB._id });
|
|
|
|
|
+ const baseRevision1 = basePage1.revision;
|
|
|
|
|
+ const baseRevision2 = basePage2.revision;
|
|
|
|
|
+ expectAllToBeTruthy([basePage1, basePage2, baseRevision1, baseRevision2]);
|
|
|
|
|
+
|
|
|
|
|
+ const newPagePath = '/dup_np_duplicate2';
|
|
|
|
|
+ await duplicate(basePage1, newPagePath, npDummyUser2, true);
|
|
|
|
|
+
|
|
|
|
|
+ const duplicatedPage1 = await Page.findOne({ path: newPagePath }).populate({ path: 'revision', model: 'Revision' });
|
|
|
|
|
+ const duplicatedPage2 = await Page.findOne({ path: '/dup_np_duplicate2/np_duplicate3' }).populate({ path: 'revision', model: 'Revision' });
|
|
|
|
|
+ const duplicatedRevision1 = duplicatedPage1.revision;
|
|
|
|
|
+ const duplicatedRevision2 = duplicatedPage2.revision;
|
|
|
|
|
+ expectAllToBeTruthy([duplicatedPage1, duplicatedPage2, duplicatedRevision1, duplicatedRevision2]);
|
|
|
|
|
+
|
|
|
|
|
+ expect(xssSpy).toHaveBeenCalled();
|
|
|
|
|
+ expect(duplicatedPage1.grantedGroup).toStrictEqual(groupIdA._id);
|
|
|
|
|
+ expect(duplicatedPage2.grantedGroup).toStrictEqual(groupIdB._id);
|
|
|
|
|
+ expect(duplicatedPage1.parent).toStrictEqual(basePage1.parent);
|
|
|
|
|
+ expect(duplicatedPage2.parent).toStrictEqual(duplicatedPage1._id);
|
|
|
|
|
+
|
|
|
|
|
+ expect(duplicatedRevision1.body).toBe(baseRevision1.body);
|
|
|
|
|
+ expect(duplicatedRevision2.body).toBe(baseRevision2.body);
|
|
|
|
|
+ expect(duplicatedRevision1.pageId).toStrictEqual(duplicatedPage1._id);
|
|
|
|
|
+ expect(duplicatedRevision2.pageId).toStrictEqual(duplicatedPage2._id);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
});
|
|
});
|
|
|
describe('Delete', () => {
|
|
describe('Delete', () => {
|
|
|
// test('', async() => {
|
|
// test('', async() => {
|