diff --git a/apps/server/src/modules/class/service/class.service.spec.ts b/apps/server/src/modules/class/service/class.service.spec.ts index c605f4de7cd..d851a38f62e 100644 --- a/apps/server/src/modules/class/service/class.service.spec.ts +++ b/apps/server/src/modules/class/service/class.service.spec.ts @@ -39,6 +39,42 @@ describe(ClassService.name, () => { await module.close(); }); + describe('findUserDataFromClasses', () => { + describe('when finding by userId', () => { + const setup = () => { + const userId1 = new ObjectId(); + const userId2 = new ObjectId(); + const userId3 = new ObjectId(); + const class1 = classEntityFactory.withUserIds([userId1, userId2]).build(); + const class2 = classEntityFactory.withUserIds([userId1, userId3]).build(); + classEntityFactory.withUserIds([userId2, userId3]).build(); + + const mappedClasses = ClassMapper.mapToDOs([class1, class2]); + + classesRepo.findAllByUserId.mockResolvedValue(mappedClasses); + + return { + userId1, + }; + }; + + it('should call classesRepo.findAllByUserId', async () => { + const { userId1 } = setup(); + await service.deleteUserDataFromClasses(userId1.toHexString()); + + expect(classesRepo.findAllByUserId).toBeCalledWith(userId1.toHexString()); + }); + + it('should return array of two teams with user', async () => { + const { userId1 } = setup(); + + const result = await service.findUserDataFromClasses(userId1.toHexString()); + + expect(result.length).toEqual(2); + }); + }); + }); + describe('deleteUserDataFromClasses', () => { describe('when user is missing', () => { const setup = () => { diff --git a/apps/server/src/modules/class/service/class.service.ts b/apps/server/src/modules/class/service/class.service.ts index 30ca6602d8f..7a42606769a 100644 --- a/apps/server/src/modules/class/service/class.service.ts +++ b/apps/server/src/modules/class/service/class.service.ts @@ -7,6 +7,12 @@ import { Class } from '../domain'; export class ClassService { constructor(private readonly classesRepo: ClassesRepo) {} + public async findUserDataFromClasses(userId: EntityId): Promise { + const classes = await this.classesRepo.findAllByUserId(userId); + + return classes; + } + public async deleteUserDataFromClasses(userId: EntityId): Promise { if (!userId) { throw new InternalServerErrorException('User id is missing');