Skip to content

Commit

Permalink
Merge branch 'main' into N21-1268-fix-expert-ctl-error
Browse files Browse the repository at this point in the history
  • Loading branch information
arnegns authored Sep 18, 2023
2 parents ed459a1 + 8cf1dca commit 46c29f7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
36 changes: 36 additions & 0 deletions apps/server/src/modules/class/service/class.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/modules/class/service/class.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { Class } from '../domain';
export class ClassService {
constructor(private readonly classesRepo: ClassesRepo) {}

public async findUserDataFromClasses(userId: EntityId): Promise<Class[]> {
const classes = await this.classesRepo.findAllByUserId(userId);

return classes;
}

public async deleteUserDataFromClasses(userId: EntityId): Promise<number> {
if (!userId) {
throw new InternalServerErrorException('User id is missing');
Expand Down

0 comments on commit 46c29f7

Please sign in to comment.