From 29ff4615a380276cf00511067d3f6cdee5097c44 Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Tue, 24 Oct 2023 15:49:58 +0200 Subject: [PATCH 01/12] Fix idm to dto mapper --- .../account-idm-to-dto.mapper.db.spec.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/account/mapper/account-idm-to-dto.mapper.db.spec.ts b/apps/server/src/modules/account/mapper/account-idm-to-dto.mapper.db.spec.ts index 2430afe6081..caa811beec8 100644 --- a/apps/server/src/modules/account/mapper/account-idm-to-dto.mapper.db.spec.ts +++ b/apps/server/src/modules/account/mapper/account-idm-to-dto.mapper.db.spec.ts @@ -54,15 +54,25 @@ describe('AccountIdmToDtoMapperDb', () => { }); describe('when date is undefined', () => { - it('should use actual date', () => { + const setup = () => { const testIdmEntity: IdmAccount = { id: 'id', }; + + const mockDate = new Date(); + jest.useFakeTimers(); + jest.setSystemTime(mockDate); + + return { testIdmEntity, mockDate }; + }; + + it('should use actual date', () => { + const { testIdmEntity, mockDate } = setup(); + const ret = mapper.mapToDto(testIdmEntity); - const now = new Date(); - expect(ret.createdAt).toEqual(now); - expect(ret.updatedAt).toEqual(now); + expect(ret.createdAt).toEqual(mockDate); + expect(ret.updatedAt).toEqual(mockDate); }); }); From db09494362594b20c93e68194674ded96b5520c0 Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Tue, 24 Oct 2023 15:57:12 +0200 Subject: [PATCH 02/12] Reset fake timers --- .../mapper/account-idm-to-dto.mapper.db.spec.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/server/src/modules/account/mapper/account-idm-to-dto.mapper.db.spec.ts b/apps/server/src/modules/account/mapper/account-idm-to-dto.mapper.db.spec.ts index caa811beec8..0774457472a 100644 --- a/apps/server/src/modules/account/mapper/account-idm-to-dto.mapper.db.spec.ts +++ b/apps/server/src/modules/account/mapper/account-idm-to-dto.mapper.db.spec.ts @@ -59,20 +59,22 @@ describe('AccountIdmToDtoMapperDb', () => { id: 'id', }; - const mockDate = new Date(); + const dateMock = new Date(); jest.useFakeTimers(); - jest.setSystemTime(mockDate); + jest.setSystemTime(dateMock); - return { testIdmEntity, mockDate }; + return { testIdmEntity, dateMock }; }; it('should use actual date', () => { - const { testIdmEntity, mockDate } = setup(); + const { testIdmEntity, dateMock } = setup(); const ret = mapper.mapToDto(testIdmEntity); - expect(ret.createdAt).toEqual(mockDate); - expect(ret.updatedAt).toEqual(mockDate); + expect(ret.createdAt).toEqual(dateMock); + expect(ret.updatedAt).toEqual(dateMock); + + jest.useRealTimers(); }); }); From 9a52633b13bace74333a84bd0b7c284efc760bc6 Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Tue, 24 Oct 2023 16:01:15 +0200 Subject: [PATCH 03/12] Mock FilesStorageClientAdapterService in task copy timeout test --- .../api-test/task-copy-timeout.api.spec.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts b/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts index 446a0fab032..f44a0f92fcb 100644 --- a/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts +++ b/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts @@ -1,9 +1,10 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { IConfig } from '@hpi-schul-cloud/commons/lib/interfaces/IConfig'; import { EntityManager } from '@mikro-orm/mongodb'; +import { ICurrentUser } from '@modules/authentication'; +import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { ICurrentUser } from '@modules/authentication'; import { cleanupCollections, courseFactory, @@ -12,14 +13,15 @@ import { taskFactory, userFactory, } from '@shared/testing'; -import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; import { Request } from 'express'; import request from 'supertest'; +// eslint-disable-next-line import/first +import { createMock } from '@golevelup/ts-jest'; +import { ServerTestModule } from '@modules/server/server.module'; +import { FilesStorageClientAdapterService } from '@src/modules/files-storage-client'; Configuration.set('FEATURE_COPY_SERVICE_ENABLED', true); Configuration.set('INCOMING_REQUEST_TIMEOUT_COPY_API', 1); -// eslint-disable-next-line import/first -import { ServerTestModule } from '@modules/server/server.module'; // This needs to be in a separate test file because of the above configuration. // When we find a way to mock the config, it should be moved alongside the other API tests. @@ -42,6 +44,8 @@ describe('Task copy (API)', () => { return true; }, }) + .overrideProvider(FilesStorageClientAdapterService) + .useValue(createMock()) .compile(); app = moduleFixture.createNestApplication(); From 4c0706c9ef210e0953461572984954e861c045e8 Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Wed, 25 Oct 2023 08:32:33 +0200 Subject: [PATCH 04/12] Move configuration setters above import of test module --- .../controller/api-test/task-copy-timeout.api.spec.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts b/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts index f44a0f92fcb..1598874a56f 100644 --- a/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts +++ b/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts @@ -15,14 +15,14 @@ import { } from '@shared/testing'; import { Request } from 'express'; import request from 'supertest'; -// eslint-disable-next-line import/first -import { createMock } from '@golevelup/ts-jest'; -import { ServerTestModule } from '@modules/server/server.module'; -import { FilesStorageClientAdapterService } from '@src/modules/files-storage-client'; +// config must be set outside before the server module is imported, otherwise the configuration is already set Configuration.set('FEATURE_COPY_SERVICE_ENABLED', true); Configuration.set('INCOMING_REQUEST_TIMEOUT_COPY_API', 1); +// eslint-disable-next-line import/first +import { ServerTestModule } from '@modules/server/server.module'; + // This needs to be in a separate test file because of the above configuration. // When we find a way to mock the config, it should be moved alongside the other API tests. describe('Task copy (API)', () => { @@ -44,8 +44,6 @@ describe('Task copy (API)', () => { return true; }, }) - .overrideProvider(FilesStorageClientAdapterService) - .useValue(createMock()) .compile(); app = moduleFixture.createNestApplication(); From 8827c59ae1135f1799571ee1cb30321babcb87a5 Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Wed, 25 Oct 2023 09:08:44 +0200 Subject: [PATCH 05/12] Add file storage client mock --- .../task/controller/api-test/task-copy-timeout.api.spec.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts b/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts index 1598874a56f..e8b36f75958 100644 --- a/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts +++ b/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts @@ -1,3 +1,4 @@ +import { createMock } from '@golevelup/ts-jest'; import { Configuration } from '@hpi-schul-cloud/commons/lib'; import { IConfig } from '@hpi-schul-cloud/commons/lib/interfaces/IConfig'; import { EntityManager } from '@mikro-orm/mongodb'; @@ -13,6 +14,7 @@ import { taskFactory, userFactory, } from '@shared/testing'; +import { FilesStorageClientAdapterService } from '@src/modules/files-storage-client'; import { Request } from 'express'; import request from 'supertest'; @@ -44,6 +46,8 @@ describe('Task copy (API)', () => { return true; }, }) + .overrideProvider(FilesStorageClientAdapterService) + .useValue(createMock()) .compile(); app = moduleFixture.createNestApplication(); From b344b8d3f48ce04183e5346ead17b8a80b2143cc Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Wed, 25 Oct 2023 10:47:31 +0200 Subject: [PATCH 06/12] Remove unecessary setSystemTime --- .../modules/legacy-school/service/school-year.service.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts b/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts index 041b80d41d1..4aded660643 100644 --- a/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts +++ b/apps/server/src/modules/legacy-school/service/school-year.service.spec.ts @@ -35,7 +35,6 @@ describe('SchoolYearService', () => { describe('getCurrentSchoolYear', () => { const setup = () => { - jest.setSystemTime(new Date('2022-06-01').getTime()); const schoolYear: SchoolYearEntity = schoolYearFactory.build({ startDate: new Date('2021-09-01'), endDate: new Date('2022-12-31'), @@ -60,7 +59,6 @@ describe('SchoolYearService', () => { describe('findById', () => { const setup = () => { - jest.setSystemTime(new Date('2022-06-01').getTime()); const schoolYear: SchoolYearEntity = schoolYearFactory.build({ startDate: new Date('2021-09-01'), endDate: new Date('2022-12-31'), From 7a890b38b07d17eb975d0593a2d9b22ab138d36a Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Wed, 25 Oct 2023 10:55:30 +0200 Subject: [PATCH 07/12] Mock node clam --- .../controller/api-test/files-security.api.spec.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts index d6b6f4b7479..447c2e05dcc 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts @@ -1,9 +1,13 @@ +import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; +import { ICurrentUser } from '@modules/authentication'; +import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; +import { FilesStorageTestModule } from '@modules/files-storage'; +import { FileRecordListResponse, ScanResultParams } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; import { Permission } from '@shared/domain'; -import { ICurrentUser } from '@modules/authentication'; import { cleanupCollections, fileRecordFactory, @@ -12,9 +16,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; -import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordListResponse, ScanResultParams } from '@modules/files-storage/controller/dto'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import request from 'supertest'; import { FileRecord, FileRecordParentType } from '../../entity'; @@ -62,6 +64,8 @@ describe(`${baseRouteName} (api)`, () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); From b6fcad060f7cde9d9993c0f98f8ea1096e7c7be6 Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Wed, 25 Oct 2023 10:57:00 +0200 Subject: [PATCH 08/12] Add node clam mock --- .../api-test/files-storage-list-files.api.spec.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts index b4d974fb24e..fcb04b9333e 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts @@ -1,4 +1,9 @@ +import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; +import { ICurrentUser } from '@modules/authentication'; +import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; +import { FilesStorageTestModule } from '@modules/files-storage'; +import { FileRecordListResponse, FileRecordResponse } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -11,10 +16,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; -import { ICurrentUser } from '@modules/authentication'; -import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordListResponse, FileRecordResponse } from '@modules/files-storage/controller/dto'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import request from 'supertest'; import { FileRecordParentType, PreviewStatus } from '../../entity'; @@ -62,6 +64,8 @@ describe(`${baseRouteName} (api)`, () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); From 411481ad08120ffe33f1e2bbd9a4393971c65e7b Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Wed, 25 Oct 2023 11:02:08 +0200 Subject: [PATCH 09/12] Add node clam mock --- .../files-storage-copy-files.api.spec.ts | 21 +++++++++++-------- .../files-storage-delete-files.api.spec.ts | 11 ++++++---- .../files-storage-download-upload.api.spec.ts | 11 ++++++---- .../files-storage-preview.api.spec.ts | 11 ++++++---- .../files-storage-rename-file.api.spec.ts | 12 +++++++---- .../files-storage-restore-files.api.spec.ts | 11 ++++++---- 6 files changed, 48 insertions(+), 29 deletions(-) diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts index e1b792dea36..48b6360702c 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts @@ -1,5 +1,14 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; +import { ICurrentUser } from '@modules/authentication'; +import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; +import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; +import { + CopyFileParams, + CopyFilesOfParentParams, + FileRecordListResponse, + FileRecordResponse, +} from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -15,15 +24,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; -import { ICurrentUser } from '@modules/authentication'; -import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; -import { - CopyFileParams, - CopyFilesOfParentParams, - FileRecordListResponse, - FileRecordResponse, -} from '@modules/files-storage/controller/dto'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; @@ -107,6 +108,8 @@ describe(`${baseRouteName} (api)`, () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts index 7a25915b3d5..59026bd0093 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts @@ -1,5 +1,9 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; +import { ICurrentUser } from '@modules/authentication'; +import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; +import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; +import { FileRecordListResponse, FileRecordResponse } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -14,10 +18,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; -import { ICurrentUser } from '@modules/authentication'; -import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordListResponse, FileRecordResponse } from '@modules/files-storage/controller/dto'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; @@ -101,6 +102,8 @@ describe(`${baseRouteName} (api)`, () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts index 331282060e2..0ab5ca7476d 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts @@ -1,5 +1,9 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; +import { ICurrentUser } from '@modules/authentication'; +import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; +import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; +import { FileRecordResponse } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -7,10 +11,7 @@ import { EntityId, Permission } from '@shared/domain'; import { AntivirusService } from '@shared/infra/antivirus'; import { S3ClientAdapter } from '@shared/infra/s3-client'; import { cleanupCollections, mapUserToCurrentUser, roleFactory, schoolFactory, userFactory } from '@shared/testing'; -import { ICurrentUser } from '@modules/authentication'; -import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordResponse } from '@modules/files-storage/controller/dto'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; @@ -114,6 +115,8 @@ describe('files-storage controller (API)', () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts index 82cc8545a97..822c3be7a03 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts @@ -1,5 +1,9 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; +import { ICurrentUser } from '@modules/authentication'; +import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; +import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; +import { FileRecordResponse } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication, NotFoundException, StreamableFile } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -7,10 +11,7 @@ import { EntityId, Permission } from '@shared/domain'; import { AntivirusService } from '@shared/infra/antivirus'; import { S3ClientAdapter } from '@shared/infra/s3-client'; import { cleanupCollections, mapUserToCurrentUser, roleFactory, schoolFactory, userFactory } from '@shared/testing'; -import { ICurrentUser } from '@modules/authentication'; -import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordResponse } from '@modules/files-storage/controller/dto'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; @@ -111,6 +112,8 @@ describe('File Controller (API) - preview', () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts index e28f4dc327f..cc35fa15743 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts @@ -1,9 +1,13 @@ +import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; +import { ICurrentUser } from '@modules/authentication'; +import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; +import { FilesStorageTestModule } from '@modules/files-storage'; +import { FileRecordResponse, RenameFileParams } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; import { Permission } from '@shared/domain'; -import { ICurrentUser } from '@modules/authentication'; import { cleanupCollections, fileRecordFactory, @@ -12,9 +16,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; -import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordResponse, RenameFileParams } from '@modules/files-storage/controller/dto'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import request from 'supertest'; import { FileRecord, FileRecordParentType } from '../../entity'; @@ -62,6 +64,8 @@ describe(`${baseRouteName} (api)`, () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts index f6e9a694ad3..e17d85ec6fb 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts @@ -1,5 +1,9 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; +import { ICurrentUser } from '@modules/authentication'; +import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; +import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; +import { FileRecordListResponse, FileRecordResponse } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -14,10 +18,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; -import { ICurrentUser } from '@modules/authentication'; -import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordListResponse, FileRecordResponse } from '@modules/files-storage/controller/dto'; +import NodeClam from 'clamscan'; import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; @@ -126,6 +127,8 @@ describe(`${baseRouteName} (api)`, () => { return true; }, }) + .overrideProvider(NodeClam) + .useValue(createMock()) .compile(); app = module.createNestApplication(); From 4710c0c357237377ee8ca24031a9e15f1187205f Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Wed, 25 Oct 2023 11:03:39 +0200 Subject: [PATCH 10/12] Fix import of files-storage-client --- .../task/controller/api-test/task-copy-timeout.api.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts b/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts index e8b36f75958..d5546c435da 100644 --- a/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts +++ b/apps/server/src/modules/task/controller/api-test/task-copy-timeout.api.spec.ts @@ -4,6 +4,7 @@ import { IConfig } from '@hpi-schul-cloud/commons/lib/interfaces/IConfig'; import { EntityManager } from '@mikro-orm/mongodb'; import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; +import { FilesStorageClientAdapterService } from '@modules/files-storage-client'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { @@ -14,7 +15,6 @@ import { taskFactory, userFactory, } from '@shared/testing'; -import { FilesStorageClientAdapterService } from '@src/modules/files-storage-client'; import { Request } from 'express'; import request from 'supertest'; From 9ab02dacab3e379d43fbd4d34e95960e8be3c250 Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Wed, 25 Oct 2023 12:21:08 +0200 Subject: [PATCH 11/12] Change to relative imports --- .../controller/api-test/files-security.api.spec.ts | 4 ++-- .../api-test/files-storage-copy-files.api.spec.ts | 10 +++------- .../api-test/files-storage-delete-files.api.spec.ts | 5 +++-- .../api-test/files-storage-download-upload.api.spec.ts | 5 +++-- .../api-test/files-storage-list-files.api.spec.ts | 4 ++-- .../api-test/files-storage-preview.api.spec.ts | 5 +++-- .../api-test/files-storage-rename-file.api.spec.ts | 4 ++-- .../api-test/files-storage-restore-files.api.spec.ts | 5 +++-- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts index 447c2e05dcc..4694b1817ac 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-security.api.spec.ts @@ -2,8 +2,6 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordListResponse, ScanResultParams } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -20,6 +18,8 @@ import NodeClam from 'clamscan'; import { Request } from 'express'; import request from 'supertest'; import { FileRecord, FileRecordParentType } from '../../entity'; +import { FilesStorageTestModule } from '../../files-storage-test.module'; +import { FileRecordListResponse, ScanResultParams } from '../dto'; const baseRouteName = '/file-security'; const scanResult: ScanResultParams = { virus_detected: false }; diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts index 48b6360702c..22a7a11fb5b 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-copy-files.api.spec.ts @@ -2,13 +2,6 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; -import { - CopyFileParams, - CopyFilesOfParentParams, - FileRecordListResponse, - FileRecordResponse, -} from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -29,6 +22,9 @@ import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; import { FileRecordParentType } from '../../entity'; +import { FilesStorageTestModule } from '../../files-storage-test.module'; +import { FILES_STORAGE_S3_CONNECTION } from '../../files-storage.config'; +import { CopyFileParams, CopyFilesOfParentParams, FileRecordListResponse, FileRecordResponse } from '../dto'; import { availableParentTypes } from './mocks'; const baseRouteName = '/file/copy'; diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts index 59026bd0093..0557843b8eb 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-delete-files.api.spec.ts @@ -2,8 +2,6 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordListResponse, FileRecordResponse } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -23,6 +21,9 @@ import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; import { FileRecordParentType, PreviewStatus } from '../../entity'; +import { FilesStorageTestModule } from '../../files-storage-test.module'; +import { FILES_STORAGE_S3_CONNECTION } from '../../files-storage.config'; +import { FileRecordListResponse, FileRecordResponse } from '../dto'; import { availableParentTypes } from './mocks'; const baseRouteName = '/file/delete'; diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts index 0ab5ca7476d..e86b778e0ce 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-download-upload.api.spec.ts @@ -2,8 +2,6 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordResponse } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -17,7 +15,10 @@ import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; import { FileRecord } from '../../entity'; import { ErrorType } from '../../error'; +import { FilesStorageTestModule } from '../../files-storage-test.module'; +import { FILES_STORAGE_S3_CONNECTION } from '../../files-storage.config'; import { TestHelper } from '../../helper/test-helper'; +import { FileRecordResponse } from '../dto'; import { availableParentTypes } from './mocks'; jest.mock('file-type-cjs/file-type-cjs-index', () => { diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts index fcb04b9333e..35410d712c8 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-list-files.api.spec.ts @@ -2,8 +2,6 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordListResponse, FileRecordResponse } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -20,6 +18,8 @@ import NodeClam from 'clamscan'; import { Request } from 'express'; import request from 'supertest'; import { FileRecordParentType, PreviewStatus } from '../../entity'; +import { FilesStorageTestModule } from '../../files-storage-test.module'; +import { FileRecordListResponse, FileRecordResponse } from '../dto'; import { availableParentTypes } from './mocks'; const baseRouteName = '/file/list'; diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts index 822c3be7a03..22749024b31 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-preview.api.spec.ts @@ -2,8 +2,6 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordResponse } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication, NotFoundException, StreamableFile } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -17,9 +15,12 @@ import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; import { FileRecord, ScanStatus } from '../../entity'; import { ErrorType } from '../../error'; +import { FilesStorageTestModule } from '../../files-storage-test.module'; +import { FILES_STORAGE_S3_CONNECTION } from '../../files-storage.config'; import { TestHelper } from '../../helper/test-helper'; import { PreviewWidth } from '../../interface'; import { PreviewOutputMimeTypes } from '../../interface/preview-output-mime-types.enum'; +import { FileRecordResponse } from '../dto'; jest.mock('file-type-cjs/file-type-cjs-index', () => { return { diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts index cc35fa15743..fb1dfa866eb 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-rename-file.api.spec.ts @@ -2,8 +2,6 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordResponse, RenameFileParams } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -20,6 +18,8 @@ import NodeClam from 'clamscan'; import { Request } from 'express'; import request from 'supertest'; import { FileRecord, FileRecordParentType } from '../../entity'; +import { FilesStorageTestModule } from '../../files-storage-test.module'; +import { FileRecordResponse, RenameFileParams } from '../dto'; const baseRouteName = '/file/rename/'; diff --git a/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts b/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts index e17d85ec6fb..496f399d41b 100644 --- a/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts +++ b/apps/server/src/modules/files-storage/controller/api-test/files-storage-restore-files.api.spec.ts @@ -2,8 +2,6 @@ import { createMock } from '@golevelup/ts-jest'; import { EntityManager, ObjectId } from '@mikro-orm/mongodb'; import { ICurrentUser } from '@modules/authentication'; import { JwtAuthGuard } from '@modules/authentication/guard/jwt-auth.guard'; -import { FILES_STORAGE_S3_CONNECTION, FilesStorageTestModule } from '@modules/files-storage'; -import { FileRecordListResponse, FileRecordResponse } from '@modules/files-storage/controller/dto'; import { ExecutionContext, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; @@ -23,6 +21,9 @@ import { Request } from 'express'; import FileType from 'file-type-cjs/file-type-cjs-index'; import request from 'supertest'; import { FileRecordParentType, PreviewStatus } from '../../entity'; +import { FilesStorageTestModule } from '../../files-storage-test.module'; +import { FILES_STORAGE_S3_CONNECTION } from '../../files-storage.config'; +import { FileRecordListResponse, FileRecordResponse } from '../dto'; import { availableParentTypes } from './mocks'; const baseRouteName = '/file/restore'; From 477cad170298fe9dff10f35ae32c56b450445953 Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Wed, 25 Oct 2023 12:34:37 +0200 Subject: [PATCH 12/12] Increase timeout of nest lint github action --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 964ab20c8f8..cbf52acce55 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -94,7 +94,7 @@ jobs: SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} nest_lint: runs-on: ubuntu-latest - timeout-minutes: 5 + timeout-minutes: 6 steps: - name: checkout uses: actions/checkout@v3