Skip to content

Commit

Permalink
BC-7800 improved exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
Loki-Afro committed Aug 6, 2024
1 parent dac2bd9 commit 47eedbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('rolename mapper', () => {
const setup = () => {
const teacherUser = userFactory.asTeacher().buildWithId();
const studentUser = userFactory.asStudent().buildWithId();
const course = courseFactory.build({
const course = courseFactory.buildWithId({
teachers: [teacherUser],
students: [studentUser],
});
Expand All @@ -48,6 +48,8 @@ describe('rolename mapper', () => {
const role = roleFactory.build({ name: RoleName.EXPERT });
const user = userFactory.buildWithId({ roles: [role] });

expect(() => RoleNameMapper.mapToRoleName(user, course)).toThrowError('Unsupported role');
expect(() => RoleNameMapper.mapToRoleName(user, course)).toThrowError(
`Unable to determine a valid role for user ${user.id} in course ${course.id}`
);
});
});
4 changes: 3 additions & 1 deletion apps/server/src/modules/learnroom/mapper/rolename.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class RoleNameMapper {
if (RoleNameMapper.isSubstitutionTeacher(user, course)) return RoleName.COURSESUBSTITUTIONTEACHER;
if (RoleNameMapper.isStudent(user, course)) return RoleName.STUDENT;

throw new UnprocessableEntityException('Unsupported role');
throw new UnprocessableEntityException(
`Unable to determine a valid role for user ${user.id} in course ${course.id}`
);
}
}

0 comments on commit 47eedbe

Please sign in to comment.