|
|
@@ -0,0 +1,85 @@
|
|
|
+package com.etotem.cfc.service;
|
|
|
+
|
|
|
+import com.etotem.cfc.dto.FamilyReportCreateDTO;
|
|
|
+import com.etotem.cfc.entity.HealthReport;
|
|
|
+import com.etotem.cfc.mapper.FamilyMapper;
|
|
|
+import com.etotem.cfc.mapper.FamilyWorkbenchMapper;
|
|
|
+import com.etotem.cfc.mapper.HealthReportMapper;
|
|
|
+import com.etotem.cfc.service.impl.FamilyWorkbenchServiceImpl;
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.mockito.ArgumentCaptor;
|
|
|
+import org.mockito.InjectMocks;
|
|
|
+import org.mockito.Mock;
|
|
|
+import org.mockito.MockitoAnnotations;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 报告手动新增契约:类型白名单校验、family_id/user_id/status 固定来自服务端(不可注入)、reportDate 默认当天。
|
|
|
+ */
|
|
|
+class FamilyWorkbenchReportCreateTest {
|
|
|
+
|
|
|
+ @Mock private FamilyMapper familyMapper;
|
|
|
+ @Mock private FamilyWorkbenchMapper workbenchMapper;
|
|
|
+ @Mock private HealthReportMapper reportMapper;
|
|
|
+ @InjectMocks private FamilyWorkbenchServiceImpl service;
|
|
|
+
|
|
|
+ @BeforeEach
|
|
|
+ void setUp() {
|
|
|
+ MockitoAnnotations.openMocks(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void 非法报告类型_拒绝() {
|
|
|
+ FamilyReportCreateDTO dto = new FamilyReportCreateDTO();
|
|
|
+ dto.setReportType("unknown_type");
|
|
|
+ RuntimeException e = assertThrows(RuntimeException.class,
|
|
|
+ () -> service.createFamilyReport(5L, 88L, dto));
|
|
|
+ assertTrue(e.getMessage().contains("报告类型不合法"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void 合法创建_familyId和userId固定来自URL且状态active() {
|
|
|
+ FamilyReportCreateDTO dto = new FamilyReportCreateDTO();
|
|
|
+ dto.setReportType("physical_exam");
|
|
|
+ dto.setReportDate(new Date());
|
|
|
+ dto.setPersonName("小明");
|
|
|
+ dto.setOverallScore(88);
|
|
|
+ when(reportMapper.insert(any(HealthReport.class))).thenReturn(1);
|
|
|
+
|
|
|
+ Long id = service.createFamilyReport(5L, 88L, dto);
|
|
|
+
|
|
|
+ ArgumentCaptor<HealthReport> cap = ArgumentCaptor.forClass(HealthReport.class);
|
|
|
+ verify(reportMapper).insert(cap.capture());
|
|
|
+ HealthReport r = cap.getValue();
|
|
|
+ assertEquals(5L, r.getFamilyId(), "family_id 必须固定为 URL 值");
|
|
|
+ assertEquals(88L, r.getUserId(), "user_id 必须为当前操作人");
|
|
|
+ assertEquals("active", r.getStatus());
|
|
|
+ assertEquals("physical_exam", r.getReportType());
|
|
|
+ assertEquals("小明", r.getPersonName());
|
|
|
+ assertEquals(Integer.valueOf(88), r.getOverallScore());
|
|
|
+ assertNotNull(r.getReportDate());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void 报告日期为空_默认当天() {
|
|
|
+ FamilyReportCreateDTO dto = new FamilyReportCreateDTO();
|
|
|
+ dto.setReportType("gut_flora");
|
|
|
+ when(reportMapper.insert(any(HealthReport.class))).thenReturn(1);
|
|
|
+
|
|
|
+ service.createFamilyReport(5L, 88L, dto);
|
|
|
+
|
|
|
+ ArgumentCaptor<HealthReport> cap = ArgumentCaptor.forClass(HealthReport.class);
|
|
|
+ verify(reportMapper).insert(cap.capture());
|
|
|
+ assertNotNull(cap.getValue().getReportDate(), "reportDate 缺省应填当天");
|
|
|
+ }
|
|
|
+}
|