Skip to content

Commit

Permalink
EW-800: Add export of card title.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkreuzkam-cap committed Apr 10, 2024
1 parent 194d96e commit a930b4a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { ComponentType } from '@shared/domain/entity';
import {
columnBoardFactory,
columnFactory,
cardFactory,
courseFactory,
lessonFactory,
setupEntities,
taskFactory,
} from '@shared/testing';
import { ColumnBoardService } from '@src/modules/board';
import AdmZip from 'adm-zip';
import { Column } from '@shared/domain/domainobject';
import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper';

describe('CommonCartridgeExportService', () => {
Expand Down Expand Up @@ -71,7 +71,9 @@ describe('CommonCartridgeExportService', () => {
});
const [lesson] = lessons;
const taskFromLesson = taskFactory.buildWithId({ course, lesson });
const columnBoard = columnBoardFactory.build({ children: [columnFactory.build()] });
const card = cardFactory.build();
const column = columnFactory.build({ children: [card] });
const columnBoard = columnBoardFactory.build({ children: [column] });

lessonServiceMock.findById.mockResolvedValue(lesson);
courseServiceMock.findById.mockResolvedValue(course);
Expand All @@ -90,7 +92,7 @@ describe('CommonCartridgeExportService', () => {
);
const archive = new AdmZip(buffer);

return { archive, course, lessons, tasks, taskFromLesson, columnBoard };
return { archive, course, lessons, tasks, taskFromLesson, columnBoard, column, card };
};

beforeAll(async () => {
Expand Down Expand Up @@ -183,10 +185,17 @@ describe('CommonCartridgeExportService', () => {
});

it('should add column', async () => {
const { archive, columnBoard } = await setup();
const { archive, column } = await setup();
const manifest = getFileContent(archive, 'imsmanifest.xml');

expect(manifest).toContain(createXmlString('title', (columnBoard.children[0] as Column).title));
expect(manifest).toContain(createXmlString('title', column.title));
});

it('should add card', async () => {
const { archive, card } = await setup();
const manifest = getFileContent(archive, 'imsmanifest.xml');

expect(manifest).toContain(createXmlString('title', card.title));
});
});

Expand Down Expand Up @@ -237,6 +246,20 @@ describe('CommonCartridgeExportService', () => {

expect(manifest).toContain(createXmlString('title', columnBoard.title));
});

it('should add column', async () => {
const { archive, column } = await setup();
const manifest = getFileContent(archive, 'imsmanifest.xml');

expect(manifest).toContain(createXmlString('title', column.title));
});

it('should add card', async () => {
const { archive, card } = await setup();
const manifest = getFileContent(archive, 'imsmanifest.xml');

expect(manifest).toContain(createXmlString('title', card.title));
});
});

describe('When topics array is empty', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { LessonService } from '@modules/lesson';
import { TaskService } from '@modules/task';
import { Injectable } from '@nestjs/common';
import { BoardExternalReferenceType, Column } from '@shared/domain/domainobject';
import { BoardExternalReferenceType, Column, Card } from '@shared/domain/domainobject';
import { ComponentProperties } from '@shared/domain/entity';
import { EntityId } from '@shared/domain/types';
import { ColumnBoardService } from '@src/modules/board';
Expand Down Expand Up @@ -111,16 +111,30 @@ export class CommonCartridgeExportService {

columnBoard.children
.filter((child) => child instanceof Column)
.forEach((column) => {
const { id } = column;
organization.addSubOrganization({
title: (column as Column).title,
identifier: createIdentifier(id),
});
});
.forEach((column) => this.addColumnToOrganization(column as Column, organization));
}
}

private addColumnToOrganization(column: Column, organizationBuilder: CommonCartridgeOrganizationBuilder): void {
const { id } = column;
const columnOrganization = organizationBuilder.addSubOrganization({
title: column.title,
identifier: createIdentifier(id),
});

column.children
.filter((child) => child instanceof Card)
.forEach((card) => this.addCardToOrganization(card as Card, columnOrganization));
}

private addCardToOrganization(card: Card, organizationBuilder: CommonCartridgeOrganizationBuilder): void {
const { id } = card;
organizationBuilder.addSubOrganization({
title: card.title,
identifier: createIdentifier(id),
});
}

private addComponentToOrganization(
organizationBuilder: CommonCartridgeOrganizationBuilder,
component: ComponentProperties
Expand Down

0 comments on commit a930b4a

Please sign in to comment.