|
@@ -88,6 +88,8 @@ describe('Test page service methods', () => {
|
|
|
const pageId7 = new mongoose.Types.ObjectId();
|
|
const pageId7 = new mongoose.Types.ObjectId();
|
|
|
const pageId8 = new mongoose.Types.ObjectId();
|
|
const pageId8 = new mongoose.Types.ObjectId();
|
|
|
const pageId9 = new mongoose.Types.ObjectId();
|
|
const pageId9 = new mongoose.Types.ObjectId();
|
|
|
|
|
+ const pageId10 = new mongoose.Types.ObjectId();
|
|
|
|
|
+ const pageId11 = new mongoose.Types.ObjectId();
|
|
|
|
|
|
|
|
await Page.insertMany([
|
|
await Page.insertMany([
|
|
|
{
|
|
{
|
|
@@ -199,6 +201,35 @@ describe('Test page service methods', () => {
|
|
|
descendantCount: 0,
|
|
descendantCount: 0,
|
|
|
isEmpty: false,
|
|
isEmpty: false,
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: pageId10,
|
|
|
|
|
+ path: '/resume_rename_11',
|
|
|
|
|
+ parent: rootPage._id,
|
|
|
|
|
+ grant: Page.GRANT_PUBLIC,
|
|
|
|
|
+ creator: dummyUser1,
|
|
|
|
|
+ lastUpdateUser: dummyUser1._id,
|
|
|
|
|
+ descendantCount: 2,
|
|
|
|
|
+ isEmpty: false,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: pageId11,
|
|
|
|
|
+ path: '/resume_rename_11/resume_rename_12',
|
|
|
|
|
+ parent: pageId10,
|
|
|
|
|
+ grant: Page.GRANT_PUBLIC,
|
|
|
|
|
+ creator: dummyUser1,
|
|
|
|
|
+ lastUpdateUser: dummyUser1._id,
|
|
|
|
|
+ descendantCount: 1,
|
|
|
|
|
+ isEmpty: false,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ path: '/resume_rename_11/resume_rename_12/resume_rename_13',
|
|
|
|
|
+ parent: pageId11,
|
|
|
|
|
+ grant: Page.GRANT_PUBLIC,
|
|
|
|
|
+ creator: dummyUser1,
|
|
|
|
|
+ lastUpdateUser: dummyUser1._id,
|
|
|
|
|
+ descendantCount: 0,
|
|
|
|
|
+ isEmpty: false,
|
|
|
|
|
+ },
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -208,10 +239,12 @@ describe('Test page service methods', () => {
|
|
|
const pageOpId2 = new mongoose.Types.ObjectId();
|
|
const pageOpId2 = new mongoose.Types.ObjectId();
|
|
|
const pageOpId3 = new mongoose.Types.ObjectId();
|
|
const pageOpId3 = new mongoose.Types.ObjectId();
|
|
|
const pageOpId4 = new mongoose.Types.ObjectId();
|
|
const pageOpId4 = new mongoose.Types.ObjectId();
|
|
|
|
|
+ const pageOpId5 = new mongoose.Types.ObjectId();
|
|
|
const pageOpRevisionId1 = new mongoose.Types.ObjectId();
|
|
const pageOpRevisionId1 = new mongoose.Types.ObjectId();
|
|
|
const pageOpRevisionId2 = new mongoose.Types.ObjectId();
|
|
const pageOpRevisionId2 = new mongoose.Types.ObjectId();
|
|
|
const pageOpRevisionId3 = new mongoose.Types.ObjectId();
|
|
const pageOpRevisionId3 = new mongoose.Types.ObjectId();
|
|
|
const pageOpRevisionId4 = new mongoose.Types.ObjectId();
|
|
const pageOpRevisionId4 = new mongoose.Types.ObjectId();
|
|
|
|
|
+ const pageOpRevisionId5 = new mongoose.Types.ObjectId();
|
|
|
|
|
|
|
|
await PageOperation.insertMany([
|
|
await PageOperation.insertMany([
|
|
|
{
|
|
{
|
|
@@ -330,6 +363,35 @@ describe('Test page service methods', () => {
|
|
|
},
|
|
},
|
|
|
unprocessableExpiryDate: null,
|
|
unprocessableExpiryDate: null,
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ _id: pageOpId5,
|
|
|
|
|
+ actionType: 'Rename',
|
|
|
|
|
+ actionStage: 'Sub',
|
|
|
|
|
+ fromPath: '/resume_rename_12',
|
|
|
|
|
+ toPath: '/resume_rename_11/resume_rename_12',
|
|
|
|
|
+ page: {
|
|
|
|
|
+ _id: pageId11,
|
|
|
|
|
+ parent: rootPage._id,
|
|
|
|
|
+ descendantCount: 1,
|
|
|
|
|
+ isEmpty: false,
|
|
|
|
|
+ path: '/resume_rename_12',
|
|
|
|
|
+ revision: pageOpRevisionId5,
|
|
|
|
|
+ status: 'published',
|
|
|
|
|
+ grant: Page.GRANT_PUBLIC,
|
|
|
|
|
+ grantedUsers: [],
|
|
|
|
|
+ grantedGroup: null,
|
|
|
|
|
+ creator: dummyUser1._id,
|
|
|
|
|
+ lastUpdateUser: dummyUser1._id,
|
|
|
|
|
+ },
|
|
|
|
|
+ user: {
|
|
|
|
|
+ _id: dummyUser1._id,
|
|
|
|
|
+ },
|
|
|
|
|
+ options: {
|
|
|
|
|
+ createRedirectPage: false,
|
|
|
|
|
+ updateMetadata: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ unprocessableExpiryDate: new Date(),
|
|
|
|
|
+ },
|
|
|
]);
|
|
]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -531,5 +593,57 @@ describe('Test page service methods', () => {
|
|
|
// cleanup
|
|
// cleanup
|
|
|
await PageOperation.findByIdAndDelete(pageOperation._id);
|
|
await PageOperation.findByIdAndDelete(pageOperation._id);
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ test(`it should succeed but 2 extra descendantCount should be added
|
|
|
|
|
+ if resumeing gets executed after updating descendantCount of ancestor in renameSubOperation is finished`, async() => {
|
|
|
|
|
+ // paths before renaming
|
|
|
|
|
+ const _path0 = '/resume_rename_11'; // out of renaming scope
|
|
|
|
|
+ const _path1 = '/resume_rename_11/resume_rename_12'; // renamed already
|
|
|
|
|
+ const _path2 = '/resume_rename_11/resume_rename_12/resume_rename_13'; // renamed already
|
|
|
|
|
+
|
|
|
|
|
+ // paths after renaming
|
|
|
|
|
+ const path0 = '/resume_rename_11';
|
|
|
|
|
+ const path1 = '/resume_rename_11/resume_rename_12';
|
|
|
|
|
+ const path2 = '/resume_rename_11/resume_rename_12/resume_rename_13';
|
|
|
|
|
+
|
|
|
|
|
+ // page
|
|
|
|
|
+ const _page0 = await Page.findOne({ path: _path0 });
|
|
|
|
|
+ const _page1 = await Page.findOne({ path: _path1 });
|
|
|
|
|
+ const _page2 = await Page.findOne({ path: _path2 });
|
|
|
|
|
+ expect(_page0).toBeTruthy();
|
|
|
|
|
+ expect(_page1).toBeTruthy();
|
|
|
|
|
+ expect(_page2).toBeTruthy();
|
|
|
|
|
+
|
|
|
|
|
+ // page operation
|
|
|
|
|
+ const _pageOperation = await PageOperation.findOne({ 'page._id': _page1._id, actionType: PageActionType.Rename, actionStage: PageActionStage.Sub });
|
|
|
|
|
+ expect(_pageOperation).toBeTruthy();
|
|
|
|
|
+
|
|
|
|
|
+ // rename
|
|
|
|
|
+ await resumeRenameSubOperation(_page1);
|
|
|
|
|
+
|
|
|
|
|
+ // page
|
|
|
|
|
+ const page0 = await Page.findById(_page0._id);
|
|
|
|
|
+ const page1 = await Page.findById(_page1._id);
|
|
|
|
|
+ const page2 = await Page.findById(_page2._id);
|
|
|
|
|
+ expect(page0).toBeTruthy();
|
|
|
|
|
+ expect(page1).toBeTruthy();
|
|
|
|
|
+ expect(page2).toBeTruthy();
|
|
|
|
|
+ expect(page0.path).toBe(path0);
|
|
|
|
|
+ expect(page1.path).toBe(path1);
|
|
|
|
|
+ expect(page2.path).toBe(path2);
|
|
|
|
|
+
|
|
|
|
|
+ // page operation
|
|
|
|
|
+ const pageOperation = await PageOperation.findById(_pageOperation._id);
|
|
|
|
|
+ expect(pageOperation).toBeNull(); // should not exist
|
|
|
|
|
+
|
|
|
|
|
+ // others
|
|
|
|
|
+ expect(page1.parent).toStrictEqual(page0._id);
|
|
|
|
|
+ expect(page2.parent).toStrictEqual(page1._id);
|
|
|
|
|
+
|
|
|
|
|
+ // 2 extra descendants should be added
|
|
|
|
|
+ expect(page0.descendantCount).toBe(4); // originally 2
|
|
|
|
|
+ expect(page1.descendantCount).toBe(1);
|
|
|
|
|
+ expect(page2.descendantCount).toBe(0);
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|