|
|
@@ -6,6 +6,9 @@ import com.etotem.cfc.dto.DanReportUploadVO;
|
|
|
import com.etotem.cfc.entity.AssessmentRecord;
|
|
|
import com.etotem.cfc.entity.Task;
|
|
|
import com.etotem.cfc.mapper.ArticleReadingRecordMapper;
|
|
|
+import com.etotem.cfc.mapper.HealthExerciseRecordMapper;
|
|
|
+import com.etotem.cfc.mapper.HealthMealRecordMapper;
|
|
|
+import com.etotem.cfc.mapper.HealthSleepRecordMapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
@@ -41,6 +44,12 @@ public class DailyOverviewServiceTest {
|
|
|
private AssessmentService assessmentService;
|
|
|
@MockBean
|
|
|
private DanReportUploadService danReportUploadService;
|
|
|
+ @MockBean
|
|
|
+ private HealthMealRecordMapper healthMealRecordMapper;
|
|
|
+ @MockBean
|
|
|
+ private HealthSleepRecordMapper healthSleepRecordMapper;
|
|
|
+ @MockBean
|
|
|
+ private HealthExerciseRecordMapper healthExerciseRecordMapper;
|
|
|
|
|
|
@Test
|
|
|
public void aggregate_四类汇总_全部正确() {
|
|
|
@@ -75,7 +84,7 @@ public class DailyOverviewServiceTest {
|
|
|
DailyOverviewVO vo = service.aggregate(1L, 10L, 100L);
|
|
|
|
|
|
assertEquals(10L, vo.getMemberId().longValue());
|
|
|
- assertEquals(3, vo.getCheckins().size());
|
|
|
+ assertEquals(6, vo.getCheckins().size());
|
|
|
assertFalse(vo.getCheckins().get(0).getDone());
|
|
|
|
|
|
assertEquals(Integer.valueOf(1), vo.getTasks().getPendingAccept());
|
|
|
@@ -87,4 +96,93 @@ public class DailyOverviewServiceTest {
|
|
|
assertEquals(Integer.valueOf(1), vo.getAssessments().getOngoing());
|
|
|
assertEquals(Integer.valueOf(0), vo.getAssessments().getReportPending());
|
|
|
}
|
|
|
+
|
|
|
+ /** 首页「打卡」分组应下发 6 项:健康/财商/情绪/饮食/睡眠/运动,路由指向各自打卡页 */
|
|
|
+ @Test
|
|
|
+ public void aggregate_打卡分组_下发六项且路由正确() {
|
|
|
+ stubEmptyCheckins();
|
|
|
+ stubZeroNewCheckinCounts();
|
|
|
+
|
|
|
+ DailyOverviewVO vo = service.aggregate(1L, 10L, 100L);
|
|
|
+
|
|
|
+ List<DailyOverviewVO.CheckinItem> checkins = vo.getCheckins();
|
|
|
+ assertEquals(6, checkins.size());
|
|
|
+
|
|
|
+ assertEquals(Arrays.asList("health", "wealth", "mind", "diet", "sleep", "exercise"), keys(checkins));
|
|
|
+ assertEquals(Arrays.asList("健康打卡", "财商打卡", "情绪打卡", "饮食打卡", "睡眠打卡", "运动打卡"), labels(checkins));
|
|
|
+ assertEquals(Arrays.asList(
|
|
|
+ "/pages/health/daily-checkin",
|
|
|
+ "/pages/wealth-sub/checkin",
|
|
|
+ "/pages/mind-detail/emotion-checkin",
|
|
|
+ "/pages/growth/diet-checkin",
|
|
|
+ "/pages/growth/sleep-checkin",
|
|
|
+ "/pages/growth/exercise-checkin"),
|
|
|
+ routes(checkins));
|
|
|
+
|
|
|
+ for (DailyOverviewVO.CheckinItem item : checkins) {
|
|
|
+ assertFalse(item.getDone(), item.getKey() + " 无今日记录时应为未完成");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 今日已有饮食/睡眠/运动记录时,对应打卡项 done 应为 true(首页显示 ✓) */
|
|
|
+ @Test
|
|
|
+ public void aggregate_今日已有饮食睡眠运动记录_done为true() {
|
|
|
+ stubEmptyCheckins();
|
|
|
+ stubZeroNewCheckinCounts();
|
|
|
+
|
|
|
+ // 饮食/睡眠/运动各有 1 条今日记录
|
|
|
+ when(healthMealRecordMapper.selectCount(any(LambdaQueryWrapper.class))).thenReturn(1L);
|
|
|
+ when(healthSleepRecordMapper.selectCount(any(LambdaQueryWrapper.class))).thenReturn(1L);
|
|
|
+ when(healthExerciseRecordMapper.selectCount(any(LambdaQueryWrapper.class))).thenReturn(1L);
|
|
|
+
|
|
|
+ DailyOverviewVO vo = service.aggregate(1L, 10L, 100L);
|
|
|
+
|
|
|
+ Map<String, Boolean> doneByKey = new LinkedHashMap<>();
|
|
|
+ for (DailyOverviewVO.CheckinItem item : vo.getCheckins()) {
|
|
|
+ doneByKey.put(item.getKey(), item.getDone());
|
|
|
+ }
|
|
|
+ assertFalse(doneByKey.get("health"));
|
|
|
+ assertFalse(doneByKey.get("wealth"));
|
|
|
+ assertFalse(doneByKey.get("mind"));
|
|
|
+ assertTrue(doneByKey.get("diet"), "今日已有饮食记录,饮食打卡应显示完成");
|
|
|
+ assertTrue(doneByKey.get("sleep"), "今日已有睡眠记录,睡眠打卡应显示完成");
|
|
|
+ assertTrue(doneByKey.get("exercise"), "今日已有运动记录,运动打卡应显示完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void stubEmptyCheckins() {
|
|
|
+ when(healthCheckinService.getCheckins(any(), any(), any())).thenReturn(Collections.emptyList());
|
|
|
+ when(financeCheckinService.getCheckins(any(), any(), any())).thenReturn(Collections.emptyList());
|
|
|
+ when(emotionCheckinService.getCheckinList(any(), anyInt(), anyInt(), any(), anyBoolean()))
|
|
|
+ .thenReturn(Collections.emptyList());
|
|
|
+ when(taskService.getMyPendingTasks(any())).thenReturn(Collections.emptyList());
|
|
|
+ when(growthTaskService.getTaskList(any(), anyMap())).thenReturn(Collections.emptyList());
|
|
|
+ when(articleReadingRecordMapper.selectCount(any(LambdaQueryWrapper.class))).thenReturn(0L);
|
|
|
+ when(assessmentService.getFamilyRecords(any())).thenReturn(Collections.emptyList());
|
|
|
+ when(danReportUploadService.listByMember(any(), any()))
|
|
|
+ .thenReturn(Result.success(Collections.<DanReportUploadVO>emptyList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void stubZeroNewCheckinCounts() {
|
|
|
+ when(healthMealRecordMapper.selectCount(any(LambdaQueryWrapper.class))).thenReturn(0L);
|
|
|
+ when(healthSleepRecordMapper.selectCount(any(LambdaQueryWrapper.class))).thenReturn(0L);
|
|
|
+ when(healthExerciseRecordMapper.selectCount(any(LambdaQueryWrapper.class))).thenReturn(0L);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> keys(List<DailyOverviewVO.CheckinItem> items) {
|
|
|
+ List<String> r = new ArrayList<>();
|
|
|
+ for (DailyOverviewVO.CheckinItem i : items) r.add(i.getKey());
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> labels(List<DailyOverviewVO.CheckinItem> items) {
|
|
|
+ List<String> r = new ArrayList<>();
|
|
|
+ for (DailyOverviewVO.CheckinItem i : items) r.add(i.getLabel());
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> routes(List<DailyOverviewVO.CheckinItem> items) {
|
|
|
+ List<String> r = new ArrayList<>();
|
|
|
+ for (DailyOverviewVO.CheckinItem i : items) r.add(i.getRoute());
|
|
|
+ return r;
|
|
|
+ }
|
|
|
}
|