Skip to content

Commit

Permalink
BC-6807 - Copy collaborative text editor (#4961)
Browse files Browse the repository at this point in the history
  • Loading branch information
bischofmax authored Apr 30, 2024
1 parent 79cb70e commit af914d5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -53,6 +53,10 @@ describe(RecursiveCopyVisitor.name, () => {
await setupEntities();
});

afterEach(() => {
jest.resetAllMocks();
});

describe('visitLinkElementAsync', () => {
const setup = (options: { withFileCopy: boolean } = { withFileCopy: false }) => {
const fileCopyServiceMock = createMock<SchoolSpecificFileCopyService>();
Expand Down Expand Up @@ -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<CopyStatus>({
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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,22 @@ export class RecursiveCopyVisitor implements BoardCompositeVisitorAsync {
return Promise.resolve();
}

async visitCollaborativeTextEditorElementAsync(
collaborativeTextEditorElement: CollaborativeTextEditorElement
): Promise<void> {
return Promise.reject(
new Error(`Cannot copy element of type: '${collaborativeTextEditorElement.constructor.name}'`)
);
async visitCollaborativeTextEditorElementAsync(original: CollaborativeTextEditorElement): Promise<void> {
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<void> {
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/copy-helper/types/copy.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit af914d5

Please sign in to comment.