|
|
|
|
@ -669,6 +669,113 @@ class TrainingTaskServiceImplTest {
|
|
|
|
|
assertNull(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void studentListReturnsComprehensiveTrainingWhenPublishedAndEnabledForTheClass() {
|
|
|
|
|
TrainingTaskServiceImpl service = studentTaskService("class-1");
|
|
|
|
|
TrainingTask legacy = storedTask("task-1", "new-product-survey");
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectList(null, null, null)).thenReturn(List.of(legacy, comprehensive));
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectListByTeachingClass("class-1", null))
|
|
|
|
|
.thenReturn(List.of(overrideTask("config-1", "class-1", "new-product-survey"),
|
|
|
|
|
overrideTask("config-2", "class-1", "comprehensive-case-training")));
|
|
|
|
|
when(service.taskAllocationMapper.selectByExample(any())).thenReturn(List.of(
|
|
|
|
|
taskAllocation(TaskAllocation.PUBLICATION_MARKER, (byte) 1),
|
|
|
|
|
taskAllocation("new-product-survey", (byte) 0),
|
|
|
|
|
taskAllocation("comprehensive-case-training", (byte) 0)));
|
|
|
|
|
|
|
|
|
|
List<TrainingTask> result = service.listForStudent("stu-1", true);
|
|
|
|
|
|
|
|
|
|
assertEquals(List.of("new-product-survey", "comprehensive-case-training"), result.stream()
|
|
|
|
|
.map(TrainingTask::getTaskKey)
|
|
|
|
|
.collect(java.util.stream.Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void studentListHidesComprehensiveTrainingWhenThePublishedKeyIsRemoved() {
|
|
|
|
|
TrainingTaskServiceImpl service = studentTaskService("class-1");
|
|
|
|
|
TrainingTask legacy = storedTask("task-1", "new-product-survey");
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectList(null, null, null)).thenReturn(List.of(legacy, comprehensive));
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectListByTeachingClass("class-1", null))
|
|
|
|
|
.thenReturn(List.of(overrideTask("config-1", "class-1", "new-product-survey"),
|
|
|
|
|
overrideTask("config-2", "class-1", "comprehensive-case-training")));
|
|
|
|
|
when(service.taskAllocationMapper.selectByExample(any())).thenReturn(List.of(
|
|
|
|
|
taskAllocation(TaskAllocation.PUBLICATION_MARKER, (byte) 1),
|
|
|
|
|
taskAllocation("new-product-survey", (byte) 0)));
|
|
|
|
|
|
|
|
|
|
List<TrainingTask> result = service.listForStudent("stu-1", true);
|
|
|
|
|
|
|
|
|
|
assertEquals(List.of("new-product-survey"), result.stream()
|
|
|
|
|
.map(TrainingTask::getTaskKey)
|
|
|
|
|
.collect(java.util.stream.Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void studentListHidesComprehensiveTrainingWhenItsPublishedAllocationIsDisabled() {
|
|
|
|
|
TrainingTaskServiceImpl service = studentTaskService("class-1");
|
|
|
|
|
TrainingTask legacy = storedTask("task-1", "new-product-survey");
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectList(null, null, null)).thenReturn(List.of(legacy, comprehensive));
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectListByTeachingClass("class-1", null))
|
|
|
|
|
.thenReturn(List.of(overrideTask("config-1", "class-1", "new-product-survey"),
|
|
|
|
|
overrideTask("config-2", "class-1", "comprehensive-case-training")));
|
|
|
|
|
when(service.taskAllocationMapper.selectByExample(any())).thenReturn(List.of(
|
|
|
|
|
taskAllocation(TaskAllocation.PUBLICATION_MARKER, (byte) 1),
|
|
|
|
|
taskAllocation("new-product-survey", (byte) 0),
|
|
|
|
|
taskAllocation("comprehensive-case-training", (byte) 1)));
|
|
|
|
|
|
|
|
|
|
List<TrainingTask> result = service.listForStudent("stu-1", true);
|
|
|
|
|
|
|
|
|
|
assertEquals(List.of("new-product-survey"), result.stream()
|
|
|
|
|
.map(TrainingTask::getTaskKey)
|
|
|
|
|
.collect(java.util.stream.Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void studentListHidesDisabledComprehensiveTrainingWhenDisabledTasksAreRequested() {
|
|
|
|
|
TrainingTaskServiceImpl service = studentTaskService("class-1");
|
|
|
|
|
TrainingTask legacy = storedTask("task-1", "new-product-survey");
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectList(null, null, null)).thenReturn(List.of(legacy, comprehensive));
|
|
|
|
|
TrainingTaskClassConfig disabled = overrideTask("config-2", "class-1", "comprehensive-case-training");
|
|
|
|
|
disabled.setEnabled(Boolean.FALSE);
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectListByTeachingClass("class-1", null))
|
|
|
|
|
.thenReturn(List.of(overrideTask("config-1", "class-1", "new-product-survey"), disabled));
|
|
|
|
|
when(service.taskAllocationMapper.selectByExample(any())).thenReturn(List.of(
|
|
|
|
|
taskAllocation(TaskAllocation.PUBLICATION_MARKER, (byte) 1),
|
|
|
|
|
taskAllocation("new-product-survey", (byte) 0),
|
|
|
|
|
taskAllocation("comprehensive-case-training", (byte) 0)));
|
|
|
|
|
|
|
|
|
|
List<TrainingTask> result = service.listForStudent("stu-1", false);
|
|
|
|
|
|
|
|
|
|
assertEquals(List.of("new-product-survey"), result.stream()
|
|
|
|
|
.map(TrainingTask::getTaskKey)
|
|
|
|
|
.collect(java.util.stream.Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void teacherClassTaskListIncludesComprehensiveTrainingWithoutPublication() {
|
|
|
|
|
TrainingTaskServiceImpl service = new TrainingTaskServiceImpl();
|
|
|
|
|
service.trainingTaskMapper = mock(TrainingTaskMapper.class);
|
|
|
|
|
service.trainingTaskClassConfigMapper = mock(TrainingTaskClassConfigMapper.class);
|
|
|
|
|
service.schoolClassMapper = mock(SchoolClassMapper.class);
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectList(null, null, null)).thenReturn(List.of(comprehensive));
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectListByTeachingClass("class-1", null)).thenReturn(Collections.emptyList());
|
|
|
|
|
SchoolClass schoolClass = teachingClass("class-1", "teacher-1");
|
|
|
|
|
schoolClass.setSchoolId("school-1");
|
|
|
|
|
when(service.schoolClassMapper.selectByPrimaryKey("class-1")).thenReturn(schoolClass);
|
|
|
|
|
JwtUser teacher = new JwtUser();
|
|
|
|
|
teacher.setUserId("teacher-1");
|
|
|
|
|
teacher.setSchoolId("school-1");
|
|
|
|
|
|
|
|
|
|
List<TrainingTask> result = service.listForTeachingClass("class-1", true, teacher);
|
|
|
|
|
|
|
|
|
|
assertEquals(List.of("comprehensive-case-training"), result.stream()
|
|
|
|
|
.map(TrainingTask::getTaskKey)
|
|
|
|
|
.collect(java.util.stream.Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TrainingTaskServiceImpl studentTaskService(String teachingClassId) {
|
|
|
|
|
TrainingTaskServiceImpl service = new TrainingTaskServiceImpl();
|
|
|
|
|
service.trainingTaskMapper = mock(TrainingTaskMapper.class);
|
|
|
|
|
|