|
@@ -24,6 +24,65 @@ import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
class DeliveryOrderNotificationServiceTest {
|
|
class DeliveryOrderNotificationServiceTest {
|
|
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void cancellationSceneIsUserOnlyAndOnlySentAfterCommit() {
|
|
|
|
|
+ IInfoUserService users = mock(IInfoUserService.class);
|
|
|
|
|
+ DeliveryOrderNotificationService service = new DeliveryOrderNotificationService(
|
|
|
|
|
+ mock(RiderPositionMapper.class), mock(PushEventService.class), users, null);
|
|
|
|
|
+ PosOrder order = availableOrder(); order.setUserId(201L); order.setQsId(301L); order.setShId(101L);
|
|
|
|
|
+ java.util.List<InfoUser> recipients = new java.util.ArrayList<>();
|
|
|
|
|
+ for (long id : new long[]{201, 301, 101}) {
|
|
|
|
|
+ InfoUser recipient = new InfoUser(); recipient.setUserId(id); recipients.add(recipient);
|
|
|
|
|
+ }
|
|
|
|
|
+ when(users.listByIds(org.mockito.ArgumentMatchers.anyCollection())).thenReturn(recipients);
|
|
|
|
|
+ java.util.Map<String, com.alibaba.fastjson.JSONObject> bodies = new java.util.HashMap<>();
|
|
|
|
|
+ try (var spring = org.mockito.Mockito.mockStatic(com.ruoyi.common.utils.spring.SpringUtils.class)) {
|
|
|
|
|
+ spring.when(() -> com.ruoyi.common.utils.spring.SpringUtils.getBean("scheduledExecutorService"))
|
|
|
|
|
+ .thenReturn(mock(java.util.concurrent.ScheduledExecutorService.class));
|
|
|
|
|
+ com.ruoyi.framework.manager.AsyncManager manager = mock(com.ruoyi.framework.manager.AsyncManager.class);
|
|
|
|
|
+ org.mockito.Mockito.doAnswer(call -> { ((java.util.TimerTask) call.getArgument(0)).run(); return null; })
|
|
|
|
|
+ .when(manager).execute(org.mockito.ArgumentMatchers.any(java.util.TimerTask.class));
|
|
|
|
|
+ try (var async = org.mockito.Mockito.mockStatic(com.ruoyi.framework.manager.AsyncManager.class);
|
|
|
|
|
+ var push = org.mockito.Mockito.mockStatic(com.ruoyi.app.utils.PayPush.class)) {
|
|
|
|
|
+ async.when(com.ruoyi.framework.manager.AsyncManager::me).thenReturn(manager);
|
|
|
|
|
+ push.when(() -> com.ruoyi.app.utils.PayPush.userPushHandleLocal(org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(),
|
|
|
|
|
+ org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.isNull(), org.mockito.ArgumentMatchers.anyString(),
|
|
|
|
|
+ org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString()))
|
|
|
|
|
+ .thenAnswer(call -> { bodies.put("user", com.alibaba.fastjson.JSON.parseObject(call.getArgument(6, String.class))); return null; });
|
|
|
|
|
+ push.when(() -> com.ruoyi.app.utils.PayPush.qsPushHandleLocal(org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(),
|
|
|
|
|
+ org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.isNull(), org.mockito.ArgumentMatchers.anyString(),
|
|
|
|
|
+ org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString()))
|
|
|
|
|
+ .thenAnswer(call -> { bodies.put("rider", com.alibaba.fastjson.JSON.parseObject(call.getArgument(6, String.class))); return null; });
|
|
|
|
|
+ push.when(() -> com.ruoyi.app.utils.PayPush.shPushHandleLocal(org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(),
|
|
|
|
|
+ org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.isNull(), org.mockito.ArgumentMatchers.anyString(),
|
|
|
|
|
+ org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString()))
|
|
|
|
|
+ .thenAnswer(call -> { bodies.put("merchant", com.alibaba.fastjson.JSON.parseObject(call.getArgument(6, String.class))); return null; });
|
|
|
|
|
+ org.springframework.transaction.support.TransactionSynchronizationManager.initSynchronization();
|
|
|
|
|
+ try {
|
|
|
|
|
+ service.notifyOrderCancelled(order, null);
|
|
|
|
|
+ org.junit.jupiter.api.Assertions.assertTrue(bodies.isEmpty());
|
|
|
|
|
+ org.springframework.transaction.support.TransactionSynchronizationManager.getSynchronizations().forEach(sync -> sync.afterCommit());
|
|
|
|
|
+ org.junit.jupiter.api.Assertions.assertEquals("ORDER_CANCELLED", bodies.get("user").getString("eventScene"));
|
|
|
|
|
+ org.junit.jupiter.api.Assertions.assertEquals(0, bodies.get("user").getIntValue("type"));
|
|
|
|
|
+ org.junit.jupiter.api.Assertions.assertFalse(bodies.get("rider").containsKey("eventScene"));
|
|
|
|
|
+ org.junit.jupiter.api.Assertions.assertFalse(bodies.get("merchant").containsKey("eventScene"));
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ org.springframework.transaction.support.TransactionSynchronizationManager.clearSynchronization();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void cancellationPreparationFailureDoesNotEscapeBusinessOperation() {
|
|
|
|
|
+ IInfoUserService users = mock(IInfoUserService.class);
|
|
|
|
|
+ DeliveryOrderNotificationService service = new DeliveryOrderNotificationService(
|
|
|
|
|
+ mock(RiderPositionMapper.class), mock(PushEventService.class), users, null);
|
|
|
|
|
+ PosOrder order = availableOrder(); order.setQsId(301L); order.setUserId(201L);
|
|
|
|
|
+ when(users.listByIds(org.mockito.ArgumentMatchers.anyCollection())).thenThrow(new IllegalStateException("failed notification lookup"));
|
|
|
|
|
+ org.junit.jupiter.api.Assertions.assertDoesNotThrow(() -> service.notifyOrderCancelled(order, null));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
void notifiesNearbyAvailableRidersOnlyAfterDeliveryOrderIsPaid() {
|
|
void notifiesNearbyAvailableRidersOnlyAfterDeliveryOrderIsPaid() {
|
|
|
RiderPositionMapper positions = mock(RiderPositionMapper.class);
|
|
RiderPositionMapper positions = mock(RiderPositionMapper.class);
|