|
@@ -1,10 +1,11 @@
|
|
|
-import type { IPage, IUser } from '@growi/core';
|
|
|
|
|
-import mongoose from 'mongoose';
|
|
|
|
|
|
|
+// import type { IPage, IUser } from '@growi/core';
|
|
|
|
|
+// import mongoose from 'mongoose';
|
|
|
import { vi } from 'vitest';
|
|
import { vi } from 'vitest';
|
|
|
|
|
|
|
|
import { ObjectIdLike } from '~/server/interfaces/mongoose-utils';
|
|
import { ObjectIdLike } from '~/server/interfaces/mongoose-utils';
|
|
|
|
|
|
|
|
-import { PageModel } from '../../models/page';
|
|
|
|
|
|
|
+// import PageModel, { PageModel } from '../../models/page';
|
|
|
|
|
+// import { UserModel } from '../../models/user';
|
|
|
|
|
|
|
|
import { deleteCompletelyUserHomeBySystem } from './delete-completely-user-home-by-system';
|
|
import { deleteCompletelyUserHomeBySystem } from './delete-completely-user-home-by-system';
|
|
|
|
|
|
|
@@ -16,78 +17,64 @@ describe('delete-completely-user-home-by-system test', () => {
|
|
|
let Page;
|
|
let Page;
|
|
|
|
|
|
|
|
const testUser01Name = 'testUser01';
|
|
const testUser01Name = 'testUser01';
|
|
|
- const testUser02Name = 'testUser02';
|
|
|
|
|
|
|
|
|
|
const rootPagePath = '/';
|
|
const rootPagePath = '/';
|
|
|
const userPagePath = '/user';
|
|
const userPagePath = '/user';
|
|
|
const testUser01HomepagePath = `${userPagePath}/${testUser01Name}`;
|
|
const testUser01HomepagePath = `${userPagePath}/${testUser01Name}`;
|
|
|
const testUser01HomeSubpagePath = `${userPagePath}/${testUser01Name}/subpage`;
|
|
const testUser01HomeSubpagePath = `${userPagePath}/${testUser01Name}/subpage`;
|
|
|
- const testUser02HomepagePath = `${userPagePath}/${testUser02Name}`;
|
|
|
|
|
-
|
|
|
|
|
- beforeAll(async() => {
|
|
|
|
|
- User = mongoose.model<IUser>('User');
|
|
|
|
|
- Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
-
|
|
|
|
|
- const rootPageId = new mongoose.Types.ObjectId();
|
|
|
|
|
- const userPageId = new mongoose.Types.ObjectId();
|
|
|
|
|
- const testUser01HomepageId = new mongoose.Types.ObjectId();
|
|
|
|
|
-
|
|
|
|
|
- await User.insertMany([
|
|
|
|
|
- {
|
|
|
|
|
- name: testUser01Name,
|
|
|
|
|
- username: testUser01Name,
|
|
|
|
|
- email: `${testUser01Name}@example.com`,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- name: testUser02Name,
|
|
|
|
|
- username: testUser02Name,
|
|
|
|
|
- email: `${testUser02Name}@example.com`,
|
|
|
|
|
- },
|
|
|
|
|
- ]);
|
|
|
|
|
-
|
|
|
|
|
- await Page.insertMany([
|
|
|
|
|
- {
|
|
|
|
|
- _id: rootPageId,
|
|
|
|
|
- path: rootPagePath,
|
|
|
|
|
- grant: Page.GRANT_PUBLIC,
|
|
|
|
|
- isEmpty: true,
|
|
|
|
|
- parent: null,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- _id: userPageId,
|
|
|
|
|
- path: userPagePath,
|
|
|
|
|
- grant: Page.GRANT_PUBLIC,
|
|
|
|
|
- isEmpty: true,
|
|
|
|
|
- parent: rootPageId,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- _id: testUser01HomepageId,
|
|
|
|
|
- path: testUser01HomepagePath,
|
|
|
|
|
- grant: Page.GRANT_PUBLIC,
|
|
|
|
|
- isEmpty: true,
|
|
|
|
|
- parent: userPageId,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- _id: new mongoose.Types.ObjectId(),
|
|
|
|
|
- path: testUser02HomepagePath,
|
|
|
|
|
- grant: Page.GRANT_PUBLIC,
|
|
|
|
|
- isEmpty: true,
|
|
|
|
|
- parent: userPageId,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- _id: new mongoose.Types.ObjectId(),
|
|
|
|
|
- path: testUser01HomeSubpagePath,
|
|
|
|
|
- grant: Page.GRANT_PUBLIC,
|
|
|
|
|
- isEmpty: true,
|
|
|
|
|
- parent: testUser01HomepageId,
|
|
|
|
|
- },
|
|
|
|
|
- ]);
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- afterEach(async() => {
|
|
|
|
|
- await User.deleteMany({});
|
|
|
|
|
- await Page.deleteMany({});
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // beforeAll(async() => {
|
|
|
|
|
+ // User = mongoose.model<IUser>('User');
|
|
|
|
|
+ // Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
|
|
+
|
|
|
|
|
+ // const rootPageId = new mongoose.Types.ObjectId();
|
|
|
|
|
+ // const userPageId = new mongoose.Types.ObjectId();
|
|
|
|
|
+ // const testUser01HomepageId = new mongoose.Types.ObjectId();
|
|
|
|
|
+
|
|
|
|
|
+ // await User.insertMany([
|
|
|
|
|
+ // {
|
|
|
|
|
+ // name: testUser01Name,
|
|
|
|
|
+ // username: testUser01Name,
|
|
|
|
|
+ // email: `${testUser01Name}@example.com`,
|
|
|
|
|
+ // },
|
|
|
|
|
+ // ]);
|
|
|
|
|
+
|
|
|
|
|
+ // await PageModel.insertMany([
|
|
|
|
|
+ // {
|
|
|
|
|
+ // _id: rootPageId,
|
|
|
|
|
+ // path: rootPagePath,
|
|
|
|
|
+ // grant: Page.GRANT_PUBLIC,
|
|
|
|
|
+ // isEmpty: true,
|
|
|
|
|
+ // parent: null,
|
|
|
|
|
+ // },
|
|
|
|
|
+ // {
|
|
|
|
|
+ // _id: userPageId,
|
|
|
|
|
+ // path: userPagePath,
|
|
|
|
|
+ // grant: Page.GRANT_PUBLIC,
|
|
|
|
|
+ // isEmpty: true,
|
|
|
|
|
+ // parent: rootPageId,
|
|
|
|
|
+ // },
|
|
|
|
|
+ // {
|
|
|
|
|
+ // _id: testUser01HomepageId,
|
|
|
|
|
+ // path: testUser01HomepagePath,
|
|
|
|
|
+ // grant: Page.GRANT_PUBLIC,
|
|
|
|
|
+ // isEmpty: true,
|
|
|
|
|
+ // parent: userPageId,
|
|
|
|
|
+ // },
|
|
|
|
|
+ // {
|
|
|
|
|
+ // _id: new mongoose.Types.ObjectId(),
|
|
|
|
|
+ // path: testUser01HomeSubpagePath,
|
|
|
|
|
+ // grant: Page.GRANT_PUBLIC,
|
|
|
|
|
+ // isEmpty: true,
|
|
|
|
|
+ // parent: testUser01HomepageId,
|
|
|
|
|
+ // },
|
|
|
|
|
+ // ]);
|
|
|
|
|
+ // });
|
|
|
|
|
+
|
|
|
|
|
+ // afterEach(async() => {
|
|
|
|
|
+ // await User.deleteMany({});
|
|
|
|
|
+ // await Page.deleteMany({});
|
|
|
|
|
+ // });
|
|
|
|
|
|
|
|
describe('deleteCompletelyUserHomeBySystem()', () => {
|
|
describe('deleteCompletelyUserHomeBySystem()', () => {
|
|
|
const mockUpdateDescendantCountOfAncestors = vi.fn().mockImplementation(
|
|
const mockUpdateDescendantCountOfAncestors = vi.fn().mockImplementation(
|
|
@@ -110,7 +97,7 @@ describe('delete-completely-user-home-by-system test', () => {
|
|
|
|
|
|
|
|
it('should call page service functions', async() => {
|
|
it('should call page service functions', async() => {
|
|
|
// when
|
|
// when
|
|
|
- await deleteCompletelyUserHomeBySystem(testUser02HomepagePath, mockPageService);
|
|
|
|
|
|
|
+ await deleteCompletelyUserHomeBySystem(testUser01HomepagePath, mockPageService);
|
|
|
|
|
|
|
|
// then
|
|
// then
|
|
|
expect(mockUpdateDescendantCountOfAncestors).toHaveBeenCalled();
|
|
expect(mockUpdateDescendantCountOfAncestors).toHaveBeenCalled();
|