From 243d0e6a28ac2c0329e20dd3ff5521e4bd6eaf7f Mon Sep 17 00:00:00 2001 From: Patrick Sachmann <20001160+psachmann@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:42:22 +0100 Subject: [PATCH] working on tests --- .../dto/file-element-response.dto.ts | 10 +++---- .../mapper/card-response.mapper.ts | 12 ++++---- .../testing/common-cartridge-dtos.factory.ts | 3 +- .../testing/file-element.factory.ts | 28 +++++++++++++++++++ 4 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/testing/file-element.factory.ts diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/card-client/dto/file-element-response.dto.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/card-client/dto/file-element-response.dto.ts index fbe23a051e..fd258ef0e7 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/card-client/dto/file-element-response.dto.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/card-client/dto/file-element-response.dto.ts @@ -11,11 +11,11 @@ export class FileElementResponseDto { public timestamps: TimestampResponseDto; - constructor(id: string, type: ContentElementType, content: FileElementContentDto, timestamps: TimestampResponseDto) { - this.id = id; - this.type = type; - this.content = content; - this.timestamps = timestamps; + constructor(props: Readonly) { + this.id = props.id; + this.type = props.type; + this.content = props.content; + this.timestamps = props.timestamps; } public static isFileElement(reference: unknown): reference is FileElementResponseDto { diff --git a/apps/server/src/modules/common-cartridge/common-cartridge-client/card-client/mapper/card-response.mapper.ts b/apps/server/src/modules/common-cartridge/common-cartridge-client/card-client/mapper/card-response.mapper.ts index da13bb72a9..e91798fb86 100644 --- a/apps/server/src/modules/common-cartridge/common-cartridge-client/card-client/mapper/card-response.mapper.ts +++ b/apps/server/src/modules/common-cartridge/common-cartridge-client/card-client/mapper/card-response.mapper.ts @@ -126,12 +126,12 @@ export class CardResponseMapper { case ContentElementType.FILE: { const content: FileElementContent = element.content as FileElementContent; elements.push( - new FileElementResponseDto( - element.id, - ContentElementType.FILE, - new FileElementContentDto(content.caption, content.alternativeText), - this.mapToTimestampDto(element.timestamps) - ) + new FileElementResponseDto({ + id: element.id, + type: ContentElementType.FILE, + content: new FileElementContentDto(content.caption, content.alternativeText), + timestamps: this.mapToTimestampDto(element.timestamps), + }) ); break; } diff --git a/apps/server/src/modules/common-cartridge/testing/common-cartridge-dtos.factory.ts b/apps/server/src/modules/common-cartridge/testing/common-cartridge-dtos.factory.ts index 253e1d421e..c08ee658be 100644 --- a/apps/server/src/modules/common-cartridge/testing/common-cartridge-dtos.factory.ts +++ b/apps/server/src/modules/common-cartridge/testing/common-cartridge-dtos.factory.ts @@ -16,6 +16,7 @@ import { BoardElementDtoType } from '../common-cartridge-client/room-client/enum import { BoardLayout } from '../common-cartridge-client/room-client/enums/board-layout.enum'; import { richTextElementFactroy } from './rich-text-element.factory'; import { linkElementFactory } from './link-element.factory'; +import { fileElementResponseDtoFactory } from './file-element.factory'; export const courseMetadataFactory = Factory.define(({ sequence }) => { return { @@ -55,7 +56,7 @@ export const cardResponseFactory = Factory.define(({ sequence } return { id: sequence.toString(), height: faker.number.int(), - elements: [richTextElementFactroy.build(), linkElementFactory.build()], + elements: [richTextElementFactroy.build(), linkElementFactory.build(), fileElementResponseDtoFactory.build()], visibilitySettings: { publishedAt: faker.date.recent().toISOString(), }, diff --git a/apps/server/src/modules/common-cartridge/testing/file-element.factory.ts b/apps/server/src/modules/common-cartridge/testing/file-element.factory.ts new file mode 100644 index 0000000000..9321601a80 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/testing/file-element.factory.ts @@ -0,0 +1,28 @@ +import { Factory } from 'fishery'; +import { faker } from '@faker-js/faker'; +import { BaseFactory } from '@shared/testing'; +import { ContentElementType } from '@modules/board'; +import { FileElementContentDto } from '../common-cartridge-client/card-client/dto/file-element-content.dto'; +import { FileElementResponseDto } from '../common-cartridge-client/card-client/dto'; + +export const fileElementContentFactory = Factory.define(() => { + return { + caption: faker.lorem.sentence(), + alternativeText: faker.lorem.sentence(), + }; +}); + +class FileElementResponseDtoFactory extends BaseFactory> {} + +export const fileElementResponseDtoFactory = FileElementResponseDtoFactory.define(FileElementResponseDto, () => { + return { + id: faker.string.uuid(), + type: ContentElementType.FILE, + content: fileElementContentFactory.build(), + timestamps: { + lastUpdatedAt: faker.date.recent().toISOString(), + createdAt: faker.date.recent().toISOString(), + deletedAt: undefined, + }, + }; +});