Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N21-2357 Extend copying of boards for board-card-links #5480

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/server/src/modules/board/domain/board-node.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Injectable, NotImplementedException, UnprocessableEntityException } fro
import { EntityId, InputFormat } from '@shared/domain/types';
import { Card } from './card.do';
import { CollaborativeTextEditorElement } from './collaborative-text-editor.do';
import { ColumnBoard } from './colum-board.do';
import { ColumnBoard } from './column-board.do';
import { Column } from './column.do';
import { DrawingElement } from './drawing-element.do';
import { ExternalToolElement } from './external-tool-element.do';
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/board/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export * from './board-node.factory';
export * from './collaborative-text-editor.do';
export * from './card.do';
export * from './column.do';
export * from './colum-board.do';
export * from './column-board.do';
export * from './drawing-element.do';
export * from './external-tool-element.do';
export * from './file-element.do';
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/board/domain/type-mapping.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NotImplementedException } from '@nestjs/common';
import { Card } from './card.do';
import { CollaborativeTextEditorElement } from './collaborative-text-editor.do';
import { ColumnBoard } from './colum-board.do';
import { ColumnBoard } from './column-board.do';
import { Column } from './column.do';
import { DeletedElement } from './deleted-element.do';
import { DrawingElement } from './drawing-element.do';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Card } from '../card.do';
import type { CollaborativeTextEditorElement } from '../collaborative-text-editor.do';
import type { ColumnBoard } from '../colum-board.do';
import type { ColumnBoard } from '../column-board.do';
import type { Column } from '../column.do';
import type { AnyMediaBoardNode } from '../media-board';
import type { SubmissionItem } from '../submission-item.do';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,23 @@ describe(BoardNodeCopyService.name, () => {

const result = await service.copyColumnBoard(columnBoard, copyContext);

expect(result.copyEntity).toBeInstanceOf(ColumnBoard);
expect(result.copy).toBeInstanceOf(ColumnBoard);
});

it('should copy the original node', async () => {
const { copyContext, columnBoard } = setup();

const result = await service.copyColumnBoard(columnBoard, copyContext);

expect(result.original).toBeInstanceOf(ColumnBoard);
});

it('should copy the children', async () => {
const { copyContext, columnBoard } = setup();

const result = await service.copyColumnBoard(columnBoard, copyContext);

expect((result.elements ?? [])[0].copyEntity).toBeInstanceOf(Column);
expect((result.elements ?? [])[0].copy).toBeInstanceOf(Column);
});

it('should use the service to derive status from children', async () => {
Expand All @@ -165,15 +173,23 @@ describe(BoardNodeCopyService.name, () => {

const result = await service.copyColumn(column, copyContext);

expect(result.copyEntity).toBeInstanceOf(Column);
expect(result.copy).toBeInstanceOf(Column);
});

it('should copy the original node', async () => {
const { copyContext, column } = setup();

const result = await service.copyColumn(column, copyContext);

expect(result.original).toBeInstanceOf(Column);
});

it('should copy the children', async () => {
const { copyContext, column } = setup();

const result = await service.copyColumn(column, copyContext);

expect((result.elements ?? [])[0].copyEntity).toBeInstanceOf(Card);
expect((result.elements ?? [])[0].copy).toBeInstanceOf(Card);
});
});

Expand All @@ -190,15 +206,22 @@ describe(BoardNodeCopyService.name, () => {

const result = await service.copyCard(card, copyContext);

expect(result.copyEntity).toBeInstanceOf(Card);
expect(result.copy).toBeInstanceOf(Card);
});

it('should copy the original node', async () => {
const { copyContext, card } = setup();

const result = await service.copyCard(card, copyContext);

expect(result.original).toBeInstanceOf(Card);
});
it('should copy the children', async () => {
const { copyContext, card } = setup();

const result = await service.copyCard(card, copyContext);

expect((result.elements ?? [])[0].copyEntity).toBeInstanceOf(RichTextElement);
expect((result.elements ?? [])[0].copy).toBeInstanceOf(RichTextElement);
});
});

Expand All @@ -221,15 +244,15 @@ describe(BoardNodeCopyService.name, () => {

const result = await service.copyFileElement(fileElement, copyContext);

expect(result.copyEntity).toBeInstanceOf(FileElement);
expect(result.copy).toBeInstanceOf(FileElement);
});

it('should copy the files', async () => {
const { copyContext, fileElement, fileCopyStatus } = setup();

const result = await service.copyFileElement(fileElement, copyContext);

expect(copyContext.copyFilesOfParent).toHaveBeenCalledWith(fileElement.id, result.copyEntity?.id);
expect(copyContext.copyFilesOfParent).toHaveBeenCalledWith(fileElement.id, result.copy?.id);
expect(result.elements ?? []).toEqual([expect.objectContaining({ title: fileCopyStatus.name })]);
});
});
Expand Down Expand Up @@ -261,15 +284,23 @@ describe(BoardNodeCopyService.name, () => {

const result = await service.copyLinkElement(linkElement, copyContext);

expect(result.copyEntity).toBeInstanceOf(LinkElement);
expect(result.copy).toBeInstanceOf(LinkElement);
});

