From c260e7cd896eeda247499a710af89d9d175764a7 Mon Sep 17 00:00:00 2001 From: Arne Gnisa Date: Mon, 17 Jun 2024 15:21:00 +0200 Subject: [PATCH] N21-1967 review and tests fixes --- .../internal/board-node-copy-context.spec.ts | 13 +++++++++---- .../copy-files-of-parent-param.builder.spec.ts | 10 +++++----- .../mapper/files-storage-param.builder.spec.ts | 6 +++--- .../mapper/files-storage-param.builder.ts | 8 ++++++-- .../service/copy-files.service.ts | 4 ++-- .../service/files-storage-client.service.spec.ts | 8 ++++---- 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/apps/server/src/modules/board/service/internal/board-node-copy-context.spec.ts b/apps/server/src/modules/board/service/internal/board-node-copy-context.spec.ts index 410e8d818ea..c25a2dbe3c8 100644 --- a/apps/server/src/modules/board/service/internal/board-node-copy-context.spec.ts +++ b/apps/server/src/modules/board/service/internal/board-node-copy-context.spec.ts @@ -1,5 +1,6 @@ import { createMock } from '@golevelup/ts-jest'; import { ObjectId } from '@mikro-orm/mongodb'; +import { StorageLocation } from '@modules/files-storage/entity'; import { FileRecordParentType } from '@src/infra/rabbitmq'; import { FilesStorageClientAdapterService } from '@src/modules/files-storage-client'; import { BoardNodeCopyContext } from './board-node-copy-context'; @@ -8,8 +9,10 @@ describe(BoardNodeCopyContext.name, () => { describe('copyFilesOfParent', () => { const setup = () => { const contextProps = { - sourceSchoolId: new ObjectId().toHexString(), - targetSchoolId: new ObjectId().toHexString(), + sourceStorageLocationId: new ObjectId().toHexString(), + targetStorageLocationId: new ObjectId().toHexString(), + sourceStorageLocation: StorageLocation.SCHOOL, + targetStorageLocation: StorageLocation.SCHOOL, userId: new ObjectId().toHexString(), filesStorageClientAdapterService: createMock(), }; @@ -31,12 +34,14 @@ describe(BoardNodeCopyContext.name, () => { source: { parentId: sourceParentId, parentType: FileRecordParentType.BoardNode, - schoolId: contextProps.sourceSchoolId, + storageLocationId: contextProps.sourceStorageLocationId, + storageLocation: contextProps.sourceStorageLocation, }, target: { parentId: targetParentId, parentType: FileRecordParentType.BoardNode, - schoolId: contextProps.targetSchoolId, + storageLocationId: contextProps.targetStorageLocationId, + storageLocation: contextProps.targetStorageLocation, }, userId: contextProps.userId, }); diff --git a/apps/server/src/modules/files-storage-client/mapper/copy-files-of-parent-param.builder.spec.ts b/apps/server/src/modules/files-storage-client/mapper/copy-files-of-parent-param.builder.spec.ts index ccce67a089a..89193019d00 100644 --- a/apps/server/src/modules/files-storage-client/mapper/copy-files-of-parent-param.builder.spec.ts +++ b/apps/server/src/modules/files-storage-client/mapper/copy-files-of-parent-param.builder.spec.ts @@ -1,5 +1,5 @@ -import { ObjectId } from '@mikro-orm/mongodb'; import { FileRecordParentType } from '@infra/rabbitmq'; +import { ObjectId } from '@mikro-orm/mongodb'; import { lessonFactory, setupEntities, taskFactory } from '@shared/testing'; import { CopyFilesOfParentParamBuilder } from './copy-files-of-parent-param.builder'; import { FileParamBuilder } from './files-storage-param.builder'; @@ -14,8 +14,8 @@ describe('CopyFilesOfParentParamBuilder', () => { const sourceEntity = taskFactory.buildWithId({}); const targetEntity = taskFactory.buildWithId(); - const source = FileParamBuilder.build(sourceEntity.getSchoolId(), sourceEntity); - const target = FileParamBuilder.build(targetEntity.getSchoolId(), targetEntity); + const source = FileParamBuilder.build(sourceEntity.getSchoolId(), sourceEntity, StorageLocation.SCHOOL); + const target = FileParamBuilder.build(targetEntity.getSchoolId(), targetEntity, StorageLocation.SCHOOL); const result = CopyFilesOfParentParamBuilder.build(userId, source, target); @@ -41,8 +41,8 @@ describe('CopyFilesOfParentParamBuilder', () => { const sourceEntity = lessonFactory.buildWithId({}); const targetEntity = lessonFactory.buildWithId(); - const source = FileParamBuilder.build(sourceEntity.getSchoolId(), sourceEntity); - const target = FileParamBuilder.build(targetEntity.getSchoolId(), targetEntity); + const source = FileParamBuilder.build(sourceEntity.getSchoolId(), sourceEntity, StorageLocation.SCHOOL); + const target = FileParamBuilder.build(targetEntity.getSchoolId(), targetEntity, StorageLocation.SCHOOL); const result = CopyFilesOfParentParamBuilder.build(userId, source, target); diff --git a/apps/server/src/modules/files-storage-client/mapper/files-storage-param.builder.spec.ts b/apps/server/src/modules/files-storage-client/mapper/files-storage-param.builder.spec.ts index 4299a371011..04df2cf5207 100644 --- a/apps/server/src/modules/files-storage-client/mapper/files-storage-param.builder.spec.ts +++ b/apps/server/src/modules/files-storage-client/mapper/files-storage-param.builder.spec.ts @@ -14,7 +14,7 @@ describe('FileParamBuilder', () => { const parentId = '123'; // @ts-expect-error: Test case - expect(() => FileParamBuilder.build(schoolId, parentType, parentId)).toThrowError(); + expect(() => FileParamBuilder.build(schoolId, parentType, StorageLocation.SCHOOL)).toThrowError(); }); it('should build valid file request infos for task over shorthand task', () => { @@ -22,7 +22,7 @@ describe('FileParamBuilder', () => { const parentType = FileRecordParentType.Task; const task = taskFactory.buildWithId(); - const result = FileParamBuilder.build(schoolId, task); + const result = FileParamBuilder.build(schoolId, task, StorageLocation.SCHOOL); const expectedResult = { storageLocationId: schoolId, @@ -39,7 +39,7 @@ describe('FileParamBuilder', () => { const parentType = FileRecordParentType.Lesson; const lesson = lessonFactory.buildWithId(); - const result = FileParamBuilder.build(schoolId, lesson); + const result = FileParamBuilder.build(schoolId, lesson, StorageLocation.SCHOOL); const expectedResult = { storageLocationId: schoolId, diff --git a/apps/server/src/modules/files-storage-client/mapper/files-storage-param.builder.ts b/apps/server/src/modules/files-storage-client/mapper/files-storage-param.builder.ts index 597f297782b..3a0b3d37323 100644 --- a/apps/server/src/modules/files-storage-client/mapper/files-storage-param.builder.ts +++ b/apps/server/src/modules/files-storage-client/mapper/files-storage-param.builder.ts @@ -4,12 +4,16 @@ import { EntitiesWithFiles, FileRequestInfo } from '../interfaces'; import { FilesStorageClientMapper } from './files-storage-client.mapper'; export class FileParamBuilder { - static build(storageLocationId: EntityId, parent: EntitiesWithFiles): FileRequestInfo { + static build( + storageLocationId: EntityId, + parent: EntitiesWithFiles, + storageLocation: StorageLocation = StorageLocation.SCHOOL + ): FileRequestInfo { const parentType = FilesStorageClientMapper.mapEntityToParentType(parent); const fileRequestInfo = { parentType, storageLocationId, - storageLocation: StorageLocation.SCHOOL, + storageLocation, parentId: parent.id, }; diff --git a/apps/server/src/modules/files-storage-client/service/copy-files.service.ts b/apps/server/src/modules/files-storage-client/service/copy-files.service.ts index 75f46b26fd5..f3ea84ae747 100644 --- a/apps/server/src/modules/files-storage-client/service/copy-files.service.ts +++ b/apps/server/src/modules/files-storage-client/service/copy-files.service.ts @@ -23,8 +23,8 @@ export class CopyFilesService { fileUrlReplacements: FileUrlReplacement[]; fileCopyStatus: CopyStatus; }> { - const source = FileParamBuilder.build(originalEntity.getSchoolId(), originalEntity); - const target = FileParamBuilder.build(copyEntity.getSchoolId(), copyEntity); + const source = FileParamBuilder.build(originalEntity.getSchoolId(), originalEntity, StorageLocation.SCHOOL); + const target = FileParamBuilder.build(copyEntity.getSchoolId(), copyEntity, StorageLocation.SCHOOL); const copyFilesOfParentParams = CopyFilesOfParentParamBuilder.build(userId, source, target); const fileDtos = await this.filesStorageClientAdapterService.copyFilesOfParent(copyFilesOfParentParams); diff --git a/apps/server/src/modules/files-storage-client/service/files-storage-client.service.spec.ts b/apps/server/src/modules/files-storage-client/service/files-storage-client.service.spec.ts index fd30530c607..a2f0993fcbb 100644 --- a/apps/server/src/modules/files-storage-client/service/files-storage-client.service.spec.ts +++ b/apps/server/src/modules/files-storage-client/service/files-storage-client.service.spec.ts @@ -74,8 +74,8 @@ describe('FilesStorageClientAdapterService', () => { const sourceEntity = taskFactory.buildWithId({ school }); const targetEntity = taskFactory.buildWithId({ school }); - const source = FileParamBuilder.build(sourceEntity.getSchoolId(), sourceEntity); - const target = FileParamBuilder.build(targetEntity.getSchoolId(), targetEntity); + const source = FileParamBuilder.build(sourceEntity.getSchoolId(), sourceEntity, StorageLocation.SCHOOL); + const target = FileParamBuilder.build(targetEntity.getSchoolId(), targetEntity, StorageLocation.SCHOOL); const param = CopyFilesOfParentParamBuilder.build(userId, source, target); @@ -98,8 +98,8 @@ describe('FilesStorageClientAdapterService', () => { const sourceEntity = taskFactory.buildWithId({ school }); const targetEntity = taskFactory.buildWithId({ school }); - const source = FileParamBuilder.build(sourceEntity.getSchoolId(), sourceEntity); - const target = FileParamBuilder.build(targetEntity.getSchoolId(), targetEntity); + const source = FileParamBuilder.build(sourceEntity.getSchoolId(), sourceEntity, StorageLocation.SCHOOL); + const target = FileParamBuilder.build(targetEntity.getSchoolId(), targetEntity, StorageLocation.SCHOOL); const param = CopyFilesOfParentParamBuilder.build(userId, source, target);