|
|
|
|
@ -4,15 +4,20 @@ import com.sztzjy.linkCommerce.config.exception.handler.ServiceException;
|
|
|
|
|
import com.sztzjy.linkCommerce.config.security.JwtUser;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.SchoolClass;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.TeachingClassScoreWeight;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.TeachingClassTeacherScore;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.SchoolClassMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.TeachingClassScoreWeightMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.TeachingClassStudentMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.TeachingClassTeacherScoreMapper;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
|
|
class TeacherScoreServiceImplTest {
|
|
|
|
|
@ -49,6 +54,42 @@ class TeacherScoreServiceImplTest {
|
|
|
|
|
assertEquals(HttpStatus.FORBIDDEN, error.getCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void savesTeacherScoreForStudentInOwnedTeachingClass() {
|
|
|
|
|
TeacherScoreServiceImpl service = new TeacherScoreServiceImpl();
|
|
|
|
|
SchoolClassMapper classMapper = mock(SchoolClassMapper.class);
|
|
|
|
|
TeachingClassStudentMapper memberMapper = mock(TeachingClassStudentMapper.class);
|
|
|
|
|
TeachingClassTeacherScoreMapper scoreMapper = mock(TeachingClassTeacherScoreMapper.class);
|
|
|
|
|
ReflectionTestUtils.setField(service, "schoolClassMapper", classMapper);
|
|
|
|
|
ReflectionTestUtils.setField(service, "teachingClassStudentMapper", memberMapper);
|
|
|
|
|
ReflectionTestUtils.setField(service, "teacherScoreMapper", scoreMapper);
|
|
|
|
|
when(classMapper.selectByPrimaryKey("class-1")).thenReturn(classRow("class-1", "teacher-1", "school-1"));
|
|
|
|
|
when(memberMapper.countByStudentUserIdAndTeachingClassId("student-1", "class-1")).thenReturn(1L);
|
|
|
|
|
|
|
|
|
|
TeachingClassTeacherScore saved = service.saveTeacherScore(
|
|
|
|
|
teacher("teacher-1", "school-1"), "class-1", "student-1", new java.math.BigDecimal("88.126"));
|
|
|
|
|
|
|
|
|
|
assertEquals(new java.math.BigDecimal("88.13"), saved.getTeacherScore());
|
|
|
|
|
assertEquals("teacher-1", saved.getScoredBy());
|
|
|
|
|
verify(scoreMapper).upsert(saved);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void rejectsTeacherScoreOutsideZeroToOneHundred() {
|
|
|
|
|
TeacherScoreServiceImpl service = new TeacherScoreServiceImpl();
|
|
|
|
|
SchoolClassMapper classMapper = mock(SchoolClassMapper.class);
|
|
|
|
|
TeachingClassStudentMapper memberMapper = mock(TeachingClassStudentMapper.class);
|
|
|
|
|
ReflectionTestUtils.setField(service, "schoolClassMapper", classMapper);
|
|
|
|
|
ReflectionTestUtils.setField(service, "teachingClassStudentMapper", memberMapper);
|
|
|
|
|
when(classMapper.selectByPrimaryKey("class-1")).thenReturn(classRow("class-1", "teacher-1", "school-1"));
|
|
|
|
|
when(memberMapper.countByStudentUserIdAndTeachingClassId("student-1", "class-1")).thenReturn(1L);
|
|
|
|
|
|
|
|
|
|
ServiceException error = assertThrows(ServiceException.class, () -> service.saveTeacherScore(
|
|
|
|
|
teacher("teacher-1", "school-1"), "class-1", "student-1", new java.math.BigDecimal("100.01")));
|
|
|
|
|
|
|
|
|
|
assertTrue(error.getMessage().contains("0至100"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JwtUser teacher(String userId, String schoolId) {
|
|
|
|
|
JwtUser user = new JwtUser();
|
|
|
|
|
user.setUserId(userId);
|
|
|
|
|
|