Taichi Masuyama 4 лет назад
Родитель
Сommit
57636edbe3

+ 6 - 1
packages/app/test/integration/service/v5.migration.test.js

@@ -26,7 +26,7 @@ describe('V5 page migration', () => {
       jest.restoreAllMocks();
 
       // initialize pages for test
-      const pages = await Page.insertMany([
+      let pages = await Page.insertMany([
         {
           path: '/private1',
           grant: Page.GRANT_OWNER,
@@ -57,6 +57,11 @@ describe('V5 page migration', () => {
         },
       ]);
 
+      if (!await Page.exists({ path: '/' })) {
+        const additionalPages = await Page.insertMany([{ path: '/', grant: Page.GRANT_PUBLIC }]);
+        pages = [...additionalPages, ...pages];
+      }
+
       const pageIds = pages.map(page => page._id);
       // migrate
       await crowi.pageService.normalizeParentRecursivelyByPageIds(pageIds, testUser1);

+ 37 - 0
packages/app/test/integration/v5-page-global-setup.js

@@ -0,0 +1,37 @@
+/** **********************************************************
+ *                           Caution
+ *
+ * Module aliases by compilerOptions.paths in tsconfig.json
+ * are NOT available in setup scripts
+ *********************************************************** */
+
+import 'tsconfig-paths/register';
+
+import mongoose from 'mongoose';
+
+import { initMongooseGlobalSettings, getMongoUri, mongoOptions } from '@growi/core';
+
+// check env
+if (process.env.NODE_ENV !== 'test') {
+  throw new Error('\'process.env.NODE_ENV\' must be \'test\'');
+}
+
+
+// eslint-disable-next-line @typescript-eslint/no-var-requires
+// const { getInstance } = require('./setup-crowi');
+
+module.exports = async() => {
+  initMongooseGlobalSettings();
+  process.env.MONGO_URI = 'mongodb://mongo/growi_pagev5_test';
+  await mongoose.connect(getMongoUri(), mongoOptions);
+
+  // drop database
+  await mongoose.connection.dropDatabase();
+
+  // init DB
+  // const crowi = await getInstance();
+  // const appService = crowi.appService;
+  // await appService.initDB();
+
+  await mongoose.disconnect();
+};

+ 26 - 0
packages/app/test/integration/v5-page-setup.js

@@ -0,0 +1,26 @@
+/** **********************************************************
+ *                           Caution
+ *
+ * Module aliases by compilerOptions.paths in tsconfig.json
+ * are NOT available in setup scripts
+ *********************************************************** */
+
+const mongoose = require('mongoose');
+
+const { initMongooseGlobalSettings, getMongoUri, mongoOptions } = require('@growi/core');
+
+mongoose.Promise = global.Promise;
+
+jest.setTimeout(30000); // default 5000
+
+beforeAll(async() => {
+  initMongooseGlobalSettings();
+  process.env.MONGO_URI = 'mongodb://mongo/growi_pagev5_test';
+  await mongoose.connect(getMongoUri(), mongoOptions);
+});
+
+afterAll(async() => {
+  await mongoose.disconnect();
+});
+
+module.exports = {};