Skip to content

Commit

Permalink
N21-1967 review and tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arnegns committed Jun 17, 2024
1 parent 5631207 commit c260e7c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<FilesStorageClientAdapterService>(),
};
Expand All @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);

Check failure on line 17 in apps/server/src/modules/files-storage-client/mapper/copy-files-of-parent-param.builder.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe argument of type `any` assigned to a parameter of type `StorageLocation`

Check failure on line 17 in apps/server/src/modules/files-storage-client/mapper/copy-files-of-parent-param.builder.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe member access .SCHOOL on an `any` value
const target = FileParamBuilder.build(targetEntity.getSchoolId(), targetEntity, StorageLocation.SCHOOL);

Check failure on line 18 in apps/server/src/modules/files-storage-client/mapper/copy-files-of-parent-param.builder.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe argument of type `any` assigned to a parameter of type `StorageLocation`

Check failure on line 18 in apps/server/src/modules/files-storage-client/mapper/copy-files-of-parent-param.builder.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe member access .SCHOOL on an `any` value

const result = CopyFilesOfParentParamBuilder.build(userId, source, target);

Expand All @@ -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);

Check failure on line 44 in apps/server/src/modules/files-storage-client/mapper/copy-files-of-parent-param.builder.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe argument of type `any` assigned to a parameter of type `StorageLocation`

Check failure on line 44 in apps/server/src/modules/files-storage-client/mapper/copy-files-of-parent-param.builder.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe member access .SCHOOL on an `any` value
const target = FileParamBuilder.build(targetEntity.getSchoolId(), targetEntity, StorageLocation.SCHOOL);

Check failure on line 45 in apps/server/src/modules/files-storage-client/mapper/copy-files-of-parent-param.builder.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe argument of type `any` assigned to a parameter of type `StorageLocation`

Check failure on line 45 in apps/server/src/modules/files-storage-client/mapper/copy-files-of-parent-param.builder.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe member access .SCHOOL on an `any` value

const result = CopyFilesOfParentParamBuilder.build(userId, source, target);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ describe('FileParamBuilder', () => {
const parentId = '123';

Check failure on line 14 in apps/server/src/modules/files-storage-client/mapper/files-storage-param.builder.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'parentId' is assigned a value but never used

// @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', () => {
const schoolId = '123';
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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check failure on line 26 in apps/server/src/modules/files-storage-client/service/copy-files.service.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Unsafe argument of type `any` assigned to a parameter of type `StorageLocation`
const target = FileParamBuilder.build(copyEntity.getSchoolId(), copyEntity, StorageLocation.SCHOOL);
const copyFilesOfParentParams = CopyFilesOfParentParamBuilder.build(userId, source, target);

const fileDtos = await this.filesStorageClientAdapterService.copyFilesOfParent(copyFilesOfParentParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit c260e7c

Please sign in to comment.