Skip to content

Commit

Permalink
BC-7143 Show copy status for column board copy (#5040)
Browse files Browse the repository at this point in the history
  • Loading branch information
bischofmax authored Jun 3, 2024
1 parent 5504f93 commit 58ac8c4
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { FileRecordParentType } from '@infra/rabbitmq';
import { ObjectId } from '@mikro-orm/mongodb';
import { CopyElementType, CopyStatus, CopyStatusEnum } from '@modules/copy-helper';
import { CopyElementType, CopyHelperService, CopyStatus, CopyStatusEnum } from '@modules/copy-helper';
import { ContextExternalTool } from '@modules/tool/context-external-tool/domain';
import { ContextExternalToolService } from '@modules/tool/context-external-tool/service';
import { contextExternalToolFactory } from '@modules/tool/context-external-tool/testing';
Expand Down Expand Up @@ -48,6 +48,7 @@ describe('recursive board copy visitor', () => {
let service: BoardDoCopyService;

let contextExternalToolService: DeepMocked<ContextExternalToolService>;
let copyHelperService: DeepMocked<CopyHelperService>;

beforeAll(async () => {
module = await Test.createTestingModule({
Expand All @@ -57,6 +58,10 @@ describe('recursive board copy visitor', () => {
provide: ContextExternalToolService,
useValue: createMock<ContextExternalToolService>(),
},
{
provide: CopyHelperService,
useValue: createMock<CopyHelperService>(),
},
{
provide: ToolFeatures,
useValue: {
Expand All @@ -68,6 +73,7 @@ describe('recursive board copy visitor', () => {

service = module.get(BoardDoCopyService);
contextExternalToolService = module.get(ContextExternalToolService);
copyHelperService = module.get(CopyHelperService);

await setupEntities();
});
Expand All @@ -92,6 +98,7 @@ describe('recursive board copy visitor', () => {
describe('when copying empty column board', () => {
const setup = () => {
const original = columnBoardFactory.build();
copyHelperService.deriveStatusFromElements.mockReturnValueOnce(CopyStatusEnum.SUCCESS);

return { original, ...setupfileCopyService() };
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CopyHelperService, CopyStatus } from '@modules/copy-helper';
import { ContextExternalToolService } from '@modules/tool/context-external-tool/service';
import { CopyStatus } from '@modules/copy-helper';
import { IToolFeatures, ToolFeatures } from '@modules/tool/tool-config';
import { Inject, Injectable } from '@nestjs/common';
import { AnyBoardDo } from '@shared/domain/domainobject';
import { IToolFeatures, ToolFeatures } from '@modules/tool/tool-config';
import { RecursiveCopyVisitor } from './recursive-copy.visitor';
import { SchoolSpecificFileCopyService } from './school-specific-file-copy.interface';

Expand All @@ -15,14 +15,16 @@ export type BoardDoCopyParams = {
export class BoardDoCopyService {
constructor(
@Inject(ToolFeatures) private readonly toolFeatures: IToolFeatures,
private readonly contextExternalToolService: ContextExternalToolService
private readonly contextExternalToolService: ContextExternalToolService,
private readonly copyHelperService: CopyHelperService
) {}

public async copy(params: BoardDoCopyParams): Promise<CopyStatus> {
const visitor = new RecursiveCopyVisitor(
params.fileCopyService,
this.contextExternalToolService,
this.toolFeatures
this.toolFeatures,
this.copyHelperService
);

const result = await visitor.copy(params.original);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { ContextExternalToolService } from '@modules/tool/context-external-tool/service';
import { IToolFeatures, ToolFeatures } from '@modules/tool/tool-config';
import { Test, TestingModule } from '@nestjs/testing';
import { CollaborativeTextEditorElement, LinkElement } from '@shared/domain/domainobject';
import { Card, CollaborativeTextEditorElement, Column, LinkElement } from '@shared/domain/domainobject';
import {
cardFactory,
collaborativeTextEditorElementFactory,
columnBoardFactory,
columnFactory,
linkElementFactory,
mediaBoardFactory,
mediaExternalToolElementFactory,
mediaLineFactory,
setupEntities,
} from '@shared/testing';
import { CopyFileDto } from '@src/modules/files-storage-client/dto';
import { CopyElementType, CopyStatus, CopyStatusEnum } from '../../../copy-helper';
import { CopyElementType, CopyHelperService, CopyStatus, CopyStatusEnum } from '../../../copy-helper';
import { RecursiveCopyVisitor } from './recursive-copy.visitor';
import { SchoolSpecificFileCopyServiceFactory } from './school-specific-file-copy-service.factory';
import { SchoolSpecificFileCopyService } from './school-specific-file-copy.interface';
Expand All @@ -22,6 +25,7 @@ describe(RecursiveCopyVisitor.name, () => {

let fileCopyServiceFactory: DeepMocked<SchoolSpecificFileCopyServiceFactory>;
let contextExternalToolService: DeepMocked<ContextExternalToolService>;
let copyHelperService: DeepMocked<CopyHelperService>;

let toolFeatures: IToolFeatures;

Expand All @@ -37,6 +41,10 @@ describe(RecursiveCopyVisitor.name, () => {
provide: ContextExternalToolService,
useValue: createMock<ContextExternalToolService>(),
},
{
provide: CopyHelperService,
useValue: createMock<CopyHelperService>(),
},
{
provide: ToolFeatures,
useValue: {
Expand All @@ -48,6 +56,7 @@ describe(RecursiveCopyVisitor.name, () => {

fileCopyServiceFactory = module.get(SchoolSpecificFileCopyServiceFactory);
contextExternalToolService = module.get(ContextExternalToolService);
copyHelperService = module.get(CopyHelperService);
toolFeatures = module.get(ToolFeatures);

await setupEntities();
Expand Down Expand Up @@ -86,7 +95,12 @@ describe(RecursiveCopyVisitor.name, () => {
const { fileCopyServiceMock } = setup();

const linkElement = linkElementFactory.build();
const visitor = new RecursiveCopyVisitor(fileCopyServiceMock, contextExternalToolService, toolFeatures);
const visitor = new RecursiveCopyVisitor(
fileCopyServiceMock,
contextExternalToolService,
toolFeatures,
copyHelperService
);

await visitor.visitLinkElementAsync(linkElement);

Expand All @@ -99,7 +113,12 @@ describe(RecursiveCopyVisitor.name, () => {
const { fileCopyServiceMock, imageUrl } = setup({ withFileCopy: true });

const linkElement = linkElementFactory.build({ imageUrl });
const visitor = new RecursiveCopyVisitor(fileCopyServiceMock, contextExternalToolService, toolFeatures);
const visitor = new RecursiveCopyVisitor(
fileCopyServiceMock,
contextExternalToolService,
toolFeatures,
copyHelperService
);

await visitor.visitLinkElementAsync(linkElement);

Expand All @@ -112,7 +131,12 @@ describe(RecursiveCopyVisitor.name, () => {
const { fileCopyServiceMock, imageUrl, newFileId } = setup({ withFileCopy: true });

const linkElement = linkElementFactory.build({ imageUrl });
const visitor = new RecursiveCopyVisitor(fileCopyServiceMock, contextExternalToolService, toolFeatures);
const visitor = new RecursiveCopyVisitor(
fileCopyServiceMock,
contextExternalToolService,
toolFeatures,
copyHelperService
);

await visitor.visitLinkElementAsync(linkElement);
const copy = visitor.copyMap.get(linkElement.id) as LinkElement;
Expand All @@ -126,7 +150,12 @@ describe(RecursiveCopyVisitor.name, () => {
const { fileCopyServiceMock } = setup({ withFileCopy: true });

const linkElement = linkElementFactory.build({ imageUrl: `https://abc.de/file/unknown-file-id` });
const visitor = new RecursiveCopyVisitor(fileCopyServiceMock, contextExternalToolService, toolFeatures);
const visitor = new RecursiveCopyVisitor(
fileCopyServiceMock,
contextExternalToolService,
toolFeatures,
copyHelperService
);

await visitor.visitLinkElementAsync(linkElement);
const copy = visitor.copyMap.get(linkElement.id) as LinkElement;
Expand All @@ -145,7 +174,8 @@ describe(RecursiveCopyVisitor.name, () => {
const visitor = new RecursiveCopyVisitor(
createMock<SchoolSpecificFileCopyService>(),
contextExternalToolService,
toolFeatures
toolFeatures,
copyHelperService
);

return {
Expand Down Expand Up @@ -184,7 +214,8 @@ describe(RecursiveCopyVisitor.name, () => {
const visitor = new RecursiveCopyVisitor(
createMock<SchoolSpecificFileCopyService>(),
contextExternalToolService,
toolFeatures
toolFeatures,
copyHelperService
);
const nowMock = new Date(2020, 1, 1, 0, 0, 0);

Expand Down Expand Up @@ -228,4 +259,93 @@ describe(RecursiveCopyVisitor.name, () => {
expect(copyMapElement?.updatedAt).toEqual(nowMock);
});
});

describe('visitColumnBoardAsync', () => {
const setup = () => {
const recursiveCopyVisitor = new RecursiveCopyVisitor(
createMock<SchoolSpecificFileCopyService>(),
contextExternalToolService,
toolFeatures,
copyHelperService
);

const collaborativeTextEditorElement = collaborativeTextEditorElementFactory.build();
const card = cardFactory.build({ children: [collaborativeTextEditorElement] });
const boardDo = columnFactory.build({ children: [card] });
const columnBoard = columnBoardFactory.build({ children: [boardDo] });

copyHelperService.deriveStatusFromElements.mockReturnValueOnce(CopyStatusEnum.PARTIAL);

return {
columnBoard,
recursiveCopyVisitor,
collaborativeTextEditorElement,
};
};

it('should set result map', async () => {
const { columnBoard, recursiveCopyVisitor } = setup();

await recursiveCopyVisitor.visitColumnBoardAsync(columnBoard);

const expectedElements = [
{
copyEntity: expect.any(Column),
elements: [
{
copyEntity: expect.any(Card),
elements: [
{
copyEntity: expect.any(CollaborativeTextEditorElement),
status: CopyStatusEnum.PARTIAL,
type: CopyElementType.COLLABORATIVE_TEXT_EDITOR_ELEMENT,
},
],
status: CopyStatusEnum.SUCCESS,
type: CopyElementType.CARD,
},
],
status: CopyStatusEnum.SUCCESS,
type: CopyElementType.COLUMN,
},
];
const expectedEntity = {
id: expect.any(String),
title: columnBoard.title,
context: columnBoard.context,
createdAt: expect.any(Date),
updatedAt: expect.any(Date),
isVisible: false,
layout: columnBoard.layout,
};
const expectedResult = {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
copyEntity: expect.objectContaining(expectedEntity),
type: CopyElementType.COLUMNBOARD,
status: CopyStatusEnum.PARTIAL,
elements: expectedElements,
};

expect(recursiveCopyVisitor.resultMap.get(columnBoard.id)).toEqual(expectedResult);
});

it('should set copyMap', async () => {
const { columnBoard, recursiveCopyVisitor } = setup();

await recursiveCopyVisitor.visitColumnBoardAsync(columnBoard);

const expectedEntity = {
id: expect.any(String),
title: columnBoard.title,
context: columnBoard.context,
createdAt: expect.any(Date),
updatedAt: expect.any(Date),
isVisible: false,
layout: columnBoard.layout,
};

const copyMapElement = recursiveCopyVisitor.copyMap.get(columnBoard.id);
expect(copyMapElement).toEqual(expect.objectContaining(expectedEntity));
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FileRecordParentType } from '@infra/rabbitmq';
import { ObjectId } from '@mikro-orm/mongodb';
import { CopyElementType, CopyStatus, CopyStatusEnum } from '@modules/copy-helper';
import { CopyElementType, CopyHelperService, CopyStatus, CopyStatusEnum } from '@modules/copy-helper';
import { ContextExternalTool } from '@modules/tool/context-external-tool/domain';
import { ContextExternalToolService } from '@modules/tool/context-external-tool/service';
import { IToolFeatures } from '@modules/tool/tool-config';
Expand Down Expand Up @@ -33,7 +33,8 @@ export class RecursiveCopyVisitor implements BoardCompositeVisitorAsync {
constructor(
private readonly fileCopyService: SchoolSpecificFileCopyService,
private readonly contextExternalToolService: ContextExternalToolService,
private readonly toolFeatures: IToolFeatures
private readonly toolFeatures: IToolFeatures,
private readonly copyHelperService: CopyHelperService
) {}

public async copy(original: AnyBoardDo): Promise<CopyStatus> {
Expand Down Expand Up @@ -61,11 +62,14 @@ export class RecursiveCopyVisitor implements BoardCompositeVisitorAsync {
layout: original.layout,
});

const copyStatusOfChildren = this.getCopyStatusesForChildrenOf(original);
const status = this.copyHelperService.deriveStatusFromElements(copyStatusOfChildren);

this.resultMap.set(original.id, {
copyEntity: copy,
type: CopyElementType.COLUMNBOARD,
status: CopyStatusEnum.SUCCESS,
elements: this.getCopyStatusesForChildrenOf(original),
status,
elements: copyStatusOfChildren,
});
this.copyMap.set(original.id, copy);
}
Expand Down

0 comments on commit 58ac8c4

Please sign in to comment.