|
|
@@ -143,79 +143,6 @@ describe('Page', () => {
|
|
|
},
|
|
|
]);
|
|
|
|
|
|
- const pageIdCreate1 = new mongoose.Types.ObjectId();
|
|
|
- const pageIdCreate2 = new mongoose.Types.ObjectId();
|
|
|
- const pageIdCreate3 = new mongoose.Types.ObjectId();
|
|
|
- const pageIdCreate4 = new mongoose.Types.ObjectId();
|
|
|
-
|
|
|
- /**
|
|
|
- * create
|
|
|
- * mc_ => model create
|
|
|
- * emp => empty => page with isEmpty: true
|
|
|
- * pub => public => GRANT_PUBLIC
|
|
|
- */
|
|
|
- await Page.insertMany([
|
|
|
- {
|
|
|
- _id: pageIdCreate1,
|
|
|
- path: '/v5_empty_create_4',
|
|
|
- grant: Page.GRANT_PUBLIC,
|
|
|
- parent: rootPage._id,
|
|
|
- isEmpty: true,
|
|
|
- },
|
|
|
- {
|
|
|
- path: '/v5_empty_create_4/v5_create_5',
|
|
|
- grant: Page.GRANT_PUBLIC,
|
|
|
- creator: dummyUser1,
|
|
|
- lastUpdateUser: dummyUser1._id,
|
|
|
- parent: pageIdCreate1,
|
|
|
- isEmpty: false,
|
|
|
- },
|
|
|
- {
|
|
|
- _id: pageIdCreate2,
|
|
|
- path: '/mc4_top/mc1_emp',
|
|
|
- grant: Page.GRANT_PUBLIC,
|
|
|
- creator: dummyUser1,
|
|
|
- lastUpdateUser: dummyUser1._id,
|
|
|
- parent: rootPage._id,
|
|
|
- isEmpty: true,
|
|
|
- },
|
|
|
- {
|
|
|
- path: '/mc4_top/mc1_emp/mc2_pub',
|
|
|
- grant: Page.GRANT_PUBLIC,
|
|
|
- creator: dummyUser1,
|
|
|
- lastUpdateUser: dummyUser1._id,
|
|
|
- parent: pageIdCreate2,
|
|
|
- isEmpty: false,
|
|
|
- },
|
|
|
- {
|
|
|
- path: '/mc5_top/mc3_awl',
|
|
|
- grant: Page.GRANT_RESTRICTED,
|
|
|
- creator: dummyUser1,
|
|
|
- lastUpdateUser: dummyUser1._id,
|
|
|
- isEmpty: false,
|
|
|
- },
|
|
|
- {
|
|
|
- _id: pageIdCreate3,
|
|
|
- path: '/mc4_top',
|
|
|
- grant: Page.GRANT_PUBLIC,
|
|
|
- creator: dummyUser1,
|
|
|
- lastUpdateUser: dummyUser1._id,
|
|
|
- isEmpty: false,
|
|
|
- parent: rootPage._id,
|
|
|
- descendantCount: 1,
|
|
|
- },
|
|
|
- {
|
|
|
- _id: pageIdCreate4,
|
|
|
- path: '/mc5_top',
|
|
|
- grant: Page.GRANT_PUBLIC,
|
|
|
- creator: dummyUser1,
|
|
|
- lastUpdateUser: dummyUser1._id,
|
|
|
- isEmpty: false,
|
|
|
- parent: rootPage._id,
|
|
|
- descendantCount: 0,
|
|
|
- },
|
|
|
- ]);
|
|
|
-
|
|
|
/**
|
|
|
* update
|
|
|
* mup_ => model update
|
|
|
@@ -507,96 +434,6 @@ describe('Page', () => {
|
|
|
},
|
|
|
]);
|
|
|
|
|
|
- });
|
|
|
- describe('create', () => {
|
|
|
-
|
|
|
- test('Should create single page', async() => {
|
|
|
- const page = await crowi.pageService.create('/v5_create1', 'create1', dummyUser1, {});
|
|
|
- expect(page).toBeTruthy();
|
|
|
- expect(page.parent).toStrictEqual(rootPage._id);
|
|
|
- });
|
|
|
-
|
|
|
- test('Should create empty-child and non-empty grandchild', async() => {
|
|
|
- const grandchildPage = await crowi.pageService.create('/v5_empty_create2/v5_create_3', 'grandchild', dummyUser1, {});
|
|
|
- const childPage = await Page.findOne({ path: '/v5_empty_create2' });
|
|
|
-
|
|
|
- expect(childPage.isEmpty).toBe(true);
|
|
|
- expect(grandchildPage).toBeTruthy();
|
|
|
- expect(childPage).toBeTruthy();
|
|
|
- expect(childPage.parent).toStrictEqual(rootPage._id);
|
|
|
- expect(grandchildPage.parent).toStrictEqual(childPage._id);
|
|
|
- });
|
|
|
-
|
|
|
- test('Should create on empty page', async() => {
|
|
|
- const beforeCreatePage = await Page.findOne({ path: '/v5_empty_create_4' });
|
|
|
- expect(beforeCreatePage.isEmpty).toBe(true);
|
|
|
-
|
|
|
- const childPage = await crowi.pageService.create('/v5_empty_create_4', 'body', dummyUser1, {});
|
|
|
- const grandchildPage = await Page.findOne({ parent: childPage._id });
|
|
|
-
|
|
|
- expect(childPage).toBeTruthy();
|
|
|
- expect(childPage.isEmpty).toBe(false);
|
|
|
- expect(childPage.revision.body).toBe('body');
|
|
|
- expect(grandchildPage).toBeTruthy();
|
|
|
- expect(childPage.parent).toStrictEqual(rootPage._id);
|
|
|
- expect(grandchildPage.parent).toStrictEqual(childPage._id);
|
|
|
- });
|
|
|
-
|
|
|
- describe('Creating a page using existing path', () => {
|
|
|
- test('with grant RESTRICTED should only create the page and change nothing else', async() => {
|
|
|
- const pathT = '/mc4_top';
|
|
|
- const path1 = '/mc4_top/mc1_emp';
|
|
|
- const path2 = '/mc4_top/mc1_emp/mc2_pub';
|
|
|
- const pageT = await Page.findOne({ path: pathT, descendantCount: 1 });
|
|
|
- const page1 = await Page.findOne({ path: path1, grant: Page.GRANT_PUBLIC });
|
|
|
- const page2 = await Page.findOne({ path: path2 });
|
|
|
- const page3 = await Page.findOne({ path: path1, grant: Page.GRANT_RESTRICTED });
|
|
|
- expect(pageT).toBeTruthy();
|
|
|
- expect(page1).toBeTruthy();
|
|
|
- expect(page2).toBeTruthy();
|
|
|
- expect(page3).toBeNull();
|
|
|
-
|
|
|
- // use existing path
|
|
|
- await crowi.pageService.create(path1, 'new body', dummyUser1, { grant: Page.GRANT_RESTRICTED });
|
|
|
-
|
|
|
- const _pageT = await Page.findOne({ path: pathT });
|
|
|
- const _page1 = await Page.findOne({ path: path1, grant: Page.GRANT_PUBLIC });
|
|
|
- const _page2 = await Page.findOne({ path: path2 });
|
|
|
- const _page3 = await Page.findOne({ path: path1, grant: Page.GRANT_RESTRICTED });
|
|
|
- expect(_pageT).toBeTruthy();
|
|
|
- expect(_page1).toBeTruthy();
|
|
|
- expect(_page2).toBeTruthy();
|
|
|
- expect(_page3).toBeTruthy();
|
|
|
- expect(_pageT.descendantCount).toBe(1);
|
|
|
- });
|
|
|
- });
|
|
|
- describe('Creating a page under a page with grant RESTRICTED', () => {
|
|
|
- test('will create a new empty page with the same path as the grant RESTRECTED page and become a parent', async() => {
|
|
|
- const pathT = '/mc5_top';
|
|
|
- const path1 = '/mc5_top/mc3_awl';
|
|
|
- const pathN = '/mc5_top/mc3_awl/mc4_pub'; // used to create
|
|
|
- const pageT = await Page.findOne({ path: pathT });
|
|
|
- const page1 = await Page.findOne({ path: path1, grant: Page.GRANT_RESTRICTED });
|
|
|
- const page2 = await Page.findOne({ path: path1, grant: Page.GRANT_PUBLIC });
|
|
|
- expect(pageT).toBeTruthy();
|
|
|
- expect(page1).toBeTruthy();
|
|
|
- expect(page2).toBeNull();
|
|
|
-
|
|
|
- await crowi.pageService.create(pathN, 'new body', dummyUser1, { grant: Page.GRANT_PUBLIC });
|
|
|
-
|
|
|
- const _pageT = await Page.findOne({ path: pathT });
|
|
|
- const _page1 = await Page.findOne({ path: path1, grant: Page.GRANT_RESTRICTED });
|
|
|
- const _page2 = await Page.findOne({ path: path1, grant: Page.GRANT_PUBLIC, isEmpty: true });
|
|
|
- const _pageN = await Page.findOne({ path: pathN, grant: Page.GRANT_PUBLIC }); // newly crated
|
|
|
- expect(_pageT).toBeTruthy();
|
|
|
- expect(_page1).toBeTruthy();
|
|
|
- expect(_page2).toBeTruthy();
|
|
|
- expect(_pageN).toBeTruthy();
|
|
|
- expect(_pageN.parent).toStrictEqual(_page2._id);
|
|
|
- expect(_pageT.descendantCount).toStrictEqual(1);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
});
|
|
|
|
|
|
describe('update', () => {
|