|
|
@@ -0,0 +1,55 @@
|
|
|
+package com.etotem.cfc.service;
|
|
|
+
|
|
|
+import com.etotem.cfc.config.ConfigService;
|
|
|
+import com.etotem.cfc.constant.CfConfigKeys;
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.mockito.InjectMocks;
|
|
|
+import org.mockito.Mock;
|
|
|
+import org.mockito.MockitoAnnotations;
|
|
|
+
|
|
|
+import java.lang.reflect.Method;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+import static org.mockito.ArgumentMatchers.anyInt;
|
|
|
+import static org.mockito.ArgumentMatchers.anyString;
|
|
|
+import static org.mockito.ArgumentMatchers.eq;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 非商品订单销售奖 P 点基数单位回归(金额按分)。
|
|
|
+ *
|
|
|
+ * 口径:calcOrderPpoints 声明"单位:分"。非商品订单(会员/套餐/订阅/测评)
|
|
|
+ * 的 P 点必须按分计算:base = amountCent × serviceRateBps / 10000。
|
|
|
+ * 100 元订单 = 10000 分,服务费率 1000bps(10%) → base = 1000 分。
|
|
|
+ * 历史 bug:先把分除以100当元再算 → base=10(缩小100倍),导致销售奖档位永不触发。
|
|
|
+ */
|
|
|
+class CfCommissionPpointUnitTest {
|
|
|
+
|
|
|
+ @Mock
|
|
|
+ private ConfigService configService;
|
|
|
+
|
|
|
+ @InjectMocks
|
|
|
+ private CfCommissionService cfCommissionService;
|
|
|
+
|
|
|
+ private Method calcOrderPpoints;
|
|
|
+
|
|
|
+ @BeforeEach
|
|
|
+ void setUp() throws Exception {
|
|
|
+ MockitoAnnotations.openMocks(this);
|
|
|
+ calcOrderPpoints = CfCommissionService.class.getDeclaredMethod(
|
|
|
+ "calcOrderPpoints", Long.class, String.class, Integer.class,
|
|
|
+ Integer.class, Long.class);
|
|
|
+ calcOrderPpoints.setAccessible(true);
|
|
|
+ when(configService.getIntConfig(eq(CfConfigKeys.COMMISSION_SERVICE_RATE), anyInt()))
|
|
|
+ .thenReturn(1000); // 1000 bps = 10%
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void nonProductOrder_pPoints_calculatedInCents() throws Exception {
|
|
|
+ // 100元会员订单 = 10000分,费率10% → P点应为1000分(不是10)
|
|
|
+ int ppoints = (Integer) calcOrderPpoints.invoke(
|
|
|
+ cfCommissionService, 1L, "membership", 10000, 10000, null);
|
|
|
+ assertEquals(1000, ppoints);
|
|
|
+ }
|
|
|
+}
|