|
|
@@ -10,6 +10,7 @@ import com.payment.platform.module.payment.leshouying.client.LeshouyingResponseP
|
|
|
import com.payment.platform.module.payment.leshouying.config.LeshouyingProperties;
|
|
|
import com.payment.platform.module.payment.leshouying.entity.LsyOrderEntity;
|
|
|
import com.payment.platform.module.payment.leshouying.mapper.LsyOrderMapper;
|
|
|
+import com.payment.platform.module.payment.stream.OrderEventPublisher;
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
@@ -33,15 +34,16 @@ class LsyOrderServiceStateTest {
|
|
|
@Mock private LsyOrderMapper orderMapper;
|
|
|
@Mock private LeshouyingClient client;
|
|
|
@Mock private LsyQueryService queryService;
|
|
|
+ @Mock private OrderEventPublisher publisher;
|
|
|
private LsyOrderService service;
|
|
|
private LeshouyingProperties props;
|
|
|
|
|
|
@BeforeEach
|
|
|
void setUp() {
|
|
|
props = new LeshouyingProperties();
|
|
|
- // 构造器签名固定为 5 参 —— 后续任务新增下单方法时不要改动它
|
|
|
+ // 构造器签名固定为 6 参(2026-10-05 加 OrderEventPublisher)—— 后续新增下单方法时不要改它
|
|
|
service = new LsyOrderService(orderMapper, client,
|
|
|
- new LeshouyingResponseParser(), props, queryService);
|
|
|
+ new LeshouyingResponseParser(), props, queryService, publisher);
|
|
|
}
|
|
|
|
|
|
private LsyOrderEntity order(String status) {
|
|
|
@@ -231,6 +233,47 @@ class LsyOrderServiceStateTest {
|
|
|
assertFalse(service.isTerminal("PARTIAL_REFUNDED"));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void applyPayResult_affectedRowIsOne_emitsLsyOrderSignal() {
|
|
|
+ when(orderMapper.update(any(), any(UpdateWrapper.class))).thenReturn(1);
|
|
|
+ LsyOrderEntity o = order("PAYING");
|
|
|
+ o.setTenantId(2L);
|
|
|
+
|
|
|
+ assertTrue(service.applyPayResult(o, "SUCCESS", patch("T1")));
|
|
|
+
|
|
|
+ verify(publisher).changed(OrderEventPublisher.CHANNEL_LSY_ORDER, 2L);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void applyPayResult_affectedRowIsZero_emitsNothing() {
|
|
|
+ when(orderMapper.update(any(), any(UpdateWrapper.class))).thenReturn(0);
|
|
|
+
|
|
|
+ assertFalse(service.applyPayResult(order("SUCCESS"), "SUCCESS", patch("T1")));
|
|
|
+
|
|
|
+ // 重复通知(条件更新未命中)一行都没改 —— 发了就是让三页白拉一次
|
|
|
+ verifyNoInteractions(publisher);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void applyRefundResult_settledRow_emitsLsyOrderSignal() {
|
|
|
+ when(orderMapper.update(any(), any(UpdateWrapper.class))).thenReturn(1);
|
|
|
+ LsyOrderEntity o = order("SUCCESS");
|
|
|
+ o.setTenantId(2L);
|
|
|
+
|
|
|
+ service.applyRefundResult(o, 100L, "REFUNDED");
|
|
|
+
|
|
|
+ verify(publisher).changed(OrderEventPublisher.CHANNEL_LSY_ORDER, 2L);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void applyRefundResult_zeroRows_emitsNothing() {
|
|
|
+ when(orderMapper.update(any(), any(UpdateWrapper.class))).thenReturn(0);
|
|
|
+
|
|
|
+ service.applyRefundResult(order("CANCELED"), 100L, "REFUNDED");
|
|
|
+
|
|
|
+ verifyNoInteractions(publisher);
|
|
|
+ }
|
|
|
+
|
|
|
/** 与 LsyNotifyServiceTest 同款(本仓库按测试文件各自持有一份,不抽公共类)。 */
|
|
|
private static void withLogCapture(Class<?> type, Consumer<List<ILoggingEvent>> body) {
|
|
|
Logger logger = (Logger) LoggerFactory.getLogger(type);
|