|
@@ -11,6 +11,7 @@ import com.etotem.cfc.entity.User;
|
|
|
import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
|
|
|
+import com.etotem.cfc.service.GuideFamilyAccessGuard;
|
|
|
import com.etotem.cfc.service.TaskService;
|
|
import com.etotem.cfc.service.TaskService;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
@@ -42,6 +43,9 @@ public class GuideFamilyTaskControllerTest {
|
|
|
@MockBean
|
|
@MockBean
|
|
|
private TaskMapper taskMapper;
|
|
private TaskMapper taskMapper;
|
|
|
|
|
|
|
|
|
|
+ @MockBean
|
|
|
|
|
+ private GuideFamilyAccessGuard guideFamilyAccessGuard;
|
|
|
|
|
+
|
|
|
private User mockUser(Long id, String role, String nickname) {
|
|
private User mockUser(Long id, String role, String nickname) {
|
|
|
User user = new User();
|
|
User user = new User();
|
|
|
user.setId(id);
|
|
user.setId(id);
|
|
@@ -94,7 +98,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
params.put("page", 1);
|
|
params.put("page", 1);
|
|
|
params.put("size", 10);
|
|
params.put("size", 10);
|
|
|
for (String role : NON_TEACHER_ROLES) {
|
|
for (String role : NON_TEACHER_ROLES) {
|
|
|
- Result<?> result = controller.getFamilyMemberTasks(100L, 20L, role, params);
|
|
|
|
|
|
|
+ Result<?> result = controller.getFamilyMemberTasks(1L, 100L, 20L, role, params);
|
|
|
assertRoleDenied(result);
|
|
assertRoleDenied(result);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -102,7 +106,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
@Test
|
|
@Test
|
|
|
public void getPendingReviewTasks_NonTeacherRole_AccessDenied() {
|
|
public void getPendingReviewTasks_NonTeacherRole_AccessDenied() {
|
|
|
for (String role : NON_TEACHER_ROLES) {
|
|
for (String role : NON_TEACHER_ROLES) {
|
|
|
- Result<?> result = controller.getPendingReviewTasks(100L, 20L, role);
|
|
|
|
|
|
|
+ Result<?> result = controller.getPendingReviewTasks(1L, 100L, 20L, role);
|
|
|
assertRoleDenied(result);
|
|
assertRoleDenied(result);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -112,7 +116,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
TaskReviewDTO dto = new TaskReviewDTO();
|
|
TaskReviewDTO dto = new TaskReviewDTO();
|
|
|
dto.setApproved(true);
|
|
dto.setApproved(true);
|
|
|
for (String role : NON_TEACHER_ROLES) {
|
|
for (String role : NON_TEACHER_ROLES) {
|
|
|
- Result<?> result = controller.reviewTask(100L, 1L, role, dto);
|
|
|
|
|
|
|
+ Result<?> result = controller.reviewTask(1L, 100L, 1L, role, dto);
|
|
|
assertRoleDenied(result);
|
|
assertRoleDenied(result);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -123,7 +127,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
params.put("taskIds", Arrays.asList(1L, 2L));
|
|
params.put("taskIds", Arrays.asList(1L, 2L));
|
|
|
params.put("approved", true);
|
|
params.put("approved", true);
|
|
|
for (String role : NON_TEACHER_ROLES) {
|
|
for (String role : NON_TEACHER_ROLES) {
|
|
|
- Result<?> result = controller.batchReviewTasks(100L, role, params);
|
|
|
|
|
|
|
+ Result<?> result = controller.batchReviewTasks(1L, 100L, role, params);
|
|
|
assertRoleDenied(result);
|
|
assertRoleDenied(result);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -133,7 +137,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
Map<String, Object> taskData = new HashMap<>();
|
|
Map<String, Object> taskData = new HashMap<>();
|
|
|
taskData.put("title", "新标题");
|
|
taskData.put("title", "新标题");
|
|
|
for (String role : NON_TEACHER_ROLES) {
|
|
for (String role : NON_TEACHER_ROLES) {
|
|
|
- Result<?> result = controller.updateTask(100L, 1L, role, taskData);
|
|
|
|
|
|
|
+ Result<?> result = controller.updateTask(1L, 100L, 1L, role, taskData);
|
|
|
assertRoleDenied(result);
|
|
assertRoleDenied(result);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -141,7 +145,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
@Test
|
|
@Test
|
|
|
public void deleteTask_NonTeacherRole_AccessDenied() {
|
|
public void deleteTask_NonTeacherRole_AccessDenied() {
|
|
|
for (String role : NON_TEACHER_ROLES) {
|
|
for (String role : NON_TEACHER_ROLES) {
|
|
|
- Result<?> result = controller.deleteTask(100L, 1L, role);
|
|
|
|
|
|
|
+ Result<?> result = controller.deleteTask(1L, 100L, 1L, role);
|
|
|
assertRoleDenied(result);
|
|
assertRoleDenied(result);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -210,7 +214,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
params.put("page", 1);
|
|
params.put("page", 1);
|
|
|
params.put("size", 10);
|
|
params.put("size", 10);
|
|
|
|
|
|
|
|
- Result<Page<Task>> result = controller.getFamilyMemberTasks(familyId, childId, "teacher", params);
|
|
|
|
|
|
|
+ Result<Page<Task>> result = controller.getFamilyMemberTasks(1L, familyId, childId, "teacher", params);
|
|
|
Page<Task> page = result.getData();
|
|
Page<Task> page = result.getData();
|
|
|
assertEquals(2, page.getTotal());
|
|
assertEquals(2, page.getTotal());
|
|
|
assertEquals(2, page.getRecords().size());
|
|
assertEquals(2, page.getRecords().size());
|
|
@@ -225,7 +229,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
);
|
|
);
|
|
|
when(taskService.getPendingReviewTasksForChild(childId)).thenReturn(pendingTasks);
|
|
when(taskService.getPendingReviewTasksForChild(childId)).thenReturn(pendingTasks);
|
|
|
|
|
|
|
|
- Result<List<Task>> result = controller.getPendingReviewTasks(familyId, childId, "teacher");
|
|
|
|
|
|
|
+ Result<List<Task>> result = controller.getPendingReviewTasks(1L, familyId, childId, "teacher");
|
|
|
assertEquals(1, result.getData().size());
|
|
assertEquals(1, result.getData().size());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -239,7 +243,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
|
|
|
|
|
when(taskService.reviewTask(eq(taskId), any(TaskReviewDTO.class))).thenReturn(true);
|
|
when(taskService.reviewTask(eq(taskId), any(TaskReviewDTO.class))).thenReturn(true);
|
|
|
|
|
|
|
|
- Result<Boolean> result = controller.reviewTask(familyId, taskId, "teacher", dto);
|
|
|
|
|
|
|
+ Result<Boolean> result = controller.reviewTask(1L, familyId, taskId, "teacher", dto);
|
|
|
assertTrue(result.getData());
|
|
assertTrue(result.getData());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -254,7 +258,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
|
|
|
|
|
when(taskService.reviewTask(anyLong(), any(TaskReviewDTO.class))).thenReturn(true);
|
|
when(taskService.reviewTask(anyLong(), any(TaskReviewDTO.class))).thenReturn(true);
|
|
|
|
|
|
|
|
- Result<Map<String, Object>> result = controller.batchReviewTasks(familyId, "teacher", params);
|
|
|
|
|
|
|
+ Result<Map<String, Object>> result = controller.batchReviewTasks(1L, familyId, "teacher", params);
|
|
|
Map<String, Object> data = result.getData();
|
|
Map<String, Object> data = result.getData();
|
|
|
assertEquals(3, data.get("successCount"));
|
|
assertEquals(3, data.get("successCount"));
|
|
|
assertEquals(0, data.get("failCount"));
|
|
assertEquals(0, data.get("failCount"));
|
|
@@ -273,7 +277,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
taskData.put("description", "新描述");
|
|
taskData.put("description", "新描述");
|
|
|
taskData.put("points", 20);
|
|
taskData.put("points", 20);
|
|
|
|
|
|
|
|
- Result<Boolean> result = controller.updateTask(familyId, taskId, "teacher", taskData);
|
|
|
|
|
|
|
+ Result<Boolean> result = controller.updateTask(1L, familyId, taskId, "teacher", taskData);
|
|
|
assertTrue(result.getData());
|
|
assertTrue(result.getData());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -283,7 +287,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
|
|
|
|
|
Map<String, Object> taskData = new HashMap<>();
|
|
Map<String, Object> taskData = new HashMap<>();
|
|
|
taskData.put("title", "新标题");
|
|
taskData.put("title", "新标题");
|
|
|
- Result<Boolean> result = controller.updateTask(100L, 999L, "teacher", taskData);
|
|
|
|
|
|
|
+ Result<Boolean> result = controller.updateTask(1L, 100L, 999L, "teacher", taskData);
|
|
|
assertEquals("任务不存在", result.getMessage());
|
|
assertEquals("任务不存在", result.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -295,7 +299,7 @@ public class GuideFamilyTaskControllerTest {
|
|
|
|
|
|
|
|
Map<String, Object> taskData = new HashMap<>();
|
|
Map<String, Object> taskData = new HashMap<>();
|
|
|
taskData.put("title", "新标题");
|
|
taskData.put("title", "新标题");
|
|
|
- Result<Boolean> result = controller.updateTask(100L, taskId, "teacher", taskData);
|
|
|
|
|
|
|
+ Result<Boolean> result = controller.updateTask(1L, 100L, taskId, "teacher", taskData);
|
|
|
assertEquals("任务不属于该家庭", result.getMessage());
|
|
assertEquals("任务不属于该家庭", result.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -307,14 +311,14 @@ public class GuideFamilyTaskControllerTest {
|
|
|
when(taskMapper.selectById(taskId)).thenReturn(task);
|
|
when(taskMapper.selectById(taskId)).thenReturn(task);
|
|
|
when(taskMapper.updateById(any(Task.class))).thenReturn(1);
|
|
when(taskMapper.updateById(any(Task.class))).thenReturn(1);
|
|
|
|
|
|
|
|
- Result<Boolean> result = controller.deleteTask(familyId, taskId, "teacher");
|
|
|
|
|
|
|
+ Result<Boolean> result = controller.deleteTask(1L, familyId, taskId, "teacher");
|
|
|
assertTrue(result.getData());
|
|
assertTrue(result.getData());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void deleteTask_NotFound_ReturnsError() {
|
|
public void deleteTask_NotFound_ReturnsError() {
|
|
|
when(taskMapper.selectById(999L)).thenReturn(null);
|
|
when(taskMapper.selectById(999L)).thenReturn(null);
|
|
|
- Result<Boolean> result = controller.deleteTask(100L, 999L, "teacher");
|
|
|
|
|
|
|
+ Result<Boolean> result = controller.deleteTask(1L, 100L, 999L, "teacher");
|
|
|
assertEquals("任务不存在", result.getMessage());
|
|
assertEquals("任务不存在", result.getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|