Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N21-1268 fix-expert-ctl-error #4410

Merged
merged 10 commits into from
Sep 21, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { NotFoundException } from '@nestjs/common/exceptions/not-found.exception
import { teamUserFactory } from '@shared/testing/factory/teamuser.factory';
import { CourseService } from '@src/modules/learnroom/service';
import { VideoConferenceService } from './video-conference.service';
import { ErrorStatus } from '../error/error-status.enum';
import { ErrorStatus } from '../error';
import { BBBRole } from '../bbb';
import { IScopeInfo, ScopeRef, VideoConferenceState } from '../uc/dto';
import { IVideoConferenceSettings, VideoConferenceOptions, VideoConferenceSettings } from '../interface';
Expand Down Expand Up @@ -193,6 +193,42 @@ describe('VideoConferenceService', () => {
};
};

it('should call the user service to find the user by id', async () => {
const { userId, scopeId } = setup();

await service.hasExpertRole(userId, VideoConferenceScope.COURSE, scopeId);

expect(userService.findById).toHaveBeenCalledWith(userId);
});

it('should return false', async () => {
const { userId, scopeId } = setup();

const result = await service.hasExpertRole(userId, VideoConferenceScope.COURSE, scopeId);

expect(result).toBe(false);
});
});

describe('when user has the EXPERT role and an additional role for a course conference', () => {
const setup = () => {
const user: UserDO = userDoFactory
.withRoles([
{ id: new ObjectId().toHexString(), name: RoleName.STUDENT },
{ id: new ObjectId().toHexString(), name: RoleName.EXPERT },
])
.buildWithId();
const userId = user.id as EntityId;
const scopeId = new ObjectId().toHexString();

userService.findById.mockResolvedValue(user);

return {
userId,
scopeId,
};
};

it('should return false', async () => {
const { userId, scopeId } = setup();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { CourseService } from '@src/modules/learnroom/service';
import { LegacySchoolService } from '@src/modules/legacy-school';
import { UserService } from '@src/modules/user';
import { BBBRole } from '../bbb';
import { ErrorStatus } from '../error/error-status.enum';
import { ErrorStatus } from '../error';
import { IVideoConferenceSettings, VideoConferenceOptions, VideoConferenceSettings } from '../interface';
import { PermissionScopeMapping } from '../mapper/video-conference.mapper';
import { IScopeInfo, VideoConferenceState } from '../uc/dto';
Expand Down Expand Up @@ -63,7 +63,8 @@ export class VideoConferenceService {
switch (conferenceScope) {
case VideoConferenceScope.COURSE: {
const user: UserDO = await this.userService.findById(userId);
isExpert = this.existsExpertRole(user.roles);
isExpert = this.existsOnlyExpertRole(user.roles);

return isExpert;
}
case VideoConferenceScope.EVENT: {
Expand All @@ -84,10 +85,14 @@ export class VideoConferenceService {
}
}

private existsExpertRole(roles: RoleReference[]): boolean {
private existsOnlyExpertRole(roles: RoleReference[]): boolean {
const roleNames: RoleName[] = roles.map((role: RoleReference) => role.name);

const isExpert: boolean = roleNames.includes(RoleName.EXPERT);
let isExpert: boolean = roleNames.includes(RoleName.EXPERT);

if (isExpert && roles.length > 1) {
isExpert = false;
}

return isExpert;
}
Expand Down