it('should copy the original node', async () => {
const { copyContext, linkElement } = setup();

const result = await service.copyLinkElement(linkElement, copyContext);

expect(result.original).toBeInstanceOf(LinkElement);
});

it('should copy the files', async () => {
const { copyContext, linkElement, fileCopyStatus } = setup();

const result = await service.copyLinkElement(linkElement, copyContext);

expect(copyContext.copyFilesOfParent).toHaveBeenCalledWith(linkElement.id, result.copyEntity?.id);
expect(copyContext.copyFilesOfParent).toHaveBeenCalledWith(linkElement.id, result.copy?.id);
expect(result.elements ?? []).toEqual([expect.objectContaining({ title: fileCopyStatus.name })]);
});

Expand All @@ -280,7 +311,7 @@ describe(BoardNodeCopyService.name, () => {
const result = await service.copyLinkElement(linkElement, copyContext);

// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
expect((result.copyEntity as LinkElement).imageUrl).toBe(`https://example.com/${fileCopyStatus.id}/bird.jpg`);
expect((result.copy as LinkElement).imageUrl).toBe(`https://example.com/${fileCopyStatus.id}/bird.jpg`);
});
});

Expand All @@ -291,7 +322,7 @@ describe(BoardNodeCopyService.name, () => {
const result = await service.copyLinkElement(linkElementWithoutId, copyContext);

// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
expect((result.copyEntity as LinkElement).imageUrl).toBe('');
expect((result.copy as LinkElement).imageUrl).toBe('');
});
});

Expand All @@ -307,7 +338,7 @@ describe(BoardNodeCopyService.name, () => {

const result = await service.copyLinkElement(linkElement, copyContext);

expect((result.copyEntity as LinkElement).imageUrl).toBe('');
expect((result.copy as LinkElement).imageUrl).toBe('');
});
});
});
Expand All @@ -325,7 +356,7 @@ describe(BoardNodeCopyService.name, () => {

const result = await service.copyRichTextElement(richTextElement, copyContext);

expect(result.copyEntity).toBeInstanceOf(RichTextElement);
expect(result.copy).toBeInstanceOf(RichTextElement);
});
});

Expand All @@ -342,7 +373,7 @@ describe(BoardNodeCopyService.name, () => {

const result = await service.copyDrawingElement(drawingElement, copyContext);

expect(result.copyEntity).toBeInstanceOf(DrawingElement);
expect(result.copy).toBeInstanceOf(DrawingElement);
});
});

Expand All @@ -361,7 +392,7 @@ describe(BoardNodeCopyService.name, () => {

const result = await service.copySubmissionContainerElement(submissionContainerElement, copyContext);

expect(result.copyEntity).toBeInstanceOf(SubmissionContainerElement);
expect(result.copy).toBeInstanceOf(SubmissionContainerElement);
});

it('should copy the children', async () => {
Expand Down Expand Up @@ -413,7 +444,7 @@ describe(BoardNodeCopyService.name, () => {

const result = await service.copyExternalToolElement(externalToolElement, copyContext);

expect(result.copyEntity).toBeInstanceOf(ExternalToolElement);
expect(result.copy).toBeInstanceOf(ExternalToolElement);
});

describe('when ctl tools copy is enabled', () => {
Expand Down Expand Up @@ -453,11 +484,11 @@ describe(BoardNodeCopyService.name, () => {

expect(contextExternalToolService.copyContextExternalTool).toHaveBeenCalledWith(
contextTool,
result.copyEntity?.id,
result.copy?.id,
copyContext.targetSchoolId
);
expect(result.copyEntity instanceof ExternalToolElement).toEqual(true);
expect((result.copyEntity as ExternalToolElement).contextExternalToolId).toEqual(copiedTool.id);
expect(result.copy instanceof ExternalToolElement).toEqual(true);
expect((result.copy as ExternalToolElement).contextExternalToolId).toEqual(copiedTool.id);
expect(result.type).toEqual(CopyElementType.EXTERNAL_TOOL_ELEMENT);
expect(result.status).toEqual(CopyStatusEnum.SUCCESS);
});
Expand Down Expand Up @@ -487,7 +518,7 @@ describe(BoardNodeCopyService.name, () => {
expect.any(String),
copyContext.targetSchoolId
);
expect(result.copyEntity instanceof DeletedElement).toEqual(true);
expect(result.copy instanceof DeletedElement).toEqual(true);
expect(result.type).toEqual(CopyElementType.EXTERNAL_TOOL_ELEMENT);
expect(result.status).toEqual(CopyStatusEnum.FAIL);
});
Expand Down Expand Up @@ -563,7 +594,7 @@ describe(BoardNodeCopyService.name, () => {

const result = await service.copyCollaborativeTextEditorElement(collaborativeTextEditor, copyContext);

expect(result.copyEntity).toBeInstanceOf(CollaborativeTextEditorElement);
expect(result.copy).toBeInstanceOf(CollaborativeTextEditorElement);
});

it('should return the correct type and status', async () => {
Expand Down Expand Up @@ -678,7 +709,7 @@ describe(BoardNodeCopyService.name, () => {

const result = await service.copyDeletedElement(deletedElement, copyContext);

expect(result.copyEntity).toBeInstanceOf(DeletedElement);
expect(result.copy).toBeInstanceOf(DeletedElement);
});
});

Expand Down
Loading
Loading