diff --git a/apps/server/src/modules/board/service/board-do-copy-service/recursive-copy.visitor.spec.ts b/apps/server/src/modules/board/service/board-do-copy-service/recursive-copy.visitor.spec.ts index acbac09848e..c4cfb838913 100644 --- a/apps/server/src/modules/board/service/board-do-copy-service/recursive-copy.visitor.spec.ts +++ b/apps/server/src/modules/board/service/board-do-copy-service/recursive-copy.visitor.spec.ts @@ -2,7 +2,7 @@ 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 { LinkElement } from '@shared/domain/domainobject'; +import { CollaborativeTextEditorElement, LinkElement } from '@shared/domain/domainobject'; import { collaborativeTextEditorElementFactory, linkElementFactory, @@ -53,6 +53,10 @@ describe(RecursiveCopyVisitor.name, () => { await setupEntities(); }); + afterEach(() => { + jest.resetAllMocks(); + }); + describe('visitLinkElementAsync', () => { const setup = (options: { withFileCopy: boolean } = { withFileCopy: false }) => { const fileCopyServiceMock = createMock(); @@ -182,20 +186,46 @@ describe(RecursiveCopyVisitor.name, () => { contextExternalToolService, toolFeatures ); + const nowMock = new Date(2020, 1, 1, 0, 0, 0); + + jest.useFakeTimers(); + jest.setSystemTime(nowMock); return { collaborativeTextEditorElement, visitor, + nowMock, }; }; - it('should throw an error', async () => { - const { visitor, collaborativeTextEditorElement } = setup(); - const error = new Error(`Cannot copy element of type: '${collaborativeTextEditorElement.constructor.name}'`); + it('should add status to the resultMap', async () => { + const { visitor, collaborativeTextEditorElement, nowMock } = setup(); + + await visitor.visitCollaborativeTextEditorElementAsync(collaborativeTextEditorElement); + + const status = visitor.resultMap.get(collaborativeTextEditorElement.id); + const expectedCopyEntity = expect.objectContaining({ + id: expect.any(String), + createdAt: nowMock, + updatedAt: nowMock, + }) as CollaborativeTextEditorElement; + + expect(status).toEqual({ + copyEntity: expectedCopyEntity, + type: CopyElementType.COLLABORATIVE_TEXT_EDITOR_ELEMENT, + status: CopyStatusEnum.SUCCESS, + }); + }); + + it('should add the element to the copyMap', async () => { + const { visitor, collaborativeTextEditorElement, nowMock } = setup(); + + await visitor.visitCollaborativeTextEditorElementAsync(collaborativeTextEditorElement); - await expect(() => - visitor.visitCollaborativeTextEditorElementAsync(collaborativeTextEditorElement) - ).rejects.toThrow(error); + const copyMapElement = visitor.copyMap.get(collaborativeTextEditorElement.id); + expect(copyMapElement?.id).toBeDefined(); + expect(copyMapElement?.createdAt).toEqual(nowMock); + expect(copyMapElement?.updatedAt).toEqual(nowMock); }); }); }); diff --git a/apps/server/src/modules/board/service/board-do-copy-service/recursive-copy.visitor.ts b/apps/server/src/modules/board/service/board-do-copy-service/recursive-copy.visitor.ts index 95cd09ce1e2..f8c00f4fdbd 100644 --- a/apps/server/src/modules/board/service/board-do-copy-service/recursive-copy.visitor.ts +++ b/apps/server/src/modules/board/service/board-do-copy-service/recursive-copy.visitor.ts @@ -287,12 +287,22 @@ export class RecursiveCopyVisitor implements BoardCompositeVisitorAsync { return Promise.resolve(); } - async visitCollaborativeTextEditorElementAsync( - collaborativeTextEditorElement: CollaborativeTextEditorElement - ): Promise { - return Promise.reject( - new Error(`Cannot copy element of type: '${collaborativeTextEditorElement.constructor.name}'`) - ); + async visitCollaborativeTextEditorElementAsync(original: CollaborativeTextEditorElement): Promise { + const now = new Date(); + const copy = new CollaborativeTextEditorElement({ + id: new ObjectId().toHexString(), + createdAt: now, + updatedAt: now, + }); + + this.resultMap.set(original.id, { + copyEntity: copy, + type: CopyElementType.COLLABORATIVE_TEXT_EDITOR_ELEMENT, + status: CopyStatusEnum.SUCCESS, + }); + this.copyMap.set(original.id, copy); + + return Promise.resolve(); } async visitMediaBoardAsync(original: MediaBoard): Promise { diff --git a/apps/server/src/modules/copy-helper/types/copy.types.ts b/apps/server/src/modules/copy-helper/types/copy.types.ts index c2c80f61fdb..27416d40303 100644 --- a/apps/server/src/modules/copy-helper/types/copy.types.ts +++ b/apps/server/src/modules/copy-helper/types/copy.types.ts @@ -14,6 +14,7 @@ export type CopyStatus = { export enum CopyElementType { BOARD = 'BOARD', CARD = 'CARD', + COLLABORATIVE_TEXT_EDITOR_ELEMENT = 'COLLABORATIVE_TEXT_EDITOR_ELEMENT', COLUMN = 'COLUMN', COLUMNBOARD = 'COLUMNBOARD', CONTENT = 'CONTENT',