Skip to content

Commit

Permalink
working on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psachmann committed Jan 10, 2025
1 parent 49a1135 commit 243d0e6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileElementResponseDto>) {
this.id = props.id;
this.type = props.type;
this.content = props.content;
this.timestamps = props.timestamps;
}

public static isFileElement(reference: unknown): reference is FileElementResponseDto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CourseCommonCartridgeMetadataDto>(({ sequence }) => {
return {
Expand Down Expand Up @@ -55,7 +56,7 @@ export const cardResponseFactory = Factory.define<CardResponseDto>(({ 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(),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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<FileElementContentDto>(() => {
return {
caption: faker.lorem.sentence(),
alternativeText: faker.lorem.sentence(),
};
});

class FileElementResponseDtoFactory extends BaseFactory<FileElementResponseDto, Readonly<FileElementResponseDto>> {}

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,
},
};
});

0 comments on commit 243d0e6

Please sign in to comment.