|
@@ -4,6 +4,7 @@ import com.etotem.cfc.entity.Activity;
|
|
|
import com.etotem.cfc.entity.DimensionWeight;
|
|
import com.etotem.cfc.entity.DimensionWeight;
|
|
|
import com.etotem.cfc.mapper.ActivityMapper;
|
|
import com.etotem.cfc.mapper.ActivityMapper;
|
|
|
import com.etotem.cfc.service.ActivityAdminService;
|
|
import com.etotem.cfc.service.ActivityAdminService;
|
|
|
|
|
+import com.etotem.cfc.service.ActivityTagService;
|
|
|
import com.etotem.cfc.service.DimensionWeightService;
|
|
import com.etotem.cfc.service.DimensionWeightService;
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
@@ -21,21 +22,25 @@ import static org.mockito.ArgumentMatchers.eq;
|
|
|
import static org.mockito.Mockito.*;
|
|
import static org.mockito.Mockito.*;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 审核中心活动审核:动作兼容 publish/reject,审核通过时必须补充五维权重。
|
|
|
|
|
|
|
+ * 审核中心活动审核:动作兼容 publish/reject;通过时只填五维权重,
|
|
|
|
|
+ * 所属维度由权重最高的维度自动推导。
|
|
|
*/
|
|
*/
|
|
|
class ActivityAuditTest {
|
|
class ActivityAuditTest {
|
|
|
|
|
|
|
|
private ActivityAdminService service;
|
|
private ActivityAdminService service;
|
|
|
private ActivityMapper activityMapper;
|
|
private ActivityMapper activityMapper;
|
|
|
private DimensionWeightService dimensionWeightService;
|
|
private DimensionWeightService dimensionWeightService;
|
|
|
|
|
+ private ActivityTagService activityTagService;
|
|
|
|
|
|
|
|
@BeforeEach
|
|
@BeforeEach
|
|
|
void setUp() throws Exception {
|
|
void setUp() throws Exception {
|
|
|
service = new ActivityAdminService();
|
|
service = new ActivityAdminService();
|
|
|
activityMapper = mock(ActivityMapper.class);
|
|
activityMapper = mock(ActivityMapper.class);
|
|
|
dimensionWeightService = mock(DimensionWeightService.class);
|
|
dimensionWeightService = mock(DimensionWeightService.class);
|
|
|
|
|
+ activityTagService = mock(ActivityTagService.class);
|
|
|
set("activityMapper", activityMapper);
|
|
set("activityMapper", activityMapper);
|
|
|
set("dimensionWeightService", dimensionWeightService);
|
|
set("dimensionWeightService", dimensionWeightService);
|
|
|
|
|
+ set("activityTagService", activityTagService);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void set(String name, Object value) throws Exception {
|
|
private void set(String name, Object value) throws Exception {
|
|
@@ -73,7 +78,7 @@ class ActivityAuditTest {
|
|
|
when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
|
when(activityMapper.updateById(any(Activity.class))).thenReturn(1);
|
|
when(activityMapper.updateById(any(Activity.class))).thenReturn(1);
|
|
|
|
|
|
|
|
- service.auditActivity(9L, "publish", null, 1L, "body", weights(20, 20, 20, 20, 20));
|
|
|
|
|
|
|
+ service.auditActivity(9L, "publish", null, 1L, weights(20, 20, 20, 20, 20));
|
|
|
|
|
|
|
|
assertEquals("published", activity.getStatus());
|
|
assertEquals("published", activity.getStatus());
|
|
|
assertEquals("approved", activity.getAuditStatus());
|
|
assertEquals("approved", activity.getAuditStatus());
|
|
@@ -82,13 +87,35 @@ class ActivityAuditTest {
|
|
|
assertNotNull(activity.getAuditedAt());
|
|
assertNotNull(activity.getAuditedAt());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void audit_通过时按最高权重自动确定所属维度() {
|
|
|
|
|
+ Activity activity = pending();
|
|
|
|
|
+ when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
|
|
|
+ when(activityMapper.updateById(any(Activity.class))).thenReturn(1);
|
|
|
|
|
+
|
|
|
|
|
+ service.auditActivity(9L, "approved", null, 1L, weights(10, 50, 10, 20, 10));
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("mind", activity.getDimensionCode());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void audit_最高权重并列时按身心灵知行顺序取第一个() {
|
|
|
|
|
+ Activity activity = pending();
|
|
|
|
|
+ when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
|
|
|
+ when(activityMapper.updateById(any(Activity.class))).thenReturn(1);
|
|
|
|
|
+
|
|
|
|
|
+ service.auditActivity(9L, "approved", null, 1L, weights(50, 50, 0, 0, 0));
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("body", activity.getDimensionCode());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
void audit_通过时保存五维权重() {
|
|
void audit_通过时保存五维权重() {
|
|
|
Activity activity = pending();
|
|
Activity activity = pending();
|
|
|
when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
|
when(activityMapper.updateById(any(Activity.class))).thenReturn(1);
|
|
when(activityMapper.updateById(any(Activity.class))).thenReturn(1);
|
|
|
|
|
|
|
|
- service.auditActivity(9L, "approved", null, 1L, "middle", weights(40, 15, 15, 15, 15));
|
|
|
|
|
|
|
+ service.auditActivity(9L, "approved", null, 1L, weights(40, 15, 15, 15, 15));
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
ArgumentCaptor<List<DimensionWeight>> captor = ArgumentCaptor.forClass(List.class);
|
|
ArgumentCaptor<List<DimensionWeight>> captor = ArgumentCaptor.forClass(List.class);
|
|
@@ -101,6 +128,20 @@ class ActivityAuditTest {
|
|
|
assertNotNull(body);
|
|
assertNotNull(body);
|
|
|
assertEquals(40, body.getWeight());
|
|
assertEquals(40, body.getWeight());
|
|
|
assertTrue(body.getEnabled());
|
|
assertTrue(body.getEnabled());
|
|
|
|
|
+ verify(activityTagService).generateIfEmptyAsync(9L);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void submitForReview_提交后异步生成标签() {
|
|
|
|
|
+ Activity activity = pending();
|
|
|
|
|
+ activity.setStatus("draft");
|
|
|
|
|
+ when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
|
|
|
+ when(activityMapper.updateById(any(Activity.class))).thenReturn(1);
|
|
|
|
|
+
|
|
|
|
|
+ service.submitForReview(9L);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("pending", activity.getStatus());
|
|
|
|
|
+ verify(activityTagService).generateIfEmptyAsync(9L);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -109,7 +150,7 @@ class ActivityAuditTest {
|
|
|
when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
|
|
|
|
|
|
IllegalStateException e = assertThrows(IllegalStateException.class,
|
|
IllegalStateException e = assertThrows(IllegalStateException.class,
|
|
|
- () -> service.auditActivity(9L, "approved", null, 1L, "body", null));
|
|
|
|
|
|
|
+ () -> service.auditActivity(9L, "approved", null, 1L, null));
|
|
|
|
|
|
|
|
assertTrue(e.getMessage().contains("五维权重"), e.getMessage());
|
|
assertTrue(e.getMessage().contains("五维权重"), e.getMessage());
|
|
|
verify(activityMapper, never()).updateById(any(Activity.class));
|
|
verify(activityMapper, never()).updateById(any(Activity.class));
|
|
@@ -122,7 +163,7 @@ class ActivityAuditTest {
|
|
|
when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
|
|
|
|
|
|
IllegalStateException e = assertThrows(IllegalStateException.class,
|
|
IllegalStateException e = assertThrows(IllegalStateException.class,
|
|
|
- () -> service.auditActivity(9L, "approved", null, 1L, "body", weights(20, 20, 20, 20, 19)));
|
|
|
|
|
|
|
+ () -> service.auditActivity(9L, "approved", null, 1L, weights(20, 20, 20, 20, 19)));
|
|
|
|
|
|
|
|
assertTrue(e.getMessage().contains("100"), e.getMessage());
|
|
assertTrue(e.getMessage().contains("100"), e.getMessage());
|
|
|
verify(activityMapper, never()).updateById(any(Activity.class));
|
|
verify(activityMapper, never()).updateById(any(Activity.class));
|
|
@@ -137,7 +178,7 @@ class ActivityAuditTest {
|
|
|
onlyFour.removeIf(m -> "wealth".equals(m.get("dimension")));
|
|
onlyFour.removeIf(m -> "wealth".equals(m.get("dimension")));
|
|
|
|
|
|
|
|
IllegalStateException e = assertThrows(IllegalStateException.class,
|
|
IllegalStateException e = assertThrows(IllegalStateException.class,
|
|
|
- () -> service.auditActivity(9L, "approved", null, 1L, "body", onlyFour));
|
|
|
|
|
|
|
+ () -> service.auditActivity(9L, "approved", null, 1L, onlyFour));
|
|
|
|
|
|
|
|
assertTrue(e.getMessage().contains("五个维度"), e.getMessage());
|
|
assertTrue(e.getMessage().contains("五个维度"), e.getMessage());
|
|
|
}
|
|
}
|
|
@@ -148,7 +189,7 @@ class ActivityAuditTest {
|
|
|
when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
|
when(activityMapper.updateById(any(Activity.class))).thenReturn(1);
|
|
when(activityMapper.updateById(any(Activity.class))).thenReturn(1);
|
|
|
|
|
|
|
|
- service.auditActivity(9L, "reject", "材料不全", 1L, null, null);
|
|
|
|
|
|
|
+ service.auditActivity(9L, "reject", "材料不全", 1L, null);
|
|
|
|
|
|
|
|
assertEquals("rejected", activity.getStatus());
|
|
assertEquals("rejected", activity.getStatus());
|
|
|
assertEquals("rejected", activity.getAuditStatus());
|
|
assertEquals("rejected", activity.getAuditStatus());
|
|
@@ -162,7 +203,7 @@ class ActivityAuditTest {
|
|
|
when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
when(activityMapper.selectById(9L)).thenReturn(activity);
|
|
|
|
|
|
|
|
IllegalStateException e = assertThrows(IllegalStateException.class,
|
|
IllegalStateException e = assertThrows(IllegalStateException.class,
|
|
|
- () -> service.auditActivity(9L, "unknown", null, 1L, "body", weights(20, 20, 20, 20, 20)));
|
|
|
|
|
|
|
+ () -> service.auditActivity(9L, "unknown", null, 1L, weights(20, 20, 20, 20, 20)));
|
|
|
|
|
|
|
|
assertTrue(e.getMessage().contains("审核操作无效"), e.getMessage());
|
|
assertTrue(e.getMessage().contains("审核操作无效"), e.getMessage());
|
|
|
}
|
|
}
|