Skip to content

Commit

Permalink
BC-4293 - Topic does not copy with empty content Learning material (#…
Browse files Browse the repository at this point in the history
…4485)

* copy lernstore content without set resource
  • Loading branch information
MartinSchuhmacher authored Oct 20, 2023
1 parent 4e8cfa0 commit 7b42e1e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 19 deletions.
49 changes: 49 additions & 0 deletions apps/server/src/modules/lesson/service/lesson-copy.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,55 @@ describe('lesson copy service', () => {
});
});

describe('when lesson contains LernStore content element without set resource', () => {
const setup = () => {
const lernStoreContent: IComponentProperties = {
title: 'text component 1',
hidden: false,
component: ComponentType.LERNSTORE,
};
const user = userFactory.build();
const originalCourse = courseFactory.build({ school: user.school });
const destinationCourse = courseFactory.build({ school: user.school, teachers: [user] });
const originalLesson = lessonFactory.build({
course: originalCourse,
contents: [lernStoreContent],
});
lessonRepo.findById.mockResolvedValueOnce(originalLesson);

return { user, originalCourse, destinationCourse, originalLesson, lernStoreContent };
};

it('the content should be fully copied', async () => {
const { user, destinationCourse, originalLesson, lernStoreContent } = setup();

const status = await copyService.copyLesson({
originalLessonId: originalLesson.id,
destinationCourse,
user,
});

const copiedLessonContents = (status.copyEntity as LessonEntity).contents as IComponentProperties[];
expect(copiedLessonContents[0]).toEqual(lernStoreContent);
});

it('should set content type to LESSON_CONTENT_LERNSTORE', async () => {
const { user, destinationCourse, originalLesson } = setup();

const status = await copyService.copyLesson({
originalLessonId: originalLesson.id,
destinationCourse,
user,
});
const contentsStatus = status.elements?.find((el) => el.type === CopyElementType.LESSON_CONTENT_GROUP);
expect(contentsStatus).toBeDefined();
if (contentsStatus?.elements) {
expect(contentsStatus.elements[0].type).toEqual(CopyElementType.LESSON_CONTENT_LERNSTORE);
expect(contentsStatus.elements[0].status).toEqual(CopyStatusEnum.SUCCESS);
}
});
});

describe('when lesson contains geoGebra content element', () => {
const setup = () => {
const geoGebraContent: IComponentProperties = {
Expand Down
39 changes: 21 additions & 18 deletions apps/server/src/modules/lesson/service/lesson-copy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,29 +266,32 @@ export class LessonCopyService {
}

private copyLernStore(element: IComponentProperties): IComponentProperties {
const resources = ((element.content as IComponentLernstoreProperties).resources ?? []).map(
({ client, description, merlinReference, title, url }) => {
const result = {
client,
description,
merlinReference,
title,
url,
};
return result;
}
);

const lernstore = {
const lernstore: IComponentProperties = {
title: element.title,
hidden: element.hidden,
component: ComponentType.LERNSTORE,
user: element.user, // TODO should be params.user - but that made the server crash, but property is normally undefined
content: {
resources,
},
};
return lernstore as IComponentProperties;

if (element.content) {
const resources = ((element.content as IComponentLernstoreProperties).resources ?? []).map(
({ client, description, merlinReference, title, url }) => {
const result = {
client,
description,
merlinReference,
title,
url,
};
return result;
}
);

const lernstoreContent: IComponentLernstoreProperties = { resources };
lernstore.content = lernstoreContent;
}

return lernstore;
}

private static copyGeogebra(originalElement: IComponentProperties): IComponentProperties {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/shared/domain/entity/lesson.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export type IComponentProperties = {
| { component: ComponentType.ETHERPAD; content: IComponentEtherpadProperties }
| { component: ComponentType.GEOGEBRA; content: IComponentGeogebraProperties }
| { component: ComponentType.INTERNAL; content: IComponentInternalProperties }
| { component: ComponentType.LERNSTORE; content: IComponentLernstoreProperties }
| { component: ComponentType.LERNSTORE; content?: IComponentLernstoreProperties }
| { component: ComponentType.NEXBOARD; content: IComponentNexboardProperties }
);

Expand Down

0 comments on commit 7b42e1e

Please sign in to comment.