|
|
@@ -0,0 +1,100 @@
|
|
|
+package com.etotem.cfc.unit;
|
|
|
+
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.Activity;
|
|
|
+import com.etotem.cfc.entity.ActivityRegistration;
|
|
|
+import com.etotem.cfc.mapper.ActivityMapper;
|
|
|
+import com.etotem.cfc.mapper.ActivityRegistrationMapper;
|
|
|
+import com.etotem.cfc.service.ActivityRegistrationService;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
+import static org.mockito.Mockito.*;
|
|
|
+
|
|
|
+class ActivityRegistrationListTest {
|
|
|
+
|
|
|
+ private ActivityRegistrationService serviceWith(ActivityRegistrationMapper regMapper,
|
|
|
+ ActivityMapper actMapper) throws Exception {
|
|
|
+ ActivityRegistrationService svc = new ActivityRegistrationService();
|
|
|
+ setField(svc, "registrationMapper", regMapper);
|
|
|
+ setField(svc, "activityMapper", actMapper);
|
|
|
+ return svc;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setField(Object target, String name, Object value) throws Exception {
|
|
|
+ Field f = ActivityRegistrationService.class.getDeclaredField(name);
|
|
|
+ f.setAccessible(true);
|
|
|
+ f.set(target, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void 全局列表补充活动标题与驳回原因() throws Exception {
|
|
|
+ ActivityRegistrationMapper regMapper = mock(ActivityRegistrationMapper.class);
|
|
|
+ ActivityMapper actMapper = mock(ActivityMapper.class);
|
|
|
+ ActivityRegistrationService svc = serviceWith(regMapper, actMapper);
|
|
|
+
|
|
|
+ ActivityRegistration reg = new ActivityRegistration();
|
|
|
+ reg.setId(1L);
|
|
|
+ reg.setActivityId(5L);
|
|
|
+ reg.setStatus("rejected");
|
|
|
+ reg.setRegistrantName("张三");
|
|
|
+ reg.setRejectReason("名额已满");
|
|
|
+
|
|
|
+ Activity act = new Activity();
|
|
|
+ act.setId(5L);
|
|
|
+ act.setTitle("亲子营");
|
|
|
+
|
|
|
+ when(regMapper.selectList(any())).thenReturn(Arrays.asList(reg));
|
|
|
+ when(actMapper.selectBatchIds(any())).thenReturn(Arrays.asList(act));
|
|
|
+
|
|
|
+ Result<List<Map<String, Object>>> result = svc.listRegistrationsForAdmin(null, "rejected");
|
|
|
+
|
|
|
+ assertEquals(200, result.getCode());
|
|
|
+ assertEquals(1, result.getData().size());
|
|
|
+ Map<String, Object> row = result.getData().get(0);
|
|
|
+ assertEquals(1L, row.get("id"));
|
|
|
+ assertEquals(5L, row.get("activityId"));
|
|
|
+ assertEquals("亲子营", row.get("activityTitle"));
|
|
|
+ assertEquals("名额已满", row.get("rejectReason"));
|
|
|
+ assertEquals("张三", row.get("registrantName"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void 无活动数据时标题降级为空且不报错() throws Exception {
|
|
|
+ ActivityRegistrationMapper regMapper = mock(ActivityRegistrationMapper.class);
|
|
|
+ ActivityMapper actMapper = mock(ActivityMapper.class);
|
|
|
+ ActivityRegistrationService svc = serviceWith(regMapper, actMapper);
|
|
|
+
|
|
|
+ ActivityRegistration reg = new ActivityRegistration();
|
|
|
+ reg.setId(2L);
|
|
|
+ reg.setStatus("pending");
|
|
|
+
|
|
|
+ when(regMapper.selectList(any())).thenReturn(Arrays.asList(reg));
|
|
|
+
|
|
|
+ Result<List<Map<String, Object>>> result = svc.listRegistrationsForAdmin(null, "pending");
|
|
|
+
|
|
|
+ assertEquals(200, result.getCode());
|
|
|
+ assertNull(result.getData().get(0).get("activityTitle"));
|
|
|
+ verify(actMapper, never()).selectBatchIds(any());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void 空列表返回空集合() throws Exception {
|
|
|
+ ActivityRegistrationMapper regMapper = mock(ActivityRegistrationMapper.class);
|
|
|
+ ActivityMapper actMapper = mock(ActivityMapper.class);
|
|
|
+ ActivityRegistrationService svc = serviceWith(regMapper, actMapper);
|
|
|
+
|
|
|
+ when(regMapper.selectList(any())).thenReturn(java.util.Collections.emptyList());
|
|
|
+
|
|
|
+ Result<List<Map<String, Object>>> result = svc.listRegistrationsForAdmin(5L, null);
|
|
|
+
|
|
|
+ assertEquals(200, result.getCode());
|
|
|
+ assertTrue(result.getData().isEmpty());
|
|
|
+ }
|
|
|
+}
|