Futa Arai 1 год назад
Родитель
Сommit
f0035c6011

+ 18 - 6
apps/app/src/features/page-bulk-export/server/service/page-bulk-export-job-cron.integ.ts

@@ -44,11 +44,11 @@ describe('PageBulkExportJobCronService', () => {
   });
   });
 
 
   describe('deleteExpiredExportJobs', () => {
   describe('deleteExpiredExportJobs', () => {
+    // arrange
     const jobId1 = new mongoose.Types.ObjectId();
     const jobId1 = new mongoose.Types.ObjectId();
     const jobId2 = new mongoose.Types.ObjectId();
     const jobId2 = new mongoose.Types.ObjectId();
     const jobId3 = new mongoose.Types.ObjectId();
     const jobId3 = new mongoose.Types.ObjectId();
     const jobId4 = new mongoose.Types.ObjectId();
     const jobId4 = new mongoose.Types.ObjectId();
-
     beforeEach(async() => {
     beforeEach(async() => {
       await configManager.updateConfigsInTheSameNamespace('crowi', { 'app:bulkExportJobExpirationSeconds': 86400 }); // 1 day
       await configManager.updateConfigsInTheSameNamespace('crowi', { 'app:bulkExportJobExpirationSeconds': 86400 }); // 1 day
 
 
@@ -84,21 +84,25 @@ describe('PageBulkExportJobCronService', () => {
     });
     });
 
 
     test('should delete expired jobs', async() => {
     test('should delete expired jobs', async() => {
+      // assert
       expect(await PageBulkExportJob.find()).toHaveLength(4);
       expect(await PageBulkExportJob.find()).toHaveLength(4);
-      await pageBulkExportJobCronService?.deleteExpiredExportJobs();
 
 
+      // act
+      await pageBulkExportJobCronService?.deleteExpiredExportJobs();
       const jobs = await PageBulkExportJob.find();
       const jobs = await PageBulkExportJob.find();
+
+      // assert
       expect(jobs).toHaveLength(2);
       expect(jobs).toHaveLength(2);
       expect(jobs.map(job => job._id).sort()).toStrictEqual([jobId1, jobId4].sort());
       expect(jobs.map(job => job._id).sort()).toStrictEqual([jobId1, jobId4].sort());
     });
     });
   });
   });
 
 
   describe('deleteDownloadExpiredExportJobs', () => {
   describe('deleteDownloadExpiredExportJobs', () => {
+    // arrange
     const jobId1 = new mongoose.Types.ObjectId();
     const jobId1 = new mongoose.Types.ObjectId();
     const jobId2 = new mongoose.Types.ObjectId();
     const jobId2 = new mongoose.Types.ObjectId();
     const jobId3 = new mongoose.Types.ObjectId();
     const jobId3 = new mongoose.Types.ObjectId();
     const jobId4 = new mongoose.Types.ObjectId();
     const jobId4 = new mongoose.Types.ObjectId();
-
     beforeEach(async() => {
     beforeEach(async() => {
       await configManager.updateConfigsInTheSameNamespace('crowi', { 'app:bulkExportDownloadExpirationSeconds': 86400 }); // 1 day
       await configManager.updateConfigsInTheSameNamespace('crowi', { 'app:bulkExportDownloadExpirationSeconds': 86400 }); // 1 day
 
 
@@ -129,20 +133,24 @@ describe('PageBulkExportJobCronService', () => {
     });
     });
 
 
     test('should delete download expired jobs', async() => {
     test('should delete download expired jobs', async() => {
+      // assert
       expect(await PageBulkExportJob.find()).toHaveLength(4);
       expect(await PageBulkExportJob.find()).toHaveLength(4);
-      await pageBulkExportJobCronService?.deleteDownloadExpiredExportJobs();
 
 
+      // act
+      await pageBulkExportJobCronService?.deleteDownloadExpiredExportJobs();
       const jobs = await PageBulkExportJob.find();
       const jobs = await PageBulkExportJob.find();
+
+      // assert
       expect(jobs).toHaveLength(3);
       expect(jobs).toHaveLength(3);
       expect(jobs.map(job => job._id).sort()).toStrictEqual([jobId1, jobId3, jobId4].sort());
       expect(jobs.map(job => job._id).sort()).toStrictEqual([jobId1, jobId3, jobId4].sort());
     });
     });
   });
   });
 
 
   describe('deleteFailedExportJobs', () => {
   describe('deleteFailedExportJobs', () => {
+    // arrange
     const jobId1 = new mongoose.Types.ObjectId();
     const jobId1 = new mongoose.Types.ObjectId();
     const jobId2 = new mongoose.Types.ObjectId();
     const jobId2 = new mongoose.Types.ObjectId();
     const jobId3 = new mongoose.Types.ObjectId();
     const jobId3 = new mongoose.Types.ObjectId();
-
     beforeEach(async() => {
     beforeEach(async() => {
       await PageBulkExportJob.insertMany([
       await PageBulkExportJob.insertMany([
         {
         {
@@ -158,10 +166,14 @@ describe('PageBulkExportJobCronService', () => {
     });
     });
 
 
     test('should delete failed export jobs', async() => {
     test('should delete failed export jobs', async() => {
+      // assert
       expect(await PageBulkExportJob.find()).toHaveLength(3);
       expect(await PageBulkExportJob.find()).toHaveLength(3);
-      await pageBulkExportJobCronService?.deleteFailedExportJobs();
 
 
+      // act
+      await pageBulkExportJobCronService?.deleteFailedExportJobs();
       const jobs = await PageBulkExportJob.find();
       const jobs = await PageBulkExportJob.find();
+
+      // assert
       expect(jobs).toHaveLength(1);
       expect(jobs).toHaveLength(1);
       expect(jobs.map(job => job._id)).toStrictEqual([jobId2]);
       expect(jobs.map(job => job._id)).toStrictEqual([jobId2]);
     });
     });

+ 2 - 1
apps/app/src/features/page-bulk-export/server/service/page-bulk-export/index.ts

@@ -3,6 +3,7 @@ import path from 'path';
 import { Writable } from 'stream';
 import { Writable } from 'stream';
 import { pipeline as pipelinePromise } from 'stream/promises';
 import { pipeline as pipelinePromise } from 'stream/promises';
 
 
+import type { IUser } from '@growi/core';
 import {
 import {
   getIdForRef, type IPage, isPopulated, SubscriptionStatusType,
   getIdForRef, type IPage, isPopulated, SubscriptionStatusType,
 } from '@growi/core';
 } from '@growi/core';
@@ -105,7 +106,7 @@ class PageBulkExportService {
    */
    */
   async executePageBulkExportJob(pageBulkExportJob: HydratedDocument<PageBulkExportJobDocument>, activityParameters?: ActivityParameters): Promise<void> {
   async executePageBulkExportJob(pageBulkExportJob: HydratedDocument<PageBulkExportJobDocument>, activityParameters?: ActivityParameters): Promise<void> {
     try {
     try {
-      const User = mongoose.model('User');
+      const User = mongoose.model<IUser>('User');
       const user = await User.findById(getIdForRef(pageBulkExportJob.user));
       const user = await User.findById(getIdForRef(pageBulkExportJob.user));
 
 
       if (pageBulkExportJob.status === PageBulkExportJobStatus.initializing) {
       if (pageBulkExportJob.status === PageBulkExportJobStatus.initializing) {