|
|
|
|
@ -156,9 +156,15 @@ class UserControllerTeacherAdminTest {
|
|
|
|
|
void teacherManagementListsCurrentSchoolTeachersAndMarksClassOwners() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
Userinfo owner = teacher("teacher-owner");
|
|
|
|
|
SchoolClass ownedClass = classCreatedBy("teacher-owner");
|
|
|
|
|
ownedClass.setSchoolClassId("class-owned");
|
|
|
|
|
ownedClass.setClassName("产品一班");
|
|
|
|
|
TeachingClassStudent member = activeMember("class-owned", "student-1");
|
|
|
|
|
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")));
|
|
|
|
|
when(controller.schoolClassMapper.selectByExample(any(SchoolClassExample.class))).thenReturn(Collections.singletonList(ownedClass));
|
|
|
|
|
when(controller.teachingClassStudentMapper.selectByTeachingClassId("class-owned"))
|
|
|
|
|
.thenReturn(Collections.singletonList(member));
|
|
|
|
|
|
|
|
|
|
ResultEntity<PageInfo<Userinfo>> result = controller.selectTeacher(null, null, null, 1, 10, "teacher-admin");
|
|
|
|
|
|
|
|
|
|
@ -167,6 +173,49 @@ class UserControllerTeacherAdminTest {
|
|
|
|
|
assertEquals(HttpStatus.OK, result.getStatusCode());
|
|
|
|
|
assertTrue(hasUserCondition(exampleCaptor.getValue(), "school_id =", "school-1"));
|
|
|
|
|
assertTrue(result.getBody().getData().getList().get(0).getHasCreatedClass());
|
|
|
|
|
assertEquals(Collections.singletonList("产品一班"),
|
|
|
|
|
result.getBody().getData().getList().get(0).getOwnedClassNames());
|
|
|
|
|
assertEquals(1, result.getBody().getData().getList().get(0).getOwnedStudentCount());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void teacherAdminCanResetTeacherPasswordInSameSchool() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
Userinfo target = teacher("teacher-2");
|
|
|
|
|
target.setPassword("changed-password");
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-2")).thenReturn(target);
|
|
|
|
|
when(controller.userinfoMapper.updateByPrimaryKey(target)).thenReturn(1);
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.updateTeacher("teacher-2", "teacher-admin");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.OK, result.getStatusCode());
|
|
|
|
|
assertEquals("123qwe", target.getPassword());
|
|
|
|
|
verify(controller.userinfoMapper).updateByPrimaryKey(target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void ordinaryTeacherCannotResetAnotherTeacherPassword() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
Userinfo target = teacher("teacher-2");
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-2")).thenReturn(target);
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.updateTeacher("teacher-2", "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.userinfoMapper, never()).updateByPrimaryKey(target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void teacherAdminCannotResetTeacherPasswordFromAnotherSchool() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
Userinfo target = teacher("teacher-2");
|
|
|
|
|
target.setSchoolId("school-2");
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-2")).thenReturn(target);
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.updateTeacher("teacher-2", "teacher-admin");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.userinfoMapper, never()).updateByPrimaryKey(target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|