|
|
|
|
@ -7,6 +7,7 @@ import com.sztzjy.linkCommerce.entity.SchoolFaculty;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.SchoolMajor;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.TeachingClassStudent;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.Userinfo;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.UserinfoExample;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.SchoolClassMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.SchoolFacultyMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.SchoolMapper;
|
|
|
|
|
@ -31,6 +32,7 @@ import java.util.List;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.argThat;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
@ -118,6 +120,48 @@ class UserControllerTeacherAdminTest {
|
|
|
|
|
verify(controller.userinfoMapper, never()).updateByPrimaryKey(any(Userinfo.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void teacherManagementListsCurrentSchoolTeachersAndMarksClassOwners() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
Userinfo owner = teacher("teacher-owner");
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-admin")).thenReturn(teacher("teacher-admin", true));
|
|
|
|
|
when(controller.userinfoMapper.selectByExample(any(UserinfoExample.class))).thenReturn(Collections.singletonList(owner));
|
|
|
|
|
when(controller.schoolClassMapper.selectByExample(any(SchoolClassExample.class))).thenReturn(Collections.singletonList(classCreatedBy("teacher-owner")));
|
|
|
|
|
|
|
|
|
|
ResultEntity<PageInfo<Userinfo>> result = controller.selectTeacher(null, null, null, 1, 10, "teacher-admin");
|
|
|
|
|
|
|
|
|
|
ArgumentCaptor<UserinfoExample> exampleCaptor = ArgumentCaptor.forClass(UserinfoExample.class);
|
|
|
|
|
verify(controller.userinfoMapper).selectByExample(exampleCaptor.capture());
|
|
|
|
|
assertEquals(HttpStatus.OK, result.getStatusCode());
|
|
|
|
|
assertTrue(hasUserCondition(exampleCaptor.getValue(), "school_id =", "school-1"));
|
|
|
|
|
assertTrue(result.getBody().getData().getList().get(0).getHasCreatedClass());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void managerTeacherCannotUpdateTeacherWhoCreatedAClass() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
Userinfo owner = teacher("teacher-owner");
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-owner")).thenReturn(owner);
|
|
|
|
|
when(controller.schoolClassMapper.selectByExample(any(SchoolClassExample.class))).thenReturn(Collections.singletonList(classCreatedBy("teacher-owner")));
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.updateTeacher(owner, "teacher-admin");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.userinfoMapper, never()).updateByPrimaryKey(any(Userinfo.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void managerTeacherCannotDeleteTeacherWhoCreatedAClass() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-owner")).thenReturn(teacher("teacher-owner"));
|
|
|
|
|
when(controller.schoolClassMapper.selectByExample(any(SchoolClassExample.class))).thenReturn(Collections.singletonList(classCreatedBy("teacher-owner")));
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.deleteTeacher("teacher-owner", "teacher-admin");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.userinfoMapper, never()).deleteByPrimaryKey("teacher-owner");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void addSchoolClassStoresCreatorTeacher() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
@ -1138,6 +1182,12 @@ class UserControllerTeacherAdminTest {
|
|
|
|
|
.anyMatch(criterion -> condition.equals(criterion.getCondition()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean hasUserCondition(UserinfoExample example, String condition, Object value) {
|
|
|
|
|
return example.getOredCriteria().stream()
|
|
|
|
|
.flatMap(criteria -> criteria.getAllCriteria().stream())
|
|
|
|
|
.anyMatch(criterion -> condition.equals(criterion.getCondition()) && value.equals(criterion.getValue()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TeachingClassStudentImportDTO teachingClassStudentRow(String studentName, String userName) {
|
|
|
|
|
TeachingClassStudentImportDTO row = new TeachingClassStudentImportDTO();
|
|
|
|
|
row.setStudentName(studentName);
|
|
|
|
|
|