From f55f8df61b228b8dd3a7cdb05e38287a688f099a Mon Sep 17 00:00:00 2001 From: WojciechGrancow Date: Wed, 20 Sep 2023 16:45:57 +0200 Subject: [PATCH 1/6] changes in lesson module --- .../lesson/service/lesson.service.spec.ts | 38 +++++++++++++++++++ .../modules/lesson/service/lesson.service.ts | 6 +++ .../src/shared/domain/entity/lesson.entity.ts | 3 +- .../src/shared/repo/lesson/lesson.repo.ts | 23 +++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/lesson/service/lesson.service.spec.ts b/apps/server/src/modules/lesson/service/lesson.service.spec.ts index f47e54475be..7a425d3dded 100644 --- a/apps/server/src/modules/lesson/service/lesson.service.spec.ts +++ b/apps/server/src/modules/lesson/service/lesson.service.spec.ts @@ -3,6 +3,8 @@ import { Test, TestingModule } from '@nestjs/testing'; import { LessonRepo } from '@shared/repo'; import { lessonFactory, setupEntities } from '@shared/testing'; import { FilesStorageClientAdapterService } from '@src/modules/files-storage-client'; +import { ObjectId } from '@mikro-orm/mongodb'; +import { ComponentType, IComponentProperties } from '@shared/domain'; import { LessonService } from './lesson.service'; describe('LessonService', () => { @@ -74,4 +76,40 @@ describe('LessonService', () => { expect(lessonRepo.findAllByCourseIds).toBeCalledWith(courseIds); }); }); + + describe('findUserDataFromLessons', () => { + const setup = () => { + const userId = new ObjectId().toHexString(); + const contentExample: IComponentProperties = { + title: 'title', + hidden: false, + user: userId, + component: ComponentType.TEXT, + content: { text: 'test of content' }, + }; + const lesson1 = lessonFactory.buildWithId({ contents: [contentExample] }); + const lesson2 = lessonFactory.buildWithId({ contents: [contentExample] }); + + lessonRepo.findByUserId.mockResolvedValue([lesson1, lesson2]); + + return { + userId, + }; + }; + + it('should call findByCourseIds from lesson repo', async () => { + const { userId } = setup(); + + await expect(lessonService.findUserDataFromLessons(userId)).resolves.not.toThrow(); + expect(lessonRepo.findByUserId).toBeCalledWith(userId); + }); + + it('should return array of lessons with userId', async () => { + const { userId } = setup(); + + const result = await lessonService.findUserDataFromLessons(userId); + + expect(result).toHaveLength(2); + }); + }); }); diff --git a/apps/server/src/modules/lesson/service/lesson.service.ts b/apps/server/src/modules/lesson/service/lesson.service.ts index d97048e8eee..7e1c67343eb 100644 --- a/apps/server/src/modules/lesson/service/lesson.service.ts +++ b/apps/server/src/modules/lesson/service/lesson.service.ts @@ -23,4 +23,10 @@ export class LessonService { async findByCourseIds(courseIds: EntityId[]): Promise> { return this.lessonRepo.findAllByCourseIds(courseIds); } + + async findUserDataFromLessons(userId: EntityId): Promise { + const lessons = await this.lessonRepo.findByUserId(userId); + + return lessons; + } } diff --git a/apps/server/src/shared/domain/entity/lesson.entity.ts b/apps/server/src/shared/domain/entity/lesson.entity.ts index 87f0e846da0..d0efa36274e 100644 --- a/apps/server/src/shared/domain/entity/lesson.entity.ts +++ b/apps/server/src/shared/domain/entity/lesson.entity.ts @@ -8,7 +8,6 @@ import { CourseGroup } from './coursegroup.entity'; import { Material } from './materials.entity'; import { Task } from './task.entity'; import type { ITaskParent } from './task.entity'; -import { User } from './user.entity'; export interface ILessonProperties { name: string; @@ -68,7 +67,7 @@ export type IComponentProperties = { _id?: string; title: string; hidden: boolean; - user?: User; + user?: EntityId; } & ( | { component: ComponentType.TEXT; content: IComponentTextProperties } | { component: ComponentType.ETHERPAD; content: IComponentEtherpadProperties } diff --git a/apps/server/src/shared/repo/lesson/lesson.repo.ts b/apps/server/src/shared/repo/lesson/lesson.repo.ts index 0da2b926b0d..1f79f18f001 100644 --- a/apps/server/src/shared/repo/lesson/lesson.repo.ts +++ b/apps/server/src/shared/repo/lesson/lesson.repo.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import { Counted, EntityId, Lesson, SortOrder } from '@shared/domain'; import { BaseRepo } from '../base.repo'; import { LessonScope } from './lesson-scope'; +import { EntityDictionary } from '@mikro-orm/core'; @Injectable() export class LessonRepo extends BaseRepo { @@ -36,4 +37,26 @@ export class LessonRepo extends BaseRepo { return [lessons, count]; } + + public async findByUserId(userId: EntityId): Promise { + const pipeline = [ + { + $match: { + contents: { + $elemMatch: { + user: userId, + }, + }, + }, + }, + ]; + + const rawLessonsDocuments = await this._em.aggregate(Lesson, pipeline); + + const lessons = rawLessonsDocuments.map((rawLessonDocument) => + this._em.map(Lesson, rawLessonDocument as EntityDictionary) + ); + + return lessons; + } } From b1444763ba99ed521a140ef3aa5d2a6923683c01 Mon Sep 17 00:00:00 2001 From: WojciechGrancow Date: Thu, 21 Sep 2023 06:40:12 +0200 Subject: [PATCH 2/6] add method for services in lesson, course and coursegroup --- .../learnroom/service/course.service.spec.ts | 31 +++++++++++++++++ .../learnroom/service/course.service.ts | 8 ++++- .../service/coursegroup.service.spec.ts | 33 +++++++++++++++++++ .../learnroom/service/coursegroup.service.ts | 8 ++++- .../modules/lesson/service/lesson.service.ts | 2 +- .../src/shared/repo/lesson/lesson.repo.ts | 1 - 6 files changed, 79 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/course.service.spec.ts b/apps/server/src/modules/learnroom/service/course.service.spec.ts index 56d5bb359b4..e4f6d5a0a0c 100644 --- a/apps/server/src/modules/learnroom/service/course.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/course.service.spec.ts @@ -50,6 +50,37 @@ describe('CourseService', () => { }); }); + describe('findUserDataFromCourses', () => { + describe('when finding by userId', () => { + const setup = () => { + const user = userFactory.buildWithId(); + const course1 = courseFactory.buildWithId({ students: [user] }); + const course2 = courseFactory.buildWithId({ teachers: [user] }); + const course3 = courseFactory.buildWithId({ substitutionTeachers: [user] }); + const allCourses = [course1, course2, course3]; + + userRepo.findById.mockResolvedValue(user); + courseRepo.findAllByUserId.mockResolvedValue([allCourses, allCourses.length]); + + return { + user, + }; + }; + + it('should call courseRepo.findAllByUserId', async () => { + const { user } = setup(); + await courseService.findUserDataFromCourses(user.id); + expect(courseRepo.findAllByUserId).toBeCalledWith(user.id); + }); + + it('should return array of courses with userId', async () => { + const { user } = setup(); + const [courses] = await courseService.findUserDataFromCourses(user.id); + expect(courses.length).toEqual(3); + }); + }); + }); + describe('when deleting by userId', () => { const setup = () => { const user = userFactory.buildWithId(); diff --git a/apps/server/src/modules/learnroom/service/course.service.ts b/apps/server/src/modules/learnroom/service/course.service.ts index ef14fcfabb2..7376b36670f 100644 --- a/apps/server/src/modules/learnroom/service/course.service.ts +++ b/apps/server/src/modules/learnroom/service/course.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { CourseRepo } from '@shared/repo'; -import { Course, EntityId } from '@shared/domain'; +import { Counted, Course, EntityId } from '@shared/domain'; @Injectable() export class CourseService { @@ -10,6 +10,12 @@ export class CourseService { return this.repo.findById(courseId); } + public async findUserDataFromCourses(userId: EntityId): Promise> { + const [courses, count] = await this.repo.findAllByUserId(userId); + + return [courses, count]; + } + public async deleteUserDataFromCourse(userId: EntityId): Promise { const [courses, count] = await this.repo.findAllByUserId(userId); diff --git a/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts b/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts index 5a445792a23..13da34d32f7 100644 --- a/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts @@ -38,6 +38,39 @@ describe('CourseGroupService', () => { jest.clearAllMocks(); }); + describe('finUserDataFromCourseGroup', () => { + describe('when finding by userId', () => { + const setup = () => { + const user = userFactory.buildWithId(); + const courseGroup1 = courseGroupFactory.buildWithId({ students: [user] }); + const courseGroup2 = courseGroupFactory.buildWithId({ students: [user] }); + + userRepo.findById.mockResolvedValue(user); + courseGroupRepo.findByUserId.mockResolvedValue([[courseGroup1, courseGroup2], 2]); + + return { + user, + }; + }; + + it('should call courseGroupRepo.findByUserId', async () => { + const { user } = setup(); + + await courseGroupService.finUserDataFromCourseGroup(user.id); + + expect(courseGroupRepo.findByUserId).toBeCalledWith(user.id); + }); + + it('should return array with coursesGroup with userId', async () => { + const { user } = setup(); + + const [courseGroup] = await courseGroupService.finUserDataFromCourseGroup(user.id); + + expect(courseGroup.length).toEqual(2); + }); + }); + }); + describe('when deleting by userId', () => { const setup = () => { const user = userFactory.buildWithId(); diff --git a/apps/server/src/modules/learnroom/service/coursegroup.service.ts b/apps/server/src/modules/learnroom/service/coursegroup.service.ts index acd8f5b9b42..9bd633768d1 100644 --- a/apps/server/src/modules/learnroom/service/coursegroup.service.ts +++ b/apps/server/src/modules/learnroom/service/coursegroup.service.ts @@ -1,11 +1,17 @@ import { Injectable } from '@nestjs/common'; -import { EntityId } from '@shared/domain'; +import { Counted, CourseGroup, EntityId } from '@shared/domain'; import { CourseGroupRepo } from '@shared/repo'; @Injectable() export class CourseGroupService { constructor(private readonly repo: CourseGroupRepo) {} + public async finUserDataFromCourseGroup(userId: EntityId): Promise> { + const [courseGroups, count] = await this.repo.findByUserId(userId); + + return [courseGroups, count]; + } + public async deleteUserDataFromCourseGroup(userId: EntityId): Promise { const [courseGroups, count] = await this.repo.findByUserId(userId); diff --git a/apps/server/src/modules/lesson/service/lesson.service.ts b/apps/server/src/modules/lesson/service/lesson.service.ts index d1f96729716..b1430c0328f 100644 --- a/apps/server/src/modules/lesson/service/lesson.service.ts +++ b/apps/server/src/modules/lesson/service/lesson.service.ts @@ -24,7 +24,7 @@ export class LessonService { return this.lessonRepo.findAllByCourseIds(courseIds); } - async findUserDataFromLessons(userId: EntityId): Promise { + async findUserDataFromLessons(userId: EntityId): Promise { const lessons = await this.lessonRepo.findByUserId(userId); return lessons; diff --git a/apps/server/src/shared/repo/lesson/lesson.repo.ts b/apps/server/src/shared/repo/lesson/lesson.repo.ts index c0a351e9ed0..26f66e9587d 100644 --- a/apps/server/src/shared/repo/lesson/lesson.repo.ts +++ b/apps/server/src/shared/repo/lesson/lesson.repo.ts @@ -3,7 +3,6 @@ import { Counted, EntityId, LessonEntity, SortOrder } from '@shared/domain'; import { EntityDictionary } from '@mikro-orm/core'; import { BaseRepo } from '../base.repo'; import { LessonScope } from './lesson-scope'; -import { EntityDictionary } from '@mikro-orm/core'; @Injectable() export class LessonRepo extends BaseRepo { From 33830a0426f0d309f6abb061e54ee1dae5e83214 Mon Sep 17 00:00:00 2001 From: WojciechGrancow Date: Thu, 21 Sep 2023 07:10:26 +0200 Subject: [PATCH 3/6] litle addition in testcase --- .../lesson/service/lesson.service.spec.ts | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/apps/server/src/modules/lesson/service/lesson.service.spec.ts b/apps/server/src/modules/lesson/service/lesson.service.spec.ts index af9f0481cc2..102c698f343 100644 --- a/apps/server/src/modules/lesson/service/lesson.service.spec.ts +++ b/apps/server/src/modules/lesson/service/lesson.service.spec.ts @@ -78,38 +78,40 @@ describe('LessonService', () => { }); describe('findUserDataFromLessons', () => { - const setup = () => { - const userId = new ObjectId().toHexString(); - const contentExample: IComponentProperties = { - title: 'title', - hidden: false, - user: userId, - component: ComponentType.TEXT, - content: { text: 'test of content' }, - }; - const lesson1 = lessonFactory.buildWithId({ contents: [contentExample] }); - const lesson2 = lessonFactory.buildWithId({ contents: [contentExample] }); + describe('when finding by userId', () => { + const setup = () => { + const userId = new ObjectId().toHexString(); + const contentExample: IComponentProperties = { + title: 'title', + hidden: false, + user: userId, + component: ComponentType.TEXT, + content: { text: 'test of content' }, + }; + const lesson1 = lessonFactory.buildWithId({ contents: [contentExample] }); + const lesson2 = lessonFactory.buildWithId({ contents: [contentExample] }); - lessonRepo.findByUserId.mockResolvedValue([lesson1, lesson2]); + lessonRepo.findByUserId.mockResolvedValue([lesson1, lesson2]); - return { - userId, + return { + userId, + }; }; - }; - it('should call findByCourseIds from lesson repo', async () => { - const { userId } = setup(); + it('should call findByCourseIds from lesson repo', async () => { + const { userId } = setup(); - await expect(lessonService.findUserDataFromLessons(userId)).resolves.not.toThrow(); - expect(lessonRepo.findByUserId).toBeCalledWith(userId); - }); + await expect(lessonService.findUserDataFromLessons(userId)).resolves.not.toThrow(); + expect(lessonRepo.findByUserId).toBeCalledWith(userId); + }); - it('should return array of lessons with userId', async () => { - const { userId } = setup(); + it('should return array of lessons with userId', async () => { + const { userId } = setup(); - const result = await lessonService.findUserDataFromLessons(userId); + const result = await lessonService.findUserDataFromLessons(userId); - expect(result).toHaveLength(2); + expect(result).toHaveLength(2); + }); }); }); From 746fe6362213a7a5bcfc85df38e9412a121c6ff9 Mon Sep 17 00:00:00 2001 From: WojciechGrancow Date: Fri, 22 Sep 2023 07:11:42 +0200 Subject: [PATCH 4/6] changes in tests --- .../src/modules/learnroom/service/course.service.spec.ts | 8 +++++++- .../modules/learnroom/service/coursegroup.service.spec.ts | 7 +++++-- .../src/modules/lesson/service/lesson.service.spec.ts | 7 +++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/course.service.spec.ts b/apps/server/src/modules/learnroom/service/course.service.spec.ts index e4f6d5a0a0c..2de9f3149ad 100644 --- a/apps/server/src/modules/learnroom/service/course.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/course.service.spec.ts @@ -64,19 +64,25 @@ describe('CourseService', () => { return { user, + allCourses, }; }; it('should call courseRepo.findAllByUserId', async () => { const { user } = setup(); + await courseService.findUserDataFromCourses(user.id); + expect(courseRepo.findAllByUserId).toBeCalledWith(user.id); }); it('should return array of courses with userId', async () => { - const { user } = setup(); + const { user, allCourses } = setup(); + const [courses] = await courseService.findUserDataFromCourses(user.id); + expect(courses.length).toEqual(3); + expect(courses).toEqual(allCourses); }); }); }); diff --git a/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts b/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts index 13da34d32f7..306020448dd 100644 --- a/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts @@ -44,12 +44,14 @@ describe('CourseGroupService', () => { const user = userFactory.buildWithId(); const courseGroup1 = courseGroupFactory.buildWithId({ students: [user] }); const courseGroup2 = courseGroupFactory.buildWithId({ students: [user] }); + const courseGroups = [courseGroup1, courseGroup2]; userRepo.findById.mockResolvedValue(user); - courseGroupRepo.findByUserId.mockResolvedValue([[courseGroup1, courseGroup2], 2]); + courseGroupRepo.findByUserId.mockResolvedValue([courseGroups, courseGroups.length]); return { user, + courseGroups, }; }; @@ -62,11 +64,12 @@ describe('CourseGroupService', () => { }); it('should return array with coursesGroup with userId', async () => { - const { user } = setup(); + const { user, courseGroups } = setup(); const [courseGroup] = await courseGroupService.finUserDataFromCourseGroup(user.id); expect(courseGroup.length).toEqual(2); + expect(courseGroup).toEqual(courseGroups); }); }); }); diff --git a/apps/server/src/modules/lesson/service/lesson.service.spec.ts b/apps/server/src/modules/lesson/service/lesson.service.spec.ts index 102c698f343..7e9691387d9 100644 --- a/apps/server/src/modules/lesson/service/lesson.service.spec.ts +++ b/apps/server/src/modules/lesson/service/lesson.service.spec.ts @@ -90,11 +90,13 @@ describe('LessonService', () => { }; const lesson1 = lessonFactory.buildWithId({ contents: [contentExample] }); const lesson2 = lessonFactory.buildWithId({ contents: [contentExample] }); + const lessons = [lesson1, lesson2]; - lessonRepo.findByUserId.mockResolvedValue([lesson1, lesson2]); + lessonRepo.findByUserId.mockResolvedValue(lessons); return { userId, + lessons, }; }; @@ -106,11 +108,12 @@ describe('LessonService', () => { }); it('should return array of lessons with userId', async () => { - const { userId } = setup(); + const { userId, lessons } = setup(); const result = await lessonService.findUserDataFromLessons(userId); expect(result).toHaveLength(2); + expect(result).toEqual(lessons); }); }); }); From 34ea77cee466b02e119645b405332f386e5c75e8 Mon Sep 17 00:00:00 2001 From: WojciechGrancow Date: Fri, 22 Sep 2023 11:47:46 +0200 Subject: [PATCH 5/6] change method names in service after review --- .../src/modules/learnroom/service/course.service.spec.ts | 6 +++--- apps/server/src/modules/learnroom/service/course.service.ts | 2 +- .../modules/learnroom/service/coursegroup.service.spec.ts | 6 +++--- .../src/modules/learnroom/service/coursegroup.service.ts | 2 +- .../src/modules/lesson/service/lesson.service.spec.ts | 6 +++--- apps/server/src/modules/lesson/service/lesson.service.ts | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/course.service.spec.ts b/apps/server/src/modules/learnroom/service/course.service.spec.ts index 2de9f3149ad..5da3ec288cf 100644 --- a/apps/server/src/modules/learnroom/service/course.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/course.service.spec.ts @@ -50,7 +50,7 @@ describe('CourseService', () => { }); }); - describe('findUserDataFromCourses', () => { + describe('findAllCoursesByUserId', () => { describe('when finding by userId', () => { const setup = () => { const user = userFactory.buildWithId(); @@ -71,7 +71,7 @@ describe('CourseService', () => { it('should call courseRepo.findAllByUserId', async () => { const { user } = setup(); - await courseService.findUserDataFromCourses(user.id); + await courseService.findAllCoursesByUserId(user.id); expect(courseRepo.findAllByUserId).toBeCalledWith(user.id); }); @@ -79,7 +79,7 @@ describe('CourseService', () => { it('should return array of courses with userId', async () => { const { user, allCourses } = setup(); - const [courses] = await courseService.findUserDataFromCourses(user.id); + const [courses] = await courseService.findAllCoursesByUserId(user.id); expect(courses.length).toEqual(3); expect(courses).toEqual(allCourses); diff --git a/apps/server/src/modules/learnroom/service/course.service.ts b/apps/server/src/modules/learnroom/service/course.service.ts index 7376b36670f..101434fda73 100644 --- a/apps/server/src/modules/learnroom/service/course.service.ts +++ b/apps/server/src/modules/learnroom/service/course.service.ts @@ -10,7 +10,7 @@ export class CourseService { return this.repo.findById(courseId); } - public async findUserDataFromCourses(userId: EntityId): Promise> { + public async findAllCoursesByUserId(userId: EntityId): Promise> { const [courses, count] = await this.repo.findAllByUserId(userId); return [courses, count]; diff --git a/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts b/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts index 306020448dd..51c9b8a6bbb 100644 --- a/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts @@ -38,7 +38,7 @@ describe('CourseGroupService', () => { jest.clearAllMocks(); }); - describe('finUserDataFromCourseGroup', () => { + describe('findAllCourseGroupsByUserId', () => { describe('when finding by userId', () => { const setup = () => { const user = userFactory.buildWithId(); @@ -58,7 +58,7 @@ describe('CourseGroupService', () => { it('should call courseGroupRepo.findByUserId', async () => { const { user } = setup(); - await courseGroupService.finUserDataFromCourseGroup(user.id); + await courseGroupService.findAllCourseGroupsByUserId(user.id); expect(courseGroupRepo.findByUserId).toBeCalledWith(user.id); }); @@ -66,7 +66,7 @@ describe('CourseGroupService', () => { it('should return array with coursesGroup with userId', async () => { const { user, courseGroups } = setup(); - const [courseGroup] = await courseGroupService.finUserDataFromCourseGroup(user.id); + const [courseGroup] = await courseGroupService.findAllCourseGroupsByUserId(user.id); expect(courseGroup.length).toEqual(2); expect(courseGroup).toEqual(courseGroups); diff --git a/apps/server/src/modules/learnroom/service/coursegroup.service.ts b/apps/server/src/modules/learnroom/service/coursegroup.service.ts index 9bd633768d1..622cdbc5e9e 100644 --- a/apps/server/src/modules/learnroom/service/coursegroup.service.ts +++ b/apps/server/src/modules/learnroom/service/coursegroup.service.ts @@ -6,7 +6,7 @@ import { CourseGroupRepo } from '@shared/repo'; export class CourseGroupService { constructor(private readonly repo: CourseGroupRepo) {} - public async finUserDataFromCourseGroup(userId: EntityId): Promise> { + public async findAllCourseGroupsByUserId(userId: EntityId): Promise> { const [courseGroups, count] = await this.repo.findByUserId(userId); return [courseGroups, count]; diff --git a/apps/server/src/modules/lesson/service/lesson.service.spec.ts b/apps/server/src/modules/lesson/service/lesson.service.spec.ts index 7e9691387d9..7f0179640b5 100644 --- a/apps/server/src/modules/lesson/service/lesson.service.spec.ts +++ b/apps/server/src/modules/lesson/service/lesson.service.spec.ts @@ -77,7 +77,7 @@ describe('LessonService', () => { }); }); - describe('findUserDataFromLessons', () => { + describe('findAllLessonsByUserId', () => { describe('when finding by userId', () => { const setup = () => { const userId = new ObjectId().toHexString(); @@ -103,14 +103,14 @@ describe('LessonService', () => { it('should call findByCourseIds from lesson repo', async () => { const { userId } = setup(); - await expect(lessonService.findUserDataFromLessons(userId)).resolves.not.toThrow(); + await expect(lessonService.findAllLessonsByUserId(userId)).resolves.not.toThrow(); expect(lessonRepo.findByUserId).toBeCalledWith(userId); }); it('should return array of lessons with userId', async () => { const { userId, lessons } = setup(); - const result = await lessonService.findUserDataFromLessons(userId); + const result = await lessonService.findAllLessonsByUserId(userId); expect(result).toHaveLength(2); expect(result).toEqual(lessons); diff --git a/apps/server/src/modules/lesson/service/lesson.service.ts b/apps/server/src/modules/lesson/service/lesson.service.ts index b1430c0328f..5a69a19f305 100644 --- a/apps/server/src/modules/lesson/service/lesson.service.ts +++ b/apps/server/src/modules/lesson/service/lesson.service.ts @@ -24,7 +24,7 @@ export class LessonService { return this.lessonRepo.findAllByCourseIds(courseIds); } - async findUserDataFromLessons(userId: EntityId): Promise { + async findAllLessonsByUserId(userId: EntityId): Promise { const lessons = await this.lessonRepo.findByUserId(userId); return lessons; From 62c2c808e70fcf39a6c25d1c7b4513522547aa0f Mon Sep 17 00:00:00 2001 From: WojciechGrancow Date: Mon, 25 Sep 2023 13:09:35 +0200 Subject: [PATCH 6/6] small changes in test --- .../src/modules/learnroom/service/coursegroup.service.spec.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts b/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts index 51c9b8a6bbb..48caf02c378 100644 --- a/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/coursegroup.service.spec.ts @@ -42,9 +42,7 @@ describe('CourseGroupService', () => { describe('when finding by userId', () => { const setup = () => { const user = userFactory.buildWithId(); - const courseGroup1 = courseGroupFactory.buildWithId({ students: [user] }); - const courseGroup2 = courseGroupFactory.buildWithId({ students: [user] }); - const courseGroups = [courseGroup1, courseGroup2]; + const courseGroups = courseGroupFactory.buildListWithId(2, { students: [user] }); userRepo.findById.mockResolvedValue(user); courseGroupRepo.findByUserId.mockResolvedValue([courseGroups, courseGroups.length]);