From ed2d219fd2fbe9dc97e5a442dd3d9cec5f8f80f9 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 27 Oct 2023 17:02:32 +0200 Subject: [PATCH 001/177] EW-539 Add ComponentType Lernstore to cc-export-service --- .../common-cartridge-export.service.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index e25d2a62367..6472fd8f76f 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -1,8 +1,8 @@ +import { LessonService } from '@modules/lesson/service'; +import { TaskService } from '@modules/task/service'; import { Injectable } from '@nestjs/common'; import { Course, EntityId, IComponentProperties, Task } from '@shared/domain'; -import { LessonService } from '@modules/lesson/service'; import { ComponentType } from '@src/shared/domain/entity/lesson.entity'; -import { TaskService } from '@modules/task/service'; import { CommonCartridgeFileBuilder, CommonCartridgeIntendedUseType, @@ -11,8 +11,8 @@ import { ICommonCartridgeResourceProps, ICommonCartridgeWebContentResourceProps, } from '../common-cartridge'; -import { CourseService } from './course.service'; import { createIdentifier } from '../common-cartridge/utils'; +import { CourseService } from './course.service'; @Injectable() export class CommonCartridgeExportService { @@ -129,6 +129,21 @@ export class CommonCartridgeExportService { }; } + if (content.component === ComponentType.LERNSTORE) { + if (content.content && Array.isArray(content.content.resources) && content.content.resources.length > 0) { + content.content.resources.map((resource) => { + return { + ...commonProps, + type: + version === CommonCartridgeVersion.V_1_3_0 + ? CommonCartridgeResourceType.WEB_LINK_V3 + : CommonCartridgeResourceType.WEB_LINK_V1, + url: resource.url, + }; + }); + } + } + return undefined; } From c5df7d1d64df8134a894ab29b604ea460d8c9a36 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 27 Oct 2023 19:55:40 +0200 Subject: [PATCH 002/177] EW-539 Adjust if statement --- .../service/common-cartridge-export.service.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 6472fd8f76f..83fd91edfc6 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -132,14 +132,10 @@ export class CommonCartridgeExportService { if (content.component === ComponentType.LERNSTORE) { if (content.content && Array.isArray(content.content.resources) && content.content.resources.length > 0) { content.content.resources.map((resource) => { - return { - ...commonProps, - type: - version === CommonCartridgeVersion.V_1_3_0 - ? CommonCartridgeResourceType.WEB_LINK_V3 - : CommonCartridgeResourceType.WEB_LINK_V1, - url: resource.url, - }; + const url = resource.url; + return version === CommonCartridgeVersion.V_1_3_0 + ? { ...commonProps, type: CommonCartridgeResourceType.WEB_LINK_V3, url } + : { ...commonProps, type: CommonCartridgeResourceType.WEB_LINK_V1, url }; }); } } From 548ec7c0d630a9c25c04f0bcb2268245f22f8740 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 2 Nov 2023 16:27:05 +0100 Subject: [PATCH 003/177] EW-539 extending organization item element of CC --- ...mon-cartridge-organization-item-element.ts | 3 +- .../common-cartridge-export.service.spec.ts | 109 ++++++++++++++---- .../common-cartridge-export.service.ts | 40 +++---- 3 files changed, 106 insertions(+), 46 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts index e77fcbc0905..6db8b90fd26 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts @@ -6,8 +6,7 @@ export type ICommonCartridgeOrganizationProps = { identifier: string; title: string; version: string; - resources: ICommonCartridgeResourceProps[]; -}; +} & ({ children: ICommonCartridgeOrganizationProps[] } | { resources: ICommonCartridgeResourceProps[] }); export class CommonCartridgeOrganizationItemElement implements ICommonCartridgeElement { constructor(private readonly props: ICommonCartridgeOrganizationProps) {} diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index af1bc727d6a..9a0d526b991 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -1,19 +1,21 @@ +import { faker } from '@faker-js/faker'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; +import { CourseService } from '@modules/learnroom/service'; +import { CommonCartridgeExportService } from '@modules/learnroom/service/common-cartridge-export.service'; +import { LessonService } from '@modules/lesson/service'; +import { TaskService } from '@modules/task/service/task.service'; import { Test, TestingModule } from '@nestjs/testing'; import { ComponentType, Course, + IComponentLernstoreProperties, IComponentProperties, - IComponentTextProperties, LessonEntity, Task, } from '@shared/domain'; import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing'; -import { CommonCartridgeExportService } from '@modules/learnroom/service/common-cartridge-export.service'; -import { CourseService } from '@modules/learnroom/service'; -import { LessonService } from '@modules/lesson/service'; -import { TaskService } from '@modules/task/service/task.service'; import AdmZip from 'adm-zip'; +import { writeFile } from 'fs/promises'; import { CommonCartridgeVersion } from '../common-cartridge'; describe('CommonCartridgeExportService', () => { @@ -51,33 +53,63 @@ describe('CommonCartridgeExportService', () => { lessonServiceMock = module.get(LessonService); taskServiceMock = module.get(TaskService); course = courseFactory.teachersWithId(2).buildWithId(); - lessons = lessonFactory.buildListWithId(5, { + lessons = lessonFactory.buildListWithId(1, { contents: [ { + _id: faker.string.uuid(), + hidden: false, component: ComponentType.TEXT, title: 'Text', content: { text: 'text', }, - } as IComponentProperties, + }, { + _id: faker.string.uuid(), + hidden: false, component: ComponentType.ETHERPAD, title: 'Etherpad', content: { - url: 'url', + title: faker.lorem.words(2), + description: faker.lorem.sentence(), + url: 'https://google.com', }, - } as IComponentProperties, + }, { + _id: faker.string.uuid(), + hidden: false, component: ComponentType.GEOGEBRA, title: 'Geogebra', content: { - materialId: 'materialId', + materialId: 'https://google.com', }, - } as IComponentProperties, - {} as IComponentProperties, + }, + { + _id: faker.string.uuid(), + hidden: false, + // AI next 18 lines + component: ComponentType.LERNSTORE, + title: 'Lernstore', + content: { + resources: [ + { + client: faker.company.name(), + title: faker.lorem.words(2), + description: faker.lorem.sentence(), + url: faker.internet.url(), + }, + { + client: faker.company.name(), + title: faker.lorem.words(2), + description: faker.lorem.sentence(), + url: faker.internet.url(), + }, + ], + }, + }, ], }); - tasks = taskFactory.buildListWithId(5); + tasks = taskFactory.buildListWithId(2); }); afterAll(async () => { @@ -87,20 +119,14 @@ describe('CommonCartridgeExportService', () => { describe('exportCourse', () => { const setupExport = async (version: CommonCartridgeVersion) => { const [lesson] = lessons; - const textContent = { text: 'Some random text' } as IComponentTextProperties; - const lessonContent: IComponentProperties = { - _id: 'random_id', - title: 'A random title', - hidden: false, - component: ComponentType.TEXT, - content: textContent, - }; - lesson.contents = [lessonContent]; + lessonServiceMock.findById.mockResolvedValueOnce(lesson); courseServiceMock.findById.mockResolvedValueOnce(course); lessonServiceMock.findByCourseIds.mockResolvedValueOnce([lessons, lessons.length]); taskServiceMock.findBySingleParent.mockResolvedValueOnce([tasks, tasks.length]); + const archive = new AdmZip(await courseExportService.exportCourse(course.id, '', version)); + return archive; }; @@ -203,5 +229,44 @@ describe('CommonCartridgeExportService', () => { expect(manifest).toContain(CommonCartridgeVersion.V_1_3_0); }); }); + + describe('when exporting learn store content from course with Common Cartridge 1.3', () => { + let archive: AdmZip; + let lernstoreProps: IComponentProperties; + + beforeAll(async () => { + const [lesson] = lessons; + + archive = await setupExport(CommonCartridgeVersion.V_1_3_0); + lernstoreProps = lesson.contents.filter((content) => content.component === ComponentType.LERNSTORE)[0]; + + await writeFile('test.zip', archive.toBuffer(), 'binary'); + }); + + it('should add learn store content to manifest file', () => { + // AI next 3 lines + const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); + + expect(manifest).toContain(lernstoreProps.title); + }); + + it.skip('should create directory for each learn store content', () => { + // AI next 3 lines + const directory = archive.getEntry(`i${lernstoreProps._id as string}/`); + + expect(directory).toBeDefined(); + }); + + it.skip('should add learn store content as web links to directory', () => { + expect(lernstoreProps.content).toBeDefined(); + expect((lernstoreProps.content as IComponentLernstoreProperties).resources).toHaveLength(2); + + (lernstoreProps.content as IComponentLernstoreProperties).resources.forEach((resource) => { + const file = archive.getEntry(`i${lernstoreProps._id as string}/${resource.title}.html`); + + expect(file).toBeDefined(); + }); + }); + }); }); }); diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 83fd91edfc6..fb471eac10d 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -87,19 +87,18 @@ export class CommonCartridgeExportService { content: IComponentProperties, version: CommonCartridgeVersion ): ICommonCartridgeResourceProps | undefined { - const commonProps = { - version, - identifier: createIdentifier(content._id), - href: `${createIdentifier(lessonId)}/${createIdentifier(content._id)}.html`, - title: content.title, - }; - - if (content.component === ComponentType.TEXT) { + const commonProps = (fileExt: 'html' | 'xml') => { return { version, identifier: createIdentifier(content._id), - href: `${createIdentifier(lessonId)}/${createIdentifier(content._id)}.html`, + href: `${createIdentifier(lessonId)}/${createIdentifier(content._id)}.${fileExt}`, title: content.title, + }; + }; + + if (content.component === ComponentType.TEXT) { + return { + ...commonProps('html'), type: CommonCartridgeResourceType.WEB_CONTENT, intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, html: `

${content.title}

${content.content.text}

`, @@ -109,35 +108,32 @@ export class CommonCartridgeExportService { if (content.component === ComponentType.GEOGEBRA) { const url = `https://www.geogebra.org/m/${content.content.materialId}`; return version === CommonCartridgeVersion.V_1_3_0 - ? { ...commonProps, type: CommonCartridgeResourceType.WEB_LINK_V3, url } - : { ...commonProps, type: CommonCartridgeResourceType.WEB_LINK_V1, url }; + ? { ...commonProps('xml'), type: CommonCartridgeResourceType.WEB_LINK_V3, url } + : { ...commonProps('xml'), type: CommonCartridgeResourceType.WEB_LINK_V1, url }; } if (content.component === ComponentType.ETHERPAD) { return version === CommonCartridgeVersion.V_1_3_0 ? { - ...commonProps, + ...commonProps('xml'), type: CommonCartridgeResourceType.WEB_LINK_V3, url: content.content.url, title: content.content.description, } : { - ...commonProps, + ...commonProps('xml'), type: CommonCartridgeResourceType.WEB_LINK_V1, url: content.content.url, title: content.content.description, }; } - if (content.component === ComponentType.LERNSTORE) { - if (content.content && Array.isArray(content.content.resources) && content.content.resources.length > 0) { - content.content.resources.map((resource) => { - const url = resource.url; - return version === CommonCartridgeVersion.V_1_3_0 - ? { ...commonProps, type: CommonCartridgeResourceType.WEB_LINK_V3, url } - : { ...commonProps, type: CommonCartridgeResourceType.WEB_LINK_V1, url }; - }); - } + if (content.component === ComponentType.LERNSTORE && content.content) { + const { resources } = content.content; + + return version === CommonCartridgeVersion.V_1_3_0 + ? { type: CommonCartridgeResourceType.WEB_LINK_V3, url: resources[0].url, ...commonProps('xml') } + : { type: CommonCartridgeResourceType.WEB_LINK_V1, url: resources[0].url, ...commonProps('xml') }; } return undefined; From 4192540cbcef84768fc8336f942dd9b810c1f701 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 9 Nov 2023 16:24:49 +0100 Subject: [PATCH 004/177] EW-539 Add new types to realize nesting Co-authored-by: Patrick Sachmann --- ...mon-cartridge-organization-item-element.ts | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts index 6db8b90fd26..53b1cf19ff9 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts @@ -8,10 +8,46 @@ export type ICommonCartridgeOrganizationProps = { version: string; } & ({ children: ICommonCartridgeOrganizationProps[] } | { resources: ICommonCartridgeResourceProps[] }); +type OrganizationItemCollection = { + title: string; + children: OrganizationItemCollection[] | OrganizationResourceCollection; + _tag: 'itemCollection'; +}; + +type OrganizationResourceCollection = { + identifier: string; + title: string; + version: string; + resources: ICommonCartridgeResourceProps[]; + _tag: 'resourceCollection'; +}; + +export type CommonCartridgeOrganizationItemElementProps = OrganizationItemCollection | OrganizationResourceCollection; + +function isOrganizationItemCollection( + item: CommonCartridgeOrganizationItemElementProps +): item is OrganizationItemCollection { + return item._tag === 'itemCollection'; +} + +function isOrganizationResourceCollection( + item: CommonCartridgeOrganizationItemElementProps +): item is OrganizationResourceCollection { + return item._tag === 'resourceCollection'; +} + export class CommonCartridgeOrganizationItemElement implements ICommonCartridgeElement { - constructor(private readonly props: ICommonCartridgeOrganizationProps) {} + constructor(private readonly props: CommonCartridgeOrganizationItemElementProps) {} transform(): Record { + if (isOrganizationItemCollection(this.props)) { + return {}; + } + + if (isOrganizationResourceCollection(this.props)) { + return {}; + } + return { $: { identifier: this.props.identifier, From 66e18543c0e05c27b21c1e2ff3319e25f3ccd9a1 Mon Sep 17 00:00:00 2001 From: Maximilian Kreuzkam Date: Wed, 22 Nov 2023 15:58:23 +0100 Subject: [PATCH 005/177] Implement transform() for CommonCartridgeOrganizationItemElement. --- ...mon-cartridge-organization-item-element.ts | 58 +++++++++++++------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts index 53b1cf19ff9..32ecdff7f1a 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts @@ -36,32 +36,54 @@ function isOrganizationResourceCollection( return item._tag === 'resourceCollection'; } +function isOrganizationItemCollectionArray( + children: OrganizationItemCollection[] | OrganizationResourceCollection +): children is OrganizationItemCollection[] { + return Array.isArray(children); +} + +function createRecordForResourceCollection( + resourceCollection: OrganizationResourceCollection +): Record { + return { + $: { + identifier: resourceCollection.identifier, + }, + title: resourceCollection.title, + item: resourceCollection.resources.map((content) => { + return { + $: { + identifier: createIdentifier(), + identifierref: content.identifier, + }, + title: content.title, + }; + }), + }; +} + export class CommonCartridgeOrganizationItemElement implements ICommonCartridgeElement { constructor(private readonly props: CommonCartridgeOrganizationItemElementProps) {} transform(): Record { - if (isOrganizationItemCollection(this.props)) { - return {}; + if (isOrganizationItemCollection(this.props) && isOrganizationItemCollectionArray(this.props.children)) { + return { + $: { + identifier: createIdentifier(), + }, + title: this.props.title, + item: this.props.children.map((child) => new CommonCartridgeOrganizationItemElement(child).transform()), // TODO rekursiv weiter? + }; + } + + if (isOrganizationItemCollection(this.props) && !isOrganizationItemCollectionArray(this.props.children)) { + return createRecordForResourceCollection(this.props.children); } if (isOrganizationResourceCollection(this.props)) { - return {}; + return createRecordForResourceCollection(this.props); } - return { - $: { - identifier: this.props.identifier, - }, - title: this.props.title, - item: this.props.resources.map((content) => { - return { - $: { - identifier: createIdentifier(), - identifierref: content.identifier, - }, - title: content.title, - }; - }), - }; + return {}; } } From 9c64a59d4ea69c491dc35c165c89e60a511ad272 Mon Sep 17 00:00:00 2001 From: Maximilian Kreuzkam Date: Thu, 23 Nov 2023 16:51:05 +0100 Subject: [PATCH 006/177] implemented nested CC export. --- .../common-cartridge-file-builder.spec.ts | 5 ++- .../common-cartridge-file-builder.ts | 40 ++++++++++++++----- ...artridge-organization-item-element.spec.ts | 5 ++- ...mon-cartridge-organization-item-element.ts | 12 ++---- .../common-cartridge-export.service.ts | 26 +++++++++--- 5 files changed, 61 insertions(+), 27 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.spec.ts index 7b5709f8a9e..e7bfc20f79d 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.spec.ts @@ -2,7 +2,7 @@ import AdmZip from 'adm-zip'; import { parseStringPromise } from 'xml2js'; import { CommonCartridgeResourceType, CommonCartridgeVersion } from './common-cartridge-enums'; import { CommonCartridgeFileBuilder, CommonCartridgeFileBuilderOptions } from './common-cartridge-file-builder'; -import { ICommonCartridgeOrganizationProps } from './common-cartridge-organization-item-element'; +import { CommonCartridgeOrganizationItemElementProps } from './common-cartridge-organization-item-element'; import { ICommonCartridgeResourceProps } from './common-cartridge-resource-item-element'; describe('CommonCartridgeFileBuilder', () => { @@ -16,11 +16,12 @@ describe('CommonCartridgeFileBuilder', () => { title: 'file-title', version: CommonCartridgeVersion.V_1_1_0, }; - const organizationProps: ICommonCartridgeOrganizationProps = { + const organizationProps: CommonCartridgeOrganizationItemElementProps = { version: CommonCartridgeVersion.V_1_1_0, identifier: 'organization-identifier', title: 'organization-title', resources: [], + _tag: 'resourceCollection', }; const ltiResourceProps: ICommonCartridgeResourceProps = { version: CommonCartridgeVersion.V_1_1_0, diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.ts index 5a40269c57b..7c9e5245881 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.ts @@ -5,7 +5,8 @@ import { CommonCartridgeVersion } from './common-cartridge-enums'; import { CommonCartridgeManifestElement } from './common-cartridge-manifest-element'; import { CommonCartridgeOrganizationItemElement, - ICommonCartridgeOrganizationProps, + CommonCartridgeOrganizationItemElementProps, + OrganizationItemCollection, } from './common-cartridge-organization-item-element'; import { CommonCartridgeResourceItemElement, @@ -22,10 +23,11 @@ export type CommonCartridgeFileBuilderOptions = { export interface ICommonCartridgeOrganizationBuilder { addResourceToOrganization(props: ICommonCartridgeResourceProps): ICommonCartridgeOrganizationBuilder; + addSubOrganization(props: CommonCartridgeOrganizationItemElementProps): ICommonCartridgeOrganizationBuilder; } export interface ICommonCartridgeFileBuilder { - addOrganization(props: ICommonCartridgeOrganizationProps): ICommonCartridgeOrganizationBuilder; + addOrganization(props: CommonCartridgeOrganizationItemElementProps): ICommonCartridgeOrganizationBuilder; addResourceToFile(props: ICommonCartridgeResourceProps): ICommonCartridgeFileBuilder; @@ -34,29 +36,49 @@ export interface ICommonCartridgeFileBuilder { class CommonCartridgeOrganizationBuilder implements ICommonCartridgeOrganizationBuilder { constructor( - private readonly props: ICommonCartridgeOrganizationProps, + private readonly props: CommonCartridgeOrganizationItemElementProps, private readonly xmlBuilder: Builder, private readonly zipBuilder: AdmZip ) {} + private resourceProperties: ICommonCartridgeResourceProps[] = []; + + private children: CommonCartridgeOrganizationBuilder[] = []; + get organization(): CommonCartridgeElement { - return new CommonCartridgeOrganizationItemElement(this.props); + return new CommonCartridgeOrganizationItemElement(this.orgProps); + } + + get orgProps(): OrganizationItemCollection { + // TODO resources + return { + _tag: 'itemCollection', + title: this.props.title, + children: this.children.map((child) => child.orgProps), + }; } get resources(): CommonCartridgeElement[] { - return this.props.resources.map( - (resourceProps) => new CommonCartridgeResourceItemElement(resourceProps, this.xmlBuilder) - ); + return this.children + .flatMap((child) => child.resourceProperties) + .concat(this.resourceProperties) + .map((resourceProps) => new CommonCartridgeResourceItemElement(resourceProps, this.xmlBuilder)); } addResourceToOrganization(props: ICommonCartridgeResourceProps): ICommonCartridgeOrganizationBuilder { const newResource = new CommonCartridgeResourceItemElement(props, this.xmlBuilder); - this.props.resources.push(props); + this.resourceProperties.push(props); if (!newResource.canInline()) { this.zipBuilder.addFile(props.href, Buffer.from(newResource.content())); } return this; } + + addSubOrganization(props: CommonCartridgeOrganizationItemElementProps): ICommonCartridgeOrganizationBuilder { + const subOrgBuilder = new CommonCartridgeOrganizationBuilder(props, this.xmlBuilder, this.zipBuilder); + this.children.push(subOrgBuilder); + return subOrgBuilder; + } } export class CommonCartridgeFileBuilder implements ICommonCartridgeFileBuilder { @@ -70,7 +92,7 @@ export class CommonCartridgeFileBuilder implements ICommonCartridgeFileBuilder { constructor(private readonly options: CommonCartridgeFileBuilderOptions) {} - addOrganization(props: ICommonCartridgeOrganizationProps): ICommonCartridgeOrganizationBuilder { + addOrganization(props: CommonCartridgeOrganizationItemElementProps): ICommonCartridgeOrganizationBuilder { const organizationBuilder = new CommonCartridgeOrganizationBuilder(props, this.xmlBuilder, this.zipBuilder); this.organizations.push(organizationBuilder); return organizationBuilder; diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.spec.ts index 525d301d939..93d6329778b 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.spec.ts @@ -1,5 +1,5 @@ import { - ICommonCartridgeOrganizationProps, + CommonCartridgeOrganizationItemElementProps, CommonCartridgeOrganizationItemElement, } from './common-cartridge-organization-item-element'; import { CommonCartridgeVersion, CommonCartridgeResourceType } from './common-cartridge-enums'; @@ -16,11 +16,12 @@ describe('CommonCartridgeOrganizationItemElement', () => { title: 'Web Link', html: 'html tags for testing', }; - const props: ICommonCartridgeOrganizationProps = { + const props: CommonCartridgeOrganizationItemElementProps = { identifier: 'identifier', title: 'title of organization item element', version: 'version of common cartridge', resources: [webContentResourceProps], + _tag: 'resourceCollection', }; const organizationItemElement = new CommonCartridgeOrganizationItemElement(props); const transformed = organizationItemElement.transform(); diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts index ffd1e7410b4..ec0fc285546 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts @@ -2,19 +2,13 @@ import { CommonCartridgeElement } from './common-cartridge-element.interface'; import { ICommonCartridgeResourceProps } from './common-cartridge-resource-item-element'; import { createIdentifier } from './utils'; -export type ICommonCartridgeOrganizationProps = { - identifier: string; - title: string; - version: string; -} & ({ children: ICommonCartridgeOrganizationProps[] } | { resources: ICommonCartridgeResourceProps[] }); - -type OrganizationItemCollection = { +export type OrganizationItemCollection = { title: string; children: OrganizationItemCollection[] | OrganizationResourceCollection; _tag: 'itemCollection'; }; -type OrganizationResourceCollection = { +export type OrganizationResourceCollection = { identifier: string; title: string; version: string; @@ -72,7 +66,7 @@ export class CommonCartridgeOrganizationItemElement implements CommonCartridgeEl identifier: createIdentifier(), }, title: this.props.title, - item: this.props.children.map((child) => new CommonCartridgeOrganizationItemElement(child).transform()), // TODO rekursiv weiter? + item: this.props.children.map((child) => new CommonCartridgeOrganizationItemElement(child).transform()), }; } diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 033e0993d9b..5dab8915684 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -8,6 +8,7 @@ import { CommonCartridgeIntendedUseType, CommonCartridgeResourceType, CommonCartridgeVersion, + ICommonCartridgeOrganizationBuilder, ICommonCartridgeResourceProps, ICommonCartridgeWebContentResourceProps, } from '../common-cartridge'; @@ -51,10 +52,11 @@ export class CommonCartridgeExportService { identifier: createIdentifier(lesson.id), title: lesson.name, resources: [], + _tag: 'resourceCollection', }); lesson.contents.forEach((content) => { - const resourceProps = this.mapContentToResource(lesson.id, content, version); + const resourceProps = this.mapContentToResource(lesson.id, content, version, organizationBuilder); if (resourceProps) { organizationBuilder.addResourceToOrganization(resourceProps); } @@ -75,6 +77,7 @@ export class CommonCartridgeExportService { // FIXME: change the title for tasks organization title: '', resources: [], + _tag: 'resourceCollection', }); tasks.forEach((task) => { @@ -85,7 +88,8 @@ export class CommonCartridgeExportService { private mapContentToResource( lessonId: string, content: ComponentProperties, - version: CommonCartridgeVersion + version: CommonCartridgeVersion, + orgBuilder: ICommonCartridgeOrganizationBuilder ): ICommonCartridgeResourceProps | undefined { const commonProps = (fileExt: 'html' | 'xml') => { return { @@ -131,9 +135,21 @@ export class CommonCartridgeExportService { if (content.component === ComponentType.LERNSTORE && content.content) { const { resources } = content.content; - return version === CommonCartridgeVersion.V_1_3_0 - ? { type: CommonCartridgeResourceType.WEB_LINK_V3, url: resources[0].url, ...commonProps('xml') } - : { type: CommonCartridgeResourceType.WEB_LINK_V1, url: resources[0].url, ...commonProps('xml') }; + const resourceProps: ICommonCartridgeResourceProps[] = resources.map((resource) => + version === CommonCartridgeVersion.V_1_3_0 + ? { type: CommonCartridgeResourceType.WEB_LINK_V3, url: resource.url, ...commonProps('xml') } + : { type: CommonCartridgeResourceType.WEB_LINK_V1, url: resource.url, ...commonProps('xml') } + ); + + orgBuilder.addSubOrganization({ + version, + identifier: createIdentifier(content._id), + title: content.title, + resources: resourceProps, + _tag: 'resourceCollection', + }); + + return undefined; } return undefined; From a94892046819c563ba8c4b62809c06a74a2aa74a Mon Sep 17 00:00:00 2001 From: Maximilian Kreuzkam Date: Fri, 24 Nov 2023 08:35:56 +0100 Subject: [PATCH 007/177] Add resourceCollection to returned OrganizationItemCollection. --- .../common-cartridge-file-builder.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.ts index 7c9e5245881..1d6571e0dd1 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.ts @@ -50,11 +50,19 @@ class CommonCartridgeOrganizationBuilder implements ICommonCartridgeOrganization } get orgProps(): OrganizationItemCollection { - // TODO resources return { _tag: 'itemCollection', title: this.props.title, - children: this.children.map((child) => child.orgProps), + children: + this.props._tag === 'resourceCollection' + ? { + _tag: 'resourceCollection', + resources: this.resourceProperties, + identifier: this.props.identifier, + version: this.props.version, + title: this.props.title, + } + : this.children.map((child) => child.orgProps), }; } From 15f5ec0fcc7b6f7fa51ed93de91990cf3adc3607 Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 24 Nov 2023 16:03:04 +0100 Subject: [PATCH 008/177] EW-539 startin with commo cartridge builder refactoring --- .../common-cartridge-file-builder.spec.ts | 47 +++++++++++++++++++ .../builders/common-cartridge-file-builder.ts | 27 +++++++++++ .../temp/common-cartridge.enums.ts | 6 +++ .../common-cartridge-manifest-element.ts | 7 +++ .../common-cartridge-metadata-element.ts | 36 ++++++++++++++ .../learnroom/common-cartridge/temp/index.ts | 2 + .../common-cartridge-element.interface.ts | 10 ++++ .../common-cartridge-resource.interface.ts | 24 ++++++++++ 8 files changed, 159 insertions(+) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-manifest-element.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/index.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts new file mode 100644 index 00000000000..09cde64c319 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts @@ -0,0 +1,47 @@ +import AdmZip from 'adm-zip'; +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeFileBuilder } from './common-cartridge-file-builder'; + +describe('CommonCartridgeFileBuilder', () => { + let sut: CommonCartridgeFileBuilder; + + const getFileContentAsString = (archive: AdmZip, path: string): string | undefined => + archive.getEntry(path)?.getData().toString(); + + beforeAll(() => { + sut = new CommonCartridgeFileBuilder({ + version: CommonCartridgeVersion.V_1_1, + }); + }); + + it('should be defined', () => { + expect(sut).toBeDefined(); + }); + + describe('build', () => { + describe('when using version 1.1', () => { + it('should create imsmanifest.xml in archive root', async () => { + const archive = new AdmZip(await sut.build()); + const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); + + expect(manifest).toBeDefined(); + }); + + it('should create metadata section in imsmanifest.xml', async () => { + const archive = new AdmZip(await sut.build()); + const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); + + expect(manifest).toContain(''); + expect(manifest).toContain(''); + }); + + it('should create organization section in imsmanifest.xml', async () => { + const archive = new AdmZip(await sut.build()); + const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); + + expect(manifest).toContain(''); + expect(manifest).toContain(''); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts new file mode 100644 index 00000000000..bc5ef08de5a --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts @@ -0,0 +1,27 @@ +import AdmZip from 'adm-zip'; +import { Builder } from 'xml2js'; +import { CommonCartridgeVersion } from '../common-cartridge.enums'; + +type CommonCartridgeFileBuilderOptions = { + version: CommonCartridgeVersion; +}; + +const DEFAULT_OPTIONS: CommonCartridgeFileBuilderOptions = { + version: CommonCartridgeVersion.V_1_3, +}; + +export class CommonCartridgeFileBuilder { + private readonly archive: AdmZip = new AdmZip(); + + private readonly xmlBuilder: Builder = new Builder(); + + constructor(private readonly options: CommonCartridgeFileBuilderOptions) { + Object.assign(this.options, DEFAULT_OPTIONS, options); + } + + public build(): Promise { + this.archive.addFile('imsmanifest.xml', Buffer.from('')); + + return Promise.resolve(this.archive.toBuffer()); + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts new file mode 100644 index 00000000000..d39f8f5c91b --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts @@ -0,0 +1,6 @@ +export enum CommonCartridgeVersion { + V_1_0 = '1.0', + V_1_1 = '1.1', + V_1_2 = '1.2', + V_1_3 = '1.3', +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-manifest-element.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-manifest-element.ts new file mode 100644 index 00000000000..a158494e03f --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-manifest-element.ts @@ -0,0 +1,7 @@ +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; + +export class CommonCartridgeManifestElement implements CommonCartridgeElement { + getManifestXmlObject(): Record { + throw new Error('Method not implemented.'); + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts new file mode 100644 index 00000000000..c9ea5d17c54 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts @@ -0,0 +1,36 @@ +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; + +type CommonCartridgeMetadataElementProps = { + version: string; + title: string; + creationDate: Date; + copyrightOwners: string[]; +}; + +export class CommonCartridgeMetadataElement implements CommonCartridgeElement { + constructor(private readonly props: CommonCartridgeMetadataElementProps) {} + + getManifestXmlObject(): Record { + return { + schema: 'IMS Common Cartridge', + schemaversion: this.props.version, + 'mnf:lom': { + 'mnf:general': { + 'mnf:title': { + 'mnf:string': this.props.title, + }, + }, + 'mnf:rights': { + 'mnf:copyrightAndOtherRestrictions': { + 'mnf:value': 'yes', + }, + 'mnf:description': { + 'mnf:string': `${this.props.creationDate.getFullYear()} ${this.props.copyrightOwners.join( + ', ' + )}`, + }, + }, + }, + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts new file mode 100644 index 00000000000..ad48a87feb6 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts @@ -0,0 +1,2 @@ +export * from './builders/common-cartridge-file-builder'; +export * from './common-cartridge.enums'; diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts new file mode 100644 index 00000000000..b39b9ee1236 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts @@ -0,0 +1,10 @@ +/** + * Every element which should be listed in the Common Cartridge manifest must implement this interface. + */ +export interface CommonCartridgeElement { + /** + * Returns the XML representation of the element. + * This method is used to build the imsmanifest.xml file. + */ + getManifestXmlObject(): Record; +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts new file mode 100644 index 00000000000..ac3a59bf2f2 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts @@ -0,0 +1,24 @@ +import AdmZip from 'adm-zip'; + +/** + * Every resource which should be added to the Common Cartridge archive must implement this interface. + */ +export interface CommonCartridgeResource { + /** + * In later Common Cartridge versions, resources can be inlined in the imsmanifest.xml file. + * @returns true if the resource can be inlined, otherwise false. + */ + canInline(): boolean; + + /** + * Adds the resource to the Common Cartridge archive. + * @param archive The archive to which the resource should be added. + */ + addToArchive(archive: AdmZip): void; + + /** + * This method is used to build the imsmanifest.xml file. + * @returns The XML representation of the resource if the resource can be inlined otherwise undefined. + */ + getManifestXmlObject(): Record | undefined; +} From 2ac3da602303f7ec9a39161f1f7695d9bd283315 Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 27 Nov 2023 15:47:12 +0100 Subject: [PATCH 009/177] EW-539 working on builders --- .../builders/common-cartridge-file-builder.ts | 45 ++++++++++++++++-- .../common-cartridge-metadata-builder.ts | 46 +++++++++++++++++++ .../common-cartridge-organization-builder.ts | 32 +++++++++++++ .../common-cartridge-manifest-element.ts | 10 +++- .../common-cartridge-metadata-element.ts | 2 +- .../common-cartridge-element.interface.ts | 2 +- .../common-cartridge-resource.interface.ts | 2 +- 7 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts index bc5ef08de5a..5f080b38d08 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts @@ -1,26 +1,61 @@ import AdmZip from 'adm-zip'; import { Builder } from 'xml2js'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeManifestElement } from '../elements/common-cartridge-manifest-element'; +import { CommonCartridgeMetadataBuilder } from './common-cartridge-metadata-builder'; +import { CommonCartridgeOrganizationBuilder } from './common-cartridge-organization-builder'; type CommonCartridgeFileBuilderOptions = { version: CommonCartridgeVersion; + title: string; + copyrightOwners?: string[]; + creationDate?: Date; }; const DEFAULT_OPTIONS: CommonCartridgeFileBuilderOptions = { - version: CommonCartridgeVersion.V_1_3, + version: CommonCartridgeVersion.V_1_1, + title: '', + copyrightOwners: [], + creationDate: new Date(), }; export class CommonCartridgeFileBuilder { - private readonly archive: AdmZip = new AdmZip(); + private readonly archive = new AdmZip(); - private readonly xmlBuilder: Builder = new Builder(); + private readonly xmlBuilder = new Builder(); - constructor(private readonly options: CommonCartridgeFileBuilderOptions) { + private readonly metadataBuilder = new CommonCartridgeMetadataBuilder(); + + private readonly organizationBuilders = new Array(); + + public constructor(private readonly options: CommonCartridgeFileBuilderOptions) { Object.assign(this.options, DEFAULT_OPTIONS, options); } + public withMetadata(): CommonCartridgeMetadataBuilder { + return this.metadataBuilder; + } + + public withOrganization(): CommonCartridgeOrganizationBuilder { + const builder = new CommonCartridgeOrganizationBuilder(); + + this.organizationBuilders.push(builder); + + return builder; + } + public build(): Promise { - this.archive.addFile('imsmanifest.xml', Buffer.from('')); + const metadata = this.metadataBuilder.build(); + const organizations = this.organizationBuilders.map((builder) => builder.build()); + const manifest = this.xmlBuilder.buildObject(new CommonCartridgeManifestElement({}).getManifestXml()); + + for (const organization of organizations) { + if (!organization.canInline()) { + organization.addToArchive(this.archive); + } + } + + this.archive.addFile('imsmanifest.xml', Buffer.from(manifest)); return Promise.resolve(this.archive.toBuffer()); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts new file mode 100644 index 00000000000..d8131c426b3 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts @@ -0,0 +1,46 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeMetadataElement } from '../elements/common-cartridge-metadata-element'; +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; + +export class CommonCartridgeMetadataBuilder { + private version = CommonCartridgeVersion.V_1_1; + + private title = ''; + + private copyrightOwners: string[] = []; + + private creationDate: Date = new Date(); + + public setVersion(version: CommonCartridgeVersion): CommonCartridgeMetadataBuilder { + this.version = version; + + return this; + } + + public setTitle(title: string): CommonCartridgeMetadataBuilder { + this.title = title; + + return this; + } + + public setCopyrightOwners(copyrightOwners: string[]): CommonCartridgeMetadataBuilder { + this.copyrightOwners = copyrightOwners; + + return this; + } + + public setCreationDate(creationDate: Date): CommonCartridgeMetadataBuilder { + this.creationDate = creationDate; + + return this; + } + + public build(): CommonCartridgeElement { + return new CommonCartridgeMetadataElement({ + version: this.version, + title: this.title, + copyrightOwners: this.copyrightOwners, + creationDate: this.creationDate, + }); + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts new file mode 100644 index 00000000000..f8fb1e7b625 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts @@ -0,0 +1,32 @@ +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; + +export class CommonCartridgeOrganizationBuilder { + private title = ''; + + private identifier = ''; + + private items: CommonCartridgeElement[] = []; + + public setIdentifier(identifier: string): CommonCartridgeOrganizationBuilder { + this.identifier = identifier; + + return this; + } + + public setTitle(title: string): CommonCartridgeOrganizationBuilder { + this.title = title; + + return this; + } + + public addItem(item: CommonCartridgeElement): CommonCartridgeOrganizationBuilder { + this.items.push(item); + + return this; + } + + public build(): CommonCartridgeElement & CommonCartridgeResource { + throw new Error('Method not implemented.'); + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-manifest-element.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-manifest-element.ts index a158494e03f..9257650f75a 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-manifest-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-manifest-element.ts @@ -1,7 +1,15 @@ import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; +type CommonCartridgeManifestElementProps = { + metadata: CommonCartridgeElement; + organizations: CommonCartridgeElement; + resources: CommonCartridgeElement; +}; + export class CommonCartridgeManifestElement implements CommonCartridgeElement { - getManifestXmlObject(): Record { + public constructor(private readonly props: CommonCartridgeManifestElementProps) {} + + public getManifestXml(): Record { throw new Error('Method not implemented.'); } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts index c9ea5d17c54..3e42fe0c242 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts @@ -10,7 +10,7 @@ type CommonCartridgeMetadataElementProps = { export class CommonCartridgeMetadataElement implements CommonCartridgeElement { constructor(private readonly props: CommonCartridgeMetadataElementProps) {} - getManifestXmlObject(): Record { + getManifestXml(): Record { return { schema: 'IMS Common Cartridge', schemaversion: this.props.version, diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts index b39b9ee1236..5a802fcdeeb 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts @@ -6,5 +6,5 @@ export interface CommonCartridgeElement { * Returns the XML representation of the element. * This method is used to build the imsmanifest.xml file. */ - getManifestXmlObject(): Record; + getManifestXml(): Record; } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts index ac3a59bf2f2..65b86ff8d35 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts @@ -20,5 +20,5 @@ export interface CommonCartridgeResource { * This method is used to build the imsmanifest.xml file. * @returns The XML representation of the resource if the resource can be inlined otherwise undefined. */ - getManifestXmlObject(): Record | undefined; + getManifestXml(): Record | undefined; } From d350da9c798860d5b6f962348ecf6f127d12d447 Mon Sep 17 00:00:00 2001 From: psachmann Date: Tue, 28 Nov 2023 10:37:42 +0100 Subject: [PATCH 010/177] EW-539 updatinf common cartridge interfaces --- .../common-cartridge-element.interface.ts | 4 ++-- .../common-cartridge-resource.interface.ts | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts index 5a802fcdeeb..9ec6eca68de 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts @@ -3,8 +3,8 @@ */ export interface CommonCartridgeElement { /** - * Returns the XML representation of the element. * This method is used to build the imsmanifest.xml file. + * @returns The XML object representation for the imsmanifest.xml file. */ - getManifestXml(): Record; + getManifestXml(): Record | undefined; } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts index 65b86ff8d35..459d3e311be 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts @@ -1,9 +1,9 @@ -import AdmZip from 'adm-zip'; +import { CommonCartridgeElement } from './common-cartridge-element.interface'; /** * Every resource which should be added to the Common Cartridge archive must implement this interface. */ -export interface CommonCartridgeResource { +export interface CommonCartridgeResource extends CommonCartridgeElement { /** * In later Common Cartridge versions, resources can be inlined in the imsmanifest.xml file. * @returns true if the resource can be inlined, otherwise false. @@ -11,14 +11,14 @@ export interface CommonCartridgeResource { canInline(): boolean; /** - * Adds the resource to the Common Cartridge archive. - * @param archive The archive to which the resource should be added. + * This method is used to determine the path of the resource in the Common Cartridge archive. + * @returns The path of the resource in the Common Cartridge archive. */ - addToArchive(archive: AdmZip): void; + getFilePath(): string; /** - * This method is used to build the imsmanifest.xml file. - * @returns The XML representation of the resource if the resource can be inlined otherwise undefined. + * This method is used to get the content of the resource. + * @returns The content of the resource. */ - getManifestXml(): Record | undefined; + getFileContent(): string; } From aa3cd5a033ab54446f0bf37c26942500d517b262 Mon Sep 17 00:00:00 2001 From: psachmann Date: Tue, 28 Nov 2023 10:39:58 +0100 Subject: [PATCH 011/177] EW-539 finishing working on builders --- .../builders/common-cartridge-file-builder.ts | 30 +++++------- .../common-cartridge-manifest-builder.ts | 46 +++++++++++++++++++ .../common-cartridge-metadata-builder.ts | 10 ++-- .../common-cartridge-organization-builder.ts | 8 ++-- 4 files changed, 67 insertions(+), 27 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts index 5f080b38d08..fe59055512c 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts @@ -1,42 +1,33 @@ import AdmZip from 'adm-zip'; -import { Builder } from 'xml2js'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeManifestElement } from '../elements/common-cartridge-manifest-element'; import { CommonCartridgeMetadataBuilder } from './common-cartridge-metadata-builder'; import { CommonCartridgeOrganizationBuilder } from './common-cartridge-organization-builder'; +import { CommonCartridgeManifestBuilder } from './common-cartridge-manifest-builder'; type CommonCartridgeFileBuilderOptions = { version: CommonCartridgeVersion; - title: string; - copyrightOwners?: string[]; - creationDate?: Date; }; const DEFAULT_OPTIONS: CommonCartridgeFileBuilderOptions = { version: CommonCartridgeVersion.V_1_1, - title: '', - copyrightOwners: [], - creationDate: new Date(), }; export class CommonCartridgeFileBuilder { private readonly archive = new AdmZip(); - private readonly xmlBuilder = new Builder(); - private readonly metadataBuilder = new CommonCartridgeMetadataBuilder(); private readonly organizationBuilders = new Array(); - public constructor(private readonly options: CommonCartridgeFileBuilderOptions) { + constructor(private readonly options: CommonCartridgeFileBuilderOptions) { Object.assign(this.options, DEFAULT_OPTIONS, options); } - public withMetadata(): CommonCartridgeMetadataBuilder { + withMetadata(): CommonCartridgeMetadataBuilder { return this.metadataBuilder; } - public withOrganization(): CommonCartridgeOrganizationBuilder { + withOrganization(): CommonCartridgeOrganizationBuilder { const builder = new CommonCartridgeOrganizationBuilder(); this.organizationBuilders.push(builder); @@ -44,19 +35,22 @@ export class CommonCartridgeFileBuilder { return builder; } - public build(): Promise { + build(): Promise { const metadata = this.metadataBuilder.build(); const organizations = this.organizationBuilders.map((builder) => builder.build()); - const manifest = this.xmlBuilder.buildObject(new CommonCartridgeManifestElement({}).getManifestXml()); + const manifest = new CommonCartridgeManifestBuilder(this.options.version) + .setMetadata(metadata) + .setOrganizations(organizations) + .build(); for (const organization of organizations) { if (!organization.canInline()) { - organization.addToArchive(this.archive); + this.archive.addFile(organization.getFilePath(), Buffer.from(organization.getFileContent())); } } - this.archive.addFile('imsmanifest.xml', Buffer.from(manifest)); + this.archive.addFile(manifest.getFilePath(), Buffer.from(manifest.getFileContent())); - return Promise.resolve(this.archive.toBuffer()); + return this.archive.toBufferPromise(); } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts new file mode 100644 index 00000000000..298e17fe900 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts @@ -0,0 +1,46 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeManifestElement } from '../elements/common-cartridge-manifest-element'; +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; +import { checkForNullOrUndefined } from '../utils'; + +export class CommonCartridgeManifestBuilder { + private metadata?: CommonCartridgeElement; + + private organizations?: CommonCartridgeElement[]; + + private resources?: CommonCartridgeResource[]; + + constructor(private readonly version: CommonCartridgeVersion) {} + + setMetadata(metadata: CommonCartridgeElement): CommonCartridgeManifestBuilder { + this.metadata = metadata; + + return this; + } + + setOrganizations(organizations: CommonCartridgeElement[]): CommonCartridgeManifestBuilder { + this.organizations = organizations; + + return this; + } + + setResources(resources: CommonCartridgeResource[]): CommonCartridgeManifestBuilder { + this.resources = resources; + + return this; + } + + build(): CommonCartridgeResource { + const metadata = checkForNullOrUndefined(this.metadata, 'Metadata'); + const organizations = checkForNullOrUndefined(this.organizations, 'Organizations'); + const resources = checkForNullOrUndefined(this.resources, 'Resources'); + + return new CommonCartridgeManifestElement({ + version: this.version, + metadata, + organizations, + resources, + }); + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts index d8131c426b3..b115180ce8f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts @@ -11,31 +11,31 @@ export class CommonCartridgeMetadataBuilder { private creationDate: Date = new Date(); - public setVersion(version: CommonCartridgeVersion): CommonCartridgeMetadataBuilder { + setVersion(version: CommonCartridgeVersion): CommonCartridgeMetadataBuilder { this.version = version; return this; } - public setTitle(title: string): CommonCartridgeMetadataBuilder { + setTitle(title: string): CommonCartridgeMetadataBuilder { this.title = title; return this; } - public setCopyrightOwners(copyrightOwners: string[]): CommonCartridgeMetadataBuilder { + setCopyrightOwners(copyrightOwners: string[]): CommonCartridgeMetadataBuilder { this.copyrightOwners = copyrightOwners; return this; } - public setCreationDate(creationDate: Date): CommonCartridgeMetadataBuilder { + setCreationDate(creationDate: Date): CommonCartridgeMetadataBuilder { this.creationDate = creationDate; return this; } - public build(): CommonCartridgeElement { + build(): CommonCartridgeElement { return new CommonCartridgeMetadataElement({ version: this.version, title: this.title, diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts index f8fb1e7b625..44a59c79ca5 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts @@ -8,25 +8,25 @@ export class CommonCartridgeOrganizationBuilder { private items: CommonCartridgeElement[] = []; - public setIdentifier(identifier: string): CommonCartridgeOrganizationBuilder { + setIdentifier(identifier: string): CommonCartridgeOrganizationBuilder { this.identifier = identifier; return this; } - public setTitle(title: string): CommonCartridgeOrganizationBuilder { + setTitle(title: string): CommonCartridgeOrganizationBuilder { this.title = title; return this; } - public addItem(item: CommonCartridgeElement): CommonCartridgeOrganizationBuilder { + addItem(item: CommonCartridgeElement): CommonCartridgeOrganizationBuilder { this.items.push(item); return this; } - public build(): CommonCartridgeElement & CommonCartridgeResource { + build(): CommonCartridgeResource { throw new Error('Method not implemented.'); } } From 7e38b2c94ec9ecad9efb9e36103803f2910d82da Mon Sep 17 00:00:00 2001 From: psachmann Date: Tue, 28 Nov 2023 11:26:39 +0100 Subject: [PATCH 012/177] EW-539 renaming manifest element to resource --- .../builders/common-cartridge-file-builder.ts | 10 ++++-- .../common-cartridge-manifest-builder.ts | 4 +-- .../common-cartridge-metadata-builder.ts | 8 +---- .../common-cartridge-manifest-element.ts | 15 --------- .../common-cartridge-manifest-resource.ts | 33 +++++++++++++++++++ .../learnroom/common-cartridge/temp/utils.ts | 7 ++++ 6 files changed, 50 insertions(+), 27 deletions(-) delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-manifest-element.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts index fe59055512c..91ffb6f1d8e 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts @@ -13,14 +13,18 @@ const DEFAULT_OPTIONS: CommonCartridgeFileBuilderOptions = { }; export class CommonCartridgeFileBuilder { - private readonly archive = new AdmZip(); + private readonly archive: AdmZip; - private readonly metadataBuilder = new CommonCartridgeMetadataBuilder(); + private readonly metadataBuilder: CommonCartridgeMetadataBuilder; - private readonly organizationBuilders = new Array(); + private readonly organizationBuilders: CommonCartridgeOrganizationBuilder[]; constructor(private readonly options: CommonCartridgeFileBuilderOptions) { Object.assign(this.options, DEFAULT_OPTIONS, options); + + this.archive = new AdmZip(); + this.metadataBuilder = new CommonCartridgeMetadataBuilder(this.options.version); + this.organizationBuilders = []; } withMetadata(): CommonCartridgeMetadataBuilder { diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts index 298e17fe900..1ea68931009 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts @@ -1,7 +1,7 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeManifestElement } from '../elements/common-cartridge-manifest-element'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeManifestResource } from '../resources/common-cartridge-manifest-resource'; import { checkForNullOrUndefined } from '../utils'; export class CommonCartridgeManifestBuilder { @@ -36,7 +36,7 @@ export class CommonCartridgeManifestBuilder { const organizations = checkForNullOrUndefined(this.organizations, 'Organizations'); const resources = checkForNullOrUndefined(this.resources, 'Resources'); - return new CommonCartridgeManifestElement({ + return new CommonCartridgeManifestResource({ version: this.version, metadata, organizations, diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts index b115180ce8f..40943c0a2c9 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts @@ -3,19 +3,13 @@ import { CommonCartridgeMetadataElement } from '../elements/common-cartridge-met import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; export class CommonCartridgeMetadataBuilder { - private version = CommonCartridgeVersion.V_1_1; - private title = ''; private copyrightOwners: string[] = []; private creationDate: Date = new Date(); - setVersion(version: CommonCartridgeVersion): CommonCartridgeMetadataBuilder { - this.version = version; - - return this; - } + constructor(private readonly version: CommonCartridgeVersion) {} setTitle(title: string): CommonCartridgeMetadataBuilder { this.title = title; diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-manifest-element.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-manifest-element.ts deleted file mode 100644 index 9257650f75a..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-manifest-element.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; - -type CommonCartridgeManifestElementProps = { - metadata: CommonCartridgeElement; - organizations: CommonCartridgeElement; - resources: CommonCartridgeElement; -}; - -export class CommonCartridgeManifestElement implements CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeManifestElementProps) {} - - public getManifestXml(): Record { - throw new Error('Method not implemented.'); - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts new file mode 100644 index 00000000000..e207ec4293b --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts @@ -0,0 +1,33 @@ +import { Builder } from 'xml2js'; +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; + +type CommonCartridgeManifestElementProps = { + version: CommonCartridgeVersion; + metadata: CommonCartridgeElement; + organizations: CommonCartridgeElement[]; + resources: CommonCartridgeElement[]; +}; + +export class CommonCartridgeManifestResource implements CommonCartridgeResource { + private readonly xmlBuilder = new Builder(); + + constructor(private readonly props: CommonCartridgeManifestElementProps) {} + + canInline(): boolean { + return false; + } + + getFilePath(): string { + return 'imsmanifest.xml'; + } + + getFileContent(): string { + return this.xmlBuilder.buildObject(this.getManifestXml()); + } + + getManifestXml(): Record | undefined { + throw new Error('Method not implemented.'); + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts new file mode 100644 index 00000000000..659a4fccba5 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts @@ -0,0 +1,7 @@ +export function checkForNullOrUndefined(value: T | undefined | null, name: string): T | never { + if (value) { + return value; + } + + throw new Error(`${name} is null or undefined`); +} From e0706b7bd57c5116012fd597a508aa917297b521 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 28 Nov 2023 13:49:45 +0100 Subject: [PATCH 013/177] EW-539 Move web link resource to new folder --- ...common-cartridge-web-link-resource.spec.ts | 77 ++++++++++++++++++ .../common-cartridge-web-link-resource.ts | 78 +++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts new file mode 100644 index 00000000000..2c39ebff4ce --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts @@ -0,0 +1,77 @@ +import { Builder } from 'xml2js'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { + CommonCartridgeWebLinkResourceElement, + ICommonCartridgeWebLinkResourceProps, +} from './common-cartridge-web-link-resource'; + +describe('CommonCartridgeWebLinkResourceElement', () => { + const xmlBuilder = new Builder(); + const propsOfV3: ICommonCartridgeWebLinkResourceProps = { + type: CommonCartridgeResourceType.WEB_LINK_V_1_3, + version: CommonCartridgeVersion.V_1_3, + identifier: 'web-link-v3', + href: 'https://example.com/linkv3', + title: 'Web Link v3', + url: 'https://example.com/linkv3', + }; + const propsOfV1: ICommonCartridgeWebLinkResourceProps = { + type: CommonCartridgeResourceType.WEB_LINK_V_1_1, + version: CommonCartridgeVersion.V_1_1, + identifier: 'web-link-v1', + href: 'https://example.com/link1', + title: 'Web Link v1', + url: 'https://example.com/link1', + }; + + describe('CommonCartridgeWebLinkResourceElement of version 3', () => { + it('should return XML content of common cartridge version 3', () => { + const webLinkResource = new CommonCartridgeWebLinkResourceElement(propsOfV3, xmlBuilder); + const content = webLinkResource.getFileContent(); + const transformed = webLinkResource.getManifestXml(); + + expect(content).toContain('webLink'); + expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); + expect(content).toContain('http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3'); + expect(content).toContain('http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd'); + expect(transformed).toEqual({ + $: { + identifier: propsOfV3.identifier, + type: propsOfV3.type, + }, + file: { + $: { + href: propsOfV3.href, + }, + }, + }); + expect(webLinkResource.canInline()).toBe(false); + }); + }); + + describe('CommonCartridgeWebLinkResourceElement of version 1', () => { + it('should return XML content of common cartridge version 1', () => { + const webLinkResource = new CommonCartridgeWebLinkResourceElement(propsOfV1, xmlBuilder); + const content = webLinkResource.getFileContent(); + const transformed = webLinkResource.getManifestXml(); + + expect(content).toContain('webLink'); + expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); + expect(content).toContain('http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1'); + expect(content).toContain( + 'https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd' + ); + expect(transformed).toEqual({ + $: { + identifier: propsOfV1.identifier, + type: propsOfV1.type, + }, + file: { + $: { + href: propsOfV1.href, + }, + }, + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts new file mode 100644 index 00000000000..4fa1bfe1a86 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts @@ -0,0 +1,78 @@ +import { Builder } from 'xml2js'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; + +export type ICommonCartridgeWebLinkResourceProps = { + type: CommonCartridgeResourceType.WEB_LINK_V_1_1 | CommonCartridgeResourceType.WEB_LINK_V_1_3; + version: CommonCartridgeVersion; + identifier: string; + href: string; + title: string; + url: string; +}; + +export class CommonCartridgeWebLinkResourceElement implements CommonCartridgeResource { + constructor(private readonly props: ICommonCartridgeWebLinkResourceProps, private readonly xmlBuilder: Builder) {} + + canInline(): boolean { + return false; + } + + // TODO: This is not correct. The href should be relative to the imsmanifest.xml file. + getFilePath(): string { + return this.props.href; + } + + getFileContent(): string { + const commonTags = { + title: this.props.title, + url: { + $: { + href: this.props.url, + target: '_self', + windowFeatures: 'width=100, height=100', + }, + }, + }; + switch (this.props.version) { + case CommonCartridgeVersion.V_1_3: + return this.xmlBuilder.buildObject({ + webLink: { + ...commonTags, + $: { + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': + 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd', + }, + }, + }); + default: + return this.xmlBuilder.buildObject({ + webLink: { + ...commonTags, + $: { + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': + 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', + }, + }, + }); + } + } + + getManifestXml(): Record { + return { + $: { + identifier: this.props.identifier, + type: this.props.type, + }, + file: { + $: { + href: this.props.href, + }, + }, + }; + } +} From f911c5a9bdeaa0d1e112bf8647db0e422f4e2779 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 28 Nov 2023 13:50:21 +0100 Subject: [PATCH 014/177] EW-539 Add resource type to enums --- .../common-cartridge/temp/common-cartridge.enums.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts index d39f8f5c91b..4c9c1e874f0 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts @@ -4,3 +4,10 @@ export enum CommonCartridgeVersion { V_1_2 = '1.2', V_1_3 = '1.3', } + +export enum CommonCartridgeResourceType { + LTI = 'imsbasiclti_xmlv1p0', + WEB_CONTENT = 'webcontent', + WEB_LINK_V_1_1 = 'imswl_xmlv1p1', + WEB_LINK_V_1_3 = 'imswl_xmlv1p3', +} From 08db6668cd03f8f6c20eb94ca98605ef8a919109 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 28 Nov 2023 14:18:32 +0100 Subject: [PATCH 015/177] EW-539 Move web content and lti resources to new folder --- .../temp/common-cartridge.enums.ts | 7 + .../common-cartridge-lti-resource.spec.ts | 144 ++++++++++++++++++ .../common-cartridge-lti-resource.ts | 98 ++++++++++++ ...mon-cartridge-web-content-resource.spec.ts | 46 ++++++ .../common-cartridge-web-content-resource.ts | 48 ++++++ 5 files changed, 343 insertions(+) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts index 4c9c1e874f0..c9c2463e867 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts @@ -11,3 +11,10 @@ export enum CommonCartridgeResourceType { WEB_LINK_V_1_1 = 'imswl_xmlv1p1', WEB_LINK_V_1_3 = 'imswl_xmlv1p3', } + +export enum CommonCartridgeIntendedUseType { + ASSIGNMENT = 'assignment', + LESSON_PLAN = 'lessonplan', + SYLLABUS = 'syllabus', + UNSPECIFIED = 'unspecified', +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts new file mode 100644 index 00000000000..1dda7effe77 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts @@ -0,0 +1,144 @@ +import { Builder } from 'xml2js'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeLtiResource, ICommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; + +describe('CommonCartridgeLtiResource', () => { + const propsVersion1: ICommonCartridgeLtiResourceProps = { + type: CommonCartridgeResourceType.LTI, + version: CommonCartridgeVersion.V_1_1, + identifier: 'lti-identifier-version1', + href: 'lti-identifier-version1/lti.xml', + title: 'lti-title-version1', + description: 'lti-description-version1', + url: 'https://to-a-lti-tool-version1.tld', + }; + + const propsVersion3: ICommonCartridgeLtiResourceProps = { + type: CommonCartridgeResourceType.LTI, + version: CommonCartridgeVersion.V_1_3, + identifier: 'lti-identifier-version3', + href: 'lti-identifier-version3/lti.xml', + title: 'lti-title-version3', + description: 'lti-description-version3', + url: 'https://to-a-lti-tool-version3.tld', + }; + + const ltiResourceVersion1 = new CommonCartridgeLtiResource(propsVersion1, new Builder()); + const ltiResourceVersion3 = new CommonCartridgeLtiResource(propsVersion3, new Builder()); + + describe('content', () => { + describe('When Common Cartridge version 1.1', () => { + it('should return correct content for version 1.1', () => { + const expectedContent = ` + + + lti-title-version1 + lti-description-version1 + https://to-a-lti-tool-version1.tld + https://to-a-lti-tool-version1.tld + + + + `; + + const content = ltiResourceVersion1.getFileContent(); + + expect(content.replace(/\s/g, '')).toEqual(expectedContent.replace(/\s/g, '')); + }); + }); + + describe('When Common Cartridge version 1.3', () => { + it('should return correct content for version 1.3', () => { + const expectedContent = ` + + + lti-title-version3 + lti-description-version3 + https://to-a-lti-tool-version3.tld + https://to-a-lti-tool-version3.tld + + + + `; + + const content = ltiResourceVersion3.getFileContent(); + + expect(content.replace(/\s/g, '')).toEqual(expectedContent.replace(/\s/g, '')); + }); + }); + }); + + describe('transform', () => { + describe('When Common Cartridge version 1.1', () => { + it('should transform props into the expected resource structure', () => { + const expectedOutput = { + $: { + identifier: propsVersion1.identifier, + type: propsVersion1.type, + }, + file: { + $: { + href: propsVersion1.href, + }, + }, + }; + + const transformed = ltiResourceVersion1.getManifestXml(); + expect(transformed).toEqual(expectedOutput); + }); + }); + describe('When Common Cartridge version 1.3', () => { + it('should transform props into the expected resource structure', () => { + const expectedOutput = { + $: { + identifier: propsVersion3.identifier, + type: propsVersion3.type, + }, + file: { + $: { + href: propsVersion3.href, + }, + }, + }; + + const transformed = ltiResourceVersion3.getManifestXml(); + expect(transformed).toEqual(expectedOutput); + }); + }); + }); + + describe('canInline', () => { + describe('When Common Cartridge version 1.1', () => { + it('should return false for canInline', () => { + const result = ltiResourceVersion1.canInline(); + expect(result).toBe(false); + }); + }); + describe('When Common Cartridge version 1.3', () => { + it('should return false for canInline', () => { + const result = ltiResourceVersion3.canInline(); + expect(result).toBe(false); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts new file mode 100644 index 00000000000..5d204b4483b --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts @@ -0,0 +1,98 @@ +import { Builder } from 'xml2js'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; + +export type ICommonCartridgeLtiResourceProps = { + type: CommonCartridgeResourceType.LTI; + version: CommonCartridgeVersion; + identifier: string; + href: string; + title: string; + description?: string; + url: string; +}; + +export class CommonCartridgeLtiResource implements CommonCartridgeResource { + constructor(private readonly props: ICommonCartridgeLtiResourceProps, private readonly xmlBuilder: Builder) {} + + canInline(): boolean { + return false; + } + + // TODO: This is not correct. The href should be relative to the imsmanifest.xml file. + getFilePath(): string { + return this.props.href; + } + + getFileContent(): string { + const commonObject = { + cartridge_basiclti_link: { + $: { + xmlns: '', + 'xmlns:blti': '', + 'xmlns:lticm': '', + 'xmlns:lticp': '', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': '', + }, + blti: { + title: this.props.title, + description: this.props.description, + launch_url: this.props.url, + secure_launch_url: this.props.url, + cartridge_bundle: { + $: { + identifierref: 'BLTI001_Bundle', + }, + }, + cartridge_icon: { + $: { + identifierref: 'BLTI001_Icon', + }, + }, + }, + }, + }; + + switch (this.props.version) { + case CommonCartridgeVersion.V_1_3: + commonObject.cartridge_basiclti_link.$.xmlns = 'http://www.imsglobal.org/xsd/imslticc_v1p3'; + commonObject.cartridge_basiclti_link.$['xmlns:blti'] = 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0'; + commonObject.cartridge_basiclti_link.$['xmlns:lticm'] = 'http://www.imsglobal.org/xsd/imslticm_v1p0'; + commonObject.cartridge_basiclti_link.$['xmlns:lticp'] = 'http://www.imsglobal.org/xsd/imslticp_v1p0'; + commonObject.cartridge_basiclti_link.$['xsi:schemaLocation'] = + 'http://www.imsglobal.org/xsd/imslticc_v1p3 http://www.imsglobal.org/xsd/imslticc_v1p3.xsd' + + 'http://www.imsglobal.org/xsd/imslticp_v1p0 imslticp_v1p0.xsd' + + 'http://www.imsglobal.org/xsd/imslticm_v1p0 imslticm_v1p0.xsd' + + 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0 imsbasiclti_v1p0p1.xsd"'; + break; + default: + commonObject.cartridge_basiclti_link.$.xmlns = '/xsd/imslticc_v1p0'; + commonObject.cartridge_basiclti_link.$['xmlns:blti'] = '/xsd/imsbasiclti_v1p0'; + commonObject.cartridge_basiclti_link.$['xmlns:lticm'] = '/xsd/imslticm_v1p0'; + commonObject.cartridge_basiclti_link.$['xmlns:lticp'] = '/xsd/imslticp_v1p0'; + commonObject.cartridge_basiclti_link.$['xsi:schemaLocation'] = + '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd' + + '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd' + + '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd' + + '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd"'; + break; + } + + return this.xmlBuilder.buildObject(commonObject); + } + + getManifestXml(): Record { + return { + $: { + identifier: this.props.identifier, + type: this.props.type, + }, + file: { + $: { + href: this.props.href, + }, + }, + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts new file mode 100644 index 00000000000..806b739c4ee --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts @@ -0,0 +1,46 @@ +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { + CommonCartridgeWebContentResource, + ICommonCartridgeWebContentResourceProps, +} from './common-cartridge-web-content-resource'; + +describe('CommonCartridgeWebContentResource', () => { + const props: ICommonCartridgeWebContentResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_3, + identifier: 'web-link', + href: 'https://example.com/link', + title: 'Web Link', + html: 'html tages for testing', + }; + const webContentResource = new CommonCartridgeWebContentResource(props); + describe('content', () => { + it('should return html content regardless of common cartridge version', () => { + const content = webContentResource.getFileContent(); + expect(content).toContain(props.html); + }); + }); + describe('canInline', () => { + it('check the return value of the method Can Inline ', () => { + expect(webContentResource.canInline()).toBe(false); + }); + }); + describe('transform', () => { + it('should transform XML content regardless of common cartridge version', () => { + const transformed = webContentResource.getManifestXml(); + expect(webContentResource.canInline()).toBe(false); + expect(transformed).toEqual({ + $: { + identifier: props.identifier, + type: props.type, + intendeduse: 'unspecified', + }, + file: { + $: { + href: props.href, + }, + }, + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts new file mode 100644 index 00000000000..4a78c71a809 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts @@ -0,0 +1,48 @@ +import { + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../common-cartridge.enums'; +import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; + +export type ICommonCartridgeWebContentResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT; + version: CommonCartridgeVersion; + identifier: string; + href: string; + title: string; + html: string; + intendedUse?: CommonCartridgeIntendedUseType; +}; + +export class CommonCartridgeWebContentResource implements CommonCartridgeResource { + constructor(private readonly props: ICommonCartridgeWebContentResourceProps) {} + + canInline(): boolean { + return false; + } + + // TODO: This is not correct. The href should be relative to the imsmanifest.xml file. + getFilePath(): string { + return this.props.href; + } + + getFileContent(): string { + return this.props.html; + } + + getManifestXml(): Record { + return { + $: { + identifier: this.props.identifier, + type: this.props.type, + intendeduse: this.props.intendedUse ?? CommonCartridgeIntendedUseType.UNSPECIFIED, + }, + file: { + $: { + href: this.props.href, + }, + }, + }; + } +} From 70ca958ff4540ec127857a3cf7d23a69e930e05e Mon Sep 17 00:00:00 2001 From: psachmann Date: Tue, 28 Nov 2023 12:26:16 +0100 Subject: [PATCH 016/177] EW-539 adding utils and wrapper elements --- ...cartridge-organizations-wrapper-element.ts | 26 ++++++++++ ...mon-cartridge-resources-wrapper-element.ts | 15 ++++++ .../learnroom/common-cartridge/temp/utils.ts | 52 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-organizations-wrapper-element.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-resources-wrapper-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-organizations-wrapper-element.ts new file mode 100644 index 00000000000..6a318621ab3 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-organizations-wrapper-element.ts @@ -0,0 +1,26 @@ +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; + +export class CommonCartridgeOrganizationsWrapperElement implements CommonCartridgeElement { + constructor(private readonly items: CommonCartridgeElement[]) {} + + getManifestXml(): Record { + return { + organization: [ + { + $: { + identifier: 'org-1', + structure: 'rooted-hierarchy', + }, + item: [ + { + $: { + identifier: 'LearningModules', + }, + item: this.items.map((items) => items.getManifestXml()), + }, + ], + }, + ], + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-resources-wrapper-element.ts new file mode 100644 index 00000000000..49c7dc48ebf --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-resources-wrapper-element.ts @@ -0,0 +1,15 @@ +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; + +export class CommonCartridgeResourcesWrapperElement implements CommonCartridgeElement { + constructor(private readonly items: CommonCartridgeElement[]) {} + + getManifestXml(): Record { + return { + resources: [ + { + resource: this.items.map((items) => items.getManifestXml()), + }, + ], + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts index 659a4fccba5..12e616029d8 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts @@ -1,3 +1,28 @@ +import { ObjectId } from 'bson'; +import { CommonCartridgeVersion } from './common-cartridge.enums'; +import { CommonCartridgeElement } from './interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from './interfaces/common-cartridge-resource.interface'; + +export function createIdentifier(id?: string | ObjectId): string { + id = id ?? new ObjectId(); + + return `i${id.toString()}`; +} + +export function createVersionNotSupportedError(version: CommonCartridgeVersion): Error { + return new Error(`Version ${version} is not supported`); +} + +export function checkCommonCartridgeVersion(version: CommonCartridgeVersion): void | never { + const supportedVersions = [CommonCartridgeVersion.V_1_1, CommonCartridgeVersion.V_1_3]; + + if (supportedVersions.includes(version)) { + return; + } + + throw createVersionNotSupportedError(version); +} + export function checkForNullOrUndefined(value: T | undefined | null, name: string): T | never { if (value) { return value; @@ -5,3 +30,30 @@ export function checkForNullOrUndefined(value: T | undefined | null, name: st throw new Error(`${name} is null or undefined`); } + +export function isCommonCartridgeElement(element: unknown): element is CommonCartridgeElement { + return ( + (element as CommonCartridgeElement).getManifestXml !== undefined && + typeof (element as CommonCartridgeElement).getManifestXml === 'function' + ); +} + +export function isCommonCartridgeElementArray(elements: unknown[]): elements is CommonCartridgeElement[] { + return elements.every((element) => isCommonCartridgeElement(element)); +} + +export function isCommonCartridgeResource(element: unknown): element is CommonCartridgeResource { + return ( + isCommonCartridgeElement(element) && + (element as CommonCartridgeResource).canInline !== undefined && + typeof (element as CommonCartridgeResource).canInline === 'function' && + (element as CommonCartridgeResource).getFilePath !== undefined && + typeof (element as CommonCartridgeResource).getFilePath === 'function' && + (element as CommonCartridgeResource).getFileContent !== undefined && + typeof (element as CommonCartridgeResource).getFileContent === 'function' + ); +} + +export function isCommonCartridgeResourceArray(elements: unknown[]): elements is CommonCartridgeResource[] { + return elements.every((element) => isCommonCartridgeResource(element)); +} From e71b06da525b7f8151ad4c5a0c6742e18e03987f Mon Sep 17 00:00:00 2001 From: psachmann Date: Tue, 28 Nov 2023 14:33:44 +0100 Subject: [PATCH 017/177] EW-539 working on builders --- .../builders/common-cartridge-file-builder.ts | 31 ++++++------ .../common-cartridge-manifest-builder.ts | 18 +++++-- .../common-cartridge-organization-builder.ts | 25 ++++++++-- .../temp/common-cartridge.enums.ts | 41 ++++++++-------- .../common-cartridge-manifest-resource.ts | 48 ++++++++++++++++++- .../learnroom/common-cartridge/temp/utils.ts | 2 +- 6 files changed, 120 insertions(+), 45 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts index 91ffb6f1d8e..84172b00981 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts @@ -3,36 +3,37 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeMetadataBuilder } from './common-cartridge-metadata-builder'; import { CommonCartridgeOrganizationBuilder } from './common-cartridge-organization-builder'; import { CommonCartridgeManifestBuilder } from './common-cartridge-manifest-builder'; - -type CommonCartridgeFileBuilderOptions = { - version: CommonCartridgeVersion; -}; - -const DEFAULT_OPTIONS: CommonCartridgeFileBuilderOptions = { - version: CommonCartridgeVersion.V_1_1, -}; +import { checkCommonCartridgeVersion, isCommonCartridgeResource, checkDefined } from '../utils'; export class CommonCartridgeFileBuilder { + private identifier?: string; + private readonly archive: AdmZip; private readonly metadataBuilder: CommonCartridgeMetadataBuilder; private readonly organizationBuilders: CommonCartridgeOrganizationBuilder[]; - constructor(private readonly options: CommonCartridgeFileBuilderOptions) { - Object.assign(this.options, DEFAULT_OPTIONS, options); + constructor(private readonly version: CommonCartridgeVersion) { + checkCommonCartridgeVersion(version); this.archive = new AdmZip(); - this.metadataBuilder = new CommonCartridgeMetadataBuilder(this.options.version); + this.metadataBuilder = new CommonCartridgeMetadataBuilder(version); this.organizationBuilders = []; } + setIdentifier(identifier: string): CommonCartridgeFileBuilder { + this.identifier = identifier; + + return this; + } + withMetadata(): CommonCartridgeMetadataBuilder { return this.metadataBuilder; } withOrganization(): CommonCartridgeOrganizationBuilder { - const builder = new CommonCartridgeOrganizationBuilder(); + const builder = new CommonCartridgeOrganizationBuilder(this.version); this.organizationBuilders.push(builder); @@ -40,15 +41,17 @@ export class CommonCartridgeFileBuilder { } build(): Promise { + const identifier = checkDefined(this.identifier, 'Identifier'); const metadata = this.metadataBuilder.build(); const organizations = this.organizationBuilders.map((builder) => builder.build()); - const manifest = new CommonCartridgeManifestBuilder(this.options.version) + const manifest = new CommonCartridgeManifestBuilder(this.version) + .setIdentifier(identifier) .setMetadata(metadata) .setOrganizations(organizations) .build(); for (const organization of organizations) { - if (!organization.canInline()) { + if (isCommonCartridgeResource(organization) && !organization.canInline()) { this.archive.addFile(organization.getFilePath(), Buffer.from(organization.getFileContent())); } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts index 1ea68931009..81093ee09cc 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts @@ -2,9 +2,11 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { CommonCartridgeManifestResource } from '../resources/common-cartridge-manifest-resource'; -import { checkForNullOrUndefined } from '../utils'; +import { checkDefined } from '../utils'; export class CommonCartridgeManifestBuilder { + private identifier?: string; + private metadata?: CommonCartridgeElement; private organizations?: CommonCartridgeElement[]; @@ -13,6 +15,12 @@ export class CommonCartridgeManifestBuilder { constructor(private readonly version: CommonCartridgeVersion) {} + setIdentifier(identifier: string): CommonCartridgeManifestBuilder { + this.identifier = identifier; + + return this; + } + setMetadata(metadata: CommonCartridgeElement): CommonCartridgeManifestBuilder { this.metadata = metadata; @@ -32,12 +40,14 @@ export class CommonCartridgeManifestBuilder { } build(): CommonCartridgeResource { - const metadata = checkForNullOrUndefined(this.metadata, 'Metadata'); - const organizations = checkForNullOrUndefined(this.organizations, 'Organizations'); - const resources = checkForNullOrUndefined(this.resources, 'Resources'); + const identifier = checkDefined(this.identifier, 'Identifier'); + const metadata = checkDefined(this.metadata, 'Metadata'); + const organizations = checkDefined(this.organizations, 'Organizations'); + const resources = checkDefined(this.resources, 'Resources'); return new CommonCartridgeManifestResource({ version: this.version, + identifier, metadata, organizations, resources, diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts index 44a59c79ca5..5b36389e77f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts @@ -1,12 +1,18 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; +import { checkDefined } from '../utils'; export class CommonCartridgeOrganizationBuilder { - private title = ''; + private title?: string; - private identifier = ''; + private identifier?: string; - private items: CommonCartridgeElement[] = []; + private items: CommonCartridgeResource[] = []; + + private children: CommonCartridgeElement[] = []; + + constructor(private readonly version: CommonCartridgeVersion, private readonly parent?: CommonCartridgeElement) {} setIdentifier(identifier: string): CommonCartridgeOrganizationBuilder { this.identifier = identifier; @@ -20,13 +26,22 @@ export class CommonCartridgeOrganizationBuilder { return this; } - addItem(item: CommonCartridgeElement): CommonCartridgeOrganizationBuilder { + addOrganization(organization: CommonCartridgeElement): CommonCartridgeOrganizationBuilder { + this.items.push(organization); + + return new CommonCartridgeOrganizationBuilder(this.version); + } + + addOrganizationItem(item: CommonCartridgeResource): CommonCartridgeOrganizationBuilder { this.items.push(item); return this; } build(): CommonCartridgeResource { - throw new Error('Method not implemented.'); + // const title = isDefined(this.title, 'Title'); + // const identifier = isDefined(this.identifier, 'Identifier'); + + throw new Error('Not implemented'); } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts index c9c2463e867..1c33faba8fb 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts @@ -1,20 +1,21 @@ -export enum CommonCartridgeVersion { - V_1_0 = '1.0', - V_1_1 = '1.1', - V_1_2 = '1.2', - V_1_3 = '1.3', -} - -export enum CommonCartridgeResourceType { - LTI = 'imsbasiclti_xmlv1p0', - WEB_CONTENT = 'webcontent', - WEB_LINK_V_1_1 = 'imswl_xmlv1p1', - WEB_LINK_V_1_3 = 'imswl_xmlv1p3', -} - -export enum CommonCartridgeIntendedUseType { - ASSIGNMENT = 'assignment', - LESSON_PLAN = 'lessonplan', - SYLLABUS = 'syllabus', - UNSPECIFIED = 'unspecified', -} +export enum CommonCartridgeVersion { + V_1_0 = '1.0.0', + V_1_1 = '1.1.0', + V_1_2 = '1.2.0', + V_1_3 = '1.3.0', + V_1_4 = '1.4.0', +} + +export enum CommonCartridgeResourceType { + LTI = 'imsbasiclti_xmlv1p0', + WEB_CONTENT = 'webcontent', + WEB_LINK_V_1_1 = 'imswl_xmlv1p1', + WEB_LINK_V_1_3 = 'imswl_xmlv1p3', +} + +export enum CommonCartridgeIntendedUseType { + ASSIGNMENT = 'assignment', + LESSON_PLAN = 'lessonplan', + SYLLABUS = 'syllabus', + UNSPECIFIED = 'unspecified', +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts index e207ec4293b..d6f15020839 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts @@ -2,9 +2,13 @@ import { Builder } from 'xml2js'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeOrganizationsWrapperElement } from '../elements/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElement } from '../elements/common-cartridge-resources-wrapper-element'; +import { createVersionNotSupportedError } from '../utils'; type CommonCartridgeManifestElementProps = { version: CommonCartridgeVersion; + identifier: string; metadata: CommonCartridgeElement; organizations: CommonCartridgeElement[]; resources: CommonCartridgeElement[]; @@ -28,6 +32,48 @@ export class CommonCartridgeManifestResource implements CommonCartridgeResource } getManifestXml(): Record | undefined { - throw new Error('Method not implemented.'); + return { + manifest: { + $: this.getXmlNamespacesByVersion(), + metadata: this.props.metadata.getManifestXml(), + organizations: new CommonCartridgeOrganizationsWrapperElement( + this.props.organizations + ).getManifestXml(), + resources: new CommonCartridgeResourcesWrapperElement(this.props.resources).getManifestXml(), + }, + }; + } + + private getXmlNamespacesByVersion(): Record { + switch (this.props.version) { + case CommonCartridgeVersion.V_1_1: + return { + identifier: this.props.identifier, + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1', + 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest', + 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource', + 'xmlns:ext': 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': + 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lomresource_v1p0.xsd ' + + 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd ' + + 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd ' + + 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_cpextensionv1p2_v1p0.xsd', + }; + case CommonCartridgeVersion.V_1_3: + return { + identifier: this.props.identifier, + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', + 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', + 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd ' + + 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ', + }; + default: + throw createVersionNotSupportedError(this.props.version); + } } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts index 12e616029d8..fe5d94e325b 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts @@ -23,7 +23,7 @@ export function checkCommonCartridgeVersion(version: CommonCartridgeVersion): vo throw createVersionNotSupportedError(version); } -export function checkForNullOrUndefined(value: T | undefined | null, name: string): T | never { +export function checkDefined(value: T | undefined | null, name: string): T | never { if (value) { return value; } From 1d3942d06447073b8525c936ce03145ed2a31bdc Mon Sep 17 00:00:00 2001 From: psachmann Date: Tue, 28 Nov 2023 15:09:43 +0100 Subject: [PATCH 018/177] EW-539 working on resources --- .../temp/common-cartridge.enums.ts | 6 +++ .../learnroom/common-cartridge/temp/index.ts | 1 + .../common-cartridge-lti-resource.spec.ts | 45 +++++++++---------- .../common-cartridge-lti-resource.ts | 12 ++--- .../common-cartridge-resource-factory.ts | 31 +++++++++++++ ...mon-cartridge-web-content-resource.spec.ts | 8 ++-- .../common-cartridge-web-content-resource.ts | 12 ++--- ...common-cartridge-web-link-resource.spec.ts | 20 ++++----- .../common-cartridge-web-link-resource.ts | 16 +++---- .../learnroom/common-cartridge/temp/utils.ts | 7 +++ 10 files changed, 98 insertions(+), 60 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts index 1c33faba8fb..699c90ee806 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts @@ -6,6 +6,12 @@ export enum CommonCartridgeVersion { V_1_4 = '1.4.0', } +export enum CCResourceType { + LTI = 'lti', + WEB_CONTENT = 'webcontent', + WEB_LINK = 'weblink', +} + export enum CommonCartridgeResourceType { LTI = 'imsbasiclti_xmlv1p0', WEB_CONTENT = 'webcontent', diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts index ad48a87feb6..02c89a2b2d3 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts @@ -1,2 +1,3 @@ export * from './builders/common-cartridge-file-builder'; +export * from './resources/common-cartridge-resource-factory'; export * from './common-cartridge.enums'; diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts index 1dda7effe77..fdc9a4b7ea8 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts @@ -1,10 +1,9 @@ -import { Builder } from 'xml2js'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeLtiResource, ICommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; +import { CCResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeLtiResource, CommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; describe('CommonCartridgeLtiResource', () => { - const propsVersion1: ICommonCartridgeLtiResourceProps = { - type: CommonCartridgeResourceType.LTI, + const propsVersion1: CommonCartridgeLtiResourceProps = { + type: CCResourceType.LTI, version: CommonCartridgeVersion.V_1_1, identifier: 'lti-identifier-version1', href: 'lti-identifier-version1/lti.xml', @@ -13,8 +12,8 @@ describe('CommonCartridgeLtiResource', () => { url: 'https://to-a-lti-tool-version1.tld', }; - const propsVersion3: ICommonCartridgeLtiResourceProps = { - type: CommonCartridgeResourceType.LTI, + const propsVersion3: CommonCartridgeLtiResourceProps = { + type: CCResourceType.LTI, version: CommonCartridgeVersion.V_1_3, identifier: 'lti-identifier-version3', href: 'lti-identifier-version3/lti.xml', @@ -23,23 +22,23 @@ describe('CommonCartridgeLtiResource', () => { url: 'https://to-a-lti-tool-version3.tld', }; - const ltiResourceVersion1 = new CommonCartridgeLtiResource(propsVersion1, new Builder()); - const ltiResourceVersion3 = new CommonCartridgeLtiResource(propsVersion3, new Builder()); + const ltiResourceVersion1 = new CommonCartridgeLtiResource(propsVersion1); + const ltiResourceVersion3 = new CommonCartridgeLtiResource(propsVersion3); describe('content', () => { describe('When Common Cartridge version 1.1', () => { it('should return correct content for version 1.1', () => { const expectedContent = ` - lti-title-version1 @@ -60,12 +59,12 @@ describe('CommonCartridgeLtiResource', () => { describe('When Common Cartridge version 1.3', () => { it('should return correct content for version 1.3', () => { const expectedContent = ` - { @@ -95,4 +61,35 @@ export class CommonCartridgeLtiResource implements CommonCartridgeResource { }, }; } + + private getXmlNamespacesByVersion(): Record { + switch (this.props.version) { + case CommonCartridgeVersion.V_1_1: + return { + xmlns: '/xsd/imslticc_v1p0', + 'xmlns:blti': '/xsd/imsbasiclti_v1p0', + 'xmlns:lticm': '/xsd/imslticm_v1p0', + 'xmlns:lticp': '/xsd/imslticp_v1p0', + 'xsi:schemaLocation': + '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd' + + '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd' + + '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd' + + '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd"', + }; + case CommonCartridgeVersion.V_1_3: + return { + xmlns: 'http://www.imsglobal.org/xsd/imslticc_v1p3', + 'xmlns:blti': 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0', + 'xmlns:lticm': 'http://www.imsglobal.org/xsd/imslticm_v1p0', + 'xmlns:lticp': 'http://www.imsglobal.org/xsd/imslticp_v1p0', + 'xsi:schemaLocation': + 'http://www.imsglobal.org/xsd/imslticc_v1p3 http://www.imsglobal.org/xsd/imslticc_v1p3.xsd' + + 'http://www.imsglobal.org/xsd/imslticp_v1p0 imslticp_v1p0.xsd' + + 'http://www.imsglobal.org/xsd/imslticm_v1p0 imslticm_v1p0.xsd' + + 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0 imsbasiclti_v1p0p1.xsd"', + }; + default: + throw createVersionNotSupportedError(this.props.version); + } + } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.ts index 848688668ed..1ac01ed39cc 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.ts @@ -1,4 +1,4 @@ -import { CCResourceType } from '../common-cartridge.enums'; +import { CommonCartridgeResourceType } from '../common-cartridge.enums'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { CommonCartridgeLtiResource, CommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; import { @@ -18,11 +18,11 @@ type CommonCartridgeResourceProps = export class CommonCartridgeResourceFactory { static createResource(props: CommonCartridgeResourceProps): CommonCartridgeResource { switch (props.type) { - case CCResourceType.LTI: + case CommonCartridgeResourceType.LTI: return new CommonCartridgeLtiResource(props); - case CCResourceType.WEB_CONTENT: + case CommonCartridgeResourceType.WEB_CONTENT: return new CommonCartridgeWebContentResource(props); - case CCResourceType.WEB_LINK: + case CommonCartridgeResourceType.WEB_LINK: return new CommonCartridgeWebLinkResource(props); default: throw new Error(`Unknown Common Cartridge resource type`); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts index e09584fa95c..7a1bb78f601 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts @@ -1,4 +1,4 @@ -import { CCResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeWebContentResource, CommonCartridgeWebContentResourceProps, @@ -6,7 +6,7 @@ import { describe('CommonCartridgeWebContentResource', () => { const props: CommonCartridgeWebContentResourceProps = { - type: CCResourceType.WEB_CONTENT, + type: CommonCartridgeResourceType.WEB_CONTENT, version: CommonCartridgeVersion.V_1_3, identifier: 'web-link', href: 'https://example.com/link', diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts index 22f22febd6d..c69b084e976 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts @@ -1,8 +1,12 @@ -import { CCResourceType, CommonCartridgeIntendedUseType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { + CommonCartridgeResourceType, + CommonCartridgeIntendedUseType, + CommonCartridgeVersion, +} from '../common-cartridge.enums'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; export type CommonCartridgeWebContentResourceProps = { - type: CCResourceType.WEB_CONTENT; + type: CommonCartridgeResourceType.WEB_CONTENT; version: CommonCartridgeVersion; identifier: string; href: string; diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts index 0589a240e4a..a7ede99c8bc 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts @@ -1,4 +1,4 @@ -import { CCResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeWebLinkResource, CommonCartridgeWebLinkResourceProps, @@ -6,7 +6,7 @@ import { describe('CommonCartridgeWebLinkResourceElement', () => { const propsOfV3: CommonCartridgeWebLinkResourceProps = { - type: CCResourceType.WEB_LINK, + type: CommonCartridgeResourceType.WEB_LINK, version: CommonCartridgeVersion.V_1_3, identifier: 'web-link-v3', href: 'https://example.com/linkv3', @@ -14,7 +14,7 @@ describe('CommonCartridgeWebLinkResourceElement', () => { url: 'https://example.com/linkv3', }; const propsOfV1: CommonCartridgeWebLinkResourceProps = { - type: CCResourceType.WEB_LINK, + type: CommonCartridgeResourceType.WEB_LINK, version: CommonCartridgeVersion.V_1_1, identifier: 'web-link-v1', href: 'https://example.com/link1', diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts index 88fb3edca49..a6e1c1dce5d 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts @@ -1,9 +1,9 @@ -import { CCResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { buildXmlString } from '../utils'; +import { buildXmlString, createVersionNotSupportedError } from '../utils'; export type CommonCartridgeWebLinkResourceProps = { - type: CCResourceType.WEB_LINK; + type: CommonCartridgeResourceType.WEB_LINK; version: CommonCartridgeVersion; identifier: string; href: string; @@ -24,7 +24,8 @@ export class CommonCartridgeWebLinkResource implements CommonCartridgeResource { } getFileContent(): string { - const commonTags = { + return buildXmlString({ + $: this.getXmlNamespacesByVersion(), title: this.props.title, url: { $: { @@ -33,33 +34,7 @@ export class CommonCartridgeWebLinkResource implements CommonCartridgeResource { windowFeatures: 'width=100, height=100', }, }, - }; - switch (this.props.version) { - case CommonCartridgeVersion.V_1_3: - return buildXmlString({ - webLink: { - ...commonTags, - $: { - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd', - }, - }, - }); - default: - return buildXmlString({ - webLink: { - ...commonTags, - $: { - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', - }, - }, - }); - } + }); } getManifestXml(): Record { @@ -75,4 +50,25 @@ export class CommonCartridgeWebLinkResource implements CommonCartridgeResource { }, }; } + + private getXmlNamespacesByVersion(): Record { + switch (this.props.version) { + case CommonCartridgeVersion.V_1_1: + return { + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': + 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', + }; + case CommonCartridgeVersion.V_1_3: + return { + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': + 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd', + }; + default: + throw createVersionNotSupportedError(this.props.version); + } + } } From da8eb6007a3ecda8ecfcd3d52deddfefb4563117 Mon Sep 17 00:00:00 2001 From: psachmann Date: Tue, 28 Nov 2023 16:16:46 +0100 Subject: [PATCH 020/177] EW-539 working on file builder --- .../common-cartridge-file-builder.spec.ts | 12 ++++ .../common-cartridge-manifest-builder.ts | 62 +++++-------------- .../common-cartridge-organization-builder.ts | 31 +++------- .../common-cartridge-element.interface.ts | 2 +- .../common-cartridge-manifest-resource.ts | 2 +- .../common-cartridge-organization-resource.ts | 21 +++++++ 6 files changed, 61 insertions(+), 69 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-organization-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts index 09cde64c319..61c5cb83d54 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts @@ -42,6 +42,18 @@ describe('CommonCartridgeFileBuilder', () => { expect(manifest).toContain(''); expect(manifest).toContain(''); }); + + it('foobar', () => { + // const builder = new CommonCartridgeFileBuilder(CommonCartridgeVersion.V_1_1); + // const metadataBuilder = builder.withMetadata(); + // metadataBuilder + // .setTitle('test-title') + // .setCopyrightOwners(['PS', 'SR']) + // .setCreationDate(new Date('2021-01-01')); + // const organization1Builder = builder.withOrganization(); + // const organization2Builder = builder.withOrganization(); + // organization1Builder.addOrganization() + }); }); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts index 81093ee09cc..7d8a2127e37 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts @@ -2,55 +2,27 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { CommonCartridgeManifestResource } from '../resources/common-cartridge-manifest-resource'; -import { checkDefined } from '../utils'; -export class CommonCartridgeManifestBuilder { - private identifier?: string; - - private metadata?: CommonCartridgeElement; - - private organizations?: CommonCartridgeElement[]; - - private resources?: CommonCartridgeResource[]; - - constructor(private readonly version: CommonCartridgeVersion) {} +type CommonCartridgeManifestBuilderProps = { + version: CommonCartridgeVersion; + identifier: string; + metadata: CommonCartridgeElement; + organizations: CommonCartridgeElement[]; + resources: CommonCartridgeResource[]; +}; - setIdentifier(identifier: string): CommonCartridgeManifestBuilder { - this.identifier = identifier; - - return this; - } - - setMetadata(metadata: CommonCartridgeElement): CommonCartridgeManifestBuilder { - this.metadata = metadata; - - return this; - } - - setOrganizations(organizations: CommonCartridgeElement[]): CommonCartridgeManifestBuilder { - this.organizations = organizations; - - return this; - } - - setResources(resources: CommonCartridgeResource[]): CommonCartridgeManifestBuilder { - this.resources = resources; - - return this; - } +export class CommonCartridgeManifestBuilder { + constructor(private readonly props: CommonCartridgeManifestBuilderProps) {} build(): CommonCartridgeResource { - const identifier = checkDefined(this.identifier, 'Identifier'); - const metadata = checkDefined(this.metadata, 'Metadata'); - const organizations = checkDefined(this.organizations, 'Organizations'); - const resources = checkDefined(this.resources, 'Resources'); - - return new CommonCartridgeManifestResource({ - version: this.version, - identifier, - metadata, - organizations, - resources, + const manifestResource = new CommonCartridgeManifestResource({ + version: this.props.version, + identifier: this.props.identifier, + metadata: this.props.metadata, + organizations: this.props.organizations, + resources: this.props.resources, }); + + return manifestResource; } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts index 5b36389e77f..2ef269fc515 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts @@ -1,35 +1,22 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { checkDefined } from '../utils'; -export class CommonCartridgeOrganizationBuilder { - private title?: string; - - private identifier?: string; +type CommonCartridgeOrganizationProps = { + version: CommonCartridgeVersion; + title: string; + identifier: string; +}; +export class CommonCartridgeOrganizationBuilder { private items: CommonCartridgeResource[] = []; private children: CommonCartridgeElement[] = []; - constructor(private readonly version: CommonCartridgeVersion, private readonly parent?: CommonCartridgeElement) {} - - setIdentifier(identifier: string): CommonCartridgeOrganizationBuilder { - this.identifier = identifier; - - return this; - } - - setTitle(title: string): CommonCartridgeOrganizationBuilder { - this.title = title; - - return this; - } - - addOrganization(organization: CommonCartridgeElement): CommonCartridgeOrganizationBuilder { - this.items.push(organization); + constructor(private readonly props: CommonCartridgeOrganizationProps) {} - return new CommonCartridgeOrganizationBuilder(this.version); + addOrganization(props: CommonCartridgeOrganizationProps): CommonCartridgeOrganizationBuilder { + return new CommonCartridgeOrganizationBuilder(props); } addOrganizationItem(item: CommonCartridgeResource): CommonCartridgeOrganizationBuilder { diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts index 9ec6eca68de..6b38658c162 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts @@ -6,5 +6,5 @@ export interface CommonCartridgeElement { * This method is used to build the imsmanifest.xml file. * @returns The XML object representation for the imsmanifest.xml file. */ - getManifestXml(): Record | undefined; + getManifestXml(): Record; } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts index d6f15020839..5b5af84844a 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts @@ -31,7 +31,7 @@ export class CommonCartridgeManifestResource implements CommonCartridgeResource return this.xmlBuilder.buildObject(this.getManifestXml()); } - getManifestXml(): Record | undefined { + getManifestXml(): Record { return { manifest: { $: this.getXmlNamespacesByVersion(), diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-organization-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-organization-resource.ts new file mode 100644 index 00000000000..476197dfbab --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-organization-resource.ts @@ -0,0 +1,21 @@ +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; + +type CommonCartridgeOrganizationElementProps = { + identifier: string; + title: string; + items: CommonCartridgeElement[]; +}; + +export class CommonCartridgeOrganizationElement implements CommonCartridgeElement { + constructor(private readonly props: CommonCartridgeOrganizationElementProps) {} + + getManifestXml(): Record { + return { + $: { + identifier: this.props.identifier, + }, + title: this.props.title, + item: this.props.items.map((item) => item.getManifestXml()), + }; + } +} From 873bba12e4d2323c4321d38dd54d676171b9bd91 Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 29 Nov 2023 09:31:40 +0100 Subject: [PATCH 021/177] EW-539 cleaning up code --- .../builders/common-cartridge-file-builder.ts | 59 +++++++++++-------- .../common-cartridge-manifest-builder.ts | 28 --------- .../common-cartridge-metadata-builder.ts | 40 ------------- .../common-cartridge-organization-builder.ts | 25 +++++--- .../common-cartridge-metadata-element.ts | 5 +- 5 files changed, 54 insertions(+), 103 deletions(-) delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts index 84172b00981..91fcf7bc114 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts @@ -1,39 +1,45 @@ import AdmZip from 'adm-zip'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeMetadataBuilder } from './common-cartridge-metadata-builder'; -import { CommonCartridgeOrganizationBuilder } from './common-cartridge-organization-builder'; -import { CommonCartridgeManifestBuilder } from './common-cartridge-manifest-builder'; +import { + CommonCartridgeOrganizationBuilder, + CommonCartridgeOrganizationBuilderOptions, +} from './common-cartridge-organization-builder'; import { checkCommonCartridgeVersion, isCommonCartridgeResource, checkDefined } from '../utils'; +import { CommonCartridgeManifestResource } from '../resources/common-cartridge-manifest-resource'; +import { + CommonCartridgeMetadataElement, + CommonCartridgeMetadataElementProps, +} from '../elements/common-cartridge-metadata-element'; +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; + +export type CommonCartridgeFileBuilderProps = { + version: CommonCartridgeVersion; + identifier: string; +}; export class CommonCartridgeFileBuilder { - private identifier?: string; + private readonly archive: AdmZip = new AdmZip(); - private readonly archive: AdmZip; - - private readonly metadataBuilder: CommonCartridgeMetadataBuilder; + private metadata?: CommonCartridgeElement; private readonly organizationBuilders: CommonCartridgeOrganizationBuilder[]; - constructor(private readonly version: CommonCartridgeVersion) { - checkCommonCartridgeVersion(version); + constructor(private readonly props: CommonCartridgeFileBuilderProps) { + checkCommonCartridgeVersion(props.version); - this.archive = new AdmZip(); - this.metadataBuilder = new CommonCartridgeMetadataBuilder(version); this.organizationBuilders = []; } - setIdentifier(identifier: string): CommonCartridgeFileBuilder { - this.identifier = identifier; + withMetadata(props: Omit): CommonCartridgeFileBuilder { + this.metadata = new CommonCartridgeMetadataElement({ ...props, version: this.props.version }); return this; } - withMetadata(): CommonCartridgeMetadataBuilder { - return this.metadataBuilder; - } - - withOrganization(): CommonCartridgeOrganizationBuilder { - const builder = new CommonCartridgeOrganizationBuilder(this.version); + withOrganization( + props: Omit + ): CommonCartridgeOrganizationBuilder { + const builder = new CommonCartridgeOrganizationBuilder({ ...props, version: this.props.version }); this.organizationBuilders.push(builder); @@ -41,14 +47,15 @@ export class CommonCartridgeFileBuilder { } build(): Promise { - const identifier = checkDefined(this.identifier, 'Identifier'); - const metadata = this.metadataBuilder.build(); + const metadata = checkDefined(this.metadata, 'metadata'); const organizations = this.organizationBuilders.map((builder) => builder.build()); - const manifest = new CommonCartridgeManifestBuilder(this.version) - .setIdentifier(identifier) - .setMetadata(metadata) - .setOrganizations(organizations) - .build(); + const manifest = new CommonCartridgeManifestResource({ + version: this.props.version, + identifier: this.props.identifier, + metadata, + organizations, + resources: [], // TODO: add resources + }); for (const organization of organizations) { if (isCommonCartridgeResource(organization) && !organization.canInline()) { diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts deleted file mode 100644 index 7d8a2127e37..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-manifest-builder.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { CommonCartridgeManifestResource } from '../resources/common-cartridge-manifest-resource'; - -type CommonCartridgeManifestBuilderProps = { - version: CommonCartridgeVersion; - identifier: string; - metadata: CommonCartridgeElement; - organizations: CommonCartridgeElement[]; - resources: CommonCartridgeResource[]; -}; - -export class CommonCartridgeManifestBuilder { - constructor(private readonly props: CommonCartridgeManifestBuilderProps) {} - - build(): CommonCartridgeResource { - const manifestResource = new CommonCartridgeManifestResource({ - version: this.props.version, - identifier: this.props.identifier, - metadata: this.props.metadata, - organizations: this.props.organizations, - resources: this.props.resources, - }); - - return manifestResource; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts deleted file mode 100644 index 40943c0a2c9..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-metadata-builder.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeMetadataElement } from '../elements/common-cartridge-metadata-element'; -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; - -export class CommonCartridgeMetadataBuilder { - private title = ''; - - private copyrightOwners: string[] = []; - - private creationDate: Date = new Date(); - - constructor(private readonly version: CommonCartridgeVersion) {} - - setTitle(title: string): CommonCartridgeMetadataBuilder { - this.title = title; - - return this; - } - - setCopyrightOwners(copyrightOwners: string[]): CommonCartridgeMetadataBuilder { - this.copyrightOwners = copyrightOwners; - - return this; - } - - setCreationDate(creationDate: Date): CommonCartridgeMetadataBuilder { - this.creationDate = creationDate; - - return this; - } - - build(): CommonCartridgeElement { - return new CommonCartridgeMetadataElement({ - version: this.version, - title: this.title, - copyrightOwners: this.copyrightOwners, - creationDate: this.creationDate, - }); - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts index 2ef269fc515..d0caa0358df 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts @@ -2,21 +2,32 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -type CommonCartridgeOrganizationProps = { +export type CommonCartridgeOrganizationBuilderOptions = { version: CommonCartridgeVersion; title: string; identifier: string; }; export class CommonCartridgeOrganizationBuilder { - private items: CommonCartridgeResource[] = []; + private readonly items = new Array(); - private children: CommonCartridgeElement[] = []; + private readonly children = new Array(); - constructor(private readonly props: CommonCartridgeOrganizationProps) {} + constructor( + protected readonly options: CommonCartridgeOrganizationBuilderOptions, + private readonly parent?: CommonCartridgeOrganizationBuilder + ) {} - addOrganization(props: CommonCartridgeOrganizationProps): CommonCartridgeOrganizationBuilder { - return new CommonCartridgeOrganizationBuilder(props); + public get resources(): CommonCartridgeResource[] { + return this.items; + } + + addOrganization(options: CommonCartridgeOrganizationBuilderOptions): CommonCartridgeOrganizationBuilder { + const child = new CommonCartridgeOrganizationBuilder(options, this); + + this.children.push(child); + + return child; } addOrganizationItem(item: CommonCartridgeResource): CommonCartridgeOrganizationBuilder { @@ -25,7 +36,7 @@ export class CommonCartridgeOrganizationBuilder { return this; } - build(): CommonCartridgeResource { + build(): CommonCartridgeElement { // const title = isDefined(this.title, 'Title'); // const identifier = isDefined(this.identifier, 'Identifier'); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts index 3e42fe0c242..02f23c422b4 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts @@ -1,7 +1,8 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; -type CommonCartridgeMetadataElementProps = { - version: string; +export type CommonCartridgeMetadataElementProps = { + version: CommonCartridgeVersion; title: string; creationDate: Date; copyrightOwners: string[]; From 01bab92aa84b298bc3df033ac61722597ba6e087 Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 29 Nov 2023 09:49:00 +0100 Subject: [PATCH 022/177] EW-539 updating cc file builder tests --- .../common-cartridge-file-builder.spec.ts | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts index 61c5cb83d54..3c3bc923bab 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts @@ -19,7 +19,7 @@ describe('CommonCartridgeFileBuilder', () => { }); describe('build', () => { - describe('when using version 1.1', () => { + describe('when using version 1.1.0', () => { it('should create imsmanifest.xml in archive root', async () => { const archive = new AdmZip(await sut.build()); const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); @@ -27,6 +27,14 @@ describe('CommonCartridgeFileBuilder', () => { expect(manifest).toBeDefined(); }); + it('should create manifest section in imsmanifest.xml', async () => { + const archive = new AdmZip(await sut.build()); + const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); + + expect(manifest).toContain(''); + expect(manifest).toContain(''); + }); + it('should create metadata section in imsmanifest.xml', async () => { const archive = new AdmZip(await sut.build()); const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); @@ -43,16 +51,12 @@ describe('CommonCartridgeFileBuilder', () => { expect(manifest).toContain(''); }); - it('foobar', () => { - // const builder = new CommonCartridgeFileBuilder(CommonCartridgeVersion.V_1_1); - // const metadataBuilder = builder.withMetadata(); - // metadataBuilder - // .setTitle('test-title') - // .setCopyrightOwners(['PS', 'SR']) - // .setCreationDate(new Date('2021-01-01')); - // const organization1Builder = builder.withOrganization(); - // const organization2Builder = builder.withOrganization(); - // organization1Builder.addOrganization() + it('should create resources section in imsmanifest.xml', async () => { + const archive = new AdmZip(await sut.build()); + const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); + + expect(manifest).toContain(''); + expect(manifest).toContain(''); }); }); }); From d9f54e9da04628dd8cf16877ee01a4054a640618 Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 29 Nov 2023 14:12:23 +0100 Subject: [PATCH 023/177] EW-539 creating sub organizations is now possible --- .../common-cartridge-file-builder.spec.ts | 113 ++++++++++++------ .../builders/common-cartridge-file-builder.ts | 44 ++++--- .../common-cartridge-organization-builder.ts | 47 ++++++-- .../common-cartridge-lti-resource.spec.ts | 8 +- .../common-cartridge-lti-resource.ts | 6 +- .../common-cartridge-resource-factory.ts | 10 +- ...mon-cartridge-web-content-resource.spec.ts | 4 +- .../common-cartridge-web-content-resource.ts | 9 +- ...common-cartridge-web-link-resource.spec.ts | 8 +- .../common-cartridge-web-link-resource.ts | 7 +- .../learnroom/common-cartridge/temp/utils.ts | 40 +------ 11 files changed, 166 insertions(+), 130 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts index 3c3bc923bab..f597f5b1b0a 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts @@ -1,62 +1,99 @@ import AdmZip from 'adm-zip'; -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeFileBuilder } from './common-cartridge-file-builder'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeMetadataElementProps } from '../elements/common-cartridge-metadata-element'; +import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; +import { CommonCartridgeFileBuilder, CommonCartridgeFileBuilderProps } from './common-cartridge-file-builder'; +import { CommonCartridgeOrganizationBuilderOptions } from './common-cartridge-organization-builder'; describe('CommonCartridgeFileBuilder', () => { let sut: CommonCartridgeFileBuilder; + let archive: AdmZip; - const getFileContentAsString = (archive: AdmZip, path: string): string | undefined => - archive.getEntry(path)?.getData().toString(); - - beforeAll(() => { - sut = new CommonCartridgeFileBuilder({ - version: CommonCartridgeVersion.V_1_1, - }); - }); - - it('should be defined', () => { - expect(sut).toBeDefined(); - }); + const getFileContentAsString = (zip: AdmZip, path: string): string | undefined => + zip.getEntry(path)?.getData().toString(); + const fileBuilderOptions: CommonCartridgeFileBuilderProps = { + version: CommonCartridgeVersion.V_1_1, + identifier: 'manifest-identifier', + }; + const metadataProps: Omit = { + title: 'metadata-title', + creationDate: new Date(), + copyrightOwners: ['John Doe', 'Jane Doe'], + }; + const organizationProps: Omit = { + title: 'organization-title', + identifier: 'organization-identifier', + }; + const subOrganizationProps: Omit = { + title: 'sub-organization-title', + identifier: 'sub-organization-identifier', + }; + const subSubOrganizationProps: Omit = { + title: 'sub-sub-organization-title', + identifier: 'sub-sub-organization-identifier', + }; + const resource1: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: 'resource-1-identifier', + title: 'resource-1-title', + html: '

resource-1-html

', + }; + const resource2: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: 'resource-2-identifier', + title: 'resource-2-title', + html: '

resource-2-html

', + }; + const resource3: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: 'resource-3-identifier', + title: 'resource-3-title', + html: '

resource-3-html

', + }; describe('build', () => { - describe('when using version 1.1.0', () => { - it('should create imsmanifest.xml in archive root', async () => { - const archive = new AdmZip(await sut.build()); - const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); + describe('when creating a common cartridge archive', () => { + beforeAll(async () => { + sut = new CommonCartridgeFileBuilder(fileBuilderOptions); + sut.addMetadata(metadataProps) + .addOrganization(organizationProps) + .addResource(resource1) + .addSubOrganization(subOrganizationProps) + .addResource(resource2) + .addSubOrganization(subSubOrganizationProps) + .addResource(resource3); - expect(manifest).toBeDefined(); + archive = new AdmZip(await sut.build()); }); - it('should create manifest section in imsmanifest.xml', async () => { - const archive = new AdmZip(await sut.build()); + it('should create imsmanifest.xml in archive root', () => { const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); - expect(manifest).toContain(''); - expect(manifest).toContain(''); + expect(manifest).toBeDefined(); }); - it('should create metadata section in imsmanifest.xml', async () => { - const archive = new AdmZip(await sut.build()); - const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); + it('should create resource in organization folder', () => { + const resource = getFileContentAsString(archive, 'organization-identifier/resource-1-identifier.html'); - expect(manifest).toContain(''); - expect(manifest).toContain(''); + expect(resource).toBeDefined(); }); - it('should create organization section in imsmanifest.xml', async () => { - const archive = new AdmZip(await sut.build()); - const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); + it('should create resource in sub-organization folder', () => { + const resource = getFileContentAsString( + archive, + 'organization-identifier/sub-organization-identifier/resource-2-identifier.html' + ); - expect(manifest).toContain(''); - expect(manifest).toContain(''); + expect(resource).toBeDefined(); }); - it('should create resources section in imsmanifest.xml', async () => { - const archive = new AdmZip(await sut.build()); - const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); + it('should create resource in sub-sub-organization folder', () => { + const resource = getFileContentAsString( + archive, + 'organization-identifier/sub-organization-identifier/sub-sub-organization-identifier/resource-3-identifier.html' + ); - expect(manifest).toContain(''); - expect(manifest).toContain(''); + expect(resource).toBeDefined(); }); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts index 91fcf7bc114..33bc8b1c748 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts @@ -1,16 +1,17 @@ import AdmZip from 'adm-zip'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { - CommonCartridgeOrganizationBuilder, - CommonCartridgeOrganizationBuilderOptions, -} from './common-cartridge-organization-builder'; -import { checkCommonCartridgeVersion, isCommonCartridgeResource, checkDefined } from '../utils'; -import { CommonCartridgeManifestResource } from '../resources/common-cartridge-manifest-resource'; import { CommonCartridgeMetadataElement, CommonCartridgeMetadataElementProps, } from '../elements/common-cartridge-metadata-element'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeManifestResource } from '../resources/common-cartridge-manifest-resource'; +import { OmitVersion, checkCommonCartridgeVersion, checkDefined } from '../utils'; +import { + CommonCartridgeOrganizationBuilder, + CommonCartridgeOrganizationBuilderOptions, +} from './common-cartridge-organization-builder'; export type CommonCartridgeFileBuilderProps = { version: CommonCartridgeVersion; @@ -20,26 +21,27 @@ export type CommonCartridgeFileBuilderProps = { export class CommonCartridgeFileBuilder { private readonly archive: AdmZip = new AdmZip(); - private metadata?: CommonCartridgeElement; + private readonly organizationBuilders = new Array(); + + private readonly resources = new Array(); - private readonly organizationBuilders: CommonCartridgeOrganizationBuilder[]; + private metadata?: CommonCartridgeElement; constructor(private readonly props: CommonCartridgeFileBuilderProps) { checkCommonCartridgeVersion(props.version); - - this.organizationBuilders = []; } - withMetadata(props: Omit): CommonCartridgeFileBuilder { + addMetadata(props: OmitVersion): CommonCartridgeFileBuilder { this.metadata = new CommonCartridgeMetadataElement({ ...props, version: this.props.version }); return this; } - withOrganization( - props: Omit - ): CommonCartridgeOrganizationBuilder { - const builder = new CommonCartridgeOrganizationBuilder({ ...props, version: this.props.version }); + addOrganization(props: OmitVersion): CommonCartridgeOrganizationBuilder { + const builder = new CommonCartridgeOrganizationBuilder( + { ...props, version: this.props.version }, + this.addResource.bind(this) + ); this.organizationBuilders.push(builder); @@ -54,12 +56,12 @@ export class CommonCartridgeFileBuilder { identifier: this.props.identifier, metadata, organizations, - resources: [], // TODO: add resources + resources: this.resources, }); - for (const organization of organizations) { - if (isCommonCartridgeResource(organization) && !organization.canInline()) { - this.archive.addFile(organization.getFilePath(), Buffer.from(organization.getFileContent())); + for (const resources of this.resources) { + if (!resources.canInline()) { + this.archive.addFile(resources.getFilePath(), Buffer.from(resources.getFileContent())); } } @@ -67,4 +69,8 @@ export class CommonCartridgeFileBuilder { return this.archive.toBufferPromise(); } + + private addResource(resource: CommonCartridgeResource): void { + this.resources.push(resource); + } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts index d0caa0358df..10706e7dc83 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts @@ -1,45 +1,66 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeOrganizationElement } from '../resources/common-cartridge-organization-resource'; +import { + CommonCartridgeResourceFactory, + CommonCartridgeResourceProps, +} from '../resources/common-cartridge-resource-factory'; export type CommonCartridgeOrganizationBuilderOptions = { version: CommonCartridgeVersion; - title: string; identifier: string; + title: string; + parentFolder?: string; }; export class CommonCartridgeOrganizationBuilder { - private readonly items = new Array(); + private readonly items = new Array(); private readonly children = new Array(); constructor( protected readonly options: CommonCartridgeOrganizationBuilderOptions, - private readonly parent?: CommonCartridgeOrganizationBuilder + private readonly addResourceToFileBuilder: (resource: CommonCartridgeResource) => void ) {} - public get resources(): CommonCartridgeResource[] { - return this.items; + private get folder(): string { + return this.options.parentFolder + ? `${this.options.parentFolder}/${this.options.identifier}` + : this.options.identifier; } - addOrganization(options: CommonCartridgeOrganizationBuilderOptions): CommonCartridgeOrganizationBuilder { - const child = new CommonCartridgeOrganizationBuilder(options, this); + addSubOrganization( + options: Omit + ): CommonCartridgeOrganizationBuilder { + const child = new CommonCartridgeOrganizationBuilder( + { ...options, version: this.options.version, parentFolder: this.folder }, + this.addResourceToFileBuilder.bind(this) + ); this.children.push(child); return child; } - addOrganizationItem(item: CommonCartridgeResource): CommonCartridgeOrganizationBuilder { - this.items.push(item); + addResource(props: CommonCartridgeResourceProps): CommonCartridgeOrganizationBuilder { + const resource = CommonCartridgeResourceFactory.create({ + ...props, + version: this.options.version, + folder: this.folder, + }); + + this.items.push(resource); + this.addResourceToFileBuilder(resource); return this; } build(): CommonCartridgeElement { - // const title = isDefined(this.title, 'Title'); - // const identifier = isDefined(this.identifier, 'Identifier'); - - throw new Error('Not implemented'); + return new CommonCartridgeOrganizationElement({ + identifier: this.options.identifier, + title: this.options.title, + items: this.items, + }); } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts index ec28daed256..773db4637d6 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts @@ -6,7 +6,7 @@ describe('CommonCartridgeLtiResource', () => { type: CommonCartridgeResourceType.LTI, version: CommonCartridgeVersion.V_1_1, identifier: 'lti-identifier-version1', - href: 'lti-identifier-version1/lti.xml', + folder: 'lti-identifier-version1/lti.xml', title: 'lti-title-version1', description: 'lti-description-version1', url: 'https://to-a-lti-tool-version1.tld', @@ -16,7 +16,7 @@ describe('CommonCartridgeLtiResource', () => { type: CommonCartridgeResourceType.LTI, version: CommonCartridgeVersion.V_1_3, identifier: 'lti-identifier-version3', - href: 'lti-identifier-version3/lti.xml', + folder: 'lti-identifier-version3/lti.xml', title: 'lti-title-version3', description: 'lti-description-version3', url: 'https://to-a-lti-tool-version3.tld', @@ -97,7 +97,7 @@ describe('CommonCartridgeLtiResource', () => { }, file: { $: { - href: propsVersion1.href, + href: propsVersion1.folder, }, }, }; @@ -115,7 +115,7 @@ describe('CommonCartridgeLtiResource', () => { }, file: { $: { - href: propsVersion3.href, + href: propsVersion3.folder, }, }, }; diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts index 4712238f13a..fa5396c17e5 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts @@ -6,7 +6,7 @@ export type CommonCartridgeLtiResourceProps = { type: CommonCartridgeResourceType.LTI; version: CommonCartridgeVersion; identifier: string; - href: string; + folder: string; title: string; description?: string; url: string; @@ -21,7 +21,7 @@ export class CommonCartridgeLtiResource implements CommonCartridgeResource { // TODO: This is not correct. The href should be relative to the imsmanifest.xml file. getFilePath(): string { - return this.props.href; + return `${this.props.folder}/${this.props.identifier}.xml`; } getFileContent(): string { @@ -56,7 +56,7 @@ export class CommonCartridgeLtiResource implements CommonCartridgeResource { }, file: { $: { - href: this.props.href, + href: this.props.folder, }, }, }; diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.ts index 1ac01ed39cc..5a457249a57 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.ts @@ -1,5 +1,6 @@ import { CommonCartridgeResourceType } from '../common-cartridge.enums'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; +import { OmitVersionAndFolder } from '../utils'; import { CommonCartridgeLtiResource, CommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; import { CommonCartridgeWebContentResource, @@ -10,13 +11,18 @@ import { CommonCartridgeWebLinkResourceProps, } from './common-cartridge-web-link-resource'; -type CommonCartridgeResourceProps = +export type CommonCartridgeResourceProps = + | OmitVersionAndFolder + | OmitVersionAndFolder + | OmitVersionAndFolder; + +type CommonCartridgeResourcePropsInternal = | CommonCartridgeLtiResourceProps | CommonCartridgeWebContentResourceProps | CommonCartridgeWebLinkResourceProps; export class CommonCartridgeResourceFactory { - static createResource(props: CommonCartridgeResourceProps): CommonCartridgeResource { + static create(props: CommonCartridgeResourcePropsInternal): CommonCartridgeResource { switch (props.type) { case CommonCartridgeResourceType.LTI: return new CommonCartridgeLtiResource(props); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts index 7a1bb78f601..e8055fc4cfb 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts @@ -9,7 +9,7 @@ describe('CommonCartridgeWebContentResource', () => { type: CommonCartridgeResourceType.WEB_CONTENT, version: CommonCartridgeVersion.V_1_3, identifier: 'web-link', - href: 'https://example.com/link', + folder: 'https://example.com/link', title: 'Web Link', html: 'html tages for testing', }; @@ -37,7 +37,7 @@ describe('CommonCartridgeWebContentResource', () => { }, file: { $: { - href: props.href, + href: props.folder, }, }, }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts index c69b084e976..5d0f4364db7 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts @@ -1,6 +1,6 @@ import { - CommonCartridgeResourceType, CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, CommonCartridgeVersion, } from '../common-cartridge.enums'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; @@ -9,7 +9,7 @@ export type CommonCartridgeWebContentResourceProps = { type: CommonCartridgeResourceType.WEB_CONTENT; version: CommonCartridgeVersion; identifier: string; - href: string; + folder: string; title: string; html: string; intendedUse?: CommonCartridgeIntendedUseType; @@ -22,9 +22,8 @@ export class CommonCartridgeWebContentResource implements CommonCartridgeResourc return false; } - // TODO: This is not correct. The href should be relative to the imsmanifest.xml file. getFilePath(): string { - return this.props.href; + return `${this.props.folder}/${this.props.identifier}.html`; } getFileContent(): string { @@ -40,7 +39,7 @@ export class CommonCartridgeWebContentResource implements CommonCartridgeResourc }, file: { $: { - href: this.props.href, + href: this.props.folder, }, }, }; diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts index a7ede99c8bc..b95dc77bd67 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts @@ -9,7 +9,7 @@ describe('CommonCartridgeWebLinkResourceElement', () => { type: CommonCartridgeResourceType.WEB_LINK, version: CommonCartridgeVersion.V_1_3, identifier: 'web-link-v3', - href: 'https://example.com/linkv3', + folder: 'https://example.com/linkv3', title: 'Web Link v3', url: 'https://example.com/linkv3', }; @@ -17,7 +17,7 @@ describe('CommonCartridgeWebLinkResourceElement', () => { type: CommonCartridgeResourceType.WEB_LINK, version: CommonCartridgeVersion.V_1_1, identifier: 'web-link-v1', - href: 'https://example.com/link1', + folder: 'https://example.com/link1', title: 'Web Link v1', url: 'https://example.com/link1', }; @@ -39,7 +39,7 @@ describe('CommonCartridgeWebLinkResourceElement', () => { }, file: { $: { - href: propsOfV3.href, + href: propsOfV3.folder, }, }, }); @@ -66,7 +66,7 @@ describe('CommonCartridgeWebLinkResourceElement', () => { }, file: { $: { - href: propsOfV1.href, + href: propsOfV1.folder, }, }, }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts index a6e1c1dce5d..cb3c8c06534 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts @@ -6,7 +6,7 @@ export type CommonCartridgeWebLinkResourceProps = { type: CommonCartridgeResourceType.WEB_LINK; version: CommonCartridgeVersion; identifier: string; - href: string; + folder: string; title: string; url: string; }; @@ -18,9 +18,8 @@ export class CommonCartridgeWebLinkResource implements CommonCartridgeResource { return false; } - // TODO: This is not correct. The href should be relative to the imsmanifest.xml file. getFilePath(): string { - return this.props.href; + return `${this.props.folder}/${this.props.identifier}.xml`; } getFileContent(): string { @@ -45,7 +44,7 @@ export class CommonCartridgeWebLinkResource implements CommonCartridgeResource { }, file: { $: { - href: this.props.href, + href: this.props.folder, }, }, }; diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts index 302290d6515..55c144aedd1 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts @@ -1,8 +1,9 @@ -import { ObjectId } from 'bson'; import { Builder } from 'xml2js'; import { CommonCartridgeVersion } from './common-cartridge.enums'; -import { CommonCartridgeElement } from './interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from './interfaces/common-cartridge-resource.interface'; + +export type OmitVersion = Omit; + +export type OmitVersionAndFolder = Omit; const xmlBuilder = new Builder(); @@ -10,12 +11,6 @@ export function buildXmlString(obj: unknown): string { return xmlBuilder.buildObject(obj); } -export function createIdentifier(id?: string | ObjectId): string { - id = id ?? new ObjectId(); - - return `i${id.toString()}`; -} - export function createVersionNotSupportedError(version: CommonCartridgeVersion): Error { return new Error(`Version ${version} is not supported`); } @@ -37,30 +32,3 @@ export function checkDefined(value: T | undefined | null, name: string): T | throw new Error(`${name} is null or undefined`); } - -export function isCommonCartridgeElement(element: unknown): element is CommonCartridgeElement { - return ( - (element as CommonCartridgeElement).getManifestXml !== undefined && - typeof (element as CommonCartridgeElement).getManifestXml === 'function' - ); -} - -export function isCommonCartridgeElementArray(elements: unknown[]): elements is CommonCartridgeElement[] { - return elements.every((element) => isCommonCartridgeElement(element)); -} - -export function isCommonCartridgeResource(element: unknown): element is CommonCartridgeResource { - return ( - isCommonCartridgeElement(element) && - (element as CommonCartridgeResource).canInline !== undefined && - typeof (element as CommonCartridgeResource).canInline === 'function' && - (element as CommonCartridgeResource).getFilePath !== undefined && - typeof (element as CommonCartridgeResource).getFilePath === 'function' && - (element as CommonCartridgeResource).getFileContent !== undefined && - typeof (element as CommonCartridgeResource).getFileContent === 'function' - ); -} - -export function isCommonCartridgeResourceArray(elements: unknown[]): elements is CommonCartridgeResource[] { - return elements.every((element) => isCommonCartridgeResource(element)); -} From ee07405752740d29089050f63412866389ce0930 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 29 Nov 2023 15:20:18 +0100 Subject: [PATCH 024/177] EW-539 Adjust test structure for web link resources --- ...common-cartridge-web-link-resource.spec.ts | 121 ++++++++++++------ .../common-cartridge-web-link-resource.ts | 16 ++- 2 files changed, 91 insertions(+), 46 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts index b95dc77bd67..867610f8b25 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts @@ -4,7 +4,7 @@ import { CommonCartridgeWebLinkResourceProps, } from './common-cartridge-web-link-resource'; -describe('CommonCartridgeWebLinkResourceElement', () => { +describe('CommonCartridgeWebLinkResource', () => { const propsOfV3: CommonCartridgeWebLinkResourceProps = { type: CommonCartridgeResourceType.WEB_LINK, version: CommonCartridgeVersion.V_1_3, @@ -22,53 +22,96 @@ describe('CommonCartridgeWebLinkResourceElement', () => { url: 'https://example.com/link1', }; - describe('CommonCartridgeWebLinkResourceElement of version 3', () => { - it('should return XML content of common cartridge version 3', () => { - const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV3); - const content = webLinkResource.getFileContent(); - const transformed = webLinkResource.getManifestXml(); + describe('canInline', () => { + describe('when version is 1.3', () => { + it('should return false', () => { + const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV3); + expect(webLinkResource.canInline()).toBe(false); + }); + }); + describe('when version is 1.1', () => { + it('should return false', () => { + const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV1); + expect(webLinkResource.canInline()).toBe(false); + }); + }); + }); + + describe('getFileContent', () => { + describe('when version is 1.3', () => { + it('should return XML content of common cartridge version 1.3', () => { + const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV3); + const content = webLinkResource.getFileContent(); + + expect(content).toContain('webLink'); + expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); + expect(content).toContain('http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3'); + expect(content).toContain('http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd'); + }); + }); + + describe('when version is 1.1', () => { + it('should return XML content of common cartridge version 1.1', () => { + const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV1); + const content = webLinkResource.getFileContent(); + + expect(content).toContain('webLink'); + expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); + expect(content).toContain('http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1'); + expect(content).toContain( + 'https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd' + ); + }); + }); + + describe('when version is not supported', () => { + it('should throw an error', () => { + const webLinkResource = new CommonCartridgeWebLinkResource({ + ...propsOfV1, + version: 'xxx' as CommonCartridgeVersion, + }); - expect(content).toContain('webLink'); - expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); - expect(content).toContain('http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3'); - expect(content).toContain('http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd'); - expect(transformed).toEqual({ - $: { - identifier: propsOfV3.identifier, - type: propsOfV3.type, - }, - file: { + expect(() => webLinkResource.getFileContent()).toThrowError('Version xxx is not supported'); + }); + }); + }); + + describe('getManifestXml', () => { + describe('when version is 1.3', () => { + it('should return manifest XML of common cartridge version 1.3', () => { + const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV3); + const transformed = webLinkResource.getManifestXml(); + + expect(transformed).toEqual({ $: { - href: propsOfV3.folder, + identifier: propsOfV3.identifier, + type: propsOfV3.type, + }, + file: { + $: { + href: propsOfV3.folder, + }, }, - }, + }); }); - expect(webLinkResource.canInline()).toBe(false); }); - }); - describe('CommonCartridgeWebLinkResourceElement of version 1', () => { - it('should return XML content of common cartridge version 1', () => { - const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV1); - const content = webLinkResource.getFileContent(); - const transformed = webLinkResource.getManifestXml(); + describe('when version is 1.1', () => { + it('should return manifest XML of common cartridge version 1.1', () => { + const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV1); + const transformed = webLinkResource.getManifestXml(); - expect(content).toContain('webLink'); - expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); - expect(content).toContain('http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1'); - expect(content).toContain( - 'https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd' - ); - expect(transformed).toEqual({ - $: { - identifier: propsOfV1.identifier, - type: propsOfV1.type, - }, - file: { + expect(transformed).toEqual({ $: { - href: propsOfV1.folder, + identifier: propsOfV1.identifier, + type: propsOfV1.type, + }, + file: { + $: { + href: propsOfV1.folder, + }, }, - }, + }); }); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts index cb3c8c06534..135ee590806 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts @@ -24,13 +24,15 @@ export class CommonCartridgeWebLinkResource implements CommonCartridgeResource { getFileContent(): string { return buildXmlString({ - $: this.getXmlNamespacesByVersion(), - title: this.props.title, - url: { - $: { - href: this.props.url, - target: '_self', - windowFeatures: 'width=100, height=100', + webLink: { + $: this.getXmlNamespacesByVersion(), + title: this.props.title, + url: { + $: { + href: this.props.url, + target: '_self', + windowFeatures: 'width=100, height=100', + }, }, }, }); From 3ebc7d468dd1d88c5737868f9c59802a7a8cff0d Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 29 Nov 2023 16:38:38 +0100 Subject: [PATCH 025/177] EW-539 Adjust tests for web content and web link resources --- ...mon-cartridge-web-content-resource.spec.ts | 57 ++++++++++++------- ...common-cartridge-web-link-resource.spec.ts | 51 +++++++++-------- 2 files changed, 63 insertions(+), 45 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts index e8055fc4cfb..19be3bed985 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts @@ -14,32 +14,49 @@ describe('CommonCartridgeWebContentResource', () => { html: 'html tages for testing', }; const webContentResource = new CommonCartridgeWebContentResource(props); - describe('content', () => { - it('should return html content regardless of common cartridge version', () => { - const content = webContentResource.getFileContent(); - expect(content).toContain(props.html); + + describe('canInline', () => { + describe('when the return value of the method is called', () => { + it('should return false regardless of the common cartridge version', () => { + expect(webContentResource.canInline()).toBe(false); + }); }); }); - describe('canInline', () => { - it('check the return value of the method Can Inline ', () => { - expect(webContentResource.canInline()).toBe(false); + + describe('getFilePath', () => { + describe('when the return value of the method is called', () => { + it('should return the file path regardless of the common cartridge version', () => { + const filePath = webContentResource.getFilePath(); + expect(filePath).toBe(`${props.folder}/${props.identifier}.html`); + }); }); }); - describe('transform', () => { - it('should transform XML content regardless of common cartridge version', () => { - const transformed = webContentResource.getManifestXml(); - expect(webContentResource.canInline()).toBe(false); - expect(transformed).toEqual({ - $: { - identifier: props.identifier, - type: props.type, - intendeduse: 'unspecified', - }, - file: { + + describe('getFileContent', () => { + describe('when the return value of the method is called', () => { + it('should return html content regardless of the common cartridge version', () => { + const content = webContentResource.getFileContent(); + expect(content).toContain(props.html); + }); + }); + }); + + describe('getManifestXml', () => { + describe('when the return value of the method is called', () => { + it('should return manifest xml content regardless of the common cartridge version', () => { + const transformed = webContentResource.getManifestXml(); + expect(transformed).toEqual({ $: { - href: props.folder, + identifier: props.identifier, + type: props.type, + intendeduse: 'unspecified', + }, + file: { + $: { + href: props.folder, + }, }, - }, + }); }); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts index 867610f8b25..8fe08939f72 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts @@ -13,6 +13,7 @@ describe('CommonCartridgeWebLinkResource', () => { title: 'Web Link v3', url: 'https://example.com/linkv3', }; + const propsOfV1: CommonCartridgeWebLinkResourceProps = { type: CommonCartridgeResourceType.WEB_LINK, version: CommonCartridgeVersion.V_1_1, @@ -22,17 +23,26 @@ describe('CommonCartridgeWebLinkResource', () => { url: 'https://example.com/link1', }; + const webLinkResourceV3 = new CommonCartridgeWebLinkResource(propsOfV3); + const webLinkResourceV1 = new CommonCartridgeWebLinkResource(propsOfV1); + describe('canInline', () => { - describe('when version is 1.3', () => { - it('should return false', () => { - const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV3); - expect(webLinkResource.canInline()).toBe(false); + describe('when the return value of the method is called', () => { + it('should return false regardless of the common cartridge version', () => { + expect(webLinkResourceV3.canInline()).toBe(false); + expect(webLinkResourceV1.canInline()).toBe(false); }); }); - describe('when version is 1.1', () => { - it('should return false', () => { - const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV1); - expect(webLinkResource.canInline()).toBe(false); + }); + + describe('getFilePath', () => { + describe('when the return value of the method is called', () => { + it('should return the file path regardless of the common cartridge version', () => { + const filePathV3 = webLinkResourceV3.getFilePath(); + const filePathV1 = webLinkResourceV1.getFilePath(); + + expect(filePathV3).toBe(`${propsOfV3.folder}/${propsOfV3.identifier}.xml`); + expect(filePathV1).toBe(`${propsOfV1.folder}/${propsOfV1.identifier}.xml`); }); }); }); @@ -40,8 +50,7 @@ describe('CommonCartridgeWebLinkResource', () => { describe('getFileContent', () => { describe('when version is 1.3', () => { it('should return XML content of common cartridge version 1.3', () => { - const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV3); - const content = webLinkResource.getFileContent(); + const content = webLinkResourceV3.getFileContent(); expect(content).toContain('webLink'); expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); @@ -52,8 +61,7 @@ describe('CommonCartridgeWebLinkResource', () => { describe('when version is 1.1', () => { it('should return XML content of common cartridge version 1.1', () => { - const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV1); - const content = webLinkResource.getFileContent(); + const content = webLinkResourceV1.getFileContent(); expect(content).toContain('webLink'); expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); @@ -77,12 +85,12 @@ describe('CommonCartridgeWebLinkResource', () => { }); describe('getManifestXml', () => { - describe('when version is 1.3', () => { - it('should return manifest XML of common cartridge version 1.3', () => { - const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV3); - const transformed = webLinkResource.getManifestXml(); + describe('when the return value of the method is called', () => { + it('should return manifest xml content regardless of the common cartridge version', () => { + const transformedV3 = webLinkResourceV3.getManifestXml(); + const transformedV1 = webLinkResourceV1.getManifestXml(); - expect(transformed).toEqual({ + expect(transformedV3).toEqual({ $: { identifier: propsOfV3.identifier, type: propsOfV3.type, @@ -93,15 +101,8 @@ describe('CommonCartridgeWebLinkResource', () => { }, }, }); - }); - }); - - describe('when version is 1.1', () => { - it('should return manifest XML of common cartridge version 1.1', () => { - const webLinkResource = new CommonCartridgeWebLinkResource(propsOfV1); - const transformed = webLinkResource.getManifestXml(); - expect(transformed).toEqual({ + expect(transformedV1).toEqual({ $: { identifier: propsOfV1.identifier, type: propsOfV1.type, From 53936276e6d865c397793f6067df1489aaffb732 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 29 Nov 2023 18:25:14 +0100 Subject: [PATCH 026/177] EW-539 Adjust test for lti resource --- .../common-cartridge-lti-resource.spec.ts | 152 ++++++++---------- .../common-cartridge-lti-resource.ts | 1 - 2 files changed, 71 insertions(+), 82 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts index 773db4637d6..6dc8cf1332a 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts @@ -25,72 +25,86 @@ describe('CommonCartridgeLtiResource', () => { const ltiResourceVersion1 = new CommonCartridgeLtiResource(propsVersion1); const ltiResourceVersion3 = new CommonCartridgeLtiResource(propsVersion3); - describe('content', () => { - describe('When Common Cartridge version 1.1', () => { - it('should return correct content for version 1.1', () => { - const expectedContent = ` - - - lti-title-version1 - lti-description-version1 - https://to-a-lti-tool-version1.tld - https://to-a-lti-tool-version1.tld - - - - `; + describe('canInline', () => { + describe('when the return value of the method is called', () => { + it('should return false regardless of the common cartridge version', () => { + const resultVersion1 = ltiResourceVersion1.canInline(); + const resultVersion3 = ltiResourceVersion3.canInline(); - const content = ltiResourceVersion1.getFileContent(); + expect(resultVersion1).toBe(false); + expect(resultVersion3).toBe(false); + }); + }); + }); + + describe('getFilePath', () => { + describe('when the return value of the method is called', () => { + it('should return the file path regardless of the common cartridge version', () => { + const filePathVersion1 = ltiResourceVersion1.getFilePath(); + const filePathVersion3 = ltiResourceVersion3.getFilePath(); - expect(content.replace(/\s/g, '')).toEqual(expectedContent.replace(/\s/g, '')); + expect(filePathVersion1).toBe(`${propsVersion1.folder}/${propsVersion1.identifier}.xml`); + expect(filePathVersion3).toBe(`${propsVersion3.folder}/${propsVersion3.identifier}.xml`); }); }); + }); - describe('When Common Cartridge version 1.3', () => { - it('should return correct content for version 1.3', () => { - const expectedContent = ` - - - lti-title-version3 - lti-description-version3 - https://to-a-lti-tool-version3.tld - https://to-a-lti-tool-version3.tld - - - - `; + describe('getFileContent', () => { + describe('when Common Cartridge version 1.1', () => { + it('should return correct XML content for version 1.1', () => { + const content = ltiResourceVersion1.getFileContent(); + + expect(content).toContain('cartridge_basiclti_link'); + expect(content).toContain('/xsd/imslticc_v1p0'); + expect(content).toContain('/xsd/imsbasiclti_v1p0'); + expect(content).toContain('/xsd/imslticm_v1p0'); + expect(content).toContain('/xsd/imslticp_v1p0'); + expect(content).toContain( + '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd' + + '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd' + + '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd' + + '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd' + ); + }); + }); + describe('when Common Cartridge version 1.3', () => { + it('should return correct XML content for version 1.3', () => { const content = ltiResourceVersion3.getFileContent(); - expect(content.replace(/\s/g, '')).toEqual(expectedContent.replace(/\s/g, '')); + expect(content).toContain('cartridge_basiclti_link'); + expect(content).toContain('http://www.imsglobal.org/xsd/imslticc_v1p3'); + expect(content).toContain('http://www.imsglobal.org/xsd/imsbasiclti_v1p0'); + expect(content).toContain('http://www.imsglobal.org/xsd/imslticm_v1p0'); + expect(content).toContain('http://www.imsglobal.org/xsd/imslticp_v1p0'); + expect(content).toContain( + 'http://www.imsglobal.org/xsd/imslticc_v1p3 http://www.imsglobal.org/xsd/imslticc_v1p3.xsd' + + 'http://www.imsglobal.org/xsd/imslticp_v1p0 imslticp_v1p0.xsd' + + 'http://www.imsglobal.org/xsd/imslticm_v1p0 imslticm_v1p0.xsd' + + 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0 imsbasiclti_v1p0p1.xsd' + ); + }); + }); + + describe('when version is not supported', () => { + it('should throw an error', () => { + const ltiResource = new CommonCartridgeLtiResource({ + ...propsVersion1, + version: 'xxx' as CommonCartridgeVersion, + }); + + expect(() => ltiResource.getFileContent()).toThrowError('Version xxx is not supported'); }); }); }); - describe('transform', () => { - describe('When Common Cartridge version 1.1', () => { - it('should transform props into the expected resource structure', () => { - const expectedOutput = { + describe('getManifestXml', () => { + describe('when the return value of the method is called', () => { + it('should return manifest xml content regardless of the common cartridge version', () => { + const transformedVersion1 = ltiResourceVersion1.getManifestXml(); + const transformedVersion3 = ltiResourceVersion3.getManifestXml(); + + expect(transformedVersion1).toEqual({ $: { identifier: propsVersion1.identifier, type: propsVersion1.type, @@ -100,15 +114,9 @@ describe('CommonCartridgeLtiResource', () => { href: propsVersion1.folder, }, }, - }; + }); - const transformed = ltiResourceVersion1.getManifestXml(); - expect(transformed).toEqual(expectedOutput); - }); - }); - describe('When Common Cartridge version 1.3', () => { - it('should transform props into the expected resource structure', () => { - const expectedOutput = { + expect(transformedVersion3).toEqual({ $: { identifier: propsVersion3.identifier, type: propsVersion3.type, @@ -118,25 +126,7 @@ describe('CommonCartridgeLtiResource', () => { href: propsVersion3.folder, }, }, - }; - - const transformed = ltiResourceVersion3.getManifestXml(); - expect(transformed).toEqual(expectedOutput); - }); - }); - }); - - describe('canInline', () => { - describe('When Common Cartridge version 1.1', () => { - it('should return false for canInline', () => { - const result = ltiResourceVersion1.canInline(); - expect(result).toBe(false); - }); - }); - describe('When Common Cartridge version 1.3', () => { - it('should return false for canInline', () => { - const result = ltiResourceVersion3.canInline(); - expect(result).toBe(false); + }); }); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts index fa5396c17e5..ccb1b9b1217 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts @@ -19,7 +19,6 @@ export class CommonCartridgeLtiResource implements CommonCartridgeResource { return false; } - // TODO: This is not correct. The href should be relative to the imsmanifest.xml file. getFilePath(): string { return `${this.props.folder}/${this.props.identifier}.xml`; } From 82c37e4bf9c267a8f446dc34cea452e34e2c93ce Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 30 Nov 2023 09:45:35 +0100 Subject: [PATCH 027/177] EW-539 renaming and adding tests --- .../common-cartridge-file-builder.spec.ts | 27 ++++--- ...mon-cartridge-organization-builder.spec.ts | 79 +++++++++++++++++++ .../common-cartridge-organization-builder.ts | 2 +- .../common-cartridge-organization-element.ts} | 0 4 files changed, 94 insertions(+), 14 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.spec.ts rename apps/server/src/modules/learnroom/common-cartridge/temp/{resources/common-cartridge-organization-resource.ts => elements/common-cartridge-organization-element.ts} (100%) diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts index f597f5b1b0a..c8c08e685f8 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts @@ -2,6 +2,7 @@ import AdmZip from 'adm-zip'; import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeMetadataElementProps } from '../elements/common-cartridge-metadata-element'; import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; +import { OmitVersion } from '../utils'; import { CommonCartridgeFileBuilder, CommonCartridgeFileBuilderProps } from './common-cartridge-file-builder'; import { CommonCartridgeOrganizationBuilderOptions } from './common-cartridge-organization-builder'; @@ -15,36 +16,36 @@ describe('CommonCartridgeFileBuilder', () => { version: CommonCartridgeVersion.V_1_1, identifier: 'manifest-identifier', }; - const metadataProps: Omit = { + const metadataProps: OmitVersion = { title: 'metadata-title', creationDate: new Date(), copyrightOwners: ['John Doe', 'Jane Doe'], }; - const organizationProps: Omit = { + const organizationOptions: OmitVersion = { title: 'organization-title', identifier: 'organization-identifier', }; - const subOrganizationProps: Omit = { + const subOrganizationOptions: OmitVersion = { title: 'sub-organization-title', identifier: 'sub-organization-identifier', }; - const subSubOrganizationProps: Omit = { + const subSubOrganizationOptions: OmitVersion = { title: 'sub-sub-organization-title', identifier: 'sub-sub-organization-identifier', }; - const resource1: CommonCartridgeResourceProps = { + const resource1Props: CommonCartridgeResourceProps = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'resource-1-identifier', title: 'resource-1-title', html: '

resource-1-html

', }; - const resource2: CommonCartridgeResourceProps = { + const resource2Props: CommonCartridgeResourceProps = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'resource-2-identifier', title: 'resource-2-title', html: '

resource-2-html

', }; - const resource3: CommonCartridgeResourceProps = { + const resource3Props: CommonCartridgeResourceProps = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'resource-3-identifier', title: 'resource-3-title', @@ -56,12 +57,12 @@ describe('CommonCartridgeFileBuilder', () => { beforeAll(async () => { sut = new CommonCartridgeFileBuilder(fileBuilderOptions); sut.addMetadata(metadataProps) - .addOrganization(organizationProps) - .addResource(resource1) - .addSubOrganization(subOrganizationProps) - .addResource(resource2) - .addSubOrganization(subSubOrganizationProps) - .addResource(resource3); + .addOrganization(organizationOptions) + .addResource(resource1Props) + .addSubOrganization(subOrganizationOptions) + .addResource(resource2Props) + .addSubOrganization(subSubOrganizationOptions) + .addResource(resource3Props); archive = new AdmZip(await sut.build()); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.spec.ts new file mode 100644 index 00000000000..27ca2816f2b --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.spec.ts @@ -0,0 +1,79 @@ +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeOrganizationElement } from '../elements/common-cartridge-organization-element'; +import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; +import { + CommonCartridgeOrganizationBuilder, + CommonCartridgeOrganizationBuilderOptions, +} from './common-cartridge-organization-builder'; + +describe('CommonCartridgeOrganizationBuilder', () => { + let sut: CommonCartridgeOrganizationBuilder; + + const resources = new Array(); + + const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { + title: 'organization-title', + identifier: 'organization-identifier', + version: CommonCartridgeVersion.V_1_1, + }; + const subOrganizationOptions: CommonCartridgeOrganizationBuilderOptions = { + title: 'sub-organization-title', + identifier: 'sub-organization-identifier', + version: CommonCartridgeVersion.V_1_1, + }; + const subSubOrganizationOptions: CommonCartridgeOrganizationBuilderOptions = { + title: 'sub-sub-organization-title', + identifier: 'sub-sub-organization-identifier', + version: CommonCartridgeVersion.V_1_1, + }; + const resource1Props: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: 'resource-1-identifier', + title: 'resource-1-title', + html: '

resource-1-html

', + }; + const resource2Props: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: 'resource-2-identifier', + title: 'resource-2-title', + html: '

resource-2-html

', + }; + const resource3Props: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: 'resource-3-identifier', + title: 'resource-3-title', + html: '

resource-3-html

', + }; + + beforeEach(() => { + jest.clearAllMocks(); + }); + + describe('build', () => { + describe('when creating a common cartridge archive', () => { + beforeAll(() => { + sut = new CommonCartridgeOrganizationBuilder(organizationOptions, (resource) => + resources.push(resource) + ); + sut.addResource(resource1Props) + .addSubOrganization(subOrganizationOptions) + .addResource(resource2Props) + .addSubOrganization(subSubOrganizationOptions) + .addResource(resource3Props) + .build(); + }); + + it('should return a common cartridge organization element', () => { + const element = sut.build(); + + expect(element).toBeDefined(); + expect(element).toBeInstanceOf(CommonCartridgeOrganizationElement); + }); + + it('should add 3 resources', () => { + expect(resources).toHaveLength(3); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts index 10706e7dc83..717974da712 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts @@ -1,7 +1,7 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeOrganizationElement } from '../elements/common-cartridge-organization-element'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { CommonCartridgeOrganizationElement } from '../resources/common-cartridge-organization-resource'; import { CommonCartridgeResourceFactory, CommonCartridgeResourceProps, diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-organization-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-organization-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-organization-resource.ts rename to apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-organization-element.ts From fb5ffb7b9309d371fb1f463036c1f6360cdc2022 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 30 Nov 2023 10:22:22 +0100 Subject: [PATCH 028/177] EW-539 adding tests for common cartridge utils --- .../learnroom/common-cartridge/temp/index.ts | 1 - .../common-cartridge/temp/utils.spec.ts | 57 +++++++++++++++++++ .../learnroom/common-cartridge/temp/utils.ts | 2 +- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/utils.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts index 02c89a2b2d3..ad48a87feb6 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts @@ -1,3 +1,2 @@ export * from './builders/common-cartridge-file-builder'; -export * from './resources/common-cartridge-resource-factory'; export * from './common-cartridge.enums'; diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.spec.ts new file mode 100644 index 00000000000..fac2d2a7c2e --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.spec.ts @@ -0,0 +1,57 @@ +import { CommonCartridgeVersion } from './common-cartridge.enums'; +import { buildXmlString, checkCommonCartridgeVersion, checkDefined, createVersionNotSupportedError } from './utils'; + +describe('CommonCartridgeUtils', () => { + describe('buildXmlString', () => { + it('should create xml string', () => { + const xml = buildXmlString({ root: { child: 'value' } }); + + expect(xml).toBe('\n value\n'); + }); + }); + + describe('createVersionNotSupportedError', () => { + describe('when creating error', () => { + it('should return error with message', () => { + const error = createVersionNotSupportedError(CommonCartridgeVersion.V_1_0); + + expect(error).toBeDefined(); + expect(error.message).toBe('Version 1.0.0 is not supported'); + }); + }); + }); + + // AI next 12 lines + describe('checkCommonCartridgeVersion', () => { + describe('when checking version', () => { + it('should not throw error when version is supported', () => { + expect(() => checkCommonCartridgeVersion(CommonCartridgeVersion.V_1_1)).not.toThrow(); + }); + + it('should throw error when version is not supported', () => { + expect(() => checkCommonCartridgeVersion(CommonCartridgeVersion.V_1_0)).toThrow( + createVersionNotSupportedError(CommonCartridgeVersion.V_1_0) + ); + }); + }); + }); + + // AI next 16 lines + describe('checkDefined', () => { + describe('when checking value', () => { + it('should return value when value is defined', () => { + const value = 'value'; + + expect(checkDefined(value, 'value')).toBe(value); + }); + + it('should throw error when value is undefined', () => { + expect(() => checkDefined(undefined, 'value')).toThrow(new Error('value is null or undefined')); + }); + + it('should throw error when value is null', () => { + expect(() => checkDefined(null, 'value')).toThrow(new Error('value is null or undefined')); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts index 55c144aedd1..5fc348fa8b0 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts @@ -5,7 +5,7 @@ export type OmitVersion = Omit; export type OmitVersionAndFolder = Omit; -const xmlBuilder = new Builder(); +const xmlBuilder = new Builder({ headless: true }); export function buildXmlString(obj: unknown): string { return xmlBuilder.buildObject(obj); From 2f126d0f3c24fcf583d07c1d37bdcedd0f73bc89 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 30 Nov 2023 10:41:03 +0100 Subject: [PATCH 029/177] EW-539 adding resource factory tests --- .editorconfig | 9 +++ .../common-cartridge-resource-factory.spec.ts | 60 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 .editorconfig create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.spec.ts diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000000..7d2f033b21e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*.ts] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = tab +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.spec.ts new file mode 100644 index 00000000000..cab3290c7ea --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.spec.ts @@ -0,0 +1,60 @@ +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeLtiResource } from './common-cartridge-lti-resource'; +import { CommonCartridgeResourceFactory, CommonCartridgeResourceProps } from './common-cartridge-resource-factory'; +import { CommonCartridgeWebContentResource } from './common-cartridge-web-content-resource'; +import { CommonCartridgeWebLinkResource } from './common-cartridge-web-link-resource'; + +describe('CommonCartridgeResourceFactory', () => { + const versionAndFolderProps = { version: CommonCartridgeVersion.V_1_1, folder: 'folder' }; + + describe('create', () => { + // AI next 14 lines + describe('when creating a lti resource', () => { + it('should return a lti resource', () => { + const props: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.LTI, + identifier: 'lti-identifier', + title: 'title', + description: 'description', + url: 'url', + }; + + const resource = CommonCartridgeResourceFactory.create({ ...props, ...versionAndFolderProps }); + + expect(resource).toBeInstanceOf(CommonCartridgeLtiResource); + }); + }); + + // AI next 13 lines + describe('when creating a web content resource', () => { + it('should return a web content resource', () => { + const props: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: 'web-content-identifier', + title: 'title', + html: 'html', + }; + + const resource = CommonCartridgeResourceFactory.create({ ...props, ...versionAndFolderProps }); + + expect(resource).toBeInstanceOf(CommonCartridgeWebContentResource); + }); + }); + + // AI next 13 lines + describe('when creating a web link resource', () => { + it('should return a web link resource', () => { + const props: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_LINK, + identifier: 'web-link-identifier', + title: 'title', + url: 'url', + }; + + const resource = CommonCartridgeResourceFactory.create({ ...props, ...versionAndFolderProps }); + + expect(resource).toBeInstanceOf(CommonCartridgeWebLinkResource); + }); + }); + }); +}); From 37fe9d0c9933b2a2a62901152a5fcf52ec2de56c Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 30 Nov 2023 10:45:08 +0100 Subject: [PATCH 030/177] EW-539 replacing old with new files --- .../common-cartridge-file-builder.spec.ts | 0 .../builders/common-cartridge-file-builder.ts | 0 ...mon-cartridge-organization-builder.spec.ts | 0 .../common-cartridge-organization-builder.ts | 0 .../common-cartridge-element.interface.ts | 3 - .../common-cartridge-enums.ts | 18 --- .../common-cartridge-file-builder.spec.ts | 106 ------------- .../common-cartridge-file-builder.ts | 139 ---------------- .../common-cartridge-file.interface.ts | 4 - ...common-cartridge-lesson-content-element.ts | 8 - .../common-cartridge-lti-resource.spec.ts | 144 ----------------- .../common-cartridge-lti-resource.ts | 94 ----------- .../common-cartridge-manifest-element.spec.ts | 149 ------------------ .../common-cartridge-manifest-element.ts | 64 -------- .../common-cartridge-metadata-element.spec.ts | 37 ----- .../common-cartridge-metadata-element.ts | 35 ---- ...artridge-organization-item-element.spec.ts | 45 ------ ...mon-cartridge-organization-item-element.ts | 83 ---------- ...ridge-organization-wrapper-element.spec.ts | 40 ----- ...-cartridge-organization-wrapper-element.ts | 26 --- ...on-cartridge-resource-item-element.spec.ts | 15 -- .../common-cartridge-resource-item-element.ts | 49 ------ ...cartridge-resource-wrapper-element.spec.ts | 25 --- ...mmon-cartridge-resource-wrapper-element.ts | 11 -- ...mon-cartridge-web-content-resource.spec.ts | 46 ------ .../common-cartridge-web-content-resource.ts | 44 ------ ...common-cartridge-web-link-resource.spec.ts | 77 --------- .../common-cartridge-web-link-resource.ts | 74 --------- .../common-cartridge.config.ts | 3 - .../{temp => }/common-cartridge.enums.ts | 0 .../common-cartridge-metadata-element.ts | 0 .../common-cartridge-organization-element.ts | 0 ...cartridge-organizations-wrapper-element.ts | 0 ...mon-cartridge-resources-wrapper-element.ts | 0 .../learnroom/common-cartridge/index.ts | 16 +- .../common-cartridge-element.interface.ts | 0 .../common-cartridge-resource.interface.ts | 0 .../common-cartridge-lti-resource.spec.ts | 0 .../common-cartridge-lti-resource.ts | 0 .../common-cartridge-manifest-resource.ts | 0 .../common-cartridge-resource-factory.spec.ts | 0 .../common-cartridge-resource-factory.ts | 0 ...mon-cartridge-web-content-resource.spec.ts | 0 .../common-cartridge-web-content-resource.ts | 0 ...common-cartridge-web-link-resource.spec.ts | 0 .../common-cartridge-web-link-resource.ts | 0 .../learnroom/common-cartridge/temp/index.ts | 2 - .../learnroom/common-cartridge/temp/utils.ts | 34 ---- .../common-cartridge/{temp => }/utils.spec.ts | 0 .../learnroom/common-cartridge/utils.ts | 40 ++++- 50 files changed, 36 insertions(+), 1395 deletions(-) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/builders/common-cartridge-file-builder.spec.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/builders/common-cartridge-file-builder.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/builders/common-cartridge-organization-builder.spec.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/builders/common-cartridge-organization-builder.ts (100%) delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-element.interface.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-enums.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file.interface.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-lesson-content-element.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-lti-resource.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-lti-resource.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-manifest-element.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-manifest-element.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-metadata-element.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-metadata-element.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-wrapper-element.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-wrapper-element.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-item-element.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-item-element.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-wrapper-element.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-wrapper-element.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-content-resource.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-content-resource.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-link-resource.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-link-resource.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/common-cartridge.enums.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/elements/common-cartridge-metadata-element.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/elements/common-cartridge-organization-element.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/elements/common-cartridge-organizations-wrapper-element.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/elements/common-cartridge-resources-wrapper-element.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/interfaces/common-cartridge-element.interface.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/interfaces/common-cartridge-resource.interface.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/resources/common-cartridge-lti-resource.spec.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/resources/common-cartridge-lti-resource.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/resources/common-cartridge-manifest-resource.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/resources/common-cartridge-resource-factory.spec.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/resources/common-cartridge-resource-factory.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/resources/common-cartridge-web-content-resource.spec.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/resources/common-cartridge-web-content-resource.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/resources/common-cartridge-web-link-resource.spec.ts (100%) rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/resources/common-cartridge-web-link-resource.ts (100%) delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/index.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts rename apps/server/src/modules/learnroom/common-cartridge/{temp => }/utils.spec.ts (100%) diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.spec.ts rename to apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-file-builder.ts rename to apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.spec.ts rename to apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/builders/common-cartridge-organization-builder.ts rename to apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-element.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-element.interface.ts deleted file mode 100644 index 400b31dabb1..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-element.interface.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface CommonCartridgeElement { - transform(): Record; -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-enums.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-enums.ts deleted file mode 100644 index 52ccd5c5818..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-enums.ts +++ /dev/null @@ -1,18 +0,0 @@ -export enum CommonCartridgeVersion { - V_1_1_0 = '1.1.0', - V_1_3_0 = '1.3.0', -} - -export enum CommonCartridgeResourceType { - LTI = 'imsbasiclti_xmlv1p0', - WEB_CONTENT = 'webcontent', - WEB_LINK_V1 = 'imswl_xmlv1p1', - WEB_LINK_V3 = 'imswl_xmlv1p3', -} - -export enum CommonCartridgeIntendedUseType { - ASSIGNMENT = 'assignment', - LESSON_PLAN = 'lessonplan', - SYLLABUS = 'syllabus', - UNSPECIFIED = 'unspecified', -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.spec.ts deleted file mode 100644 index e7bfc20f79d..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.spec.ts +++ /dev/null @@ -1,106 +0,0 @@ -import AdmZip from 'adm-zip'; -import { parseStringPromise } from 'xml2js'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from './common-cartridge-enums'; -import { CommonCartridgeFileBuilder, CommonCartridgeFileBuilderOptions } from './common-cartridge-file-builder'; -import { CommonCartridgeOrganizationItemElementProps } from './common-cartridge-organization-item-element'; -import { ICommonCartridgeResourceProps } from './common-cartridge-resource-item-element'; - -describe('CommonCartridgeFileBuilder', () => { - let archive: AdmZip; - - const getFileContentAsString = (path: string): string | undefined => archive.getEntry(path)?.getData().toString(); - const fileBuilderOptions: CommonCartridgeFileBuilderOptions = { - identifier: 'file-identifier', - copyrightOwners: 'Placeholder Copyright', - creationYear: 'Placeholder Creation Year', - title: 'file-title', - version: CommonCartridgeVersion.V_1_1_0, - }; - const organizationProps: CommonCartridgeOrganizationItemElementProps = { - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'organization-identifier', - title: 'organization-title', - resources: [], - _tag: 'resourceCollection', - }; - const ltiResourceProps: ICommonCartridgeResourceProps = { - version: CommonCartridgeVersion.V_1_1_0, - type: CommonCartridgeResourceType.LTI, - identifier: 'lti-identifier', - href: 'lti-identifier/lti.xml', - title: 'lti-title', - description: 'lti-description', - url: 'https://to-a-lti-tool.tld', - }; - const webContentResourceProps: ICommonCartridgeResourceProps = { - version: CommonCartridgeVersion.V_1_1_0, - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: 'web-content-identifier', - href: 'web-content-identifier/web-content.html', - title: 'web-content-title', - html: '

Text Resource Title

Text Resource Description

', - }; - - beforeAll(async () => { - const fileBuilder = new CommonCartridgeFileBuilder(fileBuilderOptions).addResourceToFile(webContentResourceProps); - fileBuilder.addOrganization(organizationProps).addResourceToOrganization(ltiResourceProps); - - archive = new AdmZip(await fileBuilder.build()); - }); - - describe('addOrganization', () => { - describe('when adding an organization to the common cartridge file', () => { - it('should add organization to manifest', () => { - const manifest = getFileContentAsString('imsmanifest.xml'); - expect(manifest).toContain(organizationProps.identifier); - expect(manifest).toContain(organizationProps.title); - expect(manifest).toContain(organizationProps.version); - }); - }); - - describe('when adding a resource to an organization', () => { - it('should add resource to organization', () => { - const manifest = getFileContentAsString('imsmanifest.xml'); - expect(manifest).toContain(`${ltiResourceProps.title}`); - }); - - it('should add resource to manifest', () => { - const manifest = getFileContentAsString('imsmanifest.xml'); - expect(manifest).toContain(``); - }); - - it('should create corresponding resource file in archive', () => { - expect(getFileContentAsString(ltiResourceProps.href)).toBeTruthy(); - }); - }); - }); - - describe('addResourceToFile', () => { - describe('when adding a resource to the common cartridge file', () => { - it('should add resource to manifest', () => { - const manifest = getFileContentAsString('imsmanifest.xml'); - expect(manifest).toContain(webContentResourceProps.identifier); - expect(manifest).toContain(``); - expect(manifest).not.toContain(webContentResourceProps.title); - }); - - it('should create corresponding file in archive', () => { - expect(getFileContentAsString(webContentResourceProps.href)).toBeTruthy(); - }); - }); - }); - - describe('build', () => { - describe('when creating common cartridge archive', () => { - it('should create manifest file at archive root', () => { - const manifest = getFileContentAsString('imsmanifest.xml'); - expect(manifest).toBeTruthy(); - }); - - it('should create valid manifest file', async () => { - const manifest = getFileContentAsString('imsmanifest.xml'); - await expect(parseStringPromise(manifest as string)).resolves.not.toThrow(); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.ts deleted file mode 100644 index 1d6571e0dd1..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file-builder.ts +++ /dev/null @@ -1,139 +0,0 @@ -import AdmZip from 'adm-zip'; -import { Builder } from 'xml2js'; -import { CommonCartridgeElement } from './common-cartridge-element.interface'; -import { CommonCartridgeVersion } from './common-cartridge-enums'; -import { CommonCartridgeManifestElement } from './common-cartridge-manifest-element'; -import { - CommonCartridgeOrganizationItemElement, - CommonCartridgeOrganizationItemElementProps, - OrganizationItemCollection, -} from './common-cartridge-organization-item-element'; -import { - CommonCartridgeResourceItemElement, - ICommonCartridgeResourceProps, -} from './common-cartridge-resource-item-element'; - -export type CommonCartridgeFileBuilderOptions = { - identifier: string; - title: string; - copyrightOwners: string; - creationYear: string; - version: CommonCartridgeVersion; -}; - -export interface ICommonCartridgeOrganizationBuilder { - addResourceToOrganization(props: ICommonCartridgeResourceProps): ICommonCartridgeOrganizationBuilder; - addSubOrganization(props: CommonCartridgeOrganizationItemElementProps): ICommonCartridgeOrganizationBuilder; -} - -export interface ICommonCartridgeFileBuilder { - addOrganization(props: CommonCartridgeOrganizationItemElementProps): ICommonCartridgeOrganizationBuilder; - - addResourceToFile(props: ICommonCartridgeResourceProps): ICommonCartridgeFileBuilder; - - build(): Promise; -} - -class CommonCartridgeOrganizationBuilder implements ICommonCartridgeOrganizationBuilder { - constructor( - private readonly props: CommonCartridgeOrganizationItemElementProps, - private readonly xmlBuilder: Builder, - private readonly zipBuilder: AdmZip - ) {} - - private resourceProperties: ICommonCartridgeResourceProps[] = []; - - private children: CommonCartridgeOrganizationBuilder[] = []; - - get organization(): CommonCartridgeElement { - return new CommonCartridgeOrganizationItemElement(this.orgProps); - } - - get orgProps(): OrganizationItemCollection { - return { - _tag: 'itemCollection', - title: this.props.title, - children: - this.props._tag === 'resourceCollection' - ? { - _tag: 'resourceCollection', - resources: this.resourceProperties, - identifier: this.props.identifier, - version: this.props.version, - title: this.props.title, - } - : this.children.map((child) => child.orgProps), - }; - } - - get resources(): CommonCartridgeElement[] { - return this.children - .flatMap((child) => child.resourceProperties) - .concat(this.resourceProperties) - .map((resourceProps) => new CommonCartridgeResourceItemElement(resourceProps, this.xmlBuilder)); - } - - addResourceToOrganization(props: ICommonCartridgeResourceProps): ICommonCartridgeOrganizationBuilder { - const newResource = new CommonCartridgeResourceItemElement(props, this.xmlBuilder); - this.resourceProperties.push(props); - if (!newResource.canInline()) { - this.zipBuilder.addFile(props.href, Buffer.from(newResource.content())); - } - return this; - } - - addSubOrganization(props: CommonCartridgeOrganizationItemElementProps): ICommonCartridgeOrganizationBuilder { - const subOrgBuilder = new CommonCartridgeOrganizationBuilder(props, this.xmlBuilder, this.zipBuilder); - this.children.push(subOrgBuilder); - return subOrgBuilder; - } -} - -export class CommonCartridgeFileBuilder implements ICommonCartridgeFileBuilder { - private readonly xmlBuilder = new Builder(); - - private readonly zipBuilder = new AdmZip(); - - private readonly organizations = new Array(); - - private readonly resources = new Array(); - - constructor(private readonly options: CommonCartridgeFileBuilderOptions) {} - - addOrganization(props: CommonCartridgeOrganizationItemElementProps): ICommonCartridgeOrganizationBuilder { - const organizationBuilder = new CommonCartridgeOrganizationBuilder(props, this.xmlBuilder, this.zipBuilder); - this.organizations.push(organizationBuilder); - return organizationBuilder; - } - - addResourceToFile(props: ICommonCartridgeResourceProps): ICommonCartridgeFileBuilder { - const resource = new CommonCartridgeResourceItemElement(props, this.xmlBuilder); - if (!resource.canInline()) { - this.zipBuilder.addFile(props.href, Buffer.from(resource.content())); - } - this.resources.push(resource); - return this; - } - - async build(): Promise { - const organizations = this.organizations.map((organization) => organization.organization); - const resources = this.organizations.flatMap((organization) => organization.resources).concat(this.resources); - const manifest = this.xmlBuilder.buildObject( - new CommonCartridgeManifestElement( - { - identifier: this.options.identifier, - }, - { - title: this.options.title, - copyrightOwners: this.options.copyrightOwners, - creationYear: this.options.creationYear, - version: this.options.version, - }, - organizations, - resources - ).transform() - ); - this.zipBuilder.addFile('imsmanifest.xml', Buffer.from(manifest)); - return this.zipBuilder.toBufferPromise(); - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file.interface.ts deleted file mode 100644 index 0969e712b05..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-file.interface.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface CommonCartridgeFile { - canInline(): boolean; - content(): string; -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-lesson-content-element.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-lesson-content-element.ts deleted file mode 100644 index edac1e4f30a..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-lesson-content-element.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * This type represents the content of a Lesson. - */ -export type ICommonCartridgeLessonContentProps = { - identifier: string; - title: string; - content: string; -}; diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-lti-resource.spec.ts deleted file mode 100644 index f52493e6f98..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-lti-resource.spec.ts +++ /dev/null @@ -1,144 +0,0 @@ -import { Builder } from 'xml2js'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from './common-cartridge-enums'; -import { CommonCartridgeLtiResource, ICommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; - -describe('CommonCartridgeLtiResource', () => { - const propsVersion1: ICommonCartridgeLtiResourceProps = { - type: CommonCartridgeResourceType.LTI, - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'lti-identifier-version1', - href: 'lti-identifier-version1/lti.xml', - title: 'lti-title-version1', - description: 'lti-description-version1', - url: 'https://to-a-lti-tool-version1.tld', - }; - - const propsVersion3: ICommonCartridgeLtiResourceProps = { - type: CommonCartridgeResourceType.LTI, - version: CommonCartridgeVersion.V_1_3_0, - identifier: 'lti-identifier-version3', - href: 'lti-identifier-version3/lti.xml', - title: 'lti-title-version3', - description: 'lti-description-version3', - url: 'https://to-a-lti-tool-version3.tld', - }; - - const ltiResourceVersion1 = new CommonCartridgeLtiResource(propsVersion1, new Builder()); - const ltiResourceVersion3 = new CommonCartridgeLtiResource(propsVersion3, new Builder()); - - describe('content', () => { - describe('When Common Cartridge version 1.1', () => { - it('should return correct content for version 1.1', () => { - const expectedContent = ` - - - lti-title-version1 - lti-description-version1 - https://to-a-lti-tool-version1.tld - https://to-a-lti-tool-version1.tld - - - - `; - - const content = ltiResourceVersion1.content(); - - expect(content.replace(/\s/g, '')).toEqual(expectedContent.replace(/\s/g, '')); - }); - }); - - describe('When Common Cartridge version 1.3', () => { - it('should return correct content for version 1.3', () => { - const expectedContent = ` - - - lti-title-version3 - lti-description-version3 - https://to-a-lti-tool-version3.tld - https://to-a-lti-tool-version3.tld - - - - `; - - const content = ltiResourceVersion3.content(); - - expect(content.replace(/\s/g, '')).toEqual(expectedContent.replace(/\s/g, '')); - }); - }); - }); - - describe('transform', () => { - describe('When Common Cartridge version 1.1', () => { - it('should transform props into the expected resource structure', () => { - const expectedOutput = { - $: { - identifier: propsVersion1.identifier, - type: propsVersion1.type, - }, - file: { - $: { - href: propsVersion1.href, - }, - }, - }; - - const transformed = ltiResourceVersion1.transform(); - expect(transformed).toEqual(expectedOutput); - }); - }); - describe('When Common Cartridge version 1.3', () => { - it('should transform props into the expected resource structure', () => { - const expectedOutput = { - $: { - identifier: propsVersion3.identifier, - type: propsVersion3.type, - }, - file: { - $: { - href: propsVersion3.href, - }, - }, - }; - - const transformed = ltiResourceVersion3.transform(); - expect(transformed).toEqual(expectedOutput); - }); - }); - }); - - describe('canInline', () => { - describe('When Common Cartridge version 1.1', () => { - it('should return false for canInline', () => { - const result = ltiResourceVersion1.canInline(); - expect(result).toBe(false); - }); - }); - describe('When Common Cartridge version 1.3', () => { - it('should return false for canInline', () => { - const result = ltiResourceVersion3.canInline(); - expect(result).toBe(false); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-lti-resource.ts deleted file mode 100644 index a374b3687a6..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-lti-resource.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { Builder } from 'xml2js'; -import { CommonCartridgeElement } from './common-cartridge-element.interface'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from './common-cartridge-enums'; -import { CommonCartridgeFile } from './common-cartridge-file.interface'; - -export type ICommonCartridgeLtiResourceProps = { - type: CommonCartridgeResourceType.LTI; - version: CommonCartridgeVersion; - identifier: string; - href: string; - title: string; - description?: string; - url: string; -}; - -export class CommonCartridgeLtiResource implements CommonCartridgeElement, CommonCartridgeFile { - constructor(private readonly props: ICommonCartridgeLtiResourceProps, private readonly xmlBuilder: Builder) {} - - canInline(): boolean { - return false; - } - - content(): string { - const commonObject = { - cartridge_basiclti_link: { - $: { - xmlns: '', - 'xmlns:blti': '', - 'xmlns:lticm': '', - 'xmlns:lticp': '', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': '', - }, - blti: { - title: this.props.title, - description: this.props.description, - launch_url: this.props.url, - secure_launch_url: this.props.url, - cartridge_bundle: { - $: { - identifierref: 'BLTI001_Bundle', - }, - }, - cartridge_icon: { - $: { - identifierref: 'BLTI001_Icon', - }, - }, - }, - }, - }; - - switch (this.props.version) { - case CommonCartridgeVersion.V_1_3_0: - commonObject.cartridge_basiclti_link.$.xmlns = 'http://www.imsglobal.org/xsd/imslticc_v1p3'; - commonObject.cartridge_basiclti_link.$['xmlns:blti'] = 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0'; - commonObject.cartridge_basiclti_link.$['xmlns:lticm'] = 'http://www.imsglobal.org/xsd/imslticm_v1p0'; - commonObject.cartridge_basiclti_link.$['xmlns:lticp'] = 'http://www.imsglobal.org/xsd/imslticp_v1p0'; - commonObject.cartridge_basiclti_link.$['xsi:schemaLocation'] = - 'http://www.imsglobal.org/xsd/imslticc_v1p3 http://www.imsglobal.org/xsd/imslticc_v1p3.xsd' + - 'http://www.imsglobal.org/xsd/imslticp_v1p0 imslticp_v1p0.xsd' + - 'http://www.imsglobal.org/xsd/imslticm_v1p0 imslticm_v1p0.xsd' + - 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0 imsbasiclti_v1p0p1.xsd"'; - break; - default: - commonObject.cartridge_basiclti_link.$.xmlns = '/xsd/imslticc_v1p0'; - commonObject.cartridge_basiclti_link.$['xmlns:blti'] = '/xsd/imsbasiclti_v1p0'; - commonObject.cartridge_basiclti_link.$['xmlns:lticm'] = '/xsd/imslticm_v1p0'; - commonObject.cartridge_basiclti_link.$['xmlns:lticp'] = '/xsd/imslticp_v1p0'; - commonObject.cartridge_basiclti_link.$['xsi:schemaLocation'] = - '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd' + - '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd' + - '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd' + - '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd"'; - break; - } - - return this.xmlBuilder.buildObject(commonObject); - } - - transform(): Record { - return { - $: { - identifier: this.props.identifier, - type: this.props.type, - }, - file: { - $: { - href: this.props.href, - }, - }, - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-manifest-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-manifest-element.spec.ts deleted file mode 100644 index c6d681ab393..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-manifest-element.spec.ts +++ /dev/null @@ -1,149 +0,0 @@ -import { CommonCartridgeManifestElement } from './common-cartridge-manifest-element'; -import { CommonCartridgeVersion } from './common-cartridge-enums'; -import { ICommonCartridgeMetadataProps } from './common-cartridge-metadata-element'; - -describe('CommonCartridgeManifestElement', () => { - const metadataPropsV3: ICommonCartridgeMetadataProps = { - version: CommonCartridgeVersion.V_1_3_0, - title: 'title of test metadata v3', - copyrightOwners: 'test copy right', - creationYear: 'test year', - }; - - const metadataPropsV1: ICommonCartridgeMetadataProps = { - version: CommonCartridgeVersion.V_1_1_0, - title: 'title of test metadata v1', - copyrightOwners: 'test copy right', - creationYear: 'test year', - }; - - const props = { - identifier: 'manifest-1', - }; - describe('commen cartridge version 3', () => { - it('should transform the manifest based on the provided common cartridge version 3', () => { - const manifestElement = new CommonCartridgeManifestElement(props, metadataPropsV3, [], []); - const result = manifestElement.transform(); - - expect(result).toEqual({ - manifest: { - $: { - identifier: 'manifest-1', - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1', - 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest', - 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource', - 'xmlns:ext': 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lomresource_v1p0.xsd ' + - 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd ' + - 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_cpextensionv1p2_v1p0.xsd', - }, - metadata: { - schema: 'IMS Common Cartridge', - schemaversion: metadataPropsV3.version, - 'mnf:lom': { - 'mnf:general': { - 'mnf:title': { - 'mnf:string': metadataPropsV3.title, - }, - }, - 'mnf:rights': { - 'mnf:copyrightAndOtherRestrictions': { - 'mnf:value': 'yes', - }, - 'mnf:description': { - 'mnf:string': `${metadataPropsV3.creationYear} ${metadataPropsV3.copyrightOwners}`, - }, - }, - }, - }, - organizations: { - organization: [ - { - $: { - identifier: 'org-1', - structure: 'rooted-hierarchy', - }, - item: [ - { - $: { - identifier: 'LearningModules', - }, - item: [], - }, - ], - }, - ], - }, - resources: { - resource: [], - }, - }, - }); - }); - }); - describe('commen cartridge version 1', () => { - it('should transform the manifest based on the provided common cartridge version 1', () => { - const manifestElement = new CommonCartridgeManifestElement(props, metadataPropsV1, [], []); - const result = manifestElement.transform(); - - expect(result).toEqual({ - manifest: { - $: { - identifier: 'manifest-1', - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', - 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', - 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd ' + - 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ', - }, - metadata: { - schema: 'IMS Common Cartridge', - schemaversion: metadataPropsV1.version, - 'mnf:lom': { - 'mnf:general': { - 'mnf:title': { - 'mnf:string': metadataPropsV1.title, - }, - }, - 'mnf:rights': { - 'mnf:copyrightAndOtherRestrictions': { - 'mnf:value': 'yes', - }, - 'mnf:description': { - 'mnf:string': `${metadataPropsV1.creationYear} ${metadataPropsV1.copyrightOwners}`, - }, - }, - }, - }, - organizations: { - organization: [ - { - $: { - identifier: 'org-1', - structure: 'rooted-hierarchy', - }, - item: [ - { - $: { - identifier: 'LearningModules', - }, - item: [], - }, - ], - }, - ], - }, - resources: { - resource: [], - }, - }, - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-manifest-element.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-manifest-element.ts deleted file mode 100644 index 8e71b9adee4..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-manifest-element.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { CommonCartridgeElement } from './common-cartridge-element.interface'; -import { CommonCartridgeVersion } from './common-cartridge-enums'; -import { CommonCartridgeMetadataElement, ICommonCartridgeMetadataProps } from './common-cartridge-metadata-element'; -import { CommonCartridgeOrganizationWrapperElement } from './common-cartridge-organization-wrapper-element'; -import { CommonCartridgeResourceWrapperElement } from './common-cartridge-resource-wrapper-element'; - -export type ICommonCartridgeManifestProps = { - identifier: string; -}; - -export class CommonCartridgeManifestElement implements CommonCartridgeElement { - constructor( - private readonly props: ICommonCartridgeManifestProps, - private readonly metadataProps: ICommonCartridgeMetadataProps, - private readonly organizations: CommonCartridgeElement[], - private readonly resources: CommonCartridgeElement[] - ) {} - - transform(): Record { - const versionNumber = this.metadataProps.version; - switch (versionNumber) { - case CommonCartridgeVersion.V_1_3_0: - return { - manifest: { - $: { - identifier: this.props.identifier, - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1', - 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest', - 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource', - 'xmlns:ext': 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lomresource_v1p0.xsd ' + - 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd ' + - 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_cpextensionv1p2_v1p0.xsd', - }, - metadata: new CommonCartridgeMetadataElement(this.metadataProps).transform(), - organizations: new CommonCartridgeOrganizationWrapperElement(this.organizations).transform(), - resources: new CommonCartridgeResourceWrapperElement(this.resources).transform(), - }, - }; - default: - return { - manifest: { - $: { - identifier: this.props.identifier, - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', - 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', - 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd ' + - 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ', - }, - metadata: new CommonCartridgeMetadataElement(this.metadataProps).transform(), - organizations: new CommonCartridgeOrganizationWrapperElement(this.organizations).transform(), - resources: new CommonCartridgeResourceWrapperElement(this.resources).transform(), - }, - }; - } - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-metadata-element.spec.ts deleted file mode 100644 index 3e2f648eda0..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-metadata-element.spec.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { ICommonCartridgeMetadataProps, CommonCartridgeMetadataElement } from './common-cartridge-metadata-element'; -import { CommonCartridgeVersion } from './common-cartridge-enums'; - -describe('CommonCartridgeMetadataElement', () => { - describe('transform', () => { - it('should return correct metadata regardless of common cartridge version', () => { - const props: ICommonCartridgeMetadataProps = { - title: 'title of metadata', - copyrightOwners: 'owner of course', - creationYear: '2023', - version: CommonCartridgeVersion.V_1_1_0, - }; - - const metadata = new CommonCartridgeMetadataElement(props); - const transformed = metadata.transform(); - expect(transformed).toEqual({ - schema: 'IMS Common Cartridge', - schemaversion: props.version, - 'mnf:lom': { - 'mnf:general': { - 'mnf:title': { - 'mnf:string': props.title, - }, - }, - 'mnf:rights': { - 'mnf:copyrightAndOtherRestrictions': { - 'mnf:value': 'yes', - }, - 'mnf:description': { - 'mnf:string': `${props.creationYear} ${props.copyrightOwners}`, - }, - }, - }, - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-metadata-element.ts deleted file mode 100644 index 17a0cf45faa..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-metadata-element.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { CommonCartridgeElement } from './common-cartridge-element.interface'; -import { CommonCartridgeVersion } from './common-cartridge-enums'; - -export type ICommonCartridgeMetadataProps = { - title: string; - copyrightOwners: string; - creationYear: string; - version: CommonCartridgeVersion; -}; - -export class CommonCartridgeMetadataElement implements CommonCartridgeElement { - constructor(private readonly props: ICommonCartridgeMetadataProps) {} - - transform(): Record { - return { - schema: 'IMS Common Cartridge', - schemaversion: this.props.version, - 'mnf:lom': { - 'mnf:general': { - 'mnf:title': { - 'mnf:string': this.props.title, - }, - }, - 'mnf:rights': { - 'mnf:copyrightAndOtherRestrictions': { - 'mnf:value': 'yes', - }, - 'mnf:description': { - 'mnf:string': `${this.props.creationYear} ${this.props.copyrightOwners}`, - }, - }, - }, - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.spec.ts deleted file mode 100644 index 93d6329778b..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.spec.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { - CommonCartridgeOrganizationItemElementProps, - CommonCartridgeOrganizationItemElement, -} from './common-cartridge-organization-item-element'; -import { CommonCartridgeVersion, CommonCartridgeResourceType } from './common-cartridge-enums'; -import { ICommonCartridgeResourceProps } from './common-cartridge-resource-item-element'; - -describe('CommonCartridgeOrganizationItemElement', () => { - describe('transform', () => { - it('should return correct organization item element regardless of common cartridge version', () => { - const webContentResourceProps: ICommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_3_0, - identifier: 'web-link', - href: 'https://example.com/link', - title: 'Web Link', - html: 'html tags for testing', - }; - const props: CommonCartridgeOrganizationItemElementProps = { - identifier: 'identifier', - title: 'title of organization item element', - version: 'version of common cartridge', - resources: [webContentResourceProps], - _tag: 'resourceCollection', - }; - const organizationItemElement = new CommonCartridgeOrganizationItemElement(props); - const transformed = organizationItemElement.transform(); - expect(transformed).toEqual({ - $: { - identifier: props.identifier, - }, - title: props.title, - item: [ - { - $: { - identifier: expect.any(String), - identifierref: webContentResourceProps.identifier, - }, - title: webContentResourceProps.title, - }, - ], - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts deleted file mode 100644 index ec0fc285546..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-item-element.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { CommonCartridgeElement } from './common-cartridge-element.interface'; -import { ICommonCartridgeResourceProps } from './common-cartridge-resource-item-element'; -import { createIdentifier } from './utils'; - -export type OrganizationItemCollection = { - title: string; - children: OrganizationItemCollection[] | OrganizationResourceCollection; - _tag: 'itemCollection'; -}; - -export type OrganizationResourceCollection = { - identifier: string; - title: string; - version: string; - resources: ICommonCartridgeResourceProps[]; - _tag: 'resourceCollection'; -}; - -export type CommonCartridgeOrganizationItemElementProps = OrganizationItemCollection | OrganizationResourceCollection; - -function isOrganizationItemCollection( - item: CommonCartridgeOrganizationItemElementProps -): item is OrganizationItemCollection { - return item._tag === 'itemCollection'; -} - -function isOrganizationResourceCollection( - item: CommonCartridgeOrganizationItemElementProps -): item is OrganizationResourceCollection { - return item._tag === 'resourceCollection'; -} - -function isOrganizationItemCollectionArray( - children: OrganizationItemCollection[] | OrganizationResourceCollection -): children is OrganizationItemCollection[] { - return Array.isArray(children); -} - -function createRecordForResourceCollection( - resourceCollection: OrganizationResourceCollection -): Record { - return { - $: { - identifier: resourceCollection.identifier, - }, - title: resourceCollection.title, - item: resourceCollection.resources.map((content) => { - return { - $: { - identifier: createIdentifier(), - identifierref: content.identifier, - }, - title: content.title, - }; - }), - }; -} - -export class CommonCartridgeOrganizationItemElement implements CommonCartridgeElement { - constructor(private readonly props: CommonCartridgeOrganizationItemElementProps) {} - - transform(): Record { - if (isOrganizationItemCollection(this.props) && isOrganizationItemCollectionArray(this.props.children)) { - return { - $: { - identifier: createIdentifier(), - }, - title: this.props.title, - item: this.props.children.map((child) => new CommonCartridgeOrganizationItemElement(child).transform()), - }; - } - - if (isOrganizationItemCollection(this.props) && !isOrganizationItemCollectionArray(this.props.children)) { - return createRecordForResourceCollection(this.props.children); - } - - if (isOrganizationResourceCollection(this.props)) { - return createRecordForResourceCollection(this.props); - } - - return {}; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-wrapper-element.spec.ts deleted file mode 100644 index a26e40bc37c..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-wrapper-element.spec.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { CommonCartridgeElement } from './common-cartridge-element.interface'; -import { CommonCartridgeOrganizationWrapperElement } from './common-cartridge-organization-wrapper-element'; - -describe('CommonCartridgeOrganizationWrapperElement', () => { - it('should transform the organization elements into the expected structure', () => { - const organizationElementsMock: CommonCartridgeElement[] = [ - { - transform: jest.fn().mockReturnValue({ identifier: 'element-1' }), - }, - { - transform: jest.fn().mockReturnValue({ identifier: 'element-2' }), - }, - ]; - - const organizationWrapperElement = new CommonCartridgeOrganizationWrapperElement(organizationElementsMock); - const result = organizationWrapperElement.transform(); - - expect(result).toEqual({ - organization: [ - { - $: { - identifier: 'org-1', - structure: 'rooted-hierarchy', - }, - item: [ - { - $: { - identifier: 'LearningModules', - }, - item: [{ identifier: 'element-1' }, { identifier: 'element-2' }], - }, - ], - }, - ], - }); - - expect(organizationElementsMock[0].transform).toHaveBeenCalled(); - expect(organizationElementsMock[1].transform).toHaveBeenCalled(); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-wrapper-element.ts deleted file mode 100644 index 34200b31e37..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-organization-wrapper-element.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { CommonCartridgeElement } from './common-cartridge-element.interface'; - -export class CommonCartridgeOrganizationWrapperElement implements CommonCartridgeElement { - constructor(private readonly organizationElements: CommonCartridgeElement[]) {} - - transform(): Record { - return { - organization: [ - { - $: { - identifier: 'org-1', - structure: 'rooted-hierarchy', - }, - item: [ - { - $: { - identifier: 'LearningModules', - }, - item: this.organizationElements.map((organizationElement) => organizationElement.transform()), - }, - ], - }, - ], - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-item-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-item-element.spec.ts deleted file mode 100644 index 0c32f9de0b5..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-item-element.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Builder } from 'xml2js'; -import { - CommonCartridgeResourceItemElement, - ICommonCartridgeResourceProps, -} from './common-cartridge-resource-item-element'; - -describe('CommonCartridgeResourceItemElement', () => { - describe('when creating a common cartridge resouce with unkown type', () => { - it('should throw an error', () => { - expect( - () => new CommonCartridgeResourceItemElement({} as ICommonCartridgeResourceProps, new Builder()) - ).toThrowError(); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-item-element.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-item-element.ts deleted file mode 100644 index 219e7296075..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-item-element.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Builder } from 'xml2js'; -import { CommonCartridgeElement } from './common-cartridge-element.interface'; -import { CommonCartridgeResourceType } from './common-cartridge-enums'; -import { CommonCartridgeFile } from './common-cartridge-file.interface'; -import { CommonCartridgeLtiResource, ICommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; -import { - CommonCartridgeWebContentResource, - ICommonCartridgeWebContentResourceProps, -} from './common-cartridge-web-content-resource'; -import { - CommonCartridgeWebLinkResourceElement, - ICommonCartridgeWebLinkResourceProps, -} from './common-cartridge-web-link-resource'; - -export type ICommonCartridgeResourceProps = - | ICommonCartridgeLtiResourceProps - | ICommonCartridgeWebContentResourceProps - | ICommonCartridgeWebLinkResourceProps; - -export class CommonCartridgeResourceItemElement implements CommonCartridgeElement, CommonCartridgeFile { - private readonly inner: CommonCartridgeElement & CommonCartridgeFile; - - constructor(props: ICommonCartridgeResourceProps, xmlBuilder: Builder) { - if (props.type === CommonCartridgeResourceType.LTI) { - this.inner = new CommonCartridgeLtiResource(props, xmlBuilder); - } else if (props.type === CommonCartridgeResourceType.WEB_CONTENT) { - this.inner = new CommonCartridgeWebContentResource(props); - } else if ( - props.type === CommonCartridgeResourceType.WEB_LINK_V1 || - props.type === CommonCartridgeResourceType.WEB_LINK_V3 - ) { - this.inner = new CommonCartridgeWebLinkResourceElement(props, xmlBuilder); - } else { - throw new Error('Resource type is unknown!'); - } - } - - canInline(): boolean { - return this.inner.canInline(); - } - - content(): string { - return this.inner.content(); - } - - transform(): Record { - return this.inner.transform(); - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-wrapper-element.spec.ts deleted file mode 100644 index cd96c9d6784..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-wrapper-element.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { CommonCartridgeElement } from './common-cartridge-element.interface'; -import { CommonCartridgeResourceWrapperElement } from './common-cartridge-resource-wrapper-element'; - -describe('CommonCartridgeResourceWrapperElement', () => { - it('should transform the resource elements into an array of transformed objects', () => { - const resourceElementsMock: CommonCartridgeElement[] = [ - { - transform: jest.fn().mockReturnValue({ identifier: 'resource-1' }), - }, - { - transform: jest.fn().mockReturnValue({ identifier: 'resource-2' }), - }, - ]; - - const resourceWrapperElement = new CommonCartridgeResourceWrapperElement(resourceElementsMock); - const result = resourceWrapperElement.transform(); - - expect(result).toEqual({ - resource: [{ identifier: 'resource-1' }, { identifier: 'resource-2' }], - }); - - expect(resourceElementsMock[0].transform).toHaveBeenCalled(); - expect(resourceElementsMock[1].transform).toHaveBeenCalled(); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-wrapper-element.ts deleted file mode 100644 index c188651f3d4..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-resource-wrapper-element.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { CommonCartridgeElement } from './common-cartridge-element.interface'; - -export class CommonCartridgeResourceWrapperElement implements CommonCartridgeElement { - constructor(private readonly resourceElements: CommonCartridgeElement[]) {} - - transform(): Record { - return { - resource: this.resourceElements.map((resourceElement) => resourceElement.transform()), - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-content-resource.spec.ts deleted file mode 100644 index 5bcb07c0b2f..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-content-resource.spec.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { CommonCartridgeVersion, CommonCartridgeResourceType } from './common-cartridge-enums'; -import { - ICommonCartridgeWebContentResourceProps, - CommonCartridgeWebContentResource, -} from './common-cartridge-web-content-resource'; - -describe('CommonCartridgeWebContentResource', () => { - const props: ICommonCartridgeWebContentResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_3_0, - identifier: 'web-link', - href: 'https://example.com/link', - title: 'Web Link', - html: 'html tages for testing', - }; - const webContentResource = new CommonCartridgeWebContentResource(props); - describe('content', () => { - it('should return html content regardless of common cartridge version', () => { - const content = webContentResource.content(); - expect(content).toContain(props.html); - }); - }); - describe('canInline', () => { - it('check the return value of the method Can Inline ', () => { - expect(webContentResource.canInline()).toBe(false); - }); - }); - describe('transform', () => { - it('should transform XML content regardless of common cartridge version', () => { - const transformed = webContentResource.transform(); - expect(webContentResource.canInline()).toBe(false); - expect(transformed).toEqual({ - $: { - identifier: props.identifier, - type: props.type, - intendeduse: 'unspecified', - }, - file: { - $: { - href: props.href, - }, - }, - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-content-resource.ts deleted file mode 100644 index c45b981184f..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-content-resource.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { CommonCartridgeElement } from './common-cartridge-element.interface'; -import { - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from './common-cartridge-enums'; -import { CommonCartridgeFile } from './common-cartridge-file.interface'; - -export type ICommonCartridgeWebContentResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT; - version: CommonCartridgeVersion; - identifier: string; - href: string; - title: string; - html: string; - intendedUse?: CommonCartridgeIntendedUseType; -}; - -export class CommonCartridgeWebContentResource implements CommonCartridgeElement, CommonCartridgeFile { - constructor(private readonly props: ICommonCartridgeWebContentResourceProps) {} - - canInline(): boolean { - return false; - } - - content(): string { - return this.props.html; - } - - transform(): Record { - return { - $: { - identifier: this.props.identifier, - type: this.props.type, - intendeduse: this.props.intendedUse ?? CommonCartridgeIntendedUseType.UNSPECIFIED, - }, - file: { - $: { - href: this.props.href, - }, - }, - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-link-resource.spec.ts deleted file mode 100644 index cd5c374df60..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-link-resource.spec.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { Builder } from 'xml2js'; -import { CommonCartridgeVersion, CommonCartridgeResourceType } from './common-cartridge-enums'; -import { - ICommonCartridgeWebLinkResourceProps, - CommonCartridgeWebLinkResourceElement, -} from './common-cartridge-web-link-resource'; - -describe('CommonCartridgeWebLinkResourceElement', () => { - const xmlBuilder = new Builder(); - const propsOfV3: ICommonCartridgeWebLinkResourceProps = { - type: CommonCartridgeResourceType.WEB_LINK_V3, - version: CommonCartridgeVersion.V_1_3_0, - identifier: 'web-link-v3', - href: 'https://example.com/linkv3', - title: 'Web Link v3', - url: 'https://example.com/linkv3', - }; - const propsOfV1: ICommonCartridgeWebLinkResourceProps = { - type: CommonCartridgeResourceType.WEB_LINK_V1, - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'web-link-v1', - href: 'https://example.com/link1', - title: 'Web Link v1', - url: 'https://example.com/link1', - }; - - describe('CommonCartridgeWebLinkResourceElement of version 3', () => { - it('should return XML content of common cartridge version 3', () => { - const webLinkResource = new CommonCartridgeWebLinkResourceElement(propsOfV3, xmlBuilder); - const content = webLinkResource.content(); - const transformed = webLinkResource.transform(); - - expect(content).toContain('webLink'); - expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); - expect(content).toContain('http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3'); - expect(content).toContain('http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd'); - expect(transformed).toEqual({ - $: { - identifier: propsOfV3.identifier, - type: propsOfV3.type, - }, - file: { - $: { - href: propsOfV3.href, - }, - }, - }); - expect(webLinkResource.canInline()).toBe(false); - }); - }); - - describe('CommonCartridgeWebLinkResourceElement of version 1', () => { - it('should return XML content of common cartridge version 1', () => { - const webLinkResource = new CommonCartridgeWebLinkResourceElement(propsOfV1, xmlBuilder); - const content = webLinkResource.content(); - const transformed = webLinkResource.transform(); - - expect(content).toContain('webLink'); - expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); - expect(content).toContain('http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1'); - expect(content).toContain( - 'https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd' - ); - expect(transformed).toEqual({ - $: { - identifier: propsOfV1.identifier, - type: propsOfV1.type, - }, - file: { - $: { - href: propsOfV1.href, - }, - }, - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-link-resource.ts deleted file mode 100644 index 09184d5ef0f..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge-web-link-resource.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { Builder } from 'xml2js'; -import { CommonCartridgeElement } from './common-cartridge-element.interface'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from './common-cartridge-enums'; -import { CommonCartridgeFile } from './common-cartridge-file.interface'; - -export type ICommonCartridgeWebLinkResourceProps = { - type: CommonCartridgeResourceType.WEB_LINK_V1 | CommonCartridgeResourceType.WEB_LINK_V3; - version: CommonCartridgeVersion; - identifier: string; - href: string; - title: string; - url: string; -}; - -export class CommonCartridgeWebLinkResourceElement implements CommonCartridgeElement, CommonCartridgeFile { - constructor(private readonly props: ICommonCartridgeWebLinkResourceProps, private readonly xmlBuilder: Builder) {} - - canInline(): boolean { - return false; - } - - content(): string { - const commonTags = { - title: this.props.title, - url: { - $: { - href: this.props.url, - target: '_self', - windowFeatures: 'width=100, height=100', - }, - }, - }; - switch (this.props.version) { - case CommonCartridgeVersion.V_1_3_0: - return this.xmlBuilder.buildObject({ - webLink: { - ...commonTags, - $: { - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd', - }, - }, - }); - default: - return this.xmlBuilder.buildObject({ - webLink: { - ...commonTags, - $: { - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', - }, - }, - }); - } - } - - transform(): Record { - return { - $: { - identifier: this.props.identifier, - type: this.props.type, - }, - file: { - $: { - href: this.props.href, - }, - }, - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts deleted file mode 100644 index afbff1098a5..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface CommonCartridgeConfig { - FEATURE_IMSCC_COURSE_EXPORT_ENABLED: boolean; -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/common-cartridge.enums.ts rename to apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-metadata-element.ts rename to apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-organization-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-organization-element.ts rename to apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-organizations-wrapper-element.ts rename to apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/elements/common-cartridge-resources-wrapper-element.ts rename to apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/index.ts b/apps/server/src/modules/learnroom/common-cartridge/index.ts index ed0b36becf1..ad48a87feb6 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/index.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/index.ts @@ -1,14 +1,2 @@ -export * from './common-cartridge-element.interface'; -export * from './common-cartridge-enums'; -export * from './common-cartridge-file-builder'; -export * from './common-cartridge-file.interface'; -export * from './common-cartridge-lti-resource'; -export * from './common-cartridge-manifest-element'; -export * from './common-cartridge-metadata-element'; -export * from './common-cartridge-organization-item-element'; -export * from './common-cartridge-organization-wrapper-element'; -export * from './common-cartridge-resource-item-element'; -export * from './common-cartridge-resource-wrapper-element'; -export * from './common-cartridge-web-content-resource'; -export * from './common-cartridge-web-link-resource'; -export * from './common-cartridge.config'; +export * from './builders/common-cartridge-file-builder'; +export * from './common-cartridge.enums'; diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element.interface.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-element.interface.ts rename to apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element.interface.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource.interface.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/interfaces/common-cartridge-resource.interface.ts rename to apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource.interface.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.spec.ts rename to apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-lti-resource.ts rename to apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-manifest-resource.ts rename to apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.spec.ts rename to apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-resource-factory.ts rename to apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.spec.ts rename to apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-content-resource.ts rename to apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.spec.ts rename to apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/resources/common-cartridge-web-link-resource.ts rename to apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts deleted file mode 100644 index ad48a87feb6..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './builders/common-cartridge-file-builder'; -export * from './common-cartridge.enums'; diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts deleted file mode 100644 index 5fc348fa8b0..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Builder } from 'xml2js'; -import { CommonCartridgeVersion } from './common-cartridge.enums'; - -export type OmitVersion = Omit; - -export type OmitVersionAndFolder = Omit; - -const xmlBuilder = new Builder({ headless: true }); - -export function buildXmlString(obj: unknown): string { - return xmlBuilder.buildObject(obj); -} - -export function createVersionNotSupportedError(version: CommonCartridgeVersion): Error { - return new Error(`Version ${version} is not supported`); -} - -export function checkCommonCartridgeVersion(version: CommonCartridgeVersion): void | never { - const supportedVersions = [CommonCartridgeVersion.V_1_1, CommonCartridgeVersion.V_1_3]; - - if (supportedVersions.includes(version)) { - return; - } - - throw createVersionNotSupportedError(version); -} - -export function checkDefined(value: T | undefined | null, name: string): T | never { - if (value) { - return value; - } - - throw new Error(`${name} is null or undefined`); -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/utils.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/temp/utils.spec.ts rename to apps/server/src/modules/learnroom/common-cartridge/utils.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.ts index b83f8ec220a..5fc348fa8b0 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/utils.ts @@ -1,6 +1,34 @@ -import { ObjectId } from 'bson'; - -export function createIdentifier(id?: string | ObjectId): string { - id = id ?? new ObjectId(); - return `i${id.toString()}`; -} +import { Builder } from 'xml2js'; +import { CommonCartridgeVersion } from './common-cartridge.enums'; + +export type OmitVersion = Omit; + +export type OmitVersionAndFolder = Omit; + +const xmlBuilder = new Builder({ headless: true }); + +export function buildXmlString(obj: unknown): string { + return xmlBuilder.buildObject(obj); +} + +export function createVersionNotSupportedError(version: CommonCartridgeVersion): Error { + return new Error(`Version ${version} is not supported`); +} + +export function checkCommonCartridgeVersion(version: CommonCartridgeVersion): void | never { + const supportedVersions = [CommonCartridgeVersion.V_1_1, CommonCartridgeVersion.V_1_3]; + + if (supportedVersions.includes(version)) { + return; + } + + throw createVersionNotSupportedError(version); +} + +export function checkDefined(value: T | undefined | null, name: string): T | never { + if (value) { + return value; + } + + throw new Error(`${name} is null or undefined`); +} From 0229862cc6409ddd76a03dfd09d6d2b2103e8d73 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 30 Nov 2023 14:13:28 +0100 Subject: [PATCH 031/177] EW-539 renaming cc versions enum --- .../builders/common-cartridge-file-builder.spec.ts | 2 +- .../common-cartridge-organization-builder.spec.ts | 6 +++--- .../common-cartridge/common-cartridge.enums.ts | 10 +++++----- .../src/modules/learnroom/common-cartridge/index.ts | 1 + .../resources/common-cartridge-lti-resource.spec.ts | 4 ++-- .../resources/common-cartridge-lti-resource.ts | 4 ++-- .../resources/common-cartridge-manifest-resource.ts | 8 ++++---- .../common-cartridge-resource-factory.spec.ts | 2 +- .../common-cartridge-web-content-resource.spec.ts | 2 +- .../common-cartridge-web-link-resource.spec.ts | 4 ++-- .../resources/common-cartridge-web-link-resource.ts | 4 ++-- .../modules/learnroom/common-cartridge/utils.spec.ts | 8 ++++---- .../src/modules/learnroom/common-cartridge/utils.ts | 2 +- 13 files changed, 29 insertions(+), 28 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts index c8c08e685f8..ea5ad639ea0 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts @@ -13,7 +13,7 @@ describe('CommonCartridgeFileBuilder', () => { const getFileContentAsString = (zip: AdmZip, path: string): string | undefined => zip.getEntry(path)?.getData().toString(); const fileBuilderOptions: CommonCartridgeFileBuilderProps = { - version: CommonCartridgeVersion.V_1_1, + version: CommonCartridgeVersion.V_1_1_0, identifier: 'manifest-identifier', }; const metadataProps: OmitVersion = { diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts index 27ca2816f2b..236bcb9b1fb 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts @@ -15,17 +15,17 @@ describe('CommonCartridgeOrganizationBuilder', () => { const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { title: 'organization-title', identifier: 'organization-identifier', - version: CommonCartridgeVersion.V_1_1, + version: CommonCartridgeVersion.V_1_1_0, }; const subOrganizationOptions: CommonCartridgeOrganizationBuilderOptions = { title: 'sub-organization-title', identifier: 'sub-organization-identifier', - version: CommonCartridgeVersion.V_1_1, + version: CommonCartridgeVersion.V_1_1_0, }; const subSubOrganizationOptions: CommonCartridgeOrganizationBuilderOptions = { title: 'sub-sub-organization-title', identifier: 'sub-sub-organization-identifier', - version: CommonCartridgeVersion.V_1_1, + version: CommonCartridgeVersion.V_1_1_0, }; const resource1Props: CommonCartridgeResourceProps = { type: CommonCartridgeResourceType.WEB_CONTENT, diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts index a12024283ad..0b03cdbdc09 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts @@ -1,9 +1,9 @@ export enum CommonCartridgeVersion { - V_1_0 = '1.0.0', - V_1_1 = '1.1.0', - V_1_2 = '1.2.0', - V_1_3 = '1.3.0', - V_1_4 = '1.4.0', + V_1_0_0 = '1.0.0', + V_1_1_0 = '1.1.0', + V_1_2_0 = '1.2.0', + V_1_3_0 = '1.3.0', + V_1_4_0 = '1.4.0', } export enum CommonCartridgeResourceType { diff --git a/apps/server/src/modules/learnroom/common-cartridge/index.ts b/apps/server/src/modules/learnroom/common-cartridge/index.ts index ad48a87feb6..6f7d524f290 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/index.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/index.ts @@ -1,2 +1,3 @@ export * from './builders/common-cartridge-file-builder'; export * from './common-cartridge.enums'; +export { CommonCartridgeResourceProps } from './resources/common-cartridge-resource-factory'; diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts index 6dc8cf1332a..95b0e673fde 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts @@ -4,7 +4,7 @@ import { CommonCartridgeLtiResource, CommonCartridgeLtiResourceProps } from './c describe('CommonCartridgeLtiResource', () => { const propsVersion1: CommonCartridgeLtiResourceProps = { type: CommonCartridgeResourceType.LTI, - version: CommonCartridgeVersion.V_1_1, + version: CommonCartridgeVersion.V_1_1_0, identifier: 'lti-identifier-version1', folder: 'lti-identifier-version1/lti.xml', title: 'lti-title-version1', @@ -14,7 +14,7 @@ describe('CommonCartridgeLtiResource', () => { const propsVersion3: CommonCartridgeLtiResourceProps = { type: CommonCartridgeResourceType.LTI, - version: CommonCartridgeVersion.V_1_3, + version: CommonCartridgeVersion.V_1_3_0, identifier: 'lti-identifier-version3', folder: 'lti-identifier-version3/lti.xml', title: 'lti-title-version3', diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts index ccb1b9b1217..758426807a2 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts @@ -63,7 +63,7 @@ export class CommonCartridgeLtiResource implements CommonCartridgeResource { private getXmlNamespacesByVersion(): Record { switch (this.props.version) { - case CommonCartridgeVersion.V_1_1: + case CommonCartridgeVersion.V_1_1_0: return { xmlns: '/xsd/imslticc_v1p0', 'xmlns:blti': '/xsd/imsbasiclti_v1p0', @@ -75,7 +75,7 @@ export class CommonCartridgeLtiResource implements CommonCartridgeResource { '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd' + '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd"', }; - case CommonCartridgeVersion.V_1_3: + case CommonCartridgeVersion.V_1_3_0: return { xmlns: 'http://www.imsglobal.org/xsd/imslticc_v1p3', 'xmlns:blti': 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0', diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts index 5b5af84844a..d83f8eba2c1 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts @@ -1,9 +1,9 @@ import { Builder } from 'xml2js'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { CommonCartridgeOrganizationsWrapperElement } from '../elements/common-cartridge-organizations-wrapper-element'; import { CommonCartridgeResourcesWrapperElement } from '../elements/common-cartridge-resources-wrapper-element'; +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { createVersionNotSupportedError } from '../utils'; type CommonCartridgeManifestElementProps = { @@ -46,7 +46,7 @@ export class CommonCartridgeManifestResource implements CommonCartridgeResource private getXmlNamespacesByVersion(): Record { switch (this.props.version) { - case CommonCartridgeVersion.V_1_1: + case CommonCartridgeVersion.V_1_1_0: return { identifier: this.props.identifier, xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1', @@ -60,7 +60,7 @@ export class CommonCartridgeManifestResource implements CommonCartridgeResource 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd ' + 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_cpextensionv1p2_v1p0.xsd', }; - case CommonCartridgeVersion.V_1_3: + case CommonCartridgeVersion.V_1_3_0: return { identifier: this.props.identifier, xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts index cab3290c7ea..bf9aecaab60 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts @@ -5,7 +5,7 @@ import { CommonCartridgeWebContentResource } from './common-cartridge-web-conten import { CommonCartridgeWebLinkResource } from './common-cartridge-web-link-resource'; describe('CommonCartridgeResourceFactory', () => { - const versionAndFolderProps = { version: CommonCartridgeVersion.V_1_1, folder: 'folder' }; + const versionAndFolderProps = { version: CommonCartridgeVersion.V_1_1_0, folder: 'folder' }; describe('create', () => { // AI next 14 lines diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts index 19be3bed985..e0107f534de 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts @@ -7,7 +7,7 @@ import { describe('CommonCartridgeWebContentResource', () => { const props: CommonCartridgeWebContentResourceProps = { type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_3, + version: CommonCartridgeVersion.V_1_3_0, identifier: 'web-link', folder: 'https://example.com/link', title: 'Web Link', diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts index 8fe08939f72..eeba1c7992a 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts @@ -7,7 +7,7 @@ import { describe('CommonCartridgeWebLinkResource', () => { const propsOfV3: CommonCartridgeWebLinkResourceProps = { type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_3, + version: CommonCartridgeVersion.V_1_3_0, identifier: 'web-link-v3', folder: 'https://example.com/linkv3', title: 'Web Link v3', @@ -16,7 +16,7 @@ describe('CommonCartridgeWebLinkResource', () => { const propsOfV1: CommonCartridgeWebLinkResourceProps = { type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_1, + version: CommonCartridgeVersion.V_1_1_0, identifier: 'web-link-v1', folder: 'https://example.com/link1', title: 'Web Link v1', diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts index 135ee590806..787c4d5e31a 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts @@ -54,14 +54,14 @@ export class CommonCartridgeWebLinkResource implements CommonCartridgeResource { private getXmlNamespacesByVersion(): Record { switch (this.props.version) { - case CommonCartridgeVersion.V_1_1: + case CommonCartridgeVersion.V_1_1_0: return { xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', }; - case CommonCartridgeVersion.V_1_3: + case CommonCartridgeVersion.V_1_3_0: return { xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.spec.ts index fac2d2a7c2e..4a23c26971f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/utils.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/utils.spec.ts @@ -13,7 +13,7 @@ describe('CommonCartridgeUtils', () => { describe('createVersionNotSupportedError', () => { describe('when creating error', () => { it('should return error with message', () => { - const error = createVersionNotSupportedError(CommonCartridgeVersion.V_1_0); + const error = createVersionNotSupportedError(CommonCartridgeVersion.V_1_0_0); expect(error).toBeDefined(); expect(error.message).toBe('Version 1.0.0 is not supported'); @@ -25,12 +25,12 @@ describe('CommonCartridgeUtils', () => { describe('checkCommonCartridgeVersion', () => { describe('when checking version', () => { it('should not throw error when version is supported', () => { - expect(() => checkCommonCartridgeVersion(CommonCartridgeVersion.V_1_1)).not.toThrow(); + expect(() => checkCommonCartridgeVersion(CommonCartridgeVersion.V_1_1_0)).not.toThrow(); }); it('should throw error when version is not supported', () => { - expect(() => checkCommonCartridgeVersion(CommonCartridgeVersion.V_1_0)).toThrow( - createVersionNotSupportedError(CommonCartridgeVersion.V_1_0) + expect(() => checkCommonCartridgeVersion(CommonCartridgeVersion.V_1_0_0)).toThrow( + createVersionNotSupportedError(CommonCartridgeVersion.V_1_0_0) ); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.ts index 5fc348fa8b0..59d11d46841 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/utils.ts @@ -16,7 +16,7 @@ export function createVersionNotSupportedError(version: CommonCartridgeVersion): } export function checkCommonCartridgeVersion(version: CommonCartridgeVersion): void | never { - const supportedVersions = [CommonCartridgeVersion.V_1_1, CommonCartridgeVersion.V_1_3]; + const supportedVersions = [CommonCartridgeVersion.V_1_1_0, CommonCartridgeVersion.V_1_3_0]; if (supportedVersions.includes(version)) { return; From 6932790fb2455bde911bfc17dd4995c263aca2c3 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 30 Nov 2023 16:10:00 +0100 Subject: [PATCH 032/177] EW-539 refactoring of cc export service --- .../learnroom/common-cartridge/index.ts | 3 + .../mapper/common-cartridge.mapper.ts | 96 +++++++++++ .../common-cartridge-export.service.ts | 160 +++--------------- 3 files changed, 124 insertions(+), 135 deletions(-) create mode 100644 apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/index.ts b/apps/server/src/modules/learnroom/common-cartridge/index.ts index 6f7d524f290..8dfd72fd85e 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/index.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/index.ts @@ -1,3 +1,6 @@ export * from './builders/common-cartridge-file-builder'; +export * from './builders/common-cartridge-organization-builder'; export * from './common-cartridge.enums'; +export { CommonCartridgeMetadataElementProps } from './elements/common-cartridge-metadata-element'; export { CommonCartridgeResourceProps } from './resources/common-cartridge-resource-factory'; +export { OmitVersion } from './utils'; diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts new file mode 100644 index 00000000000..8baa401f876 --- /dev/null +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -0,0 +1,96 @@ +import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain'; +import { ObjectId } from 'bson'; +import { + CommonCartridgeIntendedUseType, + CommonCartridgeMetadataElementProps, + CommonCartridgeOrganizationBuilderOptions, + CommonCartridgeResourceProps, + CommonCartridgeResourceType, + CommonCartridgeVersion, + OmitVersion, +} from '../common-cartridge'; + +export class CommonCartridgeMapper { + static mapCourseToMetadata(course: Course): OmitVersion { + return { + title: course.name, + copyrightOwners: course.teachers.toArray().map((teacher) => `${teacher.firstName} ${teacher.lastName}`), + creationDate: course.createdAt, + }; + } + + static mapLessonToOrganization(lesson: LessonEntity): OmitVersion { + return { + identifier: lesson.id, + title: lesson.name, + }; + } + + static mapContentToOrganization( + content: ComponentProperties + ): OmitVersion { + return { + identifier: content._id || new ObjectId().toHexString(), + title: content.title, + }; + } + + static mapTaskToResource(task: Task, version: CommonCartridgeVersion): CommonCartridgeResourceProps { + return { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: task.id, + title: task.name, + html: `

${task.name}

${task.description}

`, + intendedUse: + version === CommonCartridgeVersion.V_1_1_0 + ? CommonCartridgeIntendedUseType.UNSPECIFIED + : CommonCartridgeIntendedUseType.ASSIGNMENT, + }; + } + + static mapContentToResources( + content: ComponentProperties, + version: CommonCartridgeVersion + ): CommonCartridgeResourceProps | CommonCartridgeResourceProps[] { + switch (content.component) { + case ComponentType.TEXT: + return { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: content._id || new ObjectId().toHexString(), + title: content.title, + html: `

${content.title}

${content.content.text}

`, + intendedUse: + version === CommonCartridgeVersion.V_1_1_0 + ? CommonCartridgeIntendedUseType.UNSPECIFIED + : CommonCartridgeIntendedUseType.ASSIGNMENT, + }; + case ComponentType.GEOGEBRA: + return { + type: CommonCartridgeResourceType.WEB_LINK, + identifier: content._id || new ObjectId().toHexString(), + title: content.title, + url: `https://www.geogebra.org/m/${content.content.materialId}`, // FIXME: hardcoded hostname + }; + case ComponentType.ETHERPAD: + return { + type: CommonCartridgeResourceType.WEB_LINK, + identifier: content._id || new ObjectId().toHexString(), + title: `${content.content.title} - ${content.content.description}`, + url: content.content.url, + }; + case ComponentType.LERNSTORE: + return ( + content.content?.resources.map((resource) => { + return { + type: CommonCartridgeResourceType.WEB_LINK, + identifier: content._id || new ObjectId().toHexString(), + title: resource.description, + url: resource.url, + }; + }) || [] + ); + default: + return []; + } + } +} diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 5dab8915684..c08f809183f 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -1,18 +1,10 @@ import { LessonService } from '@modules/lesson'; import { TaskService } from '@modules/task'; import { Injectable } from '@nestjs/common'; -import { ComponentProperties, Course, EntityId, Task } from '@shared/domain'; -import { ComponentType } from '@src/shared/domain/entity/lesson.entity'; -import { - CommonCartridgeFileBuilder, - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, - ICommonCartridgeOrganizationBuilder, - ICommonCartridgeResourceProps, - ICommonCartridgeWebContentResourceProps, -} from '../common-cartridge'; -import { createIdentifier } from '../common-cartridge/utils'; +import { EntityId } from '@shared/domain'; +import { ObjectId } from 'bson'; +import { CommonCartridgeFileBuilder, CommonCartridgeVersion } from '../common-cartridge'; +import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; import { CourseService } from './course.service'; @Injectable() @@ -26,13 +18,12 @@ export class CommonCartridgeExportService { async exportCourse(courseId: EntityId, userId: EntityId, version: CommonCartridgeVersion): Promise { const course = await this.courseService.findById(courseId); const builder = new CommonCartridgeFileBuilder({ - identifier: createIdentifier(courseId), - title: course.name, + identifier: courseId, version, - copyrightOwners: this.mapCourseTeachersToCopyrightOwners(course), - creationYear: course.createdAt.getFullYear().toString(), }); + builder.addMetadata(CommonCartridgeMapper.mapCourseToMetadata(course)); + await this.addLessons(builder, version, courseId); await this.addTasks(builder, version, courseId, userId); @@ -47,18 +38,23 @@ export class CommonCartridgeExportService { const [lessons] = await this.lessonService.findByCourseIds([courseId]); lessons.forEach((lesson) => { - const organizationBuilder = builder.addOrganization({ - version, - identifier: createIdentifier(lesson.id), - title: lesson.name, - resources: [], - _tag: 'resourceCollection', - }); + const organizationBuilder = builder.addOrganization(CommonCartridgeMapper.mapLessonToOrganization(lesson)); lesson.contents.forEach((content) => { - const resourceProps = this.mapContentToResource(lesson.id, content, version, organizationBuilder); - if (resourceProps) { - organizationBuilder.addResourceToOrganization(resourceProps); + const resources = CommonCartridgeMapper.mapContentToResources(content, version); + + if (!Array.isArray(resources)) { + organizationBuilder.addResource(resources); + } + + if (Array.isArray(resources)) { + const subOrganizationBuilder = organizationBuilder.addSubOrganization( + CommonCartridgeMapper.mapContentToOrganization(content) + ); + + resources.forEach((resource) => { + subOrganizationBuilder.addResource(resource); + }); } }); }); @@ -72,118 +68,12 @@ export class CommonCartridgeExportService { ): Promise { const [tasks] = await this.taskService.findBySingleParent(userId, courseId); const organizationBuilder = builder.addOrganization({ - version, - identifier: createIdentifier(), - // FIXME: change the title for tasks organization - title: '', - resources: [], - _tag: 'resourceCollection', + identifier: new ObjectId().toHexString(), + title: '', // FIXME: add title }); tasks.forEach((task) => { - organizationBuilder.addResourceToOrganization(this.mapTaskToWebContentResource(task, version)); + organizationBuilder.addResource(CommonCartridgeMapper.mapTaskToResource(task, version)); }); } - - private mapContentToResource( - lessonId: string, - content: ComponentProperties, - version: CommonCartridgeVersion, - orgBuilder: ICommonCartridgeOrganizationBuilder - ): ICommonCartridgeResourceProps | undefined { - const commonProps = (fileExt: 'html' | 'xml') => { - return { - version, - identifier: createIdentifier(content._id), - href: `${createIdentifier(lessonId)}/${createIdentifier(content._id)}.${fileExt}`, - title: content.title, - }; - }; - - if (content.component === ComponentType.TEXT) { - return { - ...commonProps('html'), - type: CommonCartridgeResourceType.WEB_CONTENT, - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - html: `

${content.title}

${content.content.text}

`, - }; - } - - if (content.component === ComponentType.GEOGEBRA) { - const url = `https://www.geogebra.org/m/${content.content.materialId}`; - return version === CommonCartridgeVersion.V_1_3_0 - ? { ...commonProps('xml'), type: CommonCartridgeResourceType.WEB_LINK_V3, url } - : { ...commonProps('xml'), type: CommonCartridgeResourceType.WEB_LINK_V1, url }; - } - - if (content.component === ComponentType.ETHERPAD) { - return version === CommonCartridgeVersion.V_1_3_0 - ? { - ...commonProps('xml'), - type: CommonCartridgeResourceType.WEB_LINK_V3, - url: content.content.url, - title: content.content.description, - } - : { - ...commonProps('xml'), - type: CommonCartridgeResourceType.WEB_LINK_V1, - url: content.content.url, - title: content.content.description, - }; - } - - if (content.component === ComponentType.LERNSTORE && content.content) { - const { resources } = content.content; - - const resourceProps: ICommonCartridgeResourceProps[] = resources.map((resource) => - version === CommonCartridgeVersion.V_1_3_0 - ? { type: CommonCartridgeResourceType.WEB_LINK_V3, url: resource.url, ...commonProps('xml') } - : { type: CommonCartridgeResourceType.WEB_LINK_V1, url: resource.url, ...commonProps('xml') } - ); - - orgBuilder.addSubOrganization({ - version, - identifier: createIdentifier(content._id), - title: content.title, - resources: resourceProps, - _tag: 'resourceCollection', - }); - - return undefined; - } - - return undefined; - } - - /** - * This method gets the course as parameter and maps the contained teacher names within the teachers Collection to a string. - * @param Course - * @return string - * */ - private mapCourseTeachersToCopyrightOwners(course: Course): string { - const result = course.teachers - .toArray() - .map((teacher) => `${teacher.firstName} ${teacher.lastName}`) - .reduce((previousTeachers, currentTeacher) => `${previousTeachers}, ${currentTeacher}`); - return result; - } - - private mapTaskToWebContentResource( - task: Task, - version: CommonCartridgeVersion - ): ICommonCartridgeWebContentResourceProps { - const taskIdentifier = createIdentifier(task.id); - return { - version, - identifier: taskIdentifier, - href: `${taskIdentifier}/${taskIdentifier}.html`, - title: task.name, - type: CommonCartridgeResourceType.WEB_CONTENT, - html: `

${task.name}

${task.description}

`, - intendedUse: - version === CommonCartridgeVersion.V_1_1_0 - ? CommonCartridgeIntendedUseType.UNSPECIFIED - : CommonCartridgeIntendedUseType.ASSIGNMENT, - }; - } } From fcb90d2981beb5a72c5c0c9d8e1880764c0fea54 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 30 Nov 2023 16:23:22 +0100 Subject: [PATCH 033/177] EW-539 code cleanup --- TODO.md | 8 ++++++++ .../builders/common-cartridge-organization-builder.ts | 11 +++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index 7fa92508759..140aa806db5 100644 --- a/TODO.md +++ b/TODO.md @@ -89,3 +89,11 @@ e.g. api: , , domain: , + +### EW-539 + +- tests for CCExportService +- tests for CCMapper +- tests for CCManifestResource +- tests for CC*Element +- Cleanup FIXMEs diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts index 717974da712..474eb6a4345 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts @@ -6,12 +6,13 @@ import { CommonCartridgeResourceFactory, CommonCartridgeResourceProps, } from '../resources/common-cartridge-resource-factory'; +import { OmitVersionAndFolder } from '../utils'; export type CommonCartridgeOrganizationBuilderOptions = { version: CommonCartridgeVersion; identifier: string; title: string; - parentFolder?: string; + folder?: string; }; export class CommonCartridgeOrganizationBuilder { @@ -25,16 +26,14 @@ export class CommonCartridgeOrganizationBuilder { ) {} private get folder(): string { - return this.options.parentFolder - ? `${this.options.parentFolder}/${this.options.identifier}` - : this.options.identifier; + return this.options.folder ? `${this.options.folder}/${this.options.identifier}` : this.options.identifier; } addSubOrganization( - options: Omit + options: OmitVersionAndFolder ): CommonCartridgeOrganizationBuilder { const child = new CommonCartridgeOrganizationBuilder( - { ...options, version: this.options.version, parentFolder: this.folder }, + { ...options, version: this.options.version, folder: this.folder }, this.addResourceToFileBuilder.bind(this) ); From 5788de290631f357a20cdbab5c51f9e7b0489949 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 30 Nov 2023 16:35:31 +0100 Subject: [PATCH 034/177] EW-539 refactoring cc export service --- .../common-cartridge-export.service.ts | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index c08f809183f..17d1ecc7876 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -1,9 +1,13 @@ import { LessonService } from '@modules/lesson'; import { TaskService } from '@modules/task'; import { Injectable } from '@nestjs/common'; -import { EntityId } from '@shared/domain'; +import { ComponentProperties, EntityId } from '@shared/domain'; import { ObjectId } from 'bson'; -import { CommonCartridgeFileBuilder, CommonCartridgeVersion } from '../common-cartridge'; +import { + CommonCartridgeFileBuilder, + CommonCartridgeOrganizationBuilder, + CommonCartridgeVersion, +} from '../common-cartridge'; import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; import { CourseService } from './course.service'; @@ -41,21 +45,7 @@ export class CommonCartridgeExportService { const organizationBuilder = builder.addOrganization(CommonCartridgeMapper.mapLessonToOrganization(lesson)); lesson.contents.forEach((content) => { - const resources = CommonCartridgeMapper.mapContentToResources(content, version); - - if (!Array.isArray(resources)) { - organizationBuilder.addResource(resources); - } - - if (Array.isArray(resources)) { - const subOrganizationBuilder = organizationBuilder.addSubOrganization( - CommonCartridgeMapper.mapContentToOrganization(content) - ); - - resources.forEach((resource) => { - subOrganizationBuilder.addResource(resource); - }); - } + this.addComponent(organizationBuilder, content, version); }); }); } @@ -76,4 +66,26 @@ export class CommonCartridgeExportService { organizationBuilder.addResource(CommonCartridgeMapper.mapTaskToResource(task, version)); }); } + + private addComponent( + organizationBuilder: CommonCartridgeOrganizationBuilder, + component: ComponentProperties, + version: CommonCartridgeVersion + ): void { + const resources = CommonCartridgeMapper.mapContentToResources(component, version); + + if (!Array.isArray(resources)) { + organizationBuilder.addResource(resources); + } + + if (Array.isArray(resources)) { + const subOrganizationBuilder = organizationBuilder.addSubOrganization( + CommonCartridgeMapper.mapContentToOrganization(component) + ); + + resources.forEach((resource) => { + subOrganizationBuilder.addResource(resource); + }); + } + } } From e9021dcd6bbca0e7123779d2c9d44ebdc626b033 Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 1 Dec 2023 09:28:04 +0100 Subject: [PATCH 035/177] EW-539 adding tests --- ...mon-cartridge-organization-element.spec.ts | 39 ++++++++++++++++ ...idge-organizations-wrapper-element.spec.ts | 46 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts new file mode 100644 index 00000000000..95a4ea538e4 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts @@ -0,0 +1,39 @@ +import { CommonCartridgeOrganizationElement } from './common-cartridge-organization-element'; + +describe('CommonCartridgeOrganizationElement', () => { + describe('getManifestXml', () => { + it('should return the correct xml object', () => { + const element = new CommonCartridgeOrganizationElement({ + identifier: 'identifier', + title: 'title', + items: [ + { + getManifestXml: () => { + return { + $: { + identifier: 'identifier', + }, + title: 'title', + }; + }, + }, + ], + }); + + expect(element.getManifestXml()).toStrictEqual({ + $: { + identifier: 'identifier', + }, + title: 'title', + item: [ + { + $: { + identifier: 'identifier', + }, + title: 'title', + }, + ], + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts new file mode 100644 index 00000000000..c2387027521 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts @@ -0,0 +1,46 @@ +import { CommonCartridgeOrganizationsWrapperElement } from './common-cartridge-organizations-wrapper-element'; + +describe('CommonCartridgeOrganizationsWrapperElement', () => { + describe('getManifestXml', () => { + it('should return the correct xml object', () => { + const element = new CommonCartridgeOrganizationsWrapperElement([ + { + getManifestXml: () => { + return { + $: { + identifier: 'identifier', + }, + title: 'title', + }; + }, + }, + ]); + + expect(element.getManifestXml()).toStrictEqual({ + organization: [ + { + $: { + identifier: 'org-1', + structure: 'rooted-hierarchy', + }, + item: [ + { + $: { + identifier: 'LearningModules', + }, + item: [ + { + $: { + identifier: 'identifier', + }, + title: 'title', + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); From 472f84b1e0b2f217f9cf9c871f63d9ee8693eaae Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 1 Dec 2023 09:28:10 +0100 Subject: [PATCH 036/177] EW-539 Finish tests for lti, web content and web link resources --- .../common-cartridge-lti-resource.spec.ts | 41 +++++--- ...mon-cartridge-web-content-resource.spec.ts | 96 ++++++++++++++----- ...common-cartridge-web-link-resource.spec.ts | 76 +++++++++------ 3 files changed, 144 insertions(+), 69 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts index 95b0e673fde..5f04408a714 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts @@ -26,24 +26,32 @@ describe('CommonCartridgeLtiResource', () => { const ltiResourceVersion3 = new CommonCartridgeLtiResource(propsVersion3); describe('canInline', () => { - describe('when the return value of the method is called', () => { - it('should return false regardless of the common cartridge version', () => { + describe('when common cartridge version 1.1', () => { + it('should return false', () => { const resultVersion1 = ltiResourceVersion1.canInline(); - const resultVersion3 = ltiResourceVersion3.canInline(); - expect(resultVersion1).toBe(false); + }); + }); + + describe('when common cartridge version 1.3', () => { + it('should return false', () => { + const resultVersion3 = ltiResourceVersion3.canInline(); expect(resultVersion3).toBe(false); }); }); }); describe('getFilePath', () => { - describe('when the return value of the method is called', () => { - it('should return the file path regardless of the common cartridge version', () => { + describe('when common cartridge version 1.1', () => { + it('should return the file path regarding version 1.1', () => { const filePathVersion1 = ltiResourceVersion1.getFilePath(); - const filePathVersion3 = ltiResourceVersion3.getFilePath(); - expect(filePathVersion1).toBe(`${propsVersion1.folder}/${propsVersion1.identifier}.xml`); + }); + }); + + describe('when common cartridge version 1.3', () => { + it('should return the file path regarding version 1.3', () => { + const filePathVersion3 = ltiResourceVersion3.getFilePath(); expect(filePathVersion3).toBe(`${propsVersion3.folder}/${propsVersion3.identifier}.xml`); }); }); @@ -99,12 +107,11 @@ describe('CommonCartridgeLtiResource', () => { }); describe('getManifestXml', () => { - describe('when the return value of the method is called', () => { - it('should return manifest xml content regardless of the common cartridge version', () => { - const transformedVersion1 = ltiResourceVersion1.getManifestXml(); - const transformedVersion3 = ltiResourceVersion3.getManifestXml(); + describe('when common cartridge version 1.1', () => { + it('should return manifest xml content regarding version 1.1', () => { + const transformed = ltiResourceVersion1.getManifestXml(); - expect(transformedVersion1).toEqual({ + expect(transformed).toEqual({ $: { identifier: propsVersion1.identifier, type: propsVersion1.type, @@ -115,8 +122,14 @@ describe('CommonCartridgeLtiResource', () => { }, }, }); + }); + }); + + describe('when common cartridge version 1.3', () => { + it('should return manifest xml content regarding version 1.3', () => { + const transformed = ltiResourceVersion3.getManifestXml(); - expect(transformedVersion3).toEqual({ + expect(transformed).toEqual({ $: { identifier: propsVersion3.identifier, type: propsVersion3.type, diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts index e0107f534de..6d5f7c8dc6e 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts @@ -5,55 +5,103 @@ import { } from './common-cartridge-web-content-resource'; describe('CommonCartridgeWebContentResource', () => { - const props: CommonCartridgeWebContentResourceProps = { + const propsVersion1: CommonCartridgeWebContentResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_1_0, + identifier: 'web-link-v1', + folder: 'https://example.com/link1', + title: 'Web Link Version 1', + html: 'html tages for testing version 1', + }; + const propsVersion3: CommonCartridgeWebContentResourceProps = { type: CommonCartridgeResourceType.WEB_CONTENT, version: CommonCartridgeVersion.V_1_3_0, - identifier: 'web-link', - folder: 'https://example.com/link', - title: 'Web Link', - html: 'html tages for testing', + identifier: 'web-link-v3', + folder: 'https://example.com/link3', + title: 'Web Link Version 3', + html: 'html tages for testing version 3', }; - const webContentResource = new CommonCartridgeWebContentResource(props); + + const webContentResourceVersion1 = new CommonCartridgeWebContentResource(propsVersion1); + const webContentResourceVersion3 = new CommonCartridgeWebContentResource(propsVersion3); describe('canInline', () => { - describe('when the return value of the method is called', () => { - it('should return false regardless of the common cartridge version', () => { - expect(webContentResource.canInline()).toBe(false); + describe('when common cartridge version 1.1', () => { + it('should return false', () => { + expect(webContentResourceVersion1.canInline()).toBe(false); + }); + }); + + describe('when common cartridge version 1.3', () => { + it('should return false', () => { + expect(webContentResourceVersion3.canInline()).toBe(false); }); }); }); describe('getFilePath', () => { - describe('when the return value of the method is called', () => { - it('should return the file path regardless of the common cartridge version', () => { - const filePath = webContentResource.getFilePath(); - expect(filePath).toBe(`${props.folder}/${props.identifier}.html`); + describe('when common cartridge version 1.1', () => { + it('should return the file path regarding version 1.1', () => { + const filePath = webContentResourceVersion1.getFilePath(); + expect(filePath).toBe(`${propsVersion1.folder}/${propsVersion1.identifier}.html`); + }); + }); + + describe('when common cartridge version 1.3', () => { + it('should return the file path regarding version 1.3', () => { + const filePath = webContentResourceVersion3.getFilePath(); + expect(filePath).toBe(`${propsVersion3.folder}/${propsVersion3.identifier}.html`); }); }); }); describe('getFileContent', () => { - describe('when the return value of the method is called', () => { - it('should return html content regardless of the common cartridge version', () => { - const content = webContentResource.getFileContent(); - expect(content).toContain(props.html); + describe('when common cartridge version 1.1', () => { + it('should return XML content of common cartridge version 1.1', () => { + const content = webContentResourceVersion1.getFileContent(); + expect(content).toContain(propsVersion1.html); + }); + }); + + describe('when common cartridge version 1.3', () => { + it('should return XML content of common cartridge version 1.3', () => { + const content = webContentResourceVersion3.getFileContent(); + expect(content).toContain(propsVersion3.html); }); }); }); describe('getManifestXml', () => { - describe('when the return value of the method is called', () => { - it('should return manifest xml content regardless of the common cartridge version', () => { - const transformed = webContentResource.getManifestXml(); - expect(transformed).toEqual({ + describe('when common cartridge version 1.1', () => { + it('should return manifest xml content regarding version 1.1', () => { + const transformed = webContentResourceVersion1.getManifestXml(); + expect(transformed).toStrictEqual({ + $: { + identifier: propsVersion1.identifier, + type: propsVersion1.type, + intendeduse: 'unspecified', + }, + file: { + $: { + href: propsVersion1.folder, + }, + }, + }); + }); + }); + + describe('when common cartridge version 1.3', () => { + it('should return manifest xml content regarding version 1.3', () => { + const transformed = webContentResourceVersion3.getManifestXml(); + expect(transformed).toStrictEqual({ $: { - identifier: props.identifier, - type: props.type, + identifier: propsVersion3.identifier, + type: propsVersion3.type, intendeduse: 'unspecified', }, file: { $: { - href: props.folder, + href: propsVersion3.folder, }, }, }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts index eeba1c7992a..14ff92d8fea 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts @@ -27,39 +27,37 @@ describe('CommonCartridgeWebLinkResource', () => { const webLinkResourceV1 = new CommonCartridgeWebLinkResource(propsOfV1); describe('canInline', () => { - describe('when the return value of the method is called', () => { - it('should return false regardless of the common cartridge version', () => { - expect(webLinkResourceV3.canInline()).toBe(false); + describe('when common cartridge version 1.1', () => { + it('should return false', () => { expect(webLinkResourceV1.canInline()).toBe(false); }); }); + + describe('when common cartridge version 1.3', () => { + it('should return false', () => { + expect(webLinkResourceV3.canInline()).toBe(false); + }); + }); }); describe('getFilePath', () => { - describe('when the return value of the method is called', () => { - it('should return the file path regardless of the common cartridge version', () => { - const filePathV3 = webLinkResourceV3.getFilePath(); + describe('when common cartridge version 1.1', () => { + it('should return the file path regarding version 1.1', () => { const filePathV1 = webLinkResourceV1.getFilePath(); - - expect(filePathV3).toBe(`${propsOfV3.folder}/${propsOfV3.identifier}.xml`); expect(filePathV1).toBe(`${propsOfV1.folder}/${propsOfV1.identifier}.xml`); }); - }); - }); - - describe('getFileContent', () => { - describe('when version is 1.3', () => { - it('should return XML content of common cartridge version 1.3', () => { - const content = webLinkResourceV3.getFileContent(); - expect(content).toContain('webLink'); - expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); - expect(content).toContain('http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3'); - expect(content).toContain('http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd'); + describe('when common cartridge version 1.3', () => { + it('should return the file path regarding version 1.3', () => { + const filePathV3 = webLinkResourceV3.getFilePath(); + expect(filePathV3).toBe(`${propsOfV3.folder}/${propsOfV3.identifier}.xml`); + }); }); }); + }); - describe('when version is 1.1', () => { + describe('getFileContent', () => { + describe('when common cartridge version 1.1', () => { it('should return XML content of common cartridge version 1.1', () => { const content = webLinkResourceV1.getFileContent(); @@ -72,6 +70,17 @@ describe('CommonCartridgeWebLinkResource', () => { }); }); + describe('when common cartridge version 1.3', () => { + it('should return XML content of common cartridge version 1.3', () => { + const content = webLinkResourceV3.getFileContent(); + + expect(content).toContain('webLink'); + expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); + expect(content).toContain('http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3'); + expect(content).toContain('http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd'); + }); + }); + describe('when version is not supported', () => { it('should throw an error', () => { const webLinkResource = new CommonCartridgeWebLinkResource({ @@ -85,31 +94,36 @@ describe('CommonCartridgeWebLinkResource', () => { }); describe('getManifestXml', () => { - describe('when the return value of the method is called', () => { - it('should return manifest xml content regardless of the common cartridge version', () => { - const transformedV3 = webLinkResourceV3.getManifestXml(); + describe('when common cartridge version 1.1', () => { + it('should return manifest xml content regarding version 1.1', () => { const transformedV1 = webLinkResourceV1.getManifestXml(); - expect(transformedV3).toEqual({ + expect(transformedV1).toStrictEqual({ $: { - identifier: propsOfV3.identifier, - type: propsOfV3.type, + identifier: propsOfV1.identifier, + type: propsOfV1.type, }, file: { $: { - href: propsOfV3.folder, + href: propsOfV1.folder, }, }, }); + }); + }); - expect(transformedV1).toEqual({ + describe('when common cartridge version 1.3', () => { + it('should return manifest xml content regarding version 1.3', () => { + const transformedV3 = webLinkResourceV3.getManifestXml(); + + expect(transformedV3).toStrictEqual({ $: { - identifier: propsOfV1.identifier, - type: propsOfV1.type, + identifier: propsOfV3.identifier, + type: propsOfV3.type, }, file: { $: { - href: propsOfV1.folder, + href: propsOfV3.folder, }, }, }); From 520a49f8b33ff03dacbd48352ea050ad9f56b90a Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 1 Dec 2023 09:31:55 +0100 Subject: [PATCH 037/177] EW-539 adding tests for elements --- ...mon-cartridge-organization-element.spec.ts | 1 + ...idge-organizations-wrapper-element.spec.ts | 1 + ...artridge-resources-wrapper-element.spec.ts | 36 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts index 95a4ea538e4..c0419e4387d 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts @@ -1,6 +1,7 @@ import { CommonCartridgeOrganizationElement } from './common-cartridge-organization-element'; describe('CommonCartridgeOrganizationElement', () => { + // AI next 34 lines describe('getManifestXml', () => { it('should return the correct xml object', () => { const element = new CommonCartridgeOrganizationElement({ diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts index c2387027521..1c0ae2ee38c 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts @@ -1,6 +1,7 @@ import { CommonCartridgeOrganizationsWrapperElement } from './common-cartridge-organizations-wrapper-element'; describe('CommonCartridgeOrganizationsWrapperElement', () => { + // AI next 40 lines describe('getManifestXml', () => { it('should return the correct xml object', () => { const element = new CommonCartridgeOrganizationsWrapperElement([ diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts new file mode 100644 index 00000000000..62393284c3e --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts @@ -0,0 +1,36 @@ +import { CommonCartridgeResourcesWrapperElement } from './common-cartridge-resources-wrapper-element'; + +describe('CommonCartridgeResourcesWrapperElement', () => { + // AI next 30 lines + describe('getManifestXml', () => { + it('should return the correct xml object', () => { + const element = new CommonCartridgeResourcesWrapperElement([ + { + getManifestXml: () => { + return { + $: { + identifier: 'identifier', + }, + title: 'title', + }; + }, + }, + ]); + + expect(element.getManifestXml()).toStrictEqual({ + resources: [ + { + resource: [ + { + $: { + identifier: 'identifier', + }, + title: 'title', + }, + ], + }, + ], + }); + }); + }); +}); From 45415d2924310d0d78246a1c8ca5a8ca69efb948 Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 1 Dec 2023 09:37:33 +0100 Subject: [PATCH 038/177] EW-539 renaming getManifestXml to getManifestXmlObject --- .../elements/common-cartridge-metadata-element.ts | 2 +- .../common-cartridge-organization-element.spec.ts | 4 ++-- .../elements/common-cartridge-organization-element.ts | 4 ++-- ...mon-cartridge-organizations-wrapper-element.spec.ts | 4 ++-- .../common-cartridge-organizations-wrapper-element.ts | 4 ++-- .../common-cartridge-resources-wrapper-element.spec.ts | 4 ++-- .../common-cartridge-resources-wrapper-element.ts | 4 ++-- .../interfaces/common-cartridge-element.interface.ts | 2 +- .../resources/common-cartridge-lti-resource.spec.ts | 4 ++-- .../resources/common-cartridge-lti-resource.ts | 2 +- .../resources/common-cartridge-manifest-resource.ts | 10 +++++----- .../common-cartridge-web-content-resource.spec.ts | 4 ++-- .../resources/common-cartridge-web-content-resource.ts | 2 +- .../common-cartridge-web-link-resource.spec.ts | 4 ++-- .../resources/common-cartridge-web-link-resource.ts | 2 +- 15 files changed, 28 insertions(+), 28 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts index 02f23c422b4..70fd3101bdd 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts @@ -11,7 +11,7 @@ export type CommonCartridgeMetadataElementProps = { export class CommonCartridgeMetadataElement implements CommonCartridgeElement { constructor(private readonly props: CommonCartridgeMetadataElementProps) {} - getManifestXml(): Record { + getManifestXmlObject(): Record { return { schema: 'IMS Common Cartridge', schemaversion: this.props.version, diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts index c0419e4387d..cbcd1e0fe73 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts @@ -9,7 +9,7 @@ describe('CommonCartridgeOrganizationElement', () => { title: 'title', items: [ { - getManifestXml: () => { + getManifestXmlObject: () => { return { $: { identifier: 'identifier', @@ -21,7 +21,7 @@ describe('CommonCartridgeOrganizationElement', () => { ], }); - expect(element.getManifestXml()).toStrictEqual({ + expect(element.getManifestXmlObject()).toStrictEqual({ $: { identifier: 'identifier', }, diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts index 476197dfbab..f4e5b5c6c58 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts @@ -9,13 +9,13 @@ type CommonCartridgeOrganizationElementProps = { export class CommonCartridgeOrganizationElement implements CommonCartridgeElement { constructor(private readonly props: CommonCartridgeOrganizationElementProps) {} - getManifestXml(): Record { + getManifestXmlObject(): Record { return { $: { identifier: this.props.identifier, }, title: this.props.title, - item: this.props.items.map((item) => item.getManifestXml()), + item: this.props.items.map((item) => item.getManifestXmlObject()), }; } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts index 1c0ae2ee38c..85da46c7305 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts @@ -6,7 +6,7 @@ describe('CommonCartridgeOrganizationsWrapperElement', () => { it('should return the correct xml object', () => { const element = new CommonCartridgeOrganizationsWrapperElement([ { - getManifestXml: () => { + getManifestXmlObject: () => { return { $: { identifier: 'identifier', @@ -17,7 +17,7 @@ describe('CommonCartridgeOrganizationsWrapperElement', () => { }, ]); - expect(element.getManifestXml()).toStrictEqual({ + expect(element.getManifestXmlObject()).toStrictEqual({ organization: [ { $: { diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts index 6a318621ab3..6bd41f8aea7 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts @@ -3,7 +3,7 @@ import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.i export class CommonCartridgeOrganizationsWrapperElement implements CommonCartridgeElement { constructor(private readonly items: CommonCartridgeElement[]) {} - getManifestXml(): Record { + getManifestXmlObject(): Record { return { organization: [ { @@ -16,7 +16,7 @@ export class CommonCartridgeOrganizationsWrapperElement implements CommonCartrid $: { identifier: 'LearningModules', }, - item: this.items.map((items) => items.getManifestXml()), + item: this.items.map((items) => items.getManifestXmlObject()), }, ], }, diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts index 62393284c3e..aa4d0874a6a 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts @@ -6,7 +6,7 @@ describe('CommonCartridgeResourcesWrapperElement', () => { it('should return the correct xml object', () => { const element = new CommonCartridgeResourcesWrapperElement([ { - getManifestXml: () => { + getManifestXmlObject: () => { return { $: { identifier: 'identifier', @@ -17,7 +17,7 @@ describe('CommonCartridgeResourcesWrapperElement', () => { }, ]); - expect(element.getManifestXml()).toStrictEqual({ + expect(element.getManifestXmlObject()).toStrictEqual({ resources: [ { resource: [ diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts index 49c7dc48ebf..e6f91f5aa05 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts @@ -3,11 +3,11 @@ import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.i export class CommonCartridgeResourcesWrapperElement implements CommonCartridgeElement { constructor(private readonly items: CommonCartridgeElement[]) {} - getManifestXml(): Record { + getManifestXmlObject(): Record { return { resources: [ { - resource: this.items.map((items) => items.getManifestXml()), + resource: this.items.map((items) => items.getManifestXmlObject()), }, ], }; diff --git a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element.interface.ts index 6b38658c162..fc8ddb8ec3d 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element.interface.ts @@ -6,5 +6,5 @@ export interface CommonCartridgeElement { * This method is used to build the imsmanifest.xml file. * @returns The XML object representation for the imsmanifest.xml file. */ - getManifestXml(): Record; + getManifestXmlObject(): Record; } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts index 5f04408a714..3e881f83bd3 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts @@ -109,7 +109,7 @@ describe('CommonCartridgeLtiResource', () => { describe('getManifestXml', () => { describe('when common cartridge version 1.1', () => { it('should return manifest xml content regarding version 1.1', () => { - const transformed = ltiResourceVersion1.getManifestXml(); + const transformed = ltiResourceVersion1.getManifestXmlObject(); expect(transformed).toEqual({ $: { @@ -127,7 +127,7 @@ describe('CommonCartridgeLtiResource', () => { describe('when common cartridge version 1.3', () => { it('should return manifest xml content regarding version 1.3', () => { - const transformed = ltiResourceVersion3.getManifestXml(); + const transformed = ltiResourceVersion3.getManifestXmlObject(); expect(transformed).toEqual({ $: { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts index 758426807a2..4ad8fae9341 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts @@ -47,7 +47,7 @@ export class CommonCartridgeLtiResource implements CommonCartridgeResource { }); } - getManifestXml(): Record { + getManifestXmlObject(): Record { return { $: { identifier: this.props.identifier, diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts index d83f8eba2c1..b2fd99e805c 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts @@ -28,18 +28,18 @@ export class CommonCartridgeManifestResource implements CommonCartridgeResource } getFileContent(): string { - return this.xmlBuilder.buildObject(this.getManifestXml()); + return this.xmlBuilder.buildObject(this.getManifestXmlObject()); } - getManifestXml(): Record { + getManifestXmlObject(): Record { return { manifest: { $: this.getXmlNamespacesByVersion(), - metadata: this.props.metadata.getManifestXml(), + metadata: this.props.metadata.getManifestXmlObject(), organizations: new CommonCartridgeOrganizationsWrapperElement( this.props.organizations - ).getManifestXml(), - resources: new CommonCartridgeResourcesWrapperElement(this.props.resources).getManifestXml(), + ).getManifestXmlObject(), + resources: new CommonCartridgeResourcesWrapperElement(this.props.resources).getManifestXmlObject(), }, }; } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts index 6d5f7c8dc6e..14bd1d3e91d 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts @@ -74,7 +74,7 @@ describe('CommonCartridgeWebContentResource', () => { describe('getManifestXml', () => { describe('when common cartridge version 1.1', () => { it('should return manifest xml content regarding version 1.1', () => { - const transformed = webContentResourceVersion1.getManifestXml(); + const transformed = webContentResourceVersion1.getManifestXmlObject(); expect(transformed).toStrictEqual({ $: { identifier: propsVersion1.identifier, @@ -92,7 +92,7 @@ describe('CommonCartridgeWebContentResource', () => { describe('when common cartridge version 1.3', () => { it('should return manifest xml content regarding version 1.3', () => { - const transformed = webContentResourceVersion3.getManifestXml(); + const transformed = webContentResourceVersion3.getManifestXmlObject(); expect(transformed).toStrictEqual({ $: { identifier: propsVersion3.identifier, diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts index 5d0f4364db7..3f4754de724 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts @@ -30,7 +30,7 @@ export class CommonCartridgeWebContentResource implements CommonCartridgeResourc return this.props.html; } - getManifestXml(): Record { + getManifestXmlObject(): Record { return { $: { identifier: this.props.identifier, diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts index 14ff92d8fea..44551fa770d 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts @@ -96,7 +96,7 @@ describe('CommonCartridgeWebLinkResource', () => { describe('getManifestXml', () => { describe('when common cartridge version 1.1', () => { it('should return manifest xml content regarding version 1.1', () => { - const transformedV1 = webLinkResourceV1.getManifestXml(); + const transformedV1 = webLinkResourceV1.getManifestXmlObject(); expect(transformedV1).toStrictEqual({ $: { @@ -114,7 +114,7 @@ describe('CommonCartridgeWebLinkResource', () => { describe('when common cartridge version 1.3', () => { it('should return manifest xml content regarding version 1.3', () => { - const transformedV3 = webLinkResourceV3.getManifestXml(); + const transformedV3 = webLinkResourceV3.getManifestXmlObject(); expect(transformedV3).toStrictEqual({ $: { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts index 787c4d5e31a..38fdf185563 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts @@ -38,7 +38,7 @@ export class CommonCartridgeWebLinkResource implements CommonCartridgeResource { }); } - getManifestXml(): Record { + getManifestXmlObject(): Record { return { $: { identifier: this.props.identifier, From 9845a607943cbf47b4e03f2238a10f2e22231c57 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 1 Dec 2023 09:39:21 +0100 Subject: [PATCH 039/177] EW-539 Start tests for metadata element and manifest resource --- .../common-cartridge-metadata-element.spec.ts | 52 +++++++++++++++++++ ...common-cartridge-manifest-resource.spec.ts | 34 ++++++++++++ .../common-cartridge-manifest-resource.ts | 2 +- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts new file mode 100644 index 00000000000..016bddcaa92 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts @@ -0,0 +1,52 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { + CommonCartridgeMetadataElement, + CommonCartridgeMetadataElementProps, +} from './common-cartridge-metadata-element'; + +describe('CommonCartridgeMetadataElement', () => { + const propsVersion1: CommonCartridgeMetadataElementProps = { + version: CommonCartridgeVersion.V_1_1, + title: 'Metadata Element Version 1.1', + creationDate: new Date(), + copyrightOwners: ['copyrightOwner1Version1', 'copyrightOwner2Version1'], + }; + + const propsVersion3: CommonCartridgeMetadataElementProps = { + version: CommonCartridgeVersion.V_1_3, + title: 'Metadata Element Version 1.3', + creationDate: new Date(), + copyrightOwners: ['copyrightOwner1Version3', 'copyrightOwner2Version3'], + }; + + const metadataElementVersion1 = new CommonCartridgeMetadataElement(propsVersion1); + const metadataElementVersion3 = new CommonCartridgeMetadataElement(propsVersion3); + + describe('getManifestXml', () => { + describe('when the return value of the method is called', () => { + it('should return manifest xml content regardless of the common cartridge version', () => { + const transformed = metadataElement.getManifestXml(); + + expect(transformed).toStrictEqual({ + schema: 'IMS Common Cartridge', + schemaversion: props.version, + 'mnf:lom': { + 'mnf:general': { + 'mnf:title': { + 'mnf:string': props.title, + }, + }, + 'mnf:rights': { + 'mnf:copyrightAndOtherRestrictions': { + 'mnf:value': 'yes', + }, + 'mnf:description': { + 'mnf:string': `${props.creationDate.getFullYear()} ${props.creationDate.getFullYear()}`, + }, + }, + }, + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts new file mode 100644 index 00000000000..249756b872e --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts @@ -0,0 +1,34 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeManifestElementProps } from './common-cartridge-manifest-resource'; + +describe('CommonCartridgeManifestResource', () => { + const propsOfVersion1: CommonCartridgeManifestElementProps = { + version: CommonCartridgeVersion.V_1_1_0, + identifier: 'manifest-v1', + metadata: { + getManifestXml: () => { + return { + schema: 'IMS Common Cartridge', + schemaversion: propsOfVersion1.version, + 'mnf:lom': { + 'mnf:general': { + 'mnf:title': { + 'mnf:string': 'Manifest v1', + }, + }, + 'mnf:rights': { + 'mnf:copyrightAndOtherRestrictions': { + 'mnf:value': 'yes', + }, + 'mnf:description': { + 'mnf:string': 'Test Manifest V1', + }, + }, + }, + }; + }, + }, + organizations: [], + resources: [], + }; +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts index b2fd99e805c..c727b29513f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts @@ -6,7 +6,7 @@ import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.i import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { createVersionNotSupportedError } from '../utils'; -type CommonCartridgeManifestElementProps = { +export type CommonCartridgeManifestElementProps = { version: CommonCartridgeVersion; identifier: string; metadata: CommonCartridgeElement; From 3bcdd711bf1736a10ef27b1072357b05c42cd2e8 Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 1 Dec 2023 10:13:06 +0100 Subject: [PATCH 040/177] EW-539 finishing tests for elements --- .../common-cartridge-metadata-element.spec.ts | 62 +++++++++++---- ...mon-cartridge-organization-element.spec.ts | 59 +++++++------- ...idge-organizations-wrapper-element.spec.ts | 77 ++++++++++--------- ...artridge-resources-wrapper-element.spec.ts | 55 ++++++------- .../mapper/common-cartridge.mapper.spec.ts | 1 + 5 files changed, 150 insertions(+), 104 deletions(-) create mode 100644 apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts index 016bddcaa92..b54a239de42 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts @@ -5,35 +5,69 @@ import { } from './common-cartridge-metadata-element'; describe('CommonCartridgeMetadataElement', () => { + let sut: CommonCartridgeMetadataElement; + const propsVersion1: CommonCartridgeMetadataElementProps = { - version: CommonCartridgeVersion.V_1_1, + version: CommonCartridgeVersion.V_1_1_0, title: 'Metadata Element Version 1.1', creationDate: new Date(), copyrightOwners: ['copyrightOwner1Version1', 'copyrightOwner2Version1'], }; - const propsVersion3: CommonCartridgeMetadataElementProps = { - version: CommonCartridgeVersion.V_1_3, + version: CommonCartridgeVersion.V_1_3_0, title: 'Metadata Element Version 1.3', creationDate: new Date(), copyrightOwners: ['copyrightOwner1Version3', 'copyrightOwner2Version3'], }; - const metadataElementVersion1 = new CommonCartridgeMetadataElement(propsVersion1); - const metadataElementVersion3 = new CommonCartridgeMetadataElement(propsVersion3); + describe('getManifestXmlObject', () => { + describe('when using common cartridge version 1.1', () => { + beforeAll(() => { + sut = new CommonCartridgeMetadataElement(propsVersion1); + }); + + it('should return correct xml object', () => { + const xmlObject = sut.getManifestXmlObject(); + + expect(xmlObject).toStrictEqual({ + schema: 'IMS Common Cartridge', + schemaversion: propsVersion1.version, + 'mnf:lom': { + 'mnf:general': { + 'mnf:title': { + 'mnf:string': propsVersion1.title, + }, + }, + 'mnf:rights': { + 'mnf:copyrightAndOtherRestrictions': { + 'mnf:value': 'yes', + }, + 'mnf:description': { + 'mnf:string': `${propsVersion1.creationDate.getFullYear()} ${propsVersion1.copyrightOwners.join( + ', ' + )}`, + }, + }, + }, + }); + }); + }); + + describe('when using common cartridge version 1.3', () => { + beforeAll(() => { + sut = new CommonCartridgeMetadataElement(propsVersion3); + }); - describe('getManifestXml', () => { - describe('when the return value of the method is called', () => { - it('should return manifest xml content regardless of the common cartridge version', () => { - const transformed = metadataElement.getManifestXml(); + it('should return correct xml object', () => { + const xmlObject = sut.getManifestXmlObject(); - expect(transformed).toStrictEqual({ + expect(xmlObject).toStrictEqual({ schema: 'IMS Common Cartridge', - schemaversion: props.version, + schemaversion: propsVersion3.version, 'mnf:lom': { 'mnf:general': { 'mnf:title': { - 'mnf:string': props.title, + 'mnf:string': propsVersion3.title, }, }, 'mnf:rights': { @@ -41,7 +75,9 @@ describe('CommonCartridgeMetadataElement', () => { 'mnf:value': 'yes', }, 'mnf:description': { - 'mnf:string': `${props.creationDate.getFullYear()} ${props.creationDate.getFullYear()}`, + 'mnf:string': `${propsVersion3.creationDate.getFullYear()} ${propsVersion3.copyrightOwners.join( + ', ' + )}`, }, }, }, diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts index cbcd1e0fe73..26486180c6b 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts @@ -1,39 +1,42 @@ import { CommonCartridgeOrganizationElement } from './common-cartridge-organization-element'; describe('CommonCartridgeOrganizationElement', () => { - // AI next 34 lines - describe('getManifestXml', () => { - it('should return the correct xml object', () => { - const element = new CommonCartridgeOrganizationElement({ - identifier: 'identifier', - title: 'title', - items: [ - { - getManifestXmlObject: () => { - return { - $: { - identifier: 'identifier', - }, - title: 'title', - }; - }, - }, - ], - }); - - expect(element.getManifestXmlObject()).toStrictEqual({ - $: { - identifier: 'identifier', - }, - title: 'title', - item: [ - { + const sut = new CommonCartridgeOrganizationElement({ + identifier: 'identifier', + title: 'title', + items: [ + { + getManifestXmlObject: () => { + return { $: { identifier: 'identifier', }, title: 'title', + }; + }, + }, + ], + }); + + describe('getManifestXmlObject', () => { + describe('when building common cartridge manifest', () => { + it('should return correct xml object', () => { + const xmlObject = sut.getManifestXmlObject(); + + expect(xmlObject).toStrictEqual({ + $: { + identifier: 'identifier', }, - ], + title: 'title', + item: [ + { + $: { + identifier: 'identifier', + }, + title: 'title', + }, + ], + }); }); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts index 85da46c7305..ea01a411dfd 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts @@ -1,46 +1,49 @@ import { CommonCartridgeOrganizationsWrapperElement } from './common-cartridge-organizations-wrapper-element'; describe('CommonCartridgeOrganizationsWrapperElement', () => { - // AI next 40 lines - describe('getManifestXml', () => { - it('should return the correct xml object', () => { - const element = new CommonCartridgeOrganizationsWrapperElement([ - { - getManifestXmlObject: () => { - return { - $: { - identifier: 'identifier', - }, - title: 'title', - }; + const sut = new CommonCartridgeOrganizationsWrapperElement([ + { + getManifestXmlObject: () => { + return { + $: { + identifier: 'identifier', }, - }, - ]); + title: 'title', + }; + }, + }, + ]); - expect(element.getManifestXmlObject()).toStrictEqual({ - organization: [ - { - $: { - identifier: 'org-1', - structure: 'rooted-hierarchy', - }, - item: [ - { - $: { - identifier: 'LearningModules', - }, - item: [ - { - $: { - identifier: 'identifier', - }, - title: 'title', - }, - ], + describe('getManifestXmlObject', () => { + describe('when building common cartridge manifest', () => { + it('should return correct xml object', () => { + const xmlObject = sut.getManifestXmlObject(); + + expect(xmlObject).toStrictEqual({ + organization: [ + { + $: { + identifier: 'org-1', + structure: 'rooted-hierarchy', }, - ], - }, - ], + item: [ + { + $: { + identifier: 'LearningModules', + }, + item: [ + { + $: { + identifier: 'identifier', + }, + title: 'title', + }, + ], + }, + ], + }, + ], + }); }); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts index aa4d0874a6a..b2fef191cff 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts @@ -1,35 +1,38 @@ import { CommonCartridgeResourcesWrapperElement } from './common-cartridge-resources-wrapper-element'; describe('CommonCartridgeResourcesWrapperElement', () => { - // AI next 30 lines - describe('getManifestXml', () => { - it('should return the correct xml object', () => { - const element = new CommonCartridgeResourcesWrapperElement([ - { - getManifestXmlObject: () => { - return { - $: { - identifier: 'identifier', - }, - title: 'title', - }; + const sut = new CommonCartridgeResourcesWrapperElement([ + { + getManifestXmlObject: () => { + return { + $: { + identifier: 'identifier', }, - }, - ]); + title: 'title', + }; + }, + }, + ]); - expect(element.getManifestXmlObject()).toStrictEqual({ - resources: [ - { - resource: [ - { - $: { - identifier: 'identifier', + describe('getManifestXmlObject', () => { + describe('when building common cartridge manifest', () => { + it('should return the correct xml object', () => { + const xmlObject = sut.getManifestXmlObject(); + + expect(xmlObject).toStrictEqual({ + resources: [ + { + resource: [ + { + $: { + identifier: 'identifier', + }, + title: 'title', }, - title: 'title', - }, - ], - }, - ], + ], + }, + ], + }); }); }); }); diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts new file mode 100644 index 00000000000..534f24ce16c --- /dev/null +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -0,0 +1 @@ +describe('CommonCartridgeMapper', () => {}); From 9e8b3baa754cbd079b82a16167b06f6c8d5c3fbd Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 1 Dec 2023 13:22:14 +0100 Subject: [PATCH 041/177] EW-539 adding test for cc mapper --- .../learnroom/common-cartridge/index.ts | 2 +- .../common-cartridge-web-content-resource.ts | 6 +- .../mapper/common-cartridge.mapper.spec.ts | 202 +++++++++++++++++- .../mapper/common-cartridge.mapper.ts | 15 +- 4 files changed, 208 insertions(+), 17 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/index.ts b/apps/server/src/modules/learnroom/common-cartridge/index.ts index 8dfd72fd85e..237fcaa46e3 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/index.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/index.ts @@ -1,6 +1,6 @@ export * from './builders/common-cartridge-file-builder'; export * from './builders/common-cartridge-organization-builder'; -export * from './common-cartridge.enums'; +export { CommonCartridgeResourceType, CommonCartridgeVersion } from './common-cartridge.enums'; export { CommonCartridgeMetadataElementProps } from './elements/common-cartridge-metadata-element'; export { CommonCartridgeResourceProps } from './resources/common-cartridge-resource-factory'; export { OmitVersion } from './utils'; diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts index 3f4754de724..2811b684d8c 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts @@ -12,7 +12,6 @@ export type CommonCartridgeWebContentResourceProps = { folder: string; title: string; html: string; - intendedUse?: CommonCartridgeIntendedUseType; }; export class CommonCartridgeWebContentResource implements CommonCartridgeResource { @@ -35,7 +34,10 @@ export class CommonCartridgeWebContentResource implements CommonCartridgeResourc $: { identifier: this.props.identifier, type: this.props.type, - intendeduse: this.props.intendedUse ?? CommonCartridgeIntendedUseType.UNSPECIFIED, + intendeduse: + this.props.version === CommonCartridgeVersion.V_1_3_0 + ? CommonCartridgeIntendedUseType.ASSIGNMENT + : CommonCartridgeIntendedUseType.UNSPECIFIED, }, file: { $: { diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index 534f24ce16c..735348149b1 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -1 +1,201 @@ -describe('CommonCartridgeMapper', () => {}); +import { MikroORM } from '@mikro-orm/core'; +import { ComponentProperties, ComponentType } from '@shared/domain'; +import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing'; +import { + CommonCartridgeMetadataElementProps, + CommonCartridgeOrganizationBuilderOptions, + CommonCartridgeResourceProps, + CommonCartridgeResourceType, + OmitVersion, +} from '../common-cartridge'; +import { CommonCartridgeMapper } from './common-cartridge.mapper'; + +describe('CommonCartridgeMapper', () => { + let orm: MikroORM; + + beforeAll(async () => { + orm = await setupEntities(); + }); + + afterAll(async () => { + await orm.close(); + }); + + describe('mapCourseToMetadata', () => { + describe('when mapping course to metadata', () => { + const course = courseFactory.buildWithId(); + + it('should map to metadata', () => { + const metadataProps = CommonCartridgeMapper.mapCourseToMetadata(course); + + expect(metadataProps).toStrictEqual>({ + title: course.name, + copyrightOwners: course.teachers + .toArray() + .map((teacher) => `${teacher.firstName} ${teacher.lastName}`), + creationDate: course.createdAt, + }); + }); + }); + }); + + describe('mapLessonToOrganization', () => { + describe('when mapping lesson to organization', () => { + const lesson = lessonFactory.buildWithId(); + + it('should map to organization', () => { + const organizationProps = CommonCartridgeMapper.mapLessonToOrganization(lesson); + + expect(organizationProps).toStrictEqual>({ + identifier: lesson.id, + title: lesson.name, + }); + }); + }); + }); + + describe('mapContentToOrganization', () => { + describe('when mapping content to organization', () => { + const componentProps: ComponentProperties = { + _id: 'id', + title: 'title', + hidden: false, + component: ComponentType.TEXT, + content: { + text: 'text', + }, + }; + + it('should map to organization', () => { + const organizationProps = CommonCartridgeMapper.mapContentToOrganization(componentProps); + + expect(organizationProps).toStrictEqual>({ + identifier: componentProps._id as string, + title: componentProps.title, + }); + }); + }); + }); + + describe('mapTaskToResource', () => { + describe('when mapping task', () => { + const task = taskFactory.buildWithId(); + + it('should map to web content', () => { + const resourceProps = CommonCartridgeMapper.mapTaskToResource(task); + + expect(resourceProps).toStrictEqual({ + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: task.id, + title: task.name, + html: `

${task.name}

${task.description}

`, + }); + }); + }); + }); + + describe('mapContentToResources', () => { + describe('when mapping text content', () => { + const componentProps: ComponentProperties = { + _id: 'id', + title: 'title', + hidden: false, + component: ComponentType.TEXT, + content: { + text: 'text', + }, + }; + + it('should map to web content', () => { + const resourceProps = CommonCartridgeMapper.mapContentToResources(componentProps); + + expect(resourceProps).toStrictEqual({ + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: componentProps._id as string, + title: componentProps.title, + html: `

${componentProps.title}

${componentProps?.content.text}

`, + }); + }); + }); + + describe('when mapping geogebra content', () => { + const componentProps: ComponentProperties = { + _id: 'id', + title: 'title', + hidden: false, + component: ComponentType.GEOGEBRA, + content: { + materialId: 'material-id', + }, + }; + + it('should map to web link', () => { + const resourceProps = CommonCartridgeMapper.mapContentToResources(componentProps); + + expect(resourceProps).toStrictEqual({ + type: CommonCartridgeResourceType.WEB_LINK, + identifier: componentProps._id as string, + title: componentProps.title, + url: `https://www.geogebra.org/m/${componentProps.content.materialId}`, + }); + }); + }); + + describe('when mapping etherpad content', () => { + const componentProps: ComponentProperties = { + _id: 'id', + title: 'title', + hidden: false, + component: ComponentType.ETHERPAD, + content: { + description: 'description', + title: 'title', + url: 'url', + }, + }; + + it('should map to web link', () => { + const resourceProps = CommonCartridgeMapper.mapContentToResources(componentProps); + + expect(resourceProps).toStrictEqual({ + type: CommonCartridgeResourceType.WEB_LINK, + identifier: componentProps._id as string, + title: `${componentProps.content.title} - ${componentProps.content.description}`, + url: componentProps.content.url, + }); + }); + }); + + describe('when mapping learning store content to resources', () => { + const componentProps: ComponentProperties = { + _id: 'id', + title: 'title', + hidden: false, + component: ComponentType.LERNSTORE, + content: { + resources: [ + { + client: 'client', + description: 'description', + title: 'title', + url: 'url', + }, + ], + }, + }; + + it('should map to web link', () => { + const resourceProps = CommonCartridgeMapper.mapContentToResources(componentProps); + + expect(resourceProps).toStrictEqual([ + { + type: CommonCartridgeResourceType.WEB_LINK, + identifier: componentProps._id as string, + title: componentProps.content?.resources[0].description as string, + url: componentProps.content?.resources[0].url as string, + }, + ]); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 8baa401f876..5d50e07f8d2 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -1,12 +1,10 @@ import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain'; import { ObjectId } from 'bson'; import { - CommonCartridgeIntendedUseType, CommonCartridgeMetadataElementProps, CommonCartridgeOrganizationBuilderOptions, CommonCartridgeResourceProps, CommonCartridgeResourceType, - CommonCartridgeVersion, OmitVersion, } from '../common-cartridge'; @@ -35,22 +33,17 @@ export class CommonCartridgeMapper { }; } - static mapTaskToResource(task: Task, version: CommonCartridgeVersion): CommonCartridgeResourceProps { + static mapTaskToResource(task: Task): CommonCartridgeResourceProps { return { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: task.id, title: task.name, html: `

${task.name}

${task.description}

`, - intendedUse: - version === CommonCartridgeVersion.V_1_1_0 - ? CommonCartridgeIntendedUseType.UNSPECIFIED - : CommonCartridgeIntendedUseType.ASSIGNMENT, }; } static mapContentToResources( - content: ComponentProperties, - version: CommonCartridgeVersion + content: ComponentProperties ): CommonCartridgeResourceProps | CommonCartridgeResourceProps[] { switch (content.component) { case ComponentType.TEXT: @@ -59,10 +52,6 @@ export class CommonCartridgeMapper { identifier: content._id || new ObjectId().toHexString(), title: content.title, html: `

${content.title}

${content.content.text}

`, - intendedUse: - version === CommonCartridgeVersion.V_1_1_0 - ? CommonCartridgeIntendedUseType.UNSPECIFIED - : CommonCartridgeIntendedUseType.ASSIGNMENT, }; case ComponentType.GEOGEBRA: return { From 6d30635c482296105a5539a01bcd66b3178a87bf Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 1 Dec 2023 15:21:30 +0100 Subject: [PATCH 042/177] EW-539 working on tests --- TODO.md | 4 +- .../common-cartridge-lti-resource.ts | 2 +- .../common-cartridge-web-content-resource.ts | 2 +- .../common-cartridge-web-link-resource.ts | 2 +- .../mapper/common-cartridge.mapper.ts | 10 +- .../common-cartridge-export.service.spec.ts | 193 +++++------------- .../common-cartridge-export.service.ts | 26 +-- 7 files changed, 67 insertions(+), 172 deletions(-) diff --git a/TODO.md b/TODO.md index 140aa806db5..5d0bfca2d2d 100644 --- a/TODO.md +++ b/TODO.md @@ -92,8 +92,6 @@ ### EW-539 -- tests for CCExportService -- tests for CCMapper - tests for CCManifestResource -- tests for CC*Element - Cleanup FIXMEs +- Manual tests diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts index 4ad8fae9341..f162d8e76e3 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts @@ -55,7 +55,7 @@ export class CommonCartridgeLtiResource implements CommonCartridgeResource { }, file: { $: { - href: this.props.folder, + href: this.getFilePath(), }, }, }; diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts index 2811b684d8c..8c17f29667e 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts @@ -41,7 +41,7 @@ export class CommonCartridgeWebContentResource implements CommonCartridgeResourc }, file: { $: { - href: this.props.folder, + href: this.getFilePath(), }, }, }; diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts index 38fdf185563..715ce17fe93 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts @@ -46,7 +46,7 @@ export class CommonCartridgeWebLinkResource implements CommonCartridgeResource { }, file: { $: { - href: this.props.folder, + href: this.getFilePath(), }, }, }; diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 5d50e07f8d2..a6364faa245 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -28,7 +28,7 @@ export class CommonCartridgeMapper { content: ComponentProperties ): OmitVersion { return { - identifier: content._id || new ObjectId().toHexString(), + identifier: new ObjectId(content._id).toHexString(), title: content.title, }; } @@ -49,21 +49,21 @@ export class CommonCartridgeMapper { case ComponentType.TEXT: return { type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: content._id || new ObjectId().toHexString(), + identifier: new ObjectId(content._id).toHexString(), title: content.title, html: `

${content.title}

${content.content.text}

`, }; case ComponentType.GEOGEBRA: return { type: CommonCartridgeResourceType.WEB_LINK, - identifier: content._id || new ObjectId().toHexString(), + identifier: new ObjectId(content._id).toHexString(), title: content.title, url: `https://www.geogebra.org/m/${content.content.materialId}`, // FIXME: hardcoded hostname }; case ComponentType.ETHERPAD: return { type: CommonCartridgeResourceType.WEB_LINK, - identifier: content._id || new ObjectId().toHexString(), + identifier: new ObjectId(content._id).toHexString(), title: `${content.content.title} - ${content.content.description}`, url: content.content.url, }; @@ -72,7 +72,7 @@ export class CommonCartridgeMapper { content.content?.resources.map((resource) => { return { type: CommonCartridgeResourceType.WEB_LINK, - identifier: content._id || new ObjectId().toHexString(), + identifier: new ObjectId().toHexString(), title: resource.description, url: resource.url, }; diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index 5f3bf951c45..80c3efb283f 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -1,21 +1,11 @@ -import { faker } from '@faker-js/faker'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { CommonCartridgeExportService, CourseService } from '@modules/learnroom'; import { LessonService } from '@modules/lesson'; import { TaskService } from '@modules/task'; import { Test, TestingModule } from '@nestjs/testing'; -import { - ComponentLernstoreProperties, - ComponentProperties, - ComponentTextProperties, - ComponentType, - Course, - LessonEntity, - Task, -} from '@shared/domain'; +import { ComponentType, Course, LessonEntity, Task } from '@shared/domain'; import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing'; import AdmZip from 'adm-zip'; -import { writeFile } from 'fs/promises'; import { CommonCartridgeVersion } from '../common-cartridge'; describe('CommonCartridgeExportService', () => { @@ -29,6 +19,11 @@ describe('CommonCartridgeExportService', () => { let lessons: LessonEntity[]; let tasks: Task[]; + const createXmlString = (nodeName: string, value: boolean | number | string): string => + `<${nodeName}>${value.toString()}`; + const getFileContent = (archive: AdmZip, filePath: string): string | undefined => + archive.getEntry(filePath)?.getData().toString(); + beforeAll(async () => { await setupEntities(); module = await Test.createTestingModule({ @@ -53,41 +48,40 @@ describe('CommonCartridgeExportService', () => { lessonServiceMock = module.get(LessonService); taskServiceMock = module.get(TaskService); course = courseFactory.teachersWithId(2).buildWithId(); + tasks = taskFactory.buildListWithId(2); lessons = lessonFactory.buildListWithId(1, { contents: [ { - _id: faker.string.uuid(), + title: 'text-title', hidden: false, component: ComponentType.TEXT, - title: 'Text', content: { text: 'text', }, - } as ComponentProperties, - { - _id: faker.string.uuid(), - hidden: false, - component: ComponentType.ETHERPAD, - title: 'Etherpad', - content: { - title: faker.lorem.words(2), - description: faker.lorem.sentence(), - url: 'https://google.com', - }, - } as ComponentProperties, + }, { - _id: faker.string.uuid(), + title: 'lernstore-title', hidden: false, - component: ComponentType.GEOGEBRA, - title: 'Geogebra', + component: ComponentType.LERNSTORE, content: { - materialId: 'https://google.com', + resources: [ + { + client: 'client-1', + description: 'description-1', + title: 'title-1', + url: 'url-1', + }, + { + client: 'board-2', + description: 'description-2', + title: 'title-2', + url: 'url-2', + }, + ], }, - } as ComponentProperties, - {} as ComponentProperties, + }, ], }); - tasks = taskFactory.buildListWithId(2); }); afterAll(async () => { @@ -97,160 +91,73 @@ describe('CommonCartridgeExportService', () => { describe('exportCourse', () => { const setupExport = async (version: CommonCartridgeVersion) => { const [lesson] = lessons; - const textContent = { text: 'Some random text' } as ComponentTextProperties; - const lessonContent: ComponentProperties = { - _id: 'random_id', - title: 'A random title', - hidden: false, - component: ComponentType.TEXT, - content: textContent, - }; - lesson.contents = [lessonContent]; + lessonServiceMock.findById.mockResolvedValueOnce(lesson); courseServiceMock.findById.mockResolvedValueOnce(course); lessonServiceMock.findByCourseIds.mockResolvedValueOnce([lessons, lessons.length]); taskServiceMock.findBySingleParent.mockResolvedValueOnce([tasks, tasks.length]); - const archive = new AdmZip(await courseExportService.exportCourse(course.id, '', version)); + const archive = new AdmZip(await courseExportService.exportCourse(course.id, 'user-id', version)); return archive; }; - describe('When Common Cartridge version 1.1', () => { + describe('when using version 1.1', () => { let archive: AdmZip; beforeAll(async () => { archive = await setupExport(CommonCartridgeVersion.V_1_1_0); }); - it('should create manifest file', () => { - expect(archive.getEntry('imsmanifest.xml')).toBeDefined(); + it('should use schema version 1.1.0', () => { + expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('schemaversion', '1.1.0')); }); - it('should add title to manifest file', () => { - expect(archive.getEntry('imsmanifest.xml')?.getData().toString()).toContain(course.name); + it('should add course', () => { + expect(getFileContent(archive, 'imsmanifest.xml')).toContain( + createXmlString('mnf:string', course.name) + ); }); - it('should add lessons as organization items to manifest file', () => { - const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); + it('should add lessons', () => { lessons.forEach((lesson) => { - expect(manifest).toContain(lesson.name); + expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('title', lesson.name)); }); }); - it('should add lesson text content to manifest file', () => { - const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); - expect(manifest).toContain(lessons[0].contents[0].title); - }); - - it('should add copyright information to manifest file', () => { - const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); - expect(manifest).toContain(course.teachers[0].firstName); - expect(manifest).toContain(course.teachers[0].lastName); - expect(manifest).toContain(course.teachers[1].firstName); - expect(manifest).toContain(course.teachers[1].lastName); - expect(manifest).toContain(course.createdAt.getFullYear().toString()); - }); - - it('should add tasks as assignments', () => { - const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); + it('should add tasks', () => { tasks.forEach((task) => { - expect(manifest).toContain(`${task.name}`); - expect(manifest).toContain(`identifier="i${task.id}" type="webcontent" intendeduse="unspecified"`); + expect(getFileContent(archive, 'imsmanifest.xml')).toContain(` { - const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); - expect(manifest).toContain(CommonCartridgeVersion.V_1_1_0); - }); }); - describe('When Common Cartridge version 1.3', () => { + describe('when using version 1.3', () => { let archive: AdmZip; beforeAll(async () => { archive = await setupExport(CommonCartridgeVersion.V_1_3_0); }); - it('should create manifest file', () => { - expect(archive.getEntry('imsmanifest.xml')).toBeDefined(); + it('should use schema version 1.3.0', () => { + expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('schemaversion', '1.3.0')); }); - it('should add title to manifest file', () => { - expect(archive.getEntry('imsmanifest.xml')?.getData().toString()).toContain(course.name); + it('should add course', () => { + expect(getFileContent(archive, 'imsmanifest.xml')).toContain( + createXmlString('mnf:string', course.name) + ); }); - it('should add lessons as organization items to manifest file', () => { - const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); + it('should add lessons', () => { lessons.forEach((lesson) => { - expect(manifest).toContain(lesson.name); + expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('title', lesson.name)); }); }); - it('should add lesson text content to manifest file', () => { - const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); - expect(manifest).toContain(lessons[0].contents[0].title); - }); - - it('should add copyright information to manifest file', () => { - const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); - expect(manifest).toContain(course.teachers[0].firstName); - expect(manifest).toContain(course.teachers[0].lastName); - expect(manifest).toContain(course.teachers[1].firstName); - expect(manifest).toContain(course.teachers[1].lastName); - expect(manifest).toContain(course.createdAt.getFullYear().toString()); - }); - - it('should add tasks as assignments', () => { - const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); + it('should add tasks', () => { tasks.forEach((task) => { - expect(manifest).toContain(`${task.name}`); - expect(manifest).toContain(`identifier="i${task.id}" type="webcontent" intendeduse="assignment"`); - }); - }); - - it('should add version 3 information to manifest file', () => { - const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); - expect(manifest).toContain(CommonCartridgeVersion.V_1_3_0); - }); - }); - - describe('when exporting learn store content from course with Common Cartridge 1.3', () => { - let archive: AdmZip; - let lernstoreProps: ComponentProperties; - - beforeAll(async () => { - const [lesson] = lessons; - - archive = await setupExport(CommonCartridgeVersion.V_1_3_0); - lernstoreProps = lesson.contents.filter((content) => content.component === ComponentType.LERNSTORE)[0]; - - await writeFile('test.zip', archive.toBuffer(), 'binary'); - }); - - it('should add learn store content to manifest file', () => { - // AI next 3 lines - const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); - - expect(manifest).toContain(lernstoreProps.title); - }); - - it.skip('should create directory for each learn store content', () => { - // AI next 3 lines - const directory = archive.getEntry(`i${lernstoreProps._id as string}/`); - - expect(directory).toBeDefined(); - }); - - it.skip('should add learn store content as web links to directory', () => { - expect(lernstoreProps.content).toBeDefined(); - expect((lernstoreProps.content as ComponentLernstoreProperties).resources).toHaveLength(2); - - (lernstoreProps.content as ComponentLernstoreProperties).resources.forEach((resource) => { - const file = archive.getEntry(`i${lernstoreProps._id as string}/${resource.title}.html`); - - expect(file).toBeDefined(); + expect(getFileContent(archive, 'imsmanifest.xml')).toContain(` { + private async addLessons(builder: CommonCartridgeFileBuilder, courseId: EntityId): Promise { const [lessons] = await this.lessonService.findByCourseIds([courseId]); lessons.forEach((lesson) => { const organizationBuilder = builder.addOrganization(CommonCartridgeMapper.mapLessonToOrganization(lesson)); lesson.contents.forEach((content) => { - this.addComponent(organizationBuilder, content, version); + this.addComponent(organizationBuilder, content); }); }); } - private async addTasks( - builder: CommonCartridgeFileBuilder, - version: CommonCartridgeVersion, - courseId: EntityId, - userId: EntityId - ): Promise { + private async addTasks(builder: CommonCartridgeFileBuilder, courseId: EntityId, userId: EntityId): Promise { const [tasks] = await this.taskService.findBySingleParent(userId, courseId); const organizationBuilder = builder.addOrganization({ identifier: new ObjectId().toHexString(), @@ -63,16 +54,15 @@ export class CommonCartridgeExportService { }); tasks.forEach((task) => { - organizationBuilder.addResource(CommonCartridgeMapper.mapTaskToResource(task, version)); + organizationBuilder.addResource(CommonCartridgeMapper.mapTaskToResource(task)); }); } private addComponent( organizationBuilder: CommonCartridgeOrganizationBuilder, - component: ComponentProperties, - version: CommonCartridgeVersion + component: ComponentProperties ): void { - const resources = CommonCartridgeMapper.mapContentToResources(component, version); + const resources = CommonCartridgeMapper.mapContentToResources(component); if (!Array.isArray(resources)) { organizationBuilder.addResource(resources); From e0135a96eb5088528cf852b1f995d6b654778c79 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 4 Dec 2023 08:41:35 +0100 Subject: [PATCH 043/177] EW-539 Adjust test for lti resource --- .../resources/common-cartridge-lti-resource.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts index 3e881f83bd3..d06c67b2a22 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts @@ -6,7 +6,7 @@ describe('CommonCartridgeLtiResource', () => { type: CommonCartridgeResourceType.LTI, version: CommonCartridgeVersion.V_1_1_0, identifier: 'lti-identifier-version1', - folder: 'lti-identifier-version1/lti.xml', + folder: 'lti-identifier-version1', title: 'lti-title-version1', description: 'lti-description-version1', url: 'https://to-a-lti-tool-version1.tld', @@ -16,7 +16,7 @@ describe('CommonCartridgeLtiResource', () => { type: CommonCartridgeResourceType.LTI, version: CommonCartridgeVersion.V_1_3_0, identifier: 'lti-identifier-version3', - folder: 'lti-identifier-version3/lti.xml', + folder: 'lti-identifier-version3', title: 'lti-title-version3', description: 'lti-description-version3', url: 'https://to-a-lti-tool-version3.tld', From f37f4829082c5c8b113e8963483707da8087e101 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 4 Dec 2023 08:42:33 +0100 Subject: [PATCH 044/177] EW-539 Correct namespaces by versions --- .../common-cartridge-manifest-resource.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts index c727b29513f..30ff1584451 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts @@ -47,6 +47,18 @@ export class CommonCartridgeManifestResource implements CommonCartridgeResource private getXmlNamespacesByVersion(): Record { switch (this.props.version) { case CommonCartridgeVersion.V_1_1_0: + return { + identifier: this.props.identifier, + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', + 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', + 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd ' + + 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ', + }; + case CommonCartridgeVersion.V_1_3_0: return { identifier: this.props.identifier, xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1', @@ -60,18 +72,6 @@ export class CommonCartridgeManifestResource implements CommonCartridgeResource 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd ' + 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_cpextensionv1p2_v1p0.xsd', }; - case CommonCartridgeVersion.V_1_3_0: - return { - identifier: this.props.identifier, - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', - 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', - 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd ' + - 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ', - }; default: throw createVersionNotSupportedError(this.props.version); } From c046c1fce27c4fc759b574bdad9d081a4ee81001 Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 4 Dec 2023 09:33:04 +0100 Subject: [PATCH 045/177] EW-539 adding config --- .../common-cartridge/common-cartridge.config.ts | 3 +++ .../src/modules/learnroom/common-cartridge/index.ts | 1 + .../learnroom/controller/course.controller.ts | 12 ++++++++++-- apps/server/src/modules/server/server.config.ts | 12 +++++++++--- config/default.schema.json | 4 ++-- config/development.json | 2 +- config/test.json | 2 +- src/services/config/publicAppConfigService.js | 2 +- 8 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts new file mode 100644 index 00000000000..8239e1c04e8 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts @@ -0,0 +1,3 @@ +export interface CommonCartridgeConfig { + FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED: boolean; +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/index.ts b/apps/server/src/modules/learnroom/common-cartridge/index.ts index 237fcaa46e3..f64e53c3c24 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/index.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/index.ts @@ -1,5 +1,6 @@ export * from './builders/common-cartridge-file-builder'; export * from './builders/common-cartridge-organization-builder'; +export * from './common-cartridge.config'; export { CommonCartridgeResourceType, CommonCartridgeVersion } from './common-cartridge.enums'; export { CommonCartridgeMetadataElementProps } from './elements/common-cartridge-metadata-element'; export { CommonCartridgeResourceProps } from './resources/common-cartridge-resource-factory'; diff --git a/apps/server/src/modules/learnroom/controller/course.controller.ts b/apps/server/src/modules/learnroom/controller/course.controller.ts index 7f026002ea7..57e575d2d13 100644 --- a/apps/server/src/modules/learnroom/controller/course.controller.ts +++ b/apps/server/src/modules/learnroom/controller/course.controller.ts @@ -39,12 +39,20 @@ export class CourseController { @Query() queryParams: CourseQueryParams, @Res({ passthrough: true }) response: Response ): Promise { - if (!this.configService.get('FEATURE_IMSCC_COURSE_EXPORT_ENABLED')) throw new NotFoundException(); - const result = await this.courseExportUc.exportCourse(urlParams.courseId, currentUser.userId, queryParams.version); + if (!this.configService.get('FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED')) + throw new NotFoundException(); + + const result = await this.courseExportUc.exportCourse( + urlParams.courseId, + currentUser.userId, + queryParams.version + ); + response.set({ 'Content-Type': 'application/zip', 'Content-Disposition': 'attachment;', }); + return new StreamableFile(result); } } diff --git a/apps/server/src/modules/server/server.config.ts b/apps/server/src/modules/server/server.config.ts index c119d0fa25a..1e61f738f76 100644 --- a/apps/server/src/modules/server/server.config.ts +++ b/apps/server/src/modules/server/server.config.ts @@ -37,10 +37,16 @@ const config: ServerConfig = { TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE: Configuration.get( 'TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE' ) as boolean, - FEATURE_IMSCC_COURSE_EXPORT_ENABLED: Configuration.get('FEATURE_IMSCC_COURSE_EXPORT_ENABLED') as boolean, + FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED: Configuration.get( + 'FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED' + ) as boolean, FEATURE_IDENTITY_MANAGEMENT_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_ENABLED') as boolean, - FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED') as boolean, - FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED') as boolean, + FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED: Configuration.get( + 'FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED' + ) as boolean, + FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED: Configuration.get( + 'FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED' + ) as boolean, ADDITIONAL_BLACKLISTED_EMAIL_DOMAINS: (Configuration.get('ADDITIONAL_BLACKLISTED_EMAIL_DOMAINS') as string) .split(',') .map((domain) => domain.trim()), diff --git a/config/default.schema.json b/config/default.schema.json index 89d0a328a59..d31f1dfa163 100644 --- a/config/default.schema.json +++ b/config/default.schema.json @@ -177,7 +177,7 @@ }, "ADDITIONAL_BLACKLISTED_EMAIL_DOMAINS": { "type": "string", - "default":"", + "default": "", "description": "Add custom domain to the list of blocked domains (comma separated list)." }, "FEATURE_TSP_AUTO_CONSENT_ENABLED": { @@ -1124,7 +1124,7 @@ "default": false, "description": "Toggle for copy course feature." }, - "FEATURE_IMSCC_COURSE_EXPORT_ENABLED": { + "FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED": { "type": "boolean", "default": false, "description": "Toggle for the IMSCC course download feature." diff --git a/config/development.json b/config/development.json index eb106993b10..fde0a6a3a4c 100644 --- a/config/development.json +++ b/config/development.json @@ -69,7 +69,7 @@ "SECRET": "devSecret" }, "HYDRA_URI": "http://localhost:9001", - "FEATURE_IMSCC_COURSE_EXPORT_ENABLED": true, + "FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED": true, "NEST_LOG_LEVEL": "debug", "SESSION_SECRET": "dev-session-secret", "FEATURE_COURSE_SHARE": true, diff --git a/config/test.json b/config/test.json index c8b82b383ba..5184d88c4d2 100644 --- a/config/test.json +++ b/config/test.json @@ -47,7 +47,7 @@ "NEST_LOG_LEVEL": "error", "CALENDAR_URI": "https://schul.tech:3000", "HYDRA_URI": "http://hydra:9000", - "FEATURE_IMSCC_COURSE_EXPORT_ENABLED": true, + "FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED": true, "SESSION": { "SAME_SITE": "lax", "SECURE": false, diff --git a/src/services/config/publicAppConfigService.js b/src/services/config/publicAppConfigService.js index 62615f0efb1..09b697fa994 100644 --- a/src/services/config/publicAppConfigService.js +++ b/src/services/config/publicAppConfigService.js @@ -51,7 +51,7 @@ const exposedVars = [ 'ACCESSIBILITY_REPORT_EMAIL', 'GHOST_BASE_URL', 'FEATURE_CONSENT_NECESSARY', - 'FEATURE_IMSCC_COURSE_EXPORT_ENABLED', + 'FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED', 'FEATURE_SCHOOL_SANIS_USER_MIGRATION_ENABLED', 'FEATURE_ALLOW_INSECURE_LDAP_URL_ENABLED', 'FEATURE_NEW_SCHOOL_ADMINISTRATION_PAGE_AS_DEFAULT_ENABLED', From 717c6023f4dbfb5caea77534a997a82c760a799a Mon Sep 17 00:00:00 2001 From: Thomas Feldtkeller Date: Mon, 4 Dec 2023 12:02:40 +0100 Subject: [PATCH 046/177] review comments 04.12.23 --- .../builders/common-cartridge-file-builder.spec.ts | 10 +++++----- .../builders/common-cartridge-file-builder.ts | 2 ++ .../common-cartridge-organization-builder.spec.ts | 7 +++++++ .../common-cartridge/common-cartridge.config.ts | 1 + .../common-cartridge/common-cartridge.enums.ts | 2 ++ .../elements/common-cartridge-metadata-element.spec.ts | 1 + .../resources/common-cartridge-resource-factory.ts | 1 + .../modules/learnroom/common-cartridge/review-notes.md | 5 +++++ .../learnroom/mapper/common-cartridge.mapper.ts | 1 + .../service/common-cartridge-export.service.spec.ts | 2 ++ .../service/common-cartridge-export.service.ts | 2 ++ 11 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/review-notes.md diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts index ea5ad639ea0..92dd82daf85 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts @@ -53,7 +53,7 @@ describe('CommonCartridgeFileBuilder', () => { }; describe('build', () => { - describe('when creating a common cartridge archive', () => { + describe('when a common cartridge archive has been created', () => { beforeAll(async () => { sut = new CommonCartridgeFileBuilder(fileBuilderOptions); sut.addMetadata(metadataProps) @@ -67,19 +67,19 @@ describe('CommonCartridgeFileBuilder', () => { archive = new AdmZip(await sut.build()); }); - it('should create imsmanifest.xml in archive root', () => { + it('should have a imsmanifest.xml in archive root', () => { const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); expect(manifest).toBeDefined(); }); - it('should create resource in organization folder', () => { + it('should have included the resource in organization folder', () => { const resource = getFileContentAsString(archive, 'organization-identifier/resource-1-identifier.html'); expect(resource).toBeDefined(); }); - it('should create resource in sub-organization folder', () => { + it('should have included the resource in sub-organization folder', () => { const resource = getFileContentAsString( archive, 'organization-identifier/sub-organization-identifier/resource-2-identifier.html' @@ -88,7 +88,7 @@ describe('CommonCartridgeFileBuilder', () => { expect(resource).toBeDefined(); }); - it('should create resource in sub-sub-organization folder', () => { + it('should have included the resource in sub-sub-organization folder', () => { const resource = getFileContentAsString( archive, 'organization-identifier/sub-organization-identifier/sub-sub-organization-identifier/resource-3-identifier.html' diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts index 33bc8b1c748..d7f198f62f1 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts @@ -31,6 +31,8 @@ export class CommonCartridgeFileBuilder { checkCommonCartridgeVersion(props.version); } + // TODO: explicitly mark public methods + addMetadata(props: OmitVersion): CommonCartridgeFileBuilder { this.metadata = new CommonCartridgeMetadataElement({ ...props, version: this.props.version }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts index 236bcb9b1fb..d5a6c3642a2 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts @@ -50,6 +50,13 @@ describe('CommonCartridgeOrganizationBuilder', () => { jest.clearAllMocks(); }); + /* + TODO: + - create testfactories for CommonCartridgeResourceProps and CommonCartridgeOrganizationBuilderOptions + - move fixture creation into setup function (you can even inline it, eg. .addSubOrganization(CommonCartrigeOrganizationFactory.build())) + - use setup function instead of beforeAll to get rid of "global" variables + */ + describe('build', () => { describe('when creating a common cartridge archive', () => { beforeAll(() => { diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts index 8239e1c04e8..26a856fff82 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts @@ -1,3 +1,4 @@ +// TODO: move into learnroom config, since its controlling a course route export interface CommonCartridgeConfig { FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED: boolean; } diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts index 0b03cdbdc09..96380d265ba 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts @@ -6,6 +6,8 @@ export enum CommonCartridgeVersion { V_1_4_0 = '1.4.0', } +// TODO: think about if there is a way to ensure that an implementation that is dependent on these versions has implementations for all versions. (HINT: helper class, composable, abstract class...) + export enum CommonCartridgeResourceType { LTI = 'lti', WEB_CONTENT = 'webcontent', diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts index b54a239de42..c1242518055 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts @@ -7,6 +7,7 @@ import { describe('CommonCartridgeMetadataElement', () => { let sut: CommonCartridgeMetadataElement; + // move testfixtures into the blocks they are used in const propsVersion1: CommonCartridgeMetadataElementProps = { version: CommonCartridgeVersion.V_1_1_0, title: 'Metadata Element Version 1.1', diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts index 5a457249a57..6a00f29c64e 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts @@ -31,6 +31,7 @@ export class CommonCartridgeResourceFactory { case CommonCartridgeResourceType.WEB_LINK: return new CommonCartridgeWebLinkResource(props); default: + // use InternalServerErrorException throw new Error(`Unknown Common Cartridge resource type`); } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/review-notes.md b/apps/server/src/modules/learnroom/common-cartridge/review-notes.md new file mode 100644 index 00000000000..5c2d061949b --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/review-notes.md @@ -0,0 +1,5 @@ +# review 04.12.23 + +- put all course-independent code into a seperate "common-cartrige" module +- import common-cartrige into learnroom +- adjust all tests to avoid global variables. create factories where useful, and use setup function instead of beforeAll \ No newline at end of file diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index a6364faa245..dd2d4f139ee 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -58,6 +58,7 @@ export class CommonCartridgeMapper { type: CommonCartridgeResourceType.WEB_LINK, identifier: new ObjectId(content._id).toHexString(), title: content.title, + // TODO: put into environment, talk to capcakes if geogebra has been moved to tools, maybe there is a url in the data by now url: `https://www.geogebra.org/m/${content.content.materialId}`, // FIXME: hardcoded hostname }; case ComponentType.ETHERPAD: diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index 80c3efb283f..bba078b26bf 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -15,6 +15,7 @@ describe('CommonCartridgeExportService', () => { let lessonServiceMock: DeepMocked; let taskServiceMock: DeepMocked; + // move into setup methods let course: Course; let lessons: LessonEntity[]; let tasks: Task[]; @@ -47,6 +48,7 @@ describe('CommonCartridgeExportService', () => { courseServiceMock = module.get(CourseService); lessonServiceMock = module.get(LessonService); taskServiceMock = module.get(TaskService); + // TODO: everything below this line belongs into setup methods course = courseFactory.teachersWithId(2).buildWithId(); tasks = taskFactory.buildListWithId(2); lessons = lessonFactory.buildListWithId(1, { diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 5924efb198e..d318971066a 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -47,7 +47,9 @@ export class CommonCartridgeExportService { } private async addTasks(builder: CommonCartridgeFileBuilder, courseId: EntityId, userId: EntityId): Promise { + // TODO: figure out with UX/PM if drafts should be exported. explicitly set the option const [tasks] = await this.taskService.findBySingleParent(userId, courseId); + // TODO: each task can be their own organisation const organizationBuilder = builder.addOrganization({ identifier: new ObjectId().toHexString(), title: '', // FIXME: add title From f9e3b3f9cff64ab92bba6f980d3a0739f15e42f8 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 4 Dec 2023 13:18:00 +0100 Subject: [PATCH 047/177] EW-539 Mark methods as public --- .../builders/common-cartridge-file-builder.ts | 10 +++++----- .../builders/common-cartridge-organization-builder.ts | 6 +++--- .../elements/common-cartridge-metadata-element.ts | 2 +- .../elements/common-cartridge-organization-element.ts | 2 +- .../common-cartridge-organizations-wrapper-element.ts | 2 +- .../common-cartridge-resources-wrapper-element.ts | 2 +- .../resources/common-cartridge-lti-resource.ts | 8 ++++---- .../resources/common-cartridge-manifest-resource.ts | 8 ++++---- .../resources/common-cartridge-web-content-resource.ts | 8 ++++---- .../resources/common-cartridge-web-link-resource.ts | 8 ++++---- 10 files changed, 28 insertions(+), 28 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts index d7f198f62f1..ed9cbf69ea0 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts @@ -31,15 +31,15 @@ export class CommonCartridgeFileBuilder { checkCommonCartridgeVersion(props.version); } - // TODO: explicitly mark public methods - - addMetadata(props: OmitVersion): CommonCartridgeFileBuilder { + public addMetadata(props: OmitVersion): CommonCartridgeFileBuilder { this.metadata = new CommonCartridgeMetadataElement({ ...props, version: this.props.version }); return this; } - addOrganization(props: OmitVersion): CommonCartridgeOrganizationBuilder { + public addOrganization( + props: OmitVersion + ): CommonCartridgeOrganizationBuilder { const builder = new CommonCartridgeOrganizationBuilder( { ...props, version: this.props.version }, this.addResource.bind(this) @@ -50,7 +50,7 @@ export class CommonCartridgeFileBuilder { return builder; } - build(): Promise { + public build(): Promise { const metadata = checkDefined(this.metadata, 'metadata'); const organizations = this.organizationBuilders.map((builder) => builder.build()); const manifest = new CommonCartridgeManifestResource({ diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts index 474eb6a4345..e9cea3cd2fa 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts @@ -29,7 +29,7 @@ export class CommonCartridgeOrganizationBuilder { return this.options.folder ? `${this.options.folder}/${this.options.identifier}` : this.options.identifier; } - addSubOrganization( + public addSubOrganization( options: OmitVersionAndFolder ): CommonCartridgeOrganizationBuilder { const child = new CommonCartridgeOrganizationBuilder( @@ -42,7 +42,7 @@ export class CommonCartridgeOrganizationBuilder { return child; } - addResource(props: CommonCartridgeResourceProps): CommonCartridgeOrganizationBuilder { + public addResource(props: CommonCartridgeResourceProps): CommonCartridgeOrganizationBuilder { const resource = CommonCartridgeResourceFactory.create({ ...props, version: this.options.version, @@ -55,7 +55,7 @@ export class CommonCartridgeOrganizationBuilder { return this; } - build(): CommonCartridgeElement { + public build(): CommonCartridgeElement { return new CommonCartridgeOrganizationElement({ identifier: this.options.identifier, title: this.options.title, diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts index 70fd3101bdd..63a826075f9 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts @@ -11,7 +11,7 @@ export type CommonCartridgeMetadataElementProps = { export class CommonCartridgeMetadataElement implements CommonCartridgeElement { constructor(private readonly props: CommonCartridgeMetadataElementProps) {} - getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { schema: 'IMS Common Cartridge', schemaversion: this.props.version, diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts index f4e5b5c6c58..96926074a01 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts @@ -9,7 +9,7 @@ type CommonCartridgeOrganizationElementProps = { export class CommonCartridgeOrganizationElement implements CommonCartridgeElement { constructor(private readonly props: CommonCartridgeOrganizationElementProps) {} - getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { $: { identifier: this.props.identifier, diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts index 6bd41f8aea7..ab56623261d 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts @@ -3,7 +3,7 @@ import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.i export class CommonCartridgeOrganizationsWrapperElement implements CommonCartridgeElement { constructor(private readonly items: CommonCartridgeElement[]) {} - getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { organization: [ { diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts index e6f91f5aa05..c0b47b3f628 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts @@ -3,7 +3,7 @@ import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.i export class CommonCartridgeResourcesWrapperElement implements CommonCartridgeElement { constructor(private readonly items: CommonCartridgeElement[]) {} - getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { resources: [ { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts index f162d8e76e3..f7c9d91d736 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts @@ -15,15 +15,15 @@ export type CommonCartridgeLtiResourceProps = { export class CommonCartridgeLtiResource implements CommonCartridgeResource { constructor(private readonly props: CommonCartridgeLtiResourceProps) {} - canInline(): boolean { + public canInline(): boolean { return false; } - getFilePath(): string { + public getFilePath(): string { return `${this.props.folder}/${this.props.identifier}.xml`; } - getFileContent(): string { + public getFileContent(): string { return buildXmlString({ cartridge_basiclti_link: { $: this.getXmlNamespacesByVersion(), @@ -47,7 +47,7 @@ export class CommonCartridgeLtiResource implements CommonCartridgeResource { }); } - getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { $: { identifier: this.props.identifier, diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts index 30ff1584451..5b120d085fe 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts @@ -19,19 +19,19 @@ export class CommonCartridgeManifestResource implements CommonCartridgeResource constructor(private readonly props: CommonCartridgeManifestElementProps) {} - canInline(): boolean { + public canInline(): boolean { return false; } - getFilePath(): string { + public getFilePath(): string { return 'imsmanifest.xml'; } - getFileContent(): string { + public getFileContent(): string { return this.xmlBuilder.buildObject(this.getManifestXmlObject()); } - getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { manifest: { $: this.getXmlNamespacesByVersion(), diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts index 8c17f29667e..a465c2a0d9b 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts @@ -17,19 +17,19 @@ export type CommonCartridgeWebContentResourceProps = { export class CommonCartridgeWebContentResource implements CommonCartridgeResource { constructor(private readonly props: CommonCartridgeWebContentResourceProps) {} - canInline(): boolean { + public canInline(): boolean { return false; } - getFilePath(): string { + public getFilePath(): string { return `${this.props.folder}/${this.props.identifier}.html`; } - getFileContent(): string { + public getFileContent(): string { return this.props.html; } - getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { $: { identifier: this.props.identifier, diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts index 715ce17fe93..bcc0d8d252d 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts @@ -14,15 +14,15 @@ export type CommonCartridgeWebLinkResourceProps = { export class CommonCartridgeWebLinkResource implements CommonCartridgeResource { constructor(private readonly props: CommonCartridgeWebLinkResourceProps) {} - canInline(): boolean { + public canInline(): boolean { return false; } - getFilePath(): string { + public getFilePath(): string { return `${this.props.folder}/${this.props.identifier}.xml`; } - getFileContent(): string { + public getFileContent(): string { return buildXmlString({ webLink: { $: this.getXmlNamespacesByVersion(), @@ -38,7 +38,7 @@ export class CommonCartridgeWebLinkResource implements CommonCartridgeResource { }); } - getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { $: { identifier: this.props.identifier, From 657716b721d627ee0cbff257c51d27c55d8d4521 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 4 Dec 2023 13:40:07 +0100 Subject: [PATCH 048/177] EW-539 Start to adjust test for manifest resource --- ...common-cartridge-manifest-resource.spec.ts | 187 +++++++++++++++--- 1 file changed, 161 insertions(+), 26 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts index 249756b872e..6ad7d9d5f3f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts @@ -1,34 +1,169 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeManifestElementProps } from './common-cartridge-manifest-resource'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeMetadataElement } from '../elements/common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElement } from '../elements/common-cartridge-organization-element'; +import { + CommonCartridgeManifestElementProps, + CommonCartridgeManifestResource, +} from './common-cartridge-manifest-resource'; +import { CommonCartridgeResourceFactory, CommonCartridgeResourceProps } from './common-cartridge-resource-factory'; describe('CommonCartridgeManifestResource', () => { + const metadataElementPropsVersion1 = { + version: CommonCartridgeVersion.V_1_1_0, + title: 'Manifest v1', + creationDate: new Date(), + copyrightOwners: ['Owner1Version1', 'Owner2Version2'], + }; + + const organizationElementPropsVersion1 = { + identifier: 'organization-v1', + title: 'Organization v1', + items: [], + }; + + const webcontentResourcePropsVersion1: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: 'webcontent-v1', + title: 'Webcontent Version 1', + html: '

Webcontent v1

', + }; + + const webcontentResourceVersion1 = CommonCartridgeResourceFactory.create({ + ...webcontentResourcePropsVersion1, + version: CommonCartridgeVersion.V_1_1_0, + folder: 'webcontent', + }); + const propsOfVersion1: CommonCartridgeManifestElementProps = { version: CommonCartridgeVersion.V_1_1_0, identifier: 'manifest-v1', - metadata: { - getManifestXml: () => { - return { - schema: 'IMS Common Cartridge', - schemaversion: propsOfVersion1.version, - 'mnf:lom': { - 'mnf:general': { - 'mnf:title': { - 'mnf:string': 'Manifest v1', - }, - }, - 'mnf:rights': { - 'mnf:copyrightAndOtherRestrictions': { - 'mnf:value': 'yes', - }, - 'mnf:description': { - 'mnf:string': 'Test Manifest V1', - }, + metadata: new CommonCartridgeMetadataElement(metadataElementPropsVersion1), + organizations: [new CommonCartridgeOrganizationElement(organizationElementPropsVersion1)], + resources: [webcontentResourceVersion1], + }; + + const metadataElementPropsVersion3 = { + version: CommonCartridgeVersion.V_1_3_0, + title: 'Manifest v3', + creationDate: new Date(), + copyrightOwners: ['Owner1Version3', 'Owner2Version3'], + }; + + const organizationElementPropsVersion3 = { + identifier: 'organization-v3', + title: 'Organization v3', + items: [], + }; + + const webcontentResourcePropsVersion3: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: 'webcontent-v3', + title: 'Webcontent Version 3', + html: '

Webcontent v3

', + }; + + const webcontentResourceVersion3 = CommonCartridgeResourceFactory.create({ + ...webcontentResourcePropsVersion3, + version: CommonCartridgeVersion.V_1_3_0, + folder: 'webcontent', + }); + + const propsOfVersion3: CommonCartridgeManifestElementProps = { + version: CommonCartridgeVersion.V_1_3_0, + identifier: 'manifest-v3', + metadata: new CommonCartridgeMetadataElement(metadataElementPropsVersion3), + organizations: [new CommonCartridgeOrganizationElement(organizationElementPropsVersion3)], + resources: [webcontentResourceVersion3], + }; + + const manifestResourceV1 = new CommonCartridgeManifestResource(propsOfVersion1); + const manifestResourceV3 = new CommonCartridgeManifestResource(propsOfVersion3); + + describe('canInline', () => { + // AI next 28 lines + describe('when common cartridge version 1.1', () => { + it('should return false', () => { + expect(manifestResourceV1.canInline()).toBe(false); + }); + }); + + describe('when common cartridge version 1.3', () => { + it('should return false', () => { + expect(manifestResourceV3.canInline()).toBe(false); + }); + }); + }); + + describe('getFilePath', () => { + describe('when common cartridge version 1.1', () => { + it('should return the file path regarding version 1.1', () => { + const filePathV1 = manifestResourceV1.getFilePath(); + expect(filePathV1).toBe('imsmanifest.xml'); + }); + }); + + describe('when common cartridge version 1.3', () => { + it('should return the file path regarding version 1.3', () => { + const filePathV3 = manifestResourceV3.getFilePath(); + expect(filePathV3).toBe('imsmanifest.xml'); + }); + }); + }); + + describe('getFileContent', () => { + describe('when common cartridge version 1.1', () => { + it('should return the file content regarding version 1.1', () => { + const fileContentV1 = manifestResourceV1.getFileContent(); + expect(fileContentV1).toContain('manifest'); + expect(fileContentV1).toContain('metadata'); + expect(fileContentV1).toContain('organizations'); + expect(fileContentV1).toContain('resources'); + }); + }); + + describe('when common cartridge version 1.3', () => { + it('should return the file content regarding version 1.3', () => { + const fileContentV3 = manifestResourceV3.getFileContent(); + expect(fileContentV3).toContain('manifest'); + expect(fileContentV3).toContain('metadata'); + expect(fileContentV3).toContain('organizations'); + expect(fileContentV3).toContain('resources'); + }); + }); + }); + + describe('getManifestXmlObject', () => { + describe('when common cartridge version 1.1', () => { + it('should return the manifest XML object regarding version 1.1', () => { + const transformedV1 = manifestResourceV1.getManifestXmlObject(); + + expect(transformedV1).toContain('manifest'); + + expect(transformedV1).toStrictEqual({ + manifest: { + $: { + identifier: 'manifest-v1', + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', + 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', + 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd ' + + 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ', }, + metadata: {}, + organizations: {}, + resources: {}, }, - }; - }, - }, - organizations: [], - resources: [], - }; + }); + }); + }); + + describe('when common cartridge version 1.3', () => { + it('should return the manifest XML object regarding version 1.3', () => { + const transformedV3 = manifestResourceV3.getManifestXmlObject(); + }); + }); + }); }); From 15933b516d08d6d673e1217f131f3d06d6cae20f Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 4 Dec 2023 15:42:25 +0100 Subject: [PATCH 049/177] EW-539 Working on revieiw comments --- .../common-cartridge-metadata-element.spec.ts | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts index c1242518055..45f2932d77b 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts @@ -5,27 +5,16 @@ import { } from './common-cartridge-metadata-element'; describe('CommonCartridgeMetadataElement', () => { - let sut: CommonCartridgeMetadataElement; - - // move testfixtures into the blocks they are used in - const propsVersion1: CommonCartridgeMetadataElementProps = { - version: CommonCartridgeVersion.V_1_1_0, - title: 'Metadata Element Version 1.1', - creationDate: new Date(), - copyrightOwners: ['copyrightOwner1Version1', 'copyrightOwner2Version1'], - }; - const propsVersion3: CommonCartridgeMetadataElementProps = { - version: CommonCartridgeVersion.V_1_3_0, - title: 'Metadata Element Version 1.3', - creationDate: new Date(), - copyrightOwners: ['copyrightOwner1Version3', 'copyrightOwner2Version3'], - }; - describe('getManifestXmlObject', () => { describe('when using common cartridge version 1.1', () => { - beforeAll(() => { - sut = new CommonCartridgeMetadataElement(propsVersion1); - }); + const propsVersion1: CommonCartridgeMetadataElementProps = { + version: CommonCartridgeVersion.V_1_1_0, + title: 'Metadata Element Version 1.1', + creationDate: new Date(), + copyrightOwners: ['copyrightOwner1Version1', 'copyrightOwner2Version1'], + }; + + const sut = new CommonCartridgeMetadataElement(propsVersion1); it('should return correct xml object', () => { const xmlObject = sut.getManifestXmlObject(); @@ -55,9 +44,14 @@ describe('CommonCartridgeMetadataElement', () => { }); describe('when using common cartridge version 1.3', () => { - beforeAll(() => { - sut = new CommonCartridgeMetadataElement(propsVersion3); - }); + const propsVersion3: CommonCartridgeMetadataElementProps = { + version: CommonCartridgeVersion.V_1_3_0, + title: 'Metadata Element Version 1.3', + creationDate: new Date(), + copyrightOwners: ['copyrightOwner1Version3', 'copyrightOwner2Version3'], + }; + + const sut = new CommonCartridgeMetadataElement(propsVersion3); it('should return correct xml object', () => { const xmlObject = sut.getManifestXmlObject(); From 336e0094ebc4b40aa8dfd804c60bdebd9f2c49b5 Mon Sep 17 00:00:00 2001 From: psachmann Date: Tue, 5 Dec 2023 08:29:49 +0100 Subject: [PATCH 050/177] EW-539 refactoring common cartridge mapper --- .../src/modules/learnroom/learnroom.module.ts | 2 + .../mapper/common-cartridge.mapper.spec.ts | 207 ++++++++++++------ .../mapper/common-cartridge.mapper.ts | 28 ++- .../common-cartridge-export.service.ts | 24 +- .../learnroom/service/learnroom.config.ts | 4 + 5 files changed, 180 insertions(+), 85 deletions(-) create mode 100644 apps/server/src/modules/learnroom/service/learnroom.config.ts diff --git a/apps/server/src/modules/learnroom/learnroom.module.ts b/apps/server/src/modules/learnroom/learnroom.module.ts index 02071369766..b9cf36bf129 100644 --- a/apps/server/src/modules/learnroom/learnroom.module.ts +++ b/apps/server/src/modules/learnroom/learnroom.module.ts @@ -5,6 +5,7 @@ import { TaskModule } from '@modules/task'; import { Module } from '@nestjs/common'; import { BoardRepo, CourseRepo, DashboardModelMapper, DashboardRepo, UserRepo } from '@shared/repo'; import { LoggerModule } from '@src/core/logger'; +import { CommonCartridgeMapper } from './mapper/common-cartridge.mapper'; import { BoardCopyService, ColumnBoardTargetService, @@ -31,6 +32,7 @@ import { CourseService, CommonCartridgeExportService, ColumnBoardTargetService, + CommonCartridgeMapper, ], exports: [CourseCopyService, CourseService, RoomsService, CommonCartridgeExportService], }) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index 735348149b1..a80bcfea2ee 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -1,4 +1,7 @@ +import { DeepMocked, createMock } from '@golevelup/ts-jest'; import { MikroORM } from '@mikro-orm/core'; +import { ConfigService } from '@nestjs/config'; +import { Test, TestingModule } from '@nestjs/testing'; import { ComponentProperties, ComponentType } from '@shared/domain'; import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing'; import { @@ -8,25 +11,52 @@ import { CommonCartridgeResourceType, OmitVersion, } from '../common-cartridge'; +import { LearnroomConfig } from '../service/learnroom.config'; import { CommonCartridgeMapper } from './common-cartridge.mapper'; describe('CommonCartridgeMapper', () => { + let module: TestingModule; + let sut: CommonCartridgeMapper; let orm: MikroORM; + let configServiceMock: DeepMocked>; beforeAll(async () => { + module = await Test.createTestingModule({ + providers: [ + CommonCartridgeMapper, + { + provide: ConfigService, + useValue: createMock>(), + }, + ], + }).compile(); orm = await setupEntities(); + sut = module.get(CommonCartridgeMapper); + configServiceMock = module.get(ConfigService); }); afterAll(async () => { + await module.close(); await orm.close(); }); + beforeEach(() => { + jest.clearAllMocks(); + }); + describe('mapCourseToMetadata', () => { describe('when mapping course to metadata', () => { - const course = courseFactory.buildWithId(); + const setup = () => { + const course = courseFactory.buildWithId(); + + configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + + return { course }; + }; it('should map to metadata', () => { - const metadataProps = CommonCartridgeMapper.mapCourseToMetadata(course); + const { course } = setup(); + const metadataProps = sut.mapCourseToMetadata(course); expect(metadataProps).toStrictEqual>({ title: course.name, @@ -41,10 +71,17 @@ describe('CommonCartridgeMapper', () => { describe('mapLessonToOrganization', () => { describe('when mapping lesson to organization', () => { - const lesson = lessonFactory.buildWithId(); + const setup = () => { + const lesson = lessonFactory.buildWithId(); + + configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + + return { lesson }; + }; it('should map to organization', () => { - const organizationProps = CommonCartridgeMapper.mapLessonToOrganization(lesson); + const { lesson } = setup(); + const organizationProps = sut.mapLessonToOrganization(lesson); expect(organizationProps).toStrictEqual>({ identifier: lesson.id, @@ -56,21 +93,27 @@ describe('CommonCartridgeMapper', () => { describe('mapContentToOrganization', () => { describe('when mapping content to organization', () => { - const componentProps: ComponentProperties = { - _id: 'id', - title: 'title', - hidden: false, - component: ComponentType.TEXT, - content: { - text: 'text', - }, + const setup = () => { + const componentProps: ComponentProperties = { + title: 'title', + hidden: false, + component: ComponentType.TEXT, + content: { + text: 'text', + }, + }; + + configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + + return { componentProps }; }; it('should map to organization', () => { - const organizationProps = CommonCartridgeMapper.mapContentToOrganization(componentProps); + const { componentProps } = setup(); + const organizationProps = sut.mapContentToOrganization(componentProps); expect(organizationProps).toStrictEqual>({ - identifier: componentProps._id as string, + identifier: expect.any(String), title: componentProps.title, }); }); @@ -79,10 +122,17 @@ describe('CommonCartridgeMapper', () => { describe('mapTaskToResource', () => { describe('when mapping task', () => { - const task = taskFactory.buildWithId(); + const setup = () => { + const task = taskFactory.buildWithId(); + + configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + + return { task }; + }; it('should map to web content', () => { - const resourceProps = CommonCartridgeMapper.mapTaskToResource(task); + const { task } = setup(); + const resourceProps = sut.mapTaskToResource(task); expect(resourceProps).toStrictEqual({ type: CommonCartridgeResourceType.WEB_CONTENT, @@ -96,22 +146,28 @@ describe('CommonCartridgeMapper', () => { describe('mapContentToResources', () => { describe('when mapping text content', () => { - const componentProps: ComponentProperties = { - _id: 'id', - title: 'title', - hidden: false, - component: ComponentType.TEXT, - content: { - text: 'text', - }, + const setup = () => { + const componentProps: ComponentProperties = { + title: 'title', + hidden: false, + component: ComponentType.TEXT, + content: { + text: 'text', + }, + }; + + configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + + return { componentProps }; }; it('should map to web content', () => { - const resourceProps = CommonCartridgeMapper.mapContentToResources(componentProps); + const { componentProps } = setup(); + const resourceProps = sut.mapContentToResources(componentProps); expect(resourceProps).toStrictEqual({ type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: componentProps._id as string, + identifier: expect.any(String), title: componentProps.title, html: `

${componentProps.title}

${componentProps?.content.text}

`, }); @@ -119,47 +175,61 @@ describe('CommonCartridgeMapper', () => { }); describe('when mapping geogebra content', () => { - const componentProps: ComponentProperties = { - _id: 'id', - title: 'title', - hidden: false, - component: ComponentType.GEOGEBRA, - content: { - materialId: 'material-id', - }, + const setup = () => { + const componentProps: ComponentProperties = { + title: 'title', + hidden: false, + component: ComponentType.GEOGEBRA, + content: { + materialId: 'material-id', + }, + }; + + configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + + return { componentProps }; }; it('should map to web link', () => { - const resourceProps = CommonCartridgeMapper.mapContentToResources(componentProps); + const { componentProps } = setup(); + const resourceProps = sut.mapContentToResources(componentProps); expect(resourceProps).toStrictEqual({ type: CommonCartridgeResourceType.WEB_LINK, - identifier: componentProps._id as string, title: componentProps.title, - url: `https://www.geogebra.org/m/${componentProps.content.materialId}`, + identifier: expect.any(String), + url: `${configServiceMock.getOrThrow('FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED')}/m/${ + componentProps.content.materialId + }`, }); }); }); describe('when mapping etherpad content', () => { - const componentProps: ComponentProperties = { - _id: 'id', - title: 'title', - hidden: false, - component: ComponentType.ETHERPAD, - content: { - description: 'description', + const setup = () => { + const componentProps: ComponentProperties = { title: 'title', - url: 'url', - }, + hidden: false, + component: ComponentType.ETHERPAD, + content: { + description: 'description', + title: 'title', + url: 'url', + }, + }; + + configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + + return { componentProps }; }; it('should map to web link', () => { - const resourceProps = CommonCartridgeMapper.mapContentToResources(componentProps); + const { componentProps } = setup(); + const resourceProps = sut.mapContentToResources(componentProps); expect(resourceProps).toStrictEqual({ type: CommonCartridgeResourceType.WEB_LINK, - identifier: componentProps._id as string, + identifier: expect.any(String), title: `${componentProps.content.title} - ${componentProps.content.description}`, url: componentProps.content.url, }); @@ -167,30 +237,37 @@ describe('CommonCartridgeMapper', () => { }); describe('when mapping learning store content to resources', () => { - const componentProps: ComponentProperties = { - _id: 'id', - title: 'title', - hidden: false, - component: ComponentType.LERNSTORE, - content: { - resources: [ - { - client: 'client', - description: 'description', - title: 'title', - url: 'url', - }, - ], - }, + const setup = () => { + const componentProps: ComponentProperties = { + _id: 'id', + title: 'title', + hidden: false, + component: ComponentType.LERNSTORE, + content: { + resources: [ + { + client: 'client', + description: 'description', + title: 'title', + url: 'url', + }, + ], + }, + }; + + configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + + return { componentProps }; }; it('should map to web link', () => { - const resourceProps = CommonCartridgeMapper.mapContentToResources(componentProps); + const { componentProps } = setup(); + const resourceProps = sut.mapContentToResources(componentProps); expect(resourceProps).toStrictEqual([ { type: CommonCartridgeResourceType.WEB_LINK, - identifier: componentProps._id as string, + identifier: expect.any(String), title: componentProps.content?.resources[0].description as string, url: componentProps.content?.resources[0].url as string, }, diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index dd2d4f139ee..30c891f1613 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -1,3 +1,5 @@ +import { Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain'; import { ObjectId } from 'bson'; import { @@ -7,9 +9,13 @@ import { CommonCartridgeResourceType, OmitVersion, } from '../common-cartridge'; +import { LearnroomConfig } from '../service/learnroom.config'; +@Injectable() export class CommonCartridgeMapper { - static mapCourseToMetadata(course: Course): OmitVersion { + public constructor(private readonly configService: ConfigService) {} + + public mapCourseToMetadata(course: Course): OmitVersion { return { title: course.name, copyrightOwners: course.teachers.toArray().map((teacher) => `${teacher.firstName} ${teacher.lastName}`), @@ -17,14 +23,14 @@ export class CommonCartridgeMapper { }; } - static mapLessonToOrganization(lesson: LessonEntity): OmitVersion { + public mapLessonToOrganization(lesson: LessonEntity): OmitVersion { return { identifier: lesson.id, title: lesson.name, }; } - static mapContentToOrganization( + public mapContentToOrganization( content: ComponentProperties ): OmitVersion { return { @@ -33,7 +39,14 @@ export class CommonCartridgeMapper { }; } - static mapTaskToResource(task: Task): CommonCartridgeResourceProps { + public mapTaskToOrganization(task: Task): OmitVersion { + return { + identifier: task.id, + title: task.name, + }; + } + + public mapTaskToResource(task: Task): CommonCartridgeResourceProps { return { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: task.id, @@ -42,7 +55,7 @@ export class CommonCartridgeMapper { }; } - static mapContentToResources( + public mapContentToResources( content: ComponentProperties ): CommonCartridgeResourceProps | CommonCartridgeResourceProps[] { switch (content.component) { @@ -58,8 +71,9 @@ export class CommonCartridgeMapper { type: CommonCartridgeResourceType.WEB_LINK, identifier: new ObjectId(content._id).toHexString(), title: content.title, - // TODO: put into environment, talk to capcakes if geogebra has been moved to tools, maybe there is a url in the data by now - url: `https://www.geogebra.org/m/${content.content.materialId}`, // FIXME: hardcoded hostname + url: `${this.configService.getOrThrow( + 'FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED' + )}/m/${content.content.materialId}`, }; case ComponentType.ETHERPAD: return { diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index d318971066a..6fb937c7108 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -2,7 +2,6 @@ import { LessonService } from '@modules/lesson'; import { TaskService } from '@modules/task'; import { Injectable } from '@nestjs/common'; import { ComponentProperties, EntityId } from '@shared/domain'; -import { ObjectId } from 'bson'; import { CommonCartridgeFileBuilder, CommonCartridgeOrganizationBuilder, @@ -16,7 +15,8 @@ export class CommonCartridgeExportService { constructor( private readonly courseService: CourseService, private readonly lessonService: LessonService, - private readonly taskService: TaskService + private readonly taskService: TaskService, + private readonly commonCartridgeMapper: CommonCartridgeMapper ) {} async exportCourse(courseId: EntityId, userId: EntityId, version: CommonCartridgeVersion): Promise { @@ -26,7 +26,7 @@ export class CommonCartridgeExportService { version, }); - builder.addMetadata(CommonCartridgeMapper.mapCourseToMetadata(course)); + builder.addMetadata(this.commonCartridgeMapper.mapCourseToMetadata(course)); await this.addLessons(builder, courseId); await this.addTasks(builder, courseId, userId); @@ -38,7 +38,9 @@ export class CommonCartridgeExportService { const [lessons] = await this.lessonService.findByCourseIds([courseId]); lessons.forEach((lesson) => { - const organizationBuilder = builder.addOrganization(CommonCartridgeMapper.mapLessonToOrganization(lesson)); + const organizationBuilder = builder.addOrganization( + this.commonCartridgeMapper.mapLessonToOrganization(lesson) + ); lesson.contents.forEach((content) => { this.addComponent(organizationBuilder, content); @@ -47,16 +49,12 @@ export class CommonCartridgeExportService { } private async addTasks(builder: CommonCartridgeFileBuilder, courseId: EntityId, userId: EntityId): Promise { - // TODO: figure out with UX/PM if drafts should be exported. explicitly set the option const [tasks] = await this.taskService.findBySingleParent(userId, courseId); - // TODO: each task can be their own organisation - const organizationBuilder = builder.addOrganization({ - identifier: new ObjectId().toHexString(), - title: '', // FIXME: add title - }); tasks.forEach((task) => { - organizationBuilder.addResource(CommonCartridgeMapper.mapTaskToResource(task)); + const organization = builder.addOrganization(this.commonCartridgeMapper.mapTaskToOrganization(task)); + + organization.addResource(this.commonCartridgeMapper.mapTaskToResource(task)); }); } @@ -64,7 +62,7 @@ export class CommonCartridgeExportService { organizationBuilder: CommonCartridgeOrganizationBuilder, component: ComponentProperties ): void { - const resources = CommonCartridgeMapper.mapContentToResources(component); + const resources = this.commonCartridgeMapper.mapContentToResources(component); if (!Array.isArray(resources)) { organizationBuilder.addResource(resources); @@ -72,7 +70,7 @@ export class CommonCartridgeExportService { if (Array.isArray(resources)) { const subOrganizationBuilder = organizationBuilder.addSubOrganization( - CommonCartridgeMapper.mapContentToOrganization(component) + this.commonCartridgeMapper.mapContentToOrganization(component) ); resources.forEach((resource) => { diff --git a/apps/server/src/modules/learnroom/service/learnroom.config.ts b/apps/server/src/modules/learnroom/service/learnroom.config.ts new file mode 100644 index 00000000000..13caa8d2fce --- /dev/null +++ b/apps/server/src/modules/learnroom/service/learnroom.config.ts @@ -0,0 +1,4 @@ +export interface LearnroomConfig { + FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED: boolean; + GEOGEBRA_BASE_URL: string; +} From bff93d0492f772ab53b9738dbea8bb57063390f9 Mon Sep 17 00:00:00 2001 From: psachmann Date: Tue, 5 Dec 2023 09:07:42 +0100 Subject: [PATCH 051/177] EW-539 refactoring mapper --- .../learnroom/common-cartridge/common-cartridge.config.ts | 4 ---- .../server/src/modules/learnroom/common-cartridge/index.ts | 1 - apps/server/src/modules/learnroom/index.ts | 1 + .../modules/learnroom/{service => }/learnroom.config.ts | 0 .../learnroom/mapper/common-cartridge.mapper.spec.ts | 2 +- .../modules/learnroom/mapper/common-cartridge.mapper.ts | 2 +- .../learnroom/service/common-cartridge-export.service.ts | 4 ++-- apps/server/src/modules/server/server.config.ts | 5 +++-- config/default.schema.json | 7 +++++++ 9 files changed, 15 insertions(+), 11 deletions(-) delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts rename apps/server/src/modules/learnroom/{service => }/learnroom.config.ts (100%) diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts deleted file mode 100644 index 26a856fff82..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.config.ts +++ /dev/null @@ -1,4 +0,0 @@ -// TODO: move into learnroom config, since its controlling a course route -export interface CommonCartridgeConfig { - FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED: boolean; -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/index.ts b/apps/server/src/modules/learnroom/common-cartridge/index.ts index f64e53c3c24..237fcaa46e3 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/index.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/index.ts @@ -1,6 +1,5 @@ export * from './builders/common-cartridge-file-builder'; export * from './builders/common-cartridge-organization-builder'; -export * from './common-cartridge.config'; export { CommonCartridgeResourceType, CommonCartridgeVersion } from './common-cartridge.enums'; export { CommonCartridgeMetadataElementProps } from './elements/common-cartridge-metadata-element'; export { CommonCartridgeResourceProps } from './resources/common-cartridge-resource-factory'; diff --git a/apps/server/src/modules/learnroom/index.ts b/apps/server/src/modules/learnroom/index.ts index 9fe9c100886..f5eaaac92cd 100644 --- a/apps/server/src/modules/learnroom/index.ts +++ b/apps/server/src/modules/learnroom/index.ts @@ -1,2 +1,3 @@ +export * from './learnroom.config'; export * from './learnroom.module'; export { CommonCartridgeExportService, CourseCopyService, CourseService, RoomsService } from './service'; diff --git a/apps/server/src/modules/learnroom/service/learnroom.config.ts b/apps/server/src/modules/learnroom/learnroom.config.ts similarity index 100% rename from apps/server/src/modules/learnroom/service/learnroom.config.ts rename to apps/server/src/modules/learnroom/learnroom.config.ts diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index a80bcfea2ee..5b5bd90e002 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -11,7 +11,7 @@ import { CommonCartridgeResourceType, OmitVersion, } from '../common-cartridge'; -import { LearnroomConfig } from '../service/learnroom.config'; +import { LearnroomConfig } from '../learnroom.config'; import { CommonCartridgeMapper } from './common-cartridge.mapper'; describe('CommonCartridgeMapper', () => { diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 30c891f1613..2f77afa8236 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -9,7 +9,7 @@ import { CommonCartridgeResourceType, OmitVersion, } from '../common-cartridge'; -import { LearnroomConfig } from '../service/learnroom.config'; +import { LearnroomConfig } from '../learnroom.config'; @Injectable() export class CommonCartridgeMapper { diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 6fb937c7108..a74ac24c206 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -12,14 +12,14 @@ import { CourseService } from './course.service'; @Injectable() export class CommonCartridgeExportService { - constructor( + public constructor( private readonly courseService: CourseService, private readonly lessonService: LessonService, private readonly taskService: TaskService, private readonly commonCartridgeMapper: CommonCartridgeMapper ) {} - async exportCourse(courseId: EntityId, userId: EntityId, version: CommonCartridgeVersion): Promise { + public async exportCourse(courseId: EntityId, userId: EntityId, version: CommonCartridgeVersion): Promise { const course = await this.courseService.findById(courseId); const builder = new CommonCartridgeFileBuilder({ identifier: courseId, diff --git a/apps/server/src/modules/server/server.config.ts b/apps/server/src/modules/server/server.config.ts index 1e61f738f76..860d58e8460 100644 --- a/apps/server/src/modules/server/server.config.ts +++ b/apps/server/src/modules/server/server.config.ts @@ -2,7 +2,7 @@ import { Configuration } from '@hpi-schul-cloud/commons'; import type { IdentityManagementConfig } from '@infra/identity-management'; import type { AccountConfig } from '@modules/account'; import type { FilesStorageClientConfig } from '@modules/files-storage-client'; -import type { CommonCartridgeConfig } from '@modules/learnroom/common-cartridge'; +import type { LearnroomConfig } from '@modules/learnroom'; import type { UserConfig } from '@modules/user'; import type { CoreModuleConfig } from '@src/core'; import { MailConfig } from '@src/infra/mail/interfaces/mail-config'; @@ -20,7 +20,7 @@ export interface ServerConfig FilesStorageClientConfig, AccountConfig, IdentityManagementConfig, - CommonCartridgeConfig, + LearnroomConfig, MailConfig { NODE_ENV: string; SC_DOMAIN: string; @@ -40,6 +40,7 @@ const config: ServerConfig = { FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED: Configuration.get( 'FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED' ) as boolean, + GEOGEBRA_BASE_URL: Configuration.get('GEOGEBRA_BASE_URL') as string, FEATURE_IDENTITY_MANAGEMENT_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_ENABLED') as boolean, FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED: Configuration.get( 'FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED' diff --git a/config/default.schema.json b/config/default.schema.json index d31f1dfa163..038f657b45c 100644 --- a/config/default.schema.json +++ b/config/default.schema.json @@ -1129,6 +1129,13 @@ "default": false, "description": "Toggle for the IMSCC course download feature." }, + "GEOGEBRA_BASE_URL": { + "type": "string", + "format": "uri", + "default": "https://www.geogebra.org", + "pattern": ".*(? Date: Tue, 5 Dec 2023 09:16:39 +0100 Subject: [PATCH 052/177] EW-539 improving tests --- .../mapper/common-cartridge.mapper.spec.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index 5b5bd90e002..77747505f31 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -3,7 +3,7 @@ import { MikroORM } from '@mikro-orm/core'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { ComponentProperties, ComponentType } from '@shared/domain'; -import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing'; +import { courseFactory, lessonFactory, setupEntities, taskFactory, userFactory } from '@shared/testing'; import { CommonCartridgeMetadataElementProps, CommonCartridgeOrganizationBuilderOptions, @@ -47,7 +47,9 @@ describe('CommonCartridgeMapper', () => { describe('mapCourseToMetadata', () => { describe('when mapping course to metadata', () => { const setup = () => { - const course = courseFactory.buildWithId(); + const course = courseFactory.buildWithId({ + teachers: userFactory.buildListWithId(2), + }); configServiceMock.getOrThrow.mockReturnValue('https://example.com'); @@ -144,6 +146,28 @@ describe('CommonCartridgeMapper', () => { }); }); + describe('mapTaskToOrganization', () => { + describe('when mapping task', () => { + const setup = () => { + const task = taskFactory.buildWithId(); + + configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + + return { task }; + }; + + it('should map to organization', () => { + const { task } = setup(); + const organizationProps = sut.mapTaskToOrganization(task); + + expect(organizationProps).toStrictEqual>({ + identifier: task.id, + title: task.name, + }); + }); + }); + }); + describe('mapContentToResources', () => { describe('when mapping text content', () => { const setup = () => { From cb5e873ea4d155d45044c8fe5c9c393a29ec2e6b Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 6 Dec 2023 10:48:23 +0100 Subject: [PATCH 053/177] EW-539 Start with cc resource props test factory --- ...n-cartridge-resource-props-test-factory.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-props-test-factory.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-props-test-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-props-test-factory.ts new file mode 100644 index 00000000000..cf8b03abdfb --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-props-test-factory.ts @@ -0,0 +1,40 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResourceProps } from './common-cartridge-resource-factory'; + +export class CommonCartridgeResourcePropsFactory { + static create(): CommonCartridgeResourceProps { + switch (props.type) { + case CommonCartridgeResourceType.LTI: + return { + type: CommonCartridgeResourceType.LTI, + version: CommonCartridgeVersion.V_1_1_0, + identifier: 'lti-resource-props-identifier', + folder: 'lti-resource-props-folder', + title: 'lti-resource-props-title', + description: 'lti-resource-props-description', + url: 'lti-resource-props-url', + }; + case CommonCartridgeResourceType.WEB_CONTENT: + return { + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_1_0, + identifier: 'web-content-resource-props-identifier', + folder: 'web-content-resource-props-folder', + title: 'web-content-resource-resource-title', + html: '

web-content-resource-props-html

', + }; + case CommonCartridgeResourceType.WEB_LINK: + return { + type: CommonCartridgeResourceType.WEB_LINK, + version: CommonCartridgeVersion.V_1_1_0, + identifier: 'web-link-resource-props-identifier', + folder: 'web-link-resource-props-folder', + title: 'web-link-resource-props-title', + url: 'web-link-resource-props-url', + }; + default: + throw new InternalServerErrorException(`Unknown Common Cartridge resource props`); + } + } +} From 71eb836ac8cba861b78626410837106d698cbb3d Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 6 Dec 2023 11:04:37 +0100 Subject: [PATCH 054/177] EW-539 working on everything --- .../common-cartridge-organization-builder.ts | 2 +- ...ommon-cartridge-element-version-factory.ts | 17 ++++++++ .../common-cartridge-metadata-element.ts | 12 ++++-- .../common-cartridge-organization-element.ts | 14 ++++-- ...cartridge-organizations-wrapper-element.ts | 20 +++++++-- ...mon-cartridge-resources-wrapper-element.ts | 20 +++++++-- .../common-cartridge-element-factory.ts | 13 ++++++ .../common-cartridge-metadata-element.ts | 43 +++++++++++++++++++ .../common-cartridge-element-factory.ts | 13 ++++++ .../common-cartridge-metadata-element.ts | 43 +++++++++++++++++++ .../common-cartridge-element.interface.ts | 25 ++++++++++- .../common-cartridge-resource.interface.ts | 8 ++-- .../learnroom/common-cartridge/utils.ts | 6 ++- 13 files changed, 214 insertions(+), 22 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts index e9cea3cd2fa..5dd1d08f963 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts @@ -20,7 +20,7 @@ export class CommonCartridgeOrganizationBuilder { private readonly children = new Array(); - constructor( + public constructor( protected readonly options: CommonCartridgeOrganizationBuilderOptions, private readonly addResourceToFileBuilder: (resource: CommonCartridgeResource) => void ) {} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts new file mode 100644 index 00000000000..b673047fa13 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts @@ -0,0 +1,17 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeElementFactory as CommonCartridgeElementFactoryV110 } from './v1.1.0/common-cartridge-element-factory'; +import { CommonCartridgeElementFactory as CommonCartridgeElementFactoryV130 } from './v1.3.0/common-cartridge-element-factory'; + +export class CommonCartridgeElementVersionFactory { + public static createFactory(version: CommonCartridgeVersion) { + switch (version) { + case CommonCartridgeVersion.V_1_1_0: + return CommonCartridgeElementFactoryV110.getInstance(); + case CommonCartridgeVersion.V_1_3_0: + return CommonCartridgeElementFactoryV130.getInstance(); + default: + throw new InternalServerErrorException(`Common Cartridge version ${version} is not supported`); + } + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts index 63a826075f9..ecefa557407 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts @@ -8,10 +8,16 @@ export type CommonCartridgeMetadataElementProps = { copyrightOwners: string[]; }; -export class CommonCartridgeMetadataElement implements CommonCartridgeElement { - constructor(private readonly props: CommonCartridgeMetadataElementProps) {} +export class CommonCartridgeMetadataElement extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeMetadataElementProps) { + super(props); + } + + public override getSupportedVersions(): CommonCartridgeVersion[] { + return [CommonCartridgeVersion.V_1_1_0, CommonCartridgeVersion.V_1_2_0, CommonCartridgeVersion.V_1_3_0]; + } - public getManifestXmlObject(): Record { + public override getManifestXmlObject(): Record { return { schema: 'IMS Common Cartridge', schemaversion: this.props.version, diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts index 96926074a01..bcae0f10c7c 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts @@ -1,15 +1,23 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; type CommonCartridgeOrganizationElementProps = { + version: CommonCartridgeVersion; identifier: string; title: string; items: CommonCartridgeElement[]; }; -export class CommonCartridgeOrganizationElement implements CommonCartridgeElement { - constructor(private readonly props: CommonCartridgeOrganizationElementProps) {} +export class CommonCartridgeOrganizationElement extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeOrganizationElementProps) { + super(props); + } + + public override getSupportedVersions(): CommonCartridgeVersion[] { + return [CommonCartridgeVersion.V_1_1_0, CommonCartridgeVersion.V_1_3_0]; + } - public getManifestXmlObject(): Record { + public override getManifestXmlObject(): Record { return { $: { identifier: this.props.identifier, diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts index ab56623261d..46ebc3a4890 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts @@ -1,9 +1,21 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; -export class CommonCartridgeOrganizationsWrapperElement implements CommonCartridgeElement { - constructor(private readonly items: CommonCartridgeElement[]) {} +export type CommonCartridgeOrganizationsWrapperElementProps = { + version: CommonCartridgeVersion; + items: CommonCartridgeElement[]; +}; - public getManifestXmlObject(): Record { +export class CommonCartridgeOrganizationsWrapperElement extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementProps) { + super(props); + } + + public override getSupportedVersions(): CommonCartridgeVersion[] { + return [CommonCartridgeVersion.V_1_1_0, CommonCartridgeVersion.V_1_3_0]; + } + + public override getManifestXmlObject(): Record { return { organization: [ { @@ -16,7 +28,7 @@ export class CommonCartridgeOrganizationsWrapperElement implements CommonCartrid $: { identifier: 'LearningModules', }, - item: this.items.map((items) => items.getManifestXmlObject()), + item: this.props.items.map((items) => items.getManifestXmlObject()), }, ], }, diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts index c0b47b3f628..4352c008dc2 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts @@ -1,13 +1,25 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; -export class CommonCartridgeResourcesWrapperElement implements CommonCartridgeElement { - constructor(private readonly items: CommonCartridgeElement[]) {} +export type CommonCartridgeResourcesWrapperElementProps = { + version: CommonCartridgeVersion; + items: CommonCartridgeElement[]; +}; - public getManifestXmlObject(): Record { +export class CommonCartridgeResourcesWrapperElement extends CommonCartridgeElement { + constructor(private readonly props: CommonCartridgeResourcesWrapperElementProps) { + super(props); + } + + public override getSupportedVersions(): CommonCartridgeVersion[] { + return [CommonCartridgeVersion.V_1_1_0, CommonCartridgeVersion.V_1_3_0]; + } + + public override getManifestXmlObject(): Record { return { resources: [ { - resource: this.items.map((items) => items.getManifestXmlObject()), + resource: this.props.items.map((items) => items.getManifestXmlObject()), }, ], }; diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts new file mode 100644 index 00000000000..2f7c52f5ac4 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts @@ -0,0 +1,13 @@ +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; + +export class CommonCartridgeElementFactory { + private static readonly instance = new CommonCartridgeElementFactory(); + + public static getInstance(): CommonCartridgeElementFactory { + return this.instance; + } + + public createElement(_props: unknown): CommonCartridgeElement { + throw new Error('Method not implemented.'); + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts new file mode 100644 index 00000000000..8d11678379d --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts @@ -0,0 +1,43 @@ +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; + +export type CommonCartridgeMetadataElementProps = { + version: CommonCartridgeVersion; + title: string; + creationDate: Date; + copyrightOwners: string[]; +}; + +export class CommonCartridgeMetadataElement extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeMetadataElementProps) { + super(props); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_1_0; + } + + public override getManifestXmlObject(): Record { + return { + schema: '1EdTech Common Cartridge', + schemaversion: '1.1.0', + 'mnf:lom': { + 'mnf:general': { + 'mnf:title': { + 'mnf:string': this.props.title, + }, + }, + 'mnf:rights': { + 'mnf:copyrightAndOtherRestrictions': { + 'mnf:value': 'yes', + }, + 'mnf:description': { + 'mnf:string': `${this.props.creationDate.getFullYear()} ${this.props.copyrightOwners.join( + ', ' + )}`, + }, + }, + }, + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts new file mode 100644 index 00000000000..2f7c52f5ac4 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts @@ -0,0 +1,13 @@ +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; + +export class CommonCartridgeElementFactory { + private static readonly instance = new CommonCartridgeElementFactory(); + + public static getInstance(): CommonCartridgeElementFactory { + return this.instance; + } + + public createElement(_props: unknown): CommonCartridgeElement { + throw new Error('Method not implemented.'); + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts new file mode 100644 index 00000000000..05af73fb07e --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts @@ -0,0 +1,43 @@ +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; + +export type CommonCartridgeMetadataElementProps = { + version: CommonCartridgeVersion; + title: string; + creationDate: Date; + copyrightOwners: string[]; +}; + +export class CommonCartridgeMetadataElement extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeMetadataElementProps) { + super(props); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_3_0; + } + + public override getManifestXmlObject(): Record { + return { + schema: '1EdTech Common Cartridge', + schemaversion: '1.3.0', + 'mnf:lom': { + 'mnf:general': { + 'mnf:title': { + 'mnf:string': this.props.title, + }, + }, + 'mnf:rights': { + 'mnf:copyrightAndOtherRestrictions': { + 'mnf:value': 'yes', + }, + 'mnf:description': { + 'mnf:string': `${this.props.creationDate.getFullYear()} ${this.props.copyrightOwners.join( + ', ' + )}`, + }, + }, + }, + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element.interface.ts index fc8ddb8ec3d..5961551aaac 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element.interface.ts @@ -1,10 +1,31 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { CommonCartridgeVersion } from '../common-cartridge.enums'; + /** * Every element which should be listed in the Common Cartridge manifest must implement this interface. */ -export interface CommonCartridgeElement { +export abstract class CommonCartridgeElement { + protected constructor(args: { version: CommonCartridgeVersion }) { + this.checkVersion(args.version); + } + + /** + * Every element must know which versions it supports. + * @returns The supported versions for this element. + */ + abstract getSupportedVersion(): CommonCartridgeVersion; + /** * This method is used to build the imsmanifest.xml file. * @returns The XML object representation for the imsmanifest.xml file. */ - getManifestXmlObject(): Record; + abstract getManifestXmlObject(): Record; + + private checkVersion(target: CommonCartridgeVersion): void | never { + if (this.getSupportedVersion() === target) { + return; + } + + throw new InternalServerErrorException(`Common Cartridge version ${target} is not supported`); + } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource.interface.ts index 459d3e311be..dfa3adbc8b4 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource.interface.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource.interface.ts @@ -3,22 +3,22 @@ import { CommonCartridgeElement } from './common-cartridge-element.interface'; /** * Every resource which should be added to the Common Cartridge archive must implement this interface. */ -export interface CommonCartridgeResource extends CommonCartridgeElement { +export abstract class CommonCartridgeResource extends CommonCartridgeElement { /** * In later Common Cartridge versions, resources can be inlined in the imsmanifest.xml file. * @returns true if the resource can be inlined, otherwise false. */ - canInline(): boolean; + abstract canInline(): boolean; /** * This method is used to determine the path of the resource in the Common Cartridge archive. * @returns The path of the resource in the Common Cartridge archive. */ - getFilePath(): string; + abstract getFilePath(): string; /** * This method is used to get the content of the resource. * @returns The content of the resource. */ - getFileContent(): string; + abstract getFileContent(): string; } diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.ts index 59d11d46841..00392a02653 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/utils.ts @@ -16,7 +16,11 @@ export function createVersionNotSupportedError(version: CommonCartridgeVersion): } export function checkCommonCartridgeVersion(version: CommonCartridgeVersion): void | never { - const supportedVersions = [CommonCartridgeVersion.V_1_1_0, CommonCartridgeVersion.V_1_3_0]; + const supportedVersions = [ + CommonCartridgeVersion.V_1_1_0, + CommonCartridgeVersion.V_1_2_0, + CommonCartridgeVersion.V_1_3_0, + ]; if (supportedVersions.includes(version)) { return; From 7e6fd67567b023ed23e5f2618ae361029f141167 Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 6 Dec 2023 13:55:46 +0100 Subject: [PATCH 055/177] EW-539 working on resources --- ...on-cartridge-resource-factory.interface.ts | 8 ++ .../common-cartridge-lti-resource.ts | 3 +- ...mmon-cartridge-resource-version-factory.ts | 17 ++++ .../v1.1.0/common-cartridge-lti-resource.ts | 79 +++++++++++++++++++ .../common-cartridge-resource-factory.ts | 17 ++++ .../common-cartridge-web-content-resource.ts | 53 +++++++++++++ .../common-cartridge-web-link-resource.ts | 65 +++++++++++++++ .../v1.3.0/common-cartridge-lti-resource.ts | 79 +++++++++++++++++++ .../common-cartridge-resource-factory.ts | 39 +++++++++ .../common-cartridge-web-content-resource.ts | 53 +++++++++++++ .../common-cartridge-web-link-resource.ts | 65 +++++++++++++++ .../learnroom/common-cartridge/utils.ts | 9 ++- 12 files changed, 483 insertions(+), 4 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource-factory.interface.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource-factory.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource-factory.interface.ts new file mode 100644 index 00000000000..9d3b670d8d8 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource-factory.interface.ts @@ -0,0 +1,8 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResource } from './common-cartridge-resource.interface'; + +export type CommonCartridgeResourceProps = { version: CommonCartridgeVersion }; + +export abstract class CommonCartridgeResourceFactory { + abstract createResource(props: CommonCartridgeResourceProps): CommonCartridgeResource; +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts index f7c9d91d736..41808f35ec1 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts @@ -1,5 +1,4 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { buildXmlString, createVersionNotSupportedError } from '../utils'; export type CommonCartridgeLtiResourceProps = { @@ -12,7 +11,7 @@ export type CommonCartridgeLtiResourceProps = { url: string; }; -export class CommonCartridgeLtiResource implements CommonCartridgeResource { +export class CommonCartridgeLtiResource { constructor(private readonly props: CommonCartridgeLtiResourceProps) {} public canInline(): boolean { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts new file mode 100644 index 00000000000..78fb31e29d8 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts @@ -0,0 +1,17 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResourceFactory } from '../interfaces/common-cartridge-resource-factory.interface'; +import { CommonCartridgeResourceFactoryV110 } from './v1.1.0/common-cartridge-resource-factory'; +import { CommonCartridgeResourceFactoryV130 } from './v1.3.0/common-cartridge-resource-factory'; + +export class CommonCartridgeResourceVersionFactory { + public static createFactory(version: CommonCartridgeVersion): CommonCartridgeResourceFactory { + switch (version) { + case CommonCartridgeVersion.V_1_1_0: + return CommonCartridgeResourceFactoryV110.getInstance(); + case CommonCartridgeVersion.V_1_3_0: + return CommonCartridgeResourceFactoryV130.getInstance(); + default: + throw new Error(`Common Cartridge version ${version} is not supported`); + } + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.ts new file mode 100644 index 00000000000..457821df6d6 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.ts @@ -0,0 +1,79 @@ +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { buildXmlString } from '../../utils'; + +export type CommonCartridgeLtiResourceProps = { + type: CommonCartridgeResourceType.LTI; + version: CommonCartridgeVersion; + identifier: string; + folder: string; + title: string; + description?: string; + url: string; +}; + +export class CommonCartridgeLtiResource extends CommonCartridgeResource { + public constructor(private readonly props: CommonCartridgeLtiResourceProps) { + super(props); + } + + public override canInline(): boolean { + return false; + } + + public override getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.xml`; + } + + public override getFileContent(): string { + return buildXmlString({ + cartridge_basiclti_link: { + $: { + xmlns: '/xsd/imslticc_v1p0', + 'xmlns:blti': '/xsd/imsbasiclti_v1p0', + 'xmlns:lticm': '/xsd/imslticm_v1p0', + 'xmlns:lticp': '/xsd/imslticp_v1p0', + 'xsi:schemaLocation': + '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd' + + '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd' + + '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd' + + '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd"', + }, + blti: { + title: this.props.title, + description: this.props.description, + launch_url: this.props.url, + secure_launch_url: this.props.url, + cartridge_bundle: { + $: { + identifierref: 'BLTI001_Bundle', + }, + }, + cartridge_icon: { + $: { + identifierref: 'BLTI001_Icon', + }, + }, + }, + }, + }); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_1_0; + } + + public override getManifestXmlObject(): Record { + return { + $: { + identifier: this.props.identifier, + type: this.props.type, + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts new file mode 100644 index 00000000000..2a0c4dda618 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts @@ -0,0 +1,17 @@ +import { + CommonCartridgeResourceFactory, + CommonCartridgeResourceProps, +} from '../../interfaces/common-cartridge-resource-factory.interface'; +import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; + +export class CommonCartridgeResourceFactoryV110 extends CommonCartridgeResourceFactory { + public static readonly instance = new CommonCartridgeResourceFactoryV110(); + + public static getInstance(): CommonCartridgeResourceFactory { + return this.instance; + } + + public override createResource(props: CommonCartridgeResourceProps): CommonCartridgeResource { + throw new Error('Method not implemented.'); + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts new file mode 100644 index 00000000000..51f4f3cba6d --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -0,0 +1,53 @@ +import { + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; + +export type CommonCartridgeWebContentResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT; + version: CommonCartridgeVersion.V_1_1_0; + identifier: string; + folder: string; + title: string; + html: string; + intendedUse: CommonCartridgeIntendedUseType; +}; + +export class CommonCartridgeWebContentResource extends CommonCartridgeResource { + constructor(private readonly props: CommonCartridgeWebContentResourceProps) { + super(props); + } + + public override canInline(): boolean { + return false; + } + + public override getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.html`; + } + + public override getFileContent(): string { + return this.props.html; + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_1_0; + } + + public override getManifestXmlObject(): Record { + return { + $: { + identifier: this.props.identifier, + type: this.props.type, + intendeduse: this.props.intendedUse, + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts new file mode 100644 index 00000000000..60f4c063f40 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -0,0 +1,65 @@ +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { buildXmlString } from '../../utils'; + +export type CommonCartridgeWebLinkResourceProps = { + type: CommonCartridgeResourceType.WEB_LINK; + version: CommonCartridgeVersion.V_1_1_0; + identifier: string; + folder: string; + title: string; + url: string; +}; + +export class CommonCartridgeWebLinkResource extends CommonCartridgeResource { + constructor(private readonly props: CommonCartridgeWebLinkResourceProps) { + super(props); + } + + public canInline(): boolean { + return false; + } + + public getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.xml`; + } + + public getFileContent(): string { + return buildXmlString({ + webLink: { + $: { + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': + 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', + }, + title: this.props.title, + url: { + $: { + href: this.props.url, + target: '_self', + windowFeatures: 'width=100, height=100', + }, + }, + }, + }); + } + + public getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_1_0; + } + + public getManifestXmlObject(): Record { + return { + $: { + identifier: this.props.identifier, + type: this.props.type, + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.ts new file mode 100644 index 00000000000..612c0672ad5 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.ts @@ -0,0 +1,79 @@ +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { buildXmlString } from '../../utils'; + +export type CommonCartridgeLtiResourceProps = { + type: CommonCartridgeResourceType.LTI; + version: CommonCartridgeVersion; + identifier: string; + folder: string; + title: string; + description?: string; + url: string; +}; + +export class CommonCartridgeLtiResource extends CommonCartridgeResource { + public constructor(private readonly props: CommonCartridgeLtiResourceProps) { + super(props); + } + + public override canInline(): boolean { + return false; + } + + public override getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.xml`; + } + + public override getFileContent(): string { + return buildXmlString({ + cartridge_basiclti_link: { + $: { + xmlns: 'http://www.imsglobal.org/xsd/imslticc_v1p3', + 'xmlns:blti': 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0', + 'xmlns:lticm': 'http://www.imsglobal.org/xsd/imslticm_v1p0', + 'xmlns:lticp': 'http://www.imsglobal.org/xsd/imslticp_v1p0', + 'xsi:schemaLocation': + 'http://www.imsglobal.org/xsd/imslticc_v1p3 http://www.imsglobal.org/xsd/imslticc_v1p3.xsd' + + 'http://www.imsglobal.org/xsd/imslticp_v1p0 imslticp_v1p0.xsd' + + 'http://www.imsglobal.org/xsd/imslticm_v1p0 imslticm_v1p0.xsd' + + 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0 imsbasiclti_v1p0p1.xsd"', + }, + blti: { + title: this.props.title, + description: this.props.description, + launch_url: this.props.url, + secure_launch_url: this.props.url, + cartridge_bundle: { + $: { + identifierref: 'BLTI001_Bundle', + }, + }, + cartridge_icon: { + $: { + identifierref: 'BLTI001_Icon', + }, + }, + }, + }, + }); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_3_0; + } + + public override getManifestXmlObject(): Record { + return { + $: { + identifier: this.props.identifier, + type: this.props.type, + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts new file mode 100644 index 00000000000..13b721a9405 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts @@ -0,0 +1,39 @@ +import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; +import { CommonCartridgeResourceFactory } from '../../interfaces/common-cartridge-resource-factory.interface'; +import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { createResourceTypeNotSupportedError } from '../../utils'; +import { CommonCartridgeLtiResource, CommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; +import { + CommonCartridgeWebContentResource, + CommonCartridgeWebContentResourceProps, +} from './common-cartridge-web-content-resource'; +import { + CommonCartridgeWebLinkResource, + CommonCartridgeWebLinkResourceProps, +} from './common-cartridge-web-link-resource'; + +export type CommonCartridgeResourceProps = + | CommonCartridgeLtiResourceProps + | CommonCartridgeWebContentResourceProps + | CommonCartridgeWebLinkResourceProps; + +export class CommonCartridgeResourceFactoryV130 extends CommonCartridgeResourceFactory { + public static readonly instance = new CommonCartridgeResourceFactoryV130(); + + public static getInstance(): CommonCartridgeResourceFactory { + return this.instance; + } + + public override createResource(props: CommonCartridgeResourceProps): CommonCartridgeResource { + switch (props.type) { + case CommonCartridgeResourceType.LTI: + return new CommonCartridgeLtiResource(props); + case CommonCartridgeResourceType.WEB_CONTENT: + return new CommonCartridgeWebContentResource(props); + case CommonCartridgeResourceType.WEB_LINK: + return new CommonCartridgeWebLinkResource(props); + default: + throw createResourceTypeNotSupportedError(props.type); + } + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts new file mode 100644 index 00000000000..c4d4d22f3ca --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -0,0 +1,53 @@ +import { + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; + +export type CommonCartridgeWebContentResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT; + version: CommonCartridgeVersion.V_1_3_0; + identifier: string; + folder: string; + title: string; + html: string; + intendedUse: CommonCartridgeIntendedUseType; +}; + +export class CommonCartridgeWebContentResource extends CommonCartridgeResource { + public constructor(private readonly props: CommonCartridgeWebContentResourceProps) { + super(props); + } + + public override canInline(): boolean { + return false; + } + + public override getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.html`; + } + + public override getFileContent(): string { + return this.props.html; + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_3_0; + } + + public override getManifestXmlObject(): Record { + return { + $: { + identifier: this.props.identifier, + type: this.props.type, + intendeduse: this.props.intendedUse, + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts new file mode 100644 index 00000000000..79021860356 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -0,0 +1,65 @@ +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { buildXmlString } from '../../utils'; + +export type CommonCartridgeWebLinkResourceProps = { + type: CommonCartridgeResourceType.WEB_LINK; + version: CommonCartridgeVersion.V_1_3_0; + identifier: string; + folder: string; + title: string; + url: string; +}; + +export class CommonCartridgeWebLinkResource extends CommonCartridgeResource { + public constructor(private readonly props: CommonCartridgeWebLinkResourceProps) { + super(props); + } + + public override canInline(): boolean { + return false; + } + + public override getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.xml`; + } + + public override getFileContent(): string { + return buildXmlString({ + webLink: { + $: { + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': + 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd', + }, + title: this.props.title, + url: { + $: { + href: this.props.url, + target: '_self', + windowFeatures: 'width=100, height=100', + }, + }, + }, + }); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_3_0; + } + + public override getManifestXmlObject(): Record { + return { + $: { + identifier: this.props.identifier, + type: this.props.type, + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.ts index 00392a02653..b0b3ada2528 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/utils.ts @@ -1,3 +1,4 @@ +import { InternalServerErrorException } from '@nestjs/common'; import { Builder } from 'xml2js'; import { CommonCartridgeVersion } from './common-cartridge.enums'; @@ -11,8 +12,12 @@ export function buildXmlString(obj: unknown): string { return xmlBuilder.buildObject(obj); } -export function createVersionNotSupportedError(version: CommonCartridgeVersion): Error { - return new Error(`Version ${version} is not supported`); +export function createVersionNotSupportedError(version: string): Error { + return new InternalServerErrorException(`Common Cartridge version ${version} is not supported`); +} + +export function createResourceTypeNotSupportedError(type: string): Error { + return new InternalServerErrorException(`Common Cartridge resource type ${type} is not supported`); } export function checkCommonCartridgeVersion(version: CommonCartridgeVersion): void | never { From 4c2853c8ad200636d6fd1f34196cec0a93c431b6 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 6 Dec 2023 16:40:28 +0100 Subject: [PATCH 056/177] EW-539 Working on elements --- .../common-cartridge.enums.ts | 7 +++ .../common-cartridge-element-factory.ts | 45 +++++++++++++++++-- .../common-cartridge-metadata-element.ts | 3 +- .../common-cartridge-organization-element.ts | 30 +++++++++++++ ...cartridge-organizations-wrapper-element.ts | 39 ++++++++++++++++ ...mon-cartridge-resources-wrapper-element.ts | 28 ++++++++++++ .../common-cartridge-element-factory.ts | 45 +++++++++++++++++-- .../common-cartridge-metadata-element.ts | 3 +- .../common-cartridge-organization-element.ts | 30 +++++++++++++ ...cartridge-organizations-wrapper-element.ts | 39 ++++++++++++++++ ...mon-cartridge-resources-wrapper-element.ts | 28 ++++++++++++ ...mon-cartridge-element-factory.interface.ts | 8 ++++ .../learnroom/common-cartridge/utils.ts | 5 +++ 13 files changed, 300 insertions(+), 10 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element-factory.interface.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts index 96380d265ba..541368dc40f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts @@ -20,3 +20,10 @@ export enum CommonCartridgeIntendedUseType { SYLLABUS = 'syllabus', UNSPECIFIED = 'unspecified', } + +export enum CommonCartridgeElementType { + METADATA = 'metadata', + ORGANIZATION = 'organization', + RESOURCES_WRAPPER = 'resourceswrapper', + ORGANIZATIONS_WRAPPER = 'organizationswrapper', +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts index 2f7c52f5ac4..3f3fae2fc6c 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts @@ -1,13 +1,50 @@ +import { CommonCartridgeElementType } from '../../common-cartridge.enums'; +import { CommonCartridgeElementFactory } from '../../interfaces/common-cartridge-element-factory.interface'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { createElementTypeNotSupportedError } from '../../utils'; +import { + CommonCartridgeMetadataElement, + CommonCartridgeMetadataElementProps, +} from './common-cartridge-metadata-element'; +import { + CommonCartridgeOrganizationElement, + CommonCartridgeOrganizationElementProps, +} from './common-cartridge-organization-element'; +import { + CommonCartridgeOrganizationsWrapperElement, + CommonCartridgeOrganizationsWrapperElementProps, +} from './common-cartridge-organizations-wrapper-element'; +import { + CommonCartridgeResourcesWrapperElement, + CommonCartridgeResourcesWrapperElementProps, +} from './common-cartridge-resources-wrapper-element'; -export class CommonCartridgeElementFactory { - private static readonly instance = new CommonCartridgeElementFactory(); +export type CommonCartridgeElementProps = + | CommonCartridgeMetadataElementProps + | CommonCartridgeOrganizationElementProps + | CommonCartridgeOrganizationsWrapperElementProps + | CommonCartridgeResourcesWrapperElementProps; + +export class CommonCartridgeElementFactoryV110 extends CommonCartridgeElementFactory { + public static readonly instance = new CommonCartridgeElementFactoryV110(); public static getInstance(): CommonCartridgeElementFactory { return this.instance; } - public createElement(_props: unknown): CommonCartridgeElement { - throw new Error('Method not implemented.'); + public createElement(props: CommonCartridgeElementProps): CommonCartridgeElement { + switch (props.type) { + // AI next 8 lines + case CommonCartridgeElementType.METADATA: + return new CommonCartridgeMetadataElement(props); + case CommonCartridgeElementType.ORGANIZATION: + return new CommonCartridgeOrganizationElement(props); + case CommonCartridgeElementType.ORGANIZATIONS_WRAPPER: + return new CommonCartridgeOrganizationsWrapperElement(props); + case CommonCartridgeElementType.RESOURCES_WRAPPER: + return new CommonCartridgeResourcesWrapperElement(props); + default: + throw createElementTypeNotSupportedError((props as { type: string }).type); // FIXME: remove type assertion + } } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts index 8d11678379d..414d9653b8c 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts @@ -1,7 +1,8 @@ -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; export type CommonCartridgeMetadataElementProps = { + type: CommonCartridgeElementType.METADATA; version: CommonCartridgeVersion; title: string; creationDate: Date; diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts new file mode 100644 index 00000000000..cf5bf579117 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts @@ -0,0 +1,30 @@ +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; + +export type CommonCartridgeOrganizationElementProps = { + type: CommonCartridgeElementType.ORGANIZATION; + version: CommonCartridgeVersion; + identifier: string; + title: string; + items: CommonCartridgeElement[]; +}; + +export class CommonCartridgeOrganizationElement extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeOrganizationElementProps) { + super(props); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_1_0; + } + + public override getManifestXmlObject(): Record { + return { + $: { + identifier: this.props.identifier, + }, + title: this.props.title, + item: this.props.items.map((item) => item.getManifestXmlObject()), + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts new file mode 100644 index 00000000000..714918d581a --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts @@ -0,0 +1,39 @@ +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; + +export type CommonCartridgeOrganizationsWrapperElementProps = { + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; + version: CommonCartridgeVersion; + items: CommonCartridgeElement[]; +}; + +export class CommonCartridgeOrganizationsWrapperElement extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementProps) { + super(props); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_1_0; + } + + public override getManifestXmlObject(): Record { + return { + organization: [ + { + $: { + identifier: 'org-1', + structure: 'rooted-hierarchy', + }, + item: [ + { + $: { + identifier: 'LearningModules', + }, + item: this.props.items.map((items) => items.getManifestXmlObject()), + }, + ], + }, + ], + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts new file mode 100644 index 00000000000..1bbc07b4377 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts @@ -0,0 +1,28 @@ +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; + +export type CommonCartridgeResourcesWrapperElementProps = { + type: CommonCartridgeElementType.RESOURCES_WRAPPER; + version: CommonCartridgeVersion; + items: CommonCartridgeElement[]; +}; + +export class CommonCartridgeResourcesWrapperElement extends CommonCartridgeElement { + constructor(private readonly props: CommonCartridgeResourcesWrapperElementProps) { + super(props); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_1_0; + } + + public override getManifestXmlObject(): Record { + return { + resources: [ + { + resource: this.props.items.map((items) => items.getManifestXmlObject()), + }, + ], + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts index 2f7c52f5ac4..90ee7aae2ca 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts @@ -1,13 +1,50 @@ +import { CommonCartridgeElementType } from '../../common-cartridge.enums'; +import { CommonCartridgeElementFactory } from '../../interfaces/common-cartridge-element-factory.interface'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { createElementTypeNotSupportedError } from '../../utils'; +import { + CommonCartridgeMetadataElement, + CommonCartridgeMetadataElementProps, +} from './common-cartridge-metadata-element'; +import { + CommonCartridgeOrganizationElement, + CommonCartridgeOrganizationElementProps, +} from './common-cartridge-organization-element'; +import { + CommonCartridgeOrganizationsWrapperElement, + CommonCartridgeOrganizationsWrapperElementProps, +} from './common-cartridge-organizations-wrapper-element'; +import { + CommonCartridgeResourcesWrapperElement, + CommonCartridgeResourcesWrapperElementProps, +} from './common-cartridge-resources-wrapper-element'; -export class CommonCartridgeElementFactory { - private static readonly instance = new CommonCartridgeElementFactory(); +export type CommonCartridgeElementProps = + | CommonCartridgeMetadataElementProps + | CommonCartridgeOrganizationElementProps + | CommonCartridgeOrganizationsWrapperElementProps + | CommonCartridgeResourcesWrapperElementProps; + +export class CommonCartridgeElementFactoryV130 extends CommonCartridgeElementFactory { + public static readonly instance = new CommonCartridgeElementFactoryV130(); public static getInstance(): CommonCartridgeElementFactory { return this.instance; } - public createElement(_props: unknown): CommonCartridgeElement { - throw new Error('Method not implemented.'); + public createElement(props: CommonCartridgeElementProps): CommonCartridgeElement { + switch (props.type) { + // AI next 8 lines + case CommonCartridgeElementType.METADATA: + return new CommonCartridgeMetadataElement(props); + case CommonCartridgeElementType.ORGANIZATION: + return new CommonCartridgeOrganizationElement(props); + case CommonCartridgeElementType.ORGANIZATIONS_WRAPPER: + return new CommonCartridgeOrganizationsWrapperElement(props); + case CommonCartridgeElementType.RESOURCES_WRAPPER: + return new CommonCartridgeResourcesWrapperElement(props); + default: + throw createElementTypeNotSupportedError((props as { type: string }).type); // FIXME: remove type assertion + } } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts index 05af73fb07e..42499b2f91e 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts @@ -1,7 +1,8 @@ -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; export type CommonCartridgeMetadataElementProps = { + type: CommonCartridgeElementType.METADATA; version: CommonCartridgeVersion; title: string; creationDate: Date; diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts new file mode 100644 index 00000000000..e806656e8ea --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts @@ -0,0 +1,30 @@ +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; + +export type CommonCartridgeOrganizationElementProps = { + type: CommonCartridgeElementType.ORGANIZATION; + version: CommonCartridgeVersion; + identifier: string; + title: string; + items: CommonCartridgeElement[]; +}; + +export class CommonCartridgeOrganizationElement extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeOrganizationElementProps) { + super(props); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_3_0; + } + + public override getManifestXmlObject(): Record { + return { + $: { + identifier: this.props.identifier, + }, + title: this.props.title, + item: this.props.items.map((item) => item.getManifestXmlObject()), + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts new file mode 100644 index 00000000000..a25a2d2955a --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts @@ -0,0 +1,39 @@ +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; + +export type CommonCartridgeOrganizationsWrapperElementProps = { + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; + version: CommonCartridgeVersion; + items: CommonCartridgeElement[]; +}; + +export class CommonCartridgeOrganizationsWrapperElement extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementProps) { + super(props); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_3_0; + } + + public override getManifestXmlObject(): Record { + return { + organization: [ + { + $: { + identifier: 'org-1', + structure: 'rooted-hierarchy', + }, + item: [ + { + $: { + identifier: 'LearningModules', + }, + item: this.props.items.map((items) => items.getManifestXmlObject()), + }, + ], + }, + ], + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts new file mode 100644 index 00000000000..199940d0c14 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts @@ -0,0 +1,28 @@ +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; + +export type CommonCartridgeResourcesWrapperElementProps = { + type: CommonCartridgeElementType.RESOURCES_WRAPPER; + version: CommonCartridgeVersion; + items: CommonCartridgeElement[]; +}; + +export class CommonCartridgeResourcesWrapperElement extends CommonCartridgeElement { + constructor(private readonly props: CommonCartridgeResourcesWrapperElementProps) { + super(props); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_3_0; + } + + public override getManifestXmlObject(): Record { + return { + resources: [ + { + resource: this.props.items.map((items) => items.getManifestXmlObject()), + }, + ], + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element-factory.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element-factory.interface.ts new file mode 100644 index 00000000000..5390d47e66b --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element-factory.interface.ts @@ -0,0 +1,8 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeElement } from './common-cartridge-element.interface'; + +export type CommonCartridgeElementProps = { version: CommonCartridgeVersion }; + +export abstract class CommonCartridgeElementFactory { + abstract createElement(props: CommonCartridgeElementProps): CommonCartridgeElement; +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.ts index b0b3ada2528..b9a2cb3db07 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/utils.ts @@ -20,6 +20,11 @@ export function createResourceTypeNotSupportedError(type: string): Error { return new InternalServerErrorException(`Common Cartridge resource type ${type} is not supported`); } +export function createElementTypeNotSupportedError(type: string): Error { + // AI next 1 line + return new InternalServerErrorException(`Common Cartridge element type ${type} is not supported`); +} + export function checkCommonCartridgeVersion(version: CommonCartridgeVersion): void | never { const supportedVersions = [ CommonCartridgeVersion.V_1_1_0, From 28f45ea95c195149a2895dcacaa540b73cbdc9f7 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 6 Dec 2023 16:50:38 +0100 Subject: [PATCH 057/177] EW-539 Working on resource factory --- .../common-cartridge-resource-factory.ts | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts index 2a0c4dda618..83e1b81b336 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts @@ -1,8 +1,21 @@ -import { - CommonCartridgeResourceFactory, - CommonCartridgeResourceProps, -} from '../../interfaces/common-cartridge-resource-factory.interface'; +import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; +import { CommonCartridgeResourceFactory } from '../../interfaces/common-cartridge-resource-factory.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { createResourceTypeNotSupportedError } from '../../utils'; +import { CommonCartridgeLtiResource, CommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; +import { + CommonCartridgeWebContentResource, + CommonCartridgeWebContentResourceProps, +} from './common-cartridge-web-content-resource'; +import { + CommonCartridgeWebLinkResource, + CommonCartridgeWebLinkResourceProps, +} from './common-cartridge-web-link-resource'; + +export type CommonCartridgeResourceProps = + | CommonCartridgeLtiResourceProps + | CommonCartridgeWebContentResourceProps + | CommonCartridgeWebLinkResourceProps; export class CommonCartridgeResourceFactoryV110 extends CommonCartridgeResourceFactory { public static readonly instance = new CommonCartridgeResourceFactoryV110(); @@ -12,6 +25,15 @@ export class CommonCartridgeResourceFactoryV110 extends CommonCartridgeResourceF } public override createResource(props: CommonCartridgeResourceProps): CommonCartridgeResource { - throw new Error('Method not implemented.'); + switch (props.type) { + case CommonCartridgeResourceType.LTI: + return new CommonCartridgeLtiResource(props); + case CommonCartridgeResourceType.WEB_CONTENT: + return new CommonCartridgeWebContentResource(props); + case CommonCartridgeResourceType.WEB_LINK: + return new CommonCartridgeWebLinkResource(props); + default: + throw createResourceTypeNotSupportedError(props.type); + } } } From 2a43e322583f80afd27ff2bae3dff135ca41efef Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 7 Dec 2023 09:26:13 +0100 Subject: [PATCH 058/177] EW-539 Add public keyword to methods --- .../common-cartridge/builders/common-cartridge-file-builder.ts | 2 +- .../v1.1.0/common-cartridge-resources-wrapper-element.ts | 2 +- .../v1.3.0/common-cartridge-resources-wrapper-element.ts | 2 +- .../resources/v1.1.0/common-cartridge-web-content-resource.ts | 2 +- .../resources/v1.1.0/common-cartridge-web-link-resource.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts index ed9cbf69ea0..6bbccf7ade6 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts @@ -27,7 +27,7 @@ export class CommonCartridgeFileBuilder { private metadata?: CommonCartridgeElement; - constructor(private readonly props: CommonCartridgeFileBuilderProps) { + public constructor(private readonly props: CommonCartridgeFileBuilderProps) { checkCommonCartridgeVersion(props.version); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts index 1bbc07b4377..eeca33badfd 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts @@ -8,7 +8,7 @@ export type CommonCartridgeResourcesWrapperElementProps = { }; export class CommonCartridgeResourcesWrapperElement extends CommonCartridgeElement { - constructor(private readonly props: CommonCartridgeResourcesWrapperElementProps) { + public constructor(private readonly props: CommonCartridgeResourcesWrapperElementProps) { super(props); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts index 199940d0c14..9bfaa4192a0 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts @@ -8,7 +8,7 @@ export type CommonCartridgeResourcesWrapperElementProps = { }; export class CommonCartridgeResourcesWrapperElement extends CommonCartridgeElement { - constructor(private readonly props: CommonCartridgeResourcesWrapperElementProps) { + public constructor(private readonly props: CommonCartridgeResourcesWrapperElementProps) { super(props); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts index 51f4f3cba6d..c42f8ffdf74 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -16,7 +16,7 @@ export type CommonCartridgeWebContentResourceProps = { }; export class CommonCartridgeWebContentResource extends CommonCartridgeResource { - constructor(private readonly props: CommonCartridgeWebContentResourceProps) { + public constructor(private readonly props: CommonCartridgeWebContentResourceProps) { super(props); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts index 60f4c063f40..11a5e2fca54 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -12,7 +12,7 @@ export type CommonCartridgeWebLinkResourceProps = { }; export class CommonCartridgeWebLinkResource extends CommonCartridgeResource { - constructor(private readonly props: CommonCartridgeWebLinkResourceProps) { + public constructor(private readonly props: CommonCartridgeWebLinkResourceProps) { super(props); } From a88101e3f0d946ccfe91caa06bce083b33f952e5 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 7 Dec 2023 09:30:07 +0100 Subject: [PATCH 059/177] EW-539 Adjust element version factory --- .../elements/common-cartridge-element-version-factory.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts index b673047fa13..45768c17120 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts @@ -1,7 +1,7 @@ import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElementFactory as CommonCartridgeElementFactoryV110 } from './v1.1.0/common-cartridge-element-factory'; -import { CommonCartridgeElementFactory as CommonCartridgeElementFactoryV130 } from './v1.3.0/common-cartridge-element-factory'; +import { CommonCartridgeElementFactoryV110 } from './v1.1.0/common-cartridge-element-factory'; +import { CommonCartridgeElementFactoryV130 } from './v1.3.0/common-cartridge-element-factory'; export class CommonCartridgeElementVersionFactory { public static createFactory(version: CommonCartridgeVersion) { From ed38847b3ae92ef706013cc0aac0d08dc0c1edd7 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 7 Dec 2023 10:18:38 +0100 Subject: [PATCH 060/177] EW-539 working on resources --- .../common-cartridge.enums.ts | 1 + ...mmon-cartridge-resource-version-factory.ts | 3 +- .../common-cartridge-resource-factory.ts | 6 +- .../common-cartridge-manifest-resource.ts | 68 +++++++++++++++++++ .../common-cartridge-resource-factory.ts | 13 +++- 5 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts index 541368dc40f..39ffc3a519f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts @@ -10,6 +10,7 @@ export enum CommonCartridgeVersion { export enum CommonCartridgeResourceType { LTI = 'lti', + MANIFEST = 'manifest', WEB_CONTENT = 'webcontent', WEB_LINK = 'weblink', } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts index 78fb31e29d8..21bd729d51c 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts @@ -1,5 +1,6 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../interfaces/common-cartridge-resource-factory.interface'; +import { createVersionNotSupportedError } from '../utils'; import { CommonCartridgeResourceFactoryV110 } from './v1.1.0/common-cartridge-resource-factory'; import { CommonCartridgeResourceFactoryV130 } from './v1.3.0/common-cartridge-resource-factory'; @@ -11,7 +12,7 @@ export class CommonCartridgeResourceVersionFactory { case CommonCartridgeVersion.V_1_3_0: return CommonCartridgeResourceFactoryV130.getInstance(); default: - throw new Error(`Common Cartridge version ${version} is not supported`); + throw createVersionNotSupportedError(version); } } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts index 83e1b81b336..c286ad87ba5 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts @@ -25,7 +25,9 @@ export class CommonCartridgeResourceFactoryV110 extends CommonCartridgeResourceF } public override createResource(props: CommonCartridgeResourceProps): CommonCartridgeResource { - switch (props.type) { + const { type } = props; + + switch (type) { case CommonCartridgeResourceType.LTI: return new CommonCartridgeLtiResource(props); case CommonCartridgeResourceType.WEB_CONTENT: @@ -33,7 +35,7 @@ export class CommonCartridgeResourceFactoryV110 extends CommonCartridgeResourceF case CommonCartridgeResourceType.WEB_LINK: return new CommonCartridgeWebLinkResource(props); default: - throw createResourceTypeNotSupportedError(props.type); + throw createResourceTypeNotSupportedError(type); } } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts new file mode 100644 index 00000000000..88c368f94ff --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -0,0 +1,68 @@ +import { Builder } from 'xml2js'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeOrganizationsWrapperElement } from '../../elements/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElement } from '../../elements/common-cartridge-resources-wrapper-element'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; + +export type CommonCartridgeManifestResourceProps = { + type: CommonCartridgeResourceType.MANIFEST; + version: CommonCartridgeVersion; + identifier: string; + metadata: CommonCartridgeElement; + organizations: CommonCartridgeElement[]; + resources: CommonCartridgeElement[]; +}; + +export class CommonCartridgeManifestResource extends CommonCartridgeResource { + private readonly xmlBuilder = new Builder(); + + public constructor(private readonly props: CommonCartridgeManifestResourceProps) { + super(props); + } + + public override canInline(): boolean { + return false; + } + + public override getFilePath(): string { + return 'imsmanifest.xml'; + } + + public override getFileContent(): string { + return this.xmlBuilder.buildObject(this.getManifestXmlObject()); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_3_0; + } + + public override getManifestXmlObject(): Record { + return { + manifest: { + $: { + identifier: this.props.identifier, + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1', + 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest', + 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource', + 'xmlns:ext': 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': + 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lomresource_v1p0.xsd ' + + 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd ' + + 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd ' + + 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_cpextensionv1p2_v1p0.xsd', + }, + metadata: this.props.metadata.getManifestXmlObject(), + organizations: new CommonCartridgeOrganizationsWrapperElement({ + version: this.props.version, + organizations: this.props.organizations, + }).getManifestXmlObject(), + resources: new CommonCartridgeResourcesWrapperElement({ + version: this.props.version, + resources: this.props.resources, + }).getManifestXmlObject(), + }, + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts index 13b721a9405..ec967bc8cff 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts @@ -3,6 +3,10 @@ import { CommonCartridgeResourceFactory } from '../../interfaces/common-cartridg import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; import { createResourceTypeNotSupportedError } from '../../utils'; import { CommonCartridgeLtiResource, CommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; +import { + CommonCartridgeManifestResource, + CommonCartridgeManifestResourceProps, +} from './common-cartridge-manifest-resource'; import { CommonCartridgeWebContentResource, CommonCartridgeWebContentResourceProps, @@ -14,6 +18,7 @@ import { export type CommonCartridgeResourceProps = | CommonCartridgeLtiResourceProps + | CommonCartridgeManifestResourceProps | CommonCartridgeWebContentResourceProps | CommonCartridgeWebLinkResourceProps; @@ -25,15 +30,19 @@ export class CommonCartridgeResourceFactoryV130 extends CommonCartridgeResourceF } public override createResource(props: CommonCartridgeResourceProps): CommonCartridgeResource { - switch (props.type) { + const { type } = props; + + switch (type) { case CommonCartridgeResourceType.LTI: return new CommonCartridgeLtiResource(props); + case CommonCartridgeResourceType.MANIFEST: + return new CommonCartridgeManifestResource(props); case CommonCartridgeResourceType.WEB_CONTENT: return new CommonCartridgeWebContentResource(props); case CommonCartridgeResourceType.WEB_LINK: return new CommonCartridgeWebLinkResource(props); default: - throw createResourceTypeNotSupportedError(props.type); + throw createResourceTypeNotSupportedError(type as string); } } } From a6495bfc032009d1f6942b0463cebdd3efbbd4e2 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 7 Dec 2023 10:32:54 +0100 Subject: [PATCH 061/177] EW-539 some renaming --- .../common-cartridge-organizations-wrapper-element.ts | 4 ++-- .../elements/common-cartridge-resources-wrapper-element.ts | 4 ++-- .../resources/v1.1.0/common-cartridge-resource-factory.ts | 4 ++-- .../resources/v1.3.0/common-cartridge-manifest-resource.ts | 2 +- .../resources/v1.3.0/common-cartridge-resource-factory.ts | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts index 46ebc3a4890..69395a4155e 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts @@ -3,7 +3,7 @@ import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.i export type CommonCartridgeOrganizationsWrapperElementProps = { version: CommonCartridgeVersion; - items: CommonCartridgeElement[]; + organizations: CommonCartridgeElement[]; }; export class CommonCartridgeOrganizationsWrapperElement extends CommonCartridgeElement { @@ -28,7 +28,7 @@ export class CommonCartridgeOrganizationsWrapperElement extends CommonCartridgeE $: { identifier: 'LearningModules', }, - item: this.props.items.map((items) => items.getManifestXmlObject()), + item: this.props.organizations.map((items) => items.getManifestXmlObject()), }, ], }, diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts index 4352c008dc2..f86722f32d6 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts @@ -3,7 +3,7 @@ import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.i export type CommonCartridgeResourcesWrapperElementProps = { version: CommonCartridgeVersion; - items: CommonCartridgeElement[]; + resources: CommonCartridgeElement[]; }; export class CommonCartridgeResourcesWrapperElement extends CommonCartridgeElement { @@ -19,7 +19,7 @@ export class CommonCartridgeResourcesWrapperElement extends CommonCartridgeEleme return { resources: [ { - resource: this.props.items.map((items) => items.getManifestXmlObject()), + resource: this.props.resources.map((items) => items.getManifestXmlObject()), }, ], }; diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts index c286ad87ba5..9a878afb95d 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts @@ -12,7 +12,7 @@ import { CommonCartridgeWebLinkResourceProps, } from './common-cartridge-web-link-resource'; -export type CommonCartridgeResourceProps = +export type CommonCartridgeResourcePropsV110 = | CommonCartridgeLtiResourceProps | CommonCartridgeWebContentResourceProps | CommonCartridgeWebLinkResourceProps; @@ -24,7 +24,7 @@ export class CommonCartridgeResourceFactoryV110 extends CommonCartridgeResourceF return this.instance; } - public override createResource(props: CommonCartridgeResourceProps): CommonCartridgeResource { + public override createResource(props: CommonCartridgeResourcePropsV110): CommonCartridgeResource { const { type } = props; switch (type) { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts index 88c368f94ff..37b39843558 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -7,7 +7,7 @@ import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resou export type CommonCartridgeManifestResourceProps = { type: CommonCartridgeResourceType.MANIFEST; - version: CommonCartridgeVersion; + version: CommonCartridgeVersion.V_1_3_0; identifier: string; metadata: CommonCartridgeElement; organizations: CommonCartridgeElement[]; diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts index ec967bc8cff..f4a2ce6f890 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts @@ -16,7 +16,7 @@ import { CommonCartridgeWebLinkResourceProps, } from './common-cartridge-web-link-resource'; -export type CommonCartridgeResourceProps = +export type CommonCartridgeResourcePropsV130 = | CommonCartridgeLtiResourceProps | CommonCartridgeManifestResourceProps | CommonCartridgeWebContentResourceProps @@ -29,7 +29,7 @@ export class CommonCartridgeResourceFactoryV130 extends CommonCartridgeResourceF return this.instance; } - public override createResource(props: CommonCartridgeResourceProps): CommonCartridgeResource { + public override createResource(props: CommonCartridgeResourcePropsV130): CommonCartridgeResource { const { type } = props; switch (type) { From 829260177d3ccf5ed4989955f3859af4a2768214 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 7 Dec 2023 12:33:45 +0100 Subject: [PATCH 062/177] EW-539 working on resources --- .../common-cartridge.enums.ts | 1 + .../common-cartridge-lti-resource.spec.ts | 132 ++++++++++++++++++ .../v1.1.0/common-cartridge-lti-resource.ts | 18 +-- .../common-cartridge-manifest-resource.ts | 66 +++++++++ .../common-cartridge-resource-factory.ts | 29 ++-- .../common-cartridge-web-content-resource.ts | 6 +- ...common-cartridge-web-link-resource.spec.ts | 28 ++++ .../common-cartridge-web-link-resource.ts | 6 +- .../common-cartridge-lti-resource.spec.ts | 132 ++++++++++++++++++ .../v1.3.0/common-cartridge-lti-resource.ts | 16 +-- .../common-cartridge-manifest-resource.ts | 6 +- .../common-cartridge-resource-factory.ts | 32 ++--- .../common-cartridge-web-content-resource.ts | 6 +- .../common-cartridge-web-link-resource.ts | 6 +- 14 files changed, 425 insertions(+), 59 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts index 39ffc3a519f..69f4379b50f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts @@ -9,6 +9,7 @@ export enum CommonCartridgeVersion { // TODO: think about if there is a way to ensure that an implementation that is dependent on these versions has implementations for all versions. (HINT: helper class, composable, abstract class...) export enum CommonCartridgeResourceType { + UNKNOWN = 'unknown', LTI = 'lti', MANIFEST = 'manifest', WEB_CONTENT = 'webcontent', diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.spec.ts new file mode 100644 index 00000000000..f6308bb7018 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.spec.ts @@ -0,0 +1,132 @@ +import { faker } from '@faker-js/faker'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeLtiResourcePropsV110, CommonCartridgeLtiResourceV110 } from './common-cartridge-lti-resource'; + +describe('CommonCartridgeLtiResourceV110', () => { + const setup = () => { + const props: CommonCartridgeLtiResourcePropsV110 = { + type: CommonCartridgeResourceType.LTI, + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + folder: faker.string.uuid(), + title: faker.lorem.words(), + description: faker.lorem.sentence(), + url: faker.internet.url(), + }; + const sut = new CommonCartridgeLtiResourceV110(props); + + return { sut, props }; + }; + + describe('canInline', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return false', () => { + const { sut } = setup(); + const result = sut.canInline(); + + expect(result).toBe(false); + }); + }); + }); + + describe('getFilePath', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return the constructed file path', () => { + const { sut, props } = setup(); + const result = sut.getFilePath(); + + expect(result).toBe(`${props.folder}/${props.identifier}.xml`); + }); + }); + }); + + describe('getFileContent', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should contain correct XML root element', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(''); + }); + + it('should contain correct XML namespace', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain('xmlns="/xsd/imslticc_v1p0"'); + expect(result).toContain('xmlns:blti="/xsd/imsbasiclti_v1p0"'); + expect(result).toContain('xmlns:lticm="/xsd/imslticm_v1p0"'); + expect(result).toContain('xmlns:lticp="/xsd/imslticp_v1p0"'); + }); + + it('should contain correct XML schema', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain( + 'xsi:schemaLocation="' + + '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd ' + + '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd ' + + '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd ' + + '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd"' + ); + }); + + it('should contain correct XML title', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(`${props.title}`); + }); + + it('should contain correct XML description', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(`${props.description}`); + }); + + it('should contain correct XML url', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(`${props.url}`); + expect(result).toContain(`${props.url}`); + }); + }); + }); + + // AI next 10 lines + describe('getSupportedVersion', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return correct version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_1_0); + }); + }); + }); + + describe('getManifestXml', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return manifest xml object', () => { + const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toEqual({ + $: { + identifier: props.identifier, + type: props.type, + }, + file: { + $: { + href: `${props.folder}/${props.identifier}.xml`, + }, + }, + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.ts index 457821df6d6..c43c2b27a73 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.ts @@ -2,18 +2,18 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../commo import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; import { buildXmlString } from '../../utils'; -export type CommonCartridgeLtiResourceProps = { +export type CommonCartridgeLtiResourcePropsV110 = { type: CommonCartridgeResourceType.LTI; - version: CommonCartridgeVersion; + version: CommonCartridgeVersion.V_1_1_0; identifier: string; folder: string; title: string; - description?: string; + description: string; url: string; }; -export class CommonCartridgeLtiResource extends CommonCartridgeResource { - public constructor(private readonly props: CommonCartridgeLtiResourceProps) { +export class CommonCartridgeLtiResourceV110 extends CommonCartridgeResource { + public constructor(private readonly props: CommonCartridgeLtiResourcePropsV110) { super(props); } @@ -34,10 +34,10 @@ export class CommonCartridgeLtiResource extends CommonCartridgeResource { 'xmlns:lticm': '/xsd/imslticm_v1p0', 'xmlns:lticp': '/xsd/imslticp_v1p0', 'xsi:schemaLocation': - '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd' + - '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd' + - '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd' + - '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd"', + '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd ' + + '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd ' + + '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd ' + + '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd', }, blti: { title: this.props.title, diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts new file mode 100644 index 00000000000..496f639c98a --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -0,0 +1,66 @@ +import { Builder } from 'xml2js'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeOrganizationsWrapperElement } from '../../elements/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElement } from '../../elements/common-cartridge-resources-wrapper-element'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; + +export type CommonCartridgeManifestResourcePropsV110 = { + type: CommonCartridgeResourceType.MANIFEST; + version: CommonCartridgeVersion.V_1_1_0; + identifier: string; + metadata: CommonCartridgeElement; + organizations: CommonCartridgeElement[]; + resources: CommonCartridgeElement[]; +}; + +export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource { + private readonly xmlBuilder = new Builder(); + + public constructor(private readonly props: CommonCartridgeManifestResourcePropsV110) { + super(props); + } + + public override canInline(): boolean { + return false; + } + + public override getFilePath(): string { + return 'imsmanifest.xml'; + } + + public override getFileContent(): string { + return this.xmlBuilder.buildObject(this.getManifestXmlObject()); + } + + public override getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_1_0; + } + + public override getManifestXmlObject(): Record { + return { + manifest: { + $: { + identifier: this.props.identifier, + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', + 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', + 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation': + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd ' + + 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ', + }, + metadata: this.props.metadata.getManifestXmlObject(), + organizations: new CommonCartridgeOrganizationsWrapperElement({ + version: this.props.version, + organizations: this.props.organizations, + }).getManifestXmlObject(), + resources: new CommonCartridgeResourcesWrapperElement({ + version: this.props.version, + resources: this.props.resources, + }).getManifestXmlObject(), + }, + }; + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts index 9a878afb95d..2d113378fb3 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts @@ -2,20 +2,25 @@ import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../../interfaces/common-cartridge-resource-factory.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; import { createResourceTypeNotSupportedError } from '../../utils'; -import { CommonCartridgeLtiResource, CommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; +import { CommonCartridgeLtiResourcePropsV110, CommonCartridgeLtiResourceV110 } from './common-cartridge-lti-resource'; import { - CommonCartridgeWebContentResource, - CommonCartridgeWebContentResourceProps, + CommonCartridgeManifestResourcePropsV110, + CommonCartridgeManifestResourceV110, +} from './common-cartridge-manifest-resource'; +import { + CommonCartridgeWebContentResourcePropsV110, + CommonCartridgeWebContentResourceV110, } from './common-cartridge-web-content-resource'; import { - CommonCartridgeWebLinkResource, - CommonCartridgeWebLinkResourceProps, + CommonCartridgeWebLinkResourcePropsV110, + CommonCartridgeWebLinkResourceV110, } from './common-cartridge-web-link-resource'; export type CommonCartridgeResourcePropsV110 = - | CommonCartridgeLtiResourceProps - | CommonCartridgeWebContentResourceProps - | CommonCartridgeWebLinkResourceProps; + | CommonCartridgeLtiResourcePropsV110 + | CommonCartridgeManifestResourcePropsV110 + | CommonCartridgeWebContentResourcePropsV110 + | CommonCartridgeWebLinkResourcePropsV110; export class CommonCartridgeResourceFactoryV110 extends CommonCartridgeResourceFactory { public static readonly instance = new CommonCartridgeResourceFactoryV110(); @@ -29,11 +34,13 @@ export class CommonCartridgeResourceFactoryV110 extends CommonCartridgeResourceF switch (type) { case CommonCartridgeResourceType.LTI: - return new CommonCartridgeLtiResource(props); + return new CommonCartridgeLtiResourceV110(props); + case CommonCartridgeResourceType.MANIFEST: + return new CommonCartridgeManifestResourceV110(props); case CommonCartridgeResourceType.WEB_CONTENT: - return new CommonCartridgeWebContentResource(props); + return new CommonCartridgeWebContentResourceV110(props); case CommonCartridgeResourceType.WEB_LINK: - return new CommonCartridgeWebLinkResource(props); + return new CommonCartridgeWebLinkResourceV110(props); default: throw createResourceTypeNotSupportedError(type); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts index c42f8ffdf74..b56d84ca7c3 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -5,7 +5,7 @@ import { } from '../../common-cartridge.enums'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; -export type CommonCartridgeWebContentResourceProps = { +export type CommonCartridgeWebContentResourcePropsV110 = { type: CommonCartridgeResourceType.WEB_CONTENT; version: CommonCartridgeVersion.V_1_1_0; identifier: string; @@ -15,8 +15,8 @@ export type CommonCartridgeWebContentResourceProps = { intendedUse: CommonCartridgeIntendedUseType; }; -export class CommonCartridgeWebContentResource extends CommonCartridgeResource { - public constructor(private readonly props: CommonCartridgeWebContentResourceProps) { +export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResource { + public constructor(private readonly props: CommonCartridgeWebContentResourcePropsV110) { super(props); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts new file mode 100644 index 00000000000..f62cbce8033 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -0,0 +1,28 @@ +import { faker } from '@faker-js/faker'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { + CommonCartridgeWebLinkResourcePropsV110, + CommonCartridgeWebLinkResourceV110, +} from './common-cartridge-web-link-resource'; + +describe('CommonCartridgeWebLinkResourceV110', () => { + const setup = () => { + const props: CommonCartridgeWebLinkResourcePropsV110 = { + type: CommonCartridgeResourceType.WEB_LINK, + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + folder: faker.string.uuid(), + title: faker.lorem.words(), + url: faker.internet.url(), + }; + const sut = new CommonCartridgeWebLinkResourceV110(props); + + return { sut, props }; + }; + + describe('canInline', () => {}); + describe('getFilePath', () => {}); + describe('getFileContent', () => {}); + describe('getSupportedVersion', () => {}); + describe('getManifestXmlObject', () => {}); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts index 11a5e2fca54..b714fbe3f6b 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -2,7 +2,7 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../commo import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; import { buildXmlString } from '../../utils'; -export type CommonCartridgeWebLinkResourceProps = { +export type CommonCartridgeWebLinkResourcePropsV110 = { type: CommonCartridgeResourceType.WEB_LINK; version: CommonCartridgeVersion.V_1_1_0; identifier: string; @@ -11,8 +11,8 @@ export type CommonCartridgeWebLinkResourceProps = { url: string; }; -export class CommonCartridgeWebLinkResource extends CommonCartridgeResource { - public constructor(private readonly props: CommonCartridgeWebLinkResourceProps) { +export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource { + public constructor(private readonly props: CommonCartridgeWebLinkResourcePropsV110) { super(props); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.spec.ts new file mode 100644 index 00000000000..10f5e57d29b --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.spec.ts @@ -0,0 +1,132 @@ +import { faker } from '@faker-js/faker'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeLtiResourcePropsV130, CommonCartridgeLtiResourceV130 } from './common-cartridge-lti-resource'; + +describe('CommonCartridgeLtiResourcePropsV130', () => { + const setup = () => { + const props: CommonCartridgeLtiResourcePropsV130 = { + type: CommonCartridgeResourceType.LTI, + version: CommonCartridgeVersion.V_1_3_0, + identifier: faker.string.uuid(), + folder: faker.string.uuid(), + title: faker.lorem.words(), + description: faker.lorem.sentence(), + url: faker.internet.url(), + }; + const sut = new CommonCartridgeLtiResourceV130(props); + + return { sut, props }; + }; + + describe('canInline', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return false', () => { + const { sut } = setup(); + const result = sut.canInline(); + + expect(result).toBe(false); + }); + }); + }); + + describe('getFilePath', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return the constructed file path', () => { + const { sut, props } = setup(); + const result = sut.getFilePath(); + + expect(result).toBe(`${props.folder}/${props.identifier}.xml`); + }); + }); + }); + + describe('getFileContent', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should contain correct XML root element', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(''); + }); + + it('should contain correct XML namespace', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain('xmlns="/xsd/imslticc_v1p0"'); + expect(result).toContain('xmlns:blti="/xsd/imsbasiclti_v1p0"'); + expect(result).toContain('xmlns:lticm="/xsd/imslticm_v1p0"'); + expect(result).toContain('xmlns:lticp="/xsd/imslticp_v1p0"'); + }); + + it('should contain correct XML schema', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain( + 'xsi:schemaLocation="' + + '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd ' + + '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd ' + + '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd ' + + '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd"' + ); + }); + + it('should contain correct XML title', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(`${props.title}`); + }); + + it('should contain correct XML description', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(`${props.description}`); + }); + + it('should contain correct XML url', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(`${props.url}`); + expect(result).toContain(`${props.url}`); + }); + }); + }); + + // AI next 10 lines + describe('getSupportedVersion', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return supported version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_3_0); + }); + }); + }); + + describe('getManifestXml', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return manifest xml object', () => { + const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toEqual({ + $: { + identifier: props.identifier, + type: props.type, + }, + file: { + $: { + href: `${props.folder}/${props.identifier}.xml`, + }, + }, + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.ts index 612c0672ad5..cf0dafb085f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.ts @@ -2,18 +2,18 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../commo import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; import { buildXmlString } from '../../utils'; -export type CommonCartridgeLtiResourceProps = { +export type CommonCartridgeLtiResourcePropsV130 = { type: CommonCartridgeResourceType.LTI; - version: CommonCartridgeVersion; + version: CommonCartridgeVersion.V_1_3_0; identifier: string; folder: string; title: string; - description?: string; + description: string; url: string; }; -export class CommonCartridgeLtiResource extends CommonCartridgeResource { - public constructor(private readonly props: CommonCartridgeLtiResourceProps) { +export class CommonCartridgeLtiResourceV130 extends CommonCartridgeResource { + public constructor(private readonly props: CommonCartridgeLtiResourcePropsV130) { super(props); } @@ -46,12 +46,12 @@ export class CommonCartridgeLtiResource extends CommonCartridgeResource { secure_launch_url: this.props.url, cartridge_bundle: { $: { - identifierref: 'BLTI001_Bundle', + identifierref: 'BLTI001_Bundle', // FIXME: is this correct? }, }, cartridge_icon: { $: { - identifierref: 'BLTI001_Icon', + identifierref: 'BLTI001_Icon', // FIXME: is this correct? }, }, }, @@ -67,7 +67,7 @@ export class CommonCartridgeLtiResource extends CommonCartridgeResource { return { $: { identifier: this.props.identifier, - type: this.props.type, + type: this.props.type, // FIXME: is this correct? }, file: { $: { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts index 37b39843558..868f9cd7fdc 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -5,7 +5,7 @@ import { CommonCartridgeResourcesWrapperElement } from '../../elements/common-ca import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; -export type CommonCartridgeManifestResourceProps = { +export type CommonCartridgeManifestResourcePropsV130 = { type: CommonCartridgeResourceType.MANIFEST; version: CommonCartridgeVersion.V_1_3_0; identifier: string; @@ -14,10 +14,10 @@ export type CommonCartridgeManifestResourceProps = { resources: CommonCartridgeElement[]; }; -export class CommonCartridgeManifestResource extends CommonCartridgeResource { +export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource { private readonly xmlBuilder = new Builder(); - public constructor(private readonly props: CommonCartridgeManifestResourceProps) { + public constructor(private readonly props: CommonCartridgeManifestResourcePropsV130) { super(props); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts index f4a2ce6f890..b87d51b9b84 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts @@ -2,25 +2,25 @@ import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../../interfaces/common-cartridge-resource-factory.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; import { createResourceTypeNotSupportedError } from '../../utils'; -import { CommonCartridgeLtiResource, CommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; +import { CommonCartridgeLtiResourcePropsV130, CommonCartridgeLtiResourceV130 } from './common-cartridge-lti-resource'; import { - CommonCartridgeManifestResource, - CommonCartridgeManifestResourceProps, + CommonCartridgeManifestResourcePropsV130, + CommonCartridgeManifestResourceV130, } from './common-cartridge-manifest-resource'; import { - CommonCartridgeWebContentResource, - CommonCartridgeWebContentResourceProps, + CommonCartridgeWebContentResourcePropsV130, + CommonCartridgeWebContentResourceV130, } from './common-cartridge-web-content-resource'; import { - CommonCartridgeWebLinkResource, - CommonCartridgeWebLinkResourceProps, + CommonCartridgeWebLinkResourcePropsV130, + CommonCartridgeWebLinkResourceV130, } from './common-cartridge-web-link-resource'; export type CommonCartridgeResourcePropsV130 = - | CommonCartridgeLtiResourceProps - | CommonCartridgeManifestResourceProps - | CommonCartridgeWebContentResourceProps - | CommonCartridgeWebLinkResourceProps; + | CommonCartridgeLtiResourcePropsV130 + | CommonCartridgeManifestResourcePropsV130 + | CommonCartridgeWebContentResourcePropsV130 + | CommonCartridgeWebLinkResourcePropsV130; export class CommonCartridgeResourceFactoryV130 extends CommonCartridgeResourceFactory { public static readonly instance = new CommonCartridgeResourceFactoryV130(); @@ -34,15 +34,15 @@ export class CommonCartridgeResourceFactoryV130 extends CommonCartridgeResourceF switch (type) { case CommonCartridgeResourceType.LTI: - return new CommonCartridgeLtiResource(props); + return new CommonCartridgeLtiResourceV130(props); case CommonCartridgeResourceType.MANIFEST: - return new CommonCartridgeManifestResource(props); + return new CommonCartridgeManifestResourceV130(props); case CommonCartridgeResourceType.WEB_CONTENT: - return new CommonCartridgeWebContentResource(props); + return new CommonCartridgeWebContentResourceV130(props); case CommonCartridgeResourceType.WEB_LINK: - return new CommonCartridgeWebLinkResource(props); + return new CommonCartridgeWebLinkResourceV130(props); default: - throw createResourceTypeNotSupportedError(type as string); + throw createResourceTypeNotSupportedError(type); } } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts index c4d4d22f3ca..09607367239 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -5,7 +5,7 @@ import { } from '../../common-cartridge.enums'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; -export type CommonCartridgeWebContentResourceProps = { +export type CommonCartridgeWebContentResourcePropsV130 = { type: CommonCartridgeResourceType.WEB_CONTENT; version: CommonCartridgeVersion.V_1_3_0; identifier: string; @@ -15,8 +15,8 @@ export type CommonCartridgeWebContentResourceProps = { intendedUse: CommonCartridgeIntendedUseType; }; -export class CommonCartridgeWebContentResource extends CommonCartridgeResource { - public constructor(private readonly props: CommonCartridgeWebContentResourceProps) { +export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResource { + public constructor(private readonly props: CommonCartridgeWebContentResourcePropsV130) { super(props); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts index 79021860356..d3426a01dba 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -2,7 +2,7 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../commo import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; import { buildXmlString } from '../../utils'; -export type CommonCartridgeWebLinkResourceProps = { +export type CommonCartridgeWebLinkResourcePropsV130 = { type: CommonCartridgeResourceType.WEB_LINK; version: CommonCartridgeVersion.V_1_3_0; identifier: string; @@ -11,8 +11,8 @@ export type CommonCartridgeWebLinkResourceProps = { url: string; }; -export class CommonCartridgeWebLinkResource extends CommonCartridgeResource { - public constructor(private readonly props: CommonCartridgeWebLinkResourceProps) { +export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource { + public constructor(private readonly props: CommonCartridgeWebLinkResourcePropsV130) { super(props); } From 195c96574a9d0d5aa1960f0590f647bb7e057252 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 7 Dec 2023 14:37:15 +0100 Subject: [PATCH 063/177] EW-539 Adjust element factories --- .../elements/v1.1.0/common-cartridge-element-factory.ts | 6 ++++-- .../elements/v1.3.0/common-cartridge-element-factory.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts index 3f3fae2fc6c..5efd94a610c 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts @@ -33,7 +33,9 @@ export class CommonCartridgeElementFactoryV110 extends CommonCartridgeElementFac } public createElement(props: CommonCartridgeElementProps): CommonCartridgeElement { - switch (props.type) { + const { type } = props; + + switch (type) { // AI next 8 lines case CommonCartridgeElementType.METADATA: return new CommonCartridgeMetadataElement(props); @@ -44,7 +46,7 @@ export class CommonCartridgeElementFactoryV110 extends CommonCartridgeElementFac case CommonCartridgeElementType.RESOURCES_WRAPPER: return new CommonCartridgeResourcesWrapperElement(props); default: - throw createElementTypeNotSupportedError((props as { type: string }).type); // FIXME: remove type assertion + throw createElementTypeNotSupportedError(type); } } } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts index 90ee7aae2ca..eb7aef109cd 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts @@ -33,7 +33,9 @@ export class CommonCartridgeElementFactoryV130 extends CommonCartridgeElementFac } public createElement(props: CommonCartridgeElementProps): CommonCartridgeElement { - switch (props.type) { + const { type } = props; + + switch (type) { // AI next 8 lines case CommonCartridgeElementType.METADATA: return new CommonCartridgeMetadataElement(props); @@ -44,7 +46,7 @@ export class CommonCartridgeElementFactoryV130 extends CommonCartridgeElementFac case CommonCartridgeElementType.RESOURCES_WRAPPER: return new CommonCartridgeResourcesWrapperElement(props); default: - throw createElementTypeNotSupportedError((props as { type: string }).type); // FIXME: remove type assertion + throw createElementTypeNotSupportedError(type); } } } From 7e00a409f950039e5a3f65426a49e23910e3d8a9 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 7 Dec 2023 16:58:25 +0100 Subject: [PATCH 064/177] EW-539 saving work --- .../learnroom/common-cartridge/README.md | 14 ++ .../learnroom/common-cartridge/manifest.xml | 21 +++ ...common-cartridge-web-link-resource.spec.ts | 119 ++++++++++++++- .../common-cartridge-web-link-resource.ts | 16 +- ...common-cartridge-web-link-resource.spec.ts | 137 ++++++++++++++++++ .../common-cartridge-web-link-resource.ts | 2 +- .../common-cartridge/temp/web_link_1_1.xml | 9 ++ .../learnroom/common-cartridge/utils.ts | 2 +- 8 files changed, 306 insertions(+), 14 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/README.md create mode 100644 apps/server/src/modules/learnroom/common-cartridge/manifest.xml create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/web_link_1_1.xml diff --git a/apps/server/src/modules/learnroom/common-cartridge/README.md b/apps/server/src/modules/learnroom/common-cartridge/README.md new file mode 100644 index 00000000000..1450b786644 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/README.md @@ -0,0 +1,14 @@ +# Common Cartridge Module + +> This module contains all functionality to build an + +## XML Schema Namespaces and Definitions for Resources + +| Resource Type | XML Namespace | XSD Locations | +|:-|:-|:-| +| Manifest 1.1.0 || | +| Web Content 1.1.0 || | +| Web Link 1.1.0 | http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 | | +| Manifest 1.3.0 || | +| Web Content 1.3.0 || | +| Web Link 1.3.0 || | diff --git a/apps/server/src/modules/learnroom/common-cartridge/manifest.xml b/apps/server/src/modules/learnroom/common-cartridge/manifest.xml new file mode 100644 index 00000000000..f48382c8334 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/manifest.xml @@ -0,0 +1,21 @@ + + + + IMS Common Cartridge + 1.1.0 + + + + + + + Org 1 + + + + + + + + + diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts index f62cbce8033..ff228c3b0ef 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -20,9 +20,118 @@ describe('CommonCartridgeWebLinkResourceV110', () => { return { sut, props }; }; - describe('canInline', () => {}); - describe('getFilePath', () => {}); - describe('getFileContent', () => {}); - describe('getSupportedVersion', () => {}); - describe('getManifestXmlObject', () => {}); + describe('canInline', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return false', () => { + const { sut } = setup(); + const result = sut.canInline(); + + expect(result).toBe(false); + }); + }); + }); + + describe('getFilePath', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return the constructed file path', () => { + const { sut, props } = setup(); + const result = sut.getFilePath(); + + expect(result).toBe(`${props.folder}/${props.identifier}.xml`); + }); + }); + }); + + describe('getFileContent', () => { + it('should contain correct XML header', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(''); + }); + + it('should contain correct XML root element', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(''); + }); + + it('should contain correct XML namespace', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain('xmlns="http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1"'); + expect(result).toContain('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'); + expect(result).toContain( + 'xsi:schemaLocation="' + + 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd"' + ); + }); + + it('should contain correct title', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(`${props.title}`); + }); + + it('should contain correct url', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(` { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(`target="_self"`); + }); + + // Skipping these tests because values are hardcoded in the implementation + it.skip('should contain correct window features', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(`windowFeatures="width=100, height=100"`); + }); + }); + + describe('getSupportedVersion', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return the supported version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_1_0); + }); + }); + }); + + describe('getManifestXmlObject', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return the manifest XML object', () => { + const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toEqual({ + resource: { + $: { + identifier: props.identifier, + type: 'imswl_xmlv1p1', + }, + file: { + $: { + href: sut.getFilePath(), + }, + }, + }, + }); + }); + }); + }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts index b714fbe3f6b..7a81f3ae660 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -31,7 +31,7 @@ export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', + 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', }, title: this.props.title, url: { @@ -51,13 +51,15 @@ export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource public getManifestXmlObject(): Record { return { - $: { - identifier: this.props.identifier, - type: this.props.type, - }, - file: { + resoucec: { $: { - href: this.getFilePath(), + identifier: this.props.identifier, + type: 'imswl_xmlv1p1', + }, + file: { + $: { + href: this.getFilePath(), + }, }, }, }; diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts new file mode 100644 index 00000000000..78807f65729 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts @@ -0,0 +1,137 @@ +import { faker } from '@faker-js/faker'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { + CommonCartridgeWebLinkResourcePropsV130, + CommonCartridgeWebLinkResourceV130, +} from './common-cartridge-web-link-resource'; + +describe('CommonCartridgeWebLinkResourceV130', () => { + const setup = () => { + const props: CommonCartridgeWebLinkResourcePropsV130 = { + type: CommonCartridgeResourceType.WEB_LINK, + version: CommonCartridgeVersion.V_1_3_0, + identifier: faker.string.uuid(), + folder: faker.string.uuid(), + title: faker.lorem.words(), + url: faker.internet.url(), + }; + const sut = new CommonCartridgeWebLinkResourceV130(props); + + return { sut, props }; + }; + + describe('canInline', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return false', () => { + const { sut } = setup(); + const result = sut.canInline(); + + expect(result).toBe(false); + }); + }); + }); + + describe('getFilePath', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return the constructed file path', () => { + const { sut, props } = setup(); + const result = sut.getFilePath(); + + expect(result).toBe(`${props.folder}/${props.identifier}.xml`); + }); + }); + }); + + describe('getFileContent', () => { + it('should contain correct XML header', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(''); + }); + + it('should contain correct XML root element', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(''); + }); + + it('should contain correct XML namespace', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain('xmlns="http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1"'); + expect(result).toContain('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'); + expect(result).toContain( + 'xsi:schemaLocation="' + + 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd"' + ); + }); + + it('should contain correct title', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(`${props.title}`); + }); + + it('should contain correct url', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(` { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(`target="_self"`); + }); + + // FIXME: add to props + // Skipping these tests because values are hardcoded in the implementation + it.skip('should contain correct window features', () => { + const { sut } = setup(); + const result = sut.getFileContent(); + + expect(result).toContain(`windowFeatures="width=100, height=100"`); + }); + }); + + describe('getSupportedVersion', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return the supported version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_3_0); + }); + }); + }); + + describe('getManifestXmlObject', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return the manifest XML object', () => { + const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toEqual({ + $: { + identifier: props.identifier, + type: props.type, + }, + file: { + $: { + href: sut.getFilePath(), + }, + }, + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts index d3426a01dba..543e4f61984 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -53,7 +53,7 @@ export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource return { $: { identifier: this.props.identifier, - type: this.props.type, + type: 'web', }, file: { $: { diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/web_link_1_1.xml b/apps/server/src/modules/learnroom/common-cartridge/temp/web_link_1_1.xml new file mode 100644 index 00000000000..ae4c28d6429 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/temp/web_link_1_1.xml @@ -0,0 +1,9 @@ + + + Web Link + + \ No newline at end of file diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.ts index b9a2cb3db07..9375e639f59 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/utils.ts @@ -6,7 +6,7 @@ export type OmitVersion = Omit; export type OmitVersionAndFolder = Omit; -const xmlBuilder = new Builder({ headless: true }); +const xmlBuilder = new Builder({ xmldec: { version: '1.0', encoding: 'UTF-8' } }); export function buildXmlString(obj: unknown): string { return xmlBuilder.buildObject(obj); From 814512873014ebb3f535ecf1c9f892526a88ffda Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 8 Dec 2023 15:39:13 +0100 Subject: [PATCH 065/177] EW-539 Renaming --- .../common-cartridge-element-factory.ts | 32 +++++++++---------- .../common-cartridge-metadata-element.ts | 8 ++--- .../common-cartridge-organization-element.ts | 6 ++-- ...cartridge-organizations-wrapper-element.ts | 6 ++-- ...mon-cartridge-resources-wrapper-element.ts | 6 ++-- .../common-cartridge-element-factory.ts | 32 +++++++++---------- .../common-cartridge-metadata-element.ts | 8 ++--- .../common-cartridge-organization-element.ts | 6 ++-- ...cartridge-organizations-wrapper-element.ts | 6 ++-- ...mon-cartridge-resources-wrapper-element.ts | 6 ++-- 10 files changed, 58 insertions(+), 58 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts index 5efd94a610c..257bcc307e0 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts @@ -3,27 +3,27 @@ import { CommonCartridgeElementFactory } from '../../interfaces/common-cartridge import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { createElementTypeNotSupportedError } from '../../utils'; import { - CommonCartridgeMetadataElement, - CommonCartridgeMetadataElementProps, + CommonCartridgeMetadataElementPropsV110, + CommonCartridgeMetadataElementV110, } from './common-cartridge-metadata-element'; import { - CommonCartridgeOrganizationElement, - CommonCartridgeOrganizationElementProps, + CommonCartridgeOrganizationElementPropsV110, + CommonCartridgeOrganizationElementV110, } from './common-cartridge-organization-element'; import { - CommonCartridgeOrganizationsWrapperElement, - CommonCartridgeOrganizationsWrapperElementProps, + CommonCartridgeOrganizationsWrapperElementPropsV110, + CommonCartridgeOrganizationsWrapperElementV110, } from './common-cartridge-organizations-wrapper-element'; import { - CommonCartridgeResourcesWrapperElement, - CommonCartridgeResourcesWrapperElementProps, + CommonCartridgeResourcesWrapperElementPropsV110, + CommonCartridgeResourcesWrapperElementV110, } from './common-cartridge-resources-wrapper-element'; export type CommonCartridgeElementProps = - | CommonCartridgeMetadataElementProps - | CommonCartridgeOrganizationElementProps - | CommonCartridgeOrganizationsWrapperElementProps - | CommonCartridgeResourcesWrapperElementProps; + | CommonCartridgeMetadataElementPropsV110 + | CommonCartridgeOrganizationElementPropsV110 + | CommonCartridgeOrganizationsWrapperElementPropsV110 + | CommonCartridgeResourcesWrapperElementPropsV110; export class CommonCartridgeElementFactoryV110 extends CommonCartridgeElementFactory { public static readonly instance = new CommonCartridgeElementFactoryV110(); @@ -38,13 +38,13 @@ export class CommonCartridgeElementFactoryV110 extends CommonCartridgeElementFac switch (type) { // AI next 8 lines case CommonCartridgeElementType.METADATA: - return new CommonCartridgeMetadataElement(props); + return new CommonCartridgeMetadataElementV110(props); case CommonCartridgeElementType.ORGANIZATION: - return new CommonCartridgeOrganizationElement(props); + return new CommonCartridgeOrganizationElementV110(props); case CommonCartridgeElementType.ORGANIZATIONS_WRAPPER: - return new CommonCartridgeOrganizationsWrapperElement(props); + return new CommonCartridgeOrganizationsWrapperElementV110(props); case CommonCartridgeElementType.RESOURCES_WRAPPER: - return new CommonCartridgeResourcesWrapperElement(props); + return new CommonCartridgeResourcesWrapperElementV110(props); default: throw createElementTypeNotSupportedError(type); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts index 414d9653b8c..e9a97652f9d 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts @@ -1,7 +1,7 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; -export type CommonCartridgeMetadataElementProps = { +export type CommonCartridgeMetadataElementPropsV110 = { type: CommonCartridgeElementType.METADATA; version: CommonCartridgeVersion; title: string; @@ -9,8 +9,8 @@ export type CommonCartridgeMetadataElementProps = { copyrightOwners: string[]; }; -export class CommonCartridgeMetadataElement extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeMetadataElementProps) { +export class CommonCartridgeMetadataElementV110 extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeMetadataElementPropsV110) { super(props); } @@ -20,7 +20,7 @@ export class CommonCartridgeMetadataElement extends CommonCartridgeElement { public override getManifestXmlObject(): Record { return { - schema: '1EdTech Common Cartridge', + schema: 'IMS Common Cartridge', schemaversion: '1.1.0', 'mnf:lom': { 'mnf:general': { diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts index cf5bf579117..cfd26a48c07 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts @@ -1,7 +1,7 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; -export type CommonCartridgeOrganizationElementProps = { +export type CommonCartridgeOrganizationElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATION; version: CommonCartridgeVersion; identifier: string; @@ -9,8 +9,8 @@ export type CommonCartridgeOrganizationElementProps = { items: CommonCartridgeElement[]; }; -export class CommonCartridgeOrganizationElement extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeOrganizationElementProps) { +export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeOrganizationElementPropsV110) { super(props); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts index 714918d581a..6b896899176 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts @@ -1,14 +1,14 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; -export type CommonCartridgeOrganizationsWrapperElementProps = { +export type CommonCartridgeOrganizationsWrapperElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; version: CommonCartridgeVersion; items: CommonCartridgeElement[]; }; -export class CommonCartridgeOrganizationsWrapperElement extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementProps) { +export class CommonCartridgeOrganizationsWrapperElementV110 extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementPropsV110) { super(props); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts index eeca33badfd..75ae6086f66 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts @@ -1,14 +1,14 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; -export type CommonCartridgeResourcesWrapperElementProps = { +export type CommonCartridgeResourcesWrapperElementPropsV110 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER; version: CommonCartridgeVersion; items: CommonCartridgeElement[]; }; -export class CommonCartridgeResourcesWrapperElement extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeResourcesWrapperElementProps) { +export class CommonCartridgeResourcesWrapperElementV110 extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeResourcesWrapperElementPropsV110) { super(props); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts index eb7aef109cd..d76ad56c095 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts @@ -3,27 +3,27 @@ import { CommonCartridgeElementFactory } from '../../interfaces/common-cartridge import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { createElementTypeNotSupportedError } from '../../utils'; import { - CommonCartridgeMetadataElement, - CommonCartridgeMetadataElementProps, + CommonCartridgeMetadataElementPropsV130, + CommonCartridgeMetadataElementV130, } from './common-cartridge-metadata-element'; import { - CommonCartridgeOrganizationElement, - CommonCartridgeOrganizationElementProps, + CommonCartridgeOrganizationElementPropsV130, + CommonCartridgeOrganizationElementV130, } from './common-cartridge-organization-element'; import { - CommonCartridgeOrganizationsWrapperElement, - CommonCartridgeOrganizationsWrapperElementProps, + CommonCartridgeOrganizationsWrapperElementPropsV130, + CommonCartridgeOrganizationsWrapperElementV130, } from './common-cartridge-organizations-wrapper-element'; import { - CommonCartridgeResourcesWrapperElement, - CommonCartridgeResourcesWrapperElementProps, + CommonCartridgeResourcesWrapperElementPropsV130, + CommonCartridgeResourcesWrapperElementV130, } from './common-cartridge-resources-wrapper-element'; export type CommonCartridgeElementProps = - | CommonCartridgeMetadataElementProps - | CommonCartridgeOrganizationElementProps - | CommonCartridgeOrganizationsWrapperElementProps - | CommonCartridgeResourcesWrapperElementProps; + | CommonCartridgeMetadataElementPropsV130 + | CommonCartridgeOrganizationElementPropsV130 + | CommonCartridgeOrganizationsWrapperElementPropsV130 + | CommonCartridgeResourcesWrapperElementPropsV130; export class CommonCartridgeElementFactoryV130 extends CommonCartridgeElementFactory { public static readonly instance = new CommonCartridgeElementFactoryV130(); @@ -38,13 +38,13 @@ export class CommonCartridgeElementFactoryV130 extends CommonCartridgeElementFac switch (type) { // AI next 8 lines case CommonCartridgeElementType.METADATA: - return new CommonCartridgeMetadataElement(props); + return new CommonCartridgeMetadataElementV130(props); case CommonCartridgeElementType.ORGANIZATION: - return new CommonCartridgeOrganizationElement(props); + return new CommonCartridgeOrganizationElementV130(props); case CommonCartridgeElementType.ORGANIZATIONS_WRAPPER: - return new CommonCartridgeOrganizationsWrapperElement(props); + return new CommonCartridgeOrganizationsWrapperElementV130(props); case CommonCartridgeElementType.RESOURCES_WRAPPER: - return new CommonCartridgeResourcesWrapperElement(props); + return new CommonCartridgeResourcesWrapperElementV130(props); default: throw createElementTypeNotSupportedError(type); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts index 42499b2f91e..e403fa8417f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts @@ -1,7 +1,7 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; -export type CommonCartridgeMetadataElementProps = { +export type CommonCartridgeMetadataElementPropsV130 = { type: CommonCartridgeElementType.METADATA; version: CommonCartridgeVersion; title: string; @@ -9,8 +9,8 @@ export type CommonCartridgeMetadataElementProps = { copyrightOwners: string[]; }; -export class CommonCartridgeMetadataElement extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeMetadataElementProps) { +export class CommonCartridgeMetadataElementV130 extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeMetadataElementPropsV130) { super(props); } @@ -20,7 +20,7 @@ export class CommonCartridgeMetadataElement extends CommonCartridgeElement { public override getManifestXmlObject(): Record { return { - schema: '1EdTech Common Cartridge', + schema: 'IMS Common Cartridge', schemaversion: '1.3.0', 'mnf:lom': { 'mnf:general': { diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts index e806656e8ea..94941a2575a 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts @@ -1,7 +1,7 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; -export type CommonCartridgeOrganizationElementProps = { +export type CommonCartridgeOrganizationElementPropsV130 = { type: CommonCartridgeElementType.ORGANIZATION; version: CommonCartridgeVersion; identifier: string; @@ -9,8 +9,8 @@ export type CommonCartridgeOrganizationElementProps = { items: CommonCartridgeElement[]; }; -export class CommonCartridgeOrganizationElement extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeOrganizationElementProps) { +export class CommonCartridgeOrganizationElementV130 extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeOrganizationElementPropsV130) { super(props); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts index a25a2d2955a..9d753cff40d 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts @@ -1,14 +1,14 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; -export type CommonCartridgeOrganizationsWrapperElementProps = { +export type CommonCartridgeOrganizationsWrapperElementPropsV130 = { type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; version: CommonCartridgeVersion; items: CommonCartridgeElement[]; }; -export class CommonCartridgeOrganizationsWrapperElement extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementProps) { +export class CommonCartridgeOrganizationsWrapperElementV130 extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementPropsV130) { super(props); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts index 9bfaa4192a0..de31ddf5e11 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts @@ -1,14 +1,14 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; -export type CommonCartridgeResourcesWrapperElementProps = { +export type CommonCartridgeResourcesWrapperElementPropsV130 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER; version: CommonCartridgeVersion; items: CommonCartridgeElement[]; }; -export class CommonCartridgeResourcesWrapperElement extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeResourcesWrapperElementProps) { +export class CommonCartridgeResourcesWrapperElementV130 extends CommonCartridgeElement { + public constructor(private readonly props: CommonCartridgeResourcesWrapperElementPropsV130) { super(props); } From a933e09dfb7cf8c0ac63ab8e514b76e97cf12958 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 8 Dec 2023 15:40:48 +0100 Subject: [PATCH 066/177] EW-539 Add tests for metadata and organization elements --- .../common-cartridge-metadata-element.spec.ts | 62 +++++++++++++++++++ ...mon-cartridge-organization-element.spec.ts | 46 ++++++++++++++ .../common-cartridge-metadata-element.spec.ts | 61 ++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts new file mode 100644 index 00000000000..896d30ac116 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts @@ -0,0 +1,62 @@ +import { faker } from '@faker-js/faker'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { + CommonCartridgeMetadataElementPropsV110, + CommonCartridgeMetadataElementV110, +} from './common-cartridge-metadata-element'; + +describe('CommonCartridgeMetadataElementV110', () => { + const setup = () => { + const props: CommonCartridgeMetadataElementPropsV110 = { + type: CommonCartridgeElementType.METADATA, + version: CommonCartridgeVersion.V_1_1_0, + title: faker.lorem.words(), + creationDate: faker.date.past(), + copyrightOwners: [faker.person.fullName(), faker.person.fullName()], + }; + const sut = new CommonCartridgeMetadataElementV110(props); + + return { sut, props }; + }; + + describe('getSupportedVersion', () => { + describe('when using Common Cartridge version 1.1.0', () => { + // AI next 5 lines + it('should return correct version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_1_0); + }); + }); + }); + + describe('getManifestXmlObject', () => { + describe('when using common cartridge version 1.1', () => { + it('should return correct manifest xml object', () => { + const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toStrictEqual({ + schema: 'IMS Common Cartridge', + schemaversion: '1.1.0', + 'mnf:lom': { + 'mnf:general': { + 'mnf:title': { + 'mnf:string': props.title, + }, + }, + 'mnf:rights': { + 'mnf:copyrightAndOtherRestrictions': { + 'mnf:value': 'yes', + }, + 'mnf:description': { + 'mnf:string': `${props.creationDate.getFullYear()} ${props.copyrightOwners.join(', ')}`, + }, + }, + }, + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts new file mode 100644 index 00000000000..7fcfd8d932f --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts @@ -0,0 +1,46 @@ +import { faker } from '@faker-js/faker'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { + CommonCartridgeOrganizationElementPropsV110, + CommonCartridgeOrganizationElementV110, +} from './common-cartridge-organization-element'; + +describe('CommonCartridgeOrganizationElementV110', () => { + const setup = () => { + const item: CommonCartridgeElement = { + getManifestXmlObject: () => { + return { + $: { + identifier: faker.string.uuid(), + }, + title: faker.lorem.words(), + }; + }, + getSupportedVersion: () => CommonCartridgeVersion.V_1_1_0, + checkVersion: () => CommonCartridgeVersion.V_1_1_0, + }; + + const props: CommonCartridgeOrganizationElementPropsV110 = { + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + items: [item], + }; + const sut = new CommonCartridgeOrganizationElementV110(props); + + return { sut, props }; + }; + + describe('getSupportedVersion', () => { + describe('when using common cartridge version 1.1.0', () => { + it('should return correct version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_1_0); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts new file mode 100644 index 00000000000..3bbe6d40802 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts @@ -0,0 +1,61 @@ +import { faker } from '@faker-js/faker'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { + CommonCartridgeMetadataElementPropsV130, + CommonCartridgeMetadataElementV130, +} from './common-cartridge-metadata-element'; + +describe('CommonCartridgeMetadataElementV130', () => { + const setup = () => { + const props: CommonCartridgeMetadataElementPropsV130 = { + type: CommonCartridgeElementType.METADATA, + version: CommonCartridgeVersion.V_1_3_0, + title: faker.lorem.words(), + creationDate: faker.date.past(), + copyrightOwners: [faker.person.fullName(), faker.person.fullName()], + }; + const sut = new CommonCartridgeMetadataElementV130(props); + + return { sut, props }; + }; + + describe('getSupportedVersion', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return correct version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_3_0); + }); + }); + }); + + describe('getManifestXmlObject', () => { + describe('when using common cartridge version 1.3', () => { + it('should return correct manifest xml object', () => { + const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toStrictEqual({ + schema: 'IMS Common Cartridge', + schemaversion: '1.3.0', + 'mnf:lom': { + 'mnf:general': { + 'mnf:title': { + 'mnf:string': props.title, + }, + }, + 'mnf:rights': { + 'mnf:copyrightAndOtherRestrictions': { + 'mnf:value': 'yes', + }, + 'mnf:description': { + 'mnf:string': `${props.creationDate.getFullYear()} ${props.copyrightOwners.join(', ')}`, + }, + }, + }, + }); + }); + }); + }); +}); From 641a9fc16aef7552bd34fda41fb57ee078a789b8 Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 11 Dec 2023 08:20:01 +0100 Subject: [PATCH 067/177] EW-539 working on Common Cartridge v1.1.0 --- ...mon-cartridge-web-content-resource.spec.ts | 87 +++++++++++++++++++ .../common-cartridge-web-content-resource.ts | 5 +- ...common-cartridge-web-link-resource.spec.ts | 64 +++----------- .../common-cartridge-web-link-resource.ts | 8 +- .../learnroom/common-cartridge/utils.ts | 2 +- 5 files changed, 109 insertions(+), 57 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts new file mode 100644 index 00000000000..d3770b677b7 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts @@ -0,0 +1,87 @@ +import { faker } from '@faker-js/faker'; +import { + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { + CommonCartridgeWebContentResourcePropsV110, + CommonCartridgeWebContentResourceV110, +} from './common-cartridge-web-content-resource'; + +describe('CommonCartridgeWebContentResourceV110', () => { + const setup = () => { + const props: CommonCartridgeWebContentResourcePropsV110 = { + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + folder: faker.string.uuid(), + title: faker.lorem.words(), + html: faker.lorem.paragraph(), + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }; + const sut = new CommonCartridgeWebContentResourceV110(props); + + return { sut, props }; + }; + + describe('canInline', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return false', () => { + const { sut } = setup(); + const result = sut.canInline(); + + expect(result).toBe(false); + }); + }); + }); + + describe('getFilePath', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return the constructed file path', () => { + const { sut, props } = setup(); + const result = sut.getFilePath(); + + expect(result).toBe(`${props.folder}/${props.identifier}.html`); + }); + }); + }); + + describe('getFileContent', () => { + it('should return the HTML', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toBe(props.html); + }); + }); + + describe('getSupportedVersion', () => { + it('should return Common Cartridge version 1.1.0', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_1_0); + }); + }); + + describe('getManifestXmlObject', () => { + it('should return the correct XML object', () => { + const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toEqual({ + $: { + identifier: props.identifier, + type: 'webcontent', + intendeduse: props.intendedUse, + }, + file: { + $: { + href: sut.getFilePath(), + }, + }, + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts index b56d84ca7c3..dee829ee363 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -12,7 +12,10 @@ export type CommonCartridgeWebContentResourcePropsV110 = { folder: string; title: string; html: string; - intendedUse: CommonCartridgeIntendedUseType; + intendedUse: + | CommonCartridgeIntendedUseType.UNSPECIFIED + | CommonCartridgeIntendedUseType.LESSON_PLAN + | CommonCartridgeIntendedUseType.SYLLABUS; }; export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResource { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts index ff228c3b0ef..75242e61bac 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -14,6 +14,8 @@ describe('CommonCartridgeWebLinkResourceV110', () => { folder: faker.string.uuid(), title: faker.lorem.words(), url: faker.internet.url(), + target: faker.lorem.word(), + windowFeatures: faker.lorem.words(), }; const sut = new CommonCartridgeWebLinkResourceV110(props); @@ -43,61 +45,19 @@ describe('CommonCartridgeWebLinkResourceV110', () => { }); describe('getFileContent', () => { - it('should contain correct XML header', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(''); - }); - - it('should contain correct XML root element', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(''); - }); - - it('should contain correct XML namespace', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain('xmlns="http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1"'); - expect(result).toContain('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'); - expect(result).toContain( - 'xsi:schemaLocation="' + - 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd"' - ); - }); - - it('should contain correct title', () => { + it('should contain correct XML', () => { const { sut, props } = setup(); const result = sut.getFileContent(); - expect(result).toContain(`${props.title}`); - }); - - it('should contain correct url', () => { - const { sut, props } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(` { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(`target="_self"`); - }); - - // Skipping these tests because values are hardcoded in the implementation - it.skip('should contain correct window features', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(`windowFeatures="width=100, height=100"`); + expect(result).toEqual( + '' + + '' + + `${props.title}` + + `` + + '' + ); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts index 7a81f3ae660..1c1997fe3ee 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -9,6 +9,8 @@ export type CommonCartridgeWebLinkResourcePropsV110 = { folder: string; title: string; url: string; + target?: string; + windowFeatures?: string; }; export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource { @@ -37,8 +39,8 @@ export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource url: { $: { href: this.props.url, - target: '_self', - windowFeatures: 'width=100, height=100', + target: this.props.target, + windowFeatures: this.props.windowFeatures, }, }, }, @@ -51,7 +53,7 @@ export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource public getManifestXmlObject(): Record { return { - resoucec: { + resource: { $: { identifier: this.props.identifier, type: 'imswl_xmlv1p1', diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.ts index 9375e639f59..74c2969f55a 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/utils.ts @@ -6,7 +6,7 @@ export type OmitVersion = Omit; export type OmitVersionAndFolder = Omit; -const xmlBuilder = new Builder({ xmldec: { version: '1.0', encoding: 'UTF-8' } }); +const xmlBuilder = new Builder({ xmldec: { version: '1.0', encoding: 'UTF-8' }, renderOpts: { indent: '\t' } }); export function buildXmlString(obj: unknown): string { return xmlBuilder.buildObject(obj); From a9fc4db2d75f199bb96b7d04fc7b7bb4a857d82b Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 11 Dec 2023 09:32:35 +0100 Subject: [PATCH 068/177] EW-539 cleaning up --- .../learnroom/common-cartridge/README.md | 3 ++- .../learnroom/common-cartridge/manifest.xml | 21 ------------------- .../common-cartridge/temp/web_link_1_1.xml | 9 -------- 3 files changed, 2 insertions(+), 31 deletions(-) delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/manifest.xml delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/temp/web_link_1_1.xml diff --git a/apps/server/src/modules/learnroom/common-cartridge/README.md b/apps/server/src/modules/learnroom/common-cartridge/README.md index 1450b786644..23e9ebaaa5c 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/README.md +++ b/apps/server/src/modules/learnroom/common-cartridge/README.md @@ -7,8 +7,9 @@ | Resource Type | XML Namespace | XSD Locations | |:-|:-|:-| | Manifest 1.1.0 || | -| Web Content 1.1.0 || | +| Web Content 1.1.0 | - | - | | Web Link 1.1.0 | http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 | | +| LTI | | | | Manifest 1.3.0 || | | Web Content 1.3.0 || | | Web Link 1.3.0 || | diff --git a/apps/server/src/modules/learnroom/common-cartridge/manifest.xml b/apps/server/src/modules/learnroom/common-cartridge/manifest.xml deleted file mode 100644 index f48382c8334..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/manifest.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - IMS Common Cartridge - 1.1.0 - - - - - - - Org 1 - - - - - - - - - diff --git a/apps/server/src/modules/learnroom/common-cartridge/temp/web_link_1_1.xml b/apps/server/src/modules/learnroom/common-cartridge/temp/web_link_1_1.xml deleted file mode 100644 index ae4c28d6429..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/temp/web_link_1_1.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - Web Link - - \ No newline at end of file From 2337b6e533062d992e26faad3ad6ee2b0d1f179b Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 11 Dec 2023 10:16:11 +0100 Subject: [PATCH 069/177] EW-539 Add todos --- TODO.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/TODO.md b/TODO.md index 5d0bfca2d2d..76c0802ff6e 100644 --- a/TODO.md +++ b/TODO.md @@ -93,5 +93,9 @@ ### EW-539 - tests for CCManifestResource +- Check test coverage - Cleanup FIXMEs - Manual tests +- createIdentifier method +- merge main +- review.md and comments From b1a07e3a305720bdd199e569aeb8f50e42aa5e15 Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 11 Dec 2023 10:21:16 +0100 Subject: [PATCH 070/177] EW-539 removing unused code --- .../common-cartridge.enums.ts | 1 - .../common-cartridge-lti-resource.spec.ts | 146 ------------------ .../common-cartridge-lti-resource.ts | 93 ----------- .../common-cartridge-resource-factory.spec.ts | 18 --- .../common-cartridge-resource-factory.ts | 5 - ...n-cartridge-resource-props-test-factory.ts | 40 ----- .../common-cartridge-lti-resource.spec.ts | 132 ---------------- .../v1.1.0/common-cartridge-lti-resource.ts | 79 ---------- .../common-cartridge-resource-factory.ts | 4 - .../common-cartridge-lti-resource.spec.ts | 132 ---------------- .../v1.3.0/common-cartridge-lti-resource.ts | 79 ---------- .../common-cartridge-resource-factory.ts | 4 - 12 files changed, 733 deletions(-) delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-props-test-factory.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts index 69f4379b50f..be91e8a9f53 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts @@ -10,7 +10,6 @@ export enum CommonCartridgeVersion { export enum CommonCartridgeResourceType { UNKNOWN = 'unknown', - LTI = 'lti', MANIFEST = 'manifest', WEB_CONTENT = 'webcontent', WEB_LINK = 'weblink', diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts deleted file mode 100644 index d06c67b2a22..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.spec.ts +++ /dev/null @@ -1,146 +0,0 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeLtiResource, CommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; - -describe('CommonCartridgeLtiResource', () => { - const propsVersion1: CommonCartridgeLtiResourceProps = { - type: CommonCartridgeResourceType.LTI, - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'lti-identifier-version1', - folder: 'lti-identifier-version1', - title: 'lti-title-version1', - description: 'lti-description-version1', - url: 'https://to-a-lti-tool-version1.tld', - }; - - const propsVersion3: CommonCartridgeLtiResourceProps = { - type: CommonCartridgeResourceType.LTI, - version: CommonCartridgeVersion.V_1_3_0, - identifier: 'lti-identifier-version3', - folder: 'lti-identifier-version3', - title: 'lti-title-version3', - description: 'lti-description-version3', - url: 'https://to-a-lti-tool-version3.tld', - }; - - const ltiResourceVersion1 = new CommonCartridgeLtiResource(propsVersion1); - const ltiResourceVersion3 = new CommonCartridgeLtiResource(propsVersion3); - - describe('canInline', () => { - describe('when common cartridge version 1.1', () => { - it('should return false', () => { - const resultVersion1 = ltiResourceVersion1.canInline(); - expect(resultVersion1).toBe(false); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return false', () => { - const resultVersion3 = ltiResourceVersion3.canInline(); - expect(resultVersion3).toBe(false); - }); - }); - }); - - describe('getFilePath', () => { - describe('when common cartridge version 1.1', () => { - it('should return the file path regarding version 1.1', () => { - const filePathVersion1 = ltiResourceVersion1.getFilePath(); - expect(filePathVersion1).toBe(`${propsVersion1.folder}/${propsVersion1.identifier}.xml`); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return the file path regarding version 1.3', () => { - const filePathVersion3 = ltiResourceVersion3.getFilePath(); - expect(filePathVersion3).toBe(`${propsVersion3.folder}/${propsVersion3.identifier}.xml`); - }); - }); - }); - - describe('getFileContent', () => { - describe('when Common Cartridge version 1.1', () => { - it('should return correct XML content for version 1.1', () => { - const content = ltiResourceVersion1.getFileContent(); - - expect(content).toContain('cartridge_basiclti_link'); - expect(content).toContain('/xsd/imslticc_v1p0'); - expect(content).toContain('/xsd/imsbasiclti_v1p0'); - expect(content).toContain('/xsd/imslticm_v1p0'); - expect(content).toContain('/xsd/imslticp_v1p0'); - expect(content).toContain( - '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd' + - '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd' + - '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd' + - '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd' - ); - }); - }); - - describe('when Common Cartridge version 1.3', () => { - it('should return correct XML content for version 1.3', () => { - const content = ltiResourceVersion3.getFileContent(); - - expect(content).toContain('cartridge_basiclti_link'); - expect(content).toContain('http://www.imsglobal.org/xsd/imslticc_v1p3'); - expect(content).toContain('http://www.imsglobal.org/xsd/imsbasiclti_v1p0'); - expect(content).toContain('http://www.imsglobal.org/xsd/imslticm_v1p0'); - expect(content).toContain('http://www.imsglobal.org/xsd/imslticp_v1p0'); - expect(content).toContain( - 'http://www.imsglobal.org/xsd/imslticc_v1p3 http://www.imsglobal.org/xsd/imslticc_v1p3.xsd' + - 'http://www.imsglobal.org/xsd/imslticp_v1p0 imslticp_v1p0.xsd' + - 'http://www.imsglobal.org/xsd/imslticm_v1p0 imslticm_v1p0.xsd' + - 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0 imsbasiclti_v1p0p1.xsd' - ); - }); - }); - - describe('when version is not supported', () => { - it('should throw an error', () => { - const ltiResource = new CommonCartridgeLtiResource({ - ...propsVersion1, - version: 'xxx' as CommonCartridgeVersion, - }); - - expect(() => ltiResource.getFileContent()).toThrowError('Version xxx is not supported'); - }); - }); - }); - - describe('getManifestXml', () => { - describe('when common cartridge version 1.1', () => { - it('should return manifest xml content regarding version 1.1', () => { - const transformed = ltiResourceVersion1.getManifestXmlObject(); - - expect(transformed).toEqual({ - $: { - identifier: propsVersion1.identifier, - type: propsVersion1.type, - }, - file: { - $: { - href: propsVersion1.folder, - }, - }, - }); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return manifest xml content regarding version 1.3', () => { - const transformed = ltiResourceVersion3.getManifestXmlObject(); - - expect(transformed).toEqual({ - $: { - identifier: propsVersion3.identifier, - type: propsVersion3.type, - }, - file: { - $: { - href: propsVersion3.folder, - }, - }, - }); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts deleted file mode 100644 index 41808f35ec1..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-lti-resource.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { buildXmlString, createVersionNotSupportedError } from '../utils'; - -export type CommonCartridgeLtiResourceProps = { - type: CommonCartridgeResourceType.LTI; - version: CommonCartridgeVersion; - identifier: string; - folder: string; - title: string; - description?: string; - url: string; -}; - -export class CommonCartridgeLtiResource { - constructor(private readonly props: CommonCartridgeLtiResourceProps) {} - - public canInline(): boolean { - return false; - } - - public getFilePath(): string { - return `${this.props.folder}/${this.props.identifier}.xml`; - } - - public getFileContent(): string { - return buildXmlString({ - cartridge_basiclti_link: { - $: this.getXmlNamespacesByVersion(), - blti: { - title: this.props.title, - description: this.props.description, - launch_url: this.props.url, - secure_launch_url: this.props.url, - cartridge_bundle: { - $: { - identifierref: 'BLTI001_Bundle', - }, - }, - cartridge_icon: { - $: { - identifierref: 'BLTI001_Icon', - }, - }, - }, - }, - }); - } - - public getManifestXmlObject(): Record { - return { - $: { - identifier: this.props.identifier, - type: this.props.type, - }, - file: { - $: { - href: this.getFilePath(), - }, - }, - }; - } - - private getXmlNamespacesByVersion(): Record { - switch (this.props.version) { - case CommonCartridgeVersion.V_1_1_0: - return { - xmlns: '/xsd/imslticc_v1p0', - 'xmlns:blti': '/xsd/imsbasiclti_v1p0', - 'xmlns:lticm': '/xsd/imslticm_v1p0', - 'xmlns:lticp': '/xsd/imslticp_v1p0', - 'xsi:schemaLocation': - '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd' + - '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd' + - '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd' + - '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd"', - }; - case CommonCartridgeVersion.V_1_3_0: - return { - xmlns: 'http://www.imsglobal.org/xsd/imslticc_v1p3', - 'xmlns:blti': 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0', - 'xmlns:lticm': 'http://www.imsglobal.org/xsd/imslticm_v1p0', - 'xmlns:lticp': 'http://www.imsglobal.org/xsd/imslticp_v1p0', - 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imslticc_v1p3 http://www.imsglobal.org/xsd/imslticc_v1p3.xsd' + - 'http://www.imsglobal.org/xsd/imslticp_v1p0 imslticp_v1p0.xsd' + - 'http://www.imsglobal.org/xsd/imslticm_v1p0 imslticm_v1p0.xsd' + - 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0 imsbasiclti_v1p0p1.xsd"', - }; - default: - throw createVersionNotSupportedError(this.props.version); - } - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts index bf9aecaab60..51b9908aa7c 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts @@ -1,5 +1,4 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeLtiResource } from './common-cartridge-lti-resource'; import { CommonCartridgeResourceFactory, CommonCartridgeResourceProps } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResource } from './common-cartridge-web-content-resource'; import { CommonCartridgeWebLinkResource } from './common-cartridge-web-link-resource'; @@ -8,23 +7,6 @@ describe('CommonCartridgeResourceFactory', () => { const versionAndFolderProps = { version: CommonCartridgeVersion.V_1_1_0, folder: 'folder' }; describe('create', () => { - // AI next 14 lines - describe('when creating a lti resource', () => { - it('should return a lti resource', () => { - const props: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.LTI, - identifier: 'lti-identifier', - title: 'title', - description: 'description', - url: 'url', - }; - - const resource = CommonCartridgeResourceFactory.create({ ...props, ...versionAndFolderProps }); - - expect(resource).toBeInstanceOf(CommonCartridgeLtiResource); - }); - }); - // AI next 13 lines describe('when creating a web content resource', () => { it('should return a web content resource', () => { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts index 6a00f29c64e..f1ddc77e741 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts @@ -1,7 +1,6 @@ import { CommonCartridgeResourceType } from '../common-cartridge.enums'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { OmitVersionAndFolder } from '../utils'; -import { CommonCartridgeLtiResource, CommonCartridgeLtiResourceProps } from './common-cartridge-lti-resource'; import { CommonCartridgeWebContentResource, CommonCartridgeWebContentResourceProps, @@ -12,20 +11,16 @@ import { } from './common-cartridge-web-link-resource'; export type CommonCartridgeResourceProps = - | OmitVersionAndFolder | OmitVersionAndFolder | OmitVersionAndFolder; type CommonCartridgeResourcePropsInternal = - | CommonCartridgeLtiResourceProps | CommonCartridgeWebContentResourceProps | CommonCartridgeWebLinkResourceProps; export class CommonCartridgeResourceFactory { static create(props: CommonCartridgeResourcePropsInternal): CommonCartridgeResource { switch (props.type) { - case CommonCartridgeResourceType.LTI: - return new CommonCartridgeLtiResource(props); case CommonCartridgeResourceType.WEB_CONTENT: return new CommonCartridgeWebContentResource(props); case CommonCartridgeResourceType.WEB_LINK: diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-props-test-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-props-test-factory.ts deleted file mode 100644 index cf8b03abdfb..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-props-test-factory.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { InternalServerErrorException } from '@nestjs/common'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeResourceProps } from './common-cartridge-resource-factory'; - -export class CommonCartridgeResourcePropsFactory { - static create(): CommonCartridgeResourceProps { - switch (props.type) { - case CommonCartridgeResourceType.LTI: - return { - type: CommonCartridgeResourceType.LTI, - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'lti-resource-props-identifier', - folder: 'lti-resource-props-folder', - title: 'lti-resource-props-title', - description: 'lti-resource-props-description', - url: 'lti-resource-props-url', - }; - case CommonCartridgeResourceType.WEB_CONTENT: - return { - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'web-content-resource-props-identifier', - folder: 'web-content-resource-props-folder', - title: 'web-content-resource-resource-title', - html: '

web-content-resource-props-html

', - }; - case CommonCartridgeResourceType.WEB_LINK: - return { - type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'web-link-resource-props-identifier', - folder: 'web-link-resource-props-folder', - title: 'web-link-resource-props-title', - url: 'web-link-resource-props-url', - }; - default: - throw new InternalServerErrorException(`Unknown Common Cartridge resource props`); - } - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.spec.ts deleted file mode 100644 index f6308bb7018..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.spec.ts +++ /dev/null @@ -1,132 +0,0 @@ -import { faker } from '@faker-js/faker'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeLtiResourcePropsV110, CommonCartridgeLtiResourceV110 } from './common-cartridge-lti-resource'; - -describe('CommonCartridgeLtiResourceV110', () => { - const setup = () => { - const props: CommonCartridgeLtiResourcePropsV110 = { - type: CommonCartridgeResourceType.LTI, - version: CommonCartridgeVersion.V_1_1_0, - identifier: faker.string.uuid(), - folder: faker.string.uuid(), - title: faker.lorem.words(), - description: faker.lorem.sentence(), - url: faker.internet.url(), - }; - const sut = new CommonCartridgeLtiResourceV110(props); - - return { sut, props }; - }; - - describe('canInline', () => { - describe('when using Common Cartridge version 1.1.0', () => { - it('should return false', () => { - const { sut } = setup(); - const result = sut.canInline(); - - expect(result).toBe(false); - }); - }); - }); - - describe('getFilePath', () => { - describe('when using Common Cartridge version 1.1.0', () => { - it('should return the constructed file path', () => { - const { sut, props } = setup(); - const result = sut.getFilePath(); - - expect(result).toBe(`${props.folder}/${props.identifier}.xml`); - }); - }); - }); - - describe('getFileContent', () => { - describe('when using Common Cartridge version 1.1.0', () => { - it('should contain correct XML root element', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(''); - }); - - it('should contain correct XML namespace', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain('xmlns="/xsd/imslticc_v1p0"'); - expect(result).toContain('xmlns:blti="/xsd/imsbasiclti_v1p0"'); - expect(result).toContain('xmlns:lticm="/xsd/imslticm_v1p0"'); - expect(result).toContain('xmlns:lticp="/xsd/imslticp_v1p0"'); - }); - - it('should contain correct XML schema', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain( - 'xsi:schemaLocation="' + - '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd ' + - '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd ' + - '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd ' + - '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd"' - ); - }); - - it('should contain correct XML title', () => { - const { sut, props } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(`${props.title}`); - }); - - it('should contain correct XML description', () => { - const { sut, props } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(`${props.description}`); - }); - - it('should contain correct XML url', () => { - const { sut, props } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(`${props.url}`); - expect(result).toContain(`${props.url}`); - }); - }); - }); - - // AI next 10 lines - describe('getSupportedVersion', () => { - describe('when using Common Cartridge version 1.1.0', () => { - it('should return correct version', () => { - const { sut } = setup(); - const result = sut.getSupportedVersion(); - - expect(result).toBe(CommonCartridgeVersion.V_1_1_0); - }); - }); - }); - - describe('getManifestXml', () => { - describe('when using Common Cartridge version 1.1.0', () => { - it('should return manifest xml object', () => { - const { sut, props } = setup(); - const result = sut.getManifestXmlObject(); - - expect(result).toEqual({ - $: { - identifier: props.identifier, - type: props.type, - }, - file: { - $: { - href: `${props.folder}/${props.identifier}.xml`, - }, - }, - }); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.ts deleted file mode 100644 index c43c2b27a73..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-lti-resource.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; -import { buildXmlString } from '../../utils'; - -export type CommonCartridgeLtiResourcePropsV110 = { - type: CommonCartridgeResourceType.LTI; - version: CommonCartridgeVersion.V_1_1_0; - identifier: string; - folder: string; - title: string; - description: string; - url: string; -}; - -export class CommonCartridgeLtiResourceV110 extends CommonCartridgeResource { - public constructor(private readonly props: CommonCartridgeLtiResourcePropsV110) { - super(props); - } - - public override canInline(): boolean { - return false; - } - - public override getFilePath(): string { - return `${this.props.folder}/${this.props.identifier}.xml`; - } - - public override getFileContent(): string { - return buildXmlString({ - cartridge_basiclti_link: { - $: { - xmlns: '/xsd/imslticc_v1p0', - 'xmlns:blti': '/xsd/imsbasiclti_v1p0', - 'xmlns:lticm': '/xsd/imslticm_v1p0', - 'xmlns:lticp': '/xsd/imslticp_v1p0', - 'xsi:schemaLocation': - '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd ' + - '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd ' + - '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd ' + - '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd', - }, - blti: { - title: this.props.title, - description: this.props.description, - launch_url: this.props.url, - secure_launch_url: this.props.url, - cartridge_bundle: { - $: { - identifierref: 'BLTI001_Bundle', - }, - }, - cartridge_icon: { - $: { - identifierref: 'BLTI001_Icon', - }, - }, - }, - }, - }); - } - - public override getSupportedVersion(): CommonCartridgeVersion { - return CommonCartridgeVersion.V_1_1_0; - } - - public override getManifestXmlObject(): Record { - return { - $: { - identifier: this.props.identifier, - type: this.props.type, - }, - file: { - $: { - href: this.getFilePath(), - }, - }, - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts index 2d113378fb3..3eeb280ac9b 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts @@ -2,7 +2,6 @@ import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../../interfaces/common-cartridge-resource-factory.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; import { createResourceTypeNotSupportedError } from '../../utils'; -import { CommonCartridgeLtiResourcePropsV110, CommonCartridgeLtiResourceV110 } from './common-cartridge-lti-resource'; import { CommonCartridgeManifestResourcePropsV110, CommonCartridgeManifestResourceV110, @@ -17,7 +16,6 @@ import { } from './common-cartridge-web-link-resource'; export type CommonCartridgeResourcePropsV110 = - | CommonCartridgeLtiResourcePropsV110 | CommonCartridgeManifestResourcePropsV110 | CommonCartridgeWebContentResourcePropsV110 | CommonCartridgeWebLinkResourcePropsV110; @@ -33,8 +31,6 @@ export class CommonCartridgeResourceFactoryV110 extends CommonCartridgeResourceF const { type } = props; switch (type) { - case CommonCartridgeResourceType.LTI: - return new CommonCartridgeLtiResourceV110(props); case CommonCartridgeResourceType.MANIFEST: return new CommonCartridgeManifestResourceV110(props); case CommonCartridgeResourceType.WEB_CONTENT: diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.spec.ts deleted file mode 100644 index 10f5e57d29b..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.spec.ts +++ /dev/null @@ -1,132 +0,0 @@ -import { faker } from '@faker-js/faker'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeLtiResourcePropsV130, CommonCartridgeLtiResourceV130 } from './common-cartridge-lti-resource'; - -describe('CommonCartridgeLtiResourcePropsV130', () => { - const setup = () => { - const props: CommonCartridgeLtiResourcePropsV130 = { - type: CommonCartridgeResourceType.LTI, - version: CommonCartridgeVersion.V_1_3_0, - identifier: faker.string.uuid(), - folder: faker.string.uuid(), - title: faker.lorem.words(), - description: faker.lorem.sentence(), - url: faker.internet.url(), - }; - const sut = new CommonCartridgeLtiResourceV130(props); - - return { sut, props }; - }; - - describe('canInline', () => { - describe('when using Common Cartridge version 1.3.0', () => { - it('should return false', () => { - const { sut } = setup(); - const result = sut.canInline(); - - expect(result).toBe(false); - }); - }); - }); - - describe('getFilePath', () => { - describe('when using Common Cartridge version 1.3.0', () => { - it('should return the constructed file path', () => { - const { sut, props } = setup(); - const result = sut.getFilePath(); - - expect(result).toBe(`${props.folder}/${props.identifier}.xml`); - }); - }); - }); - - describe('getFileContent', () => { - describe('when using Common Cartridge version 1.3.0', () => { - it('should contain correct XML root element', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(''); - }); - - it('should contain correct XML namespace', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain('xmlns="/xsd/imslticc_v1p0"'); - expect(result).toContain('xmlns:blti="/xsd/imsbasiclti_v1p0"'); - expect(result).toContain('xmlns:lticm="/xsd/imslticm_v1p0"'); - expect(result).toContain('xmlns:lticp="/xsd/imslticp_v1p0"'); - }); - - it('should contain correct XML schema', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain( - 'xsi:schemaLocation="' + - '/xsd/imslticc_v1p0 /xsd/lti/ltiv1p0/imslticc_v1p0.xsd ' + - '/xsd/imsbasiclti_v1p0 /xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd ' + - '/xsd/imslticm_v1p0 /xsd/lti/ltiv1p0/imslticm_v1p0.xsd ' + - '/xsd/imslticp_v1p0 /xsd/lti/ltiv1p0/imslticp_v1p0.xsd"' - ); - }); - - it('should contain correct XML title', () => { - const { sut, props } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(`${props.title}`); - }); - - it('should contain correct XML description', () => { - const { sut, props } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(`${props.description}`); - }); - - it('should contain correct XML url', () => { - const { sut, props } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(`${props.url}`); - expect(result).toContain(`${props.url}`); - }); - }); - }); - - // AI next 10 lines - describe('getSupportedVersion', () => { - describe('when using Common Cartridge version 1.3.0', () => { - it('should return supported version', () => { - const { sut } = setup(); - const result = sut.getSupportedVersion(); - - expect(result).toBe(CommonCartridgeVersion.V_1_3_0); - }); - }); - }); - - describe('getManifestXml', () => { - describe('when using Common Cartridge version 1.3.0', () => { - it('should return manifest xml object', () => { - const { sut, props } = setup(); - const result = sut.getManifestXmlObject(); - - expect(result).toEqual({ - $: { - identifier: props.identifier, - type: props.type, - }, - file: { - $: { - href: `${props.folder}/${props.identifier}.xml`, - }, - }, - }); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.ts deleted file mode 100644 index cf0dafb085f..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-lti-resource.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; -import { buildXmlString } from '../../utils'; - -export type CommonCartridgeLtiResourcePropsV130 = { - type: CommonCartridgeResourceType.LTI; - version: CommonCartridgeVersion.V_1_3_0; - identifier: string; - folder: string; - title: string; - description: string; - url: string; -}; - -export class CommonCartridgeLtiResourceV130 extends CommonCartridgeResource { - public constructor(private readonly props: CommonCartridgeLtiResourcePropsV130) { - super(props); - } - - public override canInline(): boolean { - return false; - } - - public override getFilePath(): string { - return `${this.props.folder}/${this.props.identifier}.xml`; - } - - public override getFileContent(): string { - return buildXmlString({ - cartridge_basiclti_link: { - $: { - xmlns: 'http://www.imsglobal.org/xsd/imslticc_v1p3', - 'xmlns:blti': 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0', - 'xmlns:lticm': 'http://www.imsglobal.org/xsd/imslticm_v1p0', - 'xmlns:lticp': 'http://www.imsglobal.org/xsd/imslticp_v1p0', - 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imslticc_v1p3 http://www.imsglobal.org/xsd/imslticc_v1p3.xsd' + - 'http://www.imsglobal.org/xsd/imslticp_v1p0 imslticp_v1p0.xsd' + - 'http://www.imsglobal.org/xsd/imslticm_v1p0 imslticm_v1p0.xsd' + - 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0 imsbasiclti_v1p0p1.xsd"', - }, - blti: { - title: this.props.title, - description: this.props.description, - launch_url: this.props.url, - secure_launch_url: this.props.url, - cartridge_bundle: { - $: { - identifierref: 'BLTI001_Bundle', // FIXME: is this correct? - }, - }, - cartridge_icon: { - $: { - identifierref: 'BLTI001_Icon', // FIXME: is this correct? - }, - }, - }, - }, - }); - } - - public override getSupportedVersion(): CommonCartridgeVersion { - return CommonCartridgeVersion.V_1_3_0; - } - - public override getManifestXmlObject(): Record { - return { - $: { - identifier: this.props.identifier, - type: this.props.type, // FIXME: is this correct? - }, - file: { - $: { - href: this.getFilePath(), - }, - }, - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts index b87d51b9b84..5afdff19211 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts @@ -2,7 +2,6 @@ import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../../interfaces/common-cartridge-resource-factory.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; import { createResourceTypeNotSupportedError } from '../../utils'; -import { CommonCartridgeLtiResourcePropsV130, CommonCartridgeLtiResourceV130 } from './common-cartridge-lti-resource'; import { CommonCartridgeManifestResourcePropsV130, CommonCartridgeManifestResourceV130, @@ -17,7 +16,6 @@ import { } from './common-cartridge-web-link-resource'; export type CommonCartridgeResourcePropsV130 = - | CommonCartridgeLtiResourcePropsV130 | CommonCartridgeManifestResourcePropsV130 | CommonCartridgeWebContentResourcePropsV130 | CommonCartridgeWebLinkResourcePropsV130; @@ -33,8 +31,6 @@ export class CommonCartridgeResourceFactoryV130 extends CommonCartridgeResourceF const { type } = props; switch (type) { - case CommonCartridgeResourceType.LTI: - return new CommonCartridgeLtiResourceV130(props); case CommonCartridgeResourceType.MANIFEST: return new CommonCartridgeManifestResourceV130(props); case CommonCartridgeResourceType.WEB_CONTENT: From 10f5f3b8a9be7a4d8d70c2254235ee5b313f1c17 Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 11 Dec 2023 10:56:50 +0100 Subject: [PATCH 071/177] Ew-539 working on resource tests --- ...mon-cartridge-web-content-resource.spec.ts | 93 +++++++++++++++++++ ...common-cartridge-web-link-resource.spec.ts | 76 ++++----------- .../common-cartridge-web-link-resource.ts | 8 +- 3 files changed, 116 insertions(+), 61 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts new file mode 100644 index 00000000000..1e1f6af9717 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts @@ -0,0 +1,93 @@ +import { faker } from '@faker-js/faker'; +import { + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { + CommonCartridgeWebContentResourcePropsV130, + CommonCartridgeWebContentResourceV130, +} from './common-cartridge-web-content-resource'; + +describe('CommonCartridgeWebContentResourceV130', () => { + const setup = () => { + const props: CommonCartridgeWebContentResourcePropsV130 = { + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_3_0, + folder: faker.string.uuid(), + identifier: faker.string.uuid(), + title: faker.lorem.words(), + html: faker.lorem.words(), + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }; + const sut = new CommonCartridgeWebContentResourceV130(props); + + return { sut, props }; + }; + + describe('canInline', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return false', () => { + const { sut } = setup(); + const result = sut.canInline(); + + expect(result).toBe(false); + }); + }); + }); + + describe('getFilePath', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return the constructed file path', () => { + const { sut, props } = setup(); + const result = sut.getFilePath(); + + expect(result).toBe(`${props.folder}/${props.identifier}.html`); + }); + }); + }); + + describe('getFileContent', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return the HTML', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toBe(props.html); + }); + }); + }); + + describe('getSupportedVersion', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return the supported version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_3_0); + }); + }); + }); + + describe('getManifestXmlObject', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return the manifest XML object', () => { + const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toEqual({ + $: { + identifier: props.identifier, + type: props.type, + intendeduse: props.intendedUse, + }, + file: { + $: { + href: sut.getFilePath(), + }, + }, + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts index 78807f65729..c5ae3047f2e 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts @@ -14,6 +14,8 @@ describe('CommonCartridgeWebLinkResourceV130', () => { folder: faker.string.uuid(), title: faker.lorem.words(), url: faker.internet.url(), + target: faker.lorem.word(), + windowFeatures: faker.lorem.words(), }; const sut = new CommonCartridgeWebLinkResourceV130(props); @@ -43,63 +45,21 @@ describe('CommonCartridgeWebLinkResourceV130', () => { }); describe('getFileContent', () => { - it('should contain correct XML header', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(''); - }); - - it('should contain correct XML root element', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(''); - }); - - it('should contain correct XML namespace', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain('xmlns="http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1"'); - expect(result).toContain('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'); - expect(result).toContain( - 'xsi:schemaLocation="' + - 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd"' - ); - }); - - it('should contain correct title', () => { - const { sut, props } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(`${props.title}`); - }); - - it('should contain correct url', () => { - const { sut, props } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(` { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(`target="_self"`); - }); - - // FIXME: add to props - // Skipping these tests because values are hardcoded in the implementation - it.skip('should contain correct window features', () => { - const { sut } = setup(); - const result = sut.getFileContent(); - - expect(result).toContain(`windowFeatures="width=100, height=100"`); + describe('when using Common Cartridge version 1.3.0', () => { + it('should return correct XML', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); + + expect(result).toEqual( + '' + + '' + + `${props.title}` + + `` + + '' + ); + }); }); }); @@ -123,7 +83,7 @@ describe('CommonCartridgeWebLinkResourceV130', () => { expect(result).toEqual({ $: { identifier: props.identifier, - type: props.type, + type: 'imswl_xmlv1p3', }, file: { $: { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts index 543e4f61984..82419c59598 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -9,6 +9,8 @@ export type CommonCartridgeWebLinkResourcePropsV130 = { folder: string; title: string; url: string; + target?: string; + windowFeatures?: string; }; export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource { @@ -37,8 +39,8 @@ export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource url: { $: { href: this.props.url, - target: '_self', - windowFeatures: 'width=100, height=100', + target: this.props.target, + windowFeatures: this.props.windowFeatures, }, }, }, @@ -53,7 +55,7 @@ export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource return { $: { identifier: this.props.identifier, - type: 'web', + type: 'imswl_xmlv1p3', }, file: { $: { From 3d6faf0cbea2d63b4e75bce188f9bf532c701d3e Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 11 Dec 2023 11:25:08 +0100 Subject: [PATCH 072/177] EW-539 removing old code --- ...on-cartridge-resource-factory.interface.ts | 8 -- .../common-cartridge-resource-factory.spec.ts | 42 ------ .../common-cartridge-resource-factory.ts | 33 ----- ...mon-cartridge-web-content-resource.spec.ts | 111 --------------- .../common-cartridge-web-content-resource.ts | 49 ------- ...common-cartridge-web-link-resource.spec.ts | 133 ------------------ .../common-cartridge-web-link-resource.ts | 75 ---------- 7 files changed, 451 deletions(-) delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource-factory.interface.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource-factory.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource-factory.interface.ts deleted file mode 100644 index 9d3b670d8d8..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource-factory.interface.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeResource } from './common-cartridge-resource.interface'; - -export type CommonCartridgeResourceProps = { version: CommonCartridgeVersion }; - -export abstract class CommonCartridgeResourceFactory { - abstract createResource(props: CommonCartridgeResourceProps): CommonCartridgeResource; -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts deleted file mode 100644 index 51b9908aa7c..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeResourceFactory, CommonCartridgeResourceProps } from './common-cartridge-resource-factory'; -import { CommonCartridgeWebContentResource } from './common-cartridge-web-content-resource'; -import { CommonCartridgeWebLinkResource } from './common-cartridge-web-link-resource'; - -describe('CommonCartridgeResourceFactory', () => { - const versionAndFolderProps = { version: CommonCartridgeVersion.V_1_1_0, folder: 'folder' }; - - describe('create', () => { - // AI next 13 lines - describe('when creating a web content resource', () => { - it('should return a web content resource', () => { - const props: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: 'web-content-identifier', - title: 'title', - html: 'html', - }; - - const resource = CommonCartridgeResourceFactory.create({ ...props, ...versionAndFolderProps }); - - expect(resource).toBeInstanceOf(CommonCartridgeWebContentResource); - }); - }); - - // AI next 13 lines - describe('when creating a web link resource', () => { - it('should return a web link resource', () => { - const props: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_LINK, - identifier: 'web-link-identifier', - title: 'title', - url: 'url', - }; - - const resource = CommonCartridgeResourceFactory.create({ ...props, ...versionAndFolderProps }); - - expect(resource).toBeInstanceOf(CommonCartridgeWebLinkResource); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts deleted file mode 100644 index f1ddc77e741..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { CommonCartridgeResourceType } from '../common-cartridge.enums'; -import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { OmitVersionAndFolder } from '../utils'; -import { - CommonCartridgeWebContentResource, - CommonCartridgeWebContentResourceProps, -} from './common-cartridge-web-content-resource'; -import { - CommonCartridgeWebLinkResource, - CommonCartridgeWebLinkResourceProps, -} from './common-cartridge-web-link-resource'; - -export type CommonCartridgeResourceProps = - | OmitVersionAndFolder - | OmitVersionAndFolder; - -type CommonCartridgeResourcePropsInternal = - | CommonCartridgeWebContentResourceProps - | CommonCartridgeWebLinkResourceProps; - -export class CommonCartridgeResourceFactory { - static create(props: CommonCartridgeResourcePropsInternal): CommonCartridgeResource { - switch (props.type) { - case CommonCartridgeResourceType.WEB_CONTENT: - return new CommonCartridgeWebContentResource(props); - case CommonCartridgeResourceType.WEB_LINK: - return new CommonCartridgeWebLinkResource(props); - default: - // use InternalServerErrorException - throw new Error(`Unknown Common Cartridge resource type`); - } - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts deleted file mode 100644 index 14bd1d3e91d..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.spec.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { - CommonCartridgeWebContentResource, - CommonCartridgeWebContentResourceProps, -} from './common-cartridge-web-content-resource'; - -describe('CommonCartridgeWebContentResource', () => { - const propsVersion1: CommonCartridgeWebContentResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'web-link-v1', - folder: 'https://example.com/link1', - title: 'Web Link Version 1', - html: 'html tages for testing version 1', - }; - const propsVersion3: CommonCartridgeWebContentResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_3_0, - identifier: 'web-link-v3', - folder: 'https://example.com/link3', - title: 'Web Link Version 3', - html: 'html tages for testing version 3', - }; - - const webContentResourceVersion1 = new CommonCartridgeWebContentResource(propsVersion1); - const webContentResourceVersion3 = new CommonCartridgeWebContentResource(propsVersion3); - - describe('canInline', () => { - describe('when common cartridge version 1.1', () => { - it('should return false', () => { - expect(webContentResourceVersion1.canInline()).toBe(false); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return false', () => { - expect(webContentResourceVersion3.canInline()).toBe(false); - }); - }); - }); - - describe('getFilePath', () => { - describe('when common cartridge version 1.1', () => { - it('should return the file path regarding version 1.1', () => { - const filePath = webContentResourceVersion1.getFilePath(); - expect(filePath).toBe(`${propsVersion1.folder}/${propsVersion1.identifier}.html`); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return the file path regarding version 1.3', () => { - const filePath = webContentResourceVersion3.getFilePath(); - expect(filePath).toBe(`${propsVersion3.folder}/${propsVersion3.identifier}.html`); - }); - }); - }); - - describe('getFileContent', () => { - describe('when common cartridge version 1.1', () => { - it('should return XML content of common cartridge version 1.1', () => { - const content = webContentResourceVersion1.getFileContent(); - expect(content).toContain(propsVersion1.html); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return XML content of common cartridge version 1.3', () => { - const content = webContentResourceVersion3.getFileContent(); - expect(content).toContain(propsVersion3.html); - }); - }); - }); - - describe('getManifestXml', () => { - describe('when common cartridge version 1.1', () => { - it('should return manifest xml content regarding version 1.1', () => { - const transformed = webContentResourceVersion1.getManifestXmlObject(); - expect(transformed).toStrictEqual({ - $: { - identifier: propsVersion1.identifier, - type: propsVersion1.type, - intendeduse: 'unspecified', - }, - file: { - $: { - href: propsVersion1.folder, - }, - }, - }); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return manifest xml content regarding version 1.3', () => { - const transformed = webContentResourceVersion3.getManifestXmlObject(); - expect(transformed).toStrictEqual({ - $: { - identifier: propsVersion3.identifier, - type: propsVersion3.type, - intendeduse: 'unspecified', - }, - file: { - $: { - href: propsVersion3.folder, - }, - }, - }); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts deleted file mode 100644 index a465c2a0d9b..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-content-resource.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../common-cartridge.enums'; -import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; - -export type CommonCartridgeWebContentResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT; - version: CommonCartridgeVersion; - identifier: string; - folder: string; - title: string; - html: string; -}; - -export class CommonCartridgeWebContentResource implements CommonCartridgeResource { - constructor(private readonly props: CommonCartridgeWebContentResourceProps) {} - - public canInline(): boolean { - return false; - } - - public getFilePath(): string { - return `${this.props.folder}/${this.props.identifier}.html`; - } - - public getFileContent(): string { - return this.props.html; - } - - public getManifestXmlObject(): Record { - return { - $: { - identifier: this.props.identifier, - type: this.props.type, - intendeduse: - this.props.version === CommonCartridgeVersion.V_1_3_0 - ? CommonCartridgeIntendedUseType.ASSIGNMENT - : CommonCartridgeIntendedUseType.UNSPECIFIED, - }, - file: { - $: { - href: this.getFilePath(), - }, - }, - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts deleted file mode 100644 index 44551fa770d..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.spec.ts +++ /dev/null @@ -1,133 +0,0 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { - CommonCartridgeWebLinkResource, - CommonCartridgeWebLinkResourceProps, -} from './common-cartridge-web-link-resource'; - -describe('CommonCartridgeWebLinkResource', () => { - const propsOfV3: CommonCartridgeWebLinkResourceProps = { - type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_3_0, - identifier: 'web-link-v3', - folder: 'https://example.com/linkv3', - title: 'Web Link v3', - url: 'https://example.com/linkv3', - }; - - const propsOfV1: CommonCartridgeWebLinkResourceProps = { - type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'web-link-v1', - folder: 'https://example.com/link1', - title: 'Web Link v1', - url: 'https://example.com/link1', - }; - - const webLinkResourceV3 = new CommonCartridgeWebLinkResource(propsOfV3); - const webLinkResourceV1 = new CommonCartridgeWebLinkResource(propsOfV1); - - describe('canInline', () => { - describe('when common cartridge version 1.1', () => { - it('should return false', () => { - expect(webLinkResourceV1.canInline()).toBe(false); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return false', () => { - expect(webLinkResourceV3.canInline()).toBe(false); - }); - }); - }); - - describe('getFilePath', () => { - describe('when common cartridge version 1.1', () => { - it('should return the file path regarding version 1.1', () => { - const filePathV1 = webLinkResourceV1.getFilePath(); - expect(filePathV1).toBe(`${propsOfV1.folder}/${propsOfV1.identifier}.xml`); - }); - - describe('when common cartridge version 1.3', () => { - it('should return the file path regarding version 1.3', () => { - const filePathV3 = webLinkResourceV3.getFilePath(); - expect(filePathV3).toBe(`${propsOfV3.folder}/${propsOfV3.identifier}.xml`); - }); - }); - }); - }); - - describe('getFileContent', () => { - describe('when common cartridge version 1.1', () => { - it('should return XML content of common cartridge version 1.1', () => { - const content = webLinkResourceV1.getFileContent(); - - expect(content).toContain('webLink'); - expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); - expect(content).toContain('http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1'); - expect(content).toContain( - 'https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd' - ); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return XML content of common cartridge version 1.3', () => { - const content = webLinkResourceV3.getFileContent(); - - expect(content).toContain('webLink'); - expect(content).toContain('http://www.w3.org/2001/XMLSchema-instance'); - expect(content).toContain('http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3'); - expect(content).toContain('http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd'); - }); - }); - - describe('when version is not supported', () => { - it('should throw an error', () => { - const webLinkResource = new CommonCartridgeWebLinkResource({ - ...propsOfV1, - version: 'xxx' as CommonCartridgeVersion, - }); - - expect(() => webLinkResource.getFileContent()).toThrowError('Version xxx is not supported'); - }); - }); - }); - - describe('getManifestXml', () => { - describe('when common cartridge version 1.1', () => { - it('should return manifest xml content regarding version 1.1', () => { - const transformedV1 = webLinkResourceV1.getManifestXmlObject(); - - expect(transformedV1).toStrictEqual({ - $: { - identifier: propsOfV1.identifier, - type: propsOfV1.type, - }, - file: { - $: { - href: propsOfV1.folder, - }, - }, - }); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return manifest xml content regarding version 1.3', () => { - const transformedV3 = webLinkResourceV3.getManifestXmlObject(); - - expect(transformedV3).toStrictEqual({ - $: { - identifier: propsOfV3.identifier, - type: propsOfV3.type, - }, - file: { - $: { - href: propsOfV3.folder, - }, - }, - }); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts deleted file mode 100644 index bcc0d8d252d..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-web-link-resource.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { buildXmlString, createVersionNotSupportedError } from '../utils'; - -export type CommonCartridgeWebLinkResourceProps = { - type: CommonCartridgeResourceType.WEB_LINK; - version: CommonCartridgeVersion; - identifier: string; - folder: string; - title: string; - url: string; -}; - -export class CommonCartridgeWebLinkResource implements CommonCartridgeResource { - constructor(private readonly props: CommonCartridgeWebLinkResourceProps) {} - - public canInline(): boolean { - return false; - } - - public getFilePath(): string { - return `${this.props.folder}/${this.props.identifier}.xml`; - } - - public getFileContent(): string { - return buildXmlString({ - webLink: { - $: this.getXmlNamespacesByVersion(), - title: this.props.title, - url: { - $: { - href: this.props.url, - target: '_self', - windowFeatures: 'width=100, height=100', - }, - }, - }, - }); - } - - public getManifestXmlObject(): Record { - return { - $: { - identifier: this.props.identifier, - type: this.props.type, - }, - file: { - $: { - href: this.getFilePath(), - }, - }, - }; - } - - private getXmlNamespacesByVersion(): Record { - switch (this.props.version) { - case CommonCartridgeVersion.V_1_1_0: - return { - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/sites/default/files/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', - }; - case CommonCartridgeVersion.V_1_3_0: - return { - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd', - }; - default: - throw createVersionNotSupportedError(this.props.version); - } - } -} From d0534f4e25b839d3163c97c0db34633dd51ee409 Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 11 Dec 2023 11:25:48 +0100 Subject: [PATCH 073/177] EW-539 working on tests for factories --- ...cartridge-resource-version-factory.spec.ts | 41 ++++++++++++++ ...mmon-cartridge-resource-version-factory.ts | 5 +- .../common-cartridge-resource-factory.spec.ts | 53 +++++++++++++++++++ .../common-cartridge-resource-factory.ts | 7 ++- .../common-cartridge-resource-factory.spec.ts | 53 +++++++++++++++++++ .../common-cartridge-resource-factory.ts | 7 ++- 6 files changed, 156 insertions(+), 10 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.spec.ts new file mode 100644 index 00000000000..8ec02bd37ba --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.spec.ts @@ -0,0 +1,41 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResourceVersionFactory } from './common-cartridge-resource-version-factory'; +import { CommonCartridgeResourceFactoryV110 } from './v1.1.0/common-cartridge-resource-factory'; +import { CommonCartridgeResourceFactoryV130 } from './v1.3.0/common-cartridge-resource-factory'; + +describe('CommonCartridgeResourceVersionFactory', () => { + describe('createFactory', () => { + describe('when versions is supported', () => { + it('should return v1.1.0 factory', () => { + const result = CommonCartridgeResourceVersionFactory.createFactory(CommonCartridgeVersion.V_1_1_0); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeResourceFactoryV110); + }); + + it('should return v1.3.0 factory', () => { + const result = CommonCartridgeResourceVersionFactory.createFactory(CommonCartridgeVersion.V_1_3_0); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeResourceFactoryV130); + }); + }); + + describe('when versions is not supported', () => { + it('should throw InternalServerErrorException', () => { + const notSupportedVersions = [ + CommonCartridgeVersion.V_1_0_0, + CommonCartridgeVersion.V_1_2_0, + CommonCartridgeVersion.V_1_4_0, + ]; + + notSupportedVersions.forEach((version) => { + expect(() => CommonCartridgeResourceVersionFactory.createFactory(version)).toThrow( + InternalServerErrorException + ); + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts index 21bd729d51c..41c9f616143 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts @@ -1,11 +1,12 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeResourceFactory } from '../interfaces/common-cartridge-resource-factory.interface'; import { createVersionNotSupportedError } from '../utils'; import { CommonCartridgeResourceFactoryV110 } from './v1.1.0/common-cartridge-resource-factory'; import { CommonCartridgeResourceFactoryV130 } from './v1.3.0/common-cartridge-resource-factory'; export class CommonCartridgeResourceVersionFactory { - public static createFactory(version: CommonCartridgeVersion): CommonCartridgeResourceFactory { + public static createFactory( + version: CommonCartridgeVersion + ): CommonCartridgeResourceFactoryV110 | CommonCartridgeResourceFactoryV130 { switch (version) { case CommonCartridgeVersion.V_1_1_0: return CommonCartridgeResourceFactoryV110.getInstance(); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts new file mode 100644 index 00000000000..cb117d74687 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts @@ -0,0 +1,53 @@ +import { faker } from '@faker-js/faker'; +import { + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { CommonCartridgeResourceFactoryV110 } from './common-cartridge-resource-factory'; +import { CommonCartridgeWebContentResourceV110 } from './common-cartridge-web-content-resource'; +import { CommonCartridgeWebLinkResourceV110 } from './common-cartridge-web-link-resource'; + +describe('CommonCartridgeResourceFactoryV110', () => { + const setup = () => { + const sut = new CommonCartridgeResourceFactoryV110(); + + return { sut }; + }; + + describe('createResource', () => { + describe('when creating resources from props', () => { + it('shoul return web content resource', () => { + const { sut } = setup(); + const result = sut.createResource({ + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_1_0, + folder: faker.string.uuid(), + identifier: faker.string.uuid(), + title: faker.lorem.words(), + html: faker.lorem.paragraph(), + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }); + + expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV110); + }); + + it('shoul return web link resource', () => { + const { sut } = setup(); + const result = sut.createResource({ + type: CommonCartridgeResourceType.WEB_LINK, + version: CommonCartridgeVersion.V_1_1_0, + folder: faker.string.uuid(), + identifier: faker.string.uuid(), + title: faker.lorem.words(), + url: faker.internet.url(), + target: faker.lorem.word(), + windowFeatures: faker.lorem.words(), + }); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeWebLinkResourceV110); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts index 3eeb280ac9b..3971ce7215b 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts @@ -1,5 +1,4 @@ import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; -import { CommonCartridgeResourceFactory } from '../../interfaces/common-cartridge-resource-factory.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; import { createResourceTypeNotSupportedError } from '../../utils'; import { @@ -20,14 +19,14 @@ export type CommonCartridgeResourcePropsV110 = | CommonCartridgeWebContentResourcePropsV110 | CommonCartridgeWebLinkResourcePropsV110; -export class CommonCartridgeResourceFactoryV110 extends CommonCartridgeResourceFactory { +export class CommonCartridgeResourceFactoryV110 { public static readonly instance = new CommonCartridgeResourceFactoryV110(); - public static getInstance(): CommonCartridgeResourceFactory { + public static getInstance(): CommonCartridgeResourceFactoryV110 { return this.instance; } - public override createResource(props: CommonCartridgeResourcePropsV110): CommonCartridgeResource { + public createResource(props: CommonCartridgeResourcePropsV110): CommonCartridgeResource { const { type } = props; switch (type) { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts new file mode 100644 index 00000000000..cf57a27d14b --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts @@ -0,0 +1,53 @@ +import { faker } from '@faker-js/faker'; +import { + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { CommonCartridgeResourceFactoryV130 } from './common-cartridge-resource-factory'; +import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; +import { CommonCartridgeWebLinkResourceV130 } from './common-cartridge-web-link-resource'; + +describe('CommonCartridgeResourceFactoryV130', () => { + const setup = () => { + const sut = new CommonCartridgeResourceFactoryV130(); + + return { sut }; + }; + + describe('createResource', () => { + describe('when creating resources from props', () => { + it('shoul return web content resource', () => { + const { sut } = setup(); + const result = sut.createResource({ + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_3_0, + folder: faker.string.uuid(), + identifier: faker.string.uuid(), + title: faker.lorem.words(), + html: faker.lorem.paragraph(), + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }); + + expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV130); + }); + + it('shoul return web link resource', () => { + const { sut } = setup(); + const result = sut.createResource({ + type: CommonCartridgeResourceType.WEB_LINK, + version: CommonCartridgeVersion.V_1_3_0, + folder: faker.string.uuid(), + identifier: faker.string.uuid(), + title: faker.lorem.words(), + url: faker.internet.url(), + target: faker.lorem.word(), + windowFeatures: faker.lorem.words(), + }); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeWebLinkResourceV130); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts index 5afdff19211..6468bc2422b 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts @@ -1,5 +1,4 @@ import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; -import { CommonCartridgeResourceFactory } from '../../interfaces/common-cartridge-resource-factory.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; import { createResourceTypeNotSupportedError } from '../../utils'; import { @@ -20,14 +19,14 @@ export type CommonCartridgeResourcePropsV130 = | CommonCartridgeWebContentResourcePropsV130 | CommonCartridgeWebLinkResourcePropsV130; -export class CommonCartridgeResourceFactoryV130 extends CommonCartridgeResourceFactory { +export class CommonCartridgeResourceFactoryV130 { public static readonly instance = new CommonCartridgeResourceFactoryV130(); - public static getInstance(): CommonCartridgeResourceFactory { + public static getInstance(): CommonCartridgeResourceFactoryV130 { return this.instance; } - public override createResource(props: CommonCartridgeResourcePropsV130): CommonCartridgeResource { + public createResource(props: CommonCartridgeResourcePropsV130): CommonCartridgeResource { const { type } = props; switch (type) { From 21c33f075b45690fe5252ad56477383ed323b051 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 11 Dec 2023 15:21:08 +0100 Subject: [PATCH 074/177] EW-539 Working on --- ...idge-organizations-wrapper-element.spec.ts | 72 +++++++++++++++++++ ...artridge-resources-wrapper-element.spec.ts | 72 +++++++++++++++++++ ...idge-organizations-wrapper-element.spec.ts | 71 ++++++++++++++++++ ...mon-cartridge.organization-element.spec.ts | 63 ++++++++++++++++ 4 files changed, 278 insertions(+) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge.organization-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts new file mode 100644 index 00000000000..96e516e4172 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -0,0 +1,72 @@ +import { DeepMocked, createMock } from '@golevelup/ts-jest'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { + CommonCartridgeOrganizationsWrapperElementPropsV110, + CommonCartridgeOrganizationsWrapperElementV110, +} from './common-cartridge-organizations-wrapper-element'; + +describe('CommonCartridgeOrganizationsWrapperElementV110', () => { + const setup = () => { + const item: DeepMocked = createMock(); + + // AI next 45 lines + const props: CommonCartridgeOrganizationsWrapperElementPropsV110 = { + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, + version: CommonCartridgeVersion.V_1_1_0, + items: [item], + }; + const sut = new CommonCartridgeOrganizationsWrapperElementV110(props); + + item.getManifestXmlObject.mockReturnValueOnce({}); + item.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_1_0); + + return { sut, props }; + }; + + describe('getSupportedVersion', () => { + describe('when using common cartridge version 1.1.0', () => { + it('should return correct version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_1_0); + }); + }); + }); + + describe('getManifestXmlObject', () => { + describe('when using common cartridge version 1.1.0', () => { + it('should return correct manifest xml object', () => { + const { sut } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toStrictEqual({ + organization: [ + { + $: { + identifier: 'org-1', + structure: 'rooted-hierarchy', + }, + item: [ + { + $: { + identifier: 'LearningModules', + }, + item: [{}], + }, + ], + }, + ], + }); + }); + + it('should call getManifestXmlObject on item', () => { + const { sut, props } = setup(); + sut.getManifestXmlObject(); + + expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts new file mode 100644 index 00000000000..90f4bc44cb1 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts @@ -0,0 +1,72 @@ +import { DeepMocked, createMock } from '@golevelup/ts-jest'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { + CommonCartridgeResourcesWrapperElementPropsV110, + CommonCartridgeResourcesWrapperElementV110, +} from './common-cartridge-resources-wrapper-element'; + +describe('CommonCartridgeResourcesWrapperElementV110', () => { + const setup = () => { + const item: DeepMocked = createMock(); + + const props: CommonCartridgeResourcesWrapperElementPropsV110 = { + type: CommonCartridgeElementType.RESOURCES_WRAPPER, + version: CommonCartridgeVersion.V_1_1_0, + items: [item], + }; + const sut = new CommonCartridgeResourcesWrapperElementV110(props); + + item.getManifestXmlObject.mockReturnValueOnce({ + resources: [ + { + resource: [ + { + $: { + identifier: 'resource-1', + }, + }, + ], + }, + ], + }); + item.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_1_0); + + return { sut, props }; + }; + + describe('getSupportedVersion', () => { + describe('when using common cartridge version 1.1.0', () => { + it('should return correct version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_1_0); + }); + }); + }); + + describe('getManifestXmlObject', () => { + describe('when using common cartridge version 1.1.0', () => { + it('should return correct manifest xml object', () => { + const { sut } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toStrictEqual({ + resources: [ + { + resource: [{}], + }, + ], + }); + }); + + it('should call getManifestXmlObject on item', () => { + const { sut, props } = setup(); + sut.getManifestXmlObject(); + + expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts new file mode 100644 index 00000000000..06d86f8958d --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -0,0 +1,71 @@ +import { DeepMocked, createMock } from '@golevelup/ts-jest'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { + CommonCartridgeOrganizationsWrapperElementPropsV130, + CommonCartridgeOrganizationsWrapperElementV130, +} from './common-cartridge-organizations-wrapper-element'; + +describe('CommonCartridgeOrganizationsWrapperElementV130', () => { + const setup = () => { + const item: DeepMocked = createMock(); + + const props: CommonCartridgeOrganizationsWrapperElementPropsV130 = { + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, + version: CommonCartridgeVersion.V_1_3_0, + items: [item], + }; + const sut = new CommonCartridgeOrganizationsWrapperElementV130(props); + + item.getManifestXmlObject.mockReturnValueOnce({}); + item.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_3_0); + + return { sut, props }; + }; + + describe('getSupportedVersion', () => { + describe('when using common cartridge version 1.3.0', () => { + it('should return correct version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_3_0); + }); + }); + }); + + describe('getManifestXmlObject', () => { + describe('when using common cartridge version 1.3.0', () => { + it('should return correct manifest xml object', () => { + const { sut } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toStrictEqual({ + organization: [ + { + $: { + identifier: 'org-1', + structure: 'rooted-hierarchy', + }, + item: [ + { + $: { + identifier: 'LearningModules', + }, + item: [{}], + }, + ], + }, + ], + }); + }); + + it('should call getManifestXmlObject on item', () => { + const { sut, props } = setup(); + sut.getManifestXmlObject(); + + expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge.organization-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge.organization-element.spec.ts new file mode 100644 index 00000000000..b038a43f60e --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge.organization-element.spec.ts @@ -0,0 +1,63 @@ +import { faker } from '@faker-js/faker'; +import { DeepMocked, createMock } from '@golevelup/ts-jest'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { + CommonCartridgeOrganizationElementPropsV130, + CommonCartridgeOrganizationElementV130, +} from './common-cartridge-organization-element'; + +describe('CommonCartridgeOrganizationElementV130', () => { + const setup = () => { + const item: DeepMocked = createMock(); + + const props: CommonCartridgeOrganizationElementPropsV130 = { + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_3_0, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + items: [item], + }; + const sut = new CommonCartridgeOrganizationElementV130(props); + + item.getManifestXmlObject.mockReturnValueOnce({}); + item.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_3_0); + + return { sut, props }; + }; + + describe('getSupportedVersion', () => { + describe('when using common cartridge version 1.3.0', () => { + it('should return correct version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_3_0); + }); + }); + }); + + describe('getManifestXmlObject', () => { + describe('when using common cartridge version 1.3.0', () => { + it('should return correct manifest xml object', () => { + const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toStrictEqual({ + $: { + identifier: props.identifier, + }, + title: props.title, + item: [{}], + }); + }); + + it('should call getManifestXmlObject on item', () => { + const { sut, props } = setup(); + sut.getManifestXmlObject(); + + expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); + }); + }); + }); +}); From 08a2c8be8cfcad3f7f417f53efe583f7203d107d Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 11 Dec 2023 15:21:34 +0100 Subject: [PATCH 075/177] EW-539 working on --- ...mon-cartridge-organization-element.spec.ts | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts index 7fcfd8d932f..48ff48e2c6a 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts @@ -1,4 +1,5 @@ import { faker } from '@faker-js/faker'; +import { DeepMocked, createMock } from '@golevelup/ts-jest'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { @@ -8,18 +9,7 @@ import { describe('CommonCartridgeOrganizationElementV110', () => { const setup = () => { - const item: CommonCartridgeElement = { - getManifestXmlObject: () => { - return { - $: { - identifier: faker.string.uuid(), - }, - title: faker.lorem.words(), - }; - }, - getSupportedVersion: () => CommonCartridgeVersion.V_1_1_0, - checkVersion: () => CommonCartridgeVersion.V_1_1_0, - }; + const item: DeepMocked = createMock(); const props: CommonCartridgeOrganizationElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATION, @@ -30,6 +20,9 @@ describe('CommonCartridgeOrganizationElementV110', () => { }; const sut = new CommonCartridgeOrganizationElementV110(props); + item.getManifestXmlObject.mockReturnValueOnce({}); + item.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_1_0); + return { sut, props }; }; @@ -43,4 +36,29 @@ describe('CommonCartridgeOrganizationElementV110', () => { }); }); }); + + describe('getManifestXmlObject', () => { + // AI next 12 lines + describe('when using common cartridge version 1.1.0', () => { + it('should return correct manifest xml object', () => { + const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toStrictEqual({ + $: { + identifier: props.identifier, + }, + title: props.title, + item: [{}], + }); + }); + + it('should call getManifestXmlObject on item', () => { + const { sut, props } = setup(); + sut.getManifestXmlObject(); + + expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); + }); + }); + }); }); From d727b30e7a04aad39463d6084309700a2711fabe Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 11 Dec 2023 15:45:31 +0100 Subject: [PATCH 076/177] EW-539 fixing tests --- .../common-cartridge-manifest-resource.ts | 20 ++++++++++++------- .../common-cartridge-resource-factory.spec.ts | 2 +- .../common-cartridge-manifest-resource.ts | 20 ++++++++++++------- .../learnroom/common-cartridge/utils.spec.ts | 4 ++-- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts index 496f639c98a..6c9537c164f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -1,7 +1,11 @@ import { Builder } from 'xml2js'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeOrganizationsWrapperElement } from '../../elements/common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElement } from '../../elements/common-cartridge-resources-wrapper-element'; +import { + CommonCartridgeElementType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { CommonCartridgeOrganizationsWrapperElementV110 } from '../../elements/v1.1.0/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementV110 } from '../../elements/v1.1.0/common-cartridge-resources-wrapper-element'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; @@ -52,13 +56,15 @@ export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ', }, metadata: this.props.metadata.getManifestXmlObject(), - organizations: new CommonCartridgeOrganizationsWrapperElement({ + organizations: new CommonCartridgeOrganizationsWrapperElementV110({ + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, version: this.props.version, - organizations: this.props.organizations, + items: this.props.organizations, }).getManifestXmlObject(), - resources: new CommonCartridgeResourcesWrapperElement({ + resources: new CommonCartridgeResourcesWrapperElementV110({ + type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: this.props.version, - resources: this.props.resources, + items: this.props.resources, }).getManifestXmlObject(), }, }; diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts index cb117d74687..57d78b427b3 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts @@ -17,7 +17,7 @@ describe('CommonCartridgeResourceFactoryV110', () => { describe('createResource', () => { describe('when creating resources from props', () => { - it('shoul return web content resource', () => { + it('should return web content resource', () => { const { sut } = setup(); const result = sut.createResource({ type: CommonCartridgeResourceType.WEB_CONTENT, diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts index 868f9cd7fdc..2347cddcad9 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -1,7 +1,11 @@ import { Builder } from 'xml2js'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeOrganizationsWrapperElement } from '../../elements/common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElement } from '../../elements/common-cartridge-resources-wrapper-element'; +import { + CommonCartridgeElementType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { CommonCartridgeOrganizationsWrapperElementV130 } from '../../elements/v1.3.0/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementV130 } from '../../elements/v1.3.0/common-cartridge-resources-wrapper-element'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; @@ -54,13 +58,15 @@ export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_cpextensionv1p2_v1p0.xsd', }, metadata: this.props.metadata.getManifestXmlObject(), - organizations: new CommonCartridgeOrganizationsWrapperElement({ + organizations: new CommonCartridgeOrganizationsWrapperElementV130({ + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, version: this.props.version, - organizations: this.props.organizations, + items: this.props.organizations, }).getManifestXmlObject(), - resources: new CommonCartridgeResourcesWrapperElement({ + resources: new CommonCartridgeResourcesWrapperElementV130({ + type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: this.props.version, - resources: this.props.resources, + items: this.props.resources, }).getManifestXmlObject(), }, }; diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.spec.ts index 4a23c26971f..62a81286e41 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/utils.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/utils.spec.ts @@ -6,7 +6,7 @@ describe('CommonCartridgeUtils', () => { it('should create xml string', () => { const xml = buildXmlString({ root: { child: 'value' } }); - expect(xml).toBe('\n value\n'); + expect(xml).toBe('value'); }); }); @@ -16,7 +16,7 @@ describe('CommonCartridgeUtils', () => { const error = createVersionNotSupportedError(CommonCartridgeVersion.V_1_0_0); expect(error).toBeDefined(); - expect(error.message).toBe('Version 1.0.0 is not supported'); + expect(error.message).toBe('Common Cartridge version 1.0.0 is not supported'); }); }); }); From 01fdda50b89bc3e52ef59953f393f3ad8bd56826 Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 11 Dec 2023 16:58:34 +0100 Subject: [PATCH 077/177] EW-539 working on tests --- ...common-cartridge-manifest-resource.spec.ts | 72 +++++++++++++++++++ .../resources/v1.1.0/imsmanifest.xml | 37 ++++++++++ ...common-cartridge-manifest-resource.spec.ts | 72 +++++++++++++++++++ .../learnroom/common-cartridge/utils.ts | 5 +- 4 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/imsmanifest.xml create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts new file mode 100644 index 00000000000..2889a0493ec --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -0,0 +1,72 @@ +import { faker } from '@faker-js/faker'; +import { createMock } from '@golevelup/ts-jest'; +import { readFile } from 'fs/promises'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; + +describe('CommonCartridgeManifestResourceV110', () => { + const setup = () => { + const metadataMock = createMock(); + const sut = new CommonCartridgeManifestResourceV110({ + type: CommonCartridgeResourceType.MANIFEST, + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + metadata: metadataMock, + organizations: [], + resources: [], + }); + + return { sut, metadataMock }; + }; + + describe('canInline', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return false', () => { + const { sut } = setup(); + const result = sut.canInline(); + + expect(result).toBe(false); + }); + }); + }); + + describe('getFilePath', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return constructed file path', () => { + const { sut } = setup(); + const result = sut.getFilePath(); + + expect(result).toBe('imsmanifest.xml'); + }); + }); + }); + + describe('getFileContent', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return constructed file content', async () => { + const { sut } = setup(); + const manifest = await readFile( + './apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/imsmanifest.xml', + 'utf-8' + ); + const result = sut.getFileContent(); + + expect(result).toEqual(manifest); + }); + }); + }); + + describe('getSupportedVersion', () => { + describe('when using Common Cartridge version 1.1.0', () => { + it('should return supported version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_1_0); + }); + }); + }); + + describe('getManifestXmlObject', () => {}); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/imsmanifest.xml b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/imsmanifest.xml new file mode 100644 index 00000000000..8cf00394ccc --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/imsmanifest.xml @@ -0,0 +1,37 @@ + + + + IMS Common Cartridge + 1.1.0 + + + + Common Cartridge Example + + + This is an example of a Common Cartridge. + + + + + + + + + Title + + + Title + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts new file mode 100644 index 00000000000..a2ad56a1956 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -0,0 +1,72 @@ +import { faker } from '@faker-js/faker'; +import { createMock } from '@golevelup/ts-jest'; +import { readFile } from 'fs/promises'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; + +describe('CommonCartridgeManifestResourceV130', () => { + const setup = () => { + const metadataMock = createMock(); + const sut = new CommonCartridgeManifestResourceV130({ + type: CommonCartridgeResourceType.MANIFEST, + version: CommonCartridgeVersion.V_1_3_0, + identifier: faker.string.uuid(), + metadata: metadataMock, + organizations: [], + resources: [], + }); + + return { sut, metadataMock }; + }; + + describe('canInline', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return false', () => { + const { sut } = setup(); + const result = sut.canInline(); + + expect(result).toBe(false); + }); + }); + }); + + describe('getFilePath', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return constructed file path', () => { + const { sut } = setup(); + const result = sut.getFilePath(); + + expect(result).toBe('imsmanifest.xml'); + }); + }); + }); + + describe('getFileContent', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it.skip('should return constructed file content', async () => { + const { sut } = setup(); + const manifest = await readFile( + './apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/imsmanifest.xml', + 'utf-8' + ); + const result = sut.getFileContent(); + + expect(result).toEqual(manifest)); + }); + }); + }); + + describe('getSupportedVersion', () => { + describe('when using Common Cartridge version 1.3.0', () => { + it('should return supported version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_3_0); + }); + }); + }); + + describe('getManifestXmlObject', () => {}); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.ts index 74c2969f55a..17a542db4d4 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/utils.ts @@ -6,7 +6,10 @@ export type OmitVersion = Omit; export type OmitVersionAndFolder = Omit; -const xmlBuilder = new Builder({ xmldec: { version: '1.0', encoding: 'UTF-8' }, renderOpts: { indent: '\t' } }); +const xmlBuilder = new Builder({ + xmldec: { version: '1.0', encoding: 'UTF-8' }, + renderOpts: { pretty: true, indent: '\t', newline: '\n' }, +}); export function buildXmlString(obj: unknown): string { return xmlBuilder.buildObject(obj); From 11bf26f6b924afb119d87758b8f5dc381a24b1bd Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 11 Dec 2023 17:02:30 +0100 Subject: [PATCH 078/177] EW-539 Add tests for resources wrapper element --- ...artridge-resources-wrapper-element.spec.ts | 51 ++++++----- ...artridge-resources-wrapper-element.spec.ts | 85 +++++++++++++++++++ 2 files changed, 117 insertions(+), 19 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts index 90f4bc44cb1..f0c85a2fffe 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts @@ -8,29 +8,30 @@ import { describe('CommonCartridgeResourcesWrapperElementV110', () => { const setup = () => { - const item: DeepMocked = createMock(); + const item1: DeepMocked = createMock(); + const item2: DeepMocked = createMock(); + + item1.getManifestXmlObject.mockReturnValueOnce({ + $: { + identifier: 'resource-1', + }, + }); + item1.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_1_0); + + item2.getManifestXmlObject.mockReturnValueOnce({ + $: { + identifier: 'resource-2', + }, + }); + item2.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_1_0); const props: CommonCartridgeResourcesWrapperElementPropsV110 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: CommonCartridgeVersion.V_1_1_0, - items: [item], + items: [item1, item2], }; - const sut = new CommonCartridgeResourcesWrapperElementV110(props); - item.getManifestXmlObject.mockReturnValueOnce({ - resources: [ - { - resource: [ - { - $: { - identifier: 'resource-1', - }, - }, - ], - }, - ], - }); - item.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_1_0); + const sut = new CommonCartridgeResourcesWrapperElementV110(props); return { sut, props }; }; @@ -55,17 +56,29 @@ describe('CommonCartridgeResourcesWrapperElementV110', () => { expect(result).toStrictEqual({ resources: [ { - resource: [{}], + resource: [ + { + $: { + identifier: 'resource-1', + }, + }, + { + $: { + identifier: 'resource-2', + }, + }, + ], }, ], }); }); - it('should call getManifestXmlObject on item', () => { + it('should call getManifestXmlObject on both items', () => { const { sut, props } = setup(); sut.getManifestXmlObject(); expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); + expect(props.items[1].getManifestXmlObject).toHaveBeenCalledTimes(1); }); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts new file mode 100644 index 00000000000..2b3eddd44c2 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts @@ -0,0 +1,85 @@ +import { DeepMocked, createMock } from '@golevelup/ts-jest'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { + CommonCartridgeResourcesWrapperElementPropsV130, + CommonCartridgeResourcesWrapperElementV130, +} from './common-cartridge-resources-wrapper-element'; + +describe('CommonCartridgeResourcesWrapperElementV130', () => { + const setup = () => { + const item1: DeepMocked = createMock(); + const item2: DeepMocked = createMock(); + + item1.getManifestXmlObject.mockReturnValueOnce({ + $: { + identifier: 'resource-1', + }, + }); + item1.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_3_0); + + item2.getManifestXmlObject.mockReturnValueOnce({ + $: { + identifier: 'resource-2', + }, + }); + item2.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_3_0); + + const props: CommonCartridgeResourcesWrapperElementPropsV130 = { + type: CommonCartridgeElementType.RESOURCES_WRAPPER, + version: CommonCartridgeVersion.V_1_3_0, + items: [item1, item2], + }; + + const sut = new CommonCartridgeResourcesWrapperElementV130(props); + + return { sut, props }; + }; + + describe('getSupportedVersion', () => { + describe('when using common cartridge version 1.3.0', () => { + it('should return correct version', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_3_0); + }); + }); + }); + + describe('getManifestXmlObject', () => { + describe('when using common cartridge version 1.3.0', () => { + it('should return correct manifest xml object', () => { + const { sut } = setup(); + const result = sut.getManifestXmlObject(); + + expect(result).toStrictEqual({ + resources: [ + { + resource: [ + { + $: { + identifier: 'resource-1', + }, + }, + { + $: { + identifier: 'resource-2', + }, + }, + ], + }, + ], + }); + }); + + it('should call getManifestXmlObject on both items', () => { + const { sut, props } = setup(); + sut.getManifestXmlObject(); + + expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); + expect(props.items[1].getManifestXmlObject).toHaveBeenCalledTimes(1); + }); + }); + }); +}); From f159f6d98c16f4f0454176d2f76f9d9dd9f0f3b4 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 12 Dec 2023 09:36:53 +0100 Subject: [PATCH 079/177] EW-539 Clean up --- TODO.md | 1 + .../common-cartridge-metadata-element.spec.ts | 83 ------------------- .../common-cartridge-metadata-element.ts | 43 ---------- ...mon-cartridge-organization-element.spec.ts | 43 ---------- .../common-cartridge-organization-element.ts | 29 ------- ...idge-organizations-wrapper-element.spec.ts | 50 ----------- ...cartridge-organizations-wrapper-element.ts | 38 --------- ...artridge-resources-wrapper-element.spec.ts | 39 --------- ...mon-cartridge-resources-wrapper-element.ts | 27 ------ ...on-cartridge-organization-element.spec.ts} | 0 10 files changed, 1 insertion(+), 352 deletions(-) delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts rename apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/{common-cartridge.organization-element.spec.ts => common-cartridge-organization-element.spec.ts} (100%) diff --git a/TODO.md b/TODO.md index 76c0802ff6e..7024c61ba36 100644 --- a/TODO.md +++ b/TODO.md @@ -99,3 +99,4 @@ - createIdentifier method - merge main - review.md and comments +- move in separate module diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts deleted file mode 100644 index 45f2932d77b..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.spec.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { - CommonCartridgeMetadataElement, - CommonCartridgeMetadataElementProps, -} from './common-cartridge-metadata-element'; - -describe('CommonCartridgeMetadataElement', () => { - describe('getManifestXmlObject', () => { - describe('when using common cartridge version 1.1', () => { - const propsVersion1: CommonCartridgeMetadataElementProps = { - version: CommonCartridgeVersion.V_1_1_0, - title: 'Metadata Element Version 1.1', - creationDate: new Date(), - copyrightOwners: ['copyrightOwner1Version1', 'copyrightOwner2Version1'], - }; - - const sut = new CommonCartridgeMetadataElement(propsVersion1); - - it('should return correct xml object', () => { - const xmlObject = sut.getManifestXmlObject(); - - expect(xmlObject).toStrictEqual({ - schema: 'IMS Common Cartridge', - schemaversion: propsVersion1.version, - 'mnf:lom': { - 'mnf:general': { - 'mnf:title': { - 'mnf:string': propsVersion1.title, - }, - }, - 'mnf:rights': { - 'mnf:copyrightAndOtherRestrictions': { - 'mnf:value': 'yes', - }, - 'mnf:description': { - 'mnf:string': `${propsVersion1.creationDate.getFullYear()} ${propsVersion1.copyrightOwners.join( - ', ' - )}`, - }, - }, - }, - }); - }); - }); - - describe('when using common cartridge version 1.3', () => { - const propsVersion3: CommonCartridgeMetadataElementProps = { - version: CommonCartridgeVersion.V_1_3_0, - title: 'Metadata Element Version 1.3', - creationDate: new Date(), - copyrightOwners: ['copyrightOwner1Version3', 'copyrightOwner2Version3'], - }; - - const sut = new CommonCartridgeMetadataElement(propsVersion3); - - it('should return correct xml object', () => { - const xmlObject = sut.getManifestXmlObject(); - - expect(xmlObject).toStrictEqual({ - schema: 'IMS Common Cartridge', - schemaversion: propsVersion3.version, - 'mnf:lom': { - 'mnf:general': { - 'mnf:title': { - 'mnf:string': propsVersion3.title, - }, - }, - 'mnf:rights': { - 'mnf:copyrightAndOtherRestrictions': { - 'mnf:value': 'yes', - }, - 'mnf:description': { - 'mnf:string': `${propsVersion3.creationDate.getFullYear()} ${propsVersion3.copyrightOwners.join( - ', ' - )}`, - }, - }, - }, - }); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts deleted file mode 100644 index ecefa557407..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-metadata-element.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; - -export type CommonCartridgeMetadataElementProps = { - version: CommonCartridgeVersion; - title: string; - creationDate: Date; - copyrightOwners: string[]; -}; - -export class CommonCartridgeMetadataElement extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeMetadataElementProps) { - super(props); - } - - public override getSupportedVersions(): CommonCartridgeVersion[] { - return [CommonCartridgeVersion.V_1_1_0, CommonCartridgeVersion.V_1_2_0, CommonCartridgeVersion.V_1_3_0]; - } - - public override getManifestXmlObject(): Record { - return { - schema: 'IMS Common Cartridge', - schemaversion: this.props.version, - 'mnf:lom': { - 'mnf:general': { - 'mnf:title': { - 'mnf:string': this.props.title, - }, - }, - 'mnf:rights': { - 'mnf:copyrightAndOtherRestrictions': { - 'mnf:value': 'yes', - }, - 'mnf:description': { - 'mnf:string': `${this.props.creationDate.getFullYear()} ${this.props.copyrightOwners.join( - ', ' - )}`, - }, - }, - }, - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts deleted file mode 100644 index 26486180c6b..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.spec.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { CommonCartridgeOrganizationElement } from './common-cartridge-organization-element'; - -describe('CommonCartridgeOrganizationElement', () => { - const sut = new CommonCartridgeOrganizationElement({ - identifier: 'identifier', - title: 'title', - items: [ - { - getManifestXmlObject: () => { - return { - $: { - identifier: 'identifier', - }, - title: 'title', - }; - }, - }, - ], - }); - - describe('getManifestXmlObject', () => { - describe('when building common cartridge manifest', () => { - it('should return correct xml object', () => { - const xmlObject = sut.getManifestXmlObject(); - - expect(xmlObject).toStrictEqual({ - $: { - identifier: 'identifier', - }, - title: 'title', - item: [ - { - $: { - identifier: 'identifier', - }, - title: 'title', - }, - ], - }); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts deleted file mode 100644 index bcae0f10c7c..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organization-element.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; - -type CommonCartridgeOrganizationElementProps = { - version: CommonCartridgeVersion; - identifier: string; - title: string; - items: CommonCartridgeElement[]; -}; - -export class CommonCartridgeOrganizationElement extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeOrganizationElementProps) { - super(props); - } - - public override getSupportedVersions(): CommonCartridgeVersion[] { - return [CommonCartridgeVersion.V_1_1_0, CommonCartridgeVersion.V_1_3_0]; - } - - public override getManifestXmlObject(): Record { - return { - $: { - identifier: this.props.identifier, - }, - title: this.props.title, - item: this.props.items.map((item) => item.getManifestXmlObject()), - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts deleted file mode 100644 index ea01a411dfd..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.spec.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { CommonCartridgeOrganizationsWrapperElement } from './common-cartridge-organizations-wrapper-element'; - -describe('CommonCartridgeOrganizationsWrapperElement', () => { - const sut = new CommonCartridgeOrganizationsWrapperElement([ - { - getManifestXmlObject: () => { - return { - $: { - identifier: 'identifier', - }, - title: 'title', - }; - }, - }, - ]); - - describe('getManifestXmlObject', () => { - describe('when building common cartridge manifest', () => { - it('should return correct xml object', () => { - const xmlObject = sut.getManifestXmlObject(); - - expect(xmlObject).toStrictEqual({ - organization: [ - { - $: { - identifier: 'org-1', - structure: 'rooted-hierarchy', - }, - item: [ - { - $: { - identifier: 'LearningModules', - }, - item: [ - { - $: { - identifier: 'identifier', - }, - title: 'title', - }, - ], - }, - ], - }, - ], - }); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts deleted file mode 100644 index 69395a4155e..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-organizations-wrapper-element.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; - -export type CommonCartridgeOrganizationsWrapperElementProps = { - version: CommonCartridgeVersion; - organizations: CommonCartridgeElement[]; -}; - -export class CommonCartridgeOrganizationsWrapperElement extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementProps) { - super(props); - } - - public override getSupportedVersions(): CommonCartridgeVersion[] { - return [CommonCartridgeVersion.V_1_1_0, CommonCartridgeVersion.V_1_3_0]; - } - - public override getManifestXmlObject(): Record { - return { - organization: [ - { - $: { - identifier: 'org-1', - structure: 'rooted-hierarchy', - }, - item: [ - { - $: { - identifier: 'LearningModules', - }, - item: this.props.organizations.map((items) => items.getManifestXmlObject()), - }, - ], - }, - ], - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts deleted file mode 100644 index b2fef191cff..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.spec.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { CommonCartridgeResourcesWrapperElement } from './common-cartridge-resources-wrapper-element'; - -describe('CommonCartridgeResourcesWrapperElement', () => { - const sut = new CommonCartridgeResourcesWrapperElement([ - { - getManifestXmlObject: () => { - return { - $: { - identifier: 'identifier', - }, - title: 'title', - }; - }, - }, - ]); - - describe('getManifestXmlObject', () => { - describe('when building common cartridge manifest', () => { - it('should return the correct xml object', () => { - const xmlObject = sut.getManifestXmlObject(); - - expect(xmlObject).toStrictEqual({ - resources: [ - { - resource: [ - { - $: { - identifier: 'identifier', - }, - title: 'title', - }, - ], - }, - ], - }); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts deleted file mode 100644 index f86722f32d6..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-resources-wrapper-element.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; - -export type CommonCartridgeResourcesWrapperElementProps = { - version: CommonCartridgeVersion; - resources: CommonCartridgeElement[]; -}; - -export class CommonCartridgeResourcesWrapperElement extends CommonCartridgeElement { - constructor(private readonly props: CommonCartridgeResourcesWrapperElementProps) { - super(props); - } - - public override getSupportedVersions(): CommonCartridgeVersion[] { - return [CommonCartridgeVersion.V_1_1_0, CommonCartridgeVersion.V_1_3_0]; - } - - public override getManifestXmlObject(): Record { - return { - resources: [ - { - resource: this.props.resources.map((items) => items.getManifestXmlObject()), - }, - ], - }; - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge.organization-element.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge.organization-element.spec.ts rename to apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts From 7a7fb56ce15b592f15207810a2c87d1128a7730f Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 14 Dec 2023 06:53:25 +0100 Subject: [PATCH 080/177] EW-539 Working on element factory --- .../common-cartridge-element-factory.spec.ts | 70 +++++++++++++++++++ .../common-cartridge-element-factory.ts | 9 ++- .../common-cartridge-element-factory.spec.ts | 70 +++++++++++++++++++ .../common-cartridge-element-factory.ts | 9 ++- 4 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts new file mode 100644 index 00000000000..236a3e2bc04 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts @@ -0,0 +1,70 @@ +import { faker } from '@faker-js/faker/locale/af_ZA'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementFactoryV110 } from './common-cartridge-element-factory'; +import { CommonCartridgeMetadataElementV110 } from './common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElementV110 } from './common-cartridge-organization-element'; +import { CommonCartridgeOrganizationsWrapperElementV110 } from './common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementV110 } from './common-cartridge-resources-wrapper-element'; + +describe('CommonCartridgeElementFactoryV110', () => { + const setup = () => { + const sut = new CommonCartridgeElementFactoryV110(); + return { sut }; + }; + + describe('createElement', () => { + describe('when creating elements from props', () => { + it('should return metadata element', () => { + const { sut } = setup(); + const result = sut.createElement({ + type: CommonCartridgeElementType.METADATA, + version: CommonCartridgeVersion.V_1_1_0, + title: faker.lorem.words(), + creationDate: faker.date.past(), + copyrightOwners: [faker.person.fullName(), faker.person.fullName()], + }); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV110); + }); + + it('should return organization element', () => { + const { sut } = setup(); + const result = sut.createElement({ + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + items: [], + }); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeOrganizationElementV110); + }); + + it('should return organization wrapper element', () => { + const { sut } = setup(); + const result = sut.createElement({ + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, + version: CommonCartridgeVersion.V_1_1_0, + items: [], + }); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeOrganizationsWrapperElementV110); + }); + + it('should return resources wrapper element', () => { + const { sut } = setup(); + const result = sut.createElement({ + type: CommonCartridgeElementType.RESOURCES_WRAPPER, + version: CommonCartridgeVersion.V_1_1_0, + items: [], + }); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeResourcesWrapperElementV110); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts index 257bcc307e0..db68c173505 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts @@ -1,5 +1,4 @@ import { CommonCartridgeElementType } from '../../common-cartridge.enums'; -import { CommonCartridgeElementFactory } from '../../interfaces/common-cartridge-element-factory.interface'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { createElementTypeNotSupportedError } from '../../utils'; import { @@ -19,20 +18,20 @@ import { CommonCartridgeResourcesWrapperElementV110, } from './common-cartridge-resources-wrapper-element'; -export type CommonCartridgeElementProps = +export type CommonCartridgeElementPropsV110 = | CommonCartridgeMetadataElementPropsV110 | CommonCartridgeOrganizationElementPropsV110 | CommonCartridgeOrganizationsWrapperElementPropsV110 | CommonCartridgeResourcesWrapperElementPropsV110; -export class CommonCartridgeElementFactoryV110 extends CommonCartridgeElementFactory { +export class CommonCartridgeElementFactoryV110 { public static readonly instance = new CommonCartridgeElementFactoryV110(); - public static getInstance(): CommonCartridgeElementFactory { + public static getInstance(): CommonCartridgeElementFactoryV110 { return this.instance; } - public createElement(props: CommonCartridgeElementProps): CommonCartridgeElement { + public createElement(props: CommonCartridgeElementPropsV110): CommonCartridgeElement { const { type } = props; switch (type) { diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts new file mode 100644 index 00000000000..f96ff513df5 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts @@ -0,0 +1,70 @@ +import { faker } from '@faker-js/faker/locale/af_ZA'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementFactoryV130 } from './common-cartridge-element-factory'; +import { CommonCartridgeMetadataElementV130 } from './common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElementV130 } from './common-cartridge-organization-element'; +import { CommonCartridgeOrganizationsWrapperElementV130 } from './common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementV130 } from './common-cartridge-resources-wrapper-element'; + +describe('CommonCartridgeElementFactoryV130', () => { + const setup = () => { + const sut = new CommonCartridgeElementFactoryV130(); + return { sut }; + }; + + describe('createElement', () => { + describe('when creating elements from props', () => { + it('should return metadata element', () => { + const { sut } = setup(); + const result = sut.createElement({ + type: CommonCartridgeElementType.METADATA, + version: CommonCartridgeVersion.V_1_3_0, + title: faker.lorem.words(), + creationDate: faker.date.past(), + copyrightOwners: [faker.person.fullName(), faker.person.fullName()], + }); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV130); + }); + + it('should return organization element', () => { + const { sut } = setup(); + const result = sut.createElement({ + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_3_0, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + items: [], + }); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeOrganizationElementV130); + }); + + it('should return organization wrapper element', () => { + const { sut } = setup(); + const result = sut.createElement({ + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, + version: CommonCartridgeVersion.V_1_3_0, + items: [], + }); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeOrganizationsWrapperElementV130); + }); + + it('should return resources wrapper element', () => { + const { sut } = setup(); + const result = sut.createElement({ + type: CommonCartridgeElementType.RESOURCES_WRAPPER, + version: CommonCartridgeVersion.V_1_3_0, + items: [], + }); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeResourcesWrapperElementV130); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts index d76ad56c095..8d7fc34b30b 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts @@ -1,5 +1,4 @@ import { CommonCartridgeElementType } from '../../common-cartridge.enums'; -import { CommonCartridgeElementFactory } from '../../interfaces/common-cartridge-element-factory.interface'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { createElementTypeNotSupportedError } from '../../utils'; import { @@ -19,20 +18,20 @@ import { CommonCartridgeResourcesWrapperElementV130, } from './common-cartridge-resources-wrapper-element'; -export type CommonCartridgeElementProps = +export type CommonCartridgeElementProps130 = | CommonCartridgeMetadataElementPropsV130 | CommonCartridgeOrganizationElementPropsV130 | CommonCartridgeOrganizationsWrapperElementPropsV130 | CommonCartridgeResourcesWrapperElementPropsV130; -export class CommonCartridgeElementFactoryV130 extends CommonCartridgeElementFactory { +export class CommonCartridgeElementFactoryV130 { public static readonly instance = new CommonCartridgeElementFactoryV130(); - public static getInstance(): CommonCartridgeElementFactory { + public static getInstance(): CommonCartridgeElementFactoryV130 { return this.instance; } - public createElement(props: CommonCartridgeElementProps): CommonCartridgeElement { + public createElement(props: CommonCartridgeElementProps130): CommonCartridgeElement { const { type } = props; switch (type) { From 591a479ea060e5ed205e328df6dd3456bfc2238a Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 14 Dec 2023 06:54:07 +0100 Subject: [PATCH 081/177] EW-539 Fix typo in resource factory --- .../resources/v1.1.0/common-cartridge-resource-factory.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts index 57d78b427b3..b8971cdeb89 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts @@ -29,10 +29,11 @@ describe('CommonCartridgeResourceFactoryV110', () => { intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, }); + expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV110); }); - it('shoul return web link resource', () => { + it('should return web link resource', () => { const { sut } = setup(); const result = sut.createResource({ type: CommonCartridgeResourceType.WEB_LINK, From 68598987b5082ef62b67d8e2e484417161bbc171 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 14 Dec 2023 06:55:47 +0100 Subject: [PATCH 082/177] EW-539 Working on element version factory --- ...-cartridge-element-version-factory.spec.ts | 41 +++++++++++++++++++ ...ommon-cartridge-element-version-factory.ts | 8 ++-- 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts new file mode 100644 index 00000000000..0852d494efa --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts @@ -0,0 +1,41 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeElementVersionFactory } from './common-cartridge-element-version-factory'; +import { CommonCartridgeElementFactoryV110 } from './v1.1.0/common-cartridge-element-factory'; +import { CommonCartridgeElementFactoryV130 } from './v1.3.0/common-cartridge-element-factory'; + +describe('CommonCartridgeElementVersionFactory', () => { + describe('createFactory', () => { + describe('when versions is supported', () => { + it('should return v1.1.0 factory', () => { + const result = CommonCartridgeElementVersionFactory.createFactory(CommonCartridgeVersion.V_1_1_0); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeElementFactoryV110); + }); + + it('should return v1.3.0 factory', () => { + const result = CommonCartridgeElementVersionFactory.createFactory(CommonCartridgeVersion.V_1_3_0); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeElementFactoryV130); + }); + }); + + describe('when versions is not supported', () => { + it('should throw InternalServerErrorException', () => { + const notSupportedVersions = [ + CommonCartridgeVersion.V_1_0_0, + CommonCartridgeVersion.V_1_2_0, + CommonCartridgeVersion.V_1_4_0, + ]; + + notSupportedVersions.forEach((version) => { + expect(() => CommonCartridgeElementVersionFactory.createFactory(version)).toThrow( + InternalServerErrorException + ); + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts index 45768c17120..768ed9e7e2b 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts @@ -1,17 +1,19 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { createVersionNotSupportedError } from '../utils'; import { CommonCartridgeElementFactoryV110 } from './v1.1.0/common-cartridge-element-factory'; import { CommonCartridgeElementFactoryV130 } from './v1.3.0/common-cartridge-element-factory'; export class CommonCartridgeElementVersionFactory { - public static createFactory(version: CommonCartridgeVersion) { + public static createFactory( + version: CommonCartridgeVersion + ): CommonCartridgeElementFactoryV110 | CommonCartridgeElementFactoryV130 { switch (version) { case CommonCartridgeVersion.V_1_1_0: return CommonCartridgeElementFactoryV110.getInstance(); case CommonCartridgeVersion.V_1_3_0: return CommonCartridgeElementFactoryV130.getInstance(); default: - throw new InternalServerErrorException(`Common Cartridge version ${version} is not supported`); + throw createVersionNotSupportedError(version); } } } From 6c33ec915348c366c2d28cebaf08c64aaf2f9c54 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 14 Dec 2023 09:16:23 +0100 Subject: [PATCH 083/177] EW-539 Working on --- TODO.md | 2 ++ .../builders/common-cartridge-file-builder.ts | 26 +++++++++++++++---- .../learnroom/common-cartridge/index.ts | 12 ++++++--- ...mon-cartridge-element-factory.interface.ts | 8 ------ .../common-cartridge-manifest-resource.ts | 3 --- .../learnroom/common-cartridge/utils.ts | 2 +- 6 files changed, 33 insertions(+), 20 deletions(-) delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element-factory.interface.ts diff --git a/TODO.md b/TODO.md index 7024c61ba36..3b3547bf224 100644 --- a/TODO.md +++ b/TODO.md @@ -100,3 +100,5 @@ - merge main - review.md and comments - move in separate module +- check index.ts +- move xml files into test-assets folder diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts index 6bbccf7ade6..a1d2f35a6cb 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts @@ -1,9 +1,13 @@ import AdmZip from 'adm-zip'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { - CommonCartridgeMetadataElement, - CommonCartridgeMetadataElementProps, -} from '../elements/common-cartridge-metadata-element'; + CommonCartridgeMetadataElementPropsV110, + CommonCartridgeMetadataElementV110, +} from '../elements/v1.1.0/common-cartridge-metadata-element'; +import { + CommonCartridgeMetadataElementPropsV130, + CommonCartridgeMetadataElementV130, +} from '../elements/v1.3.0/common-cartridge-metadata-element'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { CommonCartridgeManifestResource } from '../resources/common-cartridge-manifest-resource'; @@ -31,8 +35,20 @@ export class CommonCartridgeFileBuilder { checkCommonCartridgeVersion(props.version); } - public addMetadata(props: OmitVersion): CommonCartridgeFileBuilder { - this.metadata = new CommonCartridgeMetadataElement({ ...props, version: this.props.version }); + public addMetadata( + props: OmitVersion + ): CommonCartridgeFileBuilder { + switch (this.props.version) { + case CommonCartridgeVersion.V_1_1_0: + this.metadata = new CommonCartridgeMetadataElementV110({ ...props, version: this.props.version }); + break; + case CommonCartridgeVersion.V_1_3_0: + this.metadata = new CommonCartridgeMetadataElementV130({ ...props, version: this.props.version }); + break; + default: + throw new Error('Version not supported'); + } + // this.metadata = new CommonCartridgeMetadataElement({ ...props, version: this.props.version }); return this; } diff --git a/apps/server/src/modules/learnroom/common-cartridge/index.ts b/apps/server/src/modules/learnroom/common-cartridge/index.ts index 237fcaa46e3..8bf745df6ab 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/index.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/index.ts @@ -1,6 +1,12 @@ export * from './builders/common-cartridge-file-builder'; export * from './builders/common-cartridge-organization-builder'; -export { CommonCartridgeResourceType, CommonCartridgeVersion } from './common-cartridge.enums'; -export { CommonCartridgeMetadataElementProps } from './elements/common-cartridge-metadata-element'; -export { CommonCartridgeResourceProps } from './resources/common-cartridge-resource-factory'; +export { + CommonCartridgeElementType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from './common-cartridge.enums'; +export { CommonCartridgeElementPropsV110 } from './elements/v1.1.0/common-cartridge-element-factory'; +export { CommonCartridgeElementProps130 } from './elements/v1.3.0/common-cartridge-element-factory'; +export { CommonCartridgeResourcePropsV110 } from './resources/v1.1.0/common-cartridge-resource-factory'; +export { CommonCartridgeResourcePropsV130 } from './resources/v1.3.0/common-cartridge-resource-factory'; export { OmitVersion } from './utils'; diff --git a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element-factory.interface.ts b/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element-factory.interface.ts deleted file mode 100644 index 5390d47e66b..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element-factory.interface.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElement } from './common-cartridge-element.interface'; - -export type CommonCartridgeElementProps = { version: CommonCartridgeVersion }; - -export abstract class CommonCartridgeElementFactory { - abstract createElement(props: CommonCartridgeElementProps): CommonCartridgeElement; -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts index 5b120d085fe..0ec35026382 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts @@ -1,4 +1,3 @@ -import { Builder } from 'xml2js'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeOrganizationsWrapperElement } from '../elements/common-cartridge-organizations-wrapper-element'; import { CommonCartridgeResourcesWrapperElement } from '../elements/common-cartridge-resources-wrapper-element'; @@ -15,8 +14,6 @@ export type CommonCartridgeManifestElementProps = { }; export class CommonCartridgeManifestResource implements CommonCartridgeResource { - private readonly xmlBuilder = new Builder(); - constructor(private readonly props: CommonCartridgeManifestElementProps) {} public canInline(): boolean { diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.ts index 17a542db4d4..49284ea7009 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/utils.ts @@ -7,7 +7,7 @@ export type OmitVersion = Omit; export type OmitVersionAndFolder = Omit; const xmlBuilder = new Builder({ - xmldec: { version: '1.0', encoding: 'UTF-8' }, + xmldec: { version: '1.0', encoding: 'UTF-8', standalone: false }, renderOpts: { pretty: true, indent: '\t', newline: '\n' }, }); From 82c9d76162bb5f66d6aacda598949f911dc7d8a4 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 14 Dec 2023 11:54:27 +0100 Subject: [PATCH 084/177] EW-539 finished web link --- ...common-cartridge-web-link-resource.spec.ts | 24 ++++++---------- ...common-cartridge-web-link-resource.spec.ts | 28 +++++++------------ .../learnroom/common-cartridge/utils.ts | 4 +-- .../common-cartridge/v1.1.0/weblink.xml | 5 ++++ .../common-cartridge/v1.3.0/weblink.xml | 5 ++++ 5 files changed, 31 insertions(+), 35 deletions(-) create mode 100644 apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml create mode 100644 apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts index 75242e61bac..07d0f6b5f04 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -1,4 +1,5 @@ import { faker } from '@faker-js/faker'; +import { readFile } from 'fs/promises'; import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeWebLinkResourcePropsV110, @@ -12,10 +13,10 @@ describe('CommonCartridgeWebLinkResourceV110', () => { version: CommonCartridgeVersion.V_1_1_0, identifier: faker.string.uuid(), folder: faker.string.uuid(), - title: faker.lorem.words(), - url: faker.internet.url(), - target: faker.lorem.word(), - windowFeatures: faker.lorem.words(), + title: 'Title', + url: 'http://www.example.tld', + target: '_self', + windowFeatures: 'width=100;height=100;', // FIXME: Is this a valid value? }; const sut = new CommonCartridgeWebLinkResourceV110(props); @@ -45,19 +46,12 @@ describe('CommonCartridgeWebLinkResourceV110', () => { }); describe('getFileContent', () => { - it('should contain correct XML', () => { - const { sut, props } = setup(); + it('should contain correct XML', async () => { + const { sut } = setup(); + const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml', 'utf8'); const result = sut.getFileContent(); - expect(result).toEqual( - '' + - '' + - `${props.title}` + - `` + - '' - ); + expect(result).toEqual(expected); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts index c5ae3047f2e..ec2fdc63f70 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts @@ -1,4 +1,5 @@ import { faker } from '@faker-js/faker'; +import { readFile } from 'node:fs/promises'; import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeWebLinkResourcePropsV130, @@ -12,10 +13,10 @@ describe('CommonCartridgeWebLinkResourceV130', () => { version: CommonCartridgeVersion.V_1_3_0, identifier: faker.string.uuid(), folder: faker.string.uuid(), - title: faker.lorem.words(), - url: faker.internet.url(), - target: faker.lorem.word(), - windowFeatures: faker.lorem.words(), + title: 'Title', + url: 'http://www.example.tld', + target: '_self', + windowFeatures: 'width=100;height=100;', // FIXME: Is this a valid value? }; const sut = new CommonCartridgeWebLinkResourceV130(props); @@ -45,21 +46,12 @@ describe('CommonCartridgeWebLinkResourceV130', () => { }); describe('getFileContent', () => { - describe('when using Common Cartridge version 1.3.0', () => { - it('should return correct XML', () => { - const { sut, props } = setup(); - const result = sut.getFileContent(); + it('should contain correct XML', async () => { + const { sut } = setup(); + const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml', 'utf8'); + const result = sut.getFileContent(); - expect(result).toEqual( - '' + - '' + - `${props.title}` + - `` + - '' - ); - }); + expect(result).toEqual(expected); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.ts b/apps/server/src/modules/learnroom/common-cartridge/utils.ts index 49284ea7009..654a1eabc18 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/utils.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/utils.ts @@ -7,8 +7,8 @@ export type OmitVersion = Omit; export type OmitVersionAndFolder = Omit; const xmlBuilder = new Builder({ - xmldec: { version: '1.0', encoding: 'UTF-8', standalone: false }, - renderOpts: { pretty: true, indent: '\t', newline: '\n' }, + xmldec: { version: '1.0', encoding: 'UTF-8' }, + renderOpts: { pretty: true, indent: ' ', newline: '\n' }, }); export function buildXmlString(obj: unknown): string { diff --git a/apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml b/apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml new file mode 100644 index 00000000000..eb2880bcd4f --- /dev/null +++ b/apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml @@ -0,0 +1,5 @@ + + + Title + + \ No newline at end of file diff --git a/apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml b/apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml new file mode 100644 index 00000000000..ca395c61f58 --- /dev/null +++ b/apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml @@ -0,0 +1,5 @@ + + + Title + + \ No newline at end of file From f703c5ef8f303f166e8879ba1ce43dfb8a73c2a6 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 14 Dec 2023 14:51:56 +0100 Subject: [PATCH 085/177] EW-539 working on --- .../common-cartridge-organization-builder.ts | 9 ++-- ...mmon-cartridge-resource-version-factory.ts | 23 ++++++--- ...common-cartridge-manifest-resource.spec.ts | 51 ++++++++++++++++--- .../common-cartridge-manifest-resource.ts | 16 +++--- .../common-cartridge-web-content-resource.ts | 7 +-- .../common-cartridge-web-link-resource.ts | 2 +- .../resources/v1.1.0/imsmanifest.xml | 37 -------------- .../common-cartridge-manifest-resource.ts | 2 +- .../common-cartridge-web-content-resource.ts | 2 +- .../common-cartridge-web-link-resource.ts | 2 +- .../common-cartridge/v1.1.0/manifest.xml | 37 ++++++++++++++ 11 files changed, 115 insertions(+), 73 deletions(-) delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/imsmanifest.xml create mode 100644 apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts index 5dd1d08f963..0cbf6cdfdcf 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts @@ -1,11 +1,10 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeOrganizationElement } from '../elements/common-cartridge-organization-element'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { - CommonCartridgeResourceFactory, CommonCartridgeResourceProps, -} from '../resources/common-cartridge-resource-factory'; + CommonCartridgeResourceVersionFactory, +} from '../resources/common-cartridge-resource-version-factory'; import { OmitVersionAndFolder } from '../utils'; export type CommonCartridgeOrganizationBuilderOptions = { @@ -42,8 +41,8 @@ export class CommonCartridgeOrganizationBuilder { return child; } - public addResource(props: CommonCartridgeResourceProps): CommonCartridgeOrganizationBuilder { - const resource = CommonCartridgeResourceFactory.create({ + public addResource(props: OmitVersionAndFolder): CommonCartridgeOrganizationBuilder { + const resource = CommonCartridgeResourceVersionFactory.createFactory({ ...props, version: this.options.version, folder: this.folder, diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts index 41c9f616143..cc911ccaad5 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts @@ -1,17 +1,26 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { createVersionNotSupportedError } from '../utils'; -import { CommonCartridgeResourceFactoryV110 } from './v1.1.0/common-cartridge-resource-factory'; -import { CommonCartridgeResourceFactoryV130 } from './v1.3.0/common-cartridge-resource-factory'; +import { + CommonCartridgeResourceFactoryV110, + CommonCartridgeResourcePropsV110, +} from './v1.1.0/common-cartridge-resource-factory'; +import { + CommonCartridgeResourceFactoryV130, + CommonCartridgeResourcePropsV130, +} from './v1.3.0/common-cartridge-resource-factory'; + +export type CommonCartridgeResourceProps = CommonCartridgeResourcePropsV110 | CommonCartridgeResourcePropsV130; export class CommonCartridgeResourceVersionFactory { - public static createFactory( - version: CommonCartridgeVersion - ): CommonCartridgeResourceFactoryV110 | CommonCartridgeResourceFactoryV130 { + public static createFactory(props: CommonCartridgeResourceProps): CommonCartridgeResource { + const { version } = props; + switch (version) { case CommonCartridgeVersion.V_1_1_0: - return CommonCartridgeResourceFactoryV110.getInstance(); + return CommonCartridgeResourceFactoryV110.getInstance().createResource(props); case CommonCartridgeVersion.V_1_3_0: - return CommonCartridgeResourceFactoryV130.getInstance(); + return CommonCartridgeResourceFactoryV130.getInstance().createResource(props); default: throw createVersionNotSupportedError(version); } diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index 2889a0493ec..0a3a6cf98f0 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -1,20 +1,59 @@ import { faker } from '@faker-js/faker'; import { createMock } from '@golevelup/ts-jest'; import { readFile } from 'fs/promises'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { + CommonCartridgeElementType, + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { CommonCartridgeElementFactoryV110 } from '../../elements/v1.1.0/common-cartridge-element-factory'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; +import { CommonCartridgeResourceFactoryV110 } from './common-cartridge-resource-factory'; describe('CommonCartridgeManifestResourceV110', () => { const setup = () => { + const resource1 = CommonCartridgeResourceFactoryV110.getInstance().createResource({ + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_1_0, + title: 'Title', + identifier: 'r1', + folder: 'i1', + html: '

HTML

', + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }); + const resource2 = CommonCartridgeResourceFactoryV110.getInstance().createResource({ + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_1_0, + title: 'Title', + identifier: 'r2', + folder: 'i2', + html: '

HTML

', + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }); + const organization1 = CommonCartridgeElementFactoryV110.getInstance().createElement({ + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_1_0, + title: 'Title', + identifier: 'o1', + items: [resource1], + }); + const organization2 = CommonCartridgeElementFactoryV110.getInstance().createElement({ + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_1_0, + title: 'Title', + identifier: 'o2', + items: [resource2], + }); const metadataMock = createMock(); const sut = new CommonCartridgeManifestResourceV110({ type: CommonCartridgeResourceType.MANIFEST, version: CommonCartridgeVersion.V_1_1_0, identifier: faker.string.uuid(), metadata: metadataMock, - organizations: [], - resources: [], + organizations: [organization1, organization2], + resources: [resource1, resource2], }); return { sut, metadataMock }; @@ -46,13 +85,13 @@ describe('CommonCartridgeManifestResourceV110', () => { describe('when using Common Cartridge version 1.1.0', () => { it('should return constructed file content', async () => { const { sut } = setup(); - const manifest = await readFile( - './apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/imsmanifest.xml', + const expected = await readFile( + './apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml', 'utf-8' ); const result = sut.getFileContent(); - expect(result).toEqual(manifest); + expect(result).toEqual(expected); }); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts index 6c9537c164f..94253f2dfa3 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -1,4 +1,3 @@ -import { Builder } from 'xml2js'; import { CommonCartridgeElementType, CommonCartridgeResourceType, @@ -8,10 +7,11 @@ import { CommonCartridgeOrganizationsWrapperElementV110 } from '../../elements/v import { CommonCartridgeResourcesWrapperElementV110 } from '../../elements/v1.1.0/common-cartridge-resources-wrapper-element'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { buildXmlString } from '../../utils'; export type CommonCartridgeManifestResourcePropsV110 = { type: CommonCartridgeResourceType.MANIFEST; - version: CommonCartridgeVersion.V_1_1_0; + version: CommonCartridgeVersion; identifier: string; metadata: CommonCartridgeElement; organizations: CommonCartridgeElement[]; @@ -19,8 +19,6 @@ export type CommonCartridgeManifestResourcePropsV110 = { }; export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource { - private readonly xmlBuilder = new Builder(); - public constructor(private readonly props: CommonCartridgeManifestResourcePropsV110) { super(props); } @@ -34,7 +32,7 @@ export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource } public override getFileContent(): string { - return this.xmlBuilder.buildObject(this.getManifestXmlObject()); + return buildXmlString(this.getManifestXmlObject()); } public override getSupportedVersion(): CommonCartridgeVersion { @@ -51,18 +49,18 @@ export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd ' + 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ', + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ' + + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd ', }, metadata: this.props.metadata.getManifestXmlObject(), organizations: new CommonCartridgeOrganizationsWrapperElementV110({ - type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, // FIXME: Is this necessary? version: this.props.version, items: this.props.organizations, }).getManifestXmlObject(), resources: new CommonCartridgeResourcesWrapperElementV110({ - type: CommonCartridgeElementType.RESOURCES_WRAPPER, + type: CommonCartridgeElementType.RESOURCES_WRAPPER, // FIXME: Is this necessary? version: this.props.version, items: this.props.resources, }).getManifestXmlObject(), diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts index dee829ee363..81784748f78 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -7,15 +7,12 @@ import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resou export type CommonCartridgeWebContentResourcePropsV110 = { type: CommonCartridgeResourceType.WEB_CONTENT; - version: CommonCartridgeVersion.V_1_1_0; + version: CommonCartridgeVersion; identifier: string; folder: string; title: string; html: string; - intendedUse: - | CommonCartridgeIntendedUseType.UNSPECIFIED - | CommonCartridgeIntendedUseType.LESSON_PLAN - | CommonCartridgeIntendedUseType.SYLLABUS; + intendedUse: CommonCartridgeIntendedUseType; }; export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResource { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts index 1c1997fe3ee..956e7b90146 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -4,7 +4,7 @@ import { buildXmlString } from '../../utils'; export type CommonCartridgeWebLinkResourcePropsV110 = { type: CommonCartridgeResourceType.WEB_LINK; - version: CommonCartridgeVersion.V_1_1_0; + version: CommonCartridgeVersion; identifier: string; folder: string; title: string; diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/imsmanifest.xml b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/imsmanifest.xml deleted file mode 100644 index 8cf00394ccc..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/imsmanifest.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - IMS Common Cartridge - 1.1.0 - - - - Common Cartridge Example - - - This is an example of a Common Cartridge. - - - - - - - - - Title - - - Title - - - - - - - - - - - - - \ No newline at end of file diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts index 2347cddcad9..b04a209f302 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -11,7 +11,7 @@ import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resou export type CommonCartridgeManifestResourcePropsV130 = { type: CommonCartridgeResourceType.MANIFEST; - version: CommonCartridgeVersion.V_1_3_0; + version: CommonCartridgeVersion; identifier: string; metadata: CommonCartridgeElement; organizations: CommonCartridgeElement[]; diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts index 09607367239..2f4c6ecec86 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -7,7 +7,7 @@ import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resou export type CommonCartridgeWebContentResourcePropsV130 = { type: CommonCartridgeResourceType.WEB_CONTENT; - version: CommonCartridgeVersion.V_1_3_0; + version: CommonCartridgeVersion; identifier: string; folder: string; title: string; diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts index 82419c59598..6c226e047b3 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -4,7 +4,7 @@ import { buildXmlString } from '../../utils'; export type CommonCartridgeWebLinkResourcePropsV130 = { type: CommonCartridgeResourceType.WEB_LINK; - version: CommonCartridgeVersion.V_1_3_0; + version: CommonCartridgeVersion; identifier: string; folder: string; title: string; diff --git a/apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml b/apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml new file mode 100644 index 00000000000..11b2c7d2b78 --- /dev/null +++ b/apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml @@ -0,0 +1,37 @@ + + + + IMS Common Cartridge + 1.1.0 + + + + Common Cartridge Example + + + This is an example of a Common Cartridge manifest. + + + + + + + + + Title 1 + + + Title 2 + + + + + + + + + + + + + \ No newline at end of file From 6ad8164305b2362c95a62e63a727c4249080f588 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 14 Dec 2023 15:55:32 +0100 Subject: [PATCH 086/177] EW-539 fixing resource factory props --- .../common-cartridge-file-builder.spec.ts | 9 +++- ...mon-cartridge-organization-builder.spec.ts | 8 +-- .../common-cartridge-organization-builder.ts | 10 ++-- .../learnroom/common-cartridge/index.ts | 2 - ...common-cartridge-manifest-resource.spec.ts | 9 ++-- .../common-cartridge-resource-factory.spec.ts | 54 +++++++++++++++++++ .../common-cartridge-resource-factory.ts | 40 ++++++++++++++ ...cartridge-resource-version-factory.spec.ts | 41 -------------- ...mmon-cartridge-resource-version-factory.ts | 28 ---------- .../common-cartridge-resource-factory.spec.ts | 12 +---- .../common-cartridge-resource-factory.ts | 10 +--- .../common-cartridge-resource-factory.spec.ts | 13 +---- .../common-cartridge-resource-factory.ts | 10 +--- 13 files changed, 125 insertions(+), 121 deletions(-) create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts create mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts index 92dd82daf85..27e93f93855 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts @@ -1,5 +1,9 @@ import AdmZip from 'adm-zip'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../common-cartridge.enums'; import { CommonCartridgeMetadataElementProps } from '../elements/common-cartridge-metadata-element'; import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; import { OmitVersion } from '../utils'; @@ -38,18 +42,21 @@ describe('CommonCartridgeFileBuilder', () => { identifier: 'resource-1-identifier', title: 'resource-1-title', html: '

resource-1-html

', + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, }; const resource2Props: CommonCartridgeResourceProps = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'resource-2-identifier', title: 'resource-2-title', html: '

resource-2-html

', + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, }; const resource3Props: CommonCartridgeResourceProps = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'resource-3-identifier', title: 'resource-3-title', html: '

resource-3-html

', + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, }; describe('build', () => { diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts index d5a6c3642a2..84086800e0f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts @@ -1,7 +1,7 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeOrganizationElement } from '../elements/common-cartridge-organization-element'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; +import { CommonCartridgeResourcePropsInternal } from '../resources/common-cartridge-resource-factory'; import { CommonCartridgeOrganizationBuilder, CommonCartridgeOrganizationBuilderOptions, @@ -27,19 +27,19 @@ describe('CommonCartridgeOrganizationBuilder', () => { identifier: 'sub-sub-organization-identifier', version: CommonCartridgeVersion.V_1_1_0, }; - const resource1Props: CommonCartridgeResourceProps = { + const resource1Props: CommonCartridgeResourcePropsInternal = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'resource-1-identifier', title: 'resource-1-title', html: '

resource-1-html

', }; - const resource2Props: CommonCartridgeResourceProps = { + const resource2Props: CommonCartridgeResourcePropsInternal = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'resource-2-identifier', title: 'resource-2-title', html: '

resource-2-html

', }; - const resource3Props: CommonCartridgeResourceProps = { + const resource3Props: CommonCartridgeResourcePropsInternal = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'resource-3-identifier', title: 'resource-3-title', diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts index 0cbf6cdfdcf..186b13431bd 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts @@ -2,9 +2,9 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { + CommonCartridgeResourceFactory, CommonCartridgeResourceProps, - CommonCartridgeResourceVersionFactory, -} from '../resources/common-cartridge-resource-version-factory'; +} from '../resources/common-cartridge-resource-factory'; import { OmitVersionAndFolder } from '../utils'; export type CommonCartridgeOrganizationBuilderOptions = { @@ -41,11 +41,11 @@ export class CommonCartridgeOrganizationBuilder { return child; } - public addResource(props: OmitVersionAndFolder): CommonCartridgeOrganizationBuilder { - const resource = CommonCartridgeResourceVersionFactory.createFactory({ - ...props, + public addResource(props: CommonCartridgeResourceProps): CommonCartridgeOrganizationBuilder { + const resource = CommonCartridgeResourceFactory.createResource({ version: this.options.version, folder: this.folder, + ...props, }); this.items.push(resource); diff --git a/apps/server/src/modules/learnroom/common-cartridge/index.ts b/apps/server/src/modules/learnroom/common-cartridge/index.ts index 8bf745df6ab..88f52e43c23 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/index.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/index.ts @@ -7,6 +7,4 @@ export { } from './common-cartridge.enums'; export { CommonCartridgeElementPropsV110 } from './elements/v1.1.0/common-cartridge-element-factory'; export { CommonCartridgeElementProps130 } from './elements/v1.3.0/common-cartridge-element-factory'; -export { CommonCartridgeResourcePropsV110 } from './resources/v1.1.0/common-cartridge-resource-factory'; -export { CommonCartridgeResourcePropsV130 } from './resources/v1.3.0/common-cartridge-resource-factory'; export { OmitVersion } from './utils'; diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts index 6ad7d9d5f3f..7cb3e5ce926 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts @@ -5,7 +5,10 @@ import { CommonCartridgeManifestElementProps, CommonCartridgeManifestResource, } from './common-cartridge-manifest-resource'; -import { CommonCartridgeResourceFactory, CommonCartridgeResourceProps } from './common-cartridge-resource-factory'; +import { + CommonCartridgeResourceFactory, + CommonCartridgeResourcePropsInternal, +} from './common-cartridge-resource-factory'; describe('CommonCartridgeManifestResource', () => { const metadataElementPropsVersion1 = { @@ -21,7 +24,7 @@ describe('CommonCartridgeManifestResource', () => { items: [], }; - const webcontentResourcePropsVersion1: CommonCartridgeResourceProps = { + const webcontentResourcePropsVersion1: CommonCartridgeResourcePropsInternal = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'webcontent-v1', title: 'Webcontent Version 1', @@ -55,7 +58,7 @@ describe('CommonCartridgeManifestResource', () => { items: [], }; - const webcontentResourcePropsVersion3: CommonCartridgeResourceProps = { + const webcontentResourcePropsVersion3: CommonCartridgeResourcePropsInternal = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'webcontent-v3', title: 'Webcontent Version 3', diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts new file mode 100644 index 00000000000..0143c30e233 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts @@ -0,0 +1,54 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResourceFactory } from './common-cartridge-resource-factory'; +import { + CommonCartridgeWebContentResourcePropsV110, + CommonCartridgeWebContentResourceV110, +} from './v1.1.0/common-cartridge-web-content-resource'; +import { + CommonCartridgeWebContentResourcePropsV130, + CommonCartridgeWebContentResourceV130, +} from './v1.3.0/common-cartridge-web-content-resource'; + +describe('CommonCartridgeResourceVersion', () => { + describe('createResource', () => { + describe('when Common Cartridge version is supported', () => { + it('should return v1.1.0 resource', () => { + const result = CommonCartridgeResourceFactory.createResource({ + version: CommonCartridgeVersion.V_1_1_0, + type: CommonCartridgeResourceType.WEB_CONTENT, + } as CommonCartridgeWebContentResourcePropsV110); + + expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV110); + }); + + it('should return v1.3.0 resource', () => { + const result = CommonCartridgeResourceFactory.createResource({ + version: CommonCartridgeVersion.V_1_3_0, + type: CommonCartridgeResourceType.WEB_CONTENT, + } as CommonCartridgeWebContentResourcePropsV130); + + expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV130); + }); + }); + + describe('when versions is not supported', () => { + it('should throw InternalServerErrorException', () => { + const notSupportedVersions = [ + CommonCartridgeVersion.V_1_0_0, + CommonCartridgeVersion.V_1_2_0, + CommonCartridgeVersion.V_1_4_0, + ]; + + notSupportedVersions.forEach((version) => { + expect(() => + CommonCartridgeResourceFactory.createResource({ + version, + type: CommonCartridgeResourceType.WEB_CONTENT, + } as CommonCartridgeWebContentResourcePropsV110) + ).toThrow(InternalServerErrorException); + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts new file mode 100644 index 00000000000..c7f8fbb03a2 --- /dev/null +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts @@ -0,0 +1,40 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; +import { OmitVersionAndFolder, createVersionNotSupportedError } from '../utils'; +import { CommonCartridgeManifestResourcePropsV110 } from './v1.1.0/common-cartridge-manifest-resource'; +import { CommonCartridgeResourceFactoryV110 } from './v1.1.0/common-cartridge-resource-factory'; +import { CommonCartridgeWebContentResourcePropsV110 } from './v1.1.0/common-cartridge-web-content-resource'; +import { CommonCartridgeWebLinkResourcePropsV110 } from './v1.1.0/common-cartridge-web-link-resource'; +import { CommonCartridgeManifestResourcePropsV130 } from './v1.3.0/common-cartridge-manifest-resource'; +import { CommonCartridgeResourceFactoryV130 } from './v1.3.0/common-cartridge-resource-factory'; +import { CommonCartridgeWebContentResourcePropsV130 } from './v1.3.0/common-cartridge-web-content-resource'; +import { CommonCartridgeWebLinkResourcePropsV130 } from './v1.3.0/common-cartridge-web-link-resource'; + +export type CommonCartridgeResourceProps = + | OmitVersionAndFolder + | OmitVersionAndFolder + | OmitVersionAndFolder + | OmitVersionAndFolder; + +type CommonCartridgeResourcePropsInternal = + | CommonCartridgeManifestResourcePropsV110 + | CommonCartridgeWebContentResourcePropsV110 + | CommonCartridgeWebLinkResourcePropsV110 + | CommonCartridgeManifestResourcePropsV130 + | CommonCartridgeWebContentResourcePropsV130 + | CommonCartridgeWebLinkResourcePropsV130; + +export class CommonCartridgeResourceFactory { + public static createResource(props: CommonCartridgeResourcePropsInternal): CommonCartridgeResource | never { + const { version } = props; + + switch (version) { + case CommonCartridgeVersion.V_1_1_0: + return CommonCartridgeResourceFactoryV110.createResource(props); + case CommonCartridgeVersion.V_1_3_0: + return CommonCartridgeResourceFactoryV130.createResource(props); + default: + throw createVersionNotSupportedError(version); + } + } +} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.spec.ts deleted file mode 100644 index 8ec02bd37ba..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.spec.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { InternalServerErrorException } from '@nestjs/common'; -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeResourceVersionFactory } from './common-cartridge-resource-version-factory'; -import { CommonCartridgeResourceFactoryV110 } from './v1.1.0/common-cartridge-resource-factory'; -import { CommonCartridgeResourceFactoryV130 } from './v1.3.0/common-cartridge-resource-factory'; - -describe('CommonCartridgeResourceVersionFactory', () => { - describe('createFactory', () => { - describe('when versions is supported', () => { - it('should return v1.1.0 factory', () => { - const result = CommonCartridgeResourceVersionFactory.createFactory(CommonCartridgeVersion.V_1_1_0); - - expect(result).toBeDefined(); - expect(result).toBeInstanceOf(CommonCartridgeResourceFactoryV110); - }); - - it('should return v1.3.0 factory', () => { - const result = CommonCartridgeResourceVersionFactory.createFactory(CommonCartridgeVersion.V_1_3_0); - - expect(result).toBeDefined(); - expect(result).toBeInstanceOf(CommonCartridgeResourceFactoryV130); - }); - }); - - describe('when versions is not supported', () => { - it('should throw InternalServerErrorException', () => { - const notSupportedVersions = [ - CommonCartridgeVersion.V_1_0_0, - CommonCartridgeVersion.V_1_2_0, - CommonCartridgeVersion.V_1_4_0, - ]; - - notSupportedVersions.forEach((version) => { - expect(() => CommonCartridgeResourceVersionFactory.createFactory(version)).toThrow( - InternalServerErrorException - ); - }); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts deleted file mode 100644 index cc911ccaad5..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-version-factory.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { createVersionNotSupportedError } from '../utils'; -import { - CommonCartridgeResourceFactoryV110, - CommonCartridgeResourcePropsV110, -} from './v1.1.0/common-cartridge-resource-factory'; -import { - CommonCartridgeResourceFactoryV130, - CommonCartridgeResourcePropsV130, -} from './v1.3.0/common-cartridge-resource-factory'; - -export type CommonCartridgeResourceProps = CommonCartridgeResourcePropsV110 | CommonCartridgeResourcePropsV130; - -export class CommonCartridgeResourceVersionFactory { - public static createFactory(props: CommonCartridgeResourceProps): CommonCartridgeResource { - const { version } = props; - - switch (version) { - case CommonCartridgeVersion.V_1_1_0: - return CommonCartridgeResourceFactoryV110.getInstance().createResource(props); - case CommonCartridgeVersion.V_1_3_0: - return CommonCartridgeResourceFactoryV130.getInstance().createResource(props); - default: - throw createVersionNotSupportedError(version); - } - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts index b8971cdeb89..f84972637a2 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts @@ -9,17 +9,10 @@ import { CommonCartridgeWebContentResourceV110 } from './common-cartridge-web-co import { CommonCartridgeWebLinkResourceV110 } from './common-cartridge-web-link-resource'; describe('CommonCartridgeResourceFactoryV110', () => { - const setup = () => { - const sut = new CommonCartridgeResourceFactoryV110(); - - return { sut }; - }; - describe('createResource', () => { describe('when creating resources from props', () => { it('should return web content resource', () => { - const { sut } = setup(); - const result = sut.createResource({ + const result = CommonCartridgeResourceFactoryV110.createResource({ type: CommonCartridgeResourceType.WEB_CONTENT, version: CommonCartridgeVersion.V_1_1_0, folder: faker.string.uuid(), @@ -34,8 +27,7 @@ describe('CommonCartridgeResourceFactoryV110', () => { }); it('should return web link resource', () => { - const { sut } = setup(); - const result = sut.createResource({ + const result = CommonCartridgeResourceFactoryV110.createResource({ type: CommonCartridgeResourceType.WEB_LINK, version: CommonCartridgeVersion.V_1_1_0, folder: faker.string.uuid(), diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts index 3971ce7215b..b447a5e9bb0 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts @@ -14,19 +14,13 @@ import { CommonCartridgeWebLinkResourceV110, } from './common-cartridge-web-link-resource'; -export type CommonCartridgeResourcePropsV110 = +type CommonCartridgeResourcePropsV110 = | CommonCartridgeManifestResourcePropsV110 | CommonCartridgeWebContentResourcePropsV110 | CommonCartridgeWebLinkResourcePropsV110; export class CommonCartridgeResourceFactoryV110 { - public static readonly instance = new CommonCartridgeResourceFactoryV110(); - - public static getInstance(): CommonCartridgeResourceFactoryV110 { - return this.instance; - } - - public createResource(props: CommonCartridgeResourcePropsV110): CommonCartridgeResource { + public static createResource(props: CommonCartridgeResourcePropsV110): CommonCartridgeResource { const { type } = props; switch (type) { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts index cf57a27d14b..60a9c0e5946 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts @@ -9,17 +9,10 @@ import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-co import { CommonCartridgeWebLinkResourceV130 } from './common-cartridge-web-link-resource'; describe('CommonCartridgeResourceFactoryV130', () => { - const setup = () => { - const sut = new CommonCartridgeResourceFactoryV130(); - - return { sut }; - }; - describe('createResource', () => { describe('when creating resources from props', () => { it('shoul return web content resource', () => { - const { sut } = setup(); - const result = sut.createResource({ + const result = CommonCartridgeResourceFactoryV130.createResource({ type: CommonCartridgeResourceType.WEB_CONTENT, version: CommonCartridgeVersion.V_1_3_0, folder: faker.string.uuid(), @@ -33,8 +26,7 @@ describe('CommonCartridgeResourceFactoryV130', () => { }); it('shoul return web link resource', () => { - const { sut } = setup(); - const result = sut.createResource({ + const result = CommonCartridgeResourceFactoryV130.createResource({ type: CommonCartridgeResourceType.WEB_LINK, version: CommonCartridgeVersion.V_1_3_0, folder: faker.string.uuid(), @@ -45,7 +37,6 @@ describe('CommonCartridgeResourceFactoryV130', () => { windowFeatures: faker.lorem.words(), }); - expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeWebLinkResourceV130); }); }); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts index 6468bc2422b..3c719376ca9 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts @@ -14,19 +14,13 @@ import { CommonCartridgeWebLinkResourceV130, } from './common-cartridge-web-link-resource'; -export type CommonCartridgeResourcePropsV130 = +type CommonCartridgeResourcePropsV130 = | CommonCartridgeManifestResourcePropsV130 | CommonCartridgeWebContentResourcePropsV130 | CommonCartridgeWebLinkResourcePropsV130; export class CommonCartridgeResourceFactoryV130 { - public static readonly instance = new CommonCartridgeResourceFactoryV130(); - - public static getInstance(): CommonCartridgeResourceFactoryV130 { - return this.instance; - } - - public createResource(props: CommonCartridgeResourcePropsV130): CommonCartridgeResource { + public static createResource(props: CommonCartridgeResourcePropsV130): CommonCartridgeResource { const { type } = props; switch (type) { From 6ce9cf8dffb324808ee2304e633fca2b1e30a8cb Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 15 Dec 2023 07:55:02 +0100 Subject: [PATCH 087/177] EW-539 Move common cartridge to modules --- TODO.md | 1 + .../common-cartridge/README.md | 30 +++++++++---------- .../common-cartridge-file-builder.spec.ts | 0 .../builders/common-cartridge-file-builder.ts | 0 ...mon-cartridge-organization-builder.spec.ts | 0 .../common-cartridge-organization-builder.ts | 0 .../common-cartridge.enums.ts | 0 .../common-cartridge.module.ts | 8 +++++ ...-cartridge-element-version-factory.spec.ts | 0 ...ommon-cartridge-element-version-factory.ts | 0 .../common-cartridge-element-factory.spec.ts | 0 .../common-cartridge-element-factory.ts | 0 .../common-cartridge-metadata-element.spec.ts | 0 .../common-cartridge-metadata-element.ts | 0 ...mon-cartridge-organization-element.spec.ts | 0 .../common-cartridge-organization-element.ts | 0 ...idge-organizations-wrapper-element.spec.ts | 0 ...cartridge-organizations-wrapper-element.ts | 0 ...artridge-resources-wrapper-element.spec.ts | 0 ...mon-cartridge-resources-wrapper-element.ts | 0 .../common-cartridge-element-factory.spec.ts | 0 .../common-cartridge-element-factory.ts | 0 .../common-cartridge-metadata-element.spec.ts | 0 .../common-cartridge-metadata-element.ts | 0 ...mon-cartridge-organization-element.spec.ts | 0 .../common-cartridge-organization-element.ts | 0 ...idge-organizations-wrapper-element.spec.ts | 0 ...cartridge-organizations-wrapper-element.ts | 0 ...artridge-resources-wrapper-element.spec.ts | 0 ...mon-cartridge-resources-wrapper-element.ts | 0 .../{learnroom => }/common-cartridge/index.ts | 0 .../common-cartridge-element.interface.ts | 0 .../common-cartridge-resource.interface.ts | 0 .../common-cartridge-resource-factory.spec.ts | 0 .../common-cartridge-resource-factory.ts | 0 ...common-cartridge-manifest-resource.spec.ts | 0 .../common-cartridge-manifest-resource.ts | 0 .../common-cartridge-resource-factory.spec.ts | 0 .../common-cartridge-resource-factory.ts | 0 ...mon-cartridge-web-content-resource.spec.ts | 2 +- .../common-cartridge-web-content-resource.ts | 0 ...common-cartridge-web-link-resource.spec.ts | 0 .../common-cartridge-web-link-resource.ts | 0 ...common-cartridge-manifest-resource.spec.ts | 0 .../common-cartridge-manifest-resource.ts | 0 .../common-cartridge-resource-factory.spec.ts | 0 .../common-cartridge-resource-factory.ts | 0 ...mon-cartridge-web-content-resource.spec.ts | 0 .../common-cartridge-web-content-resource.ts | 0 ...common-cartridge-web-link-resource.spec.ts | 0 .../common-cartridge-web-link-resource.ts | 0 .../common-cartridge/utils.spec.ts | 0 .../{learnroom => }/common-cartridge/utils.ts | 0 ...common-cartridge-manifest-resource.spec.ts | 10 +++---- .../common-cartridge-manifest-resource.ts | 8 ++--- .../controller/dto/course.query.params.ts | 2 +- .../mapper/common-cartridge.mapper.spec.ts | 2 +- .../mapper/common-cartridge.mapper.ts | 2 +- .../common-cartridge-export.service.spec.ts | 2 +- .../common-cartridge-export.service.ts | 2 +- .../learnroom/uc/course-export.uc.spec.ts | 10 +++---- .../modules/learnroom/uc/course-export.uc.ts | 6 ++-- 62 files changed, 47 insertions(+), 38 deletions(-) rename apps/server/src/modules/{learnroom => }/common-cartridge/README.md (96%) rename apps/server/src/modules/{learnroom => }/common-cartridge/builders/common-cartridge-file-builder.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/builders/common-cartridge-file-builder.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/builders/common-cartridge-organization-builder.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/builders/common-cartridge-organization-builder.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/common-cartridge.enums.ts (100%) create mode 100644 apps/server/src/modules/common-cartridge/common-cartridge.module.ts rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/common-cartridge-element-version-factory.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/index.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/interfaces/common-cartridge-element.interface.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/interfaces/common-cartridge-resource.interface.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/common-cartridge-resource-factory.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/common-cartridge-resource-factory.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts (96%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/utils.spec.ts (100%) rename apps/server/src/modules/{learnroom => }/common-cartridge/utils.ts (100%) diff --git a/TODO.md b/TODO.md index 3b3547bf224..33dfa4e805b 100644 --- a/TODO.md +++ b/TODO.md @@ -102,3 +102,4 @@ - move in separate module - check index.ts - move xml files into test-assets folder +- Adjust export-service diff --git a/apps/server/src/modules/learnroom/common-cartridge/README.md b/apps/server/src/modules/common-cartridge/README.md similarity index 96% rename from apps/server/src/modules/learnroom/common-cartridge/README.md rename to apps/server/src/modules/common-cartridge/README.md index 23e9ebaaa5c..d2831ef17f1 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/README.md +++ b/apps/server/src/modules/common-cartridge/README.md @@ -1,15 +1,15 @@ -# Common Cartridge Module - -> This module contains all functionality to build an - -## XML Schema Namespaces and Definitions for Resources - -| Resource Type | XML Namespace | XSD Locations | -|:-|:-|:-| -| Manifest 1.1.0 || | -| Web Content 1.1.0 | - | - | -| Web Link 1.1.0 | http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 | | -| LTI | | | -| Manifest 1.3.0 || | -| Web Content 1.3.0 || | -| Web Link 1.3.0 || | +# Common Cartridge Module + +> This module contains all functionality to build an + +## XML Schema Namespaces and Definitions for Resources + +| Resource Type | XML Namespace | XSD Locations | +|:-|:-|:-| +| Manifest 1.1.0 || | +| Web Content 1.1.0 | - | - | +| Web Link 1.1.0 | http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 | | +| LTI | | | +| Manifest 1.3.0 || | +| Web Content 1.3.0 || | +| Web Link 1.3.0 || | diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.spec.ts rename to apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-file-builder.ts rename to apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.spec.ts rename to apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/builders/common-cartridge-organization-builder.ts rename to apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts b/apps/server/src/modules/common-cartridge/common-cartridge.enums.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/common-cartridge.enums.ts rename to apps/server/src/modules/common-cartridge/common-cartridge.enums.ts diff --git a/apps/server/src/modules/common-cartridge/common-cartridge.module.ts b/apps/server/src/modules/common-cartridge/common-cartridge.module.ts new file mode 100644 index 00000000000..5eecb7cc628 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/common-cartridge.module.ts @@ -0,0 +1,8 @@ +import { Module } from '@nestjs/common'; + +@Module({ + imports: [], + providers: [], + exports: [], +}) +export class CommonCartridgeModule {} diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts rename to apps/server/src/modules/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts b/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-version-factory.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/common-cartridge-element-version-factory.ts rename to apps/server/src/modules/common-cartridge/elements/common-cartridge-element-version-factory.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts rename to apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts rename to apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts rename to apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts rename to apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts rename to apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts rename to apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts rename to apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts rename to apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts rename to apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts rename to apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts rename to apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts rename to apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts rename to apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts rename to apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts rename to apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts rename to apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts rename to apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts rename to apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts rename to apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts rename to apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/index.ts b/apps/server/src/modules/common-cartridge/index.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/index.ts rename to apps/server/src/modules/common-cartridge/index.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-element.interface.ts rename to apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource.interface.ts b/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-resource.interface.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/interfaces/common-cartridge-resource.interface.ts rename to apps/server/src/modules/common-cartridge/interfaces/common-cartridge-resource.interface.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.spec.ts rename to apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-resource-factory.ts rename to apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts rename to apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts rename to apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts rename to apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts rename to apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts similarity index 96% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts rename to apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts index d3770b677b7..44bf0bccac2 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts @@ -3,7 +3,7 @@ import { CommonCartridgeIntendedUseType, CommonCartridgeResourceType, CommonCartridgeVersion, -} from '../../common-cartridge.enums'; +} from '../../../learnroom/common-cartridge/common-cartridge.enums'; import { CommonCartridgeWebContentResourcePropsV110, CommonCartridgeWebContentResourceV110, diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts rename to apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts rename to apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts rename to apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts rename to apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts rename to apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts rename to apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts rename to apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts rename to apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts rename to apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts rename to apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts rename to apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.spec.ts b/apps/server/src/modules/common-cartridge/utils.spec.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/utils.spec.ts rename to apps/server/src/modules/common-cartridge/utils.spec.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/utils.ts b/apps/server/src/modules/common-cartridge/utils.ts similarity index 100% rename from apps/server/src/modules/learnroom/common-cartridge/utils.ts rename to apps/server/src/modules/common-cartridge/utils.ts diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts index 7cb3e5ce926..b306b69cd5f 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts @@ -1,14 +1,14 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../../common-cartridge/common-cartridge.enums'; +import { + CommonCartridgeResourceFactory, + CommonCartridgeResourcePropsInternal, +} from '../../../common-cartridge/resources/common-cartridge-resource-factory'; import { CommonCartridgeMetadataElement } from '../elements/common-cartridge-metadata-element'; import { CommonCartridgeOrganizationElement } from '../elements/common-cartridge-organization-element'; import { CommonCartridgeManifestElementProps, CommonCartridgeManifestResource, } from './common-cartridge-manifest-resource'; -import { - CommonCartridgeResourceFactory, - CommonCartridgeResourcePropsInternal, -} from './common-cartridge-resource-factory'; describe('CommonCartridgeManifestResource', () => { const metadataElementPropsVersion1 = { diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts index 0ec35026382..0bbad3ab0bf 100644 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts @@ -1,9 +1,9 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeVersion } from '../../../common-cartridge/common-cartridge.enums'; +import { CommonCartridgeElement } from '../../../common-cartridge/interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '../../../common-cartridge/interfaces/common-cartridge-resource.interface'; +import { createVersionNotSupportedError } from '../../../common-cartridge/utils'; import { CommonCartridgeOrganizationsWrapperElement } from '../elements/common-cartridge-organizations-wrapper-element'; import { CommonCartridgeResourcesWrapperElement } from '../elements/common-cartridge-resources-wrapper-element'; -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { createVersionNotSupportedError } from '../utils'; export type CommonCartridgeManifestElementProps = { version: CommonCartridgeVersion; diff --git a/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts b/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts index 59b99af2f33..309a30b4b5c 100644 --- a/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts +++ b/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts @@ -1,6 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; import { IsString, Matches } from 'class-validator'; -import { CommonCartridgeVersion } from '../../common-cartridge'; +import { CommonCartridgeVersion } from '../../../common-cartridge'; export class CourseQueryParams { @IsString() diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index 77747505f31..75c1ac7e9fb 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -10,7 +10,7 @@ import { CommonCartridgeResourceProps, CommonCartridgeResourceType, OmitVersion, -} from '../common-cartridge'; +} from '../../common-cartridge'; import { LearnroomConfig } from '../learnroom.config'; import { CommonCartridgeMapper } from './common-cartridge.mapper'; diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 2f77afa8236..0f822728be8 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -8,7 +8,7 @@ import { CommonCartridgeResourceProps, CommonCartridgeResourceType, OmitVersion, -} from '../common-cartridge'; +} from '../../common-cartridge'; import { LearnroomConfig } from '../learnroom.config'; @Injectable() diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index bba078b26bf..a785dc4023b 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -6,7 +6,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ComponentType, Course, LessonEntity, Task } from '@shared/domain'; import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing'; import AdmZip from 'adm-zip'; -import { CommonCartridgeVersion } from '../common-cartridge'; +import { CommonCartridgeVersion } from '../../common-cartridge'; describe('CommonCartridgeExportService', () => { let module: TestingModule; diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index a74ac24c206..56ec580e887 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -6,7 +6,7 @@ import { CommonCartridgeFileBuilder, CommonCartridgeOrganizationBuilder, CommonCartridgeVersion, -} from '../common-cartridge'; +} from '../../common-cartridge'; import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; import { CourseService } from './course.service'; diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts index 8ca36158f5d..812fffa12cd 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts @@ -1,11 +1,11 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { createMock, DeepMocked } from '@golevelup/ts-jest'; -import { CommonCartridgeExportService } from '@modules/learnroom/service/common-cartridge-export.service'; +import { DeepMocked, createMock } from '@golevelup/ts-jest'; import { AuthorizationReferenceService } from '@modules/authorization/domain'; -import { ObjectId } from 'bson'; +import { CommonCartridgeExportService } from '@modules/learnroom/service/common-cartridge-export.service'; import { ForbiddenException } from '@nestjs/common'; +import { Test, TestingModule } from '@nestjs/testing'; +import { ObjectId } from 'bson'; +import { CommonCartridgeVersion } from '../../common-cartridge'; import { CourseExportUc } from './course-export.uc'; -import { CommonCartridgeVersion } from '../common-cartridge'; describe('CourseExportUc', () => { let module: TestingModule; diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.ts index 758b1b550d7..c714db550da 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.ts @@ -1,8 +1,8 @@ +import { AuthorizationContextBuilder } from '@modules/authorization'; +import { AuthorizableReferenceType, AuthorizationReferenceService } from '@modules/authorization/domain'; import { Injectable } from '@nestjs/common'; import { EntityId, Permission } from '@shared/domain'; -import { AuthorizationContextBuilder } from '@modules/authorization'; -import { AuthorizationReferenceService, AuthorizableReferenceType } from '@modules/authorization/domain'; -import { CommonCartridgeVersion } from '../common-cartridge'; +import { CommonCartridgeVersion } from '../../common-cartridge'; import { CommonCartridgeExportService } from '../service/common-cartridge-export.service'; @Injectable() From 344160482ea55696e98f710072fb1386c34e7d99 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 15 Dec 2023 09:05:32 +0100 Subject: [PATCH 088/177] EW-539 Clean up --- TODO.md | 2 +- .../common-cartridge-resource-factory.ts | 2 +- .../modules/common-cartridge/review-notes.md | 5 + ...common-cartridge-manifest-resource.spec.ts | 172 ------------------ .../common-cartridge-manifest-resource.ts | 76 -------- .../common-cartridge/review-notes.md | 5 - 6 files changed, 7 insertions(+), 255 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/review-notes.md delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts delete mode 100644 apps/server/src/modules/learnroom/common-cartridge/review-notes.md diff --git a/TODO.md b/TODO.md index 33dfa4e805b..b7485f24053 100644 --- a/TODO.md +++ b/TODO.md @@ -99,7 +99,7 @@ - createIdentifier method - merge main - review.md and comments -- move in separate module +- ~~move in separate module~~ - check index.ts - move xml files into test-assets folder - Adjust export-service diff --git a/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.ts index c7f8fbb03a2..6b6e7322465 100644 --- a/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.ts @@ -13,7 +13,7 @@ import { CommonCartridgeWebLinkResourcePropsV130 } from './v1.3.0/common-cartrid export type CommonCartridgeResourceProps = | OmitVersionAndFolder | OmitVersionAndFolder - | OmitVersionAndFolder + | OmitVersionAndFolder | OmitVersionAndFolder; type CommonCartridgeResourcePropsInternal = diff --git a/apps/server/src/modules/common-cartridge/review-notes.md b/apps/server/src/modules/common-cartridge/review-notes.md new file mode 100644 index 00000000000..42c753dc4c9 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/review-notes.md @@ -0,0 +1,5 @@ +# review 04.12.23 + +- ~~put all course-independent code into a separate "common-cartridge" module~~ +- import common-cartridge into learnroom +- adjust all tests to avoid global variables. create factories where useful, and use setup function instead of beforeAll diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts deleted file mode 100644 index b306b69cd5f..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.spec.ts +++ /dev/null @@ -1,172 +0,0 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../../common-cartridge/common-cartridge.enums'; -import { - CommonCartridgeResourceFactory, - CommonCartridgeResourcePropsInternal, -} from '../../../common-cartridge/resources/common-cartridge-resource-factory'; -import { CommonCartridgeMetadataElement } from '../elements/common-cartridge-metadata-element'; -import { CommonCartridgeOrganizationElement } from '../elements/common-cartridge-organization-element'; -import { - CommonCartridgeManifestElementProps, - CommonCartridgeManifestResource, -} from './common-cartridge-manifest-resource'; - -describe('CommonCartridgeManifestResource', () => { - const metadataElementPropsVersion1 = { - version: CommonCartridgeVersion.V_1_1_0, - title: 'Manifest v1', - creationDate: new Date(), - copyrightOwners: ['Owner1Version1', 'Owner2Version2'], - }; - - const organizationElementPropsVersion1 = { - identifier: 'organization-v1', - title: 'Organization v1', - items: [], - }; - - const webcontentResourcePropsVersion1: CommonCartridgeResourcePropsInternal = { - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: 'webcontent-v1', - title: 'Webcontent Version 1', - html: '

Webcontent v1

', - }; - - const webcontentResourceVersion1 = CommonCartridgeResourceFactory.create({ - ...webcontentResourcePropsVersion1, - version: CommonCartridgeVersion.V_1_1_0, - folder: 'webcontent', - }); - - const propsOfVersion1: CommonCartridgeManifestElementProps = { - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'manifest-v1', - metadata: new CommonCartridgeMetadataElement(metadataElementPropsVersion1), - organizations: [new CommonCartridgeOrganizationElement(organizationElementPropsVersion1)], - resources: [webcontentResourceVersion1], - }; - - const metadataElementPropsVersion3 = { - version: CommonCartridgeVersion.V_1_3_0, - title: 'Manifest v3', - creationDate: new Date(), - copyrightOwners: ['Owner1Version3', 'Owner2Version3'], - }; - - const organizationElementPropsVersion3 = { - identifier: 'organization-v3', - title: 'Organization v3', - items: [], - }; - - const webcontentResourcePropsVersion3: CommonCartridgeResourcePropsInternal = { - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: 'webcontent-v3', - title: 'Webcontent Version 3', - html: '

Webcontent v3

', - }; - - const webcontentResourceVersion3 = CommonCartridgeResourceFactory.create({ - ...webcontentResourcePropsVersion3, - version: CommonCartridgeVersion.V_1_3_0, - folder: 'webcontent', - }); - - const propsOfVersion3: CommonCartridgeManifestElementProps = { - version: CommonCartridgeVersion.V_1_3_0, - identifier: 'manifest-v3', - metadata: new CommonCartridgeMetadataElement(metadataElementPropsVersion3), - organizations: [new CommonCartridgeOrganizationElement(organizationElementPropsVersion3)], - resources: [webcontentResourceVersion3], - }; - - const manifestResourceV1 = new CommonCartridgeManifestResource(propsOfVersion1); - const manifestResourceV3 = new CommonCartridgeManifestResource(propsOfVersion3); - - describe('canInline', () => { - // AI next 28 lines - describe('when common cartridge version 1.1', () => { - it('should return false', () => { - expect(manifestResourceV1.canInline()).toBe(false); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return false', () => { - expect(manifestResourceV3.canInline()).toBe(false); - }); - }); - }); - - describe('getFilePath', () => { - describe('when common cartridge version 1.1', () => { - it('should return the file path regarding version 1.1', () => { - const filePathV1 = manifestResourceV1.getFilePath(); - expect(filePathV1).toBe('imsmanifest.xml'); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return the file path regarding version 1.3', () => { - const filePathV3 = manifestResourceV3.getFilePath(); - expect(filePathV3).toBe('imsmanifest.xml'); - }); - }); - }); - - describe('getFileContent', () => { - describe('when common cartridge version 1.1', () => { - it('should return the file content regarding version 1.1', () => { - const fileContentV1 = manifestResourceV1.getFileContent(); - expect(fileContentV1).toContain('manifest'); - expect(fileContentV1).toContain('metadata'); - expect(fileContentV1).toContain('organizations'); - expect(fileContentV1).toContain('resources'); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return the file content regarding version 1.3', () => { - const fileContentV3 = manifestResourceV3.getFileContent(); - expect(fileContentV3).toContain('manifest'); - expect(fileContentV3).toContain('metadata'); - expect(fileContentV3).toContain('organizations'); - expect(fileContentV3).toContain('resources'); - }); - }); - }); - - describe('getManifestXmlObject', () => { - describe('when common cartridge version 1.1', () => { - it('should return the manifest XML object regarding version 1.1', () => { - const transformedV1 = manifestResourceV1.getManifestXmlObject(); - - expect(transformedV1).toContain('manifest'); - - expect(transformedV1).toStrictEqual({ - manifest: { - $: { - identifier: 'manifest-v1', - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', - 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', - 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd ' + - 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ', - }, - metadata: {}, - organizations: {}, - resources: {}, - }, - }); - }); - }); - - describe('when common cartridge version 1.3', () => { - it('should return the manifest XML object regarding version 1.3', () => { - const transformedV3 = manifestResourceV3.getManifestXmlObject(); - }); - }); - }); -}); diff --git a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts b/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts deleted file mode 100644 index 0bbad3ab0bf..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/resources/common-cartridge-manifest-resource.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { CommonCartridgeVersion } from '../../../common-cartridge/common-cartridge.enums'; -import { CommonCartridgeElement } from '../../../common-cartridge/interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '../../../common-cartridge/interfaces/common-cartridge-resource.interface'; -import { createVersionNotSupportedError } from '../../../common-cartridge/utils'; -import { CommonCartridgeOrganizationsWrapperElement } from '../elements/common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElement } from '../elements/common-cartridge-resources-wrapper-element'; - -export type CommonCartridgeManifestElementProps = { - version: CommonCartridgeVersion; - identifier: string; - metadata: CommonCartridgeElement; - organizations: CommonCartridgeElement[]; - resources: CommonCartridgeElement[]; -}; - -export class CommonCartridgeManifestResource implements CommonCartridgeResource { - constructor(private readonly props: CommonCartridgeManifestElementProps) {} - - public canInline(): boolean { - return false; - } - - public getFilePath(): string { - return 'imsmanifest.xml'; - } - - public getFileContent(): string { - return this.xmlBuilder.buildObject(this.getManifestXmlObject()); - } - - public getManifestXmlObject(): Record { - return { - manifest: { - $: this.getXmlNamespacesByVersion(), - metadata: this.props.metadata.getManifestXmlObject(), - organizations: new CommonCartridgeOrganizationsWrapperElement( - this.props.organizations - ).getManifestXmlObject(), - resources: new CommonCartridgeResourcesWrapperElement(this.props.resources).getManifestXmlObject(), - }, - }; - } - - private getXmlNamespacesByVersion(): Record { - switch (this.props.version) { - case CommonCartridgeVersion.V_1_1_0: - return { - identifier: this.props.identifier, - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', - 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', - 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd ' + - 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ', - }; - case CommonCartridgeVersion.V_1_3_0: - return { - identifier: this.props.identifier, - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1', - 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest', - 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource', - 'xmlns:ext': 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2', - 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation': - 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lomresource_v1p0.xsd ' + - 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd ' + - 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_cpextensionv1p2_v1p0.xsd', - }; - default: - throw createVersionNotSupportedError(this.props.version); - } - } -} diff --git a/apps/server/src/modules/learnroom/common-cartridge/review-notes.md b/apps/server/src/modules/learnroom/common-cartridge/review-notes.md deleted file mode 100644 index 5c2d061949b..00000000000 --- a/apps/server/src/modules/learnroom/common-cartridge/review-notes.md +++ /dev/null @@ -1,5 +0,0 @@ -# review 04.12.23 - -- put all course-independent code into a seperate "common-cartrige" module -- import common-cartrige into learnroom -- adjust all tests to avoid global variables. create factories where useful, and use setup function instead of beforeAll \ No newline at end of file From c8a2fd2b8dacc3b9c07327c1294251b95b7be04c Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 15 Dec 2023 11:56:03 +0100 Subject: [PATCH 089/177] EW-539 Adjust element factories --- .../common-cartridge-organization-builder.ts | 9 ++- .../common-cartridge-element-factory.spec.ts | 56 +++++++++++++++++++ .../common-cartridge-element-factory.ts | 48 ++++++++++++++++ ...-cartridge-element-version-factory.spec.ts | 41 -------------- ...ommon-cartridge-element-version-factory.ts | 19 ------- .../common-cartridge-element-factory.spec.ts | 17 ++---- .../common-cartridge-element-factory.ts | 10 +--- .../common-cartridge-element-factory.spec.ts | 17 ++---- .../common-cartridge-element-factory.ts | 10 +--- 9 files changed, 123 insertions(+), 104 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.spec.ts create mode 100644 apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.ts delete mode 100644 apps/server/src/modules/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts delete mode 100644 apps/server/src/modules/common-cartridge/elements/common-cartridge-element-version-factory.ts diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts index 186b13431bd..a296da68d5c 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts @@ -1,4 +1,5 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeElementFactory } from '../elements/common-cartridge-element-factory'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { @@ -55,10 +56,14 @@ export class CommonCartridgeOrganizationBuilder { } public build(): CommonCartridgeElement { - return new CommonCartridgeOrganizationElement({ + const organizationElement = CommonCartridgeElementFactory.createElement({ + type: CommonCartridgeElementType.ORGANIZATION, + version: this.options.version, identifier: this.options.identifier, title: this.options.title, items: this.items, }); + + return organizationElement; } } diff --git a/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.spec.ts new file mode 100644 index 00000000000..44aca28ea54 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.spec.ts @@ -0,0 +1,56 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeElementFactory } from './common-cartridge-element-factory'; +import { + CommonCartridgeMetadataElementPropsV110, + CommonCartridgeMetadataElementV110, +} from './v1.1.0/common-cartridge-metadata-element'; +import { + CommonCartridgeMetadataElementPropsV130, + CommonCartridgeMetadataElementV130, +} from './v1.3.0/common-cartridge-metadata-element'; + +describe('CommonCartridgeElementFactory', () => { + describe('createElement', () => { + describe('when Common Cartridge versions is supported', () => { + it('should return v1.1.0 element', () => { + const result = CommonCartridgeElementFactory.createElement({ + version: CommonCartridgeVersion.V_1_1_0, + type: CommonCartridgeElementType.METADATA, + } as CommonCartridgeMetadataElementPropsV110); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV110); + }); + + it('should return v1.3.0 element', () => { + const result = CommonCartridgeElementFactory.createElement({ + version: CommonCartridgeVersion.V_1_3_0, + type: CommonCartridgeElementType.METADATA, + } as CommonCartridgeMetadataElementPropsV130); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV130); + }); + }); + + describe('when versions is not supported', () => { + it('should throw InternalServerErrorException', () => { + const notSupportedVersions = [ + CommonCartridgeVersion.V_1_0_0, + CommonCartridgeVersion.V_1_2_0, + CommonCartridgeVersion.V_1_4_0, + ]; + + notSupportedVersions.forEach((version) => { + expect(() => + CommonCartridgeElementFactory.createElement({ + version, + type: CommonCartridgeElementType.METADATA, + } as CommonCartridgeMetadataElementPropsV110) + ).toThrow(InternalServerErrorException); + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.ts new file mode 100644 index 00000000000..12bd666893a --- /dev/null +++ b/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.ts @@ -0,0 +1,48 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; +import { OmitVersionAndFolder, createVersionNotSupportedError } from '../utils'; +import { CommonCartridgeElementFactoryV110 } from './v1.1.0/common-cartridge-element-factory'; +import { CommonCartridgeMetadataElementPropsV110 } from './v1.1.0/common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElementPropsV110 } from './v1.1.0/common-cartridge-organization-element'; +import { CommonCartridgeOrganizationsWrapperElementPropsV110 } from './v1.1.0/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementPropsV110 } from './v1.1.0/common-cartridge-resources-wrapper-element'; +import { CommonCartridgeElementFactoryV130 } from './v1.3.0/common-cartridge-element-factory'; +import { CommonCartridgeMetadataElementPropsV130 } from './v1.3.0/common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElementPropsV130 } from './v1.3.0/common-cartridge-organization-element'; +import { CommonCartridgeOrganizationsWrapperElementPropsV130 } from './v1.3.0/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementPropsV130 } from './v1.3.0/common-cartridge-resources-wrapper-element'; + +export type CommonCartridgeElementProps = + | OmitVersionAndFolder + | OmitVersionAndFolder + | OmitVersionAndFolder + | OmitVersionAndFolder + | OmitVersionAndFolder + | OmitVersionAndFolder + | OmitVersionAndFolder + | OmitVersionAndFolder; + +type CommonCartridgeElementPropsInternal = + | CommonCartridgeMetadataElementPropsV110 + | CommonCartridgeOrganizationElementPropsV110 + | CommonCartridgeOrganizationsWrapperElementPropsV110 + | CommonCartridgeResourcesWrapperElementPropsV110 + | CommonCartridgeMetadataElementPropsV130 + | CommonCartridgeOrganizationElementPropsV130 + | CommonCartridgeOrganizationsWrapperElementPropsV130 + | CommonCartridgeResourcesWrapperElementPropsV130; + +export class CommonCartridgeElementFactory { + public static createElement(props: CommonCartridgeElementPropsInternal): CommonCartridgeElement | never { + const { version } = props; + + switch (version) { + case CommonCartridgeVersion.V_1_1_0: + return CommonCartridgeElementFactoryV110.createElement(props); + case CommonCartridgeVersion.V_1_3_0: + return CommonCartridgeElementFactoryV130.createElement(props); + default: + throw createVersionNotSupportedError(version); + } + } +} diff --git a/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts deleted file mode 100644 index 0852d494efa..00000000000 --- a/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-version-factory.spec.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { InternalServerErrorException } from '@nestjs/common'; -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElementVersionFactory } from './common-cartridge-element-version-factory'; -import { CommonCartridgeElementFactoryV110 } from './v1.1.0/common-cartridge-element-factory'; -import { CommonCartridgeElementFactoryV130 } from './v1.3.0/common-cartridge-element-factory'; - -describe('CommonCartridgeElementVersionFactory', () => { - describe('createFactory', () => { - describe('when versions is supported', () => { - it('should return v1.1.0 factory', () => { - const result = CommonCartridgeElementVersionFactory.createFactory(CommonCartridgeVersion.V_1_1_0); - - expect(result).toBeDefined(); - expect(result).toBeInstanceOf(CommonCartridgeElementFactoryV110); - }); - - it('should return v1.3.0 factory', () => { - const result = CommonCartridgeElementVersionFactory.createFactory(CommonCartridgeVersion.V_1_3_0); - - expect(result).toBeDefined(); - expect(result).toBeInstanceOf(CommonCartridgeElementFactoryV130); - }); - }); - - describe('when versions is not supported', () => { - it('should throw InternalServerErrorException', () => { - const notSupportedVersions = [ - CommonCartridgeVersion.V_1_0_0, - CommonCartridgeVersion.V_1_2_0, - CommonCartridgeVersion.V_1_4_0, - ]; - - notSupportedVersions.forEach((version) => { - expect(() => CommonCartridgeElementVersionFactory.createFactory(version)).toThrow( - InternalServerErrorException - ); - }); - }); - }); - }); -}); diff --git a/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-version-factory.ts b/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-version-factory.ts deleted file mode 100644 index 768ed9e7e2b..00000000000 --- a/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-version-factory.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { createVersionNotSupportedError } from '../utils'; -import { CommonCartridgeElementFactoryV110 } from './v1.1.0/common-cartridge-element-factory'; -import { CommonCartridgeElementFactoryV130 } from './v1.3.0/common-cartridge-element-factory'; - -export class CommonCartridgeElementVersionFactory { - public static createFactory( - version: CommonCartridgeVersion - ): CommonCartridgeElementFactoryV110 | CommonCartridgeElementFactoryV130 { - switch (version) { - case CommonCartridgeVersion.V_1_1_0: - return CommonCartridgeElementFactoryV110.getInstance(); - case CommonCartridgeVersion.V_1_3_0: - return CommonCartridgeElementFactoryV130.getInstance(); - default: - throw createVersionNotSupportedError(version); - } - } -} diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts index 236a3e2bc04..62fec411b8e 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts @@ -7,16 +7,10 @@ import { CommonCartridgeOrganizationsWrapperElementV110 } from './common-cartrid import { CommonCartridgeResourcesWrapperElementV110 } from './common-cartridge-resources-wrapper-element'; describe('CommonCartridgeElementFactoryV110', () => { - const setup = () => { - const sut = new CommonCartridgeElementFactoryV110(); - return { sut }; - }; - describe('createElement', () => { describe('when creating elements from props', () => { it('should return metadata element', () => { - const { sut } = setup(); - const result = sut.createElement({ + const result = CommonCartridgeElementFactoryV110.createElement({ type: CommonCartridgeElementType.METADATA, version: CommonCartridgeVersion.V_1_1_0, title: faker.lorem.words(), @@ -29,8 +23,7 @@ describe('CommonCartridgeElementFactoryV110', () => { }); it('should return organization element', () => { - const { sut } = setup(); - const result = sut.createElement({ + const result = CommonCartridgeElementFactoryV110.createElement({ type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_1_0, identifier: faker.string.uuid(), @@ -43,8 +36,7 @@ describe('CommonCartridgeElementFactoryV110', () => { }); it('should return organization wrapper element', () => { - const { sut } = setup(); - const result = sut.createElement({ + const result = CommonCartridgeElementFactoryV110.createElement({ type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, version: CommonCartridgeVersion.V_1_1_0, items: [], @@ -55,8 +47,7 @@ describe('CommonCartridgeElementFactoryV110', () => { }); it('should return resources wrapper element', () => { - const { sut } = setup(); - const result = sut.createElement({ + const result = CommonCartridgeElementFactoryV110.createElement({ type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: CommonCartridgeVersion.V_1_1_0, items: [], diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts index db68c173505..2dbf4bf2334 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts @@ -18,20 +18,14 @@ import { CommonCartridgeResourcesWrapperElementV110, } from './common-cartridge-resources-wrapper-element'; -export type CommonCartridgeElementPropsV110 = +type CommonCartridgeElementPropsV110 = | CommonCartridgeMetadataElementPropsV110 | CommonCartridgeOrganizationElementPropsV110 | CommonCartridgeOrganizationsWrapperElementPropsV110 | CommonCartridgeResourcesWrapperElementPropsV110; export class CommonCartridgeElementFactoryV110 { - public static readonly instance = new CommonCartridgeElementFactoryV110(); - - public static getInstance(): CommonCartridgeElementFactoryV110 { - return this.instance; - } - - public createElement(props: CommonCartridgeElementPropsV110): CommonCartridgeElement { + public static createElement(props: CommonCartridgeElementPropsV110): CommonCartridgeElement { const { type } = props; switch (type) { diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts index f96ff513df5..4df0d41dcb2 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts @@ -7,16 +7,10 @@ import { CommonCartridgeOrganizationsWrapperElementV130 } from './common-cartrid import { CommonCartridgeResourcesWrapperElementV130 } from './common-cartridge-resources-wrapper-element'; describe('CommonCartridgeElementFactoryV130', () => { - const setup = () => { - const sut = new CommonCartridgeElementFactoryV130(); - return { sut }; - }; - describe('createElement', () => { describe('when creating elements from props', () => { it('should return metadata element', () => { - const { sut } = setup(); - const result = sut.createElement({ + const result = CommonCartridgeElementFactoryV130.createElement({ type: CommonCartridgeElementType.METADATA, version: CommonCartridgeVersion.V_1_3_0, title: faker.lorem.words(), @@ -29,8 +23,7 @@ describe('CommonCartridgeElementFactoryV130', () => { }); it('should return organization element', () => { - const { sut } = setup(); - const result = sut.createElement({ + const result = CommonCartridgeElementFactoryV130.createElement({ type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_3_0, identifier: faker.string.uuid(), @@ -43,8 +36,7 @@ describe('CommonCartridgeElementFactoryV130', () => { }); it('should return organization wrapper element', () => { - const { sut } = setup(); - const result = sut.createElement({ + const result = CommonCartridgeElementFactoryV130.createElement({ type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, version: CommonCartridgeVersion.V_1_3_0, items: [], @@ -55,8 +47,7 @@ describe('CommonCartridgeElementFactoryV130', () => { }); it('should return resources wrapper element', () => { - const { sut } = setup(); - const result = sut.createElement({ + const result = CommonCartridgeElementFactoryV130.createElement({ type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: CommonCartridgeVersion.V_1_3_0, items: [], diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts index 8d7fc34b30b..8765b72d43f 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts @@ -18,20 +18,14 @@ import { CommonCartridgeResourcesWrapperElementV130, } from './common-cartridge-resources-wrapper-element'; -export type CommonCartridgeElementProps130 = +type CommonCartridgeElementProps130 = | CommonCartridgeMetadataElementPropsV130 | CommonCartridgeOrganizationElementPropsV130 | CommonCartridgeOrganizationsWrapperElementPropsV130 | CommonCartridgeResourcesWrapperElementPropsV130; export class CommonCartridgeElementFactoryV130 { - public static readonly instance = new CommonCartridgeElementFactoryV130(); - - public static getInstance(): CommonCartridgeElementFactoryV130 { - return this.instance; - } - - public createElement(props: CommonCartridgeElementProps130): CommonCartridgeElement { + public static createElement(props: CommonCartridgeElementProps130): CommonCartridgeElement { const { type } = props; switch (type) { From be21ca79221c340821e5249e67a019306d0c5dc1 Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 15 Dec 2023 11:24:18 +0100 Subject: [PATCH 090/177] EW-539 manifest for version 1.1.0 works --- .../common-cartridge-organization-element.ts | 3 +- .../common-cartridge-element.interface.ts | 13 +++++- ...common-cartridge-manifest-resource.spec.ts | 40 ++++++++++--------- .../common-cartridge-manifest-resource.ts | 4 +- .../common-cartridge-web-link-resource.ts | 14 +++---- .../common-cartridge/v1.1.0/manifest.xml | 23 ++++++----- 6 files changed, 56 insertions(+), 41 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts index cfd26a48c07..f94298ad68c 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts @@ -22,9 +22,10 @@ export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeEleme return { $: { identifier: this.props.identifier, + identifierref: this.props.items.length === 1 ? this.props.items[0].identifier : undefined, }, title: this.props.title, - item: this.props.items.map((item) => item.getManifestXmlObject()), + // item: this.props.items.map((item) => item.getManifestXmlObject()), }; } } diff --git a/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts index 5961551aaac..8e1a9368efe 100644 --- a/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts @@ -1,12 +1,21 @@ import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; +type CommonCartridgeElementProps = { + version: CommonCartridgeVersion; + identifier?: string; +}; + /** * Every element which should be listed in the Common Cartridge manifest must implement this interface. */ export abstract class CommonCartridgeElement { - protected constructor(args: { version: CommonCartridgeVersion }) { - this.checkVersion(args.version); + protected constructor(private readonly baseProps: CommonCartridgeElementProps) { + this.checkVersion(baseProps.version); + } + + public get identifier(): string | undefined { + return this.baseProps.identifier; } /** diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index 0a3a6cf98f0..9e61035f96e 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -1,5 +1,3 @@ -import { faker } from '@faker-js/faker'; -import { createMock } from '@golevelup/ts-jest'; import { readFile } from 'fs/promises'; import { CommonCartridgeElementType, @@ -8,55 +6,59 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactoryV110 } from '../../elements/v1.1.0/common-cartridge-element-factory'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; -import { CommonCartridgeResourceFactoryV110 } from './common-cartridge-resource-factory'; describe('CommonCartridgeManifestResourceV110', () => { const setup = () => { - const resource1 = CommonCartridgeResourceFactoryV110.getInstance().createResource({ + const resource1 = CommonCartridgeResourceFactory.createResource({ type: CommonCartridgeResourceType.WEB_CONTENT, version: CommonCartridgeVersion.V_1_1_0, - title: 'Title', + title: 'Title 1', identifier: 'r1', - folder: 'i1', + folder: 'o1', html: '

HTML

', intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, }); - const resource2 = CommonCartridgeResourceFactoryV110.getInstance().createResource({ - type: CommonCartridgeResourceType.WEB_CONTENT, + const resource2 = CommonCartridgeResourceFactory.createResource({ + type: CommonCartridgeResourceType.WEB_LINK, version: CommonCartridgeVersion.V_1_1_0, - title: 'Title', + title: 'Title 2', identifier: 'r2', - folder: 'i2', - html: '

HTML

', - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + folder: 'o2', + url: 'https://www.example.tld', }); const organization1 = CommonCartridgeElementFactoryV110.getInstance().createElement({ type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_1_0, - title: 'Title', + title: 'Title 1', identifier: 'o1', items: [resource1], }); const organization2 = CommonCartridgeElementFactoryV110.getInstance().createElement({ type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_1_0, - title: 'Title', + title: 'Title 2', identifier: 'o2', items: [resource2], }); - const metadataMock = createMock(); + const metadata = CommonCartridgeElementFactoryV110.getInstance().createElement({ + type: CommonCartridgeElementType.METADATA, + version: CommonCartridgeVersion.V_1_1_0, + title: 'Common Cartridge Manifest', + copyrightOwners: ['John Doe', 'Jane Doe'], + creationDate: new Date('2023-01-01'), + }); const sut = new CommonCartridgeManifestResourceV110({ type: CommonCartridgeResourceType.MANIFEST, version: CommonCartridgeVersion.V_1_1_0, - identifier: faker.string.uuid(), - metadata: metadataMock, + identifier: 'm1', + metadata, organizations: [organization1, organization2], resources: [resource1, resource2], }); - return { sut, metadataMock }; + return { sut }; }; describe('canInline', () => { diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts index 94253f2dfa3..a953200b311 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -51,7 +51,7 @@ export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource 'xsi:schemaLocation': 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd ', + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd', }, metadata: this.props.metadata.getManifestXmlObject(), organizations: new CommonCartridgeOrganizationsWrapperElementV110({ @@ -59,7 +59,7 @@ export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource version: this.props.version, items: this.props.organizations, }).getManifestXmlObject(), - resources: new CommonCartridgeResourcesWrapperElementV110({ + ...new CommonCartridgeResourcesWrapperElementV110({ type: CommonCartridgeElementType.RESOURCES_WRAPPER, // FIXME: Is this necessary? version: this.props.version, items: this.props.resources, diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts index 956e7b90146..a40dc7142a2 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -53,15 +53,13 @@ export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource public getManifestXmlObject(): Record { return { - resource: { + $: { + identifier: this.props.identifier, + type: 'imswl_xmlv1p1', + }, + file: { $: { - identifier: this.props.identifier, - type: 'imswl_xmlv1p1', - }, - file: { - $: { - href: this.getFilePath(), - }, + href: this.getFilePath(), }, }, }; diff --git a/apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml b/apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml index 11b2c7d2b78..37d1d31dd4b 100644 --- a/apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml +++ b/apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml @@ -6,32 +6,37 @@ - Common Cartridge Example + Common Cartridge Manifest + + + + yes + - This is an example of a Common Cartridge manifest. + 2023 John Doe, Jane Doe - + - + Title 1 - + Title 2 - - + + - - + + \ No newline at end of file From 61a03a64f199ca20748190392710b87506ec2204 Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 15 Dec 2023 12:07:38 +0100 Subject: [PATCH 091/177] EW-539 tests finished for manifest v1.3.0 --- .../common-cartridge-organization-element.ts | 3 +- ...common-cartridge-manifest-resource.spec.ts | 2 - ...common-cartridge-manifest-resource.spec.ts | 73 ++++++++++++++----- .../common-cartridge-manifest-resource.ts | 12 +-- .../common-cartridge/v1.3.0/manifest.xml | 42 +++++++++++ 5 files changed, 104 insertions(+), 28 deletions(-) create mode 100644 apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts index 94941a2575a..67bfa3dd6ce 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts @@ -22,9 +22,10 @@ export class CommonCartridgeOrganizationElementV130 extends CommonCartridgeEleme return { $: { identifier: this.props.identifier, + identifierref: this.props.items.length === 1 ? this.props.items[0].identifier : undefined, }, title: this.props.title, - item: this.props.items.map((item) => item.getManifestXmlObject()), + // item: this.props.items.map((item) => item.getManifestXmlObject()), }; } } diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index 9e61035f96e..b8d5725dc8f 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -108,6 +108,4 @@ describe('CommonCartridgeManifestResourceV110', () => { }); }); }); - - describe('getManifestXmlObject', () => {}); }); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index a2ad56a1956..de73f078df8 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -1,23 +1,64 @@ -import { faker } from '@faker-js/faker'; -import { createMock } from '@golevelup/ts-jest'; import { readFile } from 'fs/promises'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { + CommonCartridgeElementType, + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { CommonCartridgeElementFactoryV130 } from '../../elements/v1.3.0/common-cartridge-element-factory'; +import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; -describe('CommonCartridgeManifestResourceV130', () => { +describe('CommonCartridgeManifestResourceV110', () => { const setup = () => { - const metadataMock = createMock(); + const resource1 = CommonCartridgeResourceFactory.createResource({ + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_3_0, + title: 'Title 1', + identifier: 'r1', + folder: 'o1', + html: '

HTML

', + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }); + const resource2 = CommonCartridgeResourceFactory.createResource({ + type: CommonCartridgeResourceType.WEB_LINK, + version: CommonCartridgeVersion.V_1_3_0, + title: 'Title 2', + identifier: 'r2', + folder: 'o2', + url: 'https://www.example.tld', + }); + const organization1 = CommonCartridgeElementFactoryV130.getInstance().createElement({ + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_3_0, + title: 'Title 1', + identifier: 'o1', + items: [resource1], + }); + const organization2 = CommonCartridgeElementFactoryV130.getInstance().createElement({ + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_3_0, + title: 'Title 2', + identifier: 'o2', + items: [resource2], + }); + const metadata = CommonCartridgeElementFactoryV130.getInstance().createElement({ + type: CommonCartridgeElementType.METADATA, + version: CommonCartridgeVersion.V_1_3_0, + title: 'Common Cartridge Manifest', + copyrightOwners: ['John Doe', 'Jane Doe'], + creationDate: new Date('2023-01-01'), + }); const sut = new CommonCartridgeManifestResourceV130({ type: CommonCartridgeResourceType.MANIFEST, version: CommonCartridgeVersion.V_1_3_0, - identifier: faker.string.uuid(), - metadata: metadataMock, - organizations: [], - resources: [], + identifier: 'm1', + metadata, + organizations: [organization1, organization2], + resources: [resource1, resource2], }); - return { sut, metadataMock }; + return { sut }; }; describe('canInline', () => { @@ -44,15 +85,15 @@ describe('CommonCartridgeManifestResourceV130', () => { describe('getFileContent', () => { describe('when using Common Cartridge version 1.3.0', () => { - it.skip('should return constructed file content', async () => { + it('should return constructed file content', async () => { const { sut } = setup(); - const manifest = await readFile( - './apps/server/src/modules/learnroom/common-cartridge/resources/v1.3.0/imsmanifest.xml', + const expected = await readFile( + './apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml', 'utf-8' ); const result = sut.getFileContent(); - expect(result).toEqual(manifest)); + expect(result).toEqual(expected); }); }); }); @@ -67,6 +108,4 @@ describe('CommonCartridgeManifestResourceV130', () => { }); }); }); - - describe('getManifestXmlObject', () => {}); }); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts index b04a209f302..23fc0cd2f23 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -1,4 +1,3 @@ -import { Builder } from 'xml2js'; import { CommonCartridgeElementType, CommonCartridgeResourceType, @@ -8,6 +7,7 @@ import { CommonCartridgeOrganizationsWrapperElementV130 } from '../../elements/v import { CommonCartridgeResourcesWrapperElementV130 } from '../../elements/v1.3.0/common-cartridge-resources-wrapper-element'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { buildXmlString } from '../../utils'; export type CommonCartridgeManifestResourcePropsV130 = { type: CommonCartridgeResourceType.MANIFEST; @@ -19,8 +19,6 @@ export type CommonCartridgeManifestResourcePropsV130 = { }; export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource { - private readonly xmlBuilder = new Builder(); - public constructor(private readonly props: CommonCartridgeManifestResourcePropsV130) { super(props); } @@ -34,7 +32,7 @@ export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource } public override getFileContent(): string { - return this.xmlBuilder.buildObject(this.getManifestXmlObject()); + return buildXmlString(this.getManifestXmlObject()); } public override getSupportedVersion(): CommonCartridgeVersion { @@ -49,13 +47,11 @@ export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1', 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest', 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource', - 'xmlns:ext': 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': - 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lomresource_v1p0.xsd ' + 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd ' + 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd ' + - 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_extensionv1p2 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_cpextensionv1p2_v1p0.xsd', + 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lomresource_v1p0.xsd', }, metadata: this.props.metadata.getManifestXmlObject(), organizations: new CommonCartridgeOrganizationsWrapperElementV130({ @@ -63,7 +59,7 @@ export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource version: this.props.version, items: this.props.organizations, }).getManifestXmlObject(), - resources: new CommonCartridgeResourcesWrapperElementV130({ + ...new CommonCartridgeResourcesWrapperElementV130({ type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: this.props.version, items: this.props.resources, diff --git a/apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml b/apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml new file mode 100644 index 00000000000..b79159a1bc7 --- /dev/null +++ b/apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml @@ -0,0 +1,42 @@ + + + + IMS Common Cartridge + 1.3.0 + + + + Common Cartridge Manifest + + + + + yes + + + 2023 John Doe, Jane Doe + + + + + + + + + Title 1 + + + Title 2 + + + + + + + + + + + + + \ No newline at end of file From b7d3a8cf7b8293afcbd022a41001f436559045d5 Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 15 Dec 2023 13:27:10 +0100 Subject: [PATCH 092/177] fixing unit tests --- .../v1.1.0/common-cartridge-manifest-resource.spec.ts | 8 ++++---- .../v1.3.0/common-cartridge-manifest-resource.spec.ts | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index b8d5725dc8f..0c18bf5d386 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -5,7 +5,7 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion, } from '../../common-cartridge.enums'; -import { CommonCartridgeElementFactoryV110 } from '../../elements/v1.1.0/common-cartridge-element-factory'; +import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; @@ -28,21 +28,21 @@ describe('CommonCartridgeManifestResourceV110', () => { folder: 'o2', url: 'https://www.example.tld', }); - const organization1 = CommonCartridgeElementFactoryV110.getInstance().createElement({ + const organization1 = CommonCartridgeElementFactory.createElement({ type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_1_0, title: 'Title 1', identifier: 'o1', items: [resource1], }); - const organization2 = CommonCartridgeElementFactoryV110.getInstance().createElement({ + const organization2 = CommonCartridgeElementFactory.createElement({ type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_1_0, title: 'Title 2', identifier: 'o2', items: [resource2], }); - const metadata = CommonCartridgeElementFactoryV110.getInstance().createElement({ + const metadata = CommonCartridgeElementFactory.createElement({ type: CommonCartridgeElementType.METADATA, version: CommonCartridgeVersion.V_1_1_0, title: 'Common Cartridge Manifest', diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index de73f078df8..12728722bc6 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -5,6 +5,7 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion, } from '../../common-cartridge.enums'; +import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; import { CommonCartridgeElementFactoryV130 } from '../../elements/v1.3.0/common-cartridge-element-factory'; import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; @@ -28,21 +29,21 @@ describe('CommonCartridgeManifestResourceV110', () => { folder: 'o2', url: 'https://www.example.tld', }); - const organization1 = CommonCartridgeElementFactoryV130.getInstance().createElement({ + const organization1 = CommonCartridgeElementFactoryV130.createElement({ type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_3_0, title: 'Title 1', identifier: 'o1', items: [resource1], }); - const organization2 = CommonCartridgeElementFactoryV130.getInstance().createElement({ + const organization2 = CommonCartridgeElementFactory.createElement({ type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_3_0, title: 'Title 2', identifier: 'o2', items: [resource2], }); - const metadata = CommonCartridgeElementFactoryV130.getInstance().createElement({ + const metadata = CommonCartridgeElementFactoryV130.createElement({ type: CommonCartridgeElementType.METADATA, version: CommonCartridgeVersion.V_1_3_0, title: 'Common Cartridge Manifest', From fda860c3e70d0fdc5a1cf7f92e2fb5de21e9005e Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 15 Dec 2023 13:30:35 +0100 Subject: [PATCH 093/177] fixing errors in cc file builder --- .../builders/common-cartridge-file-builder.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts index a1d2f35a6cb..86e068ba074 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts @@ -1,5 +1,5 @@ import AdmZip from 'adm-zip'; -import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeMetadataElementPropsV110, CommonCartridgeMetadataElementV110, @@ -10,7 +10,7 @@ import { } from '../elements/v1.3.0/common-cartridge-metadata-element'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { CommonCartridgeManifestResource } from '../resources/common-cartridge-manifest-resource'; +import { CommonCartridgeResourceFactory } from '../resources/common-cartridge-resource-factory'; import { OmitVersion, checkCommonCartridgeVersion, checkDefined } from '../utils'; import { CommonCartridgeOrganizationBuilder, @@ -69,7 +69,8 @@ export class CommonCartridgeFileBuilder { public build(): Promise { const metadata = checkDefined(this.metadata, 'metadata'); const organizations = this.organizationBuilders.map((builder) => builder.build()); - const manifest = new CommonCartridgeManifestResource({ + const manifest = CommonCartridgeResourceFactory.createResource({ + type: CommonCartridgeResourceType.MANIFEST, version: this.props.version, identifier: this.props.identifier, metadata, From 597eeb529b84b27a4fe75735a1908cde2cd1de8b Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 15 Dec 2023 14:03:45 +0100 Subject: [PATCH 094/177] Adding create identifier method --- .../server/src/modules/common-cartridge/utils.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/utils.ts b/apps/server/src/modules/common-cartridge/utils.ts index 654a1eabc18..511f2f81f62 100644 --- a/apps/server/src/modules/common-cartridge/utils.ts +++ b/apps/server/src/modules/common-cartridge/utils.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; +import { ObjectID } from 'bson'; import { Builder } from 'xml2js'; -import { CommonCartridgeVersion } from './common-cartridge.enums'; export type OmitVersion = Omit; @@ -28,18 +28,12 @@ export function createElementTypeNotSupportedError(type: string): Error { return new InternalServerErrorException(`Common Cartridge element type ${type} is not supported`); } -export function checkCommonCartridgeVersion(version: CommonCartridgeVersion): void | never { - const supportedVersions = [ - CommonCartridgeVersion.V_1_1_0, - CommonCartridgeVersion.V_1_2_0, - CommonCartridgeVersion.V_1_3_0, - ]; - - if (supportedVersions.includes(version)) { - return; +export function createIdentifier(identifier: string | ObjectID | undefined): string { + if (!identifier) { + return `i${new ObjectID().toString()}`; } - throw createVersionNotSupportedError(version); + return `i${identifier.toString()}`; } export function checkDefined(value: T | undefined | null, name: string): T | never { From d1132ae2c995adbd561977bf7bdb5d5bb5e7c1ab Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 15 Dec 2023 14:31:59 +0100 Subject: [PATCH 095/177] Cleaning up cc fle builder --- .../builders/common-cartridge-file-builder.ts | 39 +++++++------------ .../src/modules/common-cartridge/utils.ts | 2 + 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts index 86e068ba074..6f597ce9ed3 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts @@ -1,17 +1,16 @@ import AdmZip from 'adm-zip'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { - CommonCartridgeMetadataElementPropsV110, - CommonCartridgeMetadataElementV110, -} from '../elements/v1.1.0/common-cartridge-metadata-element'; -import { - CommonCartridgeMetadataElementPropsV130, - CommonCartridgeMetadataElementV130, -} from '../elements/v1.3.0/common-cartridge-metadata-element'; + CommonCartridgeElementType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../common-cartridge.enums'; +import { CommonCartridgeElementFactory } from '../elements/common-cartridge-element-factory'; +import { CommonCartridgeMetadataElementPropsV110 } from '../elements/v1.1.0/common-cartridge-metadata-element'; +import { CommonCartridgeMetadataElementPropsV130 } from '../elements/v1.3.0/common-cartridge-metadata-element'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { CommonCartridgeResourceFactory } from '../resources/common-cartridge-resource-factory'; -import { OmitVersion, checkCommonCartridgeVersion, checkDefined } from '../utils'; +import { OmitVersion, OmitVersionAndType, checkDefined } from '../utils'; import { CommonCartridgeOrganizationBuilder, CommonCartridgeOrganizationBuilderOptions, @@ -31,24 +30,16 @@ export class CommonCartridgeFileBuilder { private metadata?: CommonCartridgeElement; - public constructor(private readonly props: CommonCartridgeFileBuilderProps) { - checkCommonCartridgeVersion(props.version); - } + public constructor(private readonly props: CommonCartridgeFileBuilderProps) {} public addMetadata( - props: OmitVersion + props: OmitVersionAndType ): CommonCartridgeFileBuilder { - switch (this.props.version) { - case CommonCartridgeVersion.V_1_1_0: - this.metadata = new CommonCartridgeMetadataElementV110({ ...props, version: this.props.version }); - break; - case CommonCartridgeVersion.V_1_3_0: - this.metadata = new CommonCartridgeMetadataElementV130({ ...props, version: this.props.version }); - break; - default: - throw new Error('Version not supported'); - } - // this.metadata = new CommonCartridgeMetadataElement({ ...props, version: this.props.version }); + this.metadata = CommonCartridgeElementFactory.createElement({ + type: CommonCartridgeElementType.METADATA, + version: this.props.version, + ...props, + }); return this; } diff --git a/apps/server/src/modules/common-cartridge/utils.ts b/apps/server/src/modules/common-cartridge/utils.ts index 511f2f81f62..da8dd0321ee 100644 --- a/apps/server/src/modules/common-cartridge/utils.ts +++ b/apps/server/src/modules/common-cartridge/utils.ts @@ -6,6 +6,8 @@ export type OmitVersion = Omit; export type OmitVersionAndFolder = Omit; +export type OmitVersionAndType = Omit; + const xmlBuilder = new Builder({ xmldec: { version: '1.0', encoding: 'UTF-8' }, renderOpts: { pretty: true, indent: ' ', newline: '\n' }, From dc6fef481433616f67ff03861b6f59151e241bdf Mon Sep 17 00:00:00 2001 From: psachmann Date: Fri, 15 Dec 2023 16:04:37 +0100 Subject: [PATCH 096/177] Cleaning up code --- .../src/modules/common-cartridge/index.ts | 2 -- .../common-cartridge-manifest-resource.ts | 11 +++++------ .../common-cartridge-web-link-resource.spec.ts | 2 +- .../common-cartridge-web-link-resource.spec.ts | 2 +- .../modules/common-cartridge/review-notes.md | 17 ++++++++++++++++- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/index.ts b/apps/server/src/modules/common-cartridge/index.ts index 88f52e43c23..1dc2ce2d2ea 100644 --- a/apps/server/src/modules/common-cartridge/index.ts +++ b/apps/server/src/modules/common-cartridge/index.ts @@ -5,6 +5,4 @@ export { CommonCartridgeResourceType, CommonCartridgeVersion, } from './common-cartridge.enums'; -export { CommonCartridgeElementPropsV110 } from './elements/v1.1.0/common-cartridge-element-factory'; -export { CommonCartridgeElementProps130 } from './elements/v1.3.0/common-cartridge-element-factory'; export { OmitVersion } from './utils'; diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts index a953200b311..78e08aab1ea 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -3,8 +3,7 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion, } from '../../common-cartridge.enums'; -import { CommonCartridgeOrganizationsWrapperElementV110 } from '../../elements/v1.1.0/common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElementV110 } from '../../elements/v1.1.0/common-cartridge-resources-wrapper-element'; +import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; import { buildXmlString } from '../../utils'; @@ -54,13 +53,13 @@ export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd', }, metadata: this.props.metadata.getManifestXmlObject(), - organizations: new CommonCartridgeOrganizationsWrapperElementV110({ - type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, // FIXME: Is this necessary? + organizations: CommonCartridgeElementFactory.createElement({ + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, version: this.props.version, items: this.props.organizations, }).getManifestXmlObject(), - ...new CommonCartridgeResourcesWrapperElementV110({ - type: CommonCartridgeElementType.RESOURCES_WRAPPER, // FIXME: Is this necessary? + ...CommonCartridgeElementFactory.createElement({ + type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: this.props.version, items: this.props.resources, }).getManifestXmlObject(), diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts index 07d0f6b5f04..abf26416f2a 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -16,7 +16,7 @@ describe('CommonCartridgeWebLinkResourceV110', () => { title: 'Title', url: 'http://www.example.tld', target: '_self', - windowFeatures: 'width=100;height=100;', // FIXME: Is this a valid value? + windowFeatures: 'width=100;height=100;', }; const sut = new CommonCartridgeWebLinkResourceV110(props); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts index ec2fdc63f70..49fdb11ff07 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts @@ -16,7 +16,7 @@ describe('CommonCartridgeWebLinkResourceV130', () => { title: 'Title', url: 'http://www.example.tld', target: '_self', - windowFeatures: 'width=100;height=100;', // FIXME: Is this a valid value? + windowFeatures: 'width=100;height=100;', }; const sut = new CommonCartridgeWebLinkResourceV130(props); diff --git a/apps/server/src/modules/common-cartridge/review-notes.md b/apps/server/src/modules/common-cartridge/review-notes.md index 42c753dc4c9..e446bd3a232 100644 --- a/apps/server/src/modules/common-cartridge/review-notes.md +++ b/apps/server/src/modules/common-cartridge/review-notes.md @@ -1,5 +1,20 @@ # review 04.12.23 - ~~put all course-independent code into a separate "common-cartridge" module~~ -- import common-cartridge into learnroom +- ~~import common-cartridge into learnroom~~ - adjust all tests to avoid global variables. create factories where useful, and use setup function instead of beforeAll + +### EW-539 + +- ~~tests for CCManifestResource~~ +- Check test coverage +- Cleanup FIXMEs +- Manual tests +- ~~createIdentifier method~~ +- merge main +- review.md and comments +- ~~move in separate module~~ +- check index.ts +- ~~move xml files into test-assets folder~~ +- Adjust export-service + From d4997a6bdab0b393740de434ab95664e85c17f56 Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 18 Dec 2023 12:28:55 +0100 Subject: [PATCH 097/177] Working on Co-authored-by: Simone Radtke --- .../builders/common-cartridge-file-builder.ts | 18 ++++++------------ .../common-cartridge.module.ts | 8 -------- .../src/modules/common-cartridge/index.ts | 9 +++------ .../common-cartridge-web-content-resource.ts | 8 ++++++++ .../common-cartridge-web-content-resource.ts | 9 +++++++++ .../src/modules/common-cartridge/utils.ts | 6 ++++++ .../mapper/common-cartridge.mapper.ts | 18 ++++++++++-------- 7 files changed, 42 insertions(+), 34 deletions(-) delete mode 100644 apps/server/src/modules/common-cartridge/common-cartridge.module.ts diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts index 6f597ce9ed3..57c1f313328 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts @@ -1,16 +1,13 @@ import AdmZip from 'adm-zip'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { - CommonCartridgeElementType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../common-cartridge.enums'; -import { CommonCartridgeElementFactory } from '../elements/common-cartridge-element-factory'; -import { CommonCartridgeMetadataElementPropsV110 } from '../elements/v1.1.0/common-cartridge-metadata-element'; -import { CommonCartridgeMetadataElementPropsV130 } from '../elements/v1.3.0/common-cartridge-metadata-element'; + CommonCartridgeElementFactory, + CommonCartridgeElementProps, +} from '../elements/common-cartridge-element-factory'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { CommonCartridgeResourceFactory } from '../resources/common-cartridge-resource-factory'; -import { OmitVersion, OmitVersionAndType, checkDefined } from '../utils'; +import { OmitVersion, checkDefined } from '../utils'; import { CommonCartridgeOrganizationBuilder, CommonCartridgeOrganizationBuilderOptions, @@ -32,11 +29,8 @@ export class CommonCartridgeFileBuilder { public constructor(private readonly props: CommonCartridgeFileBuilderProps) {} - public addMetadata( - props: OmitVersionAndType - ): CommonCartridgeFileBuilder { + public addMetadata(props: CommonCartridgeElementProps): CommonCartridgeFileBuilder { this.metadata = CommonCartridgeElementFactory.createElement({ - type: CommonCartridgeElementType.METADATA, version: this.props.version, ...props, }); diff --git a/apps/server/src/modules/common-cartridge/common-cartridge.module.ts b/apps/server/src/modules/common-cartridge/common-cartridge.module.ts deleted file mode 100644 index 5eecb7cc628..00000000000 --- a/apps/server/src/modules/common-cartridge/common-cartridge.module.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Module } from '@nestjs/common'; - -@Module({ - imports: [], - providers: [], - exports: [], -}) -export class CommonCartridgeModule {} diff --git a/apps/server/src/modules/common-cartridge/index.ts b/apps/server/src/modules/common-cartridge/index.ts index 1dc2ce2d2ea..7640471be33 100644 --- a/apps/server/src/modules/common-cartridge/index.ts +++ b/apps/server/src/modules/common-cartridge/index.ts @@ -1,8 +1,5 @@ export * from './builders/common-cartridge-file-builder'; export * from './builders/common-cartridge-organization-builder'; -export { - CommonCartridgeElementType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from './common-cartridge.enums'; -export { OmitVersion } from './utils'; +export * from './common-cartridge.enums'; +export { CommonCartridgeElementProps } from './elements/common-cartridge-element-factory'; +export { CommonCartridgeResourceProps } from './resources/common-cartridge-resource-factory'; diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts index 81784748f78..4c75228dfce 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -4,6 +4,7 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { checkIntendedUse } from '../../utils'; export type CommonCartridgeWebContentResourcePropsV110 = { type: CommonCartridgeResourceType.WEB_CONTENT; @@ -16,8 +17,15 @@ export type CommonCartridgeWebContentResourcePropsV110 = { }; export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResource { + private static readonly SUPPORTED_INTENDED_USES = [ + CommonCartridgeIntendedUseType.LESSON_PLAN, + CommonCartridgeIntendedUseType.SYLLABUS, + CommonCartridgeIntendedUseType.UNSPECIFIED, + ]; + public constructor(private readonly props: CommonCartridgeWebContentResourcePropsV110) { super(props); + checkIntendedUse(props.intendedUse, CommonCartridgeWebContentResourceV110.SUPPORTED_INTENDED_USES); } public override canInline(): boolean { diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts index 2f4c6ecec86..73b33567677 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -4,6 +4,7 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { checkIntendedUse } from '../../utils'; export type CommonCartridgeWebContentResourcePropsV130 = { type: CommonCartridgeResourceType.WEB_CONTENT; @@ -16,8 +17,16 @@ export type CommonCartridgeWebContentResourcePropsV130 = { }; export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResource { + private static readonly SUPPORTED_INTENDED_USES = [ + CommonCartridgeIntendedUseType.ASSIGNMENT, + CommonCartridgeIntendedUseType.LESSON_PLAN, + CommonCartridgeIntendedUseType.SYLLABUS, + CommonCartridgeIntendedUseType.UNSPECIFIED, + ]; + public constructor(private readonly props: CommonCartridgeWebContentResourcePropsV130) { super(props); + checkIntendedUse(props.intendedUse, CommonCartridgeWebContentResourceV130.SUPPORTED_INTENDED_USES); } public override canInline(): boolean { diff --git a/apps/server/src/modules/common-cartridge/utils.ts b/apps/server/src/modules/common-cartridge/utils.ts index da8dd0321ee..9130f5b6753 100644 --- a/apps/server/src/modules/common-cartridge/utils.ts +++ b/apps/server/src/modules/common-cartridge/utils.ts @@ -38,6 +38,12 @@ export function createIdentifier(identifier: string | ObjectID | undefined): str return `i${identifier.toString()}`; } +export function checkIntendedUse(intendedUse: string, supportedIntendedUses: string[]): void | never { + if (!supportedIntendedUses.includes(intendedUse)) { + throw new Error(`Intended use ${intendedUse} is not supported`); + } +} + export function checkDefined(value: T | undefined | null, name: string): T | never { if (value) { return value; diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 0f822728be8..11f87cbf068 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -3,11 +3,12 @@ import { ConfigService } from '@nestjs/config'; import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain'; import { ObjectId } from 'bson'; import { - CommonCartridgeMetadataElementProps, + CommonCartridgeElementProps, + CommonCartridgeElementType, + CommonCartridgeIntendedUseType, CommonCartridgeOrganizationBuilderOptions, CommonCartridgeResourceProps, CommonCartridgeResourceType, - OmitVersion, } from '../../common-cartridge'; import { LearnroomConfig } from '../learnroom.config'; @@ -15,31 +16,30 @@ import { LearnroomConfig } from '../learnroom.config'; export class CommonCartridgeMapper { public constructor(private readonly configService: ConfigService) {} - public mapCourseToMetadata(course: Course): OmitVersion { + public mapCourseToMetadata(course: Course): CommonCartridgeElementProps { return { + type: CommonCartridgeElementType.METADATA, title: course.name, copyrightOwners: course.teachers.toArray().map((teacher) => `${teacher.firstName} ${teacher.lastName}`), creationDate: course.createdAt, }; } - public mapLessonToOrganization(lesson: LessonEntity): OmitVersion { + public mapLessonToOrganization(lesson: LessonEntity): CommonCartridgeOrganizationBuilderOptions { return { identifier: lesson.id, title: lesson.name, }; } - public mapContentToOrganization( - content: ComponentProperties - ): OmitVersion { + public mapContentToOrganization(content: ComponentProperties): CommonCartridgeOrganizationBuilderOptions { return { identifier: new ObjectId(content._id).toHexString(), title: content.title, }; } - public mapTaskToOrganization(task: Task): OmitVersion { + public mapTaskToOrganization(task: Task): CommonCartridgeOrganizationBuilderOptions { return { identifier: task.id, title: task.name, @@ -52,6 +52,7 @@ export class CommonCartridgeMapper { identifier: task.id, title: task.name, html: `

${task.name}

${task.description}

`, + intendedUse: CommonCartridgeIntendedUseType.ASSIGNMENT, }; } @@ -65,6 +66,7 @@ export class CommonCartridgeMapper { identifier: new ObjectId(content._id).toHexString(), title: content.title, html: `

${content.title}

${content.content.text}

`, + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, }; case ComponentType.GEOGEBRA: return { From 77c133391fde89cc9fa4d2fbed5fb108ef2c44a5 Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 18 Dec 2023 13:21:35 +0100 Subject: [PATCH 098/177] Fixing one type --- .../builders/common-cartridge-organization-builder.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts index a296da68d5c..9052316a80c 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts @@ -8,7 +8,10 @@ import { } from '../resources/common-cartridge-resource-factory'; import { OmitVersionAndFolder } from '../utils'; -export type CommonCartridgeOrganizationBuilderOptions = { +export type CommonCartridgeOrganizationBuilderOptions = + OmitVersionAndFolder; + +type CommonCartridgeOrganizationBuilderOptionsInternal = { version: CommonCartridgeVersion; identifier: string; title: string; @@ -21,7 +24,7 @@ export class CommonCartridgeOrganizationBuilder { private readonly children = new Array(); public constructor( - protected readonly options: CommonCartridgeOrganizationBuilderOptions, + protected readonly options: CommonCartridgeOrganizationBuilderOptionsInternal, private readonly addResourceToFileBuilder: (resource: CommonCartridgeResource) => void ) {} From 325bf1d4e00813e597fb1302e8d146533d8f3b3c Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 18 Dec 2023 14:27:16 +0100 Subject: [PATCH 099/177] Working on tests --- .../common-cartridge-resource-factory.spec.ts | 8 ++++- ...mon-cartridge-web-content-resource.spec.ts | 2 +- ...common-cartridge-web-link-resource.spec.ts | 14 ++++---- .../modules/common-cartridge/utils.spec.ts | 35 ++++++++++--------- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.spec.ts index 0143c30e233..9461e8ade61 100644 --- a/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.spec.ts @@ -1,5 +1,9 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResourcePropsV110, @@ -17,6 +21,7 @@ describe('CommonCartridgeResourceVersion', () => { const result = CommonCartridgeResourceFactory.createResource({ version: CommonCartridgeVersion.V_1_1_0, type: CommonCartridgeResourceType.WEB_CONTENT, + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, } as CommonCartridgeWebContentResourcePropsV110); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV110); @@ -26,6 +31,7 @@ describe('CommonCartridgeResourceVersion', () => { const result = CommonCartridgeResourceFactory.createResource({ version: CommonCartridgeVersion.V_1_3_0, type: CommonCartridgeResourceType.WEB_CONTENT, + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, } as CommonCartridgeWebContentResourcePropsV130); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV130); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts index 44bf0bccac2..d3770b677b7 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts @@ -3,7 +3,7 @@ import { CommonCartridgeIntendedUseType, CommonCartridgeResourceType, CommonCartridgeVersion, -} from '../../../learnroom/common-cartridge/common-cartridge.enums'; +} from '../../common-cartridge.enums'; import { CommonCartridgeWebContentResourcePropsV110, CommonCartridgeWebContentResourceV110, diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts index abf26416f2a..f831c84832b 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -73,15 +73,13 @@ describe('CommonCartridgeWebLinkResourceV110', () => { const result = sut.getManifestXmlObject(); expect(result).toEqual({ - resource: { + $: { + identifier: props.identifier, + type: 'imswl_xmlv1p1', + }, + file: { $: { - identifier: props.identifier, - type: 'imswl_xmlv1p1', - }, - file: { - $: { - href: sut.getFilePath(), - }, + href: sut.getFilePath(), }, }, }); diff --git a/apps/server/src/modules/common-cartridge/utils.spec.ts b/apps/server/src/modules/common-cartridge/utils.spec.ts index 62a81286e41..8fdfa22b536 100644 --- a/apps/server/src/modules/common-cartridge/utils.spec.ts +++ b/apps/server/src/modules/common-cartridge/utils.spec.ts @@ -1,12 +1,12 @@ import { CommonCartridgeVersion } from './common-cartridge.enums'; -import { buildXmlString, checkCommonCartridgeVersion, checkDefined, createVersionNotSupportedError } from './utils'; +import { buildXmlString, checkDefined, checkIntendedUse, createVersionNotSupportedError } from './utils'; describe('CommonCartridgeUtils', () => { describe('buildXmlString', () => { it('should create xml string', () => { const xml = buildXmlString({ root: { child: 'value' } }); - expect(xml).toBe('value'); + expect(xml).toBe('\n\n value\n'); }); }); @@ -21,21 +21,6 @@ describe('CommonCartridgeUtils', () => { }); }); - // AI next 12 lines - describe('checkCommonCartridgeVersion', () => { - describe('when checking version', () => { - it('should not throw error when version is supported', () => { - expect(() => checkCommonCartridgeVersion(CommonCartridgeVersion.V_1_1_0)).not.toThrow(); - }); - - it('should throw error when version is not supported', () => { - expect(() => checkCommonCartridgeVersion(CommonCartridgeVersion.V_1_0_0)).toThrow( - createVersionNotSupportedError(CommonCartridgeVersion.V_1_0_0) - ); - }); - }); - }); - // AI next 16 lines describe('checkDefined', () => { describe('when checking value', () => { @@ -54,4 +39,20 @@ describe('CommonCartridgeUtils', () => { }); }); }); + + describe('checkIntendedUse', () => { + describe('when checking supported intended use', () => { + it('should not throw', () => { + const intendedUse = 'unspecified'; + + expect(() => checkIntendedUse(intendedUse, ['unspecified'])).not.toThrow(); + }); + + it('should throw error when intended use is not supported', () => { + const intendedUse = 'unsupported'; + + expect(() => checkIntendedUse(intendedUse, [])).toThrow(`Intended use ${intendedUse} is not supported`); + }); + }); + }); }); From 8d2a7f7ccf8208b73c8a4f22a081bf94da2f4bc2 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 18 Dec 2023 14:30:43 +0100 Subject: [PATCH 100/177] EW-539 Clean up --- TODO.md | 14 -------------- .../common-cartridge/common-cartridge.enums.ts | 2 -- 2 files changed, 16 deletions(-) diff --git a/TODO.md b/TODO.md index b7485f24053..7fa92508759 100644 --- a/TODO.md +++ b/TODO.md @@ -89,17 +89,3 @@ e.g. api: , , domain: , - -### EW-539 - -- tests for CCManifestResource -- Check test coverage -- Cleanup FIXMEs -- Manual tests -- createIdentifier method -- merge main -- review.md and comments -- ~~move in separate module~~ -- check index.ts -- move xml files into test-assets folder -- Adjust export-service diff --git a/apps/server/src/modules/common-cartridge/common-cartridge.enums.ts b/apps/server/src/modules/common-cartridge/common-cartridge.enums.ts index be91e8a9f53..8e474d7c3df 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge.enums.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge.enums.ts @@ -6,8 +6,6 @@ export enum CommonCartridgeVersion { V_1_4_0 = '1.4.0', } -// TODO: think about if there is a way to ensure that an implementation that is dependent on these versions has implementations for all versions. (HINT: helper class, composable, abstract class...) - export enum CommonCartridgeResourceType { UNKNOWN = 'unknown', MANIFEST = 'manifest', From 32f1d602137d7b64ddf8b1d876b0719716f8cbb4 Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 18 Dec 2023 15:33:16 +0100 Subject: [PATCH 101/177] Fixing test coverage for cc utils --- .../modules/common-cartridge/utils.spec.ts | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/utils.spec.ts b/apps/server/src/modules/common-cartridge/utils.spec.ts index 8fdfa22b536..5fd700c5696 100644 --- a/apps/server/src/modules/common-cartridge/utils.spec.ts +++ b/apps/server/src/modules/common-cartridge/utils.spec.ts @@ -1,5 +1,15 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { ObjectID } from 'bson'; import { CommonCartridgeVersion } from './common-cartridge.enums'; -import { buildXmlString, checkDefined, checkIntendedUse, createVersionNotSupportedError } from './utils'; +import { + buildXmlString, + checkDefined, + checkIntendedUse, + createElementTypeNotSupportedError, + createIdentifier, + createResourceTypeNotSupportedError, + createVersionNotSupportedError, +} from './utils'; describe('CommonCartridgeUtils', () => { describe('buildXmlString', () => { @@ -15,7 +25,7 @@ describe('CommonCartridgeUtils', () => { it('should return error with message', () => { const error = createVersionNotSupportedError(CommonCartridgeVersion.V_1_0_0); - expect(error).toBeDefined(); + expect(error).toBeInstanceOf(InternalServerErrorException); expect(error.message).toBe('Common Cartridge version 1.0.0 is not supported'); }); }); @@ -55,4 +65,42 @@ describe('CommonCartridgeUtils', () => { }); }); }); + + describe('createIdentifier', () => { + describe('when creating identifier', () => { + it('should return identifier with prefix', () => { + const identifier = new ObjectID(); + + expect(createIdentifier(identifier)).toBe(`i${identifier.toHexString()}`); + }); + + it('should return identifier with prefix when identifier is undefined', () => { + expect(createIdentifier(undefined)).toMatch(/^i[0-9a-f]{24}$/); + }); + }); + }); + + describe('createResourceTypeNotSupportedError', () => { + describe('when creating error', () => { + it('should return error with message', () => { + const resourceType = 'unsupported'; + const error = createResourceTypeNotSupportedError(resourceType); + + expect(error).toBeInstanceOf(InternalServerErrorException); + expect(error.message).toBe(`Common Cartridge resource type ${resourceType} is not supported`); + }); + }); + }); + + describe('createElementTypeNotSupportedError', () => { + describe('when creating error', () => { + it('should return error with message', () => { + const elementType = 'unsupported'; + const error = createElementTypeNotSupportedError(elementType); + + expect(error).toBeInstanceOf(InternalServerErrorException); + expect(error.message).toBe(`Common Cartridge element type ${elementType} is not supported`); + }); + }); + }); }); From e23731ed415e2cba6199990253b3f3696059b391 Mon Sep 17 00:00:00 2001 From: psachmann Date: Tue, 19 Dec 2023 09:26:39 +0100 Subject: [PATCH 102/177] Fixing some compilation errors --- ...mon-cartridge-organization-builder.spec.ts | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts index 84086800e0f..5da9da121b4 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts @@ -1,7 +1,11 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeOrganizationElement } from '../elements/common-cartridge-organization-element'; +import { + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../common-cartridge.enums'; +import { CommonCartridgeOrganizationElementV110 } from '../elements/v1.1.0/common-cartridge-organization-element'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { CommonCartridgeResourcePropsInternal } from '../resources/common-cartridge-resource-factory'; +import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; import { CommonCartridgeOrganizationBuilder, CommonCartridgeOrganizationBuilderOptions, @@ -15,35 +19,35 @@ describe('CommonCartridgeOrganizationBuilder', () => { const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { title: 'organization-title', identifier: 'organization-identifier', - version: CommonCartridgeVersion.V_1_1_0, }; const subOrganizationOptions: CommonCartridgeOrganizationBuilderOptions = { title: 'sub-organization-title', identifier: 'sub-organization-identifier', - version: CommonCartridgeVersion.V_1_1_0, }; const subSubOrganizationOptions: CommonCartridgeOrganizationBuilderOptions = { title: 'sub-sub-organization-title', identifier: 'sub-sub-organization-identifier', - version: CommonCartridgeVersion.V_1_1_0, }; - const resource1Props: CommonCartridgeResourcePropsInternal = { + const resource1Props: CommonCartridgeResourceProps = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'resource-1-identifier', title: 'resource-1-title', html: '

resource-1-html

', + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, }; - const resource2Props: CommonCartridgeResourcePropsInternal = { + const resource2Props: CommonCartridgeResourceProps = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'resource-2-identifier', title: 'resource-2-title', html: '

resource-2-html

', + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, }; - const resource3Props: CommonCartridgeResourcePropsInternal = { + const resource3Props: CommonCartridgeResourceProps = { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: 'resource-3-identifier', title: 'resource-3-title', html: '

resource-3-html

', + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, }; beforeEach(() => { @@ -60,8 +64,9 @@ describe('CommonCartridgeOrganizationBuilder', () => { describe('build', () => { describe('when creating a common cartridge archive', () => { beforeAll(() => { - sut = new CommonCartridgeOrganizationBuilder(organizationOptions, (resource) => - resources.push(resource) + sut = new CommonCartridgeOrganizationBuilder( + { ...organizationOptions, version: CommonCartridgeVersion.V_1_1_0 }, + (resource) => resources.push(resource) ); sut.addResource(resource1Props) .addSubOrganization(subOrganizationOptions) @@ -75,7 +80,7 @@ describe('CommonCartridgeOrganizationBuilder', () => { const element = sut.build(); expect(element).toBeDefined(); - expect(element).toBeInstanceOf(CommonCartridgeOrganizationElement); + expect(element).toBeInstanceOf(CommonCartridgeOrganizationElementV110); }); it('should add 3 resources', () => { From e0e05104f1ec9c941f7b80214202b71abd7dd942 Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 20 Dec 2023 09:08:48 +0100 Subject: [PATCH 103/177] Working on tests --- ...mon-cartridge-organization-element.spec.ts | 70 +++++++++++++------ .../common-cartridge-organization-element.ts | 34 +++++++-- .../common-cartridge-organization-element.ts | 32 +++++++-- .../common-cartridge-element.interface.ts | 5 ++ ...common-cartridge-manifest-resource.spec.ts | 4 +- ...common-cartridge-manifest-resource.spec.ts | 4 +- 6 files changed, 111 insertions(+), 38 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts index 48ff48e2c6a..9ad699184b1 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts @@ -1,7 +1,14 @@ import { faker } from '@faker-js/faker'; -import { DeepMocked, createMock } from '@golevelup/ts-jest'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { + CommonCartridgeElementType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { + CommonCartridgeResourceFactory, + CommonCartridgeResourceProps, +} from '../../resources/common-cartridge-resource-factory'; +import { CommonCartridgeElementFactory, CommonCartridgeElementProps } from '../common-cartridge-element-factory'; import { CommonCartridgeOrganizationElementPropsV110, CommonCartridgeOrganizationElementV110, @@ -9,21 +16,37 @@ import { describe('CommonCartridgeOrganizationElementV110', () => { const setup = () => { - const item: DeepMocked = createMock(); - - const props: CommonCartridgeOrganizationElementPropsV110 = { + const resourceProps: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_LINK, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + url: faker.internet.url(), + }; + const subOrganizationProps: CommonCartridgeElementProps = { + type: CommonCartridgeElementType.ORGANIZATION, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + items: CommonCartridgeResourceFactory.createResource({ + ...resourceProps, + version: CommonCartridgeVersion.V_1_1_0, + folder: faker.string.alphanumeric(10), + }), + }; + const organizationProps: CommonCartridgeOrganizationElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_1_0, identifier: faker.string.uuid(), title: faker.lorem.words(), - items: [item], + items: [ + CommonCartridgeElementFactory.createElement({ + ...subOrganizationProps, + version: CommonCartridgeVersion.V_1_1_0, + }), + ], }; - const sut = new CommonCartridgeOrganizationElementV110(props); - - item.getManifestXmlObject.mockReturnValueOnce({}); - item.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_1_0); + const sut = new CommonCartridgeOrganizationElementV110(organizationProps); - return { sut, props }; + return { sut, organizationProps, subOrganizationProps, resourceProps }; }; describe('getSupportedVersion', () => { @@ -41,24 +64,25 @@ describe('CommonCartridgeOrganizationElementV110', () => { // AI next 12 lines describe('when using common cartridge version 1.1.0', () => { it('should return correct manifest xml object', () => { - const { sut, props } = setup(); + const { sut, organizationProps, subOrganizationProps, resourceProps } = setup(); const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ $: { - identifier: props.identifier, + identifier: organizationProps.identifier, }, - title: props.title, - item: [{}], + title: organizationProps.title, + item: [ + { + $: { + identifier: subOrganizationProps.identifier, + identifierref: resourceProps.identifier, + }, + title: subOrganizationProps.title, + }, + ], }); }); - - it('should call getManifestXmlObject on item', () => { - const { sut, props } = setup(); - sut.getManifestXmlObject(); - - expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); - }); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts index f94298ad68c..d80c36cd4e3 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts @@ -1,16 +1,17 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; export type CommonCartridgeOrganizationElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATION; version: CommonCartridgeVersion; identifier: string; title: string; - items: CommonCartridgeElement[]; + items: CommonCartridgeResource | Array; }; export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeOrganizationElementPropsV110) { + public constructor(protected readonly props: CommonCartridgeOrganizationElementPropsV110) { super(props); } @@ -19,13 +20,34 @@ export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeEleme } public override getManifestXmlObject(): Record { + if (this.props.items instanceof CommonCartridgeResource) { + return { + $: { + identifier: this.identifier, + identifierref: this.props.items.identifier, + }, + title: this.title, + }; + } + return { $: { - identifier: this.props.identifier, - identifierref: this.props.items.length === 1 ? this.props.items[0].identifier : undefined, + identifier: this.identifier, }, - title: this.props.title, - // item: this.props.items.map((item) => item.getManifestXmlObject()), + title: this.title, + item: this.props.items.map((item) => { + if (item instanceof CommonCartridgeResource) { + return { + $: { + identifier: item.identifier, + identifierref: item.identifier, + }, + title: item.title, + }; + } + + return item.getManifestXmlObject(); + }), }; } } diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts index 67bfa3dd6ce..c34c4fa6cbb 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts @@ -1,12 +1,13 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; export type CommonCartridgeOrganizationElementPropsV130 = { type: CommonCartridgeElementType.ORGANIZATION; version: CommonCartridgeVersion; identifier: string; title: string; - items: CommonCartridgeElement[]; + items: CommonCartridgeResource | Array; }; export class CommonCartridgeOrganizationElementV130 extends CommonCartridgeElement { @@ -19,13 +20,34 @@ export class CommonCartridgeOrganizationElementV130 extends CommonCartridgeEleme } public override getManifestXmlObject(): Record { + if (this.props.items instanceof CommonCartridgeResource) { + return { + $: { + identifier: this.identifier, + identifierref: this.props.items.identifier, + }, + title: this.title, + }; + } + return { $: { - identifier: this.props.identifier, - identifierref: this.props.items.length === 1 ? this.props.items[0].identifier : undefined, + identifier: this.identifier, }, - title: this.props.title, - // item: this.props.items.map((item) => item.getManifestXmlObject()), + title: this.title, + item: this.props.items.map((item) => { + if (item instanceof CommonCartridgeResource) { + return { + $: { + identifier: item.identifier, + identifierref: item.identifier, + }, + title: item.title, + }; + } + + return item.getManifestXmlObject(); + }), }; } } diff --git a/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts index 8e1a9368efe..b76da84c765 100644 --- a/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts @@ -4,6 +4,7 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; type CommonCartridgeElementProps = { version: CommonCartridgeVersion; identifier?: string; + title?: string; }; /** @@ -18,6 +19,10 @@ export abstract class CommonCartridgeElement { return this.baseProps.identifier; } + public get title(): string | undefined { + return this.baseProps.title; + } + /** * Every element must know which versions it supports. * @returns The supported versions for this element. diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index 0c18bf5d386..44c3cd8ffc4 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -33,14 +33,14 @@ describe('CommonCartridgeManifestResourceV110', () => { version: CommonCartridgeVersion.V_1_1_0, title: 'Title 1', identifier: 'o1', - items: [resource1], + items: resource1, }); const organization2 = CommonCartridgeElementFactory.createElement({ type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_1_0, title: 'Title 2', identifier: 'o2', - items: [resource2], + items: resource2, }); const metadata = CommonCartridgeElementFactory.createElement({ type: CommonCartridgeElementType.METADATA, diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index 12728722bc6..c0f61888101 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -34,14 +34,14 @@ describe('CommonCartridgeManifestResourceV110', () => { version: CommonCartridgeVersion.V_1_3_0, title: 'Title 1', identifier: 'o1', - items: [resource1], + items: resource1, }); const organization2 = CommonCartridgeElementFactory.createElement({ type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_3_0, title: 'Title 2', identifier: 'o2', - items: [resource2], + items: resource2, }); const metadata = CommonCartridgeElementFactoryV130.createElement({ type: CommonCartridgeElementType.METADATA, From 9d43b4ced81bb69e82a151c0067de1348d89cf4f Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 20 Dec 2023 09:54:54 +0100 Subject: [PATCH 104/177] EW-539 Adjust mapper test --- .../mapper/common-cartridge.mapper.spec.ts | 59 +++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index 75c1ac7e9fb..91194090dba 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -4,12 +4,14 @@ import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { ComponentProperties, ComponentType } from '@shared/domain'; import { courseFactory, lessonFactory, setupEntities, taskFactory, userFactory } from '@shared/testing'; +import { OmitVersion } from '@src/modules/common-cartridge/utils'; import { - CommonCartridgeMetadataElementProps, + CommonCartridgeElementProps, + CommonCartridgeElementType, + CommonCartridgeIntendedUseType, CommonCartridgeOrganizationBuilderOptions, CommonCartridgeResourceProps, CommonCartridgeResourceType, - OmitVersion, } from '../../common-cartridge'; import { LearnroomConfig } from '../learnroom.config'; import { CommonCartridgeMapper } from './common-cartridge.mapper'; @@ -60,7 +62,8 @@ describe('CommonCartridgeMapper', () => { const { course } = setup(); const metadataProps = sut.mapCourseToMetadata(course); - expect(metadataProps).toStrictEqual>({ + expect(metadataProps).toStrictEqual({ + type: CommonCartridgeElementType.METADATA, title: course.name, copyrightOwners: course.teachers .toArray() @@ -141,6 +144,7 @@ describe('CommonCartridgeMapper', () => { identifier: task.id, title: task.name, html: `

${task.name}

${task.description}

`, + intendedUse: CommonCartridgeIntendedUseType.ASSIGNMENT, }); }); }); @@ -194,6 +198,7 @@ describe('CommonCartridgeMapper', () => { identifier: expect.any(String), title: componentProps.title, html: `

${componentProps.title}

${componentProps?.content.text}

`, + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, }); }); }); @@ -260,7 +265,7 @@ describe('CommonCartridgeMapper', () => { }); }); - describe('when mapping learning store content to resources', () => { + describe('when mapping learn store content to resources', () => { const setup = () => { const componentProps: ComponentProperties = { _id: 'id', @@ -298,5 +303,51 @@ describe('CommonCartridgeMapper', () => { ]); }); }); + + describe('when no learn store content is provided', () => { + const setup = () => { + const componentProps: ComponentProperties = { + _id: 'id', + title: 'title', + hidden: false, + component: ComponentType.LERNSTORE, + }; + + configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + + return { componentProps }; + }; + + it('should map to empty array', () => { + const { componentProps } = setup(); + const resourceProps = sut.mapContentToResources(componentProps); + + expect(resourceProps).toEqual([]); + }); + }); + + describe('when mapping unknown content', () => { + const setup = () => { + const unknownComponentProps: ComponentProperties = { + title: 'title', + hidden: false, + component: ComponentType.INTERNAL, + content: { + url: 'url', + }, + }; + + configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + + return { unknownComponentProps }; + }; + + it('should map to empty array', () => { + const { unknownComponentProps } = setup(); + const resourceProps = sut.mapContentToResources(unknownComponentProps); + + expect(resourceProps).toEqual([]); + }); + }); }); }); From 0fdeeabe8cfdb9e3622c4f9041a03baec389e2ea Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 20 Dec 2023 10:31:28 +0100 Subject: [PATCH 105/177] Fixing test coverage for resource factories --- .../common-cartridge-resource-factory.spec.ts | 49 ++++++++++++------- .../common-cartridge-resource-factory.spec.ts | 47 ++++++++++++------ 2 files changed, 64 insertions(+), 32 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts index f84972637a2..ab733af46f9 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts @@ -1,28 +1,42 @@ -import { faker } from '@faker-js/faker'; +import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeIntendedUseType, CommonCartridgeResourceType, CommonCartridgeVersion, } from '../../common-cartridge.enums'; +import { + CommonCartridgeManifestResourcePropsV110, + CommonCartridgeManifestResourceV110, +} from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV110 } from './common-cartridge-resource-factory'; -import { CommonCartridgeWebContentResourceV110 } from './common-cartridge-web-content-resource'; -import { CommonCartridgeWebLinkResourceV110 } from './common-cartridge-web-link-resource'; +import { + CommonCartridgeWebContentResourcePropsV110, + CommonCartridgeWebContentResourceV110, +} from './common-cartridge-web-content-resource'; +import { + CommonCartridgeWebLinkResourcePropsV110, + CommonCartridgeWebLinkResourceV110, +} from './common-cartridge-web-link-resource'; describe('CommonCartridgeResourceFactoryV110', () => { describe('createResource', () => { describe('when creating resources from props', () => { + it('should return manifest resource', () => { + const result = CommonCartridgeResourceFactoryV110.createResource({ + type: CommonCartridgeResourceType.MANIFEST, + version: CommonCartridgeVersion.V_1_1_0, + } as CommonCartridgeManifestResourcePropsV110); + + expect(result).toBeInstanceOf(CommonCartridgeManifestResourceV110); + }); + it('should return web content resource', () => { const result = CommonCartridgeResourceFactoryV110.createResource({ type: CommonCartridgeResourceType.WEB_CONTENT, version: CommonCartridgeVersion.V_1_1_0, - folder: faker.string.uuid(), - identifier: faker.string.uuid(), - title: faker.lorem.words(), - html: faker.lorem.paragraph(), intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }); + } as CommonCartridgeWebContentResourcePropsV110); - expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV110); }); @@ -30,17 +44,18 @@ describe('CommonCartridgeResourceFactoryV110', () => { const result = CommonCartridgeResourceFactoryV110.createResource({ type: CommonCartridgeResourceType.WEB_LINK, version: CommonCartridgeVersion.V_1_1_0, - folder: faker.string.uuid(), - identifier: faker.string.uuid(), - title: faker.lorem.words(), - url: faker.internet.url(), - target: faker.lorem.word(), - windowFeatures: faker.lorem.words(), - }); + } as CommonCartridgeWebLinkResourcePropsV110); - expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeWebLinkResourceV110); }); }); + + describe('when resource type is not supported', () => { + it('should throw error', () => { + expect(() => + CommonCartridgeResourceFactoryV110.createResource({} as CommonCartridgeWebLinkResourcePropsV110) + ).toThrow(InternalServerErrorException); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts index 60a9c0e5946..c186a29527f 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts @@ -1,26 +1,41 @@ -import { faker } from '@faker-js/faker'; +import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeIntendedUseType, CommonCartridgeResourceType, CommonCartridgeVersion, } from '../../common-cartridge.enums'; +import { + CommonCartridgeManifestResourcePropsV130, + CommonCartridgeManifestResourceV130, +} from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV130 } from './common-cartridge-resource-factory'; -import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; -import { CommonCartridgeWebLinkResourceV130 } from './common-cartridge-web-link-resource'; +import { + CommonCartridgeWebContentResourcePropsV130, + CommonCartridgeWebContentResourceV130, +} from './common-cartridge-web-content-resource'; +import { + CommonCartridgeWebLinkResourcePropsV130, + CommonCartridgeWebLinkResourceV130, +} from './common-cartridge-web-link-resource'; describe('CommonCartridgeResourceFactoryV130', () => { describe('createResource', () => { describe('when creating resources from props', () => { + it('should return manifest resource', () => { + const result = CommonCartridgeResourceFactoryV130.createResource({ + type: CommonCartridgeResourceType.MANIFEST, + version: CommonCartridgeVersion.V_1_3_0, + } as CommonCartridgeManifestResourcePropsV130); + + expect(result).toBeInstanceOf(CommonCartridgeManifestResourceV130); + }); + it('shoul return web content resource', () => { const result = CommonCartridgeResourceFactoryV130.createResource({ type: CommonCartridgeResourceType.WEB_CONTENT, version: CommonCartridgeVersion.V_1_3_0, - folder: faker.string.uuid(), - identifier: faker.string.uuid(), - title: faker.lorem.words(), - html: faker.lorem.paragraph(), intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }); + } as CommonCartridgeWebContentResourcePropsV130); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV130); }); @@ -29,16 +44,18 @@ describe('CommonCartridgeResourceFactoryV130', () => { const result = CommonCartridgeResourceFactoryV130.createResource({ type: CommonCartridgeResourceType.WEB_LINK, version: CommonCartridgeVersion.V_1_3_0, - folder: faker.string.uuid(), - identifier: faker.string.uuid(), - title: faker.lorem.words(), - url: faker.internet.url(), - target: faker.lorem.word(), - windowFeatures: faker.lorem.words(), - }); + } as CommonCartridgeWebLinkResourcePropsV130); expect(result).toBeInstanceOf(CommonCartridgeWebLinkResourceV130); }); }); + + describe('when resource type is not supported', () => { + it('should throw error', () => { + expect(() => + CommonCartridgeResourceFactoryV130.createResource({} as CommonCartridgeWebLinkResourcePropsV130) + ).toThrow(InternalServerErrorException); + }); + }); }); }); From 0632cd2e0bb6e733c9c3583552cf3fb3fd3bf3a3 Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 20 Dec 2023 11:10:14 +0100 Subject: [PATCH 106/177] Finishing resources --- .../common-cartridge-element.interface.ts | 4 +- ...common-cartridge-manifest-resource.spec.ts | 18 +++++- ...mon-cartridge-web-content-resource.spec.ts | 59 ++++++++++++------- ...common-cartridge-web-link-resource.spec.ts | 28 +++++++-- ...common-cartridge-manifest-resource.spec.ts | 18 +++++- ...mon-cartridge-web-content-resource.spec.ts | 13 ++++ ...common-cartridge-web-link-resource.spec.ts | 27 +++++++-- 7 files changed, 133 insertions(+), 34 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts index b76da84c765..17cf932a85e 100644 --- a/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts @@ -1,5 +1,5 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { createVersionNotSupportedError } from '../utils'; type CommonCartridgeElementProps = { version: CommonCartridgeVersion; @@ -40,6 +40,6 @@ export abstract class CommonCartridgeElement { return; } - throw new InternalServerErrorException(`Common Cartridge version ${target} is not supported`); + throw createVersionNotSupportedError(target); } } diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index 44c3cd8ffc4..6cafe7c4f97 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -1,3 +1,4 @@ +import { InternalServerErrorException } from '@nestjs/common'; import { readFile } from 'fs/promises'; import { CommonCartridgeElementType, @@ -7,7 +8,10 @@ import { } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; -import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; +import { + CommonCartridgeManifestResourcePropsV110, + CommonCartridgeManifestResourceV110, +} from './common-cartridge-manifest-resource'; describe('CommonCartridgeManifestResourceV110', () => { const setup = () => { @@ -107,5 +111,17 @@ describe('CommonCartridgeManifestResourceV110', () => { expect(result).toBe(CommonCartridgeVersion.V_1_1_0); }); }); + + describe('when using not supported Common Cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeManifestResourceV110({ + type: CommonCartridgeResourceType.MANIFEST, + version: CommonCartridgeVersion.V_1_3_0, + } as CommonCartridgeManifestResourcePropsV110) + ).toThrow(InternalServerErrorException); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts index d3770b677b7..b35e3c00165 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts @@ -1,4 +1,5 @@ import { faker } from '@faker-js/faker'; +import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeIntendedUseType, CommonCartridgeResourceType, @@ -48,39 +49,57 @@ describe('CommonCartridgeWebContentResourceV110', () => { }); describe('getFileContent', () => { - it('should return the HTML', () => { - const { sut, props } = setup(); - const result = sut.getFileContent(); + describe('when using Common Cartridge version 1.1.0', () => { + it('should return the HTML', () => { + const { sut, props } = setup(); + const result = sut.getFileContent(); - expect(result).toBe(props.html); + expect(result).toBe(props.html); + }); }); }); describe('getSupportedVersion', () => { - it('should return Common Cartridge version 1.1.0', () => { - const { sut } = setup(); - const result = sut.getSupportedVersion(); + describe('when using Common Cartridge version 1.1.0', () => { + it('should return Common Cartridge version 1.1.0', () => { + const { sut } = setup(); + const result = sut.getSupportedVersion(); + + expect(result).toBe(CommonCartridgeVersion.V_1_1_0); + }); + }); - expect(result).toBe(CommonCartridgeVersion.V_1_1_0); + describe('when using not supported Common Cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeWebContentResourceV110({ + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_3_0, + } as CommonCartridgeWebContentResourcePropsV110) + ).toThrow(InternalServerErrorException); + }); }); }); describe('getManifestXmlObject', () => { - it('should return the correct XML object', () => { - const { sut, props } = setup(); - const result = sut.getManifestXmlObject(); + describe('when using Common Cartridge version 1.1.0', () => { + it('should return the correct XML object', () => { + const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); - expect(result).toEqual({ - $: { - identifier: props.identifier, - type: 'webcontent', - intendeduse: props.intendedUse, - }, - file: { + expect(result).toEqual({ $: { - href: sut.getFilePath(), + identifier: props.identifier, + type: 'webcontent', + intendeduse: props.intendedUse, + }, + file: { + $: { + href: sut.getFilePath(), + }, }, - }, + }); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts index f831c84832b..c87818b6856 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -1,4 +1,5 @@ import { faker } from '@faker-js/faker'; +import { InternalServerErrorException } from '@nestjs/common'; import { readFile } from 'fs/promises'; import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { @@ -46,12 +47,17 @@ describe('CommonCartridgeWebLinkResourceV110', () => { }); describe('getFileContent', () => { - it('should contain correct XML', async () => { - const { sut } = setup(); - const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml', 'utf8'); - const result = sut.getFileContent(); + describe('when using Common Cartridge version 1.1.0', () => { + it('should contain correct XML', async () => { + const { sut } = setup(); + const expected = await readFile( + './apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml', + 'utf8' + ); + const result = sut.getFileContent(); - expect(result).toEqual(expected); + expect(result).toEqual(expected); + }); }); }); @@ -64,6 +70,18 @@ describe('CommonCartridgeWebLinkResourceV110', () => { expect(result).toBe(CommonCartridgeVersion.V_1_1_0); }); }); + + describe('when using not supported Common Cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeWebLinkResourceV110({ + type: CommonCartridgeResourceType.WEB_LINK, + version: CommonCartridgeVersion.V_1_3_0, + } as CommonCartridgeWebLinkResourcePropsV110) + ).toThrow(InternalServerErrorException); + }); + }); }); describe('getManifestXmlObject', () => { diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index c0f61888101..13b321c971b 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -1,3 +1,4 @@ +import { InternalServerErrorException } from '@nestjs/common'; import { readFile } from 'fs/promises'; import { CommonCartridgeElementType, @@ -8,7 +9,10 @@ import { import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; import { CommonCartridgeElementFactoryV130 } from '../../elements/v1.3.0/common-cartridge-element-factory'; import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; -import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; +import { + CommonCartridgeManifestResourcePropsV130, + CommonCartridgeManifestResourceV130, +} from './common-cartridge-manifest-resource'; describe('CommonCartridgeManifestResourceV110', () => { const setup = () => { @@ -108,5 +112,17 @@ describe('CommonCartridgeManifestResourceV110', () => { expect(result).toBe(CommonCartridgeVersion.V_1_3_0); }); }); + + describe('when using not supported Common Cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeManifestResourceV130({ + type: CommonCartridgeResourceType.MANIFEST, + version: CommonCartridgeVersion.V_1_1_0, + } as CommonCartridgeManifestResourcePropsV130) + ).toThrow(InternalServerErrorException); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts index 1e1f6af9717..3206a0d70f7 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts @@ -1,4 +1,5 @@ import { faker } from '@faker-js/faker'; +import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeIntendedUseType, CommonCartridgeResourceType, @@ -67,6 +68,18 @@ describe('CommonCartridgeWebContentResourceV130', () => { expect(result).toBe(CommonCartridgeVersion.V_1_3_0); }); }); + + describe('when using not supported Common Cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeWebContentResourceV130({ + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_1_0, + } as CommonCartridgeWebContentResourcePropsV130) + ).toThrow(InternalServerErrorException); + }); + }); }); describe('getManifestXmlObject', () => { diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts index 49fdb11ff07..13e908feabe 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts @@ -46,12 +46,17 @@ describe('CommonCartridgeWebLinkResourceV130', () => { }); describe('getFileContent', () => { - it('should contain correct XML', async () => { - const { sut } = setup(); - const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml', 'utf8'); - const result = sut.getFileContent(); + describe('when using Common Cartridge version 1.3.0', () => { + it('should contain correct XML', async () => { + const { sut } = setup(); + const expected = await readFile( + './apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml', + 'utf8' + ); + const result = sut.getFileContent(); - expect(result).toEqual(expected); + expect(result).toEqual(expected); + }); }); }); @@ -64,6 +69,18 @@ describe('CommonCartridgeWebLinkResourceV130', () => { expect(result).toBe(CommonCartridgeVersion.V_1_3_0); }); }); + + describe('when using not supported Common Cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeWebLinkResourceV130({ + type: CommonCartridgeResourceType.WEB_LINK, + version: CommonCartridgeVersion.V_1_1_0, + } as CommonCartridgeWebLinkResourcePropsV130) + ).toThrow(); + }); + }); }); describe('getManifestXmlObject', () => { From dbcda23f1b9db78d5737444f2cb0f099a36a25b6 Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 20 Dec 2023 11:27:19 +0100 Subject: [PATCH 107/177] Fixing test coverage for element factories --- .../common-cartridge-element-factory.spec.ts | 53 +++++++++++-------- .../common-cartridge-element-factory.spec.ts | 49 ++++++++++------- 2 files changed, 61 insertions(+), 41 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts index 62fec411b8e..39830695c5e 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts @@ -1,10 +1,22 @@ -import { faker } from '@faker-js/faker/locale/af_ZA'; +import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactoryV110 } from './common-cartridge-element-factory'; -import { CommonCartridgeMetadataElementV110 } from './common-cartridge-metadata-element'; -import { CommonCartridgeOrganizationElementV110 } from './common-cartridge-organization-element'; -import { CommonCartridgeOrganizationsWrapperElementV110 } from './common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElementV110 } from './common-cartridge-resources-wrapper-element'; +import { + CommonCartridgeMetadataElementPropsV110, + CommonCartridgeMetadataElementV110, +} from './common-cartridge-metadata-element'; +import { + CommonCartridgeOrganizationElementPropsV110, + CommonCartridgeOrganizationElementV110, +} from './common-cartridge-organization-element'; +import { + CommonCartridgeOrganizationsWrapperElementPropsV110, + CommonCartridgeOrganizationsWrapperElementV110, +} from './common-cartridge-organizations-wrapper-element'; +import { + CommonCartridgeResourcesWrapperElementPropsV110, + CommonCartridgeResourcesWrapperElementV110, +} from './common-cartridge-resources-wrapper-element'; describe('CommonCartridgeElementFactoryV110', () => { describe('createElement', () => { @@ -13,12 +25,8 @@ describe('CommonCartridgeElementFactoryV110', () => { const result = CommonCartridgeElementFactoryV110.createElement({ type: CommonCartridgeElementType.METADATA, version: CommonCartridgeVersion.V_1_1_0, - title: faker.lorem.words(), - creationDate: faker.date.past(), - copyrightOwners: [faker.person.fullName(), faker.person.fullName()], - }); + } as CommonCartridgeMetadataElementPropsV110); - expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV110); }); @@ -26,12 +34,8 @@ describe('CommonCartridgeElementFactoryV110', () => { const result = CommonCartridgeElementFactoryV110.createElement({ type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_1_0, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - items: [], - }); + } as CommonCartridgeOrganizationElementPropsV110); - expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeOrganizationElementV110); }); @@ -39,10 +43,8 @@ describe('CommonCartridgeElementFactoryV110', () => { const result = CommonCartridgeElementFactoryV110.createElement({ type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, version: CommonCartridgeVersion.V_1_1_0, - items: [], - }); + } as CommonCartridgeOrganizationsWrapperElementPropsV110); - expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeOrganizationsWrapperElementV110); }); @@ -50,12 +52,21 @@ describe('CommonCartridgeElementFactoryV110', () => { const result = CommonCartridgeElementFactoryV110.createElement({ type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: CommonCartridgeVersion.V_1_1_0, - items: [], - }); + } as CommonCartridgeResourcesWrapperElementPropsV110); - expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeResourcesWrapperElementV110); }); }); + + describe('when element type is not supported', () => { + it('should throw error', () => { + expect(() => + CommonCartridgeElementFactoryV110.createElement({ + type: 'not-supported' as CommonCartridgeElementType, + version: CommonCartridgeVersion.V_1_1_0, + } as CommonCartridgeMetadataElementPropsV110) + ).toThrow(InternalServerErrorException); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts index 4df0d41dcb2..f44b88f1e15 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts @@ -1,10 +1,20 @@ -import { faker } from '@faker-js/faker/locale/af_ZA'; +import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeOrganizationsWrapperElementPropsV110 } from '../v1.1.0/common-cartridge-organizations-wrapper-element'; import { CommonCartridgeElementFactoryV130 } from './common-cartridge-element-factory'; -import { CommonCartridgeMetadataElementV130 } from './common-cartridge-metadata-element'; -import { CommonCartridgeOrganizationElementV130 } from './common-cartridge-organization-element'; +import { + CommonCartridgeMetadataElementPropsV130, + CommonCartridgeMetadataElementV130, +} from './common-cartridge-metadata-element'; +import { + CommonCartridgeOrganizationElementPropsV130, + CommonCartridgeOrganizationElementV130, +} from './common-cartridge-organization-element'; import { CommonCartridgeOrganizationsWrapperElementV130 } from './common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElementV130 } from './common-cartridge-resources-wrapper-element'; +import { + CommonCartridgeResourcesWrapperElementPropsV130, + CommonCartridgeResourcesWrapperElementV130, +} from './common-cartridge-resources-wrapper-element'; describe('CommonCartridgeElementFactoryV130', () => { describe('createElement', () => { @@ -13,12 +23,8 @@ describe('CommonCartridgeElementFactoryV130', () => { const result = CommonCartridgeElementFactoryV130.createElement({ type: CommonCartridgeElementType.METADATA, version: CommonCartridgeVersion.V_1_3_0, - title: faker.lorem.words(), - creationDate: faker.date.past(), - copyrightOwners: [faker.person.fullName(), faker.person.fullName()], - }); + } as CommonCartridgeMetadataElementPropsV130); - expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV130); }); @@ -26,12 +32,8 @@ describe('CommonCartridgeElementFactoryV130', () => { const result = CommonCartridgeElementFactoryV130.createElement({ type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_3_0, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - items: [], - }); + } as CommonCartridgeOrganizationElementPropsV130); - expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeOrganizationElementV130); }); @@ -39,10 +41,8 @@ describe('CommonCartridgeElementFactoryV130', () => { const result = CommonCartridgeElementFactoryV130.createElement({ type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, version: CommonCartridgeVersion.V_1_3_0, - items: [], - }); + } as CommonCartridgeOrganizationsWrapperElementPropsV110); - expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeOrganizationsWrapperElementV130); }); @@ -50,12 +50,21 @@ describe('CommonCartridgeElementFactoryV130', () => { const result = CommonCartridgeElementFactoryV130.createElement({ type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: CommonCartridgeVersion.V_1_3_0, - items: [], - }); + } as CommonCartridgeResourcesWrapperElementPropsV130); - expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeResourcesWrapperElementV130); }); }); + + describe('when element type is not supported', () => { + it('should throw error', () => { + expect(() => + CommonCartridgeElementFactoryV130.createElement({ + type: 'not-supported' as CommonCartridgeElementType, + version: CommonCartridgeVersion.V_1_3_0, + } as CommonCartridgeResourcesWrapperElementPropsV130) + ).toThrow(InternalServerErrorException); + }); + }); }); }); From 3bebaf40aa2cc9ecfd39a21667197e43f1d7dcd4 Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 20 Dec 2023 12:09:58 +0100 Subject: [PATCH 108/177] Fixing tests for cc elements v1.1.0 --- .../common-cartridge-metadata-element.spec.ts | 15 +++- ...mon-cartridge-organization-element.spec.ts | 60 ++++++++++++-- ...idge-organizations-wrapper-element.spec.ts | 61 +++++++++----- ...artridge-resources-wrapper-element.spec.ts | 81 ++++++++++--------- 4 files changed, 150 insertions(+), 67 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts index 896d30ac116..09212d1165a 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts @@ -1,4 +1,5 @@ import { faker } from '@faker-js/faker'; +import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeMetadataElementPropsV110, @@ -29,10 +30,22 @@ describe('CommonCartridgeMetadataElementV110', () => { expect(result).toBe(CommonCartridgeVersion.V_1_1_0); }); }); + + describe('when using not supported Common Cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeMetadataElementV110({ + type: CommonCartridgeElementType.METADATA, + version: CommonCartridgeVersion.V_1_3_0, + } as CommonCartridgeMetadataElementPropsV110) + ).toThrow(InternalServerErrorException); + }); + }); }); describe('getManifestXmlObject', () => { - describe('when using common cartridge version 1.1', () => { + describe('when using Common Cartridge version 1.1', () => { it('should return correct manifest xml object', () => { const { sut, props } = setup(); const result = sut.getManifestXmlObject(); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts index 9ad699184b1..dd1979971d4 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts @@ -1,4 +1,5 @@ import { faker } from '@faker-js/faker'; +import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeElementType, CommonCartridgeResourceType, @@ -22,7 +23,7 @@ describe('CommonCartridgeOrganizationElementV110', () => { title: faker.lorem.words(), url: faker.internet.url(), }; - const subOrganizationProps: CommonCartridgeElementProps = { + const subOrganization1Props: CommonCartridgeElementProps = { type: CommonCartridgeElementType.ORGANIZATION, identifier: faker.string.uuid(), title: faker.lorem.words(), @@ -32,6 +33,18 @@ describe('CommonCartridgeOrganizationElementV110', () => { folder: faker.string.alphanumeric(10), }), }; + const subOrganization2Props: CommonCartridgeElementProps = { + type: CommonCartridgeElementType.ORGANIZATION, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + items: [ + CommonCartridgeResourceFactory.createResource({ + ...resourceProps, + version: CommonCartridgeVersion.V_1_1_0, + folder: faker.string.alphanumeric(10), + }), + ], + }; const organizationProps: CommonCartridgeOrganizationElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_1_0, @@ -39,18 +52,22 @@ describe('CommonCartridgeOrganizationElementV110', () => { title: faker.lorem.words(), items: [ CommonCartridgeElementFactory.createElement({ - ...subOrganizationProps, + ...subOrganization1Props, + version: CommonCartridgeVersion.V_1_1_0, + }), + CommonCartridgeElementFactory.createElement({ + ...subOrganization2Props, version: CommonCartridgeVersion.V_1_1_0, }), ], }; const sut = new CommonCartridgeOrganizationElementV110(organizationProps); - return { sut, organizationProps, subOrganizationProps, resourceProps }; + return { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps }; }; describe('getSupportedVersion', () => { - describe('when using common cartridge version 1.1.0', () => { + describe('when using Common Cartridge version 1.1.0', () => { it('should return correct version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -58,13 +75,25 @@ describe('CommonCartridgeOrganizationElementV110', () => { expect(result).toBe(CommonCartridgeVersion.V_1_1_0); }); }); + + describe('when using not supported Common Cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeOrganizationElementV110({ + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_3_0, + } as CommonCartridgeOrganizationElementPropsV110) + ).toThrowError(InternalServerErrorException); + }); + }); }); describe('getManifestXmlObject', () => { // AI next 12 lines - describe('when using common cartridge version 1.1.0', () => { + describe('when using Common Cartridge version 1.1.0', () => { it('should return correct manifest xml object', () => { - const { sut, organizationProps, subOrganizationProps, resourceProps } = setup(); + const { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps } = setup(); const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ @@ -75,10 +104,25 @@ describe('CommonCartridgeOrganizationElementV110', () => { item: [ { $: { - identifier: subOrganizationProps.identifier, + identifier: subOrganization1Props.identifier, identifierref: resourceProps.identifier, }, - title: subOrganizationProps.title, + title: subOrganization1Props.title, + }, + { + $: { + identifier: subOrganization2Props.identifier, + }, + title: subOrganization2Props.title, + item: [ + { + $: { + identifier: resourceProps.identifier, + identifierref: resourceProps.identifier, + }, + title: resourceProps.title, + }, + ], }, ], }); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts index 96e516e4172..08d655bb318 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -1,6 +1,7 @@ -import { DeepMocked, createMock } from '@golevelup/ts-jest'; +import { faker } from '@faker-js/faker'; +import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeElementFactory, CommonCartridgeElementProps } from '../common-cartridge-element-factory'; import { CommonCartridgeOrganizationsWrapperElementPropsV110, CommonCartridgeOrganizationsWrapperElementV110, @@ -8,24 +9,29 @@ import { describe('CommonCartridgeOrganizationsWrapperElementV110', () => { const setup = () => { - const item: DeepMocked = createMock(); - - // AI next 45 lines + const organizationProps: CommonCartridgeElementProps = { + type: CommonCartridgeElementType.ORGANIZATION, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + items: [], + }; const props: CommonCartridgeOrganizationsWrapperElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, version: CommonCartridgeVersion.V_1_1_0, - items: [item], + items: [ + CommonCartridgeElementFactory.createElement({ + ...organizationProps, + version: CommonCartridgeVersion.V_1_1_0, + }), + ], }; const sut = new CommonCartridgeOrganizationsWrapperElementV110(props); - item.getManifestXmlObject.mockReturnValueOnce({}); - item.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_1_0); - - return { sut, props }; + return { sut, props, organizationProps }; }; describe('getSupportedVersion', () => { - describe('when using common cartridge version 1.1.0', () => { + describe('when using Common Cartridge version 1.1.0', () => { it('should return correct version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -33,12 +39,24 @@ describe('CommonCartridgeOrganizationsWrapperElementV110', () => { expect(result).toBe(CommonCartridgeVersion.V_1_1_0); }); }); + + describe('when using not supported Common Cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeOrganizationsWrapperElementV110({ + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, + version: CommonCartridgeVersion.V_1_3_0, + } as CommonCartridgeOrganizationsWrapperElementPropsV110) + ).toThrowError(InternalServerErrorException); + }); + }); }); describe('getManifestXmlObject', () => { - describe('when using common cartridge version 1.1.0', () => { + describe('when using Common Cartridge version 1.1.0', () => { it('should return correct manifest xml object', () => { - const { sut } = setup(); + const { sut, organizationProps } = setup(); const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ @@ -53,20 +71,21 @@ describe('CommonCartridgeOrganizationsWrapperElementV110', () => { $: { identifier: 'LearningModules', }, - item: [{}], + item: [ + { + $: { + identifier: organizationProps.identifier, + }, + title: organizationProps.title, + item: [], + }, + ], }, ], }, ], }); }); - - it('should call getManifestXmlObject on item', () => { - const { sut, props } = setup(); - sut.getManifestXmlObject(); - - expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); - }); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts index f0c85a2fffe..676c3c83a54 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts @@ -1,6 +1,14 @@ -import { DeepMocked, createMock } from '@golevelup/ts-jest'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { faker } from '@faker-js/faker'; +import { InternalServerErrorException } from '@nestjs/common'; +import { + CommonCartridgeElementType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { + CommonCartridgeResourceFactory, + CommonCartridgeResourceProps, +} from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeResourcesWrapperElementPropsV110, CommonCartridgeResourcesWrapperElementV110, @@ -8,32 +16,26 @@ import { describe('CommonCartridgeResourcesWrapperElementV110', () => { const setup = () => { - const item1: DeepMocked = createMock(); - const item2: DeepMocked = createMock(); - - item1.getManifestXmlObject.mockReturnValueOnce({ - $: { - identifier: 'resource-1', - }, - }); - item1.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_1_0); - - item2.getManifestXmlObject.mockReturnValueOnce({ - $: { - identifier: 'resource-2', - }, - }); - item2.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_1_0); - + const resourceProps: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_LINK, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + url: faker.internet.url(), + }; const props: CommonCartridgeResourcesWrapperElementPropsV110 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: CommonCartridgeVersion.V_1_1_0, - items: [item1, item2], + items: [ + CommonCartridgeResourceFactory.createResource({ + ...resourceProps, + version: CommonCartridgeVersion.V_1_1_0, + folder: faker.string.alphanumeric(10), + }), + ], }; - const sut = new CommonCartridgeResourcesWrapperElementV110(props); - return { sut, props }; + return { sut, props, resourceProps }; }; describe('getSupportedVersion', () => { @@ -45,12 +47,24 @@ describe('CommonCartridgeResourcesWrapperElementV110', () => { expect(result).toBe(CommonCartridgeVersion.V_1_1_0); }); }); + + describe('when using not supported common cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeResourcesWrapperElementV110({ + type: CommonCartridgeElementType.RESOURCES_WRAPPER, + version: CommonCartridgeVersion.V_1_3_0, + } as CommonCartridgeResourcesWrapperElementPropsV110) + ).toThrow(InternalServerErrorException); + }); + }); }); describe('getManifestXmlObject', () => { describe('when using common cartridge version 1.1.0', () => { it('should return correct manifest xml object', () => { - const { sut } = setup(); + const { sut, resourceProps } = setup(); const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ @@ -59,12 +73,13 @@ describe('CommonCartridgeResourcesWrapperElementV110', () => { resource: [ { $: { - identifier: 'resource-1', + identifier: resourceProps.identifier, + type: expect.any(String), }, - }, - { - $: { - identifier: 'resource-2', + file: { + $: { + href: expect.any(String), + }, }, }, ], @@ -72,14 +87,6 @@ describe('CommonCartridgeResourcesWrapperElementV110', () => { ], }); }); - - it('should call getManifestXmlObject on both items', () => { - const { sut, props } = setup(); - sut.getManifestXmlObject(); - - expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); - expect(props.items[1].getManifestXmlObject).toHaveBeenCalledTimes(1); - }); }); }); }); From 7dc14d15bf661a9fb7ea00ac2c17e1a240c2500f Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 20 Dec 2023 13:44:23 +0100 Subject: [PATCH 109/177] Finishing cc elements for version 1.3.0 --- .../common-cartridge-metadata-element.spec.ts | 13 ++ ...mon-cartridge-organization-element.spec.ts | 114 ++++++++++++++---- ...idge-organizations-wrapper-element.spec.ts | 56 ++++++--- ...artridge-resources-wrapper-element.spec.ts | 83 +++++++------ 4 files changed, 187 insertions(+), 79 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts index 3bbe6d40802..191d4729562 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts @@ -1,4 +1,5 @@ import { faker } from '@faker-js/faker'; +import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeMetadataElementPropsV130, @@ -28,6 +29,18 @@ describe('CommonCartridgeMetadataElementV130', () => { expect(result).toBe(CommonCartridgeVersion.V_1_3_0); }); }); + + describe('when using not supported Common Cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeMetadataElementV130({ + type: CommonCartridgeElementType.METADATA, + version: CommonCartridgeVersion.V_1_1_0, + } as CommonCartridgeMetadataElementPropsV130) + ).toThrow(InternalServerErrorException); + }); + }); }); describe('getManifestXmlObject', () => { diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts index b038a43f60e..c9b83826d9f 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts @@ -1,7 +1,15 @@ import { faker } from '@faker-js/faker'; -import { DeepMocked, createMock } from '@golevelup/ts-jest'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { InternalServerErrorException } from '@nestjs/common'; +import { + CommonCartridgeElementType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { + CommonCartridgeResourceFactory, + CommonCartridgeResourceProps, +} from '../../resources/common-cartridge-resource-factory'; +import { CommonCartridgeElementFactory, CommonCartridgeElementProps } from '../common-cartridge-element-factory'; import { CommonCartridgeOrganizationElementPropsV130, CommonCartridgeOrganizationElementV130, @@ -9,21 +17,53 @@ import { describe('CommonCartridgeOrganizationElementV130', () => { const setup = () => { - const item: DeepMocked = createMock(); - - const props: CommonCartridgeOrganizationElementPropsV130 = { + const resourceProps: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_LINK, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + url: faker.internet.url(), + }; + const subOrganization1Props: CommonCartridgeElementProps = { + type: CommonCartridgeElementType.ORGANIZATION, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + items: CommonCartridgeResourceFactory.createResource({ + ...resourceProps, + version: CommonCartridgeVersion.V_1_3_0, + folder: faker.string.alphanumeric(10), + }), + }; + const subOrganization2Props: CommonCartridgeElementProps = { + type: CommonCartridgeElementType.ORGANIZATION, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + items: [ + CommonCartridgeResourceFactory.createResource({ + ...resourceProps, + version: CommonCartridgeVersion.V_1_3_0, + folder: faker.string.alphanumeric(10), + }), + ], + }; + const organizationProps: CommonCartridgeOrganizationElementPropsV130 = { type: CommonCartridgeElementType.ORGANIZATION, version: CommonCartridgeVersion.V_1_3_0, identifier: faker.string.uuid(), title: faker.lorem.words(), - items: [item], + items: [ + CommonCartridgeElementFactory.createElement({ + ...subOrganization1Props, + version: CommonCartridgeVersion.V_1_3_0, + }), + CommonCartridgeElementFactory.createElement({ + ...subOrganization2Props, + version: CommonCartridgeVersion.V_1_3_0, + }), + ], }; - const sut = new CommonCartridgeOrganizationElementV130(props); + const sut = new CommonCartridgeOrganizationElementV130(organizationProps); - item.getManifestXmlObject.mockReturnValueOnce({}); - item.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_3_0); - - return { sut, props }; + return { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps }; }; describe('getSupportedVersion', () => { @@ -35,29 +75,57 @@ describe('CommonCartridgeOrganizationElementV130', () => { expect(result).toBe(CommonCartridgeVersion.V_1_3_0); }); }); + + describe('when using not supported common cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeOrganizationElementV130({ + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_1_0, + } as CommonCartridgeOrganizationElementPropsV130) + ).toThrow(InternalServerErrorException); + }); + }); }); describe('getManifestXmlObject', () => { describe('when using common cartridge version 1.3.0', () => { it('should return correct manifest xml object', () => { - const { sut, props } = setup(); + const { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps } = setup(); const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ $: { - identifier: props.identifier, + identifier: organizationProps.identifier, }, - title: props.title, - item: [{}], + title: organizationProps.title, + item: [ + { + $: { + identifier: subOrganization1Props.identifier, + identifierref: resourceProps.identifier, + }, + title: subOrganization1Props.title, + }, + { + $: { + identifier: subOrganization2Props.identifier, + }, + title: subOrganization2Props.title, + item: [ + { + $: { + identifier: resourceProps.identifier, + identifierref: resourceProps.identifier, + }, + title: resourceProps.title, + }, + ], + }, + ], }); }); - - it('should call getManifestXmlObject on item', () => { - const { sut, props } = setup(); - sut.getManifestXmlObject(); - - expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); - }); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts index 06d86f8958d..8b3acb0e93e 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -1,6 +1,7 @@ -import { DeepMocked, createMock } from '@golevelup/ts-jest'; +import { faker } from '@faker-js/faker'; +import { InternalServerErrorException } from '@nestjs/common'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeElementFactory, CommonCartridgeElementProps } from '../common-cartridge-element-factory'; import { CommonCartridgeOrganizationsWrapperElementPropsV130, CommonCartridgeOrganizationsWrapperElementV130, @@ -8,19 +9,25 @@ import { describe('CommonCartridgeOrganizationsWrapperElementV130', () => { const setup = () => { - const item: DeepMocked = createMock(); - + const organizationProps: CommonCartridgeElementProps = { + type: CommonCartridgeElementType.ORGANIZATION, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + items: [], + }; const props: CommonCartridgeOrganizationsWrapperElementPropsV130 = { type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, version: CommonCartridgeVersion.V_1_3_0, - items: [item], + items: [ + CommonCartridgeElementFactory.createElement({ + ...organizationProps, + version: CommonCartridgeVersion.V_1_3_0, + }), + ], }; const sut = new CommonCartridgeOrganizationsWrapperElementV130(props); - item.getManifestXmlObject.mockReturnValueOnce({}); - item.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_3_0); - - return { sut, props }; + return { sut, props, organizationProps }; }; describe('getSupportedVersion', () => { @@ -32,12 +39,24 @@ describe('CommonCartridgeOrganizationsWrapperElementV130', () => { expect(result).toBe(CommonCartridgeVersion.V_1_3_0); }); }); + + describe('when using not supported common cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeOrganizationsWrapperElementV130({ + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, + version: CommonCartridgeVersion.V_1_1_0, + } as CommonCartridgeOrganizationsWrapperElementPropsV130) + ).toThrow(InternalServerErrorException); + }); + }); }); describe('getManifestXmlObject', () => { describe('when using common cartridge version 1.3.0', () => { it('should return correct manifest xml object', () => { - const { sut } = setup(); + const { sut, organizationProps } = setup(); const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ @@ -52,20 +71,21 @@ describe('CommonCartridgeOrganizationsWrapperElementV130', () => { $: { identifier: 'LearningModules', }, - item: [{}], + item: [ + { + $: { + identifier: organizationProps.identifier, + }, + title: organizationProps.title, + item: [], + }, + ], }, ], }, ], }); }); - - it('should call getManifestXmlObject on item', () => { - const { sut, props } = setup(); - sut.getManifestXmlObject(); - - expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); - }); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts index 2b3eddd44c2..cee1eab7eef 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts @@ -1,6 +1,14 @@ -import { DeepMocked, createMock } from '@golevelup/ts-jest'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { faker } from '@faker-js/faker'; +import { + CommonCartridgeElementType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { + CommonCartridgeResourceFactory, + CommonCartridgeResourceProps, +} from '../../resources/common-cartridge-resource-factory'; +import { CommonCartridgeResourcesWrapperElementPropsV110 } from '../v1.1.0/common-cartridge-resources-wrapper-element'; import { CommonCartridgeResourcesWrapperElementPropsV130, CommonCartridgeResourcesWrapperElementV130, @@ -8,32 +16,26 @@ import { describe('CommonCartridgeResourcesWrapperElementV130', () => { const setup = () => { - const item1: DeepMocked = createMock(); - const item2: DeepMocked = createMock(); - - item1.getManifestXmlObject.mockReturnValueOnce({ - $: { - identifier: 'resource-1', - }, - }); - item1.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_3_0); - - item2.getManifestXmlObject.mockReturnValueOnce({ - $: { - identifier: 'resource-2', - }, - }); - item2.getSupportedVersion.mockReturnValueOnce(CommonCartridgeVersion.V_1_3_0); - - const props: CommonCartridgeResourcesWrapperElementPropsV130 = { + const resourceProps: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_LINK, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + url: faker.internet.url(), + }; + const props: CommonCartridgeResourcesWrapperElementPropsV110 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: CommonCartridgeVersion.V_1_3_0, - items: [item1, item2], + items: [ + CommonCartridgeResourceFactory.createResource({ + ...resourceProps, + version: CommonCartridgeVersion.V_1_3_0, + folder: faker.string.alphanumeric(10), + }), + ], }; - const sut = new CommonCartridgeResourcesWrapperElementV130(props); - return { sut, props }; + return { sut, props, resourceProps }; }; describe('getSupportedVersion', () => { @@ -45,12 +47,24 @@ describe('CommonCartridgeResourcesWrapperElementV130', () => { expect(result).toBe(CommonCartridgeVersion.V_1_3_0); }); }); + + describe('when using not supported common cartridge version', () => { + it('should throw error', () => { + expect( + () => + new CommonCartridgeResourcesWrapperElementV130({ + type: CommonCartridgeElementType.RESOURCES_WRAPPER, + version: CommonCartridgeVersion.V_1_1_0, + } as CommonCartridgeResourcesWrapperElementPropsV130) + ).toThrowError(); + }); + }); }); describe('getManifestXmlObject', () => { describe('when using common cartridge version 1.3.0', () => { it('should return correct manifest xml object', () => { - const { sut } = setup(); + const { sut, resourceProps } = setup(); const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ @@ -59,12 +73,13 @@ describe('CommonCartridgeResourcesWrapperElementV130', () => { resource: [ { $: { - identifier: 'resource-1', + identifier: resourceProps.identifier, + type: expect.any(String), }, - }, - { - $: { - identifier: 'resource-2', + file: { + $: { + href: expect.any(String), + }, }, }, ], @@ -72,14 +87,6 @@ describe('CommonCartridgeResourcesWrapperElementV130', () => { ], }); }); - - it('should call getManifestXmlObject on both items', () => { - const { sut, props } = setup(); - sut.getManifestXmlObject(); - - expect(props.items[0].getManifestXmlObject).toHaveBeenCalledTimes(1); - expect(props.items[1].getManifestXmlObject).toHaveBeenCalledTimes(1); - }); }); }); }); From ef7a442dc0316e17e13913d4b5f472255b1bae83 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 21 Dec 2023 08:47:57 +0100 Subject: [PATCH 110/177] Fixing some tests --- .../common-cartridge-file-builder.spec.ts | 6 +- ...mon-cartridge-organization-builder.spec.ts | 133 ++++++++++-------- .../common-cartridge-organization-builder.ts | 26 +++- 3 files changed, 97 insertions(+), 68 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts index 27e93f93855..181629d750a 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts @@ -1,10 +1,11 @@ import AdmZip from 'adm-zip'; import { + CommonCartridgeElementType, CommonCartridgeIntendedUseType, CommonCartridgeResourceType, CommonCartridgeVersion, } from '../common-cartridge.enums'; -import { CommonCartridgeMetadataElementProps } from '../elements/common-cartridge-metadata-element'; +import { CommonCartridgeElementProps } from '../elements/common-cartridge-element-factory'; import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; import { OmitVersion } from '../utils'; import { CommonCartridgeFileBuilder, CommonCartridgeFileBuilderProps } from './common-cartridge-file-builder'; @@ -20,7 +21,8 @@ describe('CommonCartridgeFileBuilder', () => { version: CommonCartridgeVersion.V_1_1_0, identifier: 'manifest-identifier', }; - const metadataProps: OmitVersion = { + const metadataProps: CommonCartridgeElementProps = { + type: CommonCartridgeElementType.METADATA, title: 'metadata-title', creationDate: new Date(), copyrightOwners: ['John Doe', 'Jane Doe'], diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts index 5da9da121b4..6f7f5fd3ef0 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts @@ -1,9 +1,11 @@ +import { faker } from '@faker-js/faker/locale/af_ZA'; import { CommonCartridgeIntendedUseType, CommonCartridgeResourceType, CommonCartridgeVersion, } from '../common-cartridge.enums'; import { CommonCartridgeOrganizationElementV110 } from '../elements/v1.1.0/common-cartridge-organization-element'; +import { CommonCartridgeOrganizationElementV130 } from '../elements/v1.3.0/common-cartridge-organization-element'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; import { @@ -12,78 +14,91 @@ import { } from './common-cartridge-organization-builder'; describe('CommonCartridgeOrganizationBuilder', () => { - let sut: CommonCartridgeOrganizationBuilder; + describe('build', () => { + describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const resources = new Array(); + const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { + identifier: faker.string.uuid(), + title: faker.lorem.words(), + }; + const resourceProps: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + html: faker.lorem.paragraphs(), + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }; + const sut = new CommonCartridgeOrganizationBuilder( + { + ...organizationOptions, + version: CommonCartridgeVersion.V_1_1_0, + }, + (resource) => resources.push(resource) + ) + .addResource(resourceProps) + .addSubOrganization(organizationOptions) + .addResource(resourceProps) + .addSubOrganization(organizationOptions) + .addResource(resourceProps); - const resources = new Array(); + return { sut, resources }; + }; - const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { - title: 'organization-title', - identifier: 'organization-identifier', - }; - const subOrganizationOptions: CommonCartridgeOrganizationBuilderOptions = { - title: 'sub-organization-title', - identifier: 'sub-organization-identifier', - }; - const subSubOrganizationOptions: CommonCartridgeOrganizationBuilderOptions = { - title: 'sub-sub-organization-title', - identifier: 'sub-sub-organization-identifier', - }; - const resource1Props: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: 'resource-1-identifier', - title: 'resource-1-title', - html: '

resource-1-html

', - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }; - const resource2Props: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: 'resource-2-identifier', - title: 'resource-2-title', - html: '

resource-2-html

', - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }; - const resource3Props: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: 'resource-3-identifier', - title: 'resource-3-title', - html: '

resource-3-html

', - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }; + it('should return a common cartridge organization element', () => { + const { sut } = setup(); + const element = sut.build(); - beforeEach(() => { - jest.clearAllMocks(); - }); + expect(element).toBeInstanceOf(CommonCartridgeOrganizationElementV110); + }); - /* - TODO: - - create testfactories for CommonCartridgeResourceProps and CommonCartridgeOrganizationBuilderOptions - - move fixture creation into setup function (you can even inline it, eg. .addSubOrganization(CommonCartrigeOrganizationFactory.build())) - - use setup function instead of beforeAll to get rid of "global" variables - */ + it('should add 3 resources', () => { + const { resources } = setup(); - describe('build', () => { - describe('when creating a common cartridge archive', () => { - beforeAll(() => { - sut = new CommonCartridgeOrganizationBuilder( - { ...organizationOptions, version: CommonCartridgeVersion.V_1_1_0 }, - (resource) => resources.push(resource) - ); - sut.addResource(resource1Props) - .addSubOrganization(subOrganizationOptions) - .addResource(resource2Props) - .addSubOrganization(subSubOrganizationOptions) - .addResource(resource3Props) - .build(); + expect(resources).toHaveLength(3); }); + }); + + describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const resources = new Array(); + const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { + identifier: faker.string.uuid(), + title: faker.lorem.words(), + }; + const resourceProps: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + html: faker.lorem.paragraphs(), + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }; + const sut = new CommonCartridgeOrganizationBuilder( + { + ...organizationOptions, + version: CommonCartridgeVersion.V_1_3_0, + }, + (resource) => resources.push(resource) + ) + .addResource(resourceProps) + .addSubOrganization(organizationOptions) + .addResource(resourceProps) + .addSubOrganization(organizationOptions) + .addResource(resourceProps); + + return { sut, resources }; + }; it('should return a common cartridge organization element', () => { + const { sut } = setup(); const element = sut.build(); - expect(element).toBeDefined(); - expect(element).toBeInstanceOf(CommonCartridgeOrganizationElementV110); + expect(element).toBeInstanceOf(CommonCartridgeOrganizationElementV130); }); it('should add 3 resources', () => { + const { resources } = setup(); + expect(resources).toHaveLength(3); }); }); diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts index 9052316a80c..b1d6d6aef8a 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts @@ -19,9 +19,9 @@ type CommonCartridgeOrganizationBuilderOptionsInternal = { }; export class CommonCartridgeOrganizationBuilder { - private readonly items = new Array(); + private readonly resources: CommonCartridgeResource[] = []; - private readonly children = new Array(); + private readonly subOrganizations: CommonCartridgeOrganizationBuilder[] = []; public constructor( protected readonly options: CommonCartridgeOrganizationBuilderOptionsInternal, @@ -35,14 +35,14 @@ export class CommonCartridgeOrganizationBuilder { public addSubOrganization( options: OmitVersionAndFolder ): CommonCartridgeOrganizationBuilder { - const child = new CommonCartridgeOrganizationBuilder( + const subOrganization = new CommonCartridgeOrganizationBuilder( { ...options, version: this.options.version, folder: this.folder }, this.addResourceToFileBuilder.bind(this) ); - this.children.push(child); + this.subOrganizations.push(subOrganization); - return child; + return subOrganization; } public addResource(props: CommonCartridgeResourceProps): CommonCartridgeOrganizationBuilder { @@ -52,7 +52,7 @@ export class CommonCartridgeOrganizationBuilder { ...props, }); - this.items.push(resource); + this.resources.push(resource); this.addResourceToFileBuilder(resource); return this; @@ -64,9 +64,21 @@ export class CommonCartridgeOrganizationBuilder { version: this.options.version, identifier: this.options.identifier, title: this.options.title, - items: this.items, + items: this.buildItems(), }); return organizationElement; } + + private buildItems(): CommonCartridgeResource | (CommonCartridgeElement | CommonCartridgeResource)[] { + if (this.resources.length === 1 && this.subOrganizations.length === 0) { + const [resource] = this.resources; + + return resource; + } + + const items = [...this.resources, ...this.subOrganizations.map((subOrganization) => subOrganization.build())]; + + return items; + } } From e2aad01e7f40246a89e41cd0c71581862f4320de Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 21 Dec 2023 11:22:39 +0100 Subject: [PATCH 111/177] Fixing test coverage --- .../common-cartridge-file-builder.spec.ts | 115 ++++++++---------- ...mon-cartridge-organization-builder.spec.ts | 53 +------- 2 files changed, 54 insertions(+), 114 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts index 181629d750a..c9419c265cd 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts @@ -1,3 +1,4 @@ +import { faker } from '@faker-js/faker'; import AdmZip from 'adm-zip'; import { CommonCartridgeElementType, @@ -7,100 +8,84 @@ import { } from '../common-cartridge.enums'; import { CommonCartridgeElementProps } from '../elements/common-cartridge-element-factory'; import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; -import { OmitVersion } from '../utils'; -import { CommonCartridgeFileBuilder, CommonCartridgeFileBuilderProps } from './common-cartridge-file-builder'; +import { CommonCartridgeFileBuilder } from './common-cartridge-file-builder'; import { CommonCartridgeOrganizationBuilderOptions } from './common-cartridge-organization-builder'; describe('CommonCartridgeFileBuilder', () => { - let sut: CommonCartridgeFileBuilder; - let archive: AdmZip; - const getFileContentAsString = (zip: AdmZip, path: string): string | undefined => zip.getEntry(path)?.getData().toString(); - const fileBuilderOptions: CommonCartridgeFileBuilderProps = { - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'manifest-identifier', - }; - const metadataProps: CommonCartridgeElementProps = { - type: CommonCartridgeElementType.METADATA, - title: 'metadata-title', - creationDate: new Date(), - copyrightOwners: ['John Doe', 'Jane Doe'], - }; - const organizationOptions: OmitVersion = { - title: 'organization-title', - identifier: 'organization-identifier', - }; - const subOrganizationOptions: OmitVersion = { - title: 'sub-organization-title', - identifier: 'sub-organization-identifier', - }; - const subSubOrganizationOptions: OmitVersion = { - title: 'sub-sub-organization-title', - identifier: 'sub-sub-organization-identifier', - }; - const resource1Props: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: 'resource-1-identifier', - title: 'resource-1-title', - html: '

resource-1-html

', - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }; - const resource2Props: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: 'resource-2-identifier', - title: 'resource-2-title', - html: '

resource-2-html

', - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }; - const resource3Props: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: 'resource-3-identifier', - title: 'resource-3-title', - html: '

resource-3-html

', - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }; describe('build', () => { describe('when a common cartridge archive has been created', () => { - beforeAll(async () => { - sut = new CommonCartridgeFileBuilder(fileBuilderOptions); - sut.addMetadata(metadataProps) + const setup = async () => { + const metadataProps: CommonCartridgeElementProps = { + type: CommonCartridgeElementType.METADATA, + title: faker.lorem.words(), + creationDate: new Date(), + copyrightOwners: ['John Doe', 'Jane Doe'], + }; + const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { + identifier: faker.string.uuid(), + title: faker.lorem.words(), + }; + const resourceProps: CommonCartridgeResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + html: faker.lorem.paragraphs(), + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }; + const builder = new CommonCartridgeFileBuilder({ + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + }); + + builder + .addMetadata(metadataProps) .addOrganization(organizationOptions) - .addResource(resource1Props) - .addSubOrganization(subOrganizationOptions) - .addResource(resource2Props) - .addSubOrganization(subSubOrganizationOptions) - .addResource(resource3Props); + .addResource(resourceProps) + .addSubOrganization(organizationOptions) + .addResource(resourceProps) + .addSubOrganization(organizationOptions) + .addResource(resourceProps); - archive = new AdmZip(await sut.build()); - }); + const archive = new AdmZip(await builder.build()); + + return { archive, metadataProps, organizationOptions, resourceProps }; + }; - it('should have a imsmanifest.xml in archive root', () => { + it('should have a imsmanifest.xml in archive root', async () => { + const { archive } = await setup(); const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); expect(manifest).toBeDefined(); }); - it('should have included the resource in organization folder', () => { - const resource = getFileContentAsString(archive, 'organization-identifier/resource-1-identifier.html'); + it('should have included the resource in organization folder', async () => { + const { archive, organizationOptions, resourceProps } = await setup(); + const resource = getFileContentAsString( + archive, + `${organizationOptions.identifier}/${resourceProps.identifier}.html` + ); expect(resource).toBeDefined(); }); - it('should have included the resource in sub-organization folder', () => { + it('should have included the resource in sub-organization folder', async () => { + const { archive, organizationOptions, resourceProps } = await setup(); const resource = getFileContentAsString( archive, - 'organization-identifier/sub-organization-identifier/resource-2-identifier.html' + `${organizationOptions.identifier}/${organizationOptions.identifier}/${resourceProps.identifier}.html` ); expect(resource).toBeDefined(); }); - it('should have included the resource in sub-sub-organization folder', () => { + it('should have included the resource in sub-sub-organization folder', async () => { + const { archive, organizationOptions, resourceProps } = await setup(); const resource = getFileContentAsString( archive, - 'organization-identifier/sub-organization-identifier/sub-sub-organization-identifier/resource-3-identifier.html' + `${organizationOptions.identifier}/${organizationOptions.identifier}/${organizationOptions.identifier}/${resourceProps.identifier}.html` ); expect(resource).toBeDefined(); diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts index 6f7f5fd3ef0..f6b2e4ad888 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts @@ -4,8 +4,7 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion, } from '../common-cartridge.enums'; -import { CommonCartridgeOrganizationElementV110 } from '../elements/v1.1.0/common-cartridge-organization-element'; -import { CommonCartridgeOrganizationElementV130 } from '../elements/v1.3.0/common-cartridge-organization-element'; +import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; import { @@ -15,7 +14,7 @@ import { describe('CommonCartridgeOrganizationBuilder', () => { describe('build', () => { - describe('when using Common Cartridge version 1.1.0', () => { + describe('when building a Common Cartridge organization', () => { const setup = () => { const resources = new Array(); const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { @@ -45,55 +44,11 @@ describe('CommonCartridgeOrganizationBuilder', () => { return { sut, resources }; }; - it('should return a common cartridge organization element', () => { + it('should return a common cartridge element', () => { const { sut } = setup(); const element = sut.build(); - expect(element).toBeInstanceOf(CommonCartridgeOrganizationElementV110); - }); - - it('should add 3 resources', () => { - const { resources } = setup(); - - expect(resources).toHaveLength(3); - }); - }); - - describe('when using Common Cartridge version 1.3.0', () => { - const setup = () => { - const resources = new Array(); - const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { - identifier: faker.string.uuid(), - title: faker.lorem.words(), - }; - const resourceProps: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - html: faker.lorem.paragraphs(), - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }; - const sut = new CommonCartridgeOrganizationBuilder( - { - ...organizationOptions, - version: CommonCartridgeVersion.V_1_3_0, - }, - (resource) => resources.push(resource) - ) - .addResource(resourceProps) - .addSubOrganization(organizationOptions) - .addResource(resourceProps) - .addSubOrganization(organizationOptions) - .addResource(resourceProps); - - return { sut, resources }; - }; - - it('should return a common cartridge organization element', () => { - const { sut } = setup(); - const element = sut.build(); - - expect(element).toBeInstanceOf(CommonCartridgeOrganizationElementV130); + expect(element).toBeInstanceOf(CommonCartridgeElement); }); it('should add 3 resources', () => { From cfd01596c966d1eb86ac6605eb20e78c39679ce3 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 21 Dec 2023 15:25:33 +0100 Subject: [PATCH 112/177] Fixing errors after merge --- .../mapper/common-cartridge.mapper.ts | 2 +- .../common-cartridge-export.service.ts | 20 +++++++++---------- .../modules/learnroom/uc/course-export.uc.ts | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 11f87cbf068..43d23ae46b9 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; -import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain'; +import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain/entity'; import { ObjectId } from 'bson'; import { CommonCartridgeElementProps, diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index e81d8788f68..4b689b94441 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -44,15 +44,13 @@ export class CommonCartridgeExportService { ); lesson.contents.forEach((content) => { - const resourceProps = this.mapContentToResource(lesson.id, content, version); - if (resourceProps) { - organizationBuilder.addResourceToOrganization(resourceProps); - } + this.addComponentToOrganization(organizationBuilder, content); }); - const tasks = lesson.tasks.getItems(); - tasks.forEach((task) => { - organizationBuilder.addResourceToOrganization(this.mapTaskToWebContentResource(task, version)); + lesson.tasks.getItems().forEach((task) => { + organizationBuilder + .addSubOrganization(this.commonCartridgeMapper.mapTaskToOrganization(task)) + .addResource(this.commonCartridgeMapper.mapTaskToResource(task)); }); }); } @@ -61,13 +59,13 @@ export class CommonCartridgeExportService { const [tasks] = await this.taskService.findBySingleParent(userId, courseId); tasks.forEach((task) => { - const organization = builder.addOrganization(this.commonCartridgeMapper.mapTaskToOrganization(task)); - - organization.addResource(this.commonCartridgeMapper.mapTaskToResource(task)); + builder + .addOrganization(this.commonCartridgeMapper.mapTaskToOrganization(task)) + .addResource(this.commonCartridgeMapper.mapTaskToResource(task)); }); } - private addComponent( + private addComponentToOrganization( organizationBuilder: CommonCartridgeOrganizationBuilder, component: ComponentProperties ): void { diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.ts index bbb4a388157..87fdc557a65 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.ts @@ -3,7 +3,7 @@ import { AuthorizableReferenceType, AuthorizationReferenceService } from '@modul import { Injectable } from '@nestjs/common'; import { Permission } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; -import { CommonCartridgeVersion } from '../common-cartridge'; +import { CommonCartridgeVersion } from '../../common-cartridge'; import { CommonCartridgeExportService } from '../service/common-cartridge-export.service'; @Injectable() From 60e10f1fdd11398e95708ff46a1e3b02ffa42c3f Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 21 Dec 2023 15:45:13 +0100 Subject: [PATCH 113/177] EW-539 updating review-notes.md --- .../server/src/modules/common-cartridge/README.md | 15 --------------- .../src/modules/common-cartridge/review-notes.md | 14 ++++++++++---- 2 files changed, 10 insertions(+), 19 deletions(-) delete mode 100644 apps/server/src/modules/common-cartridge/README.md diff --git a/apps/server/src/modules/common-cartridge/README.md b/apps/server/src/modules/common-cartridge/README.md deleted file mode 100644 index d2831ef17f1..00000000000 --- a/apps/server/src/modules/common-cartridge/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Common Cartridge Module - -> This module contains all functionality to build an - -## XML Schema Namespaces and Definitions for Resources - -| Resource Type | XML Namespace | XSD Locations | -|:-|:-|:-| -| Manifest 1.1.0 || | -| Web Content 1.1.0 | - | - | -| Web Link 1.1.0 | http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 | | -| LTI | | | -| Manifest 1.3.0 || | -| Web Content 1.3.0 || | -| Web Link 1.3.0 || | diff --git a/apps/server/src/modules/common-cartridge/review-notes.md b/apps/server/src/modules/common-cartridge/review-notes.md index e446bd3a232..efc5233a688 100644 --- a/apps/server/src/modules/common-cartridge/review-notes.md +++ b/apps/server/src/modules/common-cartridge/review-notes.md @@ -3,18 +3,24 @@ - ~~put all course-independent code into a separate "common-cartridge" module~~ - ~~import common-cartridge into learnroom~~ - adjust all tests to avoid global variables. create factories where useful, and use setup function instead of beforeAll + - ~~common-cartridge~~ + - mapper + - export service ### EW-539 - ~~tests for CCManifestResource~~ - Check test coverage -- Cleanup FIXMEs + - ~~common-cartridge~~ + - mapper + - export service +- ~~Cleanup FIXMEs~~ - Manual tests - ~~createIdentifier method~~ -- merge main +- ~~merge main~~ - review.md and comments - ~~move in separate module~~ -- check index.ts +- ~~check index.ts~~ - ~~move xml files into test-assets folder~~ -- Adjust export-service +- ~~Adjust export-service~~ From 3fe70c7ff7359730611ac2877f4d2c944af59127 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 2 Jan 2024 00:28:53 +0100 Subject: [PATCH 114/177] EW-539 Working on mapper and export service --- .../mapper/common-cartridge.mapper.spec.ts | 6 +++-- .../mapper/common-cartridge.mapper.ts | 16 +++++++++++-- .../common-cartridge-export.service.spec.ts | 23 ++++++++++++++----- .../common-cartridge-export.service.ts | 21 ++++++++++++----- 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index 91194090dba..baf4467f961 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -2,7 +2,7 @@ import { DeepMocked, createMock } from '@golevelup/ts-jest'; import { MikroORM } from '@mikro-orm/core'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; -import { ComponentProperties, ComponentType } from '@shared/domain'; +import { ComponentProperties, ComponentType } from '@shared/domain/entity'; import { courseFactory, lessonFactory, setupEntities, taskFactory, userFactory } from '@shared/testing'; import { OmitVersion } from '@src/modules/common-cartridge/utils'; import { @@ -12,6 +12,7 @@ import { CommonCartridgeOrganizationBuilderOptions, CommonCartridgeResourceProps, CommonCartridgeResourceType, + CommonCartridgeVersion, } from '../../common-cartridge'; import { LearnroomConfig } from '../learnroom.config'; import { CommonCartridgeMapper } from './common-cartridge.mapper'; @@ -137,7 +138,7 @@ describe('CommonCartridgeMapper', () => { it('should map to web content', () => { const { task } = setup(); - const resourceProps = sut.mapTaskToResource(task); + const resourceProps = sut.mapTaskToResource(task, CommonCartridgeVersion.V_1_3_0); expect(resourceProps).toStrictEqual({ type: CommonCartridgeResourceType.WEB_CONTENT, @@ -305,6 +306,7 @@ describe('CommonCartridgeMapper', () => { }); describe('when no learn store content is provided', () => { + // AI next 16 lines const setup = () => { const componentProps: ComponentProperties = { _id: 'id', diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 43d23ae46b9..69adae8cde6 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -9,6 +9,7 @@ import { CommonCartridgeOrganizationBuilderOptions, CommonCartridgeResourceProps, CommonCartridgeResourceType, + CommonCartridgeVersion, } from '../../common-cartridge'; import { LearnroomConfig } from '../learnroom.config'; @@ -46,13 +47,24 @@ export class CommonCartridgeMapper { }; } - public mapTaskToResource(task: Task): CommonCartridgeResourceProps { + public mapTaskToResource(task: Task, version: CommonCartridgeVersion): CommonCartridgeResourceProps { + const intendedUse: CommonCartridgeIntendedUseType = (() => { + switch (version) { + case CommonCartridgeVersion.V_1_1_0: + return CommonCartridgeIntendedUseType.UNSPECIFIED; + case CommonCartridgeVersion.V_1_3_0: + return CommonCartridgeIntendedUseType.ASSIGNMENT; + default: + return CommonCartridgeIntendedUseType.UNSPECIFIED; + } + })(); + return { type: CommonCartridgeResourceType.WEB_CONTENT, identifier: task.id, title: task.name, html: `

${task.name}

${task.description}

`, - intendedUse: CommonCartridgeIntendedUseType.ASSIGNMENT, + intendedUse, }; } diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index 8f9d136b436..7ba0307968c 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -1,12 +1,15 @@ +import { faker } from '@faker-js/faker'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; -import { CommonCartridgeExportService, CourseService } from '@modules/learnroom'; +import { CommonCartridgeExportService, CourseService, LearnroomConfig } from '@modules/learnroom'; import { LessonService } from '@modules/lesson'; import { TaskService } from '@modules/task'; +import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { ComponentType, Course, LessonEntity, Task } from '@shared/domain/entity'; import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing'; import AdmZip from 'adm-zip'; import { CommonCartridgeVersion } from '../../common-cartridge'; +import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; describe('CommonCartridgeExportService', () => { let module: TestingModule; @@ -14,6 +17,7 @@ describe('CommonCartridgeExportService', () => { let courseServiceMock: DeepMocked; let lessonServiceMock: DeepMocked; let taskServiceMock: DeepMocked; + let configService: DeepMocked>; // move into setup methods let course: Course; @@ -30,6 +34,7 @@ describe('CommonCartridgeExportService', () => { module = await Test.createTestingModule({ providers: [ CommonCartridgeExportService, + CommonCartridgeMapper, { provide: CourseService, useValue: createMock(), @@ -42,12 +47,17 @@ describe('CommonCartridgeExportService', () => { provide: TaskService, useValue: createMock(), }, + { + provide: ConfigService, + useValue: createMock>(), + }, ], }).compile(); courseExportService = module.get(CommonCartridgeExportService); courseServiceMock = module.get(CourseService); lessonServiceMock = module.get(LessonService); taskServiceMock = module.get(TaskService); + configService = module.get(ConfigService); // TODO: everything below this line belongs into setup methods course = courseFactory.teachersWithId(2).buildWithId(); tasks = taskFactory.buildListWithId(2); @@ -74,7 +84,7 @@ describe('CommonCartridgeExportService', () => { url: 'url-1', }, { - client: 'board-2', + client: 'client-2', description: 'description-2', title: 'title-2', url: 'url-2', @@ -94,10 +104,11 @@ describe('CommonCartridgeExportService', () => { const setupExport = async (version: CommonCartridgeVersion) => { const [lesson] = lessons; - lessonServiceMock.findById.mockResolvedValueOnce(lesson); - courseServiceMock.findById.mockResolvedValueOnce(course); - lessonServiceMock.findByCourseIds.mockResolvedValueOnce([lessons, lessons.length]); - taskServiceMock.findBySingleParent.mockResolvedValueOnce([tasks, tasks.length]); + lessonServiceMock.findById.mockResolvedValue(lesson); + courseServiceMock.findById.mockResolvedValue(course); + lessonServiceMock.findByCourseIds.mockResolvedValue([lessons, lessons.length]); + taskServiceMock.findBySingleParent.mockResolvedValue([tasks, tasks.length]); + configService.getOrThrow.mockReturnValue(faker.internet.url()); const archive = new AdmZip(await courseExportService.exportCourse(course.id, 'user-id', version)); diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 4b689b94441..c0060fc932c 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -29,13 +29,17 @@ export class CommonCartridgeExportService { builder.addMetadata(this.commonCartridgeMapper.mapCourseToMetadata(course)); - await this.addLessons(builder, courseId); - await this.addTasks(builder, courseId, userId); + await this.addLessons(builder, courseId, version); + await this.addTasks(builder, courseId, userId, version); return builder.build(); } - private async addLessons(builder: CommonCartridgeFileBuilder, courseId: EntityId): Promise { + private async addLessons( + builder: CommonCartridgeFileBuilder, + courseId: EntityId, + version: CommonCartridgeVersion + ): Promise { const [lessons] = await this.lessonService.findByCourseIds([courseId]); lessons.forEach((lesson) => { @@ -50,18 +54,23 @@ export class CommonCartridgeExportService { lesson.tasks.getItems().forEach((task) => { organizationBuilder .addSubOrganization(this.commonCartridgeMapper.mapTaskToOrganization(task)) - .addResource(this.commonCartridgeMapper.mapTaskToResource(task)); + .addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); }); }); } - private async addTasks(builder: CommonCartridgeFileBuilder, courseId: EntityId, userId: EntityId): Promise { + private async addTasks( + builder: CommonCartridgeFileBuilder, + courseId: EntityId, + userId: EntityId, + version: CommonCartridgeVersion + ): Promise { const [tasks] = await this.taskService.findBySingleParent(userId, courseId); tasks.forEach((task) => { builder .addOrganization(this.commonCartridgeMapper.mapTaskToOrganization(task)) - .addResource(this.commonCartridgeMapper.mapTaskToResource(task)); + .addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); }); } From bdce2f03a27aae8d3740c03363dca2faec19554e Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 3 Jan 2024 10:58:33 +0100 Subject: [PATCH 115/177] EW-539 fixing test coverage --- .../src/modules/common-cartridge/utils.ts | 2 +- .../mapper/common-cartridge.mapper.spec.ts | 67 +++++--- .../mapper/common-cartridge.mapper.ts | 22 ++- .../common-cartridge-export.service.spec.ts | 147 +++++++++--------- .../common-cartridge-export.service.ts | 2 +- .../src/shared/domain/entity/lesson.entity.ts | 2 + 6 files changed, 135 insertions(+), 107 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/utils.ts b/apps/server/src/modules/common-cartridge/utils.ts index 9130f5b6753..8955a12e467 100644 --- a/apps/server/src/modules/common-cartridge/utils.ts +++ b/apps/server/src/modules/common-cartridge/utils.ts @@ -30,7 +30,7 @@ export function createElementTypeNotSupportedError(type: string): Error { return new InternalServerErrorException(`Common Cartridge element type ${type} is not supported`); } -export function createIdentifier(identifier: string | ObjectID | undefined): string { +export function createIdentifier(identifier?: string | ObjectID): string { if (!identifier) { return `i${new ObjectID().toString()}`; } diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index baf4467f961..b2da3338a90 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -1,10 +1,11 @@ +import { faker } from '@faker-js/faker'; import { DeepMocked, createMock } from '@golevelup/ts-jest'; import { MikroORM } from '@mikro-orm/core'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { ComponentProperties, ComponentType } from '@shared/domain/entity'; import { courseFactory, lessonFactory, setupEntities, taskFactory, userFactory } from '@shared/testing'; -import { OmitVersion } from '@src/modules/common-cartridge/utils'; +import { OmitVersion, createIdentifier } from '@src/modules/common-cartridge/utils'; import { CommonCartridgeElementProps, CommonCartridgeElementType, @@ -54,7 +55,7 @@ describe('CommonCartridgeMapper', () => { teachers: userFactory.buildListWithId(2), }); - configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); return { course }; }; @@ -80,7 +81,7 @@ describe('CommonCartridgeMapper', () => { const setup = () => { const lesson = lessonFactory.buildWithId(); - configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); return { lesson }; }; @@ -90,7 +91,7 @@ describe('CommonCartridgeMapper', () => { const organizationProps = sut.mapLessonToOrganization(lesson); expect(organizationProps).toStrictEqual>({ - identifier: lesson.id, + identifier: createIdentifier(lesson.id), title: lesson.name, }); }); @@ -109,7 +110,7 @@ describe('CommonCartridgeMapper', () => { }, }; - configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); return { componentProps }; }; @@ -127,28 +128,52 @@ describe('CommonCartridgeMapper', () => { }); describe('mapTaskToResource', () => { - describe('when mapping task', () => { - const setup = () => { - const task = taskFactory.buildWithId(); + const setup = () => { + const task = taskFactory.buildWithId(); - configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); - return { task }; - }; + return { task }; + }; - it('should map to web content', () => { + describe('when mapping task with version 1.3.0', () => { + it('should map task to web content', () => { const { task } = setup(); const resourceProps = sut.mapTaskToResource(task, CommonCartridgeVersion.V_1_3_0); expect(resourceProps).toStrictEqual({ type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: task.id, + identifier: createIdentifier(task.id), title: task.name, html: `

${task.name}

${task.description}

`, intendedUse: CommonCartridgeIntendedUseType.ASSIGNMENT, }); }); }); + + describe('when using other version than 1.3.0', () => { + it('should map to web content', () => { + const { task } = setup(); + const versions = [ + CommonCartridgeVersion.V_1_0_0, + CommonCartridgeVersion.V_1_1_0, + CommonCartridgeVersion.V_1_2_0, + CommonCartridgeVersion.V_1_4_0, + ]; + + versions.forEach((version) => { + const resourceProps = sut.mapTaskToResource(task, version); + + expect(resourceProps).toStrictEqual({ + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: createIdentifier(task.id), + title: task.name, + html: `

${task.name}

${task.description}

`, + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }); + }); + }); + }); }); describe('mapTaskToOrganization', () => { @@ -156,7 +181,7 @@ describe('CommonCartridgeMapper', () => { const setup = () => { const task = taskFactory.buildWithId(); - configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); return { task }; }; @@ -166,7 +191,7 @@ describe('CommonCartridgeMapper', () => { const organizationProps = sut.mapTaskToOrganization(task); expect(organizationProps).toStrictEqual>({ - identifier: task.id, + identifier: createIdentifier(task.id), title: task.name, }); }); @@ -185,7 +210,7 @@ describe('CommonCartridgeMapper', () => { }, }; - configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); return { componentProps }; }; @@ -215,7 +240,7 @@ describe('CommonCartridgeMapper', () => { }, }; - configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); return { componentProps }; }; @@ -248,7 +273,7 @@ describe('CommonCartridgeMapper', () => { }, }; - configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); return { componentProps }; }; @@ -285,7 +310,7 @@ describe('CommonCartridgeMapper', () => { }, }; - configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); return { componentProps }; }; @@ -315,7 +340,7 @@ describe('CommonCartridgeMapper', () => { component: ComponentType.LERNSTORE, }; - configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); return { componentProps }; }; @@ -339,7 +364,7 @@ describe('CommonCartridgeMapper', () => { }, }; - configServiceMock.getOrThrow.mockReturnValue('https://example.com'); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); return { unknownComponentProps }; }; diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 69adae8cde6..05a7c8c2a86 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain/entity'; -import { ObjectId } from 'bson'; +import { createIdentifier } from '@src/modules/common-cartridge/utils'; import { CommonCartridgeElementProps, CommonCartridgeElementType, @@ -28,30 +28,28 @@ export class CommonCartridgeMapper { public mapLessonToOrganization(lesson: LessonEntity): CommonCartridgeOrganizationBuilderOptions { return { - identifier: lesson.id, + identifier: createIdentifier(lesson.id), title: lesson.name, }; } public mapContentToOrganization(content: ComponentProperties): CommonCartridgeOrganizationBuilderOptions { return { - identifier: new ObjectId(content._id).toHexString(), + identifier: createIdentifier(content._id), title: content.title, }; } public mapTaskToOrganization(task: Task): CommonCartridgeOrganizationBuilderOptions { return { - identifier: task.id, + identifier: createIdentifier(task.id), title: task.name, }; } public mapTaskToResource(task: Task, version: CommonCartridgeVersion): CommonCartridgeResourceProps { - const intendedUse: CommonCartridgeIntendedUseType = (() => { + const intendedUse = (() => { switch (version) { - case CommonCartridgeVersion.V_1_1_0: - return CommonCartridgeIntendedUseType.UNSPECIFIED; case CommonCartridgeVersion.V_1_3_0: return CommonCartridgeIntendedUseType.ASSIGNMENT; default: @@ -61,7 +59,7 @@ export class CommonCartridgeMapper { return { type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: task.id, + identifier: createIdentifier(task.id), title: task.name, html: `

${task.name}

${task.description}

`, intendedUse, @@ -75,7 +73,7 @@ export class CommonCartridgeMapper { case ComponentType.TEXT: return { type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: new ObjectId(content._id).toHexString(), + identifier: createIdentifier(content._id), title: content.title, html: `

${content.title}

${content.content.text}

`, intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, @@ -83,7 +81,7 @@ export class CommonCartridgeMapper { case ComponentType.GEOGEBRA: return { type: CommonCartridgeResourceType.WEB_LINK, - identifier: new ObjectId(content._id).toHexString(), + identifier: createIdentifier(content._id), title: content.title, url: `${this.configService.getOrThrow( 'FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED' @@ -92,7 +90,7 @@ export class CommonCartridgeMapper { case ComponentType.ETHERPAD: return { type: CommonCartridgeResourceType.WEB_LINK, - identifier: new ObjectId(content._id).toHexString(), + identifier: createIdentifier(content._id), title: `${content.content.title} - ${content.content.description}`, url: content.content.url, }; @@ -101,7 +99,7 @@ export class CommonCartridgeMapper { content.content?.resources.map((resource) => { return { type: CommonCartridgeResourceType.WEB_LINK, - identifier: new ObjectId().toHexString(), + identifier: createIdentifier(), title: resource.description, url: resource.url, }; diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index 7ba0307968c..17ea5a50273 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -5,7 +5,7 @@ import { LessonService } from '@modules/lesson'; import { TaskService } from '@modules/task'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; -import { ComponentType, Course, LessonEntity, Task } from '@shared/domain/entity'; +import { ComponentType } from '@shared/domain/entity'; import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing'; import AdmZip from 'adm-zip'; import { CommonCartridgeVersion } from '../../common-cartridge'; @@ -13,16 +13,11 @@ import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; describe('CommonCartridgeExportService', () => { let module: TestingModule; - let courseExportService: CommonCartridgeExportService; + let sut: CommonCartridgeExportService; let courseServiceMock: DeepMocked; let lessonServiceMock: DeepMocked; let taskServiceMock: DeepMocked; - let configService: DeepMocked>; - - // move into setup methods - let course: Course; - let lessons: LessonEntity[]; - let tasks: Task[]; + let configServiceMock: DeepMocked>; const createXmlString = (nodeName: string, value: boolean | number | string): string => `<${nodeName}>${value.toString()}`; @@ -53,47 +48,11 @@ describe('CommonCartridgeExportService', () => { }, ], }).compile(); - courseExportService = module.get(CommonCartridgeExportService); + sut = module.get(CommonCartridgeExportService); courseServiceMock = module.get(CourseService); lessonServiceMock = module.get(LessonService); taskServiceMock = module.get(TaskService); - configService = module.get(ConfigService); - // TODO: everything below this line belongs into setup methods - course = courseFactory.teachersWithId(2).buildWithId(); - tasks = taskFactory.buildListWithId(2); - lessons = lessonFactory.buildListWithId(1, { - contents: [ - { - title: 'text-title', - hidden: false, - component: ComponentType.TEXT, - content: { - text: 'text', - }, - }, - { - title: 'lernstore-title', - hidden: false, - component: ComponentType.LERNSTORE, - content: { - resources: [ - { - client: 'client-1', - description: 'description-1', - title: 'title-1', - url: 'url-1', - }, - { - client: 'client-2', - description: 'description-2', - title: 'title-2', - url: 'url-2', - }, - ], - }, - }, - ], - }); + configServiceMock = module.get(ConfigService); }); afterAll(async () => { @@ -101,51 +60,91 @@ describe('CommonCartridgeExportService', () => { }); describe('exportCourse', () => { - const setupExport = async (version: CommonCartridgeVersion) => { + const setup = async (version: CommonCartridgeVersion) => { + const course = courseFactory.teachersWithId(2).buildWithId(); + const tasks = taskFactory.buildListWithId(2); + const lessons = lessonFactory.buildListWithId(1, { + tasks, + contents: [ + { + title: 'text-title', + hidden: false, + component: ComponentType.TEXT, + content: { + text: 'text', + }, + }, + { + title: 'lernstore-title', + hidden: false, + component: ComponentType.LERNSTORE, + content: { + resources: [ + { + client: 'client-1', + description: 'description-1', + title: 'title-1', + url: 'url-1', + }, + { + client: 'client-2', + description: 'description-2', + title: 'title-2', + url: 'url-2', + }, + ], + }, + }, + ], + }); const [lesson] = lessons; lessonServiceMock.findById.mockResolvedValue(lesson); courseServiceMock.findById.mockResolvedValue(course); lessonServiceMock.findByCourseIds.mockResolvedValue([lessons, lessons.length]); taskServiceMock.findBySingleParent.mockResolvedValue([tasks, tasks.length]); - configService.getOrThrow.mockReturnValue(faker.internet.url()); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); - const archive = new AdmZip(await courseExportService.exportCourse(course.id, 'user-id', version)); + const archive = new AdmZip(await sut.exportCourse(course.id, faker.string.uuid(), version)); - return archive; + return { archive, course, lessons, tasks }; }; describe('when using version 1.1', () => { - let archive: AdmZip; + it('should use schema version 1.1.0', async () => { + const { archive } = await setup(CommonCartridgeVersion.V_1_1_0); - beforeAll(async () => { - archive = await setupExport(CommonCartridgeVersion.V_1_1_0); - }); - - it('should use schema version 1.1.0', () => { expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('schemaversion', '1.1.0')); }); - it('should add course', () => { + it('should add course', async () => { + const { archive, course } = await setup(CommonCartridgeVersion.V_1_1_0); + expect(getFileContent(archive, 'imsmanifest.xml')).toContain( createXmlString('mnf:string', course.name) ); }); - it('should add lessons', () => { + it('should add lessons', async () => { + const { archive, lessons } = await setup(CommonCartridgeVersion.V_1_1_0); + lessons.forEach((lesson) => { expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('title', lesson.name)); }); }); - it('should add tasks', () => { + it('should add tasks', async () => { + const { archive, tasks } = await setup(CommonCartridgeVersion.V_1_1_0); + tasks.forEach((task) => { - expect(getFileContent(archive, 'imsmanifest.xml')).toContain(` { + it('should add tasks of lesson to manifest file', async () => { + const { archive, lessons } = await setup(CommonCartridgeVersion.V_1_1_0); const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); + lessons[0].tasks.getItems().forEach((task) => { expect(manifest).toContain(`${task.name}`); expect(manifest).toContain(`identifier="i${task.id}" type="webcontent" intendeduse="unspecified"`); @@ -154,36 +153,40 @@ describe('CommonCartridgeExportService', () => { }); describe('when using version 1.3', () => { - let archive: AdmZip; + it('should use schema version 1.3.0', async () => { + const { archive } = await setup(CommonCartridgeVersion.V_1_3_0); - beforeAll(async () => { - archive = await setupExport(CommonCartridgeVersion.V_1_3_0); - }); - - it('should use schema version 1.3.0', () => { expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('schemaversion', '1.3.0')); }); - it('should add course', () => { + it('should add course', async () => { + const { archive, course } = await setup(CommonCartridgeVersion.V_1_3_0); + expect(getFileContent(archive, 'imsmanifest.xml')).toContain( createXmlString('mnf:string', course.name) ); }); - it('should add lessons', () => { + it('should add lessons', async () => { + const { archive, lessons } = await setup(CommonCartridgeVersion.V_1_3_0); + lessons.forEach((lesson) => { expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('title', lesson.name)); }); }); - it('should add tasks', () => { + it('should add tasks', async () => { + const { archive, tasks } = await setup(CommonCartridgeVersion.V_1_3_0); + tasks.forEach((task) => { - expect(getFileContent(archive, 'imsmanifest.xml')).toContain(` { + it('should add tasks of lesson to manifest file', async () => { + const { archive, lessons } = await setup(CommonCartridgeVersion.V_1_3_0); const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); + lessons[0].tasks.getItems().forEach((task) => { expect(manifest).toContain(`${task.name}`); expect(manifest).toContain(`identifier="i${task.id}" type="webcontent" intendeduse="assignment"`); diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index c0060fc932c..6953bbdca9f 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -51,7 +51,7 @@ export class CommonCartridgeExportService { this.addComponentToOrganization(organizationBuilder, content); }); - lesson.tasks.getItems().forEach((task) => { + lesson.getLessonLinkedTasks().forEach((task) => { organizationBuilder .addSubOrganization(this.commonCartridgeMapper.mapTaskToOrganization(task)) .addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); diff --git a/apps/server/src/shared/domain/entity/lesson.entity.ts b/apps/server/src/shared/domain/entity/lesson.entity.ts index eae1cb6169b..6cc2fa7c566 100644 --- a/apps/server/src/shared/domain/entity/lesson.entity.ts +++ b/apps/server/src/shared/domain/entity/lesson.entity.ts @@ -17,6 +17,7 @@ export interface LessonProperties { position?: number; contents: ComponentProperties[] | []; materials?: Material[]; + tasks?: Task[]; } export enum ComponentType { @@ -118,6 +119,7 @@ export class LessonEntity extends BaseEntityWithTimestamps implements LearnroomE this.position = props.position || 0; this.contents = props.contents; if (props.materials) this.materials.set(props.materials); + if (props.tasks) this.tasks.set(props.tasks); } private getParent(): LessonParent { From ce265e42b526c633fb26f273a9dd16dc6f773d7d Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 4 Jan 2024 09:56:21 +0100 Subject: [PATCH 116/177] EW-539 updating review notes --- .../modules/common-cartridge/review-notes.md | 27 +++---------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/review-notes.md b/apps/server/src/modules/common-cartridge/review-notes.md index efc5233a688..1a519980370 100644 --- a/apps/server/src/modules/common-cartridge/review-notes.md +++ b/apps/server/src/modules/common-cartridge/review-notes.md @@ -1,26 +1,5 @@ # review 04.12.23 -- ~~put all course-independent code into a separate "common-cartridge" module~~ -- ~~import common-cartridge into learnroom~~ -- adjust all tests to avoid global variables. create factories where useful, and use setup function instead of beforeAll - - ~~common-cartridge~~ - - mapper - - export service - -### EW-539 - -- ~~tests for CCManifestResource~~ -- Check test coverage - - ~~common-cartridge~~ - - mapper - - export service -- ~~Cleanup FIXMEs~~ -- Manual tests -- ~~createIdentifier method~~ -- ~~merge main~~ -- review.md and comments -- ~~move in separate module~~ -- ~~check index.ts~~ -- ~~move xml files into test-assets folder~~ -- ~~Adjust export-service~~ - +- [x] put all course-independent code into a separate "common-cartridge" module +- [x] import common-cartridge into learnroom +- [x] adjust all tests to avoid global variables. create factories where useful, and use setup function instead of beforeAll From bdbbfa2f0464132eaba408664b424b83834cc762 Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 8 Jan 2024 12:34:02 +0100 Subject: [PATCH 117/177] EW-539 fixing review comment --- .../common-cartridge-export.service.ts | 6 +-- compose.yml | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 compose.yml diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 6953bbdca9f..f3637963a64 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -80,10 +80,6 @@ export class CommonCartridgeExportService { ): void { const resources = this.commonCartridgeMapper.mapContentToResources(component); - if (!Array.isArray(resources)) { - organizationBuilder.addResource(resources); - } - if (Array.isArray(resources)) { const subOrganizationBuilder = organizationBuilder.addSubOrganization( this.commonCartridgeMapper.mapContentToOrganization(component) @@ -92,6 +88,8 @@ export class CommonCartridgeExportService { resources.forEach((resource) => { subOrganizationBuilder.addResource(resource); }); + } else { + organizationBuilder.addResource(resources); } } } diff --git a/compose.yml b/compose.yml new file mode 100644 index 00000000000..9e28e95fb55 --- /dev/null +++ b/compose.yml @@ -0,0 +1,42 @@ +version: '3' + +services: + mongodb: + image: mongo:4.4 + restart: always + ports: + - 27017:27017 + + rabbitmq: + image: rabbitmq:3.8.9-management + restart: always + ports: + - 5672:5672 + - 15672:15672 + + redis: + image: redis:latest + restart: always + ports: + - 6379:6379 + + idm: + image: ghcr.io/hpi-schul-cloud/erwin-idm/dev:latest + ports: + - 8080:8080 + - 8443:8443 + volumes: + - '$PWD/backup/idm/keycloak:/tmp/realms' + command: '&& /opt/keycloak/bin/kc.sh import --dir /tmp/realms' + + oidc: + image: ghcr.io/soluto/oidc-server-mock:0.6.0 + ports: + - 4011:80 + volumes: + - '$PWD/backup/idm/oidcmock:/tmp/config' + environment: + - ASPNETCORE_ENVIRONMENT='Development' + - SERVER_OPTIONS_PATH='/tmp/config/server-config.json' + - USERS_CONFIGURATION_PATH='/tmp/config/users-config.json' + - CLIENTS_CONFIGURATION_PATH='/tmp/config/clients-config.json' From 99cb8e000f3ecbd2d8c1ded4fd258e60ab4acc62 Mon Sep 17 00:00:00 2001 From: psachmann Date: Mon, 8 Jan 2024 12:41:41 +0100 Subject: [PATCH 118/177] removing compose.yml --- compose.yml | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 compose.yml diff --git a/compose.yml b/compose.yml deleted file mode 100644 index 9e28e95fb55..00000000000 --- a/compose.yml +++ /dev/null @@ -1,42 +0,0 @@ -version: '3' - -services: - mongodb: - image: mongo:4.4 - restart: always - ports: - - 27017:27017 - - rabbitmq: - image: rabbitmq:3.8.9-management - restart: always - ports: - - 5672:5672 - - 15672:15672 - - redis: - image: redis:latest - restart: always - ports: - - 6379:6379 - - idm: - image: ghcr.io/hpi-schul-cloud/erwin-idm/dev:latest - ports: - - 8080:8080 - - 8443:8443 - volumes: - - '$PWD/backup/idm/keycloak:/tmp/realms' - command: '&& /opt/keycloak/bin/kc.sh import --dir /tmp/realms' - - oidc: - image: ghcr.io/soluto/oidc-server-mock:0.6.0 - ports: - - 4011:80 - volumes: - - '$PWD/backup/idm/oidcmock:/tmp/config' - environment: - - ASPNETCORE_ENVIRONMENT='Development' - - SERVER_OPTIONS_PATH='/tmp/config/server-config.json' - - USERS_CONFIGURATION_PATH='/tmp/config/users-config.json' - - CLIENTS_CONFIGURATION_PATH='/tmp/config/clients-config.json' From 50e19f66e7d9eb83fac0d11290b622f9ea56ebe0 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 9 Jan 2024 11:19:22 +0100 Subject: [PATCH 119/177] EW-539 Adjust api test for course controller --- .../controller/api-test/course.api.spec.ts | 103 +++++++++++++----- 1 file changed, 74 insertions(+), 29 deletions(-) diff --git a/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts b/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts index 8ef38761c19..fad60c0178a 100644 --- a/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts +++ b/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts @@ -1,10 +1,12 @@ +import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; import { CourseMetadataListResponse } from '@modules/learnroom/controller/dto'; import { ServerTestModule } from '@modules/server/server.module'; import { INestApplication, StreamableFile } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { Permission } from '@shared/domain/interface'; -import { TestApiClient, UserAndAccountTestFactory, cleanupCollections, courseFactory } from '@shared/testing'; +import { cleanupCollections, courseFactory, TestApiClient, UserAndAccountTestFactory } from '@shared/testing'; const createStudent = () => { const { studentUser, studentAccount } = UserAndAccountTestFactory.buildStudent({}, [Permission.COURSE_VIEW]); @@ -22,11 +24,15 @@ describe('Course Controller (API)', () => { let app: INestApplication; let em: EntityManager; let testApiClient: TestApiClient; + let configServiceMock: DeepMocked; beforeAll(async () => { const module: TestingModule = await Test.createTestingModule({ imports: [ServerTestModule], - }).compile(); + }) + .overrideProvider(ConfigService) + .useValue(createMock()) + .compile(); app = module.createNestApplication(); await app.init(); @@ -51,6 +57,7 @@ describe('Course Controller (API)', () => { return { student, course, teacher }; }; + it('should find courses as student', async () => { const { student, course } = setup(); await em.persistAndFlush([student.account, student.user, course]); @@ -82,36 +89,74 @@ describe('Course Controller (API)', () => { }); describe('[GET] /courses/:id/export', () => { - const setup = () => { - const student1 = createStudent(); - const student2 = createStudent(); - const teacher = createTeacher(); - const substitutionTeacher = createTeacher(); - const teacherUnkownToCourse = createTeacher(); - const course = courseFactory.build({ - name: 'course #1', - teachers: [teacher.user], - students: [student1.user, student2.user], + beforeEach(() => { + configServiceMock = app.get(ConfigService); + }); + + describe('export feature is enabled', () => { + const setup = () => { + const student1 = createStudent(); + const student2 = createStudent(); + const teacher = createTeacher(); + const substitutionTeacher = createTeacher(); + const teacherUnknownToCourse = createTeacher(); + const course = courseFactory.build({ + name: 'course #1', + teachers: [teacher.user], + students: [student1.user, student2.user], + }); + + configServiceMock.get.mockReturnValue(true); + + return { course, teacher, teacherUnknownToCourse, substitutionTeacher, student1 }; + }; + + it('should find course export', async () => { + const { teacher, course } = setup(); + await em.persistAndFlush([teacher.account, teacher.user, course]); + em.clear(); + const version = { version: '1.1.0' }; + + const loggedInClient = await testApiClient.login(teacher.account); + const response = await loggedInClient.get(`${course.id}/export`).query(version); + + expect(response.statusCode).toEqual(200); + const file = response.body as StreamableFile; + expect(file).toBeDefined(); + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + expect(response.header['content-type']).toBe('application/zip'); + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + expect(response.header['content-disposition']).toBe('attachment;'); }); + }); - return { course, teacher, teacherUnkownToCourse, substitutionTeacher, student1 }; - }; - it('should find course export', async () => { - const { teacher, course } = setup(); - await em.persistAndFlush([teacher.account, teacher.user, course]); - em.clear(); - const version = { version: '1.1.0' }; + describe('export feature is disabled', () => { + const setup = () => { + const student = createStudent(); + const teacher = createTeacher(); - const loggedInClient = await testApiClient.login(teacher.account); - const response = await loggedInClient.get(`${course.id}/export`).query(version); - - expect(response.statusCode).toEqual(200); - const file = response.body as StreamableFile; - expect(file).toBeDefined(); - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - expect(response.header['content-type']).toBe('application/zip'); - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - expect(response.header['content-disposition']).toBe('attachment;'); + const course = courseFactory.build({ + name: 'course #2', + teachers: [teacher.user], + students: [student.user], + }); + + configServiceMock.get.mockReturnValue(false); + + return { course, teacher, student }; + }; + + it('should throw NotFoundException when course export feature is not enabled', async () => { + const { teacher, course } = setup(); + await em.persistAndFlush([teacher.account, teacher.user, course]); + em.clear(); + const version = { version: '1.1.0' }; + + const loggedInClient = await testApiClient.login(teacher.account); + const response = await loggedInClient.get(`${course.id}/export`).query(version); + + expect(response.statusCode).toEqual(404); + }); }); }); }); From 72aed7eb03c25d799d0f896c3387cfc6afa54e99 Mon Sep 17 00:00:00 2001 From: psachmann Date: Tue, 9 Jan 2024 12:15:19 +0100 Subject: [PATCH 120/177] EW-539 moving feature check to uc --- .../controller/api-test/course.api.spec.ts | 46 ++----------------- .../modules/learnroom/uc/course-export.uc.ts | 9 +++- 2 files changed, 11 insertions(+), 44 deletions(-) diff --git a/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts b/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts index fad60c0178a..b8fd14d0dee 100644 --- a/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts +++ b/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts @@ -1,12 +1,10 @@ -import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { EntityManager } from '@mikro-orm/mongodb'; import { CourseMetadataListResponse } from '@modules/learnroom/controller/dto'; import { ServerTestModule } from '@modules/server/server.module'; import { INestApplication, StreamableFile } from '@nestjs/common'; -import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { Permission } from '@shared/domain/interface'; -import { cleanupCollections, courseFactory, TestApiClient, UserAndAccountTestFactory } from '@shared/testing'; +import { TestApiClient, UserAndAccountTestFactory, cleanupCollections, courseFactory } from '@shared/testing'; const createStudent = () => { const { studentUser, studentAccount } = UserAndAccountTestFactory.buildStudent({}, [Permission.COURSE_VIEW]); @@ -24,15 +22,11 @@ describe('Course Controller (API)', () => { let app: INestApplication; let em: EntityManager; let testApiClient: TestApiClient; - let configServiceMock: DeepMocked; beforeAll(async () => { const module: TestingModule = await Test.createTestingModule({ imports: [ServerTestModule], - }) - .overrideProvider(ConfigService) - .useValue(createMock()) - .compile(); + }).compile(); app = module.createNestApplication(); await app.init(); @@ -72,6 +66,7 @@ describe('Course Controller (API)', () => { expect(data[0].startDate).toBe(course.startDate); expect(data[0].untilDate).toBe(course.untilDate); }); + it('should find courses as teacher', async () => { const { teacher, course } = setup(); await em.persistAndFlush([teacher.account, teacher.user, course]); @@ -89,10 +84,6 @@ describe('Course Controller (API)', () => { }); describe('[GET] /courses/:id/export', () => { - beforeEach(() => { - configServiceMock = app.get(ConfigService); - }); - describe('export feature is enabled', () => { const setup = () => { const student1 = createStudent(); @@ -106,8 +97,6 @@ describe('Course Controller (API)', () => { students: [student1.user, student2.user], }); - configServiceMock.get.mockReturnValue(true); - return { course, teacher, teacherUnknownToCourse, substitutionTeacher, student1 }; }; @@ -129,34 +118,5 @@ describe('Course Controller (API)', () => { expect(response.header['content-disposition']).toBe('attachment;'); }); }); - - describe('export feature is disabled', () => { - const setup = () => { - const student = createStudent(); - const teacher = createTeacher(); - - const course = courseFactory.build({ - name: 'course #2', - teachers: [teacher.user], - students: [student.user], - }); - - configServiceMock.get.mockReturnValue(false); - - return { course, teacher, student }; - }; - - it('should throw NotFoundException when course export feature is not enabled', async () => { - const { teacher, course } = setup(); - await em.persistAndFlush([teacher.account, teacher.user, course]); - em.clear(); - const version = { version: '1.1.0' }; - - const loggedInClient = await testApiClient.login(teacher.account); - const response = await loggedInClient.get(`${course.id}/export`).query(version); - - expect(response.statusCode).toEqual(404); - }); - }); }); }); diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.ts index 87fdc557a65..dae3122277f 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.ts @@ -1,19 +1,26 @@ import { AuthorizationContextBuilder } from '@modules/authorization'; import { AuthorizableReferenceType, AuthorizationReferenceService } from '@modules/authorization/domain'; -import { Injectable } from '@nestjs/common'; +import { Injectable, NotFoundException } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { Permission } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; import { CommonCartridgeVersion } from '../../common-cartridge'; +import { LearnroomConfig } from '../learnroom.config'; import { CommonCartridgeExportService } from '../service/common-cartridge-export.service'; @Injectable() export class CourseExportUc { constructor( + private readonly configService: ConfigService, private readonly courseExportService: CommonCartridgeExportService, private readonly authorizationService: AuthorizationReferenceService ) {} async exportCourse(courseId: EntityId, userId: EntityId, version: CommonCartridgeVersion): Promise { + if (!this.configService.get('FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED')) { + throw new NotFoundException(); + } + const context = AuthorizationContextBuilder.read([Permission.COURSE_EDIT]); await this.authorizationService.checkPermissionByReferences( userId, From 649d2eecf9e0985305d5288fa1f0cd033e155303 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 9 Jan 2024 13:29:20 +0100 Subject: [PATCH 121/177] EW-539 Undo changes to course controller test --- .../controller/api-test/course.api.spec.ts | 62 +++++++++---------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts b/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts index b8fd14d0dee..61b9a527c2b 100644 --- a/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts +++ b/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts @@ -84,39 +84,37 @@ describe('Course Controller (API)', () => { }); describe('[GET] /courses/:id/export', () => { - describe('export feature is enabled', () => { - const setup = () => { - const student1 = createStudent(); - const student2 = createStudent(); - const teacher = createTeacher(); - const substitutionTeacher = createTeacher(); - const teacherUnknownToCourse = createTeacher(); - const course = courseFactory.build({ - name: 'course #1', - teachers: [teacher.user], - students: [student1.user, student2.user], - }); - - return { course, teacher, teacherUnknownToCourse, substitutionTeacher, student1 }; - }; - - it('should find course export', async () => { - const { teacher, course } = setup(); - await em.persistAndFlush([teacher.account, teacher.user, course]); - em.clear(); - const version = { version: '1.1.0' }; - - const loggedInClient = await testApiClient.login(teacher.account); - const response = await loggedInClient.get(`${course.id}/export`).query(version); - - expect(response.statusCode).toEqual(200); - const file = response.body as StreamableFile; - expect(file).toBeDefined(); - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - expect(response.header['content-type']).toBe('application/zip'); - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - expect(response.header['content-disposition']).toBe('attachment;'); + const setup = () => { + const student1 = createStudent(); + const student2 = createStudent(); + const teacher = createTeacher(); + const substitutionTeacher = createTeacher(); + const teacherUnknownToCourse = createTeacher(); + const course = courseFactory.build({ + name: 'course #1', + teachers: [teacher.user], + students: [student1.user, student2.user], }); + + return { course, teacher, teacherUnknownToCourse, substitutionTeacher, student1 }; + }; + + it('should find course export', async () => { + const { teacher, course } = setup(); + await em.persistAndFlush([teacher.account, teacher.user, course]); + em.clear(); + const version = { version: '1.1.0' }; + + const loggedInClient = await testApiClient.login(teacher.account); + const response = await loggedInClient.get(`${course.id}/export`).query(version); + + expect(response.statusCode).toEqual(200); + const file = response.body as StreamableFile; + expect(file).toBeDefined(); + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + expect(response.header['content-type']).toBe('application/zip'); + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + expect(response.header['content-disposition']).toBe('attachment;'); }); }); }); From 593a14960a3087bcf627f3504a4cd611b09648cd Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 9 Jan 2024 14:21:28 +0100 Subject: [PATCH 122/177] EW-539 Adjust test for course-export-uc for coverage --- .../learnroom/uc/course-export.uc.spec.ts | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts index 812fffa12cd..2498b3d2945 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts @@ -1,10 +1,12 @@ import { DeepMocked, createMock } from '@golevelup/ts-jest'; import { AuthorizationReferenceService } from '@modules/authorization/domain'; import { CommonCartridgeExportService } from '@modules/learnroom/service/common-cartridge-export.service'; -import { ForbiddenException } from '@nestjs/common'; +import { ForbiddenException, NotFoundException } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { ObjectId } from 'bson'; import { CommonCartridgeVersion } from '../../common-cartridge'; +import { LearnroomConfig } from '../learnroom.config'; import { CourseExportUc } from './course-export.uc'; describe('CourseExportUc', () => { @@ -12,6 +14,7 @@ describe('CourseExportUc', () => { let courseExportUc: CourseExportUc; let courseExportServiceMock: DeepMocked; let authorizationServiceMock: DeepMocked; + let configServiceMock: DeepMocked>; beforeAll(async () => { module = await Test.createTestingModule({ @@ -25,11 +28,16 @@ describe('CourseExportUc', () => { provide: AuthorizationReferenceService, useValue: createMock(), }, + { + provide: ConfigService, + useValue: createMock>(), + }, ], }).compile(); courseExportUc = module.get(CourseExportUc); courseExportServiceMock = module.get(CommonCartridgeExportService); authorizationServiceMock = module.get(AuthorizationReferenceService); + configServiceMock = module.get(ConfigService); }); afterAll(async () => { @@ -54,6 +62,7 @@ describe('CourseExportUc', () => { const setup = () => { authorizationServiceMock.checkPermissionByReferences.mockRejectedValueOnce(new ForbiddenException()); courseExportServiceMock.exportCourse.mockResolvedValueOnce(Buffer.from('')); + configServiceMock.get.mockReturnValueOnce(true); return setupParams(); }; @@ -71,6 +80,7 @@ describe('CourseExportUc', () => { const setup = () => { authorizationServiceMock.checkPermissionByReferences.mockResolvedValueOnce(); courseExportServiceMock.exportCourse.mockRejectedValueOnce(new Error()); + configServiceMock.get.mockReturnValueOnce(true); return setupParams(); }; @@ -86,6 +96,7 @@ describe('CourseExportUc', () => { const setup = () => { authorizationServiceMock.checkPermissionByReferences.mockResolvedValueOnce(); courseExportServiceMock.exportCourse.mockResolvedValueOnce(Buffer.from('')); + configServiceMock.get.mockReturnValueOnce(true); return setupParams(); }; @@ -103,5 +114,23 @@ describe('CourseExportUc', () => { await expect(courseExportUc.exportCourse(courseId, userId, version)).resolves.toBeInstanceOf(Buffer); }); }); + + describe('when feature is disabled', () => { + const setup = () => { + authorizationServiceMock.checkPermissionByReferences.mockResolvedValueOnce(); + courseExportServiceMock.exportCourse.mockResolvedValueOnce(Buffer.from('')); + configServiceMock.get.mockReturnValueOnce(false); + + return setupParams(); + }; + + it('should throw a NotFoundException', async () => { + const { courseId, userId, version } = setup(); + + await expect(courseExportUc.exportCourse(courseId, userId, version)).rejects.toThrowError( + new NotFoundException() + ); + }); + }); }); }); From cfb911bd143322ad1449c123bf9ca47bc0927ee6 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 9 Jan 2024 14:29:47 +0100 Subject: [PATCH 123/177] EW-539 Fix deep import warnings --- apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts index 2498b3d2945..70530bed5ae 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts @@ -1,12 +1,12 @@ import { DeepMocked, createMock } from '@golevelup/ts-jest'; -import { AuthorizationReferenceService } from '@modules/authorization/domain'; -import { CommonCartridgeExportService } from '@modules/learnroom/service/common-cartridge-export.service'; import { ForbiddenException, NotFoundException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { ObjectId } from 'bson'; +import { AuthorizationReferenceService } from '../../authorization/domain'; import { CommonCartridgeVersion } from '../../common-cartridge'; import { LearnroomConfig } from '../learnroom.config'; +import { CommonCartridgeExportService } from '../service/common-cartridge-export.service'; import { CourseExportUc } from './course-export.uc'; describe('CourseExportUc', () => { From 40398cd7db39e6008c89d0138018453e66780b11 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 9 Jan 2024 14:53:36 +0100 Subject: [PATCH 124/177] EW-539 Remove deprecated code from course controller --- .../src/modules/learnroom/controller/course.controller.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/apps/server/src/modules/learnroom/controller/course.controller.ts b/apps/server/src/modules/learnroom/controller/course.controller.ts index 57e575d2d13..52bb624e22d 100644 --- a/apps/server/src/modules/learnroom/controller/course.controller.ts +++ b/apps/server/src/modules/learnroom/controller/course.controller.ts @@ -1,5 +1,5 @@ import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication'; -import { Controller, Get, NotFoundException, Param, Query, Res, StreamableFile } from '@nestjs/common'; +import { Controller, Get, Param, Query, Res, StreamableFile } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { ApiTags } from '@nestjs/swagger'; import { PaginationParams } from '@shared/controller/'; @@ -39,9 +39,6 @@ export class CourseController { @Query() queryParams: CourseQueryParams, @Res({ passthrough: true }) response: Response ): Promise { - if (!this.configService.get('FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED')) - throw new NotFoundException(); - const result = await this.courseExportUc.exportCourse( urlParams.courseId, currentUser.userId, From 5f9b511ccb2a1b44d962d41d0dcdd48d1faaf93f Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 9 Jan 2024 15:02:04 +0100 Subject: [PATCH 125/177] EW-539 Change http to https for sonarcloud --- .../resources/v1.1.0/common-cartridge-manifest-resource.ts | 4 ++-- .../resources/v1.1.0/common-cartridge-web-link-resource.ts | 4 ++-- .../resources/v1.3.0/common-cartridge-manifest-resource.ts | 4 ++-- .../resources/v1.3.0/common-cartridge-web-link-resource.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts index 78e08aab1ea..3b565a7074f 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -43,12 +43,12 @@ export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource manifest: { $: { identifier: this.props.identifier, - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', + xmlns: 'https://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + + 'https://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 https://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ' + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd', }, diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts index a40dc7142a2..d226e60c576 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -30,10 +30,10 @@ export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource return buildXmlString({ webLink: { $: { - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1', + xmlns: 'https://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', + 'https://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', }, title: this.props.title, url: { diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts index 23fc0cd2f23..db44e8128ba 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -44,12 +44,12 @@ export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource manifest: { $: { identifier: this.props.identifier, - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1', + xmlns: 'https://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1', 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest', 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd ' + + 'https://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1 https://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd ' + 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd ' + 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lomresource_v1p0.xsd', }, diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts index 6c226e047b3..c04f97b1075 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -30,10 +30,10 @@ export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource return buildXmlString({ webLink: { $: { - xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3', + xmlns: 'https://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': - 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3 http://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd', + 'https://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3 https://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd', }, title: this.props.title, url: { From 39d6cbbfde4b63fd882a7ef4a9cca89a7350587d Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 10 Jan 2024 12:42:59 +0100 Subject: [PATCH 126/177] EW-539 Deactivate to insert final new line for xml files --- .editorconfig | 3 +++ .vscode/settings.default.json | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.editorconfig b/.editorconfig index 7d2f033b21e..5e29fcadb61 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,6 @@ indent_size = 4 indent_style = tab insert_final_newline = true trim_trailing_whitespace = true + +[*.xml] +insert_final_newline = false diff --git a/.vscode/settings.default.json b/.vscode/settings.default.json index 7525444a021..5b30e60c2a3 100644 --- a/.vscode/settings.default.json +++ b/.vscode/settings.default.json @@ -13,6 +13,9 @@ "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" }, + "[xml]": { + "files.insertFinalNewline": false + }, "javascript.preferences.importModuleSpecifier": "relative", "jest.autoRun": { "watch": false, "onSave": "test-file" }, "coverage-gutters.showLineCoverage": true, From c0973ef4e4178a3c6ba9350b907b8fc0efb8ef69 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 10 Jan 2024 12:48:45 +0100 Subject: [PATCH 127/177] EW-539 Adjust namespaces and links for better security --- .../v1.1.0/common-cartridge-manifest-resource.ts | 8 ++++---- .../v1.1.0/common-cartridge-web-link-resource.ts | 4 ++-- .../v1.3.0/common-cartridge-manifest-resource.ts | 8 ++++---- .../v1.3.0/common-cartridge-web-link-resource.ts | 4 ++-- .../test/assets/common-cartridge/v1.1.0/manifest.xml | 2 +- .../test/assets/common-cartridge/v1.1.0/weblink.xml | 2 +- .../test/assets/common-cartridge/v1.3.0/manifest.xml | 2 +- .../test/assets/common-cartridge/v1.3.0/weblink.xml | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts index 3b565a7074f..881343b3c2e 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -43,14 +43,14 @@ export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource manifest: { $: { identifier: this.props.identifier, - xmlns: 'https://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1', 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest', 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': - 'https://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 https://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd', + 'http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 https://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd ' + + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest https://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ' + + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource https://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd', }, metadata: this.props.metadata.getManifestXmlObject(), organizations: CommonCartridgeElementFactory.createElement({ diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts index d226e60c576..d71bc033691 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -30,10 +30,10 @@ export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource return buildXmlString({ webLink: { $: { - xmlns: 'https://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1', + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': - 'https://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', + 'http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 https://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd', }, title: this.props.title, url: { diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts index db44e8128ba..9fd018d0c56 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -44,14 +44,14 @@ export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource manifest: { $: { identifier: this.props.identifier, - xmlns: 'https://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1', + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1', 'xmlns:mnf': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest', 'xmlns:res': 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': - 'https://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1 https://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd ' + - 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lomresource_v1p0.xsd', + 'http://www.imsglobal.org/xsd/imsccv1p3/imscp_v1p1 https://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imscp_v1p2_v1p0.xsd ' + + 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest https://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd ' + + 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource https://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lomresource_v1p0.xsd', }, metadata: this.props.metadata.getManifestXmlObject(), organizations: new CommonCartridgeOrganizationsWrapperElementV130({ diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts index c04f97b1075..96f83aa4bb8 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -30,10 +30,10 @@ export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource return buildXmlString({ webLink: { $: { - xmlns: 'https://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3', + xmlns: 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation': - 'https://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3 https://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd', + 'http://www.imsglobal.org/xsd/imsccv1p3/imswl_v1p3 https://www.imsglobal.org/profile/cc/ccv1p3/ccv1p3_imswl_v1p3.xsd', }, title: this.props.title, url: { diff --git a/apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml b/apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml index 37d1d31dd4b..661d182508f 100644 --- a/apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml +++ b/apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml @@ -1,5 +1,5 @@ - + IMS Common Cartridge 1.1.0 diff --git a/apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml b/apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml index eb2880bcd4f..e202cc742ec 100644 --- a/apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml +++ b/apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml @@ -1,5 +1,5 @@ - + Title \ No newline at end of file diff --git a/apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml b/apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml index b79159a1bc7..3b955fa1855 100644 --- a/apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml +++ b/apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml @@ -1,5 +1,5 @@ - + IMS Common Cartridge 1.3.0 diff --git a/apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml b/apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml index ca395c61f58..47f4a784c22 100644 --- a/apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml +++ b/apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml @@ -1,5 +1,5 @@ - + Title \ No newline at end of file From 8b408aeccb424d913de2998b03c83a8b56b197e6 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 10 Jan 2024 14:01:02 +0100 Subject: [PATCH 128/177] EW-539 Fix a code smell --- .../src/modules/learnroom/mapper/common-cartridge.mapper.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 05a7c8c2a86..a71d8bd4474 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -50,6 +50,8 @@ export class CommonCartridgeMapper { public mapTaskToResource(task: Task, version: CommonCartridgeVersion): CommonCartridgeResourceProps { const intendedUse = (() => { switch (version) { + case CommonCartridgeVersion.V_1_1_0: + return CommonCartridgeIntendedUseType.UNSPECIFIED; case CommonCartridgeVersion.V_1_3_0: return CommonCartridgeIntendedUseType.ASSIGNMENT; default: From 57a0a712dc586f73afb136dec5d50c58602bdbda Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 11 Jan 2024 13:21:19 +0100 Subject: [PATCH 129/177] EW-539 Editorconfig commented out and fix some prettier issues --- .editorconfig | 20 +++++++++---------- ...common-cartridge-manifest-resource.spec.ts | 5 +---- ...common-cartridge-web-link-resource.spec.ts | 5 +---- ...common-cartridge-manifest-resource.spec.ts | 5 +---- ...common-cartridge-web-link-resource.spec.ts | 5 +---- 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/.editorconfig b/.editorconfig index 5e29fcadb61..3698f2f2262 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,12 +1,12 @@ -root = true +# root = true -[*.ts] -charset = utf-8 -end_of_line = lf -indent_size = 4 -indent_style = tab -insert_final_newline = true -trim_trailing_whitespace = true +# [*.ts] +# charset = utf-8 +# end_of_line = lf +# indent_size = 4 +# indent_style = tab +# insert_final_newline = true +# trim_trailing_whitespace = true -[*.xml] -insert_final_newline = false +# [*.xml] +# insert_final_newline = false diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index 6cafe7c4f97..66ee12b64a3 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -91,10 +91,7 @@ describe('CommonCartridgeManifestResourceV110', () => { describe('when using Common Cartridge version 1.1.0', () => { it('should return constructed file content', async () => { const { sut } = setup(); - const expected = await readFile( - './apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml', - 'utf-8' - ); + const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml', 'utf-8'); const result = sut.getFileContent(); expect(result).toEqual(expected); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts index c87818b6856..54486366432 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -50,10 +50,7 @@ describe('CommonCartridgeWebLinkResourceV110', () => { describe('when using Common Cartridge version 1.1.0', () => { it('should contain correct XML', async () => { const { sut } = setup(); - const expected = await readFile( - './apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml', - 'utf8' - ); + const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml', 'utf8'); const result = sut.getFileContent(); expect(result).toEqual(expected); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index 13b321c971b..a91f6325590 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -92,10 +92,7 @@ describe('CommonCartridgeManifestResourceV110', () => { describe('when using Common Cartridge version 1.3.0', () => { it('should return constructed file content', async () => { const { sut } = setup(); - const expected = await readFile( - './apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml', - 'utf-8' - ); + const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml', 'utf-8'); const result = sut.getFileContent(); expect(result).toEqual(expected); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts index 13e908feabe..baab77bec25 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts @@ -49,10 +49,7 @@ describe('CommonCartridgeWebLinkResourceV130', () => { describe('when using Common Cartridge version 1.3.0', () => { it('should contain correct XML', async () => { const { sut } = setup(); - const expected = await readFile( - './apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml', - 'utf8' - ); + const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml', 'utf8'); const result = sut.getFileContent(); expect(result).toEqual(expected); From 1b7c08f1c50b5d420a3060df31703f828ce9aed1 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 11 Jan 2024 13:35:51 +0100 Subject: [PATCH 130/177] EW-539 Fix prettier errors --- .../elements/v1.1.0/common-cartridge-metadata-element.ts | 4 +--- .../elements/v1.3.0/common-cartridge-metadata-element.ts | 4 +--- .../src/modules/learnroom/controller/course.controller.ts | 6 +----- .../learnroom/mapper/common-cartridge.mapper.spec.ts | 4 +--- .../modules/learnroom/mapper/common-cartridge.mapper.ts | 6 +++--- .../service/common-cartridge-export.service.spec.ts | 8 ++------ .../learnroom/service/common-cartridge-export.service.ts | 4 +--- apps/server/src/modules/server/server.config.ts | 8 ++------ 8 files changed, 12 insertions(+), 32 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts index e9a97652f9d..1a43110d3db 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts @@ -33,9 +33,7 @@ export class CommonCartridgeMetadataElementV110 extends CommonCartridgeElement { 'mnf:value': 'yes', }, 'mnf:description': { - 'mnf:string': `${this.props.creationDate.getFullYear()} ${this.props.copyrightOwners.join( - ', ' - )}`, + 'mnf:string': `${this.props.creationDate.getFullYear()} ${this.props.copyrightOwners.join(', ')}`, }, }, }, diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts index e403fa8417f..80fb65bb993 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts @@ -33,9 +33,7 @@ export class CommonCartridgeMetadataElementV130 extends CommonCartridgeElement { 'mnf:value': 'yes', }, 'mnf:description': { - 'mnf:string': `${this.props.creationDate.getFullYear()} ${this.props.copyrightOwners.join( - ', ' - )}`, + 'mnf:string': `${this.props.creationDate.getFullYear()} ${this.props.copyrightOwners.join(', ')}`, }, }, }, diff --git a/apps/server/src/modules/learnroom/controller/course.controller.ts b/apps/server/src/modules/learnroom/controller/course.controller.ts index 52bb624e22d..4a5def6bb26 100644 --- a/apps/server/src/modules/learnroom/controller/course.controller.ts +++ b/apps/server/src/modules/learnroom/controller/course.controller.ts @@ -39,11 +39,7 @@ export class CourseController { @Query() queryParams: CourseQueryParams, @Res({ passthrough: true }) response: Response ): Promise { - const result = await this.courseExportUc.exportCourse( - urlParams.courseId, - currentUser.userId, - queryParams.version - ); + const result = await this.courseExportUc.exportCourse(urlParams.courseId, currentUser.userId, queryParams.version); response.set({ 'Content-Type': 'application/zip', diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index b2da3338a90..b75fd1352b5 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -67,9 +67,7 @@ describe('CommonCartridgeMapper', () => { expect(metadataProps).toStrictEqual({ type: CommonCartridgeElementType.METADATA, title: course.name, - copyrightOwners: course.teachers - .toArray() - .map((teacher) => `${teacher.firstName} ${teacher.lastName}`), + copyrightOwners: course.teachers.toArray().map((teacher) => `${teacher.firstName} ${teacher.lastName}`), creationDate: course.createdAt, }); }); diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index a71d8bd4474..952f36dcdd5 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -85,9 +85,9 @@ export class CommonCartridgeMapper { type: CommonCartridgeResourceType.WEB_LINK, identifier: createIdentifier(content._id), title: content.title, - url: `${this.configService.getOrThrow( - 'FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED' - )}/m/${content.content.materialId}`, + url: `${this.configService.getOrThrow('FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED')}/m/${ + content.content.materialId + }`, }; case ComponentType.ETHERPAD: return { diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index 17ea5a50273..8d31f4c01a8 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -120,9 +120,7 @@ describe('CommonCartridgeExportService', () => { it('should add course', async () => { const { archive, course } = await setup(CommonCartridgeVersion.V_1_1_0); - expect(getFileContent(archive, 'imsmanifest.xml')).toContain( - createXmlString('mnf:string', course.name) - ); + expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('mnf:string', course.name)); }); it('should add lessons', async () => { @@ -162,9 +160,7 @@ describe('CommonCartridgeExportService', () => { it('should add course', async () => { const { archive, course } = await setup(CommonCartridgeVersion.V_1_3_0); - expect(getFileContent(archive, 'imsmanifest.xml')).toContain( - createXmlString('mnf:string', course.name) - ); + expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('mnf:string', course.name)); }); it('should add lessons', async () => { diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index f3637963a64..751140a6220 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -43,9 +43,7 @@ export class CommonCartridgeExportService { const [lessons] = await this.lessonService.findByCourseIds([courseId]); lessons.forEach((lesson) => { - const organizationBuilder = builder.addOrganization( - this.commonCartridgeMapper.mapLessonToOrganization(lesson) - ); + const organizationBuilder = builder.addOrganization(this.commonCartridgeMapper.mapLessonToOrganization(lesson)); lesson.contents.forEach((content) => { this.addComponentToOrganization(organizationBuilder, content); diff --git a/apps/server/src/modules/server/server.config.ts b/apps/server/src/modules/server/server.config.ts index 8f5afeaf7dd..9c8c82109a0 100644 --- a/apps/server/src/modules/server/server.config.ts +++ b/apps/server/src/modules/server/server.config.ts @@ -46,12 +46,8 @@ const config: ServerConfig = { ) as boolean, GEOGEBRA_BASE_URL: Configuration.get('GEOGEBRA_BASE_URL') as string, FEATURE_IDENTITY_MANAGEMENT_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_ENABLED') as boolean, - FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED: Configuration.get( - 'FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED' - ) as boolean, - FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED: Configuration.get( - 'FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED' - ) as boolean, + FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED') as boolean, + FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED') as boolean, STUDENT_TEAM_CREATION: Configuration.get('STUDENT_TEAM_CREATION') as string, ADMIN_API__ALLOWED_API_KEYS: (Configuration.get('ADMIN_API__ALLOWED_API_KEYS') as string) .split(',') From fd1f232e23204dabb049b530c076a8031605325d Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 11 Jan 2024 14:22:35 +0100 Subject: [PATCH 131/177] EW-539 Delete editorconfig --- .editorconfig | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 3698f2f2262..00000000000 --- a/.editorconfig +++ /dev/null @@ -1,12 +0,0 @@ -# root = true - -# [*.ts] -# charset = utf-8 -# end_of_line = lf -# indent_size = 4 -# indent_style = tab -# insert_final_newline = true -# trim_trailing_whitespace = true - -# [*.xml] -# insert_final_newline = false From 2c96b34eadfc79fe3316213aef24dbc51936ca0c Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 15 Jan 2024 14:07:45 +0100 Subject: [PATCH 132/177] EW-539 Working on review comments --- .../service/keycloak-administration.service.ts | 2 +- .../builders/common-cartridge-file-builder.ts | 2 +- .../builders/common-cartridge-organization-builder.ts | 2 +- .../elements/v1.1.0/common-cartridge-metadata-element.ts | 2 +- .../elements/v1.1.0/common-cartridge-organization-element.ts | 2 +- .../v1.1.0/common-cartridge-organizations-wrapper-element.ts | 2 +- .../v1.1.0/common-cartridge-resources-wrapper-element.ts | 2 +- .../elements/v1.3.0/common-cartridge-metadata-element.ts | 2 +- .../elements/v1.3.0/common-cartridge-organization-element.ts | 2 +- .../v1.3.0/common-cartridge-organizations-wrapper-element.ts | 2 +- .../v1.3.0/common-cartridge-resources-wrapper-element.ts | 2 +- .../resources/v1.1.0/common-cartridge-manifest-resource.ts | 2 +- .../v1.1.0/common-cartridge-web-content-resource.ts | 2 +- .../resources/v1.1.0/common-cartridge-web-link-resource.ts | 2 +- .../resources/v1.3.0/common-cartridge-manifest-resource.ts | 2 +- .../v1.3.0/common-cartridge-web-content-resource.ts | 2 +- .../resources/v1.3.0/common-cartridge-web-link-resource.ts | 2 +- apps/server/src/modules/common-cartridge/review-notes.md | 5 ----- .../modules/learnroom/controller/dto/course.query.params.ts | 2 +- .../src/modules/learnroom/mapper/common-cartridge.mapper.ts | 2 +- .../learnroom/service/common-cartridge-export.service.ts | 2 +- .../server/src/modules/learnroom/uc/course-export.uc.spec.ts | 2 +- apps/server/src/modules/learnroom/uc/course-export.uc.ts | 2 +- 23 files changed, 22 insertions(+), 27 deletions(-) delete mode 100644 apps/server/src/modules/common-cartridge/review-notes.md diff --git a/apps/server/src/infra/identity-management/keycloak-administration/service/keycloak-administration.service.ts b/apps/server/src/infra/identity-management/keycloak-administration/service/keycloak-administration.service.ts index a953d0b558a..a6e1669f869 100644 --- a/apps/server/src/infra/identity-management/keycloak-administration/service/keycloak-administration.service.ts +++ b/apps/server/src/infra/identity-management/keycloak-administration/service/keycloak-administration.service.ts @@ -8,7 +8,7 @@ export class KeycloakAdministrationService { private static AUTHORIZATION_TIMEBOX_MS = 59 * 1000; - public constructor( + constructor( private readonly kcAdminClient: KeycloakAdminClient, @Inject(KeycloakSettings) private readonly kcSettings: IKeycloakSettings ) { diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts index 57c1f313328..8da8d237679 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts @@ -27,7 +27,7 @@ export class CommonCartridgeFileBuilder { private metadata?: CommonCartridgeElement; - public constructor(private readonly props: CommonCartridgeFileBuilderProps) {} + constructor(private readonly props: CommonCartridgeFileBuilderProps) {} public addMetadata(props: CommonCartridgeElementProps): CommonCartridgeFileBuilder { this.metadata = CommonCartridgeElementFactory.createElement({ diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts index b1d6d6aef8a..f11c6cdeba9 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts @@ -23,7 +23,7 @@ export class CommonCartridgeOrganizationBuilder { private readonly subOrganizations: CommonCartridgeOrganizationBuilder[] = []; - public constructor( + constructor( protected readonly options: CommonCartridgeOrganizationBuilderOptionsInternal, private readonly addResourceToFileBuilder: (resource: CommonCartridgeResource) => void ) {} diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts index 1a43110d3db..7845f911e22 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts @@ -10,7 +10,7 @@ export type CommonCartridgeMetadataElementPropsV110 = { }; export class CommonCartridgeMetadataElementV110 extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeMetadataElementPropsV110) { + constructor(private readonly props: CommonCartridgeMetadataElementPropsV110) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts index d80c36cd4e3..29a7361951e 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts @@ -11,7 +11,7 @@ export type CommonCartridgeOrganizationElementPropsV110 = { }; export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeElement { - public constructor(protected readonly props: CommonCartridgeOrganizationElementPropsV110) { + constructor(protected readonly props: CommonCartridgeOrganizationElementPropsV110) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts index 6b896899176..2ad14258db8 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts @@ -8,7 +8,7 @@ export type CommonCartridgeOrganizationsWrapperElementPropsV110 = { }; export class CommonCartridgeOrganizationsWrapperElementV110 extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementPropsV110) { + constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementPropsV110) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts index 75ae6086f66..4d3eb388f34 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts @@ -8,7 +8,7 @@ export type CommonCartridgeResourcesWrapperElementPropsV110 = { }; export class CommonCartridgeResourcesWrapperElementV110 extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeResourcesWrapperElementPropsV110) { + constructor(private readonly props: CommonCartridgeResourcesWrapperElementPropsV110) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts index 80fb65bb993..0ce844926e2 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts @@ -10,7 +10,7 @@ export type CommonCartridgeMetadataElementPropsV130 = { }; export class CommonCartridgeMetadataElementV130 extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeMetadataElementPropsV130) { + constructor(private readonly props: CommonCartridgeMetadataElementPropsV130) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts index c34c4fa6cbb..5afa753a092 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts @@ -11,7 +11,7 @@ export type CommonCartridgeOrganizationElementPropsV130 = { }; export class CommonCartridgeOrganizationElementV130 extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeOrganizationElementPropsV130) { + constructor(private readonly props: CommonCartridgeOrganizationElementPropsV130) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts index 9d753cff40d..8c9a437ce1c 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts @@ -8,7 +8,7 @@ export type CommonCartridgeOrganizationsWrapperElementPropsV130 = { }; export class CommonCartridgeOrganizationsWrapperElementV130 extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementPropsV130) { + constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementPropsV130) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts index de31ddf5e11..683036e988e 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts @@ -8,7 +8,7 @@ export type CommonCartridgeResourcesWrapperElementPropsV130 = { }; export class CommonCartridgeResourcesWrapperElementV130 extends CommonCartridgeElement { - public constructor(private readonly props: CommonCartridgeResourcesWrapperElementPropsV130) { + constructor(private readonly props: CommonCartridgeResourcesWrapperElementPropsV130) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts index 881343b3c2e..f2e8e2f6a3d 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -18,7 +18,7 @@ export type CommonCartridgeManifestResourcePropsV110 = { }; export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource { - public constructor(private readonly props: CommonCartridgeManifestResourcePropsV110) { + constructor(private readonly props: CommonCartridgeManifestResourcePropsV110) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts index 4c75228dfce..aa90d25ad79 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -23,7 +23,7 @@ export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResour CommonCartridgeIntendedUseType.UNSPECIFIED, ]; - public constructor(private readonly props: CommonCartridgeWebContentResourcePropsV110) { + constructor(private readonly props: CommonCartridgeWebContentResourcePropsV110) { super(props); checkIntendedUse(props.intendedUse, CommonCartridgeWebContentResourceV110.SUPPORTED_INTENDED_USES); } diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts index d71bc033691..edeb2aac52e 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -14,7 +14,7 @@ export type CommonCartridgeWebLinkResourcePropsV110 = { }; export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource { - public constructor(private readonly props: CommonCartridgeWebLinkResourcePropsV110) { + constructor(private readonly props: CommonCartridgeWebLinkResourcePropsV110) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts index 9fd018d0c56..cce95652695 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -19,7 +19,7 @@ export type CommonCartridgeManifestResourcePropsV130 = { }; export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource { - public constructor(private readonly props: CommonCartridgeManifestResourcePropsV130) { + constructor(private readonly props: CommonCartridgeManifestResourcePropsV130) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts index 73b33567677..678b747fa2f 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -24,7 +24,7 @@ export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResour CommonCartridgeIntendedUseType.UNSPECIFIED, ]; - public constructor(private readonly props: CommonCartridgeWebContentResourcePropsV130) { + constructor(private readonly props: CommonCartridgeWebContentResourcePropsV130) { super(props); checkIntendedUse(props.intendedUse, CommonCartridgeWebContentResourceV130.SUPPORTED_INTENDED_USES); } diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts index 96f83aa4bb8..451132577b2 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -14,7 +14,7 @@ export type CommonCartridgeWebLinkResourcePropsV130 = { }; export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource { - public constructor(private readonly props: CommonCartridgeWebLinkResourcePropsV130) { + constructor(private readonly props: CommonCartridgeWebLinkResourcePropsV130) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/review-notes.md b/apps/server/src/modules/common-cartridge/review-notes.md deleted file mode 100644 index 1a519980370..00000000000 --- a/apps/server/src/modules/common-cartridge/review-notes.md +++ /dev/null @@ -1,5 +0,0 @@ -# review 04.12.23 - -- [x] put all course-independent code into a separate "common-cartridge" module -- [x] import common-cartridge into learnroom -- [x] adjust all tests to avoid global variables. create factories where useful, and use setup function instead of beforeAll diff --git a/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts b/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts index 309a30b4b5c..3f285dbe354 100644 --- a/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts +++ b/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts @@ -1,6 +1,6 @@ +import { CommonCartridgeVersion } from '@modules/common-cartridge'; import { ApiProperty } from '@nestjs/swagger'; import { IsString, Matches } from 'class-validator'; -import { CommonCartridgeVersion } from '../../../common-cartridge'; export class CourseQueryParams { @IsString() diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 952f36dcdd5..f0fe6e584bd 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -15,7 +15,7 @@ import { LearnroomConfig } from '../learnroom.config'; @Injectable() export class CommonCartridgeMapper { - public constructor(private readonly configService: ConfigService) {} + constructor(private readonly configService: ConfigService) {} public mapCourseToMetadata(course: Course): CommonCartridgeElementProps { return { diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 751140a6220..ad98d7b4840 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -13,7 +13,7 @@ import { CourseService } from './course.service'; @Injectable() export class CommonCartridgeExportService { - public constructor( + constructor( private readonly courseService: CourseService, private readonly lessonService: LessonService, private readonly taskService: TaskService, diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts index 70530bed5ae..101298cd96f 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts @@ -1,10 +1,10 @@ import { DeepMocked, createMock } from '@golevelup/ts-jest'; +import { CommonCartridgeVersion } from '@modules/common-cartridge'; import { ForbiddenException, NotFoundException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { ObjectId } from 'bson'; import { AuthorizationReferenceService } from '../../authorization/domain'; -import { CommonCartridgeVersion } from '../../common-cartridge'; import { LearnroomConfig } from '../learnroom.config'; import { CommonCartridgeExportService } from '../service/common-cartridge-export.service'; import { CourseExportUc } from './course-export.uc'; diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.ts index dae3122277f..7e88c4c7ce7 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.ts @@ -1,10 +1,10 @@ import { AuthorizationContextBuilder } from '@modules/authorization'; import { AuthorizableReferenceType, AuthorizationReferenceService } from '@modules/authorization/domain'; +import { CommonCartridgeVersion } from '@modules/common-cartridge'; import { Injectable, NotFoundException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { Permission } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; -import { CommonCartridgeVersion } from '../../common-cartridge'; import { LearnroomConfig } from '../learnroom.config'; import { CommonCartridgeExportService } from '../service/common-cartridge-export.service'; From 3542ab6db3ac28ccac45a0f32fa89ce31ccd50a4 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 17 Jan 2024 12:30:45 +0100 Subject: [PATCH 133/177] EW-539 Working on review comments --- .../builders/common-cartridge-organization-builder.spec.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts index f6b2e4ad888..fe7f554fe5f 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts @@ -50,12 +50,6 @@ describe('CommonCartridgeOrganizationBuilder', () => { expect(element).toBeInstanceOf(CommonCartridgeElement); }); - - it('should add 3 resources', () => { - const { resources } = setup(); - - expect(resources).toHaveLength(3); - }); }); }); }); From e6b0912c77da8999bc6875d7478ad90e64bb4eed Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 26 Jan 2024 10:37:11 +0100 Subject: [PATCH 134/177] EW-539 Add mapper for course to manifest and fix geogebra url and organization element identifiers --- .../v1.1.0/common-cartridge-organization-element.ts | 3 ++- .../v1.3.0/common-cartridge-organization-element.ts | 3 ++- .../learnroom/mapper/common-cartridge.mapper.ts | 12 +++++++++--- .../service/common-cartridge-export.service.ts | 5 +---- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts index 29a7361951e..96c00eec488 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts @@ -1,6 +1,7 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { createIdentifier } from '../../utils'; export type CommonCartridgeOrganizationElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATION; @@ -39,7 +40,7 @@ export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeEleme if (item instanceof CommonCartridgeResource) { return { $: { - identifier: item.identifier, + identifier: createIdentifier(), identifierref: item.identifier, }, title: item.title, diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts index 5afa753a092..d4dbeea6dc0 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts @@ -1,6 +1,7 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { createIdentifier } from '../../utils'; export type CommonCartridgeOrganizationElementPropsV130 = { type: CommonCartridgeElementType.ORGANIZATION; @@ -39,7 +40,7 @@ export class CommonCartridgeOrganizationElementV130 extends CommonCartridgeEleme if (item instanceof CommonCartridgeResource) { return { $: { - identifier: item.identifier, + identifier: createIdentifier(), identifierref: item.identifier, }, title: item.title, diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index f0fe6e584bd..9f8932ce122 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -5,6 +5,7 @@ import { createIdentifier } from '@src/modules/common-cartridge/utils'; import { CommonCartridgeElementProps, CommonCartridgeElementType, + CommonCartridgeFileBuilderProps, CommonCartridgeIntendedUseType, CommonCartridgeOrganizationBuilderOptions, CommonCartridgeResourceProps, @@ -85,9 +86,7 @@ export class CommonCartridgeMapper { type: CommonCartridgeResourceType.WEB_LINK, identifier: createIdentifier(content._id), title: content.title, - url: `${this.configService.getOrThrow('FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED')}/m/${ - content.content.materialId - }`, + url: `${this.configService.getOrThrow('GEOGEBRA_BASE_URL')}/m/${content.content.materialId}`, }; case ComponentType.ETHERPAD: return { @@ -111,4 +110,11 @@ export class CommonCartridgeMapper { return []; } } + + public mapCourseToManifest(version: CommonCartridgeVersion, course: Course): CommonCartridgeFileBuilderProps { + return { + version, + identifier: createIdentifier(course.id), + }; + } } diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index ad98d7b4840..12b35c501d7 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -22,10 +22,7 @@ export class CommonCartridgeExportService { public async exportCourse(courseId: EntityId, userId: EntityId, version: CommonCartridgeVersion): Promise { const course = await this.courseService.findById(courseId); - const builder = new CommonCartridgeFileBuilder({ - identifier: courseId, - version, - }); + const builder = new CommonCartridgeFileBuilder(this.commonCartridgeMapper.mapCourseToManifest(version, course)); builder.addMetadata(this.commonCartridgeMapper.mapCourseToMetadata(course)); From 65e63cfbbc3d4cebe2ee247a3569e4b01575807d Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 26 Jan 2024 11:57:47 +0100 Subject: [PATCH 135/177] EW-539 Fix identifier for tasks in organization --- .../src/modules/learnroom/mapper/common-cartridge.mapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 9f8932ce122..27dfb41d8bb 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -43,7 +43,7 @@ export class CommonCartridgeMapper { public mapTaskToOrganization(task: Task): CommonCartridgeOrganizationBuilderOptions { return { - identifier: createIdentifier(task.id), + identifier: createIdentifier(), title: task.name, }; } From 83ae5da6841a9c58b4990e72ede9efd4f9e90f29 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 29 Jan 2024 09:12:30 +0100 Subject: [PATCH 136/177] EW-539 Fix import order in learnroom module --- apps/server/src/modules/learnroom/learnroom.module.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/learnroom/learnroom.module.ts b/apps/server/src/modules/learnroom/learnroom.module.ts index 033a14e21b9..7947a30f11a 100644 --- a/apps/server/src/modules/learnroom/learnroom.module.ts +++ b/apps/server/src/modules/learnroom/learnroom.module.ts @@ -2,6 +2,7 @@ import { BoardModule } from '@modules/board'; import { CopyHelperModule } from '@modules/copy-helper'; import { LessonModule } from '@modules/lesson'; import { TaskModule } from '@modules/task'; +import { ContextExternalToolModule } from '@modules/tool/context-external-tool'; import { Module } from '@nestjs/common'; import { BoardRepo, @@ -13,8 +14,8 @@ import { UserRepo, } from '@shared/repo'; import { LoggerModule } from '@src/core/logger'; +import { ToolConfigModule } from '../tool/tool-config.module'; import { CommonCartridgeMapper } from './mapper/common-cartridge.mapper'; -import { ContextExternalToolModule } from '@modules/tool/context-external-tool'; import { BoardCopyService, ColumnBoardTargetService, @@ -25,7 +26,6 @@ import { DashboardService, RoomsService, } from './service'; -import { ToolConfigModule } from '../tool/tool-config.module'; @Module({ imports: [ From 0267f7505d31b00e55e4826c64929b2fdd81065c Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 29 Jan 2024 10:40:21 +0100 Subject: [PATCH 137/177] EW-539 Adjust test for cc mapper --- .../mapper/common-cartridge.mapper.spec.ts | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index b75fd1352b5..9eaa55e9da1 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -1,6 +1,5 @@ import { faker } from '@faker-js/faker'; import { DeepMocked, createMock } from '@golevelup/ts-jest'; -import { MikroORM } from '@mikro-orm/core'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { ComponentProperties, ComponentType } from '@shared/domain/entity'; @@ -9,6 +8,7 @@ import { OmitVersion, createIdentifier } from '@src/modules/common-cartridge/uti import { CommonCartridgeElementProps, CommonCartridgeElementType, + CommonCartridgeFileBuilderProps, CommonCartridgeIntendedUseType, CommonCartridgeOrganizationBuilderOptions, CommonCartridgeResourceProps, @@ -21,10 +21,10 @@ import { CommonCartridgeMapper } from './common-cartridge.mapper'; describe('CommonCartridgeMapper', () => { let module: TestingModule; let sut: CommonCartridgeMapper; - let orm: MikroORM; let configServiceMock: DeepMocked>; beforeAll(async () => { + await setupEntities(); module = await Test.createTestingModule({ providers: [ CommonCartridgeMapper, @@ -34,14 +34,12 @@ describe('CommonCartridgeMapper', () => { }, ], }).compile(); - orm = await setupEntities(); sut = module.get(CommonCartridgeMapper); configServiceMock = module.get(ConfigService); }); afterAll(async () => { await module.close(); - await orm.close(); }); beforeEach(() => { @@ -189,7 +187,7 @@ describe('CommonCartridgeMapper', () => { const organizationProps = sut.mapTaskToOrganization(task); expect(organizationProps).toStrictEqual>({ - identifier: createIdentifier(task.id), + identifier: expect.any(String), title: task.name, }); }); @@ -375,4 +373,27 @@ describe('CommonCartridgeMapper', () => { }); }); }); + + describe('mapCourseToManifest', () => { + describe('when mapping course', () => { + const setup = () => { + const course = courseFactory.buildWithId(); + const version = CommonCartridgeVersion.V_1_1_0; + + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); + + return { course, version }; + }; + + it('should map to manifest', () => { + const { course, version } = setup(); + const fileBuilderProps = sut.mapCourseToManifest(version, course); + + expect(fileBuilderProps).toStrictEqual({ + version: CommonCartridgeVersion.V_1_1_0, + identifier: createIdentifier(course.id), + }); + }); + }); + }); }); From cb1a259a65e14e8543137e0e11c14eaee04a73e3 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 29 Jan 2024 13:14:04 +0100 Subject: [PATCH 138/177] EW-539 Adjust tests --- .../v1.1.0/common-cartridge-organization-element.spec.ts | 2 +- .../v1.3.0/common-cartridge-organization-element.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts index dd1979971d4..e6db4899afc 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts @@ -117,7 +117,7 @@ describe('CommonCartridgeOrganizationElementV110', () => { item: [ { $: { - identifier: resourceProps.identifier, + identifier: expect.any(String), identifierref: resourceProps.identifier, }, title: resourceProps.title, diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts index c9b83826d9f..e9d018db6fd 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts @@ -116,7 +116,7 @@ describe('CommonCartridgeOrganizationElementV130', () => { item: [ { $: { - identifier: resourceProps.identifier, + identifier: expect.any(String), identifierref: resourceProps.identifier, }, title: resourceProps.title, From 9591d18a8dd8ac80160dcfa7a350c4051ac470a0 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 29 Jan 2024 14:10:45 +0100 Subject: [PATCH 139/177] EW-539 Fix etherpad title --- .../src/modules/learnroom/mapper/common-cartridge.mapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 27dfb41d8bb..5414b82216d 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -92,7 +92,7 @@ export class CommonCartridgeMapper { return { type: CommonCartridgeResourceType.WEB_LINK, identifier: createIdentifier(content._id), - title: `${content.content.title} - ${content.content.description}`, + title: `${content.title} - ${content.content.description}`, url: content.content.url, }; case ComponentType.LERNSTORE: From ed1506c6dc7c6d64e4e6b70ec9af0dedc65a8ff6 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 31 Jan 2024 10:45:27 +0100 Subject: [PATCH 140/177] EW-539 Trial to fix lernstore content --- .../src/modules/learnroom/mapper/common-cartridge.mapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 5414b82216d..5d268323c37 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -101,7 +101,7 @@ export class CommonCartridgeMapper { return { type: CommonCartridgeResourceType.WEB_LINK, identifier: createIdentifier(), - title: resource.description, + title: resource.title, url: resource.url, }; }) || [] From d9641309a8cd1bc934018eda3b008f7ecd9196bc Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 31 Jan 2024 14:45:31 +0100 Subject: [PATCH 141/177] EW-539 Adjust test for cc mapper --- .../modules/learnroom/mapper/common-cartridge.mapper.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index 9eaa55e9da1..b39c08d2f78 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -319,7 +319,7 @@ describe('CommonCartridgeMapper', () => { { type: CommonCartridgeResourceType.WEB_LINK, identifier: expect.any(String), - title: componentProps.content?.resources[0].description as string, + title: componentProps.content?.resources[0].title as string, url: componentProps.content?.resources[0].url as string, }, ]); From 4d71e4b7a4ac58e4a2214d5ec815986c5006ff58 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 31 Jan 2024 15:09:47 +0100 Subject: [PATCH 142/177] EW-539 Working on review comments and remove the override keyword --- .../v1.1.0/common-cartridge-metadata-element.ts | 4 ++-- .../v1.1.0/common-cartridge-organization-element.ts | 4 ++-- .../common-cartridge-organizations-wrapper-element.ts | 4 ++-- .../common-cartridge-resources-wrapper-element.ts | 4 ++-- .../v1.3.0/common-cartridge-metadata-element.ts | 4 ++-- .../v1.3.0/common-cartridge-organization-element.ts | 4 ++-- .../common-cartridge-organizations-wrapper-element.ts | 4 ++-- .../common-cartridge-resources-wrapper-element.ts | 4 ++-- .../v1.1.0/common-cartridge-manifest-resource.ts | 10 +++++----- .../v1.1.0/common-cartridge-web-content-resource.ts | 10 +++++----- .../v1.3.0/common-cartridge-manifest-resource.ts | 10 +++++----- .../v1.3.0/common-cartridge-web-content-resource.ts | 10 +++++----- .../v1.3.0/common-cartridge-web-link-resource.ts | 10 +++++----- 13 files changed, 41 insertions(+), 41 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts index 7845f911e22..af4765d5e06 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts @@ -14,11 +14,11 @@ export class CommonCartridgeMetadataElementV110 extends CommonCartridgeElement { super(props); } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { schema: 'IMS Common Cartridge', schemaversion: '1.1.0', diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts index 96c00eec488..8745eab8a8f 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts @@ -16,11 +16,11 @@ export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeEleme super(props); } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { if (this.props.items instanceof CommonCartridgeResource) { return { $: { diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts index 2ad14258db8..657eec85201 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts @@ -12,11 +12,11 @@ export class CommonCartridgeOrganizationsWrapperElementV110 extends CommonCartri super(props); } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { organization: [ { diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts index 4d3eb388f34..f541ec54f37 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts @@ -12,11 +12,11 @@ export class CommonCartridgeResourcesWrapperElementV110 extends CommonCartridgeE super(props); } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { resources: [ { diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts index 0ce844926e2..1a21d8f989b 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts @@ -14,11 +14,11 @@ export class CommonCartridgeMetadataElementV130 extends CommonCartridgeElement { super(props); } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { schema: 'IMS Common Cartridge', schemaversion: '1.3.0', diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts index d4dbeea6dc0..f2d9f83d925 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts @@ -16,11 +16,11 @@ export class CommonCartridgeOrganizationElementV130 extends CommonCartridgeEleme super(props); } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { if (this.props.items instanceof CommonCartridgeResource) { return { $: { diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts index 8c9a437ce1c..676fc3bf830 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts @@ -12,11 +12,11 @@ export class CommonCartridgeOrganizationsWrapperElementV130 extends CommonCartri super(props); } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { organization: [ { diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts index 683036e988e..4ec19d81836 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts @@ -12,11 +12,11 @@ export class CommonCartridgeResourcesWrapperElementV130 extends CommonCartridgeE super(props); } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { resources: [ { diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts index f2e8e2f6a3d..b9e13a08d9e 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -22,23 +22,23 @@ export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource super(props); } - public override canInline(): boolean { + public canInline(): boolean { return false; } - public override getFilePath(): string { + public getFilePath(): string { return 'imsmanifest.xml'; } - public override getFileContent(): string { + public getFileContent(): string { return buildXmlString(this.getManifestXmlObject()); } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { manifest: { $: { diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts index aa90d25ad79..ff56797986f 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -28,23 +28,23 @@ export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResour checkIntendedUse(props.intendedUse, CommonCartridgeWebContentResourceV110.SUPPORTED_INTENDED_USES); } - public override canInline(): boolean { + public canInline(): boolean { return false; } - public override getFilePath(): string { + public getFilePath(): string { return `${this.props.folder}/${this.props.identifier}.html`; } - public override getFileContent(): string { + public getFileContent(): string { return this.props.html; } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { $: { identifier: this.props.identifier, diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts index cce95652695..20b5b485e93 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -23,23 +23,23 @@ export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource super(props); } - public override canInline(): boolean { + public canInline(): boolean { return false; } - public override getFilePath(): string { + public getFilePath(): string { return 'imsmanifest.xml'; } - public override getFileContent(): string { + public getFileContent(): string { return buildXmlString(this.getManifestXmlObject()); } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { manifest: { $: { diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts index 678b747fa2f..482afcb8da1 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -29,23 +29,23 @@ export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResour checkIntendedUse(props.intendedUse, CommonCartridgeWebContentResourceV130.SUPPORTED_INTENDED_USES); } - public override canInline(): boolean { + public canInline(): boolean { return false; } - public override getFilePath(): string { + public getFilePath(): string { return `${this.props.folder}/${this.props.identifier}.html`; } - public override getFileContent(): string { + public getFileContent(): string { return this.props.html; } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { $: { identifier: this.props.identifier, diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts index 451132577b2..78667f5531e 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -18,15 +18,15 @@ export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource super(props); } - public override canInline(): boolean { + public canInline(): boolean { return false; } - public override getFilePath(): string { + public getFilePath(): string { return `${this.props.folder}/${this.props.identifier}.xml`; } - public override getFileContent(): string { + public getFileContent(): string { return buildXmlString({ webLink: { $: { @@ -47,11 +47,11 @@ export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource }); } - public override getSupportedVersion(): CommonCartridgeVersion { + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - public override getManifestXmlObject(): Record { + public getManifestXmlObject(): Record { return { $: { identifier: this.props.identifier, From 6c95ecf8f07221e62d207d53c43b4c71f713fa0a Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 2 Feb 2024 10:07:36 +0100 Subject: [PATCH 143/177] EW-539 Working on review comments regarding wildcards in imports --- apps/server/src/modules/common-cartridge/index.ts | 14 +++++++++++--- apps/server/src/modules/learnroom/index.ts | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/index.ts b/apps/server/src/modules/common-cartridge/index.ts index 7640471be33..5fbe1ca839f 100644 --- a/apps/server/src/modules/common-cartridge/index.ts +++ b/apps/server/src/modules/common-cartridge/index.ts @@ -1,5 +1,13 @@ -export * from './builders/common-cartridge-file-builder'; -export * from './builders/common-cartridge-organization-builder'; -export * from './common-cartridge.enums'; +export { CommonCartridgeFileBuilder, CommonCartridgeFileBuilderProps } from './builders/common-cartridge-file-builder'; +export { + CommonCartridgeOrganizationBuilder, + CommonCartridgeOrganizationBuilderOptions, +} from './builders/common-cartridge-organization-builder'; +export { + CommonCartridgeElementType, + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from './common-cartridge.enums'; export { CommonCartridgeElementProps } from './elements/common-cartridge-element-factory'; export { CommonCartridgeResourceProps } from './resources/common-cartridge-resource-factory'; diff --git a/apps/server/src/modules/learnroom/index.ts b/apps/server/src/modules/learnroom/index.ts index a6c0f51a3ac..0db918062ac 100644 --- a/apps/server/src/modules/learnroom/index.ts +++ b/apps/server/src/modules/learnroom/index.ts @@ -1,10 +1,10 @@ -export * from './learnroom.config'; +export { LearnroomConfig } from './learnroom.config'; export * from './learnroom.module'; export { CommonCartridgeExportService, CourseCopyService, - CourseService, - RoomsService, CourseGroupService, + CourseService, DashboardService, + RoomsService, } from './service'; From 67ce976b1070effe0b5f13139ae5754f5d9f826d Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 7 Feb 2024 11:49:37 +0100 Subject: [PATCH 144/177] EW-539 Add test factories for element and resource props --- .../common-cartridge-element-props.factory.ts | 94 +++++++++++++++++++ ...common-cartridge-resource-props.factory.ts | 26 +++++ 2 files changed, 120 insertions(+) create mode 100644 apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts create mode 100644 apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts diff --git a/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts b/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts new file mode 100644 index 00000000000..a2c4d04975d --- /dev/null +++ b/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts @@ -0,0 +1,94 @@ +import { faker } from '@faker-js/faker'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '@src/modules/common-cartridge'; +import { CommonCartridgeMetadataElementPropsV110 } from '@src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElementPropsV110 } from '@src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element'; +import { CommonCartridgeOrganizationsWrapperElementPropsV110 } from '@src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementPropsV110 } from '@src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element'; +import { CommonCartridgeMetadataElementPropsV130 } from '@src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElementPropsV130 } from '@src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element'; +import { CommonCartridgeOrganizationsWrapperElementPropsV130 } from '@src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementPropsV130 } from '@src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element'; +import { CommonCartridgeElement } from '@src/modules/common-cartridge/interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '@src/modules/common-cartridge/interfaces/common-cartridge-resource.interface'; + +export function createCommonCartridgeMetadataElementPropsV110(): CommonCartridgeMetadataElementPropsV110 { + return { + type: CommonCartridgeElementType.METADATA, + version: CommonCartridgeVersion.V_1_1_0, + title: faker.lorem.words(), + creationDate: faker.date.past(), + copyrightOwners: [faker.person.fullName(), faker.person.fullName()], + }; +} + +export function createCommonCartridgeMetadataElementPropsV130(): CommonCartridgeMetadataElementPropsV130 { + return { + type: CommonCartridgeElementType.METADATA, + version: CommonCartridgeVersion.V_1_3_0, + title: faker.lorem.words(), + creationDate: faker.date.past(), + copyrightOwners: [faker.person.fullName(), faker.person.fullName()], + }; +} + +export function createCommonCartridgeOrganizationElementPropsV110( + items?: CommonCartridgeResource | Array +): CommonCartridgeOrganizationElementPropsV110 { + return { + type: CommonCartridgeElementType.ORGANIZATION, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + items: items || [], + version: CommonCartridgeVersion.V_1_1_0, + }; +} + +export function createCommonCartridgeOrganizationElementPropsV130(): CommonCartridgeOrganizationElementPropsV130 { + return { + type: CommonCartridgeElementType.ORGANIZATION, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + items: [], + version: CommonCartridgeVersion.V_1_3_0, + }; +} + +export function createCommonCartridgeOrganizationsWrapperElementPropsV110( + items?: CommonCartridgeElement[] +): CommonCartridgeOrganizationsWrapperElementPropsV110 { + return { + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, + version: CommonCartridgeVersion.V_1_1_0, + items: items || [], + }; +} + +export function createCommonCartridgeOrganizationsWrapperElementPropsV130( + items?: CommonCartridgeElement[] +): CommonCartridgeOrganizationsWrapperElementPropsV130 { + return { + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, + version: CommonCartridgeVersion.V_1_3_0, + items: items || [], + }; +} + +export function createCommonCartridgeResourcesWrapperElementPropsV110( + items?: CommonCartridgeResource[] +): CommonCartridgeResourcesWrapperElementPropsV110 { + return { + type: CommonCartridgeElementType.RESOURCES_WRAPPER, + version: CommonCartridgeVersion.V_1_1_0, + items: items || [], + }; +} + +export function createCommonCartridgeResourcesWrapperElementPropsV130( + items?: CommonCartridgeResource[] +): CommonCartridgeResourcesWrapperElementPropsV130 { + return { + type: CommonCartridgeElementType.RESOURCES_WRAPPER, + version: CommonCartridgeVersion.V_1_3_0, + items: items || [], + }; +} diff --git a/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts b/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts new file mode 100644 index 00000000000..1d1c7263c99 --- /dev/null +++ b/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts @@ -0,0 +1,26 @@ +import { faker } from '@faker-js/faker'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '@src/modules/common-cartridge'; +import { CommonCartridgeWebLinkResourcePropsV110 } from '@src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource'; +import { CommonCartridgeWebLinkResourcePropsV130 } from '@src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource'; + +export function createCommonCartridgeWeblinkResourcePropsV110(): CommonCartridgeWebLinkResourcePropsV110 { + return { + type: CommonCartridgeResourceType.WEB_LINK, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + url: faker.internet.url(), + version: CommonCartridgeVersion.V_1_1_0, + folder: faker.string.alphanumeric(10), + }; +} + +export function createCommonCartridgeWeblinkResourcePropsV130(): CommonCartridgeWebLinkResourcePropsV130 { + return { + type: CommonCartridgeResourceType.WEB_LINK, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + url: faker.internet.url(), + version: CommonCartridgeVersion.V_1_3_0, + folder: faker.string.alphanumeric(10), + }; +} From 37f181efc3acc33680076fcc71f4de1fa30213ac Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 7 Feb 2024 14:04:59 +0100 Subject: [PATCH 145/177] EW-539 Working on tests for cc elements --- .../common-cartridge-element-factory.spec.ts | 51 ++++---- .../common-cartridge-metadata-element.spec.ts | 47 ++++---- ...mon-cartridge-organization-element.spec.ts | 113 +++++++----------- ...idge-organizations-wrapper-element.spec.ts | 64 +++++----- ...artridge-resources-wrapper-element.spec.ts | 72 +++++------ .../common-cartridge-element-factory.spec.ts | 51 ++++---- .../common-cartridge-metadata-element.spec.ts | 47 ++++---- ...mon-cartridge-organization-element.spec.ts | 112 +++++++---------- ...idge-organizations-wrapper-element.spec.ts | 64 +++++----- ...artridge-resources-wrapper-element.spec.ts | 78 +++++------- .../common-cartridge-element-props.factory.ts | 6 +- 11 files changed, 305 insertions(+), 400 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts index 39830695c5e..10d91dff9b2 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts @@ -21,50 +21,61 @@ import { describe('CommonCartridgeElementFactoryV110', () => { describe('createElement', () => { describe('when creating elements from props', () => { - it('should return metadata element', () => { - const result = CommonCartridgeElementFactoryV110.createElement({ - type: CommonCartridgeElementType.METADATA, + const setup = (type: CommonCartridgeElementType) => { + return { + type, version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeMetadataElementPropsV110); + }; + }; + + it('should return metadata element', () => { + const props = setup(CommonCartridgeElementType.METADATA); + const result = CommonCartridgeElementFactoryV110.createElement( + props as CommonCartridgeMetadataElementPropsV110 + ); expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV110); }); it('should return organization element', () => { - const result = CommonCartridgeElementFactoryV110.createElement({ - type: CommonCartridgeElementType.ORGANIZATION, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeOrganizationElementPropsV110); + const props = setup(CommonCartridgeElementType.ORGANIZATION); + const result = CommonCartridgeElementFactoryV110.createElement( + props as CommonCartridgeOrganizationElementPropsV110 + ); expect(result).toBeInstanceOf(CommonCartridgeOrganizationElementV110); }); it('should return organization wrapper element', () => { - const result = CommonCartridgeElementFactoryV110.createElement({ - type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeOrganizationsWrapperElementPropsV110); + const props = setup(CommonCartridgeElementType.ORGANIZATIONS_WRAPPER); + const result = CommonCartridgeElementFactoryV110.createElement( + props as CommonCartridgeOrganizationsWrapperElementPropsV110 + ); expect(result).toBeInstanceOf(CommonCartridgeOrganizationsWrapperElementV110); }); it('should return resources wrapper element', () => { - const result = CommonCartridgeElementFactoryV110.createElement({ - type: CommonCartridgeElementType.RESOURCES_WRAPPER, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeResourcesWrapperElementPropsV110); + const props = setup(CommonCartridgeElementType.RESOURCES_WRAPPER); + const result = CommonCartridgeElementFactoryV110.createElement( + props as CommonCartridgeResourcesWrapperElementPropsV110 + ); expect(result).toBeInstanceOf(CommonCartridgeResourcesWrapperElementV110); }); }); describe('when element type is not supported', () => { + const setup = () => { + return { + type: 'not-supported' as CommonCartridgeElementType, + version: CommonCartridgeVersion.V_1_1_0, + }; + }; + it('should throw error', () => { expect(() => - CommonCartridgeElementFactoryV110.createElement({ - type: 'not-supported' as CommonCartridgeElementType, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeMetadataElementPropsV110) + CommonCartridgeElementFactoryV110.createElement(setup() as CommonCartridgeMetadataElementPropsV110) ).toThrow(InternalServerErrorException); }); }); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts index 09212d1165a..844243d1c1f 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts @@ -1,27 +1,18 @@ -import { faker } from '@faker-js/faker'; import { InternalServerErrorException } from '@nestjs/common'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { - CommonCartridgeMetadataElementPropsV110, - CommonCartridgeMetadataElementV110, -} from './common-cartridge-metadata-element'; +import { createCommonCartridgeMetadataElementPropsV110 } from '@shared/testing/factory/common-cartridge-element-props.factory'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeMetadataElementV110 } from './common-cartridge-metadata-element'; describe('CommonCartridgeMetadataElementV110', () => { - const setup = () => { - const props: CommonCartridgeMetadataElementPropsV110 = { - type: CommonCartridgeElementType.METADATA, - version: CommonCartridgeVersion.V_1_1_0, - title: faker.lorem.words(), - creationDate: faker.date.past(), - copyrightOwners: [faker.person.fullName(), faker.person.fullName()], - }; - const sut = new CommonCartridgeMetadataElementV110(props); - - return { sut, props }; - }; - describe('getSupportedVersion', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeMetadataElementPropsV110(); + const sut = new CommonCartridgeMetadataElementV110(props); + + return { sut, props }; + }; + // AI next 5 lines it('should return correct version', () => { const { sut } = setup(); @@ -32,20 +23,24 @@ describe('CommonCartridgeMetadataElementV110', () => { }); describe('when using not supported Common Cartridge version', () => { + const notSupportedProps = createCommonCartridgeMetadataElementPropsV110(); + notSupportedProps.version = CommonCartridgeVersion.V_1_3_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeMetadataElementV110({ - type: CommonCartridgeElementType.METADATA, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeMetadataElementPropsV110) - ).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeMetadataElementV110(notSupportedProps)).toThrow(InternalServerErrorException); }); }); }); describe('getManifestXmlObject', () => { describe('when using Common Cartridge version 1.1', () => { + const setup = () => { + const props = createCommonCartridgeMetadataElementPropsV110(); + const sut = new CommonCartridgeMetadataElementV110(props); + + return { sut, props }; + }; + it('should return correct manifest xml object', () => { const { sut, props } = setup(); const result = sut.getManifestXmlObject(); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts index e6db4899afc..bcf8c8bc788 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts @@ -1,73 +1,21 @@ -import { faker } from '@faker-js/faker'; import { InternalServerErrorException } from '@nestjs/common'; -import { - CommonCartridgeElementType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../../common-cartridge.enums'; -import { - CommonCartridgeResourceFactory, - CommonCartridgeResourceProps, -} from '../../resources/common-cartridge-resource-factory'; -import { CommonCartridgeElementFactory, CommonCartridgeElementProps } from '../common-cartridge-element-factory'; -import { - CommonCartridgeOrganizationElementPropsV110, - CommonCartridgeOrganizationElementV110, -} from './common-cartridge-organization-element'; +import { createCommonCartridgeOrganizationElementPropsV110 } from '@shared/testing/factory/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV110 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; +import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; +import { CommonCartridgeOrganizationElementV110 } from './common-cartridge-organization-element'; describe('CommonCartridgeOrganizationElementV110', () => { - const setup = () => { - const resourceProps: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_LINK, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - url: faker.internet.url(), - }; - const subOrganization1Props: CommonCartridgeElementProps = { - type: CommonCartridgeElementType.ORGANIZATION, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - items: CommonCartridgeResourceFactory.createResource({ - ...resourceProps, - version: CommonCartridgeVersion.V_1_1_0, - folder: faker.string.alphanumeric(10), - }), - }; - const subOrganization2Props: CommonCartridgeElementProps = { - type: CommonCartridgeElementType.ORGANIZATION, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - items: [ - CommonCartridgeResourceFactory.createResource({ - ...resourceProps, - version: CommonCartridgeVersion.V_1_1_0, - folder: faker.string.alphanumeric(10), - }), - ], - }; - const organizationProps: CommonCartridgeOrganizationElementPropsV110 = { - type: CommonCartridgeElementType.ORGANIZATION, - version: CommonCartridgeVersion.V_1_1_0, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - items: [ - CommonCartridgeElementFactory.createElement({ - ...subOrganization1Props, - version: CommonCartridgeVersion.V_1_1_0, - }), - CommonCartridgeElementFactory.createElement({ - ...subOrganization2Props, - version: CommonCartridgeVersion.V_1_1_0, - }), - ], - }; - const sut = new CommonCartridgeOrganizationElementV110(organizationProps); - - return { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps }; - }; - describe('getSupportedVersion', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeOrganizationElementPropsV110(); + const sut = new CommonCartridgeOrganizationElementV110(props); + + return { sut }; + }; + it('should return correct version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -77,21 +25,40 @@ describe('CommonCartridgeOrganizationElementV110', () => { }); describe('when using not supported Common Cartridge version', () => { + const notSupportedProps = createCommonCartridgeOrganizationElementPropsV110(); + notSupportedProps.version = CommonCartridgeVersion.V_1_3_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeOrganizationElementV110({ - type: CommonCartridgeElementType.ORGANIZATION, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeOrganizationElementPropsV110) - ).toThrowError(InternalServerErrorException); + expect(() => new CommonCartridgeOrganizationElementV110(notSupportedProps)).toThrowError( + InternalServerErrorException + ); }); }); }); describe('getManifestXmlObject', () => { - // AI next 12 lines describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const resourceProps = createCommonCartridgeWeblinkResourcePropsV110(); + + const subOrganization1Props = createCommonCartridgeOrganizationElementPropsV110( + CommonCartridgeResourceFactory.createResource(resourceProps) + ); + + const subOrganization2Props = createCommonCartridgeOrganizationElementPropsV110([ + CommonCartridgeResourceFactory.createResource(resourceProps), + ]); + + const organizationProps = createCommonCartridgeOrganizationElementPropsV110([ + CommonCartridgeElementFactory.createElement(subOrganization1Props), + CommonCartridgeElementFactory.createElement(subOrganization2Props), + ]); + + const sut = new CommonCartridgeOrganizationElementV110(organizationProps); + + return { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps }; + }; + it('should return correct manifest xml object', () => { const { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps } = setup(); const result = sut.getManifestXmlObject(); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts index 08d655bb318..88513e4c003 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -1,37 +1,22 @@ -import { faker } from '@faker-js/faker'; import { InternalServerErrorException } from '@nestjs/common'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElementFactory, CommonCartridgeElementProps } from '../common-cartridge-element-factory'; import { - CommonCartridgeOrganizationsWrapperElementPropsV110, - CommonCartridgeOrganizationsWrapperElementV110, -} from './common-cartridge-organizations-wrapper-element'; + createCommonCartridgeOrganizationElementPropsV110, + createCommonCartridgeOrganizationsWrapperElementPropsV110, +} from '@shared/testing/factory/common-cartridge-element-props.factory'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; +import { CommonCartridgeOrganizationsWrapperElementV110 } from './common-cartridge-organizations-wrapper-element'; describe('CommonCartridgeOrganizationsWrapperElementV110', () => { - const setup = () => { - const organizationProps: CommonCartridgeElementProps = { - type: CommonCartridgeElementType.ORGANIZATION, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - items: [], - }; - const props: CommonCartridgeOrganizationsWrapperElementPropsV110 = { - type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, - version: CommonCartridgeVersion.V_1_1_0, - items: [ - CommonCartridgeElementFactory.createElement({ - ...organizationProps, - version: CommonCartridgeVersion.V_1_1_0, - }), - ], - }; - const sut = new CommonCartridgeOrganizationsWrapperElementV110(props); - - return { sut, props, organizationProps }; - }; - describe('getSupportedVersion', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeOrganizationsWrapperElementPropsV110(); + const sut = new CommonCartridgeOrganizationsWrapperElementV110(props); + + return { sut, props }; + }; + it('should return correct version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -41,20 +26,29 @@ describe('CommonCartridgeOrganizationsWrapperElementV110', () => { }); describe('when using not supported Common Cartridge version', () => { + const notSupportedProps = createCommonCartridgeOrganizationsWrapperElementPropsV110(); + notSupportedProps.version = CommonCartridgeVersion.V_1_3_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeOrganizationsWrapperElementV110({ - type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeOrganizationsWrapperElementPropsV110) - ).toThrowError(InternalServerErrorException); + expect(() => new CommonCartridgeOrganizationsWrapperElementV110(notSupportedProps)).toThrowError( + InternalServerErrorException + ); }); }); }); describe('getManifestXmlObject', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const organizationProps = createCommonCartridgeOrganizationElementPropsV110(); + const props = createCommonCartridgeOrganizationsWrapperElementPropsV110([ + CommonCartridgeElementFactory.createElement(organizationProps), + ]); + const sut = new CommonCartridgeOrganizationsWrapperElementV110(props); + + return { sut, organizationProps }; + }; + it('should return correct manifest xml object', () => { const { sut, organizationProps } = setup(); const result = sut.getManifestXmlObject(); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts index 676c3c83a54..5f255d9bfa1 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts @@ -1,45 +1,20 @@ -import { faker } from '@faker-js/faker'; import { InternalServerErrorException } from '@nestjs/common'; -import { - CommonCartridgeElementType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../../common-cartridge.enums'; -import { - CommonCartridgeResourceFactory, - CommonCartridgeResourceProps, -} from '../../resources/common-cartridge-resource-factory'; -import { - CommonCartridgeResourcesWrapperElementPropsV110, - CommonCartridgeResourcesWrapperElementV110, -} from './common-cartridge-resources-wrapper-element'; +import { createCommonCartridgeResourcesWrapperElementPropsV110 } from '@shared/testing/factory/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV110 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; +import { CommonCartridgeResourcesWrapperElementV110 } from './common-cartridge-resources-wrapper-element'; describe('CommonCartridgeResourcesWrapperElementV110', () => { - const setup = () => { - const resourceProps: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_LINK, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - url: faker.internet.url(), - }; - const props: CommonCartridgeResourcesWrapperElementPropsV110 = { - type: CommonCartridgeElementType.RESOURCES_WRAPPER, - version: CommonCartridgeVersion.V_1_1_0, - items: [ - CommonCartridgeResourceFactory.createResource({ - ...resourceProps, - version: CommonCartridgeVersion.V_1_1_0, - folder: faker.string.alphanumeric(10), - }), - ], - }; - const sut = new CommonCartridgeResourcesWrapperElementV110(props); - - return { sut, props, resourceProps }; - }; - describe('getSupportedVersion', () => { describe('when using common cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeResourcesWrapperElementPropsV110(); + const sut = new CommonCartridgeResourcesWrapperElementV110(props); + + return { sut }; + }; + it('should return correct version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -49,20 +24,29 @@ describe('CommonCartridgeResourcesWrapperElementV110', () => { }); describe('when using not supported common cartridge version', () => { + const notSupportedProps = createCommonCartridgeResourcesWrapperElementPropsV110(); + notSupportedProps.version = CommonCartridgeVersion.V_1_3_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeResourcesWrapperElementV110({ - type: CommonCartridgeElementType.RESOURCES_WRAPPER, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeResourcesWrapperElementPropsV110) - ).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeResourcesWrapperElementV110(notSupportedProps)).toThrow( + InternalServerErrorException + ); }); }); }); describe('getManifestXmlObject', () => { describe('when using common cartridge version 1.1.0', () => { + const setup = () => { + const resourceProps = createCommonCartridgeWeblinkResourcePropsV110(); + const props = createCommonCartridgeResourcesWrapperElementPropsV110([ + CommonCartridgeResourceFactory.createResource(resourceProps), + ]); + const sut = new CommonCartridgeResourcesWrapperElementV110(props); + + return { sut, resourceProps }; + }; + it('should return correct manifest xml object', () => { const { sut, resourceProps } = setup(); const result = sut.getManifestXmlObject(); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts index f44b88f1e15..c4c5515c0e9 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts @@ -19,50 +19,61 @@ import { describe('CommonCartridgeElementFactoryV130', () => { describe('createElement', () => { describe('when creating elements from props', () => { - it('should return metadata element', () => { - const result = CommonCartridgeElementFactoryV130.createElement({ - type: CommonCartridgeElementType.METADATA, + const setup = (type: CommonCartridgeElementType) => { + return { + type, version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeMetadataElementPropsV130); + }; + }; + + it('should return metadata element', () => { + const props = setup(CommonCartridgeElementType.METADATA); + const result = CommonCartridgeElementFactoryV130.createElement( + props as CommonCartridgeMetadataElementPropsV130 + ); expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV130); }); it('should return organization element', () => { - const result = CommonCartridgeElementFactoryV130.createElement({ - type: CommonCartridgeElementType.ORGANIZATION, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeOrganizationElementPropsV130); + const props = setup(CommonCartridgeElementType.ORGANIZATION); + const result = CommonCartridgeElementFactoryV130.createElement( + props as CommonCartridgeOrganizationElementPropsV130 + ); expect(result).toBeInstanceOf(CommonCartridgeOrganizationElementV130); }); it('should return organization wrapper element', () => { - const result = CommonCartridgeElementFactoryV130.createElement({ - type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeOrganizationsWrapperElementPropsV110); + const props = setup(CommonCartridgeElementType.ORGANIZATIONS_WRAPPER); + const result = CommonCartridgeElementFactoryV130.createElement( + props as CommonCartridgeOrganizationsWrapperElementPropsV110 + ); expect(result).toBeInstanceOf(CommonCartridgeOrganizationsWrapperElementV130); }); it('should return resources wrapper element', () => { - const result = CommonCartridgeElementFactoryV130.createElement({ - type: CommonCartridgeElementType.RESOURCES_WRAPPER, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeResourcesWrapperElementPropsV130); + const props = setup(CommonCartridgeElementType.RESOURCES_WRAPPER); + const result = CommonCartridgeElementFactoryV130.createElement( + props as CommonCartridgeResourcesWrapperElementPropsV130 + ); expect(result).toBeInstanceOf(CommonCartridgeResourcesWrapperElementV130); }); }); describe('when element type is not supported', () => { + const setup = () => { + return { + type: 'not-supported' as CommonCartridgeElementType, + version: CommonCartridgeVersion.V_1_3_0, + }; + }; + it('should throw error', () => { expect(() => - CommonCartridgeElementFactoryV130.createElement({ - type: 'not-supported' as CommonCartridgeElementType, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeResourcesWrapperElementPropsV130) + CommonCartridgeElementFactoryV130.createElement(setup() as CommonCartridgeResourcesWrapperElementPropsV130) ).toThrow(InternalServerErrorException); }); }); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts index 191d4729562..8c432a595f1 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts @@ -1,27 +1,18 @@ -import { faker } from '@faker-js/faker'; import { InternalServerErrorException } from '@nestjs/common'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { - CommonCartridgeMetadataElementPropsV130, - CommonCartridgeMetadataElementV130, -} from './common-cartridge-metadata-element'; +import { createCommonCartridgeMetadataElementPropsV130 } from '@shared/testing/factory/common-cartridge-element-props.factory'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeMetadataElementV130 } from './common-cartridge-metadata-element'; describe('CommonCartridgeMetadataElementV130', () => { - const setup = () => { - const props: CommonCartridgeMetadataElementPropsV130 = { - type: CommonCartridgeElementType.METADATA, - version: CommonCartridgeVersion.V_1_3_0, - title: faker.lorem.words(), - creationDate: faker.date.past(), - copyrightOwners: [faker.person.fullName(), faker.person.fullName()], - }; - const sut = new CommonCartridgeMetadataElementV130(props); - - return { sut, props }; - }; - describe('getSupportedVersion', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeMetadataElementPropsV130(); + const sut = new CommonCartridgeMetadataElementV130(props); + + return { sut, props }; + }; + it('should return correct version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -31,20 +22,24 @@ describe('CommonCartridgeMetadataElementV130', () => { }); describe('when using not supported Common Cartridge version', () => { + const notSupportedProps = createCommonCartridgeMetadataElementPropsV130(); + notSupportedProps.version = CommonCartridgeVersion.V_1_1_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeMetadataElementV130({ - type: CommonCartridgeElementType.METADATA, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeMetadataElementPropsV130) - ).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeMetadataElementV130(notSupportedProps)).toThrow(InternalServerErrorException); }); }); }); describe('getManifestXmlObject', () => { describe('when using common cartridge version 1.3', () => { + const setup = () => { + const props = createCommonCartridgeMetadataElementPropsV130(); + const sut = new CommonCartridgeMetadataElementV130(props); + + return { sut, props }; + }; + it('should return correct manifest xml object', () => { const { sut, props } = setup(); const result = sut.getManifestXmlObject(); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts index e9d018db6fd..586e28fffb5 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts @@ -1,73 +1,21 @@ -import { faker } from '@faker-js/faker'; import { InternalServerErrorException } from '@nestjs/common'; -import { - CommonCartridgeElementType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../../common-cartridge.enums'; -import { - CommonCartridgeResourceFactory, - CommonCartridgeResourceProps, -} from '../../resources/common-cartridge-resource-factory'; -import { CommonCartridgeElementFactory, CommonCartridgeElementProps } from '../common-cartridge-element-factory'; -import { - CommonCartridgeOrganizationElementPropsV130, - CommonCartridgeOrganizationElementV130, -} from './common-cartridge-organization-element'; +import { createCommonCartridgeOrganizationElementPropsV130 } from '@shared/testing/factory/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV130 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; +import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; +import { CommonCartridgeOrganizationElementV130 } from './common-cartridge-organization-element'; describe('CommonCartridgeOrganizationElementV130', () => { - const setup = () => { - const resourceProps: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_LINK, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - url: faker.internet.url(), - }; - const subOrganization1Props: CommonCartridgeElementProps = { - type: CommonCartridgeElementType.ORGANIZATION, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - items: CommonCartridgeResourceFactory.createResource({ - ...resourceProps, - version: CommonCartridgeVersion.V_1_3_0, - folder: faker.string.alphanumeric(10), - }), - }; - const subOrganization2Props: CommonCartridgeElementProps = { - type: CommonCartridgeElementType.ORGANIZATION, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - items: [ - CommonCartridgeResourceFactory.createResource({ - ...resourceProps, - version: CommonCartridgeVersion.V_1_3_0, - folder: faker.string.alphanumeric(10), - }), - ], - }; - const organizationProps: CommonCartridgeOrganizationElementPropsV130 = { - type: CommonCartridgeElementType.ORGANIZATION, - version: CommonCartridgeVersion.V_1_3_0, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - items: [ - CommonCartridgeElementFactory.createElement({ - ...subOrganization1Props, - version: CommonCartridgeVersion.V_1_3_0, - }), - CommonCartridgeElementFactory.createElement({ - ...subOrganization2Props, - version: CommonCartridgeVersion.V_1_3_0, - }), - ], - }; - const sut = new CommonCartridgeOrganizationElementV130(organizationProps); - - return { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps }; - }; - describe('getSupportedVersion', () => { describe('when using common cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeOrganizationElementPropsV130(); + const sut = new CommonCartridgeOrganizationElementV130(props); + + return { sut }; + }; + it('should return correct version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -77,20 +25,40 @@ describe('CommonCartridgeOrganizationElementV130', () => { }); describe('when using not supported common cartridge version', () => { + const notSupportedProps = createCommonCartridgeOrganizationElementPropsV130(); + notSupportedProps.version = CommonCartridgeVersion.V_1_1_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeOrganizationElementV130({ - type: CommonCartridgeElementType.ORGANIZATION, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeOrganizationElementPropsV130) - ).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeOrganizationElementV130(notSupportedProps)).toThrow( + InternalServerErrorException + ); }); }); }); describe('getManifestXmlObject', () => { describe('when using common cartridge version 1.3.0', () => { + const setup = () => { + const resourceProps = createCommonCartridgeWeblinkResourcePropsV130(); + + const subOrganization1Props = createCommonCartridgeOrganizationElementPropsV130( + CommonCartridgeResourceFactory.createResource(resourceProps) + ); + + const subOrganization2Props = createCommonCartridgeOrganizationElementPropsV130([ + CommonCartridgeResourceFactory.createResource(resourceProps), + ]); + + const organizationProps = createCommonCartridgeOrganizationElementPropsV130([ + CommonCartridgeElementFactory.createElement(subOrganization1Props), + CommonCartridgeElementFactory.createElement(subOrganization2Props), + ]); + + const sut = new CommonCartridgeOrganizationElementV130(organizationProps); + + return { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps }; + }; + it('should return correct manifest xml object', () => { const { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps } = setup(); const result = sut.getManifestXmlObject(); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts index 8b3acb0e93e..bfd25d00f49 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -1,37 +1,22 @@ -import { faker } from '@faker-js/faker'; import { InternalServerErrorException } from '@nestjs/common'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElementFactory, CommonCartridgeElementProps } from '../common-cartridge-element-factory'; import { - CommonCartridgeOrganizationsWrapperElementPropsV130, - CommonCartridgeOrganizationsWrapperElementV130, -} from './common-cartridge-organizations-wrapper-element'; + createCommonCartridgeOrganizationElementPropsV130, + createCommonCartridgeOrganizationsWrapperElementPropsV130, +} from '@shared/testing/factory/common-cartridge-element-props.factory'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; +import { CommonCartridgeOrganizationsWrapperElementV130 } from './common-cartridge-organizations-wrapper-element'; describe('CommonCartridgeOrganizationsWrapperElementV130', () => { - const setup = () => { - const organizationProps: CommonCartridgeElementProps = { - type: CommonCartridgeElementType.ORGANIZATION, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - items: [], - }; - const props: CommonCartridgeOrganizationsWrapperElementPropsV130 = { - type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, - version: CommonCartridgeVersion.V_1_3_0, - items: [ - CommonCartridgeElementFactory.createElement({ - ...organizationProps, - version: CommonCartridgeVersion.V_1_3_0, - }), - ], - }; - const sut = new CommonCartridgeOrganizationsWrapperElementV130(props); - - return { sut, props, organizationProps }; - }; - describe('getSupportedVersion', () => { describe('when using common cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeOrganizationsWrapperElementPropsV130(); + const sut = new CommonCartridgeOrganizationsWrapperElementV130(props); + + return { sut }; + }; + it('should return correct version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -41,20 +26,29 @@ describe('CommonCartridgeOrganizationsWrapperElementV130', () => { }); describe('when using not supported common cartridge version', () => { + const notSupportedProps = createCommonCartridgeOrganizationsWrapperElementPropsV130(); + notSupportedProps.version = CommonCartridgeVersion.V_1_1_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeOrganizationsWrapperElementV130({ - type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeOrganizationsWrapperElementPropsV130) - ).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeOrganizationsWrapperElementV130(notSupportedProps)).toThrow( + InternalServerErrorException + ); }); }); }); describe('getManifestXmlObject', () => { describe('when using common cartridge version 1.3.0', () => { + const setup = () => { + const organizationProps = createCommonCartridgeOrganizationElementPropsV130(); + const props = createCommonCartridgeOrganizationsWrapperElementPropsV130([ + CommonCartridgeElementFactory.createElement(organizationProps), + ]); + const sut = new CommonCartridgeOrganizationsWrapperElementV130(props); + + return { sut, organizationProps }; + }; + it('should return correct manifest xml object', () => { const { sut, organizationProps } = setup(); const result = sut.getManifestXmlObject(); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts index cee1eab7eef..6abadf35f71 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts @@ -1,45 +1,20 @@ -import { faker } from '@faker-js/faker'; -import { - CommonCartridgeElementType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../../common-cartridge.enums'; -import { - CommonCartridgeResourceFactory, - CommonCartridgeResourceProps, -} from '../../resources/common-cartridge-resource-factory'; -import { CommonCartridgeResourcesWrapperElementPropsV110 } from '../v1.1.0/common-cartridge-resources-wrapper-element'; -import { - CommonCartridgeResourcesWrapperElementPropsV130, - CommonCartridgeResourcesWrapperElementV130, -} from './common-cartridge-resources-wrapper-element'; +import { InternalServerErrorException } from '@nestjs/common'; +import { createCommonCartridgeResourcesWrapperElementPropsV130 } from '@shared/testing/factory/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV130 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; +import { CommonCartridgeResourcesWrapperElementV130 } from './common-cartridge-resources-wrapper-element'; describe('CommonCartridgeResourcesWrapperElementV130', () => { - const setup = () => { - const resourceProps: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_LINK, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - url: faker.internet.url(), - }; - const props: CommonCartridgeResourcesWrapperElementPropsV110 = { - type: CommonCartridgeElementType.RESOURCES_WRAPPER, - version: CommonCartridgeVersion.V_1_3_0, - items: [ - CommonCartridgeResourceFactory.createResource({ - ...resourceProps, - version: CommonCartridgeVersion.V_1_3_0, - folder: faker.string.alphanumeric(10), - }), - ], - }; - const sut = new CommonCartridgeResourcesWrapperElementV130(props); - - return { sut, props, resourceProps }; - }; - describe('getSupportedVersion', () => { describe('when using common cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeResourcesWrapperElementPropsV130(); + const sut = new CommonCartridgeResourcesWrapperElementV130(props); + + return { sut }; + }; + it('should return correct version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -49,22 +24,31 @@ describe('CommonCartridgeResourcesWrapperElementV130', () => { }); describe('when using not supported common cartridge version', () => { + const notSupportedProps = createCommonCartridgeResourcesWrapperElementPropsV130(); + notSupportedProps.version = CommonCartridgeVersion.V_1_1_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeResourcesWrapperElementV130({ - type: CommonCartridgeElementType.RESOURCES_WRAPPER, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeResourcesWrapperElementPropsV130) - ).toThrowError(); + expect(() => new CommonCartridgeResourcesWrapperElementV130(notSupportedProps)).toThrowError( + InternalServerErrorException + ); }); }); }); describe('getManifestXmlObject', () => { describe('when using common cartridge version 1.3.0', () => { + const setup = () => { + const weblinkResourceProps = createCommonCartridgeWeblinkResourcePropsV130(); + const props = createCommonCartridgeResourcesWrapperElementPropsV130([ + CommonCartridgeResourceFactory.createResource(weblinkResourceProps), + ]); + const sut = new CommonCartridgeResourcesWrapperElementV130(props); + + return { sut, weblinkResourceProps }; + }; + it('should return correct manifest xml object', () => { - const { sut, resourceProps } = setup(); + const { sut, weblinkResourceProps } = setup(); const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ @@ -73,7 +57,7 @@ describe('CommonCartridgeResourcesWrapperElementV130', () => { resource: [ { $: { - identifier: resourceProps.identifier, + identifier: weblinkResourceProps.identifier, type: expect.any(String), }, file: { diff --git a/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts b/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts index a2c4d04975d..40c815e0a97 100644 --- a/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts +++ b/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts @@ -43,12 +43,14 @@ export function createCommonCartridgeOrganizationElementPropsV110( }; } -export function createCommonCartridgeOrganizationElementPropsV130(): CommonCartridgeOrganizationElementPropsV130 { +export function createCommonCartridgeOrganizationElementPropsV130( + items?: CommonCartridgeResource | Array +): CommonCartridgeOrganizationElementPropsV130 { return { type: CommonCartridgeElementType.ORGANIZATION, identifier: faker.string.uuid(), title: faker.lorem.words(), - items: [], + items: items || [], version: CommonCartridgeVersion.V_1_3_0, }; } From 95b5d8578527d80c377707a73e880e04f69bf674 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 7 Feb 2024 14:25:18 +0100 Subject: [PATCH 146/177] EW-539 Adjust test for cc element factory --- .../common-cartridge-element-factory.spec.ts | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.spec.ts index 44aca28ea54..a94eab27b9a 100644 --- a/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.spec.ts @@ -1,33 +1,31 @@ import { InternalServerErrorException } from '@nestjs/common'; +import { + createCommonCartridgeMetadataElementPropsV110, + createCommonCartridgeMetadataElementPropsV130, +} from '@shared/testing/factory/common-cartridge-element-props.factory'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElementFactory } from './common-cartridge-element-factory'; import { CommonCartridgeMetadataElementPropsV110, CommonCartridgeMetadataElementV110, } from './v1.1.0/common-cartridge-metadata-element'; -import { - CommonCartridgeMetadataElementPropsV130, - CommonCartridgeMetadataElementV130, -} from './v1.3.0/common-cartridge-metadata-element'; +import { CommonCartridgeMetadataElementV130 } from './v1.3.0/common-cartridge-metadata-element'; describe('CommonCartridgeElementFactory', () => { describe('createElement', () => { describe('when Common Cartridge versions is supported', () => { + const propsV110 = createCommonCartridgeMetadataElementPropsV110(); + const propsV130 = createCommonCartridgeMetadataElementPropsV130(); + it('should return v1.1.0 element', () => { - const result = CommonCartridgeElementFactory.createElement({ - version: CommonCartridgeVersion.V_1_1_0, - type: CommonCartridgeElementType.METADATA, - } as CommonCartridgeMetadataElementPropsV110); + const result = CommonCartridgeElementFactory.createElement(propsV110); expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV110); }); it('should return v1.3.0 element', () => { - const result = CommonCartridgeElementFactory.createElement({ - version: CommonCartridgeVersion.V_1_3_0, - type: CommonCartridgeElementType.METADATA, - } as CommonCartridgeMetadataElementPropsV130); + const result = CommonCartridgeElementFactory.createElement(propsV130); expect(result).toBeDefined(); expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV130); @@ -35,13 +33,13 @@ describe('CommonCartridgeElementFactory', () => { }); describe('when versions is not supported', () => { - it('should throw InternalServerErrorException', () => { - const notSupportedVersions = [ - CommonCartridgeVersion.V_1_0_0, - CommonCartridgeVersion.V_1_2_0, - CommonCartridgeVersion.V_1_4_0, - ]; + const notSupportedVersions = [ + CommonCartridgeVersion.V_1_0_0, + CommonCartridgeVersion.V_1_2_0, + CommonCartridgeVersion.V_1_4_0, + ]; + it('should throw InternalServerErrorException', () => { notSupportedVersions.forEach((version) => { expect(() => CommonCartridgeElementFactory.createElement({ From f5ddf8027894bd51b3f42101868d6b69daa7719a Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 7 Feb 2024 15:49:28 +0100 Subject: [PATCH 147/177] EW-539 Working on tests for cc resources --- ...mon-cartridge-web-content-resource.spec.ts | 76 ++++++++++-------- ...common-cartridge-web-link-resource.spec.ts | 77 +++++++++++-------- ...mon-cartridge-web-content-resource.spec.ts | 76 ++++++++++-------- ...common-cartridge-web-link-resource.spec.ts | 77 ++++++++++++------- ...common-cartridge-resource-props.factory.ts | 32 +++++++- 5 files changed, 214 insertions(+), 124 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts index b35e3c00165..65d7fcd2e93 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts @@ -1,33 +1,18 @@ -import { faker } from '@faker-js/faker'; import { InternalServerErrorException } from '@nestjs/common'; -import { - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../../common-cartridge.enums'; -import { - CommonCartridgeWebContentResourcePropsV110, - CommonCartridgeWebContentResourceV110, -} from './common-cartridge-web-content-resource'; +import { createCommonCartridgeWebContentResourcePropsV110 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeWebContentResourceV110 } from './common-cartridge-web-content-resource'; describe('CommonCartridgeWebContentResourceV110', () => { - const setup = () => { - const props: CommonCartridgeWebContentResourcePropsV110 = { - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_1_0, - identifier: faker.string.uuid(), - folder: faker.string.uuid(), - title: faker.lorem.words(), - html: faker.lorem.paragraph(), - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }; - const sut = new CommonCartridgeWebContentResourceV110(props); - - return { sut, props }; - }; - describe('canInline', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeWebContentResourcePropsV110(); + const sut = new CommonCartridgeWebContentResourceV110(props); + + return { sut }; + }; + it('should return false', () => { const { sut } = setup(); const result = sut.canInline(); @@ -39,6 +24,13 @@ describe('CommonCartridgeWebContentResourceV110', () => { describe('getFilePath', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeWebContentResourcePropsV110(); + const sut = new CommonCartridgeWebContentResourceV110(props); + + return { sut, props }; + }; + it('should return the constructed file path', () => { const { sut, props } = setup(); const result = sut.getFilePath(); @@ -50,6 +42,13 @@ describe('CommonCartridgeWebContentResourceV110', () => { describe('getFileContent', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeWebContentResourcePropsV110(); + const sut = new CommonCartridgeWebContentResourceV110(props); + + return { sut, props }; + }; + it('should return the HTML', () => { const { sut, props } = setup(); const result = sut.getFileContent(); @@ -61,6 +60,13 @@ describe('CommonCartridgeWebContentResourceV110', () => { describe('getSupportedVersion', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeWebContentResourcePropsV110(); + const sut = new CommonCartridgeWebContentResourceV110(props); + + return { sut }; + }; + it('should return Common Cartridge version 1.1.0', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -70,20 +76,26 @@ describe('CommonCartridgeWebContentResourceV110', () => { }); describe('when using not supported Common Cartridge version', () => { + const notSupportedProps = createCommonCartridgeWebContentResourcePropsV110(); + notSupportedProps.version = CommonCartridgeVersion.V_1_3_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeWebContentResourceV110({ - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeWebContentResourcePropsV110) - ).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeWebContentResourceV110(notSupportedProps)).toThrow( + InternalServerErrorException + ); }); }); }); describe('getManifestXmlObject', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeWebContentResourcePropsV110(); + const sut = new CommonCartridgeWebContentResourceV110(props); + + return { sut, props }; + }; + it('should return the correct XML object', () => { const { sut, props } = setup(); const result = sut.getManifestXmlObject(); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts index 54486366432..51db7626c36 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -1,31 +1,19 @@ -import { faker } from '@faker-js/faker'; import { InternalServerErrorException } from '@nestjs/common'; +import { createCommonCartridgeWeblinkResourcePropsV110 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; import { readFile } from 'fs/promises'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { - CommonCartridgeWebLinkResourcePropsV110, - CommonCartridgeWebLinkResourceV110, -} from './common-cartridge-web-link-resource'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeWebLinkResourceV110 } from './common-cartridge-web-link-resource'; describe('CommonCartridgeWebLinkResourceV110', () => { - const setup = () => { - const props: CommonCartridgeWebLinkResourcePropsV110 = { - type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_1_0, - identifier: faker.string.uuid(), - folder: faker.string.uuid(), - title: 'Title', - url: 'http://www.example.tld', - target: '_self', - windowFeatures: 'width=100;height=100;', - }; - const sut = new CommonCartridgeWebLinkResourceV110(props); - - return { sut, props }; - }; - describe('canInline', () => { - describe('when using Common Cartridge version 1.1.0', () => { + describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV110(); + const sut = new CommonCartridgeWebLinkResourceV110(props); + + return { sut }; + }; + it('should return false', () => { const { sut } = setup(); const result = sut.canInline(); @@ -37,6 +25,13 @@ describe('CommonCartridgeWebLinkResourceV110', () => { describe('getFilePath', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV110(); + const sut = new CommonCartridgeWebLinkResourceV110(props); + + return { sut, props }; + }; + it('should return the constructed file path', () => { const { sut, props } = setup(); const result = sut.getFilePath(); @@ -48,6 +43,17 @@ describe('CommonCartridgeWebLinkResourceV110', () => { describe('getFileContent', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV110(); + props.title = 'Title'; + props.url = 'http://www.example.tld'; + props.target = '_self'; + props.windowFeatures = 'width=100;height=100;'; + + const sut = new CommonCartridgeWebLinkResourceV110(props); + + return { sut }; + }; it('should contain correct XML', async () => { const { sut } = setup(); const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml', 'utf8'); @@ -60,6 +66,13 @@ describe('CommonCartridgeWebLinkResourceV110', () => { describe('getSupportedVersion', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV110(); + const sut = new CommonCartridgeWebLinkResourceV110(props); + + return { sut }; + }; + it('should return the supported version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -69,20 +82,24 @@ describe('CommonCartridgeWebLinkResourceV110', () => { }); describe('when using not supported Common Cartridge version', () => { + const notSupportedProps = createCommonCartridgeWeblinkResourcePropsV110(); + notSupportedProps.version = CommonCartridgeVersion.V_1_3_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeWebLinkResourceV110({ - type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeWebLinkResourcePropsV110) - ).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeWebLinkResourceV110(notSupportedProps)).toThrow(InternalServerErrorException); }); }); }); describe('getManifestXmlObject', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV110(); + const sut = new CommonCartridgeWebLinkResourceV110(props); + + return { sut, props }; + }; + it('should return the manifest XML object', () => { const { sut, props } = setup(); const result = sut.getManifestXmlObject(); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts index 3206a0d70f7..ee3cc4ac306 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts @@ -1,33 +1,18 @@ -import { faker } from '@faker-js/faker'; import { InternalServerErrorException } from '@nestjs/common'; -import { - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../../common-cartridge.enums'; -import { - CommonCartridgeWebContentResourcePropsV130, - CommonCartridgeWebContentResourceV130, -} from './common-cartridge-web-content-resource'; +import { createCommonCartridgeWebContentResourcePropsV130 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; describe('CommonCartridgeWebContentResourceV130', () => { - const setup = () => { - const props: CommonCartridgeWebContentResourcePropsV130 = { - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_3_0, - folder: faker.string.uuid(), - identifier: faker.string.uuid(), - title: faker.lorem.words(), - html: faker.lorem.words(), - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }; - const sut = new CommonCartridgeWebContentResourceV130(props); - - return { sut, props }; - }; - describe('canInline', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeWebContentResourcePropsV130(); + const sut = new CommonCartridgeWebContentResourceV130(props); + + return { sut }; + }; + it('should return false', () => { const { sut } = setup(); const result = sut.canInline(); @@ -39,6 +24,13 @@ describe('CommonCartridgeWebContentResourceV130', () => { describe('getFilePath', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeWebContentResourcePropsV130(); + const sut = new CommonCartridgeWebContentResourceV130(props); + + return { sut, props }; + }; + it('should return the constructed file path', () => { const { sut, props } = setup(); const result = sut.getFilePath(); @@ -50,6 +42,13 @@ describe('CommonCartridgeWebContentResourceV130', () => { describe('getFileContent', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeWebContentResourcePropsV130(); + const sut = new CommonCartridgeWebContentResourceV130(props); + + return { sut, props }; + }; + it('should return the HTML', () => { const { sut, props } = setup(); const result = sut.getFileContent(); @@ -61,6 +60,13 @@ describe('CommonCartridgeWebContentResourceV130', () => { describe('getSupportedVersion', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeWebContentResourcePropsV130(); + const sut = new CommonCartridgeWebContentResourceV130(props); + + return { sut }; + }; + it('should return the supported version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -70,20 +76,26 @@ describe('CommonCartridgeWebContentResourceV130', () => { }); describe('when using not supported Common Cartridge version', () => { + const notSupportedProps = createCommonCartridgeWebContentResourcePropsV130(); + notSupportedProps.version = CommonCartridgeVersion.V_1_1_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeWebContentResourceV130({ - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeWebContentResourcePropsV130) - ).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeWebContentResourceV130(notSupportedProps)).toThrow( + InternalServerErrorException + ); }); }); }); describe('getManifestXmlObject', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeWebContentResourcePropsV130(); + const sut = new CommonCartridgeWebContentResourceV130(props); + + return { sut, props }; + }; + it('should return the manifest XML object', () => { const { sut, props } = setup(); const result = sut.getManifestXmlObject(); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts index baab77bec25..cddfd11af90 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts @@ -1,30 +1,19 @@ -import { faker } from '@faker-js/faker'; +import { InternalServerErrorException } from '@nestjs/common'; +import { createCommonCartridgeWeblinkResourcePropsV130 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; import { readFile } from 'node:fs/promises'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { - CommonCartridgeWebLinkResourcePropsV130, - CommonCartridgeWebLinkResourceV130, -} from './common-cartridge-web-link-resource'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeWebLinkResourceV130 } from './common-cartridge-web-link-resource'; describe('CommonCartridgeWebLinkResourceV130', () => { - const setup = () => { - const props: CommonCartridgeWebLinkResourcePropsV130 = { - type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_3_0, - identifier: faker.string.uuid(), - folder: faker.string.uuid(), - title: 'Title', - url: 'http://www.example.tld', - target: '_self', - windowFeatures: 'width=100;height=100;', - }; - const sut = new CommonCartridgeWebLinkResourceV130(props); - - return { sut, props }; - }; - describe('canInline', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV130(); + const sut = new CommonCartridgeWebLinkResourceV130(props); + + return { sut }; + }; + it('should return false', () => { const { sut } = setup(); const result = sut.canInline(); @@ -36,6 +25,13 @@ describe('CommonCartridgeWebLinkResourceV130', () => { describe('getFilePath', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV130(); + const sut = new CommonCartridgeWebLinkResourceV130(props); + + return { sut, props }; + }; + it('should return the constructed file path', () => { const { sut, props } = setup(); const result = sut.getFilePath(); @@ -47,6 +43,18 @@ describe('CommonCartridgeWebLinkResourceV130', () => { describe('getFileContent', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV130(); + props.title = 'Title'; + props.url = 'http://www.example.tld'; + props.target = '_self'; + props.windowFeatures = 'width=100;height=100;'; + + const sut = new CommonCartridgeWebLinkResourceV130(props); + + return { sut }; + }; + it('should contain correct XML', async () => { const { sut } = setup(); const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml', 'utf8'); @@ -59,6 +67,13 @@ describe('CommonCartridgeWebLinkResourceV130', () => { describe('getSupportedVersion', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV130(); + const sut = new CommonCartridgeWebLinkResourceV130(props); + + return { sut }; + }; + it('should return the supported version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -68,20 +83,24 @@ describe('CommonCartridgeWebLinkResourceV130', () => { }); describe('when using not supported Common Cartridge version', () => { + const notSupportedProps = createCommonCartridgeWeblinkResourcePropsV130(); + notSupportedProps.version = CommonCartridgeVersion.V_1_1_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeWebLinkResourceV130({ - type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeWebLinkResourcePropsV130) - ).toThrow(); + expect(() => new CommonCartridgeWebLinkResourceV130(notSupportedProps)).toThrow(InternalServerErrorException); }); }); }); describe('getManifestXmlObject', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV130(); + const sut = new CommonCartridgeWebLinkResourceV130(props); + + return { sut, props }; + }; + it('should return the manifest XML object', () => { const { sut, props } = setup(); const result = sut.getManifestXmlObject(); diff --git a/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts b/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts index 1d1c7263c99..17f6cab1a14 100644 --- a/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts +++ b/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts @@ -1,6 +1,12 @@ import { faker } from '@faker-js/faker'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '@src/modules/common-cartridge'; +import { + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '@src/modules/common-cartridge'; +import { CommonCartridgeWebContentResourcePropsV110 } from '@src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource'; import { CommonCartridgeWebLinkResourcePropsV110 } from '@src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource'; +import { CommonCartridgeWebContentResourcePropsV130 } from '@src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource'; import { CommonCartridgeWebLinkResourcePropsV130 } from '@src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource'; export function createCommonCartridgeWeblinkResourcePropsV110(): CommonCartridgeWebLinkResourcePropsV110 { @@ -24,3 +30,27 @@ export function createCommonCartridgeWeblinkResourcePropsV130(): CommonCartridge folder: faker.string.alphanumeric(10), }; } + +export function createCommonCartridgeWebContentResourcePropsV110(): CommonCartridgeWebContentResourcePropsV110 { + return { + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + folder: faker.string.alphanumeric(10), + title: faker.lorem.words(), + html: faker.lorem.paragraphs(), + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }; +} + +export function createCommonCartridgeWebContentResourcePropsV130(): CommonCartridgeWebContentResourcePropsV130 { + return { + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_3_0, + identifier: faker.string.uuid(), + folder: faker.string.alphanumeric(10), + title: faker.lorem.words(), + html: faker.lorem.paragraphs(), + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }; +} From e5d09f9a9b73a4ebfca4449cb7874b6d5d550568 Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 7 Feb 2024 15:38:08 +0100 Subject: [PATCH 148/177] EW-539 working on review comments --- .../src/modules/learnroom/uc/course-export.uc.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.ts index 7e88c4c7ce7..0586569463c 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.ts @@ -17,10 +17,7 @@ export class CourseExportUc { ) {} async exportCourse(courseId: EntityId, userId: EntityId, version: CommonCartridgeVersion): Promise { - if (!this.configService.get('FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED')) { - throw new NotFoundException(); - } - + this.checkFeatureEnabled(); const context = AuthorizationContextBuilder.read([Permission.COURSE_EDIT]); await this.authorizationService.checkPermissionByReferences( userId, @@ -31,4 +28,10 @@ export class CourseExportUc { return this.courseExportService.exportCourse(courseId, userId, version); } + + private checkFeatureEnabled(): void | never { + if (!this.configService.get('FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED')) { + throw new NotFoundException(); + } + } } From 5a6bb19e8aee8ac495b96a65399871112242439d Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 7 Feb 2024 15:51:14 +0100 Subject: [PATCH 149/177] EW-539 fixing review comments --- .../common-cartridge-export.service.spec.ts | 124 +++++++++--------- 1 file changed, 64 insertions(+), 60 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index 8d31f4c01a8..c4c693771a7 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -23,6 +23,56 @@ describe('CommonCartridgeExportService', () => { `<${nodeName}>${value.toString()}`; const getFileContent = (archive: AdmZip, filePath: string): string | undefined => archive.getEntry(filePath)?.getData().toString(); + const setupParams = async (version: CommonCartridgeVersion) => { + const course = courseFactory.teachersWithId(2).buildWithId(); + const tasks = taskFactory.buildListWithId(2); + const lessons = lessonFactory.buildListWithId(1, { + tasks, + contents: [ + { + title: 'text-title', + hidden: false, + component: ComponentType.TEXT, + content: { + text: 'text', + }, + }, + { + title: 'lernstore-title', + hidden: false, + component: ComponentType.LERNSTORE, + content: { + resources: [ + { + client: 'client-1', + description: 'description-1', + title: 'title-1', + url: 'url-1', + }, + { + client: 'client-2', + description: 'description-2', + title: 'title-2', + url: 'url-2', + }, + ], + }, + }, + ], + }); + const [lesson] = lessons; + + lessonServiceMock.findById.mockResolvedValue(lesson); + courseServiceMock.findById.mockResolvedValue(course); + lessonServiceMock.findByCourseIds.mockResolvedValue([lessons, lessons.length]); + taskServiceMock.findBySingleParent.mockResolvedValue([tasks, tasks.length]); + configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); + + const buffer = await sut.exportCourse(course.id, faker.string.uuid(), version); + const archive = new AdmZip(buffer); + + return { archive, course, lessons, tasks }; + }; beforeAll(async () => { await setupEntities(); @@ -60,71 +110,23 @@ describe('CommonCartridgeExportService', () => { }); describe('exportCourse', () => { - const setup = async (version: CommonCartridgeVersion) => { - const course = courseFactory.teachersWithId(2).buildWithId(); - const tasks = taskFactory.buildListWithId(2); - const lessons = lessonFactory.buildListWithId(1, { - tasks, - contents: [ - { - title: 'text-title', - hidden: false, - component: ComponentType.TEXT, - content: { - text: 'text', - }, - }, - { - title: 'lernstore-title', - hidden: false, - component: ComponentType.LERNSTORE, - content: { - resources: [ - { - client: 'client-1', - description: 'description-1', - title: 'title-1', - url: 'url-1', - }, - { - client: 'client-2', - description: 'description-2', - title: 'title-2', - url: 'url-2', - }, - ], - }, - }, - ], - }); - const [lesson] = lessons; - - lessonServiceMock.findById.mockResolvedValue(lesson); - courseServiceMock.findById.mockResolvedValue(course); - lessonServiceMock.findByCourseIds.mockResolvedValue([lessons, lessons.length]); - taskServiceMock.findBySingleParent.mockResolvedValue([tasks, tasks.length]); - configServiceMock.getOrThrow.mockReturnValue(faker.internet.url()); - - const archive = new AdmZip(await sut.exportCourse(course.id, faker.string.uuid(), version)); - - return { archive, course, lessons, tasks }; - }; - describe('when using version 1.1', () => { + const setup = async () => setupParams(CommonCartridgeVersion.V_1_1_0); + it('should use schema version 1.1.0', async () => { - const { archive } = await setup(CommonCartridgeVersion.V_1_1_0); + const { archive } = await setup(); expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('schemaversion', '1.1.0')); }); it('should add course', async () => { - const { archive, course } = await setup(CommonCartridgeVersion.V_1_1_0); + const { archive, course } = await setup(); expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('mnf:string', course.name)); }); it('should add lessons', async () => { - const { archive, lessons } = await setup(CommonCartridgeVersion.V_1_1_0); + const { archive, lessons } = await setup(); lessons.forEach((lesson) => { expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('title', lesson.name)); @@ -132,7 +134,7 @@ describe('CommonCartridgeExportService', () => { }); it('should add tasks', async () => { - const { archive, tasks } = await setup(CommonCartridgeVersion.V_1_1_0); + const { archive, tasks } = await setup(); tasks.forEach((task) => { expect(getFileContent(archive, 'imsmanifest.xml')).toContain(` { }); it('should add tasks of lesson to manifest file', async () => { - const { archive, lessons } = await setup(CommonCartridgeVersion.V_1_1_0); + const { archive, lessons } = await setup(); const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); lessons[0].tasks.getItems().forEach((task) => { @@ -151,20 +153,22 @@ describe('CommonCartridgeExportService', () => { }); describe('when using version 1.3', () => { + const setup = async () => setupParams(CommonCartridgeVersion.V_1_3_0); + it('should use schema version 1.3.0', async () => { - const { archive } = await setup(CommonCartridgeVersion.V_1_3_0); + const { archive } = await setup(); expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('schemaversion', '1.3.0')); }); it('should add course', async () => { - const { archive, course } = await setup(CommonCartridgeVersion.V_1_3_0); + const { archive, course } = await setup(); expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('mnf:string', course.name)); }); it('should add lessons', async () => { - const { archive, lessons } = await setup(CommonCartridgeVersion.V_1_3_0); + const { archive, lessons } = await setup(); lessons.forEach((lesson) => { expect(getFileContent(archive, 'imsmanifest.xml')).toContain(createXmlString('title', lesson.name)); @@ -172,7 +176,7 @@ describe('CommonCartridgeExportService', () => { }); it('should add tasks', async () => { - const { archive, tasks } = await setup(CommonCartridgeVersion.V_1_3_0); + const { archive, tasks } = await setup(); tasks.forEach((task) => { expect(getFileContent(archive, 'imsmanifest.xml')).toContain(` { }); it('should add tasks of lesson to manifest file', async () => { - const { archive, lessons } = await setup(CommonCartridgeVersion.V_1_3_0); + const { archive, lessons } = await setup(); const manifest = archive.getEntry('imsmanifest.xml')?.getData().toString(); lessons[0].tasks.getItems().forEach((task) => { From 75375e1d2bbddd350860c04563551cf38e0e6d84 Mon Sep 17 00:00:00 2001 From: psachmann Date: Wed, 7 Feb 2024 16:51:23 +0100 Subject: [PATCH 150/177] EW-539 working on review comments --- .../common-cartridge-file-builder.spec.ts | 11 ++++++ .../builders/common-cartridge-file-builder.ts | 9 +++-- .../modules/common-cartridge/utils.spec.ts | 37 ------------------- .../src/modules/common-cartridge/utils.ts | 8 ---- 4 files changed, 17 insertions(+), 48 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts index c9419c265cd..a73b2fbf5ea 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts @@ -91,5 +91,16 @@ describe('CommonCartridgeFileBuilder', () => { expect(resource).toBeDefined(); }); }); + + describe('when metadata has not been provide', () => { + it('should throw an error', async () => { + const builder = new CommonCartridgeFileBuilder({ + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + }); + + await expect(builder.build()).rejects.toThrow('Metadata is not defined'); // TODO: does not matches the error + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts index 8da8d237679..d6e798dd940 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts @@ -7,7 +7,7 @@ import { import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; import { CommonCartridgeResourceFactory } from '../resources/common-cartridge-resource-factory'; -import { OmitVersion, checkDefined } from '../utils'; +import { OmitVersion } from '../utils'; import { CommonCartridgeOrganizationBuilder, CommonCartridgeOrganizationBuilderOptions, @@ -52,13 +52,16 @@ export class CommonCartridgeFileBuilder { } public build(): Promise { - const metadata = checkDefined(this.metadata, 'metadata'); + if (!this.metadata) { + throw new Error('Metadata is not defined'); + } + const organizations = this.organizationBuilders.map((builder) => builder.build()); const manifest = CommonCartridgeResourceFactory.createResource({ type: CommonCartridgeResourceType.MANIFEST, version: this.props.version, identifier: this.props.identifier, - metadata, + metadata: this.metadata, organizations, resources: this.resources, }); diff --git a/apps/server/src/modules/common-cartridge/utils.spec.ts b/apps/server/src/modules/common-cartridge/utils.spec.ts index 5fd700c5696..e49e0ff6777 100644 --- a/apps/server/src/modules/common-cartridge/utils.spec.ts +++ b/apps/server/src/modules/common-cartridge/utils.spec.ts @@ -3,8 +3,6 @@ import { ObjectID } from 'bson'; import { CommonCartridgeVersion } from './common-cartridge.enums'; import { buildXmlString, - checkDefined, - checkIntendedUse, createElementTypeNotSupportedError, createIdentifier, createResourceTypeNotSupportedError, @@ -31,41 +29,6 @@ describe('CommonCartridgeUtils', () => { }); }); - // AI next 16 lines - describe('checkDefined', () => { - describe('when checking value', () => { - it('should return value when value is defined', () => { - const value = 'value'; - - expect(checkDefined(value, 'value')).toBe(value); - }); - - it('should throw error when value is undefined', () => { - expect(() => checkDefined(undefined, 'value')).toThrow(new Error('value is null or undefined')); - }); - - it('should throw error when value is null', () => { - expect(() => checkDefined(null, 'value')).toThrow(new Error('value is null or undefined')); - }); - }); - }); - - describe('checkIntendedUse', () => { - describe('when checking supported intended use', () => { - it('should not throw', () => { - const intendedUse = 'unspecified'; - - expect(() => checkIntendedUse(intendedUse, ['unspecified'])).not.toThrow(); - }); - - it('should throw error when intended use is not supported', () => { - const intendedUse = 'unsupported'; - - expect(() => checkIntendedUse(intendedUse, [])).toThrow(`Intended use ${intendedUse} is not supported`); - }); - }); - }); - describe('createIdentifier', () => { describe('when creating identifier', () => { it('should return identifier with prefix', () => { diff --git a/apps/server/src/modules/common-cartridge/utils.ts b/apps/server/src/modules/common-cartridge/utils.ts index 8955a12e467..e510b8633f6 100644 --- a/apps/server/src/modules/common-cartridge/utils.ts +++ b/apps/server/src/modules/common-cartridge/utils.ts @@ -43,11 +43,3 @@ export function checkIntendedUse(intendedUse: string, supportedIntendedUses: str throw new Error(`Intended use ${intendedUse} is not supported`); } } - -export function checkDefined(value: T | undefined | null, name: string): T | never { - if (value) { - return value; - } - - throw new Error(`${name} is null or undefined`); -} From e23bc7e84c130b0bb519ab1a5b19682cb302bb95 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 8 Feb 2024 09:33:59 +0100 Subject: [PATCH 151/177] EW-539 Adjust test for cc resource factory --- .../common-cartridge-resource-factory.spec.ts | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.spec.ts index 9461e8ade61..4b46a49b49e 100644 --- a/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.spec.ts @@ -1,51 +1,42 @@ import { InternalServerErrorException } from '@nestjs/common'; import { - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../common-cartridge.enums'; + createCommonCartridgeWebContentResourcePropsV110, + createCommonCartridgeWebContentResourcePropsV130, +} from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResourcePropsV110, CommonCartridgeWebContentResourceV110, } from './v1.1.0/common-cartridge-web-content-resource'; -import { - CommonCartridgeWebContentResourcePropsV130, - CommonCartridgeWebContentResourceV130, -} from './v1.3.0/common-cartridge-web-content-resource'; +import { CommonCartridgeWebContentResourceV130 } from './v1.3.0/common-cartridge-web-content-resource'; describe('CommonCartridgeResourceVersion', () => { describe('createResource', () => { describe('when Common Cartridge version is supported', () => { it('should return v1.1.0 resource', () => { - const result = CommonCartridgeResourceFactory.createResource({ - version: CommonCartridgeVersion.V_1_1_0, - type: CommonCartridgeResourceType.WEB_CONTENT, - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - } as CommonCartridgeWebContentResourcePropsV110); + const props = createCommonCartridgeWebContentResourcePropsV110(); + const result = CommonCartridgeResourceFactory.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV110); }); it('should return v1.3.0 resource', () => { - const result = CommonCartridgeResourceFactory.createResource({ - version: CommonCartridgeVersion.V_1_3_0, - type: CommonCartridgeResourceType.WEB_CONTENT, - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - } as CommonCartridgeWebContentResourcePropsV130); + const props = createCommonCartridgeWebContentResourcePropsV130(); + const result = CommonCartridgeResourceFactory.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV130); }); }); describe('when versions is not supported', () => { - it('should throw InternalServerErrorException', () => { - const notSupportedVersions = [ - CommonCartridgeVersion.V_1_0_0, - CommonCartridgeVersion.V_1_2_0, - CommonCartridgeVersion.V_1_4_0, - ]; + const notSupportedVersions = [ + CommonCartridgeVersion.V_1_0_0, + CommonCartridgeVersion.V_1_2_0, + CommonCartridgeVersion.V_1_4_0, + ]; + it('should throw InternalServerErrorException', () => { notSupportedVersions.forEach((version) => { expect(() => CommonCartridgeResourceFactory.createResource({ From 1cc12c689cd47b6f7abc4f633d6e4339ce1c7d89 Mon Sep 17 00:00:00 2001 From: psachmann Date: Thu, 8 Feb 2024 10:43:10 +0100 Subject: [PATCH 152/177] EW-539 solving async problems --- .../builders/common-cartridge-file-builder.spec.ts | 4 ++-- .../builders/common-cartridge-file-builder.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts index a73b2fbf5ea..f65a7aabd97 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts @@ -94,12 +94,12 @@ describe('CommonCartridgeFileBuilder', () => { describe('when metadata has not been provide', () => { it('should throw an error', async () => { - const builder = new CommonCartridgeFileBuilder({ + const sut = new CommonCartridgeFileBuilder({ version: CommonCartridgeVersion.V_1_1_0, identifier: faker.string.uuid(), }); - await expect(builder.build()).rejects.toThrow('Metadata is not defined'); // TODO: does not matches the error + await expect(sut.build()).rejects.toThrow('Metadata is not defined'); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts index d6e798dd940..fbab733a82b 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts @@ -51,7 +51,7 @@ export class CommonCartridgeFileBuilder { return builder; } - public build(): Promise { + public async build(): Promise { if (!this.metadata) { throw new Error('Metadata is not defined'); } @@ -74,7 +74,9 @@ export class CommonCartridgeFileBuilder { this.archive.addFile(manifest.getFilePath(), Buffer.from(manifest.getFileContent())); - return this.archive.toBufferPromise(); + const buffer = await this.archive.toBufferPromise(); + + return buffer; } private addResource(resource: CommonCartridgeResource): void { From c0a3ce5bf0a171a970e0630c5dc4cd3fa07fb605 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 8 Feb 2024 14:25:47 +0100 Subject: [PATCH 153/177] EW-539 Working on tests --- .../common-cartridge-file-builder.spec.ts | 10 +- .../common-cartridge-element-factory.spec.ts | 73 +++------ .../common-cartridge-element-factory.spec.ts | 69 +++------ ...common-cartridge-manifest-resource.spec.ts | 140 +++++++++-------- .../common-cartridge-resource-factory.spec.ts | 37 ++--- ...common-cartridge-manifest-resource.spec.ts | 142 ++++++++++-------- .../common-cartridge-resource-factory.spec.ts | 41 ++--- ...common-cartridge-resource-props.factory.ts | 25 +++ 8 files changed, 260 insertions(+), 277 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts index f65a7aabd97..f232ca08fd7 100644 --- a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts @@ -93,12 +93,12 @@ describe('CommonCartridgeFileBuilder', () => { }); describe('when metadata has not been provide', () => { - it('should throw an error', async () => { - const sut = new CommonCartridgeFileBuilder({ - version: CommonCartridgeVersion.V_1_1_0, - identifier: faker.string.uuid(), - }); + const sut = new CommonCartridgeFileBuilder({ + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + }); + it('should throw an error', async () => { await expect(sut.build()).rejects.toThrow('Metadata is not defined'); }); }); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts index 10d91dff9b2..ad7fc17a723 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts @@ -1,82 +1,57 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElementFactoryV110 } from './common-cartridge-element-factory'; -import { - CommonCartridgeMetadataElementPropsV110, - CommonCartridgeMetadataElementV110, -} from './common-cartridge-metadata-element'; -import { - CommonCartridgeOrganizationElementPropsV110, - CommonCartridgeOrganizationElementV110, -} from './common-cartridge-organization-element'; import { - CommonCartridgeOrganizationsWrapperElementPropsV110, - CommonCartridgeOrganizationsWrapperElementV110, -} from './common-cartridge-organizations-wrapper-element'; -import { - CommonCartridgeResourcesWrapperElementPropsV110, - CommonCartridgeResourcesWrapperElementV110, -} from './common-cartridge-resources-wrapper-element'; + createCommonCartridgeMetadataElementPropsV110, + createCommonCartridgeOrganizationElementPropsV110, + createCommonCartridgeOrganizationsWrapperElementPropsV110, + createCommonCartridgeResourcesWrapperElementPropsV110, +} from '@shared/testing/factory/common-cartridge-element-props.factory'; +import { CommonCartridgeElementType } from '../../common-cartridge.enums'; +import { CommonCartridgeElementFactoryV110 } from './common-cartridge-element-factory'; +import { CommonCartridgeMetadataElementV110 } from './common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElementV110 } from './common-cartridge-organization-element'; +import { CommonCartridgeOrganizationsWrapperElementV110 } from './common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementV110 } from './common-cartridge-resources-wrapper-element'; describe('CommonCartridgeElementFactoryV110', () => { describe('createElement', () => { describe('when creating elements from props', () => { - const setup = (type: CommonCartridgeElementType) => { - return { - type, - version: CommonCartridgeVersion.V_1_1_0, - }; - }; - it('should return metadata element', () => { - const props = setup(CommonCartridgeElementType.METADATA); - const result = CommonCartridgeElementFactoryV110.createElement( - props as CommonCartridgeMetadataElementPropsV110 - ); + const props = createCommonCartridgeMetadataElementPropsV110(); + const result = CommonCartridgeElementFactoryV110.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV110); }); it('should return organization element', () => { - const props = setup(CommonCartridgeElementType.ORGANIZATION); - const result = CommonCartridgeElementFactoryV110.createElement( - props as CommonCartridgeOrganizationElementPropsV110 - ); + const props = createCommonCartridgeOrganizationElementPropsV110(); + const result = CommonCartridgeElementFactoryV110.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeOrganizationElementV110); }); it('should return organization wrapper element', () => { - const props = setup(CommonCartridgeElementType.ORGANIZATIONS_WRAPPER); - const result = CommonCartridgeElementFactoryV110.createElement( - props as CommonCartridgeOrganizationsWrapperElementPropsV110 - ); + const props = createCommonCartridgeOrganizationsWrapperElementPropsV110(); + const result = CommonCartridgeElementFactoryV110.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeOrganizationsWrapperElementV110); }); it('should return resources wrapper element', () => { - const props = setup(CommonCartridgeElementType.RESOURCES_WRAPPER); - const result = CommonCartridgeElementFactoryV110.createElement( - props as CommonCartridgeResourcesWrapperElementPropsV110 - ); + const props = createCommonCartridgeResourcesWrapperElementPropsV110(); + const result = CommonCartridgeElementFactoryV110.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeResourcesWrapperElementV110); }); }); describe('when element type is not supported', () => { - const setup = () => { - return { - type: 'not-supported' as CommonCartridgeElementType, - version: CommonCartridgeVersion.V_1_1_0, - }; - }; + const notSupportedProps = createCommonCartridgeMetadataElementPropsV110(); + notSupportedProps.type = 'not-supported' as CommonCartridgeElementType.METADATA; it('should throw error', () => { - expect(() => - CommonCartridgeElementFactoryV110.createElement(setup() as CommonCartridgeMetadataElementPropsV110) - ).toThrow(InternalServerErrorException); + expect(() => CommonCartridgeElementFactoryV110.createElement(notSupportedProps)).toThrow( + InternalServerErrorException + ); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts index c4c5515c0e9..d55c36d2a17 100644 --- a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts @@ -1,80 +1,57 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeOrganizationsWrapperElementPropsV110 } from '../v1.1.0/common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeElementFactoryV130 } from './common-cartridge-element-factory'; -import { - CommonCartridgeMetadataElementPropsV130, - CommonCartridgeMetadataElementV130, -} from './common-cartridge-metadata-element'; import { - CommonCartridgeOrganizationElementPropsV130, - CommonCartridgeOrganizationElementV130, -} from './common-cartridge-organization-element'; + createCommonCartridgeMetadataElementPropsV130, + createCommonCartridgeOrganizationElementPropsV130, + createCommonCartridgeOrganizationsWrapperElementPropsV130, + createCommonCartridgeResourcesWrapperElementPropsV130, +} from '@shared/testing/factory/common-cartridge-element-props.factory'; +import { CommonCartridgeElementType } from '../../common-cartridge.enums'; +import { CommonCartridgeElementFactoryV130 } from './common-cartridge-element-factory'; +import { CommonCartridgeMetadataElementV130 } from './common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElementV130 } from './common-cartridge-organization-element'; import { CommonCartridgeOrganizationsWrapperElementV130 } from './common-cartridge-organizations-wrapper-element'; -import { - CommonCartridgeResourcesWrapperElementPropsV130, - CommonCartridgeResourcesWrapperElementV130, -} from './common-cartridge-resources-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementV130 } from './common-cartridge-resources-wrapper-element'; describe('CommonCartridgeElementFactoryV130', () => { describe('createElement', () => { describe('when creating elements from props', () => { - const setup = (type: CommonCartridgeElementType) => { - return { - type, - version: CommonCartridgeVersion.V_1_3_0, - }; - }; - it('should return metadata element', () => { - const props = setup(CommonCartridgeElementType.METADATA); - const result = CommonCartridgeElementFactoryV130.createElement( - props as CommonCartridgeMetadataElementPropsV130 - ); + const props = createCommonCartridgeMetadataElementPropsV130(); + const result = CommonCartridgeElementFactoryV130.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV130); }); it('should return organization element', () => { - const props = setup(CommonCartridgeElementType.ORGANIZATION); - const result = CommonCartridgeElementFactoryV130.createElement( - props as CommonCartridgeOrganizationElementPropsV130 - ); + const props = createCommonCartridgeOrganizationElementPropsV130(); + const result = CommonCartridgeElementFactoryV130.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeOrganizationElementV130); }); it('should return organization wrapper element', () => { - const props = setup(CommonCartridgeElementType.ORGANIZATIONS_WRAPPER); - const result = CommonCartridgeElementFactoryV130.createElement( - props as CommonCartridgeOrganizationsWrapperElementPropsV110 - ); + const props = createCommonCartridgeOrganizationsWrapperElementPropsV130(); + const result = CommonCartridgeElementFactoryV130.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeOrganizationsWrapperElementV130); }); it('should return resources wrapper element', () => { - const props = setup(CommonCartridgeElementType.RESOURCES_WRAPPER); - const result = CommonCartridgeElementFactoryV130.createElement( - props as CommonCartridgeResourcesWrapperElementPropsV130 - ); + const props = createCommonCartridgeResourcesWrapperElementPropsV130(); + const result = CommonCartridgeElementFactoryV130.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeResourcesWrapperElementV130); }); }); describe('when element type is not supported', () => { - const setup = () => { - return { - type: 'not-supported' as CommonCartridgeElementType, - version: CommonCartridgeVersion.V_1_3_0, - }; - }; + const notSupportedProps = createCommonCartridgeOrganizationsWrapperElementPropsV130(); + notSupportedProps.type = 'not-supported' as CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; it('should throw error', () => { - expect(() => - CommonCartridgeElementFactoryV130.createElement(setup() as CommonCartridgeResourcesWrapperElementPropsV130) - ).toThrow(InternalServerErrorException); + expect(() => CommonCartridgeElementFactoryV130.createElement(notSupportedProps)).toThrow( + InternalServerErrorException + ); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index 66ee12b64a3..0f1a510ace6 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -1,4 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; +import { createCommonCartridgeManifestResourcePropsV110 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; import { readFile } from 'fs/promises'; import { CommonCartridgeElementType, @@ -8,65 +9,18 @@ import { } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; -import { - CommonCartridgeManifestResourcePropsV110, - CommonCartridgeManifestResourceV110, -} from './common-cartridge-manifest-resource'; +import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; describe('CommonCartridgeManifestResourceV110', () => { - const setup = () => { - const resource1 = CommonCartridgeResourceFactory.createResource({ - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_1_0, - title: 'Title 1', - identifier: 'r1', - folder: 'o1', - html: '

HTML

', - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }); - const resource2 = CommonCartridgeResourceFactory.createResource({ - type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_1_0, - title: 'Title 2', - identifier: 'r2', - folder: 'o2', - url: 'https://www.example.tld', - }); - const organization1 = CommonCartridgeElementFactory.createElement({ - type: CommonCartridgeElementType.ORGANIZATION, - version: CommonCartridgeVersion.V_1_1_0, - title: 'Title 1', - identifier: 'o1', - items: resource1, - }); - const organization2 = CommonCartridgeElementFactory.createElement({ - type: CommonCartridgeElementType.ORGANIZATION, - version: CommonCartridgeVersion.V_1_1_0, - title: 'Title 2', - identifier: 'o2', - items: resource2, - }); - const metadata = CommonCartridgeElementFactory.createElement({ - type: CommonCartridgeElementType.METADATA, - version: CommonCartridgeVersion.V_1_1_0, - title: 'Common Cartridge Manifest', - copyrightOwners: ['John Doe', 'Jane Doe'], - creationDate: new Date('2023-01-01'), - }); - const sut = new CommonCartridgeManifestResourceV110({ - type: CommonCartridgeResourceType.MANIFEST, - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'm1', - metadata, - organizations: [organization1, organization2], - resources: [resource1, resource2], - }); - - return { sut }; - }; - describe('canInline', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeManifestResourcePropsV110(); + const sut = new CommonCartridgeManifestResourceV110(props); + + return { sut }; + }; + it('should return false', () => { const { sut } = setup(); const result = sut.canInline(); @@ -78,6 +32,13 @@ describe('CommonCartridgeManifestResourceV110', () => { describe('getFilePath', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeManifestResourcePropsV110(); + const sut = new CommonCartridgeManifestResourceV110(props); + + return { sut }; + }; + it('should return constructed file path', () => { const { sut } = setup(); const result = sut.getFilePath(); @@ -89,6 +50,57 @@ describe('CommonCartridgeManifestResourceV110', () => { describe('getFileContent', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const resource1 = CommonCartridgeResourceFactory.createResource({ + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_1_0, + title: 'Title 1', + identifier: 'r1', + folder: 'o1', + html: '

HTML

', + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }); + const resource2 = CommonCartridgeResourceFactory.createResource({ + type: CommonCartridgeResourceType.WEB_LINK, + version: CommonCartridgeVersion.V_1_1_0, + title: 'Title 2', + identifier: 'r2', + folder: 'o2', + url: 'https://www.example.tld', + }); + const organization1 = CommonCartridgeElementFactory.createElement({ + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_1_0, + title: 'Title 1', + identifier: 'o1', + items: resource1, + }); + const organization2 = CommonCartridgeElementFactory.createElement({ + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_1_0, + title: 'Title 2', + identifier: 'o2', + items: resource2, + }); + const metadata = CommonCartridgeElementFactory.createElement({ + type: CommonCartridgeElementType.METADATA, + version: CommonCartridgeVersion.V_1_1_0, + title: 'Common Cartridge Manifest', + copyrightOwners: ['John Doe', 'Jane Doe'], + creationDate: new Date('2023-01-01'), + }); + const sut = new CommonCartridgeManifestResourceV110({ + type: CommonCartridgeResourceType.MANIFEST, + version: CommonCartridgeVersion.V_1_1_0, + identifier: 'm1', + metadata, + organizations: [organization1, organization2], + resources: [resource1, resource2], + }); + + return { sut }; + }; + it('should return constructed file content', async () => { const { sut } = setup(); const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml', 'utf-8'); @@ -101,6 +113,13 @@ describe('CommonCartridgeManifestResourceV110', () => { describe('getSupportedVersion', () => { describe('when using Common Cartridge version 1.1.0', () => { + const setup = () => { + const props = createCommonCartridgeManifestResourcePropsV110(); + const sut = new CommonCartridgeManifestResourceV110(props); + + return { sut }; + }; + it('should return supported version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -110,14 +129,11 @@ describe('CommonCartridgeManifestResourceV110', () => { }); describe('when using not supported Common Cartridge version', () => { + const notSupportedProps = createCommonCartridgeManifestResourcePropsV110(); + notSupportedProps.version = CommonCartridgeVersion.V_1_3_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeManifestResourceV110({ - type: CommonCartridgeResourceType.MANIFEST, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeManifestResourcePropsV110) - ).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeManifestResourceV110(notSupportedProps)).toThrow(InternalServerErrorException); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts index ab733af46f9..7381ef086d9 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts @@ -1,18 +1,12 @@ import { InternalServerErrorException } from '@nestjs/common'; import { - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../../common-cartridge.enums'; -import { - CommonCartridgeManifestResourcePropsV110, - CommonCartridgeManifestResourceV110, -} from './common-cartridge-manifest-resource'; + createCommonCartridgeManifestResourcePropsV110, + createCommonCartridgeWebContentResourcePropsV110, + createCommonCartridgeWeblinkResourcePropsV110, +} from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV110 } from './common-cartridge-resource-factory'; -import { - CommonCartridgeWebContentResourcePropsV110, - CommonCartridgeWebContentResourceV110, -} from './common-cartridge-web-content-resource'; +import { CommonCartridgeWebContentResourceV110 } from './common-cartridge-web-content-resource'; import { CommonCartridgeWebLinkResourcePropsV110, CommonCartridgeWebLinkResourceV110, @@ -22,29 +16,22 @@ describe('CommonCartridgeResourceFactoryV110', () => { describe('createResource', () => { describe('when creating resources from props', () => { it('should return manifest resource', () => { - const result = CommonCartridgeResourceFactoryV110.createResource({ - type: CommonCartridgeResourceType.MANIFEST, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeManifestResourcePropsV110); + const props = createCommonCartridgeManifestResourcePropsV110(); + const result = CommonCartridgeResourceFactoryV110.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeManifestResourceV110); }); it('should return web content resource', () => { - const result = CommonCartridgeResourceFactoryV110.createResource({ - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_1_0, - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - } as CommonCartridgeWebContentResourcePropsV110); + const props = createCommonCartridgeWebContentResourcePropsV110(); + const result = CommonCartridgeResourceFactoryV110.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV110); }); it('should return web link resource', () => { - const result = CommonCartridgeResourceFactoryV110.createResource({ - type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeWebLinkResourcePropsV110); + const props = createCommonCartridgeWeblinkResourcePropsV110(); + const result = CommonCartridgeResourceFactoryV110.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeWebLinkResourceV110); }); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index a91f6325590..8978c2bcfb3 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -1,4 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; +import { createCommonCartridgeManifestResourcePropsV130 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; import { readFile } from 'fs/promises'; import { CommonCartridgeElementType, @@ -9,65 +10,18 @@ import { import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; import { CommonCartridgeElementFactoryV130 } from '../../elements/v1.3.0/common-cartridge-element-factory'; import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; -import { - CommonCartridgeManifestResourcePropsV130, - CommonCartridgeManifestResourceV130, -} from './common-cartridge-manifest-resource'; - -describe('CommonCartridgeManifestResourceV110', () => { - const setup = () => { - const resource1 = CommonCartridgeResourceFactory.createResource({ - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_3_0, - title: 'Title 1', - identifier: 'r1', - folder: 'o1', - html: '

HTML

', - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }); - const resource2 = CommonCartridgeResourceFactory.createResource({ - type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_3_0, - title: 'Title 2', - identifier: 'r2', - folder: 'o2', - url: 'https://www.example.tld', - }); - const organization1 = CommonCartridgeElementFactoryV130.createElement({ - type: CommonCartridgeElementType.ORGANIZATION, - version: CommonCartridgeVersion.V_1_3_0, - title: 'Title 1', - identifier: 'o1', - items: resource1, - }); - const organization2 = CommonCartridgeElementFactory.createElement({ - type: CommonCartridgeElementType.ORGANIZATION, - version: CommonCartridgeVersion.V_1_3_0, - title: 'Title 2', - identifier: 'o2', - items: resource2, - }); - const metadata = CommonCartridgeElementFactoryV130.createElement({ - type: CommonCartridgeElementType.METADATA, - version: CommonCartridgeVersion.V_1_3_0, - title: 'Common Cartridge Manifest', - copyrightOwners: ['John Doe', 'Jane Doe'], - creationDate: new Date('2023-01-01'), - }); - const sut = new CommonCartridgeManifestResourceV130({ - type: CommonCartridgeResourceType.MANIFEST, - version: CommonCartridgeVersion.V_1_3_0, - identifier: 'm1', - metadata, - organizations: [organization1, organization2], - resources: [resource1, resource2], - }); - - return { sut }; - }; +import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; +describe('CommonCartridgeManifestResourceV130', () => { describe('canInline', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeManifestResourcePropsV130(); + const sut = new CommonCartridgeManifestResourceV130(props); + + return { sut }; + }; + it('should return false', () => { const { sut } = setup(); const result = sut.canInline(); @@ -79,6 +33,13 @@ describe('CommonCartridgeManifestResourceV110', () => { describe('getFilePath', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeManifestResourcePropsV130(); + const sut = new CommonCartridgeManifestResourceV130(props); + + return { sut }; + }; + it('should return constructed file path', () => { const { sut } = setup(); const result = sut.getFilePath(); @@ -90,6 +51,57 @@ describe('CommonCartridgeManifestResourceV110', () => { describe('getFileContent', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const resource1 = CommonCartridgeResourceFactory.createResource({ + type: CommonCartridgeResourceType.WEB_CONTENT, + version: CommonCartridgeVersion.V_1_3_0, + title: 'Title 1', + identifier: 'r1', + folder: 'o1', + html: '

HTML

', + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }); + const resource2 = CommonCartridgeResourceFactory.createResource({ + type: CommonCartridgeResourceType.WEB_LINK, + version: CommonCartridgeVersion.V_1_3_0, + title: 'Title 2', + identifier: 'r2', + folder: 'o2', + url: 'https://www.example.tld', + }); + const organization1 = CommonCartridgeElementFactoryV130.createElement({ + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_3_0, + title: 'Title 1', + identifier: 'o1', + items: resource1, + }); + const organization2 = CommonCartridgeElementFactory.createElement({ + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_3_0, + title: 'Title 2', + identifier: 'o2', + items: resource2, + }); + const metadata = CommonCartridgeElementFactoryV130.createElement({ + type: CommonCartridgeElementType.METADATA, + version: CommonCartridgeVersion.V_1_3_0, + title: 'Common Cartridge Manifest', + copyrightOwners: ['John Doe', 'Jane Doe'], + creationDate: new Date('2023-01-01'), + }); + const sut = new CommonCartridgeManifestResourceV130({ + type: CommonCartridgeResourceType.MANIFEST, + version: CommonCartridgeVersion.V_1_3_0, + identifier: 'm1', + metadata, + organizations: [organization1, organization2], + resources: [resource1, resource2], + }); + + return { sut }; + }; + it('should return constructed file content', async () => { const { sut } = setup(); const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml', 'utf-8'); @@ -102,6 +114,13 @@ describe('CommonCartridgeManifestResourceV110', () => { describe('getSupportedVersion', () => { describe('when using Common Cartridge version 1.3.0', () => { + const setup = () => { + const props = createCommonCartridgeManifestResourcePropsV130(); + const sut = new CommonCartridgeManifestResourceV130(props); + + return { sut }; + }; + it('should return supported version', () => { const { sut } = setup(); const result = sut.getSupportedVersion(); @@ -111,14 +130,11 @@ describe('CommonCartridgeManifestResourceV110', () => { }); describe('when using not supported Common Cartridge version', () => { + const notSupportedProps = createCommonCartridgeManifestResourcePropsV130(); + notSupportedProps.version = CommonCartridgeVersion.V_1_1_0; + it('should throw error', () => { - expect( - () => - new CommonCartridgeManifestResourceV130({ - type: CommonCartridgeResourceType.MANIFEST, - version: CommonCartridgeVersion.V_1_1_0, - } as CommonCartridgeManifestResourcePropsV130) - ).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeManifestResourceV130(notSupportedProps)).toThrow(InternalServerErrorException); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts index c186a29527f..f9e928326f4 100644 --- a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts @@ -1,18 +1,12 @@ import { InternalServerErrorException } from '@nestjs/common'; import { - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../../common-cartridge.enums'; -import { - CommonCartridgeManifestResourcePropsV130, - CommonCartridgeManifestResourceV130, -} from './common-cartridge-manifest-resource'; + createCommonCartridgeManifestResourcePropsV130, + createCommonCartridgeWebContentResourcePropsV130, + createCommonCartridgeWeblinkResourcePropsV130, +} from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV130 } from './common-cartridge-resource-factory'; -import { - CommonCartridgeWebContentResourcePropsV130, - CommonCartridgeWebContentResourceV130, -} from './common-cartridge-web-content-resource'; +import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; import { CommonCartridgeWebLinkResourcePropsV130, CommonCartridgeWebLinkResourceV130, @@ -22,29 +16,22 @@ describe('CommonCartridgeResourceFactoryV130', () => { describe('createResource', () => { describe('when creating resources from props', () => { it('should return manifest resource', () => { - const result = CommonCartridgeResourceFactoryV130.createResource({ - type: CommonCartridgeResourceType.MANIFEST, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeManifestResourcePropsV130); + const props = createCommonCartridgeManifestResourcePropsV130(); + const result = CommonCartridgeResourceFactoryV130.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeManifestResourceV130); }); - it('shoul return web content resource', () => { - const result = CommonCartridgeResourceFactoryV130.createResource({ - type: CommonCartridgeResourceType.WEB_CONTENT, - version: CommonCartridgeVersion.V_1_3_0, - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - } as CommonCartridgeWebContentResourcePropsV130); + it('should return web content resource', () => { + const props = createCommonCartridgeWebContentResourcePropsV130(); + const result = CommonCartridgeResourceFactoryV130.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV130); }); - it('shoul return web link resource', () => { - const result = CommonCartridgeResourceFactoryV130.createResource({ - type: CommonCartridgeResourceType.WEB_LINK, - version: CommonCartridgeVersion.V_1_3_0, - } as CommonCartridgeWebLinkResourcePropsV130); + it('should return web link resource', () => { + const props = createCommonCartridgeWeblinkResourcePropsV130(); + const result = CommonCartridgeResourceFactoryV130.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeWebLinkResourceV130); }); diff --git a/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts b/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts index 17f6cab1a14..1d90402d040 100644 --- a/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts +++ b/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts @@ -4,8 +4,11 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion, } from '@src/modules/common-cartridge'; +import { CommonCartridgeElement } from '@src/modules/common-cartridge/interfaces/common-cartridge-element.interface'; +import { CommonCartridgeManifestResourcePropsV110 } from '@src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource'; import { CommonCartridgeWebContentResourcePropsV110 } from '@src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource'; import { CommonCartridgeWebLinkResourcePropsV110 } from '@src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource'; +import { CommonCartridgeManifestResourcePropsV130 } from '@src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource'; import { CommonCartridgeWebContentResourcePropsV130 } from '@src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource'; import { CommonCartridgeWebLinkResourcePropsV130 } from '@src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource'; @@ -54,3 +57,25 @@ export function createCommonCartridgeWebContentResourcePropsV130(): CommonCartri intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, }; } + +export function createCommonCartridgeManifestResourcePropsV110(): CommonCartridgeManifestResourcePropsV110 { + return { + type: CommonCartridgeResourceType.MANIFEST, + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + metadata: {} as CommonCartridgeElement, + organizations: [], + resources: [], + }; +} + +export function createCommonCartridgeManifestResourcePropsV130(): CommonCartridgeManifestResourcePropsV130 { + return { + type: CommonCartridgeResourceType.MANIFEST, + version: CommonCartridgeVersion.V_1_3_0, + identifier: faker.string.uuid(), + metadata: {} as CommonCartridgeElement, + organizations: [], + resources: [], + }; +} From be2258cff5768e7c6ce694c7f818ede57a443e51 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 9 Feb 2024 11:45:04 +0100 Subject: [PATCH 154/177] EW-539 Add test for coverage --- .../src/modules/common-cartridge/utils.spec.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/server/src/modules/common-cartridge/utils.spec.ts b/apps/server/src/modules/common-cartridge/utils.spec.ts index e49e0ff6777..380cfb29e8f 100644 --- a/apps/server/src/modules/common-cartridge/utils.spec.ts +++ b/apps/server/src/modules/common-cartridge/utils.spec.ts @@ -3,6 +3,7 @@ import { ObjectID } from 'bson'; import { CommonCartridgeVersion } from './common-cartridge.enums'; import { buildXmlString, + checkIntendedUse, createElementTypeNotSupportedError, createIdentifier, createResourceTypeNotSupportedError, @@ -66,4 +67,16 @@ describe('CommonCartridgeUtils', () => { }); }); }); + + describe('checkIntendedUse', () => { + describe('when intended use is not supported', () => { + it('should throw error', () => { + const supportedIntendedUses = ['use1', 'use2']; + + expect(() => checkIntendedUse('use3', supportedIntendedUses)).toThrowError( + 'Intended use use3 is not supported' + ); + }); + }); + }); }); From 2e0cd436fd7fde01068f3b8a6e6f83fb89abe416 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 15 Feb 2024 10:12:45 +0100 Subject: [PATCH 155/177] EW-539 Trial to remove tasks from lesson properties --- .../service/common-cartridge-export.service.spec.ts | 9 ++++++--- apps/server/src/shared/domain/entity/lesson.entity.ts | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index c4c693771a7..ac77a28e477 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -1,11 +1,12 @@ import { faker } from '@faker-js/faker'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; +import { Collection } from '@mikro-orm/core'; import { CommonCartridgeExportService, CourseService, LearnroomConfig } from '@modules/learnroom'; import { LessonService } from '@modules/lesson'; import { TaskService } from '@modules/task'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; -import { ComponentType } from '@shared/domain/entity'; +import { ComponentType, Task } from '@shared/domain/entity'; import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing'; import AdmZip from 'adm-zip'; import { CommonCartridgeVersion } from '../../common-cartridge'; @@ -27,7 +28,7 @@ describe('CommonCartridgeExportService', () => { const course = courseFactory.teachersWithId(2).buildWithId(); const tasks = taskFactory.buildListWithId(2); const lessons = lessonFactory.buildListWithId(1, { - tasks, + // tasks, contents: [ { title: 'text-title', @@ -61,6 +62,8 @@ describe('CommonCartridgeExportService', () => { ], }); const [lesson] = lessons; + const taskFromLesson = taskFactory.buildWithId(); + lesson.tasks = new Collection([taskFromLesson]); lessonServiceMock.findById.mockResolvedValue(lesson); courseServiceMock.findById.mockResolvedValue(course); @@ -71,7 +74,7 @@ describe('CommonCartridgeExportService', () => { const buffer = await sut.exportCourse(course.id, faker.string.uuid(), version); const archive = new AdmZip(buffer); - return { archive, course, lessons, tasks }; + return { archive, course, lessons, tasks, taskFromLesson }; }; beforeAll(async () => { diff --git a/apps/server/src/shared/domain/entity/lesson.entity.ts b/apps/server/src/shared/domain/entity/lesson.entity.ts index 6cc2fa7c566..5dbcc9e961c 100644 --- a/apps/server/src/shared/domain/entity/lesson.entity.ts +++ b/apps/server/src/shared/domain/entity/lesson.entity.ts @@ -17,7 +17,7 @@ export interface LessonProperties { position?: number; contents: ComponentProperties[] | []; materials?: Material[]; - tasks?: Task[]; + // tasks?: Task[]; } export enum ComponentType { @@ -119,7 +119,7 @@ export class LessonEntity extends BaseEntityWithTimestamps implements LearnroomE this.position = props.position || 0; this.contents = props.contents; if (props.materials) this.materials.set(props.materials); - if (props.tasks) this.tasks.set(props.tasks); + // if (props.tasks) this.tasks.set(props.tasks); } private getParent(): LessonParent { From bed450c943f839ed59bef96bd84c19a650ed3947 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 16 Feb 2024 16:42:54 +0100 Subject: [PATCH 156/177] EW-539 Working on test coverage --- .../service/common-cartridge-export.service.spec.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index ac77a28e477..de44b29c992 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -1,12 +1,11 @@ import { faker } from '@faker-js/faker'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; -import { Collection } from '@mikro-orm/core'; import { CommonCartridgeExportService, CourseService, LearnroomConfig } from '@modules/learnroom'; import { LessonService } from '@modules/lesson'; import { TaskService } from '@modules/task'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; -import { ComponentType, Task } from '@shared/domain/entity'; +import { ComponentType } from '@shared/domain/entity'; import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing'; import AdmZip from 'adm-zip'; import { CommonCartridgeVersion } from '../../common-cartridge'; @@ -62,8 +61,8 @@ describe('CommonCartridgeExportService', () => { ], }); const [lesson] = lessons; - const taskFromLesson = taskFactory.buildWithId(); - lesson.tasks = new Collection([taskFromLesson]); + const taskFromLesson = taskFactory.buildWithId({ course, lesson }); + // lesson.tasks = new Collection([taskFromLesson]); lessonServiceMock.findById.mockResolvedValue(lesson); courseServiceMock.findById.mockResolvedValue(course); From ce0d313d5e83d2fa1aa2ad02af49481d872ac035 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 16 Feb 2024 17:30:55 +0100 Subject: [PATCH 157/177] EW-539 Remove unused code --- .../learnroom/service/common-cartridge-export.service.spec.ts | 2 -- apps/server/src/shared/domain/entity/lesson.entity.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index de44b29c992..fa60184e1b9 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -27,7 +27,6 @@ describe('CommonCartridgeExportService', () => { const course = courseFactory.teachersWithId(2).buildWithId(); const tasks = taskFactory.buildListWithId(2); const lessons = lessonFactory.buildListWithId(1, { - // tasks, contents: [ { title: 'text-title', @@ -62,7 +61,6 @@ describe('CommonCartridgeExportService', () => { }); const [lesson] = lessons; const taskFromLesson = taskFactory.buildWithId({ course, lesson }); - // lesson.tasks = new Collection([taskFromLesson]); lessonServiceMock.findById.mockResolvedValue(lesson); courseServiceMock.findById.mockResolvedValue(course); diff --git a/apps/server/src/shared/domain/entity/lesson.entity.ts b/apps/server/src/shared/domain/entity/lesson.entity.ts index 3fd18c21e3d..f3eb4aa1d9e 100644 --- a/apps/server/src/shared/domain/entity/lesson.entity.ts +++ b/apps/server/src/shared/domain/entity/lesson.entity.ts @@ -17,7 +17,6 @@ export interface LessonProperties { position?: number; contents: ComponentProperties[] | []; materials?: Material[]; - // tasks?: Task[]; } export enum ComponentType { @@ -119,7 +118,6 @@ export class LessonEntity extends BaseEntityWithTimestamps implements LearnroomE this.position = props.position || 0; this.contents = props.contents; if (props.materials) this.materials.set(props.materials); - // if (props.tasks) this.tasks.set(props.tasks); } private getParent(): LessonParent { From 179ea6030f3679e254c4c89df2c9c54a4b8c5c42 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 19 Feb 2024 14:54:50 +0100 Subject: [PATCH 158/177] EW-539 Adjust addTasks method in the cc export service --- .../learnroom/service/common-cartridge-export.service.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 12b35c501d7..079b8f06e5c 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -3,6 +3,7 @@ import { TaskService } from '@modules/task'; import { Injectable } from '@nestjs/common'; import { ComponentProperties } from '@shared/domain/entity'; import { EntityId } from '@shared/domain/types'; +import { createIdentifier } from '@src/modules/common-cartridge/utils'; import { CommonCartridgeFileBuilder, CommonCartridgeOrganizationBuilder, @@ -61,11 +62,13 @@ export class CommonCartridgeExportService { version: CommonCartridgeVersion ): Promise { const [tasks] = await this.taskService.findBySingleParent(userId, courseId); + const organization = builder.addOrganization({ + title: '', + identifier: createIdentifier(), + }); tasks.forEach((task) => { - builder - .addOrganization(this.commonCartridgeMapper.mapTaskToOrganization(task)) - .addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); + organization.addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); }); } From 2fa3df9128799156fbf2d5ca74f5540edf6401c7 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 26 Feb 2024 13:41:57 +0100 Subject: [PATCH 159/177] EW-539 Move export to own folder --- .../common-cartridge-file-builder.spec.ts | 0 .../builders/common-cartridge-file-builder.ts | 0 ...mon-cartridge-organization-builder.spec.ts | 0 .../common-cartridge-organization-builder.ts | 0 .../{ => export}/common-cartridge.enums.ts | 0 .../common-cartridge-element-factory.spec.ts | 0 .../common-cartridge-element-factory.ts | 0 .../common-cartridge-element-factory.spec.ts | 0 .../common-cartridge-element-factory.ts | 0 .../common-cartridge-metadata-element.spec.ts | 0 .../common-cartridge-metadata-element.ts | 0 ...mon-cartridge-organization-element.spec.ts | 0 .../common-cartridge-organization-element.ts | 0 ...idge-organizations-wrapper-element.spec.ts | 0 ...cartridge-organizations-wrapper-element.ts | 0 ...artridge-resources-wrapper-element.spec.ts | 0 ...mon-cartridge-resources-wrapper-element.ts | 0 .../common-cartridge-element-factory.spec.ts | 0 .../common-cartridge-element-factory.ts | 0 .../common-cartridge-metadata-element.spec.ts | 0 .../common-cartridge-metadata-element.ts | 0 ...mon-cartridge-organization-element.spec.ts | 0 .../common-cartridge-organization-element.ts | 0 ...idge-organizations-wrapper-element.spec.ts | 0 ...cartridge-organizations-wrapper-element.ts | 0 ...artridge-resources-wrapper-element.spec.ts | 0 ...mon-cartridge-resources-wrapper-element.ts | 0 .../common-cartridge/{ => export}/index.ts | 0 .../common-cartridge-element.interface.ts | 0 .../common-cartridge-resource.interface.ts | 0 .../common-cartridge-resource-factory.spec.ts | 0 .../common-cartridge-resource-factory.ts | 0 ...common-cartridge-manifest-resource.spec.ts | 0 .../common-cartridge-manifest-resource.ts | 0 .../common-cartridge-resource-factory.spec.ts | 0 .../common-cartridge-resource-factory.ts | 0 ...mon-cartridge-web-content-resource.spec.ts | 0 .../common-cartridge-web-content-resource.ts | 0 ...common-cartridge-web-link-resource.spec.ts | 0 .../common-cartridge-web-link-resource.ts | 0 ...common-cartridge-manifest-resource.spec.ts | 0 .../common-cartridge-manifest-resource.ts | 0 .../common-cartridge-resource-factory.spec.ts | 0 .../common-cartridge-resource-factory.ts | 0 ...mon-cartridge-web-content-resource.spec.ts | 0 .../common-cartridge-web-content-resource.ts | 0 ...common-cartridge-web-link-resource.spec.ts | 0 .../common-cartridge-web-link-resource.ts | 0 .../{ => export}/utils.spec.ts | 0 .../common-cartridge/{ => export}/utils.ts | 0 .../controller/dto/course.query.params.ts | 2 +- .../mapper/common-cartridge.mapper.spec.ts | 4 ++-- .../mapper/common-cartridge.mapper.ts | 4 ++-- .../common-cartridge-export.service.spec.ts | 2 +- .../common-cartridge-export.service.ts | 4 ++-- .../learnroom/uc/course-export.uc.spec.ts | 2 +- .../modules/learnroom/uc/course-export.uc.ts | 2 +- .../common-cartridge-element-props.factory.ts | 22 +++++++++---------- ...common-cartridge-resource-props.factory.ts | 16 +++++++------- 59 files changed, 29 insertions(+), 29 deletions(-) rename apps/server/src/modules/common-cartridge/{ => export}/builders/common-cartridge-file-builder.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/builders/common-cartridge-file-builder.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/builders/common-cartridge-organization-builder.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/builders/common-cartridge-organization-builder.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/common-cartridge.enums.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/common-cartridge-element-factory.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/common-cartridge-element-factory.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.1.0/common-cartridge-element-factory.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.1.0/common-cartridge-element-factory.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.1.0/common-cartridge-metadata-element.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.1.0/common-cartridge-metadata-element.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.1.0/common-cartridge-organization-element.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.1.0/common-cartridge-organization-element.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.3.0/common-cartridge-element-factory.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.3.0/common-cartridge-element-factory.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.3.0/common-cartridge-metadata-element.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.3.0/common-cartridge-metadata-element.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.3.0/common-cartridge-organization-element.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.3.0/common-cartridge-organization-element.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/index.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/interfaces/common-cartridge-element.interface.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/interfaces/common-cartridge-resource.interface.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/common-cartridge-resource-factory.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/common-cartridge-resource-factory.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.1.0/common-cartridge-manifest-resource.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.1.0/common-cartridge-resource-factory.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.1.0/common-cartridge-resource-factory.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.1.0/common-cartridge-web-content-resource.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.1.0/common-cartridge-web-link-resource.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.3.0/common-cartridge-manifest-resource.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.3.0/common-cartridge-resource-factory.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.3.0/common-cartridge-resource-factory.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.3.0/common-cartridge-web-content-resource.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/resources/v1.3.0/common-cartridge-web-link-resource.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/utils.spec.ts (100%) rename apps/server/src/modules/common-cartridge/{ => export}/utils.ts (100%) diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.spec.ts rename to apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/builders/common-cartridge-file-builder.ts rename to apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.spec.ts rename to apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts diff --git a/apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/builders/common-cartridge-organization-builder.ts rename to apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts diff --git a/apps/server/src/modules/common-cartridge/common-cartridge.enums.ts b/apps/server/src/modules/common-cartridge/export/common-cartridge.enums.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/common-cartridge.enums.ts rename to apps/server/src/modules/common-cartridge/export/common-cartridge.enums.ts diff --git a/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.spec.ts rename to apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts diff --git a/apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/common-cartridge-element-factory.ts rename to apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.spec.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-element-factory.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.spec.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.spec.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.spec.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-element-factory.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.spec.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.spec.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts diff --git a/apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts rename to apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts diff --git a/apps/server/src/modules/common-cartridge/index.ts b/apps/server/src/modules/common-cartridge/export/index.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/index.ts rename to apps/server/src/modules/common-cartridge/export/index.ts diff --git a/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/interfaces/common-cartridge-element.interface.ts rename to apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts diff --git a/apps/server/src/modules/common-cartridge/interfaces/common-cartridge-resource.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-resource.interface.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/interfaces/common-cartridge-resource.interface.ts rename to apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-resource.interface.ts diff --git a/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.spec.ts rename to apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts diff --git a/apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/common-cartridge-resource-factory.ts rename to apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.spec.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-resource-factory.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.spec.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-resource-factory.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts diff --git a/apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource.ts rename to apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts diff --git a/apps/server/src/modules/common-cartridge/utils.spec.ts b/apps/server/src/modules/common-cartridge/export/utils.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/utils.spec.ts rename to apps/server/src/modules/common-cartridge/export/utils.spec.ts diff --git a/apps/server/src/modules/common-cartridge/utils.ts b/apps/server/src/modules/common-cartridge/export/utils.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/utils.ts rename to apps/server/src/modules/common-cartridge/export/utils.ts diff --git a/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts b/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts index 3f285dbe354..616345bb075 100644 --- a/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts +++ b/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts @@ -1,5 +1,5 @@ -import { CommonCartridgeVersion } from '@modules/common-cartridge'; import { ApiProperty } from '@nestjs/swagger'; +import { CommonCartridgeVersion } from '@src/modules/common-cartridge/export'; import { IsString, Matches } from 'class-validator'; export class CourseQueryParams { diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index b39c08d2f78..9b10bac4e32 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -4,7 +4,7 @@ import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { ComponentProperties, ComponentType } from '@shared/domain/entity'; import { courseFactory, lessonFactory, setupEntities, taskFactory, userFactory } from '@shared/testing'; -import { OmitVersion, createIdentifier } from '@src/modules/common-cartridge/utils'; +import { OmitVersion, createIdentifier } from '@src/modules/common-cartridge/export/utils'; import { CommonCartridgeElementProps, CommonCartridgeElementType, @@ -14,7 +14,7 @@ import { CommonCartridgeResourceProps, CommonCartridgeResourceType, CommonCartridgeVersion, -} from '../../common-cartridge'; +} from '../../common-cartridge/export'; import { LearnroomConfig } from '../learnroom.config'; import { CommonCartridgeMapper } from './common-cartridge.mapper'; diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 5d268323c37..d06f4274add 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain/entity'; -import { createIdentifier } from '@src/modules/common-cartridge/utils'; +import { createIdentifier } from '@src/modules/common-cartridge/export/utils'; import { CommonCartridgeElementProps, CommonCartridgeElementType, @@ -11,7 +11,7 @@ import { CommonCartridgeResourceProps, CommonCartridgeResourceType, CommonCartridgeVersion, -} from '../../common-cartridge'; +} from '../../common-cartridge/export'; import { LearnroomConfig } from '../learnroom.config'; @Injectable() diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index fa60184e1b9..a5d4fb00bca 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -8,7 +8,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ComponentType } from '@shared/domain/entity'; import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing'; import AdmZip from 'adm-zip'; -import { CommonCartridgeVersion } from '../../common-cartridge'; +import { CommonCartridgeVersion } from '../../common-cartridge/export'; import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; describe('CommonCartridgeExportService', () => { diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 079b8f06e5c..a5d9aaa2ca8 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -3,12 +3,12 @@ import { TaskService } from '@modules/task'; import { Injectable } from '@nestjs/common'; import { ComponentProperties } from '@shared/domain/entity'; import { EntityId } from '@shared/domain/types'; -import { createIdentifier } from '@src/modules/common-cartridge/utils'; +import { createIdentifier } from '@src/modules/common-cartridge/export/utils'; import { CommonCartridgeFileBuilder, CommonCartridgeOrganizationBuilder, CommonCartridgeVersion, -} from '../../common-cartridge'; +} from '../../common-cartridge/export'; import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; import { CourseService } from './course.service'; diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts index 101298cd96f..fda2d73c9e6 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts @@ -1,8 +1,8 @@ import { DeepMocked, createMock } from '@golevelup/ts-jest'; -import { CommonCartridgeVersion } from '@modules/common-cartridge'; import { ForbiddenException, NotFoundException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; +import { CommonCartridgeVersion } from '@src/modules/common-cartridge/export'; import { ObjectId } from 'bson'; import { AuthorizationReferenceService } from '../../authorization/domain'; import { LearnroomConfig } from '../learnroom.config'; diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.ts index 0586569463c..78208277edc 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.ts @@ -1,10 +1,10 @@ import { AuthorizationContextBuilder } from '@modules/authorization'; import { AuthorizableReferenceType, AuthorizationReferenceService } from '@modules/authorization/domain'; -import { CommonCartridgeVersion } from '@modules/common-cartridge'; import { Injectable, NotFoundException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { Permission } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; +import { CommonCartridgeVersion } from '@src/modules/common-cartridge/export'; import { LearnroomConfig } from '../learnroom.config'; import { CommonCartridgeExportService } from '../service/common-cartridge-export.service'; diff --git a/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts b/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts index 40c815e0a97..de8655fce9a 100644 --- a/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts +++ b/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts @@ -1,15 +1,15 @@ import { faker } from '@faker-js/faker'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '@src/modules/common-cartridge'; -import { CommonCartridgeMetadataElementPropsV110 } from '@src/modules/common-cartridge/elements/v1.1.0/common-cartridge-metadata-element'; -import { CommonCartridgeOrganizationElementPropsV110 } from '@src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organization-element'; -import { CommonCartridgeOrganizationsWrapperElementPropsV110 } from '@src/modules/common-cartridge/elements/v1.1.0/common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElementPropsV110 } from '@src/modules/common-cartridge/elements/v1.1.0/common-cartridge-resources-wrapper-element'; -import { CommonCartridgeMetadataElementPropsV130 } from '@src/modules/common-cartridge/elements/v1.3.0/common-cartridge-metadata-element'; -import { CommonCartridgeOrganizationElementPropsV130 } from '@src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organization-element'; -import { CommonCartridgeOrganizationsWrapperElementPropsV130 } from '@src/modules/common-cartridge/elements/v1.3.0/common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElementPropsV130 } from '@src/modules/common-cartridge/elements/v1.3.0/common-cartridge-resources-wrapper-element'; -import { CommonCartridgeElement } from '@src/modules/common-cartridge/interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '@src/modules/common-cartridge/interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '@src/modules/common-cartridge/export'; +import { CommonCartridgeMetadataElementPropsV110 } from '@src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElementPropsV110 } from '@src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element'; +import { CommonCartridgeOrganizationsWrapperElementPropsV110 } from '@src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementPropsV110 } from '@src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element'; +import { CommonCartridgeMetadataElementPropsV130 } from '@src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElementPropsV130 } from '@src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element'; +import { CommonCartridgeOrganizationsWrapperElementPropsV130 } from '@src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementPropsV130 } from '@src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element'; +import { CommonCartridgeElement } from '@src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '@src/modules/common-cartridge/export/interfaces/common-cartridge-resource.interface'; export function createCommonCartridgeMetadataElementPropsV110(): CommonCartridgeMetadataElementPropsV110 { return { diff --git a/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts b/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts index 1d90402d040..1b693c51021 100644 --- a/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts +++ b/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts @@ -3,14 +3,14 @@ import { CommonCartridgeIntendedUseType, CommonCartridgeResourceType, CommonCartridgeVersion, -} from '@src/modules/common-cartridge'; -import { CommonCartridgeElement } from '@src/modules/common-cartridge/interfaces/common-cartridge-element.interface'; -import { CommonCartridgeManifestResourcePropsV110 } from '@src/modules/common-cartridge/resources/v1.1.0/common-cartridge-manifest-resource'; -import { CommonCartridgeWebContentResourcePropsV110 } from '@src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-content-resource'; -import { CommonCartridgeWebLinkResourcePropsV110 } from '@src/modules/common-cartridge/resources/v1.1.0/common-cartridge-web-link-resource'; -import { CommonCartridgeManifestResourcePropsV130 } from '@src/modules/common-cartridge/resources/v1.3.0/common-cartridge-manifest-resource'; -import { CommonCartridgeWebContentResourcePropsV130 } from '@src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-content-resource'; -import { CommonCartridgeWebLinkResourcePropsV130 } from '@src/modules/common-cartridge/resources/v1.3.0/common-cartridge-web-link-resource'; +} from '@src/modules/common-cartridge/export'; +import { CommonCartridgeElement } from '@src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface'; +import { CommonCartridgeManifestResourcePropsV110 } from '@src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource'; +import { CommonCartridgeWebContentResourcePropsV110 } from '@src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource'; +import { CommonCartridgeWebLinkResourcePropsV110 } from '@src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource'; +import { CommonCartridgeManifestResourcePropsV130 } from '@src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource'; +import { CommonCartridgeWebContentResourcePropsV130 } from '@src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource'; +import { CommonCartridgeWebLinkResourcePropsV130 } from '@src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource'; export function createCommonCartridgeWeblinkResourcePropsV110(): CommonCartridgeWebLinkResourcePropsV110 { return { From eefea01f6ddf4ba26067ba0b8cf231314a0f27dc Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 26 Feb 2024 13:43:38 +0100 Subject: [PATCH 160/177] EW-539 Fix small things after merge conflict --- .../src/modules/learnroom/controller/course.controller.ts | 1 - apps/server/src/modules/learnroom/learnroom.config.ts | 2 +- apps/server/src/modules/server/server.config.ts | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/server/src/modules/learnroom/controller/course.controller.ts b/apps/server/src/modules/learnroom/controller/course.controller.ts index 9e51e9f2446..4bcbb5bdead 100644 --- a/apps/server/src/modules/learnroom/controller/course.controller.ts +++ b/apps/server/src/modules/learnroom/controller/course.controller.ts @@ -2,7 +2,6 @@ import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication import { Controller, Get, - NotFoundException, Param, Post, Query, diff --git a/apps/server/src/modules/learnroom/learnroom.config.ts b/apps/server/src/modules/learnroom/learnroom.config.ts index c2ce1f5a562..20ec35e7f25 100644 --- a/apps/server/src/modules/learnroom/learnroom.config.ts +++ b/apps/server/src/modules/learnroom/learnroom.config.ts @@ -3,4 +3,4 @@ export interface LearnroomConfig { GEOGEBRA_BASE_URL: string; FEATURE_COMMON_CARTRIDGE_COURSE_IMPORT_ENABLED: boolean; FEATURE_COMMON_CARTRIDGE_COURSE_IMPORT_MAX_FILE_SIZE: number; -} \ No newline at end of file +} diff --git a/apps/server/src/modules/server/server.config.ts b/apps/server/src/modules/server/server.config.ts index b78fdee2b2a..279cb30f291 100644 --- a/apps/server/src/modules/server/server.config.ts +++ b/apps/server/src/modules/server/server.config.ts @@ -9,7 +9,6 @@ import type { SchoolConfig } from '@modules/school'; import type { UserConfig } from '@modules/user'; import type { CoreModuleConfig } from '@src/core'; import { MailConfig } from '@src/infra/mail/interfaces/mail-config'; -import { LearnroomConfig } from '../learnroom'; export enum NodeEnvType { TEST = 'test', From d0ea153e154e5a67b0973388e7cf787bdee2fea0 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 29 Feb 2024 09:38:51 +0100 Subject: [PATCH 161/177] EW-539 Minor corrections after fixing the merge conflicts --- apps/server/src/modules/learnroom/index.ts | 1 - apps/server/src/modules/server/api/dto/config.response.ts | 4 ++-- apps/server/src/modules/server/api/test/server.api.spec.ts | 4 ++-- apps/server/src/modules/server/server.config.ts | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/server/src/modules/learnroom/index.ts b/apps/server/src/modules/learnroom/index.ts index 721ed65ba01..0db918062ac 100644 --- a/apps/server/src/modules/learnroom/index.ts +++ b/apps/server/src/modules/learnroom/index.ts @@ -1,4 +1,3 @@ -export { CommonCartridgeConfig } from './common-cartridge'; export { LearnroomConfig } from './learnroom.config'; export * from './learnroom.module'; export { diff --git a/apps/server/src/modules/server/api/dto/config.response.ts b/apps/server/src/modules/server/api/dto/config.response.ts index 6e0fcb5e0e3..1dcb4c1f800 100644 --- a/apps/server/src/modules/server/api/dto/config.response.ts +++ b/apps/server/src/modules/server/api/dto/config.response.ts @@ -126,7 +126,7 @@ export class ConfigResponse { FEATURE_CONSENT_NECESSARY: boolean; @ApiProperty() - FEATURE_IMSCC_COURSE_EXPORT_ENABLED: boolean; + FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED: boolean; @ApiProperty() FEATURE_SCHOOL_SANIS_USER_MIGRATION_ENABLED: boolean; @@ -202,7 +202,7 @@ export class ConfigResponse { this.FEATURE_USER_MIGRATION_ENABLED = config.userMigrationEnabled; this.FEATURE_COPY_SERVICE_ENABLED = config.FEATURE_COPY_SERVICE_ENABLED; this.FEATURE_CONSENT_NECESSARY = config.FEATURE_CONSENT_NECESSARY; - this.FEATURE_IMSCC_COURSE_EXPORT_ENABLED = config.FEATURE_IMSCC_COURSE_EXPORT_ENABLED; + this.FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED = config.FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED; this.FEATURE_SCHOOL_SANIS_USER_MIGRATION_ENABLED = config.FEATURE_SCHOOL_SANIS_USER_MIGRATION_ENABLED; this.FEATURE_ALLOW_INSECURE_LDAP_URL_ENABLED = config.FEATURE_ALLOW_INSECURE_LDAP_URL_ENABLED; this.FEATURE_NEST_SYSTEMS_API_ENABLED = config.FEATURE_NEST_SYSTEMS_API_ENABLED; diff --git a/apps/server/src/modules/server/api/test/server.api.spec.ts b/apps/server/src/modules/server/api/test/server.api.spec.ts index 8a76afb0821..ba6bf7c5d29 100644 --- a/apps/server/src/modules/server/api/test/server.api.spec.ts +++ b/apps/server/src/modules/server/api/test/server.api.spec.ts @@ -1,6 +1,6 @@ +import { ServerTestModule } from '@modules/server'; import { HttpStatus, INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { ServerTestModule } from '@modules/server'; import { TestApiClient } from '@shared/testing'; import { ConfigResponse } from '../dto'; @@ -53,7 +53,7 @@ describe('Server Controller (API)', () => { 'FEATURE_ENABLE_LDAP_SYNC_DURING_MIGRATION', 'FEATURE_ES_COLLECTIONS_ENABLED', 'FEATURE_EXTENSIONS_ENABLED', - 'FEATURE_IMSCC_COURSE_EXPORT_ENABLED', + 'FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED', 'FEATURE_LERNSTORE_ENABLED', 'FEATURE_LESSON_SHARE', 'FEATURE_LOGIN_LINK_ENABLED', diff --git a/apps/server/src/modules/server/server.config.ts b/apps/server/src/modules/server/server.config.ts index e022a827c1e..7c133156065 100644 --- a/apps/server/src/modules/server/server.config.ts +++ b/apps/server/src/modules/server/server.config.ts @@ -5,7 +5,7 @@ import type { AccountConfig } from '@modules/account'; import type { AuthenticationConfig, XApiKeyConfig } from '@modules/authentication'; import type { BoardConfig } from '@modules/board'; import type { FilesStorageClientConfig } from '@modules/files-storage-client'; -import type { CommonCartridgeConfig, LearnroomConfig } from '@modules/learnroom'; +import type { LearnroomConfig } from '@modules/learnroom'; import type { LessonConfig } from '@modules/lesson'; import type { SchoolConfig } from '@modules/school'; import type { SharingConfig } from '@modules/sharing'; @@ -34,7 +34,6 @@ export interface ServerConfig FilesStorageClientConfig, AccountConfig, IdentityManagementConfig, - CommonCartridgeConfig, SchoolConfig, MailConfig, XApiKeyConfig, From 2caf5eebe4153d214816a50eae6024009e6beec5 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 29 Feb 2024 15:03:57 +0100 Subject: [PATCH 162/177] EW-539 Working on review comments and add empty line to tests --- .../export/builders/common-cartridge-file-builder.spec.ts | 4 ++++ .../builders/common-cartridge-organization-builder.spec.ts | 1 + .../elements/v1.1.0/common-cartridge-element-factory.spec.ts | 5 +++++ .../v1.1.0/common-cartridge-metadata-element.spec.ts | 3 ++- .../v1.1.0/common-cartridge-organization-element.spec.ts | 2 ++ .../common-cartridge-organizations-wrapper-element.spec.ts | 2 ++ .../common-cartridge-resources-wrapper-element.spec.ts | 2 ++ .../elements/v1.3.0/common-cartridge-element-factory.spec.ts | 4 ++++ .../v1.3.0/common-cartridge-metadata-element.spec.ts | 2 ++ .../v1.3.0/common-cartridge-organization-element.spec.ts | 2 ++ .../common-cartridge-organizations-wrapper-element.spec.ts | 2 ++ .../common-cartridge-resources-wrapper-element.spec.ts | 2 ++ .../resources/common-cartridge-resource-factory.spec.ts | 2 ++ .../v1.1.0/common-cartridge-manifest-resource.spec.ts | 4 ++++ .../v1.1.0/common-cartridge-resource-factory.spec.ts | 3 +++ .../v1.1.0/common-cartridge-web-content-resource.spec.ts | 5 +++++ .../v1.1.0/common-cartridge-web-link-resource.spec.ts | 5 +++++ .../v1.3.0/common-cartridge-manifest-resource.spec.ts | 4 ++++ .../v1.3.0/common-cartridge-resource-factory.spec.ts | 3 +++ .../v1.3.0/common-cartridge-web-content-resource.spec.ts | 5 +++++ .../v1.3.0/common-cartridge-web-link-resource.spec.ts | 5 +++++ .../server/src/modules/common-cartridge/export/utils.spec.ts | 2 ++ 22 files changed, 68 insertions(+), 1 deletion(-) diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts index f232ca08fd7..5c5db130cf5 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts @@ -56,6 +56,7 @@ describe('CommonCartridgeFileBuilder', () => { it('should have a imsmanifest.xml in archive root', async () => { const { archive } = await setup(); + const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); expect(manifest).toBeDefined(); @@ -63,6 +64,7 @@ describe('CommonCartridgeFileBuilder', () => { it('should have included the resource in organization folder', async () => { const { archive, organizationOptions, resourceProps } = await setup(); + const resource = getFileContentAsString( archive, `${organizationOptions.identifier}/${resourceProps.identifier}.html` @@ -73,6 +75,7 @@ describe('CommonCartridgeFileBuilder', () => { it('should have included the resource in sub-organization folder', async () => { const { archive, organizationOptions, resourceProps } = await setup(); + const resource = getFileContentAsString( archive, `${organizationOptions.identifier}/${organizationOptions.identifier}/${resourceProps.identifier}.html` @@ -83,6 +86,7 @@ describe('CommonCartridgeFileBuilder', () => { it('should have included the resource in sub-sub-organization folder', async () => { const { archive, organizationOptions, resourceProps } = await setup(); + const resource = getFileContentAsString( archive, `${organizationOptions.identifier}/${organizationOptions.identifier}/${organizationOptions.identifier}/${resourceProps.identifier}.html` diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts index fe7f554fe5f..879f16c84e3 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts @@ -46,6 +46,7 @@ describe('CommonCartridgeOrganizationBuilder', () => { it('should return a common cartridge element', () => { const { sut } = setup(); + const element = sut.build(); expect(element).toBeInstanceOf(CommonCartridgeElement); diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts index ad7fc17a723..11a127b9660 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts @@ -17,6 +17,7 @@ describe('CommonCartridgeElementFactoryV110', () => { describe('when creating elements from props', () => { it('should return metadata element', () => { const props = createCommonCartridgeMetadataElementPropsV110(); + const result = CommonCartridgeElementFactoryV110.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV110); @@ -24,6 +25,7 @@ describe('CommonCartridgeElementFactoryV110', () => { it('should return organization element', () => { const props = createCommonCartridgeOrganizationElementPropsV110(); + const result = CommonCartridgeElementFactoryV110.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeOrganizationElementV110); @@ -31,6 +33,7 @@ describe('CommonCartridgeElementFactoryV110', () => { it('should return organization wrapper element', () => { const props = createCommonCartridgeOrganizationsWrapperElementPropsV110(); + const result = CommonCartridgeElementFactoryV110.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeOrganizationsWrapperElementV110); @@ -38,6 +41,7 @@ describe('CommonCartridgeElementFactoryV110', () => { it('should return resources wrapper element', () => { const props = createCommonCartridgeResourcesWrapperElementPropsV110(); + const result = CommonCartridgeElementFactoryV110.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeResourcesWrapperElementV110); @@ -46,6 +50,7 @@ describe('CommonCartridgeElementFactoryV110', () => { describe('when element type is not supported', () => { const notSupportedProps = createCommonCartridgeMetadataElementPropsV110(); + notSupportedProps.type = 'not-supported' as CommonCartridgeElementType.METADATA; it('should throw error', () => { diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts index 844243d1c1f..e5d7e579e07 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts @@ -13,9 +13,9 @@ describe('CommonCartridgeMetadataElementV110', () => { return { sut, props }; }; - // AI next 5 lines it('should return correct version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_1_0); @@ -43,6 +43,7 @@ describe('CommonCartridgeMetadataElementV110', () => { it('should return correct manifest xml object', () => { const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts index bcf8c8bc788..4d962de585c 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts @@ -18,6 +18,7 @@ describe('CommonCartridgeOrganizationElementV110', () => { it('should return correct version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_1_0); @@ -61,6 +62,7 @@ describe('CommonCartridgeOrganizationElementV110', () => { it('should return correct manifest xml object', () => { const { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps } = setup(); + const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts index 88513e4c003..9e561c83a9d 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -19,6 +19,7 @@ describe('CommonCartridgeOrganizationsWrapperElementV110', () => { it('should return correct version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_1_0); @@ -51,6 +52,7 @@ describe('CommonCartridgeOrganizationsWrapperElementV110', () => { it('should return correct manifest xml object', () => { const { sut, organizationProps } = setup(); + const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts index 5f255d9bfa1..92257ad6de4 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts @@ -17,6 +17,7 @@ describe('CommonCartridgeResourcesWrapperElementV110', () => { it('should return correct version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_1_0); @@ -49,6 +50,7 @@ describe('CommonCartridgeResourcesWrapperElementV110', () => { it('should return correct manifest xml object', () => { const { sut, resourceProps } = setup(); + const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts index d55c36d2a17..fdecaf32e81 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts @@ -17,6 +17,7 @@ describe('CommonCartridgeElementFactoryV130', () => { describe('when creating elements from props', () => { it('should return metadata element', () => { const props = createCommonCartridgeMetadataElementPropsV130(); + const result = CommonCartridgeElementFactoryV130.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeMetadataElementV130); @@ -24,6 +25,7 @@ describe('CommonCartridgeElementFactoryV130', () => { it('should return organization element', () => { const props = createCommonCartridgeOrganizationElementPropsV130(); + const result = CommonCartridgeElementFactoryV130.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeOrganizationElementV130); @@ -31,6 +33,7 @@ describe('CommonCartridgeElementFactoryV130', () => { it('should return organization wrapper element', () => { const props = createCommonCartridgeOrganizationsWrapperElementPropsV130(); + const result = CommonCartridgeElementFactoryV130.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeOrganizationsWrapperElementV130); @@ -38,6 +41,7 @@ describe('CommonCartridgeElementFactoryV130', () => { it('should return resources wrapper element', () => { const props = createCommonCartridgeResourcesWrapperElementPropsV130(); + const result = CommonCartridgeElementFactoryV130.createElement(props); expect(result).toBeInstanceOf(CommonCartridgeResourcesWrapperElementV130); diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts index 8c432a595f1..aba11a59a72 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts @@ -15,6 +15,7 @@ describe('CommonCartridgeMetadataElementV130', () => { it('should return correct version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_3_0); @@ -42,6 +43,7 @@ describe('CommonCartridgeMetadataElementV130', () => { it('should return correct manifest xml object', () => { const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts index 586e28fffb5..70e0c2895d4 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts @@ -18,6 +18,7 @@ describe('CommonCartridgeOrganizationElementV130', () => { it('should return correct version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_3_0); @@ -61,6 +62,7 @@ describe('CommonCartridgeOrganizationElementV130', () => { it('should return correct manifest xml object', () => { const { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps } = setup(); + const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts index bfd25d00f49..de264a74b94 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -19,6 +19,7 @@ describe('CommonCartridgeOrganizationsWrapperElementV130', () => { it('should return correct version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_3_0); @@ -51,6 +52,7 @@ describe('CommonCartridgeOrganizationsWrapperElementV130', () => { it('should return correct manifest xml object', () => { const { sut, organizationProps } = setup(); + const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts index 6abadf35f71..9872bcede59 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts @@ -17,6 +17,7 @@ describe('CommonCartridgeResourcesWrapperElementV130', () => { it('should return correct version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_3_0); @@ -49,6 +50,7 @@ describe('CommonCartridgeResourcesWrapperElementV130', () => { it('should return correct manifest xml object', () => { const { sut, weblinkResourceProps } = setup(); + const result = sut.getManifestXmlObject(); expect(result).toStrictEqual({ diff --git a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts index 4b46a49b49e..8701f823c03 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts @@ -16,6 +16,7 @@ describe('CommonCartridgeResourceVersion', () => { describe('when Common Cartridge version is supported', () => { it('should return v1.1.0 resource', () => { const props = createCommonCartridgeWebContentResourcePropsV110(); + const result = CommonCartridgeResourceFactory.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV110); @@ -23,6 +24,7 @@ describe('CommonCartridgeResourceVersion', () => { it('should return v1.3.0 resource', () => { const props = createCommonCartridgeWebContentResourcePropsV130(); + const result = CommonCartridgeResourceFactory.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV130); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index 0f1a510ace6..a1cce719784 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -23,6 +23,7 @@ describe('CommonCartridgeManifestResourceV110', () => { it('should return false', () => { const { sut } = setup(); + const result = sut.canInline(); expect(result).toBe(false); @@ -41,6 +42,7 @@ describe('CommonCartridgeManifestResourceV110', () => { it('should return constructed file path', () => { const { sut } = setup(); + const result = sut.getFilePath(); expect(result).toBe('imsmanifest.xml'); @@ -103,6 +105,7 @@ describe('CommonCartridgeManifestResourceV110', () => { it('should return constructed file content', async () => { const { sut } = setup(); + const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml', 'utf-8'); const result = sut.getFileContent(); @@ -122,6 +125,7 @@ describe('CommonCartridgeManifestResourceV110', () => { it('should return supported version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_1_0); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts index 7381ef086d9..84169eb2e01 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts @@ -17,6 +17,7 @@ describe('CommonCartridgeResourceFactoryV110', () => { describe('when creating resources from props', () => { it('should return manifest resource', () => { const props = createCommonCartridgeManifestResourcePropsV110(); + const result = CommonCartridgeResourceFactoryV110.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeManifestResourceV110); @@ -24,6 +25,7 @@ describe('CommonCartridgeResourceFactoryV110', () => { it('should return web content resource', () => { const props = createCommonCartridgeWebContentResourcePropsV110(); + const result = CommonCartridgeResourceFactoryV110.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV110); @@ -31,6 +33,7 @@ describe('CommonCartridgeResourceFactoryV110', () => { it('should return web link resource', () => { const props = createCommonCartridgeWeblinkResourcePropsV110(); + const result = CommonCartridgeResourceFactoryV110.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeWebLinkResourceV110); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts index 65d7fcd2e93..2124aa81b68 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts @@ -15,6 +15,7 @@ describe('CommonCartridgeWebContentResourceV110', () => { it('should return false', () => { const { sut } = setup(); + const result = sut.canInline(); expect(result).toBe(false); @@ -33,6 +34,7 @@ describe('CommonCartridgeWebContentResourceV110', () => { it('should return the constructed file path', () => { const { sut, props } = setup(); + const result = sut.getFilePath(); expect(result).toBe(`${props.folder}/${props.identifier}.html`); @@ -51,6 +53,7 @@ describe('CommonCartridgeWebContentResourceV110', () => { it('should return the HTML', () => { const { sut, props } = setup(); + const result = sut.getFileContent(); expect(result).toBe(props.html); @@ -69,6 +72,7 @@ describe('CommonCartridgeWebContentResourceV110', () => { it('should return Common Cartridge version 1.1.0', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_1_0); @@ -98,6 +102,7 @@ describe('CommonCartridgeWebContentResourceV110', () => { it('should return the correct XML object', () => { const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); expect(result).toEqual({ diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts index 51db7626c36..883b4d6ba05 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -16,6 +16,7 @@ describe('CommonCartridgeWebLinkResourceV110', () => { it('should return false', () => { const { sut } = setup(); + const result = sut.canInline(); expect(result).toBe(false); @@ -34,6 +35,7 @@ describe('CommonCartridgeWebLinkResourceV110', () => { it('should return the constructed file path', () => { const { sut, props } = setup(); + const result = sut.getFilePath(); expect(result).toBe(`${props.folder}/${props.identifier}.xml`); @@ -56,6 +58,7 @@ describe('CommonCartridgeWebLinkResourceV110', () => { }; it('should contain correct XML', async () => { const { sut } = setup(); + const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml', 'utf8'); const result = sut.getFileContent(); @@ -75,6 +78,7 @@ describe('CommonCartridgeWebLinkResourceV110', () => { it('should return the supported version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_1_0); @@ -102,6 +106,7 @@ describe('CommonCartridgeWebLinkResourceV110', () => { it('should return the manifest XML object', () => { const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); expect(result).toEqual({ diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index 8978c2bcfb3..5fca0fba70e 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -24,6 +24,7 @@ describe('CommonCartridgeManifestResourceV130', () => { it('should return false', () => { const { sut } = setup(); + const result = sut.canInline(); expect(result).toBe(false); @@ -42,6 +43,7 @@ describe('CommonCartridgeManifestResourceV130', () => { it('should return constructed file path', () => { const { sut } = setup(); + const result = sut.getFilePath(); expect(result).toBe('imsmanifest.xml'); @@ -104,6 +106,7 @@ describe('CommonCartridgeManifestResourceV130', () => { it('should return constructed file content', async () => { const { sut } = setup(); + const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml', 'utf-8'); const result = sut.getFileContent(); @@ -123,6 +126,7 @@ describe('CommonCartridgeManifestResourceV130', () => { it('should return supported version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_3_0); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts index f9e928326f4..ae5db697da0 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts @@ -17,6 +17,7 @@ describe('CommonCartridgeResourceFactoryV130', () => { describe('when creating resources from props', () => { it('should return manifest resource', () => { const props = createCommonCartridgeManifestResourcePropsV130(); + const result = CommonCartridgeResourceFactoryV130.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeManifestResourceV130); @@ -24,6 +25,7 @@ describe('CommonCartridgeResourceFactoryV130', () => { it('should return web content resource', () => { const props = createCommonCartridgeWebContentResourcePropsV130(); + const result = CommonCartridgeResourceFactoryV130.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeWebContentResourceV130); @@ -31,6 +33,7 @@ describe('CommonCartridgeResourceFactoryV130', () => { it('should return web link resource', () => { const props = createCommonCartridgeWeblinkResourcePropsV130(); + const result = CommonCartridgeResourceFactoryV130.createResource(props); expect(result).toBeInstanceOf(CommonCartridgeWebLinkResourceV130); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts index ee3cc4ac306..fa13c92c064 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts @@ -15,6 +15,7 @@ describe('CommonCartridgeWebContentResourceV130', () => { it('should return false', () => { const { sut } = setup(); + const result = sut.canInline(); expect(result).toBe(false); @@ -33,6 +34,7 @@ describe('CommonCartridgeWebContentResourceV130', () => { it('should return the constructed file path', () => { const { sut, props } = setup(); + const result = sut.getFilePath(); expect(result).toBe(`${props.folder}/${props.identifier}.html`); @@ -51,6 +53,7 @@ describe('CommonCartridgeWebContentResourceV130', () => { it('should return the HTML', () => { const { sut, props } = setup(); + const result = sut.getFileContent(); expect(result).toBe(props.html); @@ -69,6 +72,7 @@ describe('CommonCartridgeWebContentResourceV130', () => { it('should return the supported version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_3_0); @@ -98,6 +102,7 @@ describe('CommonCartridgeWebContentResourceV130', () => { it('should return the manifest XML object', () => { const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); expect(result).toEqual({ diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts index cddfd11af90..7e8d1f2a3d5 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts @@ -16,6 +16,7 @@ describe('CommonCartridgeWebLinkResourceV130', () => { it('should return false', () => { const { sut } = setup(); + const result = sut.canInline(); expect(result).toBe(false); @@ -34,6 +35,7 @@ describe('CommonCartridgeWebLinkResourceV130', () => { it('should return the constructed file path', () => { const { sut, props } = setup(); + const result = sut.getFilePath(); expect(result).toBe(`${props.folder}/${props.identifier}.xml`); @@ -57,6 +59,7 @@ describe('CommonCartridgeWebLinkResourceV130', () => { it('should contain correct XML', async () => { const { sut } = setup(); + const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml', 'utf8'); const result = sut.getFileContent(); @@ -76,6 +79,7 @@ describe('CommonCartridgeWebLinkResourceV130', () => { it('should return the supported version', () => { const { sut } = setup(); + const result = sut.getSupportedVersion(); expect(result).toBe(CommonCartridgeVersion.V_1_3_0); @@ -103,6 +107,7 @@ describe('CommonCartridgeWebLinkResourceV130', () => { it('should return the manifest XML object', () => { const { sut, props } = setup(); + const result = sut.getManifestXmlObject(); expect(result).toEqual({ diff --git a/apps/server/src/modules/common-cartridge/export/utils.spec.ts b/apps/server/src/modules/common-cartridge/export/utils.spec.ts index 380cfb29e8f..5b3ef9d0b02 100644 --- a/apps/server/src/modules/common-cartridge/export/utils.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/utils.spec.ts @@ -48,6 +48,7 @@ describe('CommonCartridgeUtils', () => { describe('when creating error', () => { it('should return error with message', () => { const resourceType = 'unsupported'; + const error = createResourceTypeNotSupportedError(resourceType); expect(error).toBeInstanceOf(InternalServerErrorException); @@ -60,6 +61,7 @@ describe('CommonCartridgeUtils', () => { describe('when creating error', () => { it('should return error with message', () => { const elementType = 'unsupported'; + const error = createElementTypeNotSupportedError(elementType); expect(error).toBeInstanceOf(InternalServerErrorException); From 4c5f90c658f223d477cc6632dd7cdd75bdb013ce Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 1 Mar 2024 10:38:24 +0100 Subject: [PATCH 163/177] EW-539 Add index.ts for import and export and adjust imports --- .../modules/common-cartridge/export/index.ts | 13 ------------- .../modules/common-cartridge/import/index.ts | 1 - .../src/modules/common-cartridge/index.ts | 17 +++++++++++++++++ .../controller/dto/course.query.params.ts | 2 +- .../mapper/common-cartridge.mapper.spec.ts | 12 ++++++------ .../learnroom/mapper/common-cartridge.mapper.ts | 10 +++++----- .../common-cartridge-export.service.spec.ts | 2 +- .../service/common-cartridge-export.service.ts | 10 +++++----- .../service/common-cartridge-import.service.ts | 2 +- .../learnroom/uc/course-export.uc.spec.ts | 2 +- .../modules/learnroom/uc/course-export.uc.ts | 2 +- .../common-cartridge-element-props.factory.ts | 2 +- .../common-cartridge-resource-props.factory.ts | 2 +- 13 files changed, 40 insertions(+), 37 deletions(-) delete mode 100644 apps/server/src/modules/common-cartridge/export/index.ts delete mode 100644 apps/server/src/modules/common-cartridge/import/index.ts create mode 100644 apps/server/src/modules/common-cartridge/index.ts diff --git a/apps/server/src/modules/common-cartridge/export/index.ts b/apps/server/src/modules/common-cartridge/export/index.ts deleted file mode 100644 index 5fbe1ca839f..00000000000 --- a/apps/server/src/modules/common-cartridge/export/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -export { CommonCartridgeFileBuilder, CommonCartridgeFileBuilderProps } from './builders/common-cartridge-file-builder'; -export { - CommonCartridgeOrganizationBuilder, - CommonCartridgeOrganizationBuilderOptions, -} from './builders/common-cartridge-organization-builder'; -export { - CommonCartridgeElementType, - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from './common-cartridge.enums'; -export { CommonCartridgeElementProps } from './elements/common-cartridge-element-factory'; -export { CommonCartridgeResourceProps } from './resources/common-cartridge-resource-factory'; diff --git a/apps/server/src/modules/common-cartridge/import/index.ts b/apps/server/src/modules/common-cartridge/import/index.ts deleted file mode 100644 index 0f41a5e0581..00000000000 --- a/apps/server/src/modules/common-cartridge/import/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { CommonCartridgeFileParser } from './common-cartridge-file-parser'; diff --git a/apps/server/src/modules/common-cartridge/index.ts b/apps/server/src/modules/common-cartridge/index.ts new file mode 100644 index 00000000000..1fff35de5ce --- /dev/null +++ b/apps/server/src/modules/common-cartridge/index.ts @@ -0,0 +1,17 @@ +export { + CommonCartridgeFileBuilder, + CommonCartridgeFileBuilderProps, +} from './export/builders/common-cartridge-file-builder'; +export { + CommonCartridgeOrganizationBuilder, + CommonCartridgeOrganizationBuilderOptions, +} from './export/builders/common-cartridge-organization-builder'; +export { + CommonCartridgeElementType, + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from './export/common-cartridge.enums'; +export { CommonCartridgeElementProps } from './export/elements/common-cartridge-element-factory'; +export { CommonCartridgeResourceProps } from './export/resources/common-cartridge-resource-factory'; +export { CommonCartridgeFileParser } from './import/common-cartridge-file-parser'; diff --git a/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts b/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts index 616345bb075..3f285dbe354 100644 --- a/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts +++ b/apps/server/src/modules/learnroom/controller/dto/course.query.params.ts @@ -1,5 +1,5 @@ +import { CommonCartridgeVersion } from '@modules/common-cartridge'; import { ApiProperty } from '@nestjs/swagger'; -import { CommonCartridgeVersion } from '@src/modules/common-cartridge/export'; import { IsString, Matches } from 'class-validator'; export class CourseQueryParams { diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index 9b10bac4e32..1ee027c6008 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -1,10 +1,5 @@ import { faker } from '@faker-js/faker'; import { DeepMocked, createMock } from '@golevelup/ts-jest'; -import { ConfigService } from '@nestjs/config'; -import { Test, TestingModule } from '@nestjs/testing'; -import { ComponentProperties, ComponentType } from '@shared/domain/entity'; -import { courseFactory, lessonFactory, setupEntities, taskFactory, userFactory } from '@shared/testing'; -import { OmitVersion, createIdentifier } from '@src/modules/common-cartridge/export/utils'; import { CommonCartridgeElementProps, CommonCartridgeElementType, @@ -14,7 +9,12 @@ import { CommonCartridgeResourceProps, CommonCartridgeResourceType, CommonCartridgeVersion, -} from '../../common-cartridge/export'; +} from '@modules/common-cartridge'; +import { ConfigService } from '@nestjs/config'; +import { Test, TestingModule } from '@nestjs/testing'; +import { ComponentProperties, ComponentType } from '@shared/domain/entity'; +import { courseFactory, lessonFactory, setupEntities, taskFactory, userFactory } from '@shared/testing'; +import { OmitVersion, createIdentifier } from '@src/modules/common-cartridge/export/utils'; import { LearnroomConfig } from '../learnroom.config'; import { CommonCartridgeMapper } from './common-cartridge.mapper'; diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index d06f4274add..5078d51d60f 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -1,7 +1,3 @@ -import { Injectable } from '@nestjs/common'; -import { ConfigService } from '@nestjs/config'; -import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain/entity'; -import { createIdentifier } from '@src/modules/common-cartridge/export/utils'; import { CommonCartridgeElementProps, CommonCartridgeElementType, @@ -11,7 +7,11 @@ import { CommonCartridgeResourceProps, CommonCartridgeResourceType, CommonCartridgeVersion, -} from '../../common-cartridge/export'; +} from '@modules/common-cartridge'; +import { Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain/entity'; +import { createIdentifier } from '@src/modules/common-cartridge/export/utils'; import { LearnroomConfig } from '../learnroom.config'; @Injectable() diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index a5d4fb00bca..b8c057459df 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -1,5 +1,6 @@ import { faker } from '@faker-js/faker'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; +import { CommonCartridgeVersion } from '@modules/common-cartridge'; import { CommonCartridgeExportService, CourseService, LearnroomConfig } from '@modules/learnroom'; import { LessonService } from '@modules/lesson'; import { TaskService } from '@modules/task'; @@ -8,7 +9,6 @@ import { Test, TestingModule } from '@nestjs/testing'; import { ComponentType } from '@shared/domain/entity'; import { courseFactory, lessonFactory, setupEntities, taskFactory } from '@shared/testing'; import AdmZip from 'adm-zip'; -import { CommonCartridgeVersion } from '../../common-cartridge/export'; import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; describe('CommonCartridgeExportService', () => { diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index a5d9aaa2ca8..3371e8285ad 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -1,14 +1,14 @@ +import { + CommonCartridgeFileBuilder, + CommonCartridgeOrganizationBuilder, + CommonCartridgeVersion, +} from '@modules/common-cartridge'; import { LessonService } from '@modules/lesson'; import { TaskService } from '@modules/task'; import { Injectable } from '@nestjs/common'; import { ComponentProperties } from '@shared/domain/entity'; import { EntityId } from '@shared/domain/types'; import { createIdentifier } from '@src/modules/common-cartridge/export/utils'; -import { - CommonCartridgeFileBuilder, - CommonCartridgeOrganizationBuilder, - CommonCartridgeVersion, -} from '../../common-cartridge/export'; import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; import { CourseService } from './course.service'; diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-import.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-import.service.ts index ec822130b15..f746be3ad2c 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-import.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-import.service.ts @@ -1,6 +1,6 @@ +import { CommonCartridgeFileParser } from '@modules/common-cartridge'; import { Injectable } from '@nestjs/common'; import { Course, User } from '@shared/domain/entity'; -import { CommonCartridgeFileParser } from '@src/modules/common-cartridge/import'; @Injectable() export class CommonCartridgeImportService { diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts index fda2d73c9e6..101298cd96f 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.spec.ts @@ -1,8 +1,8 @@ import { DeepMocked, createMock } from '@golevelup/ts-jest'; +import { CommonCartridgeVersion } from '@modules/common-cartridge'; import { ForbiddenException, NotFoundException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; -import { CommonCartridgeVersion } from '@src/modules/common-cartridge/export'; import { ObjectId } from 'bson'; import { AuthorizationReferenceService } from '../../authorization/domain'; import { LearnroomConfig } from '../learnroom.config'; diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.ts index 78208277edc..0586569463c 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.ts @@ -1,10 +1,10 @@ import { AuthorizationContextBuilder } from '@modules/authorization'; import { AuthorizableReferenceType, AuthorizationReferenceService } from '@modules/authorization/domain'; +import { CommonCartridgeVersion } from '@modules/common-cartridge'; import { Injectable, NotFoundException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { Permission } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; -import { CommonCartridgeVersion } from '@src/modules/common-cartridge/export'; import { LearnroomConfig } from '../learnroom.config'; import { CommonCartridgeExportService } from '../service/common-cartridge-export.service'; diff --git a/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts b/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts index de8655fce9a..5f16373a1ca 100644 --- a/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts +++ b/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts @@ -1,5 +1,5 @@ import { faker } from '@faker-js/faker'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '@src/modules/common-cartridge/export'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '@modules/common-cartridge'; import { CommonCartridgeMetadataElementPropsV110 } from '@src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element'; import { CommonCartridgeOrganizationElementPropsV110 } from '@src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element'; import { CommonCartridgeOrganizationsWrapperElementPropsV110 } from '@src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element'; diff --git a/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts b/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts index 1b693c51021..22dfc6829c7 100644 --- a/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts +++ b/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts @@ -3,7 +3,7 @@ import { CommonCartridgeIntendedUseType, CommonCartridgeResourceType, CommonCartridgeVersion, -} from '@src/modules/common-cartridge/export'; +} from '@modules/common-cartridge'; import { CommonCartridgeElement } from '@src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface'; import { CommonCartridgeManifestResourcePropsV110 } from '@src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource'; import { CommonCartridgeWebContentResourcePropsV110 } from '@src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource'; From 9f4fe2df89481552e4652668f087172321cd9af0 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 1 Mar 2024 13:53:59 +0100 Subject: [PATCH 164/177] EW-539 Working on review comments and moving test factories and assets to their own folder in the cc module --- .../common-cartridge-element-factory.spec.ts | 2 +- .../common-cartridge-element-factory.spec.ts | 2 +- .../common-cartridge-metadata-element.spec.ts | 2 +- ...mon-cartridge-organization-element.spec.ts | 4 ++-- ...idge-organizations-wrapper-element.spec.ts | 2 +- ...artridge-resources-wrapper-element.spec.ts | 4 ++-- .../common-cartridge-element-factory.spec.ts | 2 +- .../common-cartridge-metadata-element.spec.ts | 2 +- ...mon-cartridge-organization-element.spec.ts | 4 ++-- ...idge-organizations-wrapper-element.spec.ts | 2 +- ...artridge-resources-wrapper-element.spec.ts | 4 ++-- .../common-cartridge-resource-factory.spec.ts | 2 +- ...common-cartridge-manifest-resource.spec.ts | 7 ++++-- .../common-cartridge-resource-factory.spec.ts | 2 +- ...mon-cartridge-web-content-resource.spec.ts | 2 +- ...common-cartridge-web-link-resource.spec.ts | 7 ++++-- ...common-cartridge-manifest-resource.spec.ts | 7 ++++-- .../common-cartridge-resource-factory.spec.ts | 2 +- ...mon-cartridge-web-content-resource.spec.ts | 2 +- ...common-cartridge-web-link-resource.spec.ts | 7 ++++-- .../common-cartridge-manifest-parser.spec.ts | 4 +++- .../assets}/us_history_since_1877.imscc | Bin .../testing/assets}/v1.1.0/manifest.xml | 0 .../testing/assets}/v1.1.0/weblink.xml | 0 .../testing/assets}/v1.3.0/manifest.xml | 0 .../testing/assets}/v1.3.0/weblink.xml | 0 .../common-cartridge-element-props.factory.ts | 20 +++++++++--------- ...common-cartridge-resource-props.factory.ts | 14 ++++++------ .../controller/api-test/course.api.spec.ts | 4 +++- .../common-cartridge-import.service.spec.ts | 4 +++- ...mmon-cartridge-file-validator.pipe.spec.ts | 4 +++- 31 files changed, 69 insertions(+), 49 deletions(-) rename apps/server/{test/assets/common-cartridge => src/modules/common-cartridge/testing/assets}/us_history_since_1877.imscc (100%) rename apps/server/{test/assets/common-cartridge => src/modules/common-cartridge/testing/assets}/v1.1.0/manifest.xml (100%) rename apps/server/{test/assets/common-cartridge => src/modules/common-cartridge/testing/assets}/v1.1.0/weblink.xml (100%) rename apps/server/{test/assets/common-cartridge => src/modules/common-cartridge/testing/assets}/v1.3.0/manifest.xml (100%) rename apps/server/{test/assets/common-cartridge => src/modules/common-cartridge/testing/assets}/v1.3.0/weblink.xml (100%) rename apps/server/src/{shared/testing/factory => modules/common-cartridge/testing}/common-cartridge-element-props.factory.ts (71%) rename apps/server/src/{shared/testing/factory => modules/common-cartridge/testing}/common-cartridge-resource-props.factory.ts (69%) diff --git a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts index a94eab27b9a..20f68a8d637 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts @@ -2,7 +2,7 @@ import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeMetadataElementPropsV110, createCommonCartridgeMetadataElementPropsV130, -} from '@shared/testing/factory/common-cartridge-element-props.factory'; +} from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElementFactory } from './common-cartridge-element-factory'; import { diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts index 11a127b9660..78ca2baac85 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts @@ -4,7 +4,7 @@ import { createCommonCartridgeOrganizationElementPropsV110, createCommonCartridgeOrganizationsWrapperElementPropsV110, createCommonCartridgeResourcesWrapperElementPropsV110, -} from '@shared/testing/factory/common-cartridge-element-props.factory'; +} from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactoryV110 } from './common-cartridge-element-factory'; import { CommonCartridgeMetadataElementV110 } from './common-cartridge-metadata-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts index e5d7e579e07..1f593895d70 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts @@ -1,5 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeMetadataElementPropsV110 } from '@shared/testing/factory/common-cartridge-element-props.factory'; +import { createCommonCartridgeMetadataElementPropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeMetadataElementV110 } from './common-cartridge-metadata-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts index 4d962de585c..0f5f2a19dd1 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeOrganizationElementPropsV110 } from '@shared/testing/factory/common-cartridge-element-props.factory'; -import { createCommonCartridgeWeblinkResourcePropsV110 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { createCommonCartridgeOrganizationElementPropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts index 9e561c83a9d..8b44269780f 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -2,7 +2,7 @@ import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeOrganizationElementPropsV110, createCommonCartridgeOrganizationsWrapperElementPropsV110, -} from '@shared/testing/factory/common-cartridge-element-props.factory'; +} from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; import { CommonCartridgeOrganizationsWrapperElementV110 } from './common-cartridge-organizations-wrapper-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts index 92257ad6de4..39e57dbf1ca 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeResourcesWrapperElementPropsV110 } from '@shared/testing/factory/common-cartridge-element-props.factory'; -import { createCommonCartridgeWeblinkResourcePropsV110 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { createCommonCartridgeResourcesWrapperElementPropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeResourcesWrapperElementV110 } from './common-cartridge-resources-wrapper-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts index fdecaf32e81..6adee261bfc 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts @@ -4,7 +4,7 @@ import { createCommonCartridgeOrganizationElementPropsV130, createCommonCartridgeOrganizationsWrapperElementPropsV130, createCommonCartridgeResourcesWrapperElementPropsV130, -} from '@shared/testing/factory/common-cartridge-element-props.factory'; +} from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactoryV130 } from './common-cartridge-element-factory'; import { CommonCartridgeMetadataElementV130 } from './common-cartridge-metadata-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts index aba11a59a72..8a12a2faeeb 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts @@ -1,5 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeMetadataElementPropsV130 } from '@shared/testing/factory/common-cartridge-element-props.factory'; +import { createCommonCartridgeMetadataElementPropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeMetadataElementV130 } from './common-cartridge-metadata-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts index 70e0c2895d4..b02ae6ab273 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeOrganizationElementPropsV130 } from '@shared/testing/factory/common-cartridge-element-props.factory'; -import { createCommonCartridgeWeblinkResourcePropsV130 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { createCommonCartridgeOrganizationElementPropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts index de264a74b94..d2f87ea7a5f 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -2,7 +2,7 @@ import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeOrganizationElementPropsV130, createCommonCartridgeOrganizationsWrapperElementPropsV130, -} from '@shared/testing/factory/common-cartridge-element-props.factory'; +} from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; import { CommonCartridgeOrganizationsWrapperElementV130 } from './common-cartridge-organizations-wrapper-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts index 9872bcede59..2fc21492113 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeResourcesWrapperElementPropsV130 } from '@shared/testing/factory/common-cartridge-element-props.factory'; -import { createCommonCartridgeWeblinkResourcePropsV130 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { createCommonCartridgeResourcesWrapperElementPropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeResourcesWrapperElementV130 } from './common-cartridge-resources-wrapper-element'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts index 8701f823c03..9a55cc0f0e5 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts @@ -2,7 +2,7 @@ import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeWebContentResourcePropsV110, createCommonCartridgeWebContentResourcePropsV130, -} from '@shared/testing/factory/common-cartridge-resource-props.factory'; +} from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from './common-cartridge-resource-factory'; import { diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index a1cce719784..493245e05d2 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -1,5 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeManifestResourcePropsV110 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { createCommonCartridgeManifestResourcePropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { readFile } from 'fs/promises'; import { CommonCartridgeElementType, @@ -106,7 +106,10 @@ describe('CommonCartridgeManifestResourceV110', () => { it('should return constructed file content', async () => { const { sut } = setup(); - const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml', 'utf-8'); + const expected = await readFile( + './apps/server/src/modules/common-cartridge/testing/assets/v1.1.0/manifest.xml', + 'utf-8' + ); const result = sut.getFileContent(); expect(result).toEqual(expected); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts index 84169eb2e01..8612aa96843 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts @@ -3,7 +3,7 @@ import { createCommonCartridgeManifestResourcePropsV110, createCommonCartridgeWebContentResourcePropsV110, createCommonCartridgeWeblinkResourcePropsV110, -} from '@shared/testing/factory/common-cartridge-resource-props.factory'; +} from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV110 } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResourceV110 } from './common-cartridge-web-content-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts index 2124aa81b68..b313f8ad387 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts @@ -1,5 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeWebContentResourcePropsV110 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { createCommonCartridgeWebContentResourcePropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeWebContentResourceV110 } from './common-cartridge-web-content-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts index 883b4d6ba05..281120e3608 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -1,5 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeWeblinkResourcePropsV110 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { readFile } from 'fs/promises'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeWebLinkResourceV110 } from './common-cartridge-web-link-resource'; @@ -59,7 +59,10 @@ describe('CommonCartridgeWebLinkResourceV110', () => { it('should contain correct XML', async () => { const { sut } = setup(); - const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml', 'utf8'); + const expected = await readFile( + './apps/server/src/modules/common-cartridge/testing/assets/v1.1.0/weblink.xml', + 'utf8' + ); const result = sut.getFileContent(); expect(result).toEqual(expected); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index 5fca0fba70e..b9db706903d 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -1,5 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeManifestResourcePropsV130 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { createCommonCartridgeManifestResourcePropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { readFile } from 'fs/promises'; import { CommonCartridgeElementType, @@ -107,7 +107,10 @@ describe('CommonCartridgeManifestResourceV130', () => { it('should return constructed file content', async () => { const { sut } = setup(); - const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml', 'utf-8'); + const expected = await readFile( + './apps/server/src/modules/common-cartridge/testing/assets/v1.3.0/manifest.xml', + 'utf-8' + ); const result = sut.getFileContent(); expect(result).toEqual(expected); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts index ae5db697da0..2a30d5a4a00 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts @@ -3,7 +3,7 @@ import { createCommonCartridgeManifestResourcePropsV130, createCommonCartridgeWebContentResourcePropsV130, createCommonCartridgeWeblinkResourcePropsV130, -} from '@shared/testing/factory/common-cartridge-resource-props.factory'; +} from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV130 } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts index fa13c92c064..f12a60975d0 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts @@ -1,5 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeWebContentResourcePropsV130 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { createCommonCartridgeWebContentResourcePropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts index 7e8d1f2a3d5..2cd33e7afec 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts @@ -1,5 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeWeblinkResourcePropsV130 } from '@shared/testing/factory/common-cartridge-resource-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { readFile } from 'node:fs/promises'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeWebLinkResourceV130 } from './common-cartridge-web-link-resource'; @@ -60,7 +60,10 @@ describe('CommonCartridgeWebLinkResourceV130', () => { it('should contain correct XML', async () => { const { sut } = setup(); - const expected = await readFile('./apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml', 'utf8'); + const expected = await readFile( + './apps/server/src/modules/common-cartridge/testing/assets/v1.3.0/weblink.xml', + 'utf8' + ); const result = sut.getFileContent(); expect(result).toEqual(expected); diff --git a/apps/server/src/modules/common-cartridge/import/common-cartridge-manifest-parser.spec.ts b/apps/server/src/modules/common-cartridge/import/common-cartridge-manifest-parser.spec.ts index a62a027eb1f..e469f4f36b0 100644 --- a/apps/server/src/modules/common-cartridge/import/common-cartridge-manifest-parser.spec.ts +++ b/apps/server/src/modules/common-cartridge/import/common-cartridge-manifest-parser.spec.ts @@ -10,7 +10,9 @@ describe('CommonCartridgeManifestParser', () => { return { sut }; } - const buffer = await readFile('./apps/server/test/assets/common-cartridge/us_history_since_1877.imscc'); + const buffer = await readFile( + './apps/server/src/modules/common-cartridge/testing/assets/us_history_since_1877.imscc' + ); const archive = new AdmZip(buffer); const sut = new CommonCartridgeManifestParser(archive.readAsText('imsmanifest.xml')); diff --git a/apps/server/test/assets/common-cartridge/us_history_since_1877.imscc b/apps/server/src/modules/common-cartridge/testing/assets/us_history_since_1877.imscc similarity index 100% rename from apps/server/test/assets/common-cartridge/us_history_since_1877.imscc rename to apps/server/src/modules/common-cartridge/testing/assets/us_history_since_1877.imscc diff --git a/apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml b/apps/server/src/modules/common-cartridge/testing/assets/v1.1.0/manifest.xml similarity index 100% rename from apps/server/test/assets/common-cartridge/v1.1.0/manifest.xml rename to apps/server/src/modules/common-cartridge/testing/assets/v1.1.0/manifest.xml diff --git a/apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml b/apps/server/src/modules/common-cartridge/testing/assets/v1.1.0/weblink.xml similarity index 100% rename from apps/server/test/assets/common-cartridge/v1.1.0/weblink.xml rename to apps/server/src/modules/common-cartridge/testing/assets/v1.1.0/weblink.xml diff --git a/apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml b/apps/server/src/modules/common-cartridge/testing/assets/v1.3.0/manifest.xml similarity index 100% rename from apps/server/test/assets/common-cartridge/v1.3.0/manifest.xml rename to apps/server/src/modules/common-cartridge/testing/assets/v1.3.0/manifest.xml diff --git a/apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml b/apps/server/src/modules/common-cartridge/testing/assets/v1.3.0/weblink.xml similarity index 100% rename from apps/server/test/assets/common-cartridge/v1.3.0/weblink.xml rename to apps/server/src/modules/common-cartridge/testing/assets/v1.3.0/weblink.xml diff --git a/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts b/apps/server/src/modules/common-cartridge/testing/common-cartridge-element-props.factory.ts similarity index 71% rename from apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts rename to apps/server/src/modules/common-cartridge/testing/common-cartridge-element-props.factory.ts index 5f16373a1ca..000ad586840 100644 --- a/apps/server/src/shared/testing/factory/common-cartridge-element-props.factory.ts +++ b/apps/server/src/modules/common-cartridge/testing/common-cartridge-element-props.factory.ts @@ -1,15 +1,15 @@ import { faker } from '@faker-js/faker'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '@modules/common-cartridge'; -import { CommonCartridgeMetadataElementPropsV110 } from '@src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element'; -import { CommonCartridgeOrganizationElementPropsV110 } from '@src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element'; -import { CommonCartridgeOrganizationsWrapperElementPropsV110 } from '@src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElementPropsV110 } from '@src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element'; -import { CommonCartridgeMetadataElementPropsV130 } from '@src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element'; -import { CommonCartridgeOrganizationElementPropsV130 } from '@src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element'; -import { CommonCartridgeOrganizationsWrapperElementPropsV130 } from '@src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElementPropsV130 } from '@src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element'; -import { CommonCartridgeElement } from '@src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '@src/modules/common-cartridge/export/interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeMetadataElementPropsV110 } from '../export/elements/v1.1.0/common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElementPropsV110 } from '../export/elements/v1.1.0/common-cartridge-organization-element'; +import { CommonCartridgeOrganizationsWrapperElementPropsV110 } from '../export/elements/v1.1.0/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementPropsV110 } from '../export/elements/v1.1.0/common-cartridge-resources-wrapper-element'; +import { CommonCartridgeMetadataElementPropsV130 } from '../export/elements/v1.3.0/common-cartridge-metadata-element'; +import { CommonCartridgeOrganizationElementPropsV130 } from '../export/elements/v1.3.0/common-cartridge-organization-element'; +import { CommonCartridgeOrganizationsWrapperElementPropsV130 } from '../export/elements/v1.3.0/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeResourcesWrapperElementPropsV130 } from '../export/elements/v1.3.0/common-cartridge-resources-wrapper-element'; +import { CommonCartridgeElement } from '../export/interfaces/common-cartridge-element.interface'; +import { CommonCartridgeResource } from '../export/interfaces/common-cartridge-resource.interface'; export function createCommonCartridgeMetadataElementPropsV110(): CommonCartridgeMetadataElementPropsV110 { return { diff --git a/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts b/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts similarity index 69% rename from apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts rename to apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts index 22dfc6829c7..cbe4f31f0c6 100644 --- a/apps/server/src/shared/testing/factory/common-cartridge-resource-props.factory.ts +++ b/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts @@ -4,13 +4,13 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion, } from '@modules/common-cartridge'; -import { CommonCartridgeElement } from '@src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface'; -import { CommonCartridgeManifestResourcePropsV110 } from '@src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource'; -import { CommonCartridgeWebContentResourcePropsV110 } from '@src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource'; -import { CommonCartridgeWebLinkResourcePropsV110 } from '@src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource'; -import { CommonCartridgeManifestResourcePropsV130 } from '@src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource'; -import { CommonCartridgeWebContentResourcePropsV130 } from '@src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource'; -import { CommonCartridgeWebLinkResourcePropsV130 } from '@src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource'; +import { CommonCartridgeElement } from '../export/interfaces/common-cartridge-element.interface'; +import { CommonCartridgeManifestResourcePropsV110 } from '../export/resources/v1.1.0/common-cartridge-manifest-resource'; +import { CommonCartridgeWebContentResourcePropsV110 } from '../export/resources/v1.1.0/common-cartridge-web-content-resource'; +import { CommonCartridgeWebLinkResourcePropsV110 } from '../export/resources/v1.1.0/common-cartridge-web-link-resource'; +import { CommonCartridgeManifestResourcePropsV130 } from '../export/resources/v1.3.0/common-cartridge-manifest-resource'; +import { CommonCartridgeWebContentResourcePropsV130 } from '../export/resources/v1.3.0/common-cartridge-web-content-resource'; +import { CommonCartridgeWebLinkResourcePropsV130 } from '../export/resources/v1.3.0/common-cartridge-web-link-resource'; export function createCommonCartridgeWeblinkResourcePropsV110(): CommonCartridgeWebLinkResourcePropsV110 { return { diff --git a/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts b/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts index 04c0528a907..caae44a64b3 100644 --- a/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts +++ b/apps/server/src/modules/learnroom/controller/api-test/course.api.spec.ts @@ -122,7 +122,9 @@ describe('Course Controller (API)', () => { describe('[POST] /courses/import', () => { const setup = async () => { const teacher = createTeacher(); - const course = await readFile('./apps/server/test/assets/common-cartridge/us_history_since_1877.imscc'); + const course = await readFile( + './apps/server/src/modules/common-cartridge/testing/assets/us_history_since_1877.imscc' + ); const courseFileName = 'us_history_since_1877.imscc'; await em.persistAndFlush([teacher.account, teacher.user]); diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-import.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-import.service.spec.ts index 303bb4340a5..655443d993c 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-import.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-import.service.spec.ts @@ -31,7 +31,9 @@ describe('CommonCartridgeImportService', () => { describe('when the common cartridge is valid', () => { const setup = async () => { const user = userFactory.buildWithId(); - const buffer = await readFile('./apps/server/test/assets/common-cartridge/us_history_since_1877.imscc'); + const buffer = await readFile( + './apps/server/src/modules/common-cartridge/testing/assets/us_history_since_1877.imscc' + ); return { user, buffer }; }; diff --git a/apps/server/src/modules/learnroom/utils/common-cartridge-file-validator.pipe.spec.ts b/apps/server/src/modules/learnroom/utils/common-cartridge-file-validator.pipe.spec.ts index 76466b78e49..94b9ba79bff 100644 --- a/apps/server/src/modules/learnroom/utils/common-cartridge-file-validator.pipe.spec.ts +++ b/apps/server/src/modules/learnroom/utils/common-cartridge-file-validator.pipe.spec.ts @@ -99,7 +99,9 @@ describe('CommonCartridgeFileValidatorPipe', () => { describe('when the file is valid', () => { const setup = async () => { - const buffer = await readFile('./apps/server/test/assets/common-cartridge/us_history_since_1877.imscc'); + const buffer = await readFile( + './apps/server/src/modules/common-cartridge/testing/assets/us_history_since_1877.imscc' + ); configServiceMock.getOrThrow.mockReturnValue(1000); From 5ead4686b526bb71fdaf7d826329bd7570f60ab0 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 6 Mar 2024 15:07:31 +0100 Subject: [PATCH 165/177] EW-539 Working on review comments. Deleting setting for xml files. --- .vscode/settings.default.json | 3 --- .../src/modules/common-cartridge/testing/assets/README.md | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/testing/assets/README.md diff --git a/.vscode/settings.default.json b/.vscode/settings.default.json index 5b30e60c2a3..7525444a021 100644 --- a/.vscode/settings.default.json +++ b/.vscode/settings.default.json @@ -13,9 +13,6 @@ "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" }, - "[xml]": { - "files.insertFinalNewline": false - }, "javascript.preferences.importModuleSpecifier": "relative", "jest.autoRun": { "watch": false, "onSave": "test-file" }, "coverage-gutters.showLineCoverage": true, diff --git a/apps/server/src/modules/common-cartridge/testing/assets/README.md b/apps/server/src/modules/common-cartridge/testing/assets/README.md new file mode 100644 index 00000000000..7500ae9bee3 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/testing/assets/README.md @@ -0,0 +1,7 @@ +# Important Note + +When working with the XML files in the assets folder in the `common-cartridge` module, please ensure that they are saved with LF (Line Feed) line endings instead of CRLF (Carriage Return + Line Feed). Additionally, make sure that no new line is inserted at the end of the XML files. + +This is important, as the XML files are used for comparison in tests and the Common Cartridge standard does not add a line at the end of the XML files. + +Thank you for your attention to this matter. From ea36e025cdb15416042a949c96a03755a6d700af Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 6 Mar 2024 15:10:19 +0100 Subject: [PATCH 166/177] EW-539 Working on review comments. Delete bind, rewrite code and adjust test --- .../builders/common-cartridge-file-builder.ts | 6 +- ...mon-cartridge-organization-builder.spec.ts | 56 +++++++++++++++---- .../common-cartridge-organization-builder.ts | 2 +- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts index fbab733a82b..a22fbe688d6 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts @@ -43,7 +43,7 @@ export class CommonCartridgeFileBuilder { ): CommonCartridgeOrganizationBuilder { const builder = new CommonCartridgeOrganizationBuilder( { ...props, version: this.props.version }, - this.addResource.bind(this) + (resource: CommonCartridgeResource) => this.resources.push(resource) ); this.organizationBuilders.push(builder); @@ -78,8 +78,4 @@ export class CommonCartridgeFileBuilder { return buffer; } - - private addResource(resource: CommonCartridgeResource): void { - this.resources.push(resource); - } } diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts index 879f16c84e3..852de560846 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts @@ -1,12 +1,8 @@ import { faker } from '@faker-js/faker/locale/af_ZA'; -import { - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../common-cartridge.enums'; +import { createCommonCartridgeWebContentResourcePropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; +import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; import { CommonCartridgeOrganizationBuilder, CommonCartridgeOrganizationBuilderOptions, @@ -14,20 +10,54 @@ import { describe('CommonCartridgeOrganizationBuilder', () => { describe('build', () => { - describe('when building a Common Cartridge organization', () => { + describe('when building a Common Cartridge organization with resources', () => { const setup = () => { const resources = new Array(); + const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { identifier: faker.string.uuid(), title: faker.lorem.words(), }; - const resourceProps: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, + + const resourceProps = createCommonCartridgeWebContentResourcePropsV110(); + + const sut = new CommonCartridgeOrganizationBuilder( + { + ...organizationOptions, + version: CommonCartridgeVersion.V_1_1_0, + }, + (resource) => resources.push(resource) + ) + .addResource(resourceProps) + .addSubOrganization(organizationOptions) + .addResource(resourceProps) + .addSubOrganization(organizationOptions) + .addResource(resourceProps); + + return { sut, resources }; + }; + + it('should return a common cartridge element', () => { + const { sut, resources } = setup(); + + const element = sut.build(); + + expect(element).toBeInstanceOf(CommonCartridgeElement); + expect(resources.length).toBe(3); + }); + }); + + describe('when building a Common Cartridge organization with items', () => { + const setup = () => { + const resources = new Array(); + + const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { identifier: faker.string.uuid(), title: faker.lorem.words(), - html: faker.lorem.paragraphs(), - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, }; + + const resourceProps = createCommonCartridgeWebContentResourcePropsV110(); + const sut = new CommonCartridgeOrganizationBuilder( { ...organizationOptions, @@ -39,17 +69,19 @@ describe('CommonCartridgeOrganizationBuilder', () => { .addSubOrganization(organizationOptions) .addResource(resourceProps) .addSubOrganization(organizationOptions) + .addResource(resourceProps) .addResource(resourceProps); return { sut, resources }; }; it('should return a common cartridge element', () => { - const { sut } = setup(); + const { sut, resources } = setup(); const element = sut.build(); expect(element).toBeInstanceOf(CommonCartridgeElement); + expect(resources.length).toBe(4); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts index f11c6cdeba9..e4c77a469dc 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts @@ -37,7 +37,7 @@ export class CommonCartridgeOrganizationBuilder { ): CommonCartridgeOrganizationBuilder { const subOrganization = new CommonCartridgeOrganizationBuilder( { ...options, version: this.options.version, folder: this.folder }, - this.addResourceToFileBuilder.bind(this) + (resource: CommonCartridgeResource) => this.addResourceToFileBuilder(resource) ); this.subOrganizations.push(subOrganization); From 6d70b50a0aa07fbe101a7ca144c8c5cbec1f318f Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 6 Mar 2024 15:11:24 +0100 Subject: [PATCH 167/177] EW-539 Working on review comments. Deleting never keyword --- .../export/elements/common-cartridge-element-factory.ts | 2 +- .../interfaces/common-cartridge-element.interface.ts | 8 +++----- .../export/resources/common-cartridge-resource-factory.ts | 2 +- apps/server/src/modules/learnroom/uc/course-export.uc.ts | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts index 12bd666893a..38641585dc4 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts @@ -33,7 +33,7 @@ type CommonCartridgeElementPropsInternal = | CommonCartridgeResourcesWrapperElementPropsV130; export class CommonCartridgeElementFactory { - public static createElement(props: CommonCartridgeElementPropsInternal): CommonCartridgeElement | never { + public static createElement(props: CommonCartridgeElementPropsInternal): CommonCartridgeElement { const { version } = props; switch (version) { diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts index 17cf932a85e..869aa6f576f 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts @@ -35,11 +35,9 @@ export abstract class CommonCartridgeElement { */ abstract getManifestXmlObject(): Record; - private checkVersion(target: CommonCartridgeVersion): void | never { - if (this.getSupportedVersion() === target) { - return; + private checkVersion(target: CommonCartridgeVersion): void { + if (this.getSupportedVersion() !== target) { + throw createVersionNotSupportedError(target); } - - throw createVersionNotSupportedError(target); } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts index 6b6e7322465..a3813e86aa2 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts @@ -25,7 +25,7 @@ type CommonCartridgeResourcePropsInternal = | CommonCartridgeWebLinkResourcePropsV130; export class CommonCartridgeResourceFactory { - public static createResource(props: CommonCartridgeResourcePropsInternal): CommonCartridgeResource | never { + public static createResource(props: CommonCartridgeResourcePropsInternal): CommonCartridgeResource { const { version } = props; switch (version) { diff --git a/apps/server/src/modules/learnroom/uc/course-export.uc.ts b/apps/server/src/modules/learnroom/uc/course-export.uc.ts index 0586569463c..320f35431d9 100644 --- a/apps/server/src/modules/learnroom/uc/course-export.uc.ts +++ b/apps/server/src/modules/learnroom/uc/course-export.uc.ts @@ -29,7 +29,7 @@ export class CourseExportUc { return this.courseExportService.exportCourse(courseId, userId, version); } - private checkFeatureEnabled(): void | never { + private checkFeatureEnabled(): void { if (!this.configService.get('FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED')) { throw new NotFoundException(); } From f47e3f2a9e164bdfed193f0bb6c5216e1f8de531 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 7 Mar 2024 11:51:33 +0100 Subject: [PATCH 168/177] EW-539 Working on review comments and adjust imports --- .../builders/common-cartridge-organization-builder.spec.ts | 2 +- .../export/elements/common-cartridge-element-factory.spec.ts | 2 +- .../elements/v1.1.0/common-cartridge-element-factory.spec.ts | 2 +- .../elements/v1.1.0/common-cartridge-metadata-element.spec.ts | 2 +- .../v1.1.0/common-cartridge-organization-element.spec.ts | 4 ++-- .../common-cartridge-organizations-wrapper-element.spec.ts | 2 +- .../v1.1.0/common-cartridge-resources-wrapper-element.spec.ts | 4 ++-- .../elements/v1.3.0/common-cartridge-element-factory.spec.ts | 2 +- .../elements/v1.3.0/common-cartridge-metadata-element.spec.ts | 2 +- .../v1.3.0/common-cartridge-organization-element.spec.ts | 4 ++-- .../common-cartridge-organizations-wrapper-element.spec.ts | 2 +- .../v1.3.0/common-cartridge-resources-wrapper-element.spec.ts | 4 ++-- .../resources/common-cartridge-resource-factory.spec.ts | 2 +- .../v1.1.0/common-cartridge-manifest-resource.spec.ts | 2 +- .../v1.1.0/common-cartridge-resource-factory.spec.ts | 2 +- .../v1.1.0/common-cartridge-web-content-resource.spec.ts | 2 +- .../v1.1.0/common-cartridge-web-link-resource.spec.ts | 2 +- .../v1.3.0/common-cartridge-manifest-resource.spec.ts | 2 +- .../v1.3.0/common-cartridge-resource-factory.spec.ts | 2 +- .../v1.3.0/common-cartridge-web-content-resource.spec.ts | 2 +- .../v1.3.0/common-cartridge-web-link-resource.spec.ts | 2 +- apps/server/src/modules/common-cartridge/index.ts | 1 + .../modules/learnroom/mapper/common-cartridge.mapper.spec.ts | 3 ++- .../src/modules/learnroom/mapper/common-cartridge.mapper.ts | 2 +- 24 files changed, 29 insertions(+), 27 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts index 852de560846..651aed99048 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts @@ -1,5 +1,5 @@ import { faker } from '@faker-js/faker/locale/af_ZA'; -import { createCommonCartridgeWebContentResourcePropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; +import { createCommonCartridgeWebContentResourcePropsV110 } from '../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts index 20f68a8d637..10bdeb10d2d 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts @@ -2,7 +2,7 @@ import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeMetadataElementPropsV110, createCommonCartridgeMetadataElementPropsV130, -} from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; +} from '../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElementFactory } from './common-cartridge-element-factory'; import { diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts index 78ca2baac85..3c43cf3a830 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts @@ -4,7 +4,7 @@ import { createCommonCartridgeOrganizationElementPropsV110, createCommonCartridgeOrganizationsWrapperElementPropsV110, createCommonCartridgeResourcesWrapperElementPropsV110, -} from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; +} from '../../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactoryV110 } from './common-cartridge-element-factory'; import { CommonCartridgeMetadataElementV110 } from './common-cartridge-metadata-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts index 1f593895d70..cd12efa1590 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts @@ -1,5 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeMetadataElementPropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; +import { createCommonCartridgeMetadataElementPropsV110 } from '../../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeMetadataElementV110 } from './common-cartridge-metadata-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts index 0f5f2a19dd1..8e1be0c920f 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeOrganizationElementPropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; -import { createCommonCartridgeWeblinkResourcePropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; +import { createCommonCartridgeOrganizationElementPropsV110 } from '../../../testing/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV110 } from '../../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts index 8b44269780f..fb5ae465a28 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -2,7 +2,7 @@ import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeOrganizationElementPropsV110, createCommonCartridgeOrganizationsWrapperElementPropsV110, -} from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; +} from '../../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; import { CommonCartridgeOrganizationsWrapperElementV110 } from './common-cartridge-organizations-wrapper-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts index 39e57dbf1ca..0106eefbee5 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeResourcesWrapperElementPropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; -import { createCommonCartridgeWeblinkResourcePropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; +import { createCommonCartridgeResourcesWrapperElementPropsV110 } from '../../../testing/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV110 } from '../../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeResourcesWrapperElementV110 } from './common-cartridge-resources-wrapper-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts index 6adee261bfc..7fe5e1f0cf5 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts @@ -4,7 +4,7 @@ import { createCommonCartridgeOrganizationElementPropsV130, createCommonCartridgeOrganizationsWrapperElementPropsV130, createCommonCartridgeResourcesWrapperElementPropsV130, -} from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; +} from '../../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactoryV130 } from './common-cartridge-element-factory'; import { CommonCartridgeMetadataElementV130 } from './common-cartridge-metadata-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts index 8a12a2faeeb..698b3efea04 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts @@ -1,5 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeMetadataElementPropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; +import { createCommonCartridgeMetadataElementPropsV130 } from '../../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeMetadataElementV130 } from './common-cartridge-metadata-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts index b02ae6ab273..73cb9b1af5a 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeOrganizationElementPropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; -import { createCommonCartridgeWeblinkResourcePropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; +import { createCommonCartridgeOrganizationElementPropsV130 } from '../../../testing/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV130 } from '../../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts index d2f87ea7a5f..47c68046764 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -2,7 +2,7 @@ import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeOrganizationElementPropsV130, createCommonCartridgeOrganizationsWrapperElementPropsV130, -} from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; +} from '../../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; import { CommonCartridgeOrganizationsWrapperElementV130 } from './common-cartridge-organizations-wrapper-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts index 2fc21492113..2d71adcc144 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeResourcesWrapperElementPropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-element-props.factory'; -import { createCommonCartridgeWeblinkResourcePropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; +import { createCommonCartridgeResourcesWrapperElementPropsV130 } from '../../../testing/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV130 } from '../../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeResourcesWrapperElementV130 } from './common-cartridge-resources-wrapper-element'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts index 9a55cc0f0e5..e6967661df7 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts @@ -2,7 +2,7 @@ import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeWebContentResourcePropsV110, createCommonCartridgeWebContentResourcePropsV130, -} from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; +} from '../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from './common-cartridge-resource-factory'; import { diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index 493245e05d2..aa63bb9237f 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeManifestResourcePropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { readFile } from 'fs/promises'; +import { createCommonCartridgeManifestResourcePropsV110 } from '../../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeElementType, CommonCartridgeIntendedUseType, diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts index 8612aa96843..fd93be44d2d 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts @@ -3,7 +3,7 @@ import { createCommonCartridgeManifestResourcePropsV110, createCommonCartridgeWebContentResourcePropsV110, createCommonCartridgeWeblinkResourcePropsV110, -} from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; +} from '../../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV110 } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResourceV110 } from './common-cartridge-web-content-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts index b313f8ad387..169986b451e 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts @@ -1,5 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeWebContentResourcePropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; +import { createCommonCartridgeWebContentResourcePropsV110 } from '../../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeWebContentResourceV110 } from './common-cartridge-web-content-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts index 281120e3608..79881d285f4 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeWeblinkResourcePropsV110 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { readFile } from 'fs/promises'; +import { createCommonCartridgeWeblinkResourcePropsV110 } from '../../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeWebLinkResourceV110 } from './common-cartridge-web-link-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index b9db706903d..2220c4e5381 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeManifestResourcePropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { readFile } from 'fs/promises'; +import { createCommonCartridgeManifestResourcePropsV130 } from '../../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeElementType, CommonCartridgeIntendedUseType, diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts index 2a30d5a4a00..ad630ea25d8 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts @@ -3,7 +3,7 @@ import { createCommonCartridgeManifestResourcePropsV130, createCommonCartridgeWebContentResourcePropsV130, createCommonCartridgeWeblinkResourcePropsV130, -} from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; +} from '../../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV130 } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts index f12a60975d0..e1b3334fd7d 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts @@ -1,5 +1,5 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeWebContentResourcePropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; +import { createCommonCartridgeWebContentResourcePropsV130 } from '../../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts index 2cd33e7afec..d6aee5e394f 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; -import { createCommonCartridgeWeblinkResourcePropsV130 } from '@src/modules/common-cartridge/testing/common-cartridge-resource-props.factory'; import { readFile } from 'node:fs/promises'; +import { createCommonCartridgeWeblinkResourcePropsV130 } from '../../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeWebLinkResourceV130 } from './common-cartridge-web-link-resource'; diff --git a/apps/server/src/modules/common-cartridge/index.ts b/apps/server/src/modules/common-cartridge/index.ts index 1fff35de5ce..c82ed05b595 100644 --- a/apps/server/src/modules/common-cartridge/index.ts +++ b/apps/server/src/modules/common-cartridge/index.ts @@ -14,4 +14,5 @@ export { } from './export/common-cartridge.enums'; export { CommonCartridgeElementProps } from './export/elements/common-cartridge-element-factory'; export { CommonCartridgeResourceProps } from './export/resources/common-cartridge-resource-factory'; +export { OmitVersion, createIdentifier } from './export/utils'; export { CommonCartridgeFileParser } from './import/common-cartridge-file-parser'; diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index 1ee027c6008..566d4488a5e 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -9,12 +9,13 @@ import { CommonCartridgeResourceProps, CommonCartridgeResourceType, CommonCartridgeVersion, + OmitVersion, + createIdentifier, } from '@modules/common-cartridge'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; import { ComponentProperties, ComponentType } from '@shared/domain/entity'; import { courseFactory, lessonFactory, setupEntities, taskFactory, userFactory } from '@shared/testing'; -import { OmitVersion, createIdentifier } from '@src/modules/common-cartridge/export/utils'; import { LearnroomConfig } from '../learnroom.config'; import { CommonCartridgeMapper } from './common-cartridge.mapper'; diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 5078d51d60f..b5e89980278 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -7,11 +7,11 @@ import { CommonCartridgeResourceProps, CommonCartridgeResourceType, CommonCartridgeVersion, + createIdentifier, } from '@modules/common-cartridge'; import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain/entity'; -import { createIdentifier } from '@src/modules/common-cartridge/export/utils'; import { LearnroomConfig } from '../learnroom.config'; @Injectable() From ce7e1dd11d1d14d6e632fa51a30eef09b93b8acf Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 7 Mar 2024 15:52:28 +0100 Subject: [PATCH 169/177] EW-539 Fix circular dependency --- .../context-external-tool.module.ts | 12 +++++++++--- .../school-external-tool.module.ts | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/server/src/modules/tool/context-external-tool/context-external-tool.module.ts b/apps/server/src/modules/tool/context-external-tool/context-external-tool.module.ts index d73e8a25171..102e033cb6b 100644 --- a/apps/server/src/modules/tool/context-external-tool/context-external-tool.module.ts +++ b/apps/server/src/modules/tool/context-external-tool/context-external-tool.module.ts @@ -1,15 +1,21 @@ -import { Module } from '@nestjs/common'; +import { Module, forwardRef } from '@nestjs/common'; import { LoggerModule } from '@src/core/logger'; import { CommonToolModule } from '../common'; import { ExternalToolModule } from '../external-tool'; import { SchoolExternalToolModule } from '../school-external-tool'; +import { ToolConfigModule } from '../tool-config.module'; import { ContextExternalToolAuthorizableService, ContextExternalToolService, ToolReferenceService } from './service'; import { ContextExternalToolValidationService } from './service/context-external-tool-validation.service'; -import { ToolConfigModule } from '../tool-config.module'; import { ToolVersionService } from './service/tool-version-service'; @Module({ - imports: [CommonToolModule, ExternalToolModule, SchoolExternalToolModule, LoggerModule, ToolConfigModule], + imports: [ + forwardRef(() => CommonToolModule), + forwardRef(() => ExternalToolModule), + SchoolExternalToolModule, + LoggerModule, + ToolConfigModule, + ], providers: [ ContextExternalToolService, ContextExternalToolValidationService, diff --git a/apps/server/src/modules/tool/school-external-tool/school-external-tool.module.ts b/apps/server/src/modules/tool/school-external-tool/school-external-tool.module.ts index 2ae4f66b2d8..2ff671cb62b 100644 --- a/apps/server/src/modules/tool/school-external-tool/school-external-tool.module.ts +++ b/apps/server/src/modules/tool/school-external-tool/school-external-tool.module.ts @@ -1,11 +1,11 @@ -import { Module } from '@nestjs/common'; +import { Module, forwardRef } from '@nestjs/common'; import { CommonToolModule } from '../common'; import { ExternalToolModule } from '../external-tool'; import { ToolConfigModule } from '../tool-config.module'; import { SchoolExternalToolService, SchoolExternalToolValidationService } from './service'; @Module({ - imports: [CommonToolModule, ExternalToolModule, ToolConfigModule], + imports: [forwardRef(() => CommonToolModule), forwardRef(() => ExternalToolModule), ToolConfigModule], providers: [SchoolExternalToolService, SchoolExternalToolValidationService], exports: [SchoolExternalToolService, SchoolExternalToolValidationService], }) From 20195b48baa2bed17a8409f74210c53b330978a7 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 8 Mar 2024 12:24:12 +0100 Subject: [PATCH 170/177] EW-539 Fix tasks without topic --- .../builders/common-cartridge-organization-builder.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts index e4c77a469dc..6f3d3dbb0e8 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts @@ -70,11 +70,9 @@ export class CommonCartridgeOrganizationBuilder { return organizationElement; } - private buildItems(): CommonCartridgeResource | (CommonCartridgeElement | CommonCartridgeResource)[] { + private buildItems(): (CommonCartridgeElement | CommonCartridgeResource)[] { if (this.resources.length === 1 && this.subOrganizations.length === 0) { - const [resource] = this.resources; - - return resource; + return this.resources; } const items = [...this.resources, ...this.subOrganizations.map((subOrganization) => subOrganization.build())]; From 340c03aa06e4f8f15fb46192369ee2f95b4e2a78 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 8 Mar 2024 14:16:04 +0100 Subject: [PATCH 171/177] EW-539 Fix task without topic --- .../export/builders/common-cartridge-organization-builder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts index 6f3d3dbb0e8..20ff6d3e528 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts @@ -72,7 +72,7 @@ export class CommonCartridgeOrganizationBuilder { private buildItems(): (CommonCartridgeElement | CommonCartridgeResource)[] { if (this.resources.length === 1 && this.subOrganizations.length === 0) { - return this.resources; + return [...this.resources]; } const items = [...this.resources, ...this.subOrganizations.map((subOrganization) => subOrganization.build())]; From ac084b3d6d7f2d42eefa6e1980692247ae2d9d24 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 8 Mar 2024 15:44:27 +0100 Subject: [PATCH 172/177] EW-539 Working on review comments. Add barrel files and adjust imports. --- .../builders/common-cartridge-file-builder.ts | 3 +-- ...mon-cartridge-organization-builder.spec.ts | 3 +-- .../common-cartridge-element-factory.spec.ts | 7 ++--- .../common-cartridge-element-factory.ts | 26 +++++++++++-------- .../common-cartridge-element-factory.ts | 2 +- .../common-cartridge-metadata-element.ts | 2 +- .../common-cartridge-organization-element.ts | 3 +-- ...cartridge-organizations-wrapper-element.ts | 2 +- ...mon-cartridge-resources-wrapper-element.ts | 2 +- .../export/elements/v1.1.0/index.ts | 8 ++++++ .../common-cartridge-element-factory.ts | 2 +- .../common-cartridge-metadata-element.ts | 2 +- .../common-cartridge-organization-element.ts | 3 +-- ...cartridge-organizations-wrapper-element.ts | 2 +- ...mon-cartridge-resources-wrapper-element.ts | 2 +- .../export/elements/v1.3.0/index.ts | 14 ++++++++++ .../export/interfaces/index.ts | 2 ++ .../common-cartridge-resource-factory.spec.ts | 7 ++--- .../common-cartridge-resource-factory.ts | 22 +++++++++------- .../common-cartridge-manifest-resource.ts | 3 +-- .../common-cartridge-resource-factory.ts | 2 +- .../common-cartridge-web-content-resource.ts | 2 +- .../common-cartridge-web-link-resource.ts | 2 +- .../export/resources/v1.1.0/index.ts | 7 +++++ ...common-cartridge-manifest-resource.spec.ts | 2 +- .../common-cartridge-manifest-resource.ts | 9 ++++--- .../common-cartridge-resource-factory.ts | 2 +- .../common-cartridge-web-content-resource.ts | 2 +- .../common-cartridge-web-link-resource.ts | 2 +- .../export/resources/v1.3.0/index.ts | 7 +++++ 30 files changed, 95 insertions(+), 59 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/export/elements/v1.1.0/index.ts create mode 100644 apps/server/src/modules/common-cartridge/export/elements/v1.3.0/index.ts create mode 100644 apps/server/src/modules/common-cartridge/export/interfaces/index.ts create mode 100644 apps/server/src/modules/common-cartridge/export/resources/v1.1.0/index.ts create mode 100644 apps/server/src/modules/common-cartridge/export/resources/v1.3.0/index.ts diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts index a22fbe688d6..0f605b5561d 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts @@ -4,8 +4,7 @@ import { CommonCartridgeElementFactory, CommonCartridgeElementProps, } from '../elements/common-cartridge-element-factory'; -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeElement, CommonCartridgeResource } from '../interfaces'; import { CommonCartridgeResourceFactory } from '../resources/common-cartridge-resource-factory'; import { OmitVersion } from '../utils'; import { diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts index 651aed99048..ba9a36001ae 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts @@ -1,8 +1,7 @@ import { faker } from '@faker-js/faker/locale/af_ZA'; import { createCommonCartridgeWebContentResourcePropsV110 } from '../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeElement, CommonCartridgeResource } from '../interfaces'; import { CommonCartridgeOrganizationBuilder, CommonCartridgeOrganizationBuilderOptions, diff --git a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts index 10bdeb10d2d..b891d1aa49a 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts @@ -5,11 +5,8 @@ import { } from '../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElementFactory } from './common-cartridge-element-factory'; -import { - CommonCartridgeMetadataElementPropsV110, - CommonCartridgeMetadataElementV110, -} from './v1.1.0/common-cartridge-metadata-element'; -import { CommonCartridgeMetadataElementV130 } from './v1.3.0/common-cartridge-metadata-element'; +import { CommonCartridgeMetadataElementPropsV110, CommonCartridgeMetadataElementV110 } from './v1.1.0'; +import { CommonCartridgeMetadataElementV130 } from './v1.3.0'; describe('CommonCartridgeElementFactory', () => { describe('createElement', () => { diff --git a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts index 38641585dc4..046f7033fde 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts @@ -1,16 +1,20 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeElement } from '../interfaces'; import { OmitVersionAndFolder, createVersionNotSupportedError } from '../utils'; -import { CommonCartridgeElementFactoryV110 } from './v1.1.0/common-cartridge-element-factory'; -import { CommonCartridgeMetadataElementPropsV110 } from './v1.1.0/common-cartridge-metadata-element'; -import { CommonCartridgeOrganizationElementPropsV110 } from './v1.1.0/common-cartridge-organization-element'; -import { CommonCartridgeOrganizationsWrapperElementPropsV110 } from './v1.1.0/common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElementPropsV110 } from './v1.1.0/common-cartridge-resources-wrapper-element'; -import { CommonCartridgeElementFactoryV130 } from './v1.3.0/common-cartridge-element-factory'; -import { CommonCartridgeMetadataElementPropsV130 } from './v1.3.0/common-cartridge-metadata-element'; -import { CommonCartridgeOrganizationElementPropsV130 } from './v1.3.0/common-cartridge-organization-element'; -import { CommonCartridgeOrganizationsWrapperElementPropsV130 } from './v1.3.0/common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElementPropsV130 } from './v1.3.0/common-cartridge-resources-wrapper-element'; +import { + CommonCartridgeElementFactoryV110, + CommonCartridgeMetadataElementPropsV110, + CommonCartridgeOrganizationElementPropsV110, + CommonCartridgeOrganizationsWrapperElementPropsV110, + CommonCartridgeResourcesWrapperElementPropsV110, +} from './v1.1.0'; +import { + CommonCartridgeElementFactoryV130, + CommonCartridgeMetadataElementPropsV130, + CommonCartridgeOrganizationElementPropsV130, + CommonCartridgeOrganizationsWrapperElementPropsV130, + CommonCartridgeResourcesWrapperElementPropsV130, +} from './v1.3.0'; export type CommonCartridgeElementProps = | OmitVersionAndFolder diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts index 2dbf4bf2334..88095cf218a 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeElement } from '../../interfaces'; import { createElementTypeNotSupportedError } from '../../utils'; import { CommonCartridgeMetadataElementPropsV110, diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts index af4765d5e06..c70cbd2c892 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeElement } from '../../interfaces'; export type CommonCartridgeMetadataElementPropsV110 = { type: CommonCartridgeElementType.METADATA; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts index 8745eab8a8f..ff304d6ea08 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts @@ -1,6 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeElement, CommonCartridgeResource } from '../../interfaces'; import { createIdentifier } from '../../utils'; export type CommonCartridgeOrganizationElementPropsV110 = { diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts index 657eec85201..9d1c44ec85d 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeElement } from '../../interfaces'; export type CommonCartridgeOrganizationsWrapperElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts index f541ec54f37..4048787732a 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeElement } from '../../interfaces'; export type CommonCartridgeResourcesWrapperElementPropsV110 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/index.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/index.ts new file mode 100644 index 00000000000..4fa057e5063 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/index.ts @@ -0,0 +1,8 @@ +export { CommonCartridgeElementFactoryV110 } from './common-cartridge-element-factory'; +export { + CommonCartridgeMetadataElementPropsV110, + CommonCartridgeMetadataElementV110, +} from './common-cartridge-metadata-element'; +export { CommonCartridgeOrganizationElementPropsV110 } from './common-cartridge-organization-element'; +export { CommonCartridgeOrganizationsWrapperElementPropsV110 } from './common-cartridge-organizations-wrapper-element'; +export { CommonCartridgeResourcesWrapperElementPropsV110 } from './common-cartridge-resources-wrapper-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts index 8765b72d43f..6a1216e405a 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeElement } from '../../interfaces'; import { createElementTypeNotSupportedError } from '../../utils'; import { CommonCartridgeMetadataElementPropsV130, diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts index 1a21d8f989b..a6477783e57 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeElement } from '../../interfaces'; export type CommonCartridgeMetadataElementPropsV130 = { type: CommonCartridgeElementType.METADATA; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts index f2d9f83d925..14696edfd95 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts @@ -1,6 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeElement, CommonCartridgeResource } from '../../interfaces'; import { createIdentifier } from '../../utils'; export type CommonCartridgeOrganizationElementPropsV130 = { diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts index 676fc3bf830..3c00f4844d2 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeElement } from '../../interfaces'; export type CommonCartridgeOrganizationsWrapperElementPropsV130 = { type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts index 4ec19d81836..aa11d0f457a 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; +import { CommonCartridgeElement } from '../../interfaces'; export type CommonCartridgeResourcesWrapperElementPropsV130 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/index.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/index.ts new file mode 100644 index 00000000000..1134c126384 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/index.ts @@ -0,0 +1,14 @@ +export { CommonCartridgeElementFactoryV130 } from './common-cartridge-element-factory'; +export { + CommonCartridgeMetadataElementPropsV130, + CommonCartridgeMetadataElementV130, +} from './common-cartridge-metadata-element'; +export { CommonCartridgeOrganizationElementPropsV130 } from './common-cartridge-organization-element'; +export { + CommonCartridgeOrganizationsWrapperElementPropsV130, + CommonCartridgeOrganizationsWrapperElementV130, +} from './common-cartridge-organizations-wrapper-element'; +export { + CommonCartridgeResourcesWrapperElementPropsV130, + CommonCartridgeResourcesWrapperElementV130, +} from './common-cartridge-resources-wrapper-element'; diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/index.ts b/apps/server/src/modules/common-cartridge/export/interfaces/index.ts new file mode 100644 index 00000000000..aaefb39018c --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/interfaces/index.ts @@ -0,0 +1,2 @@ +export { CommonCartridgeElement } from './common-cartridge-element.interface'; +export { CommonCartridgeResource } from './common-cartridge-resource.interface'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts index e6967661df7..9bd274d4810 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts @@ -5,11 +5,8 @@ import { } from '../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeResourceFactory } from './common-cartridge-resource-factory'; -import { - CommonCartridgeWebContentResourcePropsV110, - CommonCartridgeWebContentResourceV110, -} from './v1.1.0/common-cartridge-web-content-resource'; -import { CommonCartridgeWebContentResourceV130 } from './v1.3.0/common-cartridge-web-content-resource'; +import { CommonCartridgeWebContentResourcePropsV110, CommonCartridgeWebContentResourceV110 } from './v1.1.0'; +import { CommonCartridgeWebContentResourceV130 } from './v1.3.0'; describe('CommonCartridgeResourceVersion', () => { describe('createResource', () => { diff --git a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts index a3813e86aa2..673672c129e 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts @@ -1,14 +1,18 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeResource } from '../interfaces'; import { OmitVersionAndFolder, createVersionNotSupportedError } from '../utils'; -import { CommonCartridgeManifestResourcePropsV110 } from './v1.1.0/common-cartridge-manifest-resource'; -import { CommonCartridgeResourceFactoryV110 } from './v1.1.0/common-cartridge-resource-factory'; -import { CommonCartridgeWebContentResourcePropsV110 } from './v1.1.0/common-cartridge-web-content-resource'; -import { CommonCartridgeWebLinkResourcePropsV110 } from './v1.1.0/common-cartridge-web-link-resource'; -import { CommonCartridgeManifestResourcePropsV130 } from './v1.3.0/common-cartridge-manifest-resource'; -import { CommonCartridgeResourceFactoryV130 } from './v1.3.0/common-cartridge-resource-factory'; -import { CommonCartridgeWebContentResourcePropsV130 } from './v1.3.0/common-cartridge-web-content-resource'; -import { CommonCartridgeWebLinkResourcePropsV130 } from './v1.3.0/common-cartridge-web-link-resource'; +import { + CommonCartridgeManifestResourcePropsV110, + CommonCartridgeResourceFactoryV110, + CommonCartridgeWebContentResourcePropsV110, + CommonCartridgeWebLinkResourcePropsV110, +} from './v1.1.0'; +import { + CommonCartridgeManifestResourcePropsV130, + CommonCartridgeResourceFactoryV130, + CommonCartridgeWebContentResourcePropsV130, + CommonCartridgeWebLinkResourcePropsV130, +} from './v1.3.0'; export type CommonCartridgeResourceProps = | OmitVersionAndFolder diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts index b9e13a08d9e..ae578c34e4a 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -4,8 +4,7 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeElement, CommonCartridgeResource } from '../../interfaces'; import { buildXmlString } from '../../utils'; export type CommonCartridgeManifestResourcePropsV110 = { diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts index b447a5e9bb0..4e13ec77587 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts @@ -1,5 +1,5 @@ import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; -import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeResource } from '../../interfaces'; import { createResourceTypeNotSupportedError } from '../../utils'; import { CommonCartridgeManifestResourcePropsV110, diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts index ff56797986f..f684709e246 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -3,7 +3,7 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion, } from '../../common-cartridge.enums'; -import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeResource } from '../../interfaces'; import { checkIntendedUse } from '../../utils'; export type CommonCartridgeWebContentResourcePropsV110 = { diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts index edeb2aac52e..4da6c641215 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -1,5 +1,5 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeResource } from '../../interfaces'; import { buildXmlString } from '../../utils'; export type CommonCartridgeWebLinkResourcePropsV110 = { diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/index.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/index.ts new file mode 100644 index 00000000000..62d0bde3846 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/index.ts @@ -0,0 +1,7 @@ +export { CommonCartridgeManifestResourcePropsV110 } from './common-cartridge-manifest-resource'; +export { CommonCartridgeResourceFactoryV110 } from './common-cartridge-resource-factory'; +export { + CommonCartridgeWebContentResourcePropsV110, + CommonCartridgeWebContentResourceV110, +} from './common-cartridge-web-content-resource'; +export { CommonCartridgeWebLinkResourcePropsV110 } from './common-cartridge-web-link-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index 2220c4e5381..f49caa016c9 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -8,7 +8,7 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; -import { CommonCartridgeElementFactoryV130 } from '../../elements/v1.3.0/common-cartridge-element-factory'; +import { CommonCartridgeElementFactoryV130 } from '../../elements/v1.3.0'; import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts index 20b5b485e93..3da27cb30b8 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -3,10 +3,11 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion, } from '../../common-cartridge.enums'; -import { CommonCartridgeOrganizationsWrapperElementV130 } from '../../elements/v1.3.0/common-cartridge-organizations-wrapper-element'; -import { CommonCartridgeResourcesWrapperElementV130 } from '../../elements/v1.3.0/common-cartridge-resources-wrapper-element'; -import { CommonCartridgeElement } from '../../interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { + CommonCartridgeOrganizationsWrapperElementV130, + CommonCartridgeResourcesWrapperElementV130, +} from '../../elements/v1.3.0'; +import { CommonCartridgeElement, CommonCartridgeResource } from '../../interfaces'; import { buildXmlString } from '../../utils'; export type CommonCartridgeManifestResourcePropsV130 = { diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts index 3c719376ca9..9be5fad11c1 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts @@ -1,5 +1,5 @@ import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; -import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeResource } from '../../interfaces'; import { createResourceTypeNotSupportedError } from '../../utils'; import { CommonCartridgeManifestResourcePropsV130, diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts index 482afcb8da1..eb168087a52 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -3,7 +3,7 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion, } from '../../common-cartridge.enums'; -import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeResource } from '../../interfaces'; import { checkIntendedUse } from '../../utils'; export type CommonCartridgeWebContentResourcePropsV130 = { diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts index 78667f5531e..1cfd8a3df5b 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -1,5 +1,5 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeResource } from '../../interfaces/common-cartridge-resource.interface'; +import { CommonCartridgeResource } from '../../interfaces'; import { buildXmlString } from '../../utils'; export type CommonCartridgeWebLinkResourcePropsV130 = { diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/index.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/index.ts new file mode 100644 index 00000000000..dca0baca323 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/index.ts @@ -0,0 +1,7 @@ +export { CommonCartridgeManifestResourcePropsV130 } from './common-cartridge-manifest-resource'; +export { CommonCartridgeResourceFactoryV130 } from './common-cartridge-resource-factory'; +export { + CommonCartridgeWebContentResourcePropsV130, + CommonCartridgeWebContentResourceV130, +} from './common-cartridge-web-content-resource'; +export { CommonCartridgeWebLinkResourcePropsV130 } from './common-cartridge-web-link-resource'; From 73216e200762aa338b4034dbdcc1e4ece5f3aa32 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 12 Mar 2024 09:47:41 +0100 Subject: [PATCH 173/177] EW-539 Add feature flag for cc import to config response --- apps/server/src/modules/server/api/dto/config.response.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/server/src/modules/server/api/dto/config.response.ts b/apps/server/src/modules/server/api/dto/config.response.ts index 1dcb4c1f800..c0cdcc20caf 100644 --- a/apps/server/src/modules/server/api/dto/config.response.ts +++ b/apps/server/src/modules/server/api/dto/config.response.ts @@ -128,6 +128,9 @@ export class ConfigResponse { @ApiProperty() FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED: boolean; + @ApiProperty() + FEATURE_COMMON_CARTRIDGE_COURSE_IMPORT_ENABLED: boolean; + @ApiProperty() FEATURE_SCHOOL_SANIS_USER_MIGRATION_ENABLED: boolean; @@ -203,6 +206,7 @@ export class ConfigResponse { this.FEATURE_COPY_SERVICE_ENABLED = config.FEATURE_COPY_SERVICE_ENABLED; this.FEATURE_CONSENT_NECESSARY = config.FEATURE_CONSENT_NECESSARY; this.FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED = config.FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED; + this.FEATURE_COMMON_CARTRIDGE_COURSE_IMPORT_ENABLED = config.FEATURE_COMMON_CARTRIDGE_COURSE_IMPORT_ENABLED; this.FEATURE_SCHOOL_SANIS_USER_MIGRATION_ENABLED = config.FEATURE_SCHOOL_SANIS_USER_MIGRATION_ENABLED; this.FEATURE_ALLOW_INSECURE_LDAP_URL_ENABLED = config.FEATURE_ALLOW_INSECURE_LDAP_URL_ENABLED; this.FEATURE_NEST_SYSTEMS_API_ENABLED = config.FEATURE_NEST_SYSTEMS_API_ENABLED; From 1042db6d5c1b2620f93a4bed116fa444297eb4e3 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 12 Mar 2024 13:33:56 +0100 Subject: [PATCH 174/177] EW-539 Add feature flag for CC import to the server api test --- apps/server/src/modules/server/api/test/server.api.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/server/src/modules/server/api/test/server.api.spec.ts b/apps/server/src/modules/server/api/test/server.api.spec.ts index ba6bf7c5d29..0afd7c88ad1 100644 --- a/apps/server/src/modules/server/api/test/server.api.spec.ts +++ b/apps/server/src/modules/server/api/test/server.api.spec.ts @@ -54,6 +54,7 @@ describe('Server Controller (API)', () => { 'FEATURE_ES_COLLECTIONS_ENABLED', 'FEATURE_EXTENSIONS_ENABLED', 'FEATURE_COMMON_CARTRIDGE_COURSE_EXPORT_ENABLED', + 'FEATURE_COMMON_CARTRIDGE_COURSE_IMPORT_ENABLED', 'FEATURE_LERNSTORE_ENABLED', 'FEATURE_LESSON_SHARE', 'FEATURE_LOGIN_LINK_ENABLED', From d9b8b1f3ed1f606bada60c9a8a7a457933562abc Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 12 Mar 2024 13:34:53 +0100 Subject: [PATCH 175/177] EW-539 Fix circular dependency after merging main --- apps/server/src/modules/learnroom/learnroom.module.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/server/src/modules/learnroom/learnroom.module.ts b/apps/server/src/modules/learnroom/learnroom.module.ts index 48daa10491a..14ab282a5d6 100644 --- a/apps/server/src/modules/learnroom/learnroom.module.ts +++ b/apps/server/src/modules/learnroom/learnroom.module.ts @@ -4,7 +4,7 @@ import { LessonModule } from '@modules/lesson'; import { TaskModule } from '@modules/task'; import { ContextExternalToolModule } from '@modules/tool/context-external-tool'; import { ToolConfigModule } from '@modules/tool/tool-config.module'; -import { Module } from '@nestjs/common'; +import { Module, forwardRef } from '@nestjs/common'; import { BoardRepo, CourseGroupRepo, @@ -15,8 +15,8 @@ import { UserRepo, } from '@shared/repo'; import { LoggerModule } from '@src/core/logger'; -import { CommonCartridgeMapper } from './mapper/common-cartridge.mapper'; import { COURSE_REPO } from './domain'; +import { CommonCartridgeMapper } from './mapper/common-cartridge.mapper'; import { CourseMikroOrmRepo } from './repo/mikro-orm/course.repo'; import { BoardCopyService, @@ -36,7 +36,7 @@ import { CommonCartridgeFileValidatorPipe } from './utils'; LessonModule, TaskModule, CopyHelperModule, - BoardModule, + forwardRef(() => BoardModule), LoggerModule, ContextExternalToolModule, ToolConfigModule, From 9b541116c2c6d10d2cf083b5fcdaab65d5a5da9e Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 13 Mar 2024 08:15:31 +0100 Subject: [PATCH 176/177] EW-539 Fix linter --- apps/server/src/modules/learnroom/learnroom.module.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/learnroom/learnroom.module.ts b/apps/server/src/modules/learnroom/learnroom.module.ts index d89df185fba..96759014d12 100644 --- a/apps/server/src/modules/learnroom/learnroom.module.ts +++ b/apps/server/src/modules/learnroom/learnroom.module.ts @@ -6,15 +6,16 @@ import { ContextExternalToolModule } from '@modules/tool/context-external-tool'; import { ToolConfigModule } from '@modules/tool/tool-config.module'; import { Module, forwardRef } from '@nestjs/common'; import { - LegacyBoardRepo, CourseGroupRepo, CourseRepo, DashboardElementRepo, DashboardModelMapper, DashboardRepo, + LegacyBoardRepo, UserRepo, } from '@shared/repo'; import { LoggerModule } from '@src/core/logger'; +import { BoardNodeRepo } from '../board/repo'; import { COURSE_REPO } from './domain'; import { CommonCartridgeMapper } from './mapper/common-cartridge.mapper'; import { CourseMikroOrmRepo } from './repo/mikro-orm/course.repo'; @@ -29,10 +30,9 @@ import { RoomsService, } from './service'; import { CommonCartridgeFileValidatorPipe } from './utils'; -import { BoardNodeRepo } from '../board/repo'; @Module({ - imports: [ + imports: [ forwardRef(() => BoardModule), CopyHelperModule, ContextExternalToolModule, @@ -51,7 +51,7 @@ import { BoardNodeRepo } from '../board/repo'; CommonCartridgeExportService, CommonCartridgeFileValidatorPipe, CommonCartridgeImportService, - CommonCartridgeMapper, + CommonCartridgeMapper, CourseCopyService, CourseGroupRepo, CourseGroupService, From f8fc169d70161eeff5ff7a67ee23a7dac2a4b281 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 14 Mar 2024 09:59:09 +0100 Subject: [PATCH 177/177] EW-539 Fix task bug --- .../learnroom/service/common-cartridge-export.service.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 3371e8285ad..7ec713712a0 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -48,9 +48,7 @@ export class CommonCartridgeExportService { }); lesson.getLessonLinkedTasks().forEach((task) => { - organizationBuilder - .addSubOrganization(this.commonCartridgeMapper.mapTaskToOrganization(task)) - .addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); + organizationBuilder.addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); }); }); }