Skip to content

Commit

Permalink
EW-1060 fixed deep imports and add separate factories
Browse files Browse the repository at this point in the history
  • Loading branch information
Fshmit committed Dec 13, 2024
1 parent 6c07050 commit 5de498b
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { RoomBoardDto } from './room-board.dto';
export { BoardElementDto } from './board-element.dto';
export { BoardTaskDto } from './board-task.dto';
export { BoardTaskStatusDto } from './board-task-status.dto';
export { BoardLessonDto } from './board-lesson.dto';
export { BoardColumnBoardDto } from './board-column-board.dto';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { faker } from '@faker-js/faker';
import { BoardTaskStatusResponse } from '../room-api-client';
import { BoardTaskStatusMapper } from './board-task-status-dto.mapper';
import { BoardTaskStatusDto } from '../dto/board-task-status.dto';
import { BoardTaskStatusDto } from '../dto';

describe(BoardTaskStatusMapper.name, () => {
describe('mapBoardTaskStatusToDto', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BoardTaskStatusDto } from '../dto/board-task-status.dto';
import { BoardTaskStatusDto } from '../dto';
import { BoardTaskStatusResponse } from '../room-api-client';

export class BoardTaskStatusMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SingleColumnBoardResponse,
} from '../room-api-client';
import { RoomBoardDtoMapper } from './room-board-dto.mapper';
import { BoardTaskStatusDto } from '../dto/board-task-status.dto';
import { BoardTaskStatusDto } from '../dto';

describe(RoomBoardDtoMapper.name, () => {
describe('mapResponseToRoomBoardDto', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { BoardColumnBoardDto } from '../dto/board-column-board.dto';
import { BoardElementDto } from '../dto/board-element.dto';
import { BoardLessonDto } from '../dto/board-lesson.dto';
import { BoardTaskDto } from '../dto/board-task.dto';
import { RoomBoardDto } from '../dto/room-board.dto';
import { RoomBoardDto, BoardTaskDto, BoardLessonDto, BoardElementDto, BoardColumnBoardDto } from '../dto';
import { BoardElementDtoType } from '../enums/board-element.enum';
import {
BoardColumnBoardResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { jest } from '@jest/globals';
import { CourseRoomsApi, SingleColumnBoardResponse } from './room-api-client';
import { CourseRoomsClientAdapter } from './room-client.adapter';
import { RoomBoardDtoMapper } from './mapper/room-board-dto.mapper';
import { RoomBoardDto } from './dto/room-board.dto';
import { RoomBoardDto } from './dto';

const jwtToken = 'dummyJwtToken';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Request } from 'express';
import { extractJwtFromHeader } from '@shared/common';
import { RawAxiosRequestConfig } from 'axios';
import { CourseRoomsApi } from './room-api-client';
import { RoomBoardDto } from './dto/room-board.dto';
import { RoomBoardDto } from './dto';
import { RoomBoardDtoMapper } from './mapper/room-board-dto.mapper';

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { Body, Controller, Param, Post, Query, Res, StreamableFile } from '@nest
import { ApiTags } from '@nestjs/swagger';
import { Response } from 'express';
import { CommonCartridgeUc } from '../uc/common-cartridge.uc';
import { ExportCourseParams } from './dto';
import { CourseQueryParams } from './dto/course.query.params';
import { CourseExportBodyParams } from './dto/course-export.body.params';
import { ExportCourseParams, CourseQueryParams, CourseExportBodyParams } from './dto';

@ApiTags('common-cartridge')
@Controller('common-cartridge')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './common-cartridge.params';
export * from './common-cartridge.response';
export * from './course.query.params';
export * from './course-export.body.params';
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import { CardClientAdapter } from '../common-cartridge-client/card-client/card-c
import { LessonClientAdapter } from '../common-cartridge-client/lesson-client/lesson-client.adapter';
import { CommonCartridgeExportMapper } from './common-cartridge.mapper';
import { CommonCartridgeVersion } from '../export/common-cartridge.enums';
import { RoomBoardDto } from '../common-cartridge-client/room-client/dto/room-board.dto';
import {
RoomBoardDto,
BoardTaskDto,
BoardLessonDto,
BoardColumnBoardDto,
} from '../common-cartridge-client/room-client/dto';
import { RichTextElementContentDto } from '../common-cartridge-client/card-client/dto/rich-text-element-content.dto';
import { LinkElementContentDto } from '../common-cartridge-client/card-client/dto/link-element-content.dto';
import {
Expand All @@ -24,9 +29,6 @@ import {
roomFactory,
} from '../testing/common-cartridge-dtos.factory';
import { CardListResponseDto } from '../common-cartridge-client/card-client/dto/card-list-response.dto';
import { BoardTaskDto } from '../common-cartridge-client/room-client/dto/board-task.dto';
import { BoardLessonDto } from '../common-cartridge-client/room-client/dto/board-lesson.dto';
import { BoardColumnBoardDto } from '../common-cartridge-client/room-client/dto/board-column-board.dto';

describe('CommonCartridgeExportService', () => {
let module: TestingModule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ import { Injectable } from '@nestjs/common';
import { BoardClientAdapter, BoardSkeletonDto, ColumnSkeletonDto } from '../common-cartridge-client/board-client';
import { CourseCommonCartridgeMetadataDto, CoursesClientAdapter } from '../common-cartridge-client/course-client';
import { CourseRoomsClientAdapter } from '../common-cartridge-client/room-client';
import { RoomBoardDto } from '../common-cartridge-client/room-client/dto/room-board.dto';
import {
RoomBoardDto,
BoardElementDto,
BoardColumnBoardDto,
BoardLessonDto,
BoardTaskDto,
} from '../common-cartridge-client/room-client/dto';
import { CardClientAdapter } from '../common-cartridge-client/card-client/card-client.adapter';
import { CardListResponseDto } from '../common-cartridge-client/card-client/dto/card-list-response.dto';
import { LessonClientAdapter } from '../common-cartridge-client/lesson-client/lesson-client.adapter';
import { BoardColumnBoardDto } from '../common-cartridge-client/room-client/dto/board-column-board.dto';
import { BoardLessonDto } from '../common-cartridge-client/room-client/dto/board-lesson.dto';
import { LessonContentDto, LessonDto } from '../common-cartridge-client/lesson-client/dto';
import { CommonCartridgeFileBuilder } from '../export/builders/common-cartridge-file-builder';
import { CommonCartridgeVersion } from '../export/common-cartridge.enums';
import { CommonCartridgeExportMapper } from './common-cartridge.mapper';
import { CommonCartridgeOrganizationNode } from '../export/builders/common-cartridge-organization-node';
import { BoardTaskDto } from '../common-cartridge-client/room-client/dto/board-task.dto';
import { createIdentifier } from '../export/utils';
import { BoardElementDto } from '../common-cartridge-client/room-client/dto/board-element.dto';
import { BoardElementDtoType } from '../common-cartridge-client/room-client/enums/board-element.enum';
import { CardResponseDto } from '../common-cartridge-client/card-client/dto/card-response.dto';
import { CardResponseElementsInnerDto } from '../common-cartridge-client/card-client/types/card-response-elements-inner.type';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { faker } from '@faker-js/faker';
import { Factory } from 'fishery';
import { BaseFactory } from '@shared/testing';
import { CourseCommonCartridgeMetadataDto } from '../common-cartridge-client/course-client';
import { LessonContentDto, LessonDto, LessonLinkedTaskDto } from '../common-cartridge-client/lesson-client/dto';
import { BoardSkeletonDto, CardSkeletonDto, ColumnSkeletonDto } from '../common-cartridge-client/board-client';
import { CardListResponseDto } from '../common-cartridge-client/card-client/dto/card-list-response.dto';
import { CardResponseDto } from '../common-cartridge-client/card-client/dto/card-response.dto';
import { ContentElementType } from '../common-cartridge-client/card-client/enums/content-element-type.enum';
import { BoardTaskDto } from '../common-cartridge-client/room-client/dto/board-task.dto';
import { BoardTaskStatusDto } from '../common-cartridge-client/room-client/dto/board-task-status.dto';
import { RoomBoardDto } from '../common-cartridge-client/room-client/dto/room-board.dto';
import {
RoomBoardDto,
BoardTaskStatusDto,
BoardTaskDto,
BoardLessonDto,
BoardColumnBoardDto,
} from '../common-cartridge-client/room-client/dto';
import { BoardElementDtoType } from '../common-cartridge-client/room-client/enums/board-element.enum';
import { BoardLessonDto } from '../common-cartridge-client/room-client/dto/board-lesson.dto';
import { BoardColumnBoardDto } from '../common-cartridge-client/room-client/dto/board-column-board.dto';
import { BoardLayout } from '../common-cartridge-client/room-client/enums/board-layout.enum';
import { RichTextElementContentDto } from '../common-cartridge-client/card-client/dto/rich-text-element-content.dto';
import { LinkElementContentDto } from '../common-cartridge-client/card-client/dto/link-element-content.dto';
import { RichTextElementResponseDto } from '../common-cartridge-client/card-client/dto/rich-text-element-response.dto';
import { LinkElementResponseDto } from '../common-cartridge-client/card-client/dto/link-element-response.dto';
import { richTextElementFactroy } from './rich-text-element.factory';
import { linkElementFactory } from './link-element.factory';

export const courseMetadataFactory = Factory.define<CourseCommonCartridgeMetadataDto>(({ sequence }) => {
return {
Expand Down Expand Up @@ -53,49 +51,6 @@ export const columnBoardFactory = Factory.define<BoardSkeletonDto>(({ sequence }
};
});

export const richTextElementContentFactory = Factory.define<RichTextElementContentDto>(() => {
return {
text: faker.lorem.word(),
inputFormat: 'plainText',
};
});

class RichTextElement extends BaseFactory<RichTextElementResponseDto, Readonly<RichTextElementResponseDto>> {}
export const richTextElementFactroy = RichTextElement.define(RichTextElementResponseDto, () => {
return {
id: faker.string.uuid(),
type: ContentElementType.RICH_TEXT,
content: richTextElementContentFactory.build(),
timestamps: {
lastUpdatedAt: faker.date.recent().toISOString(),
createdAt: faker.date.recent().toISOString(),
deletedAt: undefined,
},
};
});

export const linkElementContentFactory = Factory.define<LinkElementContentDto>(() => {
return {
url: faker.internet.url(),
title: faker.lorem.word(),
description: faker.lorem.sentence(),
};
});

class LinkElementFactory extends BaseFactory<LinkElementResponseDto, Readonly<LinkElementResponseDto>> {}
export const linkElementFactory = LinkElementFactory.define(LinkElementResponseDto, () => {
return {
id: faker.string.uuid(),
type: ContentElementType.LINK,
content: linkElementContentFactory.build(),
timestamps: {
lastUpdatedAt: faker.date.recent().toISOString(),
createdAt: faker.date.recent().toISOString(),
deletedAt: undefined,
},
};
});

export const cardResponseFactory = Factory.define<CardResponseDto>(({ sequence }) => {
return {
id: sequence.toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { faker } from '@faker-js/faker';
import { BaseFactory } from '@shared/testing';
import { Factory } from 'fishery';
import { LinkElementContentDto } from '../common-cartridge-client/card-client/dto/link-element-content.dto';
import { LinkElementResponseDto } from '../common-cartridge-client/card-client/dto/link-element-response.dto';
import { ContentElementType } from '../common-cartridge-client/card-client/enums/content-element-type.enum';

export const linkElementContentFactory = Factory.define<LinkElementContentDto>(() => {
return {
url: faker.internet.url(),
title: faker.lorem.word(),
description: faker.lorem.sentence(),
};
});

class LinkElementFactory extends BaseFactory<LinkElementResponseDto, Readonly<LinkElementResponseDto>> {}
export const linkElementFactory = LinkElementFactory.define(LinkElementResponseDto, () => {
return {
id: faker.string.uuid(),
type: ContentElementType.LINK,
content: linkElementContentFactory.build(),
timestamps: {
lastUpdatedAt: faker.date.recent().toISOString(),
createdAt: faker.date.recent().toISOString(),
deletedAt: undefined,
},
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { BaseFactory } from '@shared/testing';
import { faker } from '@faker-js/faker';
import { Factory } from 'fishery';
import { RichTextElementResponseDto } from '../common-cartridge-client/card-client/dto/rich-text-element-response.dto';
import { RichTextElementContentDto } from '../common-cartridge-client/card-client/dto/rich-text-element-content.dto';
import { ContentElementType } from '../common-cartridge-client/card-client/enums/content-element-type.enum';

export const richTextElementContentFactory = Factory.define<RichTextElementContentDto>(() => {
return {
text: faker.lorem.word(),
inputFormat: 'plainText',
};
});

class RichTextElement extends BaseFactory<RichTextElementResponseDto, Readonly<RichTextElementResponseDto>> {}
export const richTextElementFactroy = RichTextElement.define(RichTextElementResponseDto, () => {
return {
id: faker.string.uuid(),
type: ContentElementType.RICH_TEXT,
content: richTextElementContentFactory.build(),
timestamps: {
lastUpdatedAt: faker.date.recent().toISOString(),
createdAt: faker.date.recent().toISOString(),
deletedAt: undefined,
},
};
});

0 comments on commit 5de498b

Please sign in to comment.