From ee3c99d29e083218984627faacaeef2fbd711953 Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Thu, 25 Apr 2024 15:11:14 +0200 Subject: [PATCH 1/2] Copy collaborative text edtior --- .../recursive-copy.visitor.spec.ts | 44 ++++++++++++++++--- .../recursive-copy.visitor.ts | 22 +++++++--- .../modules/copy-helper/types/copy.types.ts | 1 + 3 files changed, 54 insertions(+), 13 deletions(-) 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', From d78505fb03f0fb8e9efbb30981d234a0306f4e65 Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Tue, 30 Apr 2024 10:46:41 +0200 Subject: [PATCH 2/2] Remove allowance for sprintfs licence --- .github/workflows/dependency-review.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 0ab0b8d8645..b8789683080 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -15,6 +15,4 @@ jobs: uses: actions/dependency-review-action@v4 with: allow-licenses: AGPL-3.0-only, LGPL-3.0, MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause, ISC, X11, 0BSD, GPL-3.0, Unlicense, CC0-1.0 - # temporarily ignore dependency error sprintf-js 1.0.3, remove when it gets upgraded to 1.1.3 - allow-dependencies-licenses: 'pkg:npm/sprintf-js@1.0.3' allow-ghsas: 'GHSA-vxvm-qww3-2fh7'