|
|
@@ -1,5 +1,7 @@
|
|
|
package com.ruoyi.app.order;
|
|
|
|
|
|
+import com.ruoyi.app.push.BusinessPushService;
|
|
|
+import com.ruoyi.app.push.RecipientApp;
|
|
|
import com.ruoyi.app.user.MerchantTokenSessionService;
|
|
|
import com.ruoyi.app.utils.event.PushEventService;
|
|
|
import com.ruoyi.system.domain.InfoUser;
|
|
|
@@ -13,9 +15,10 @@ import org.junit.jupiter.api.Test;
|
|
|
import java.util.List;
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.anyLong;
|
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
+import static org.mockito.ArgumentMatchers.eq;
|
|
|
import static org.mockito.ArgumentMatchers.anyString;
|
|
|
import static org.mockito.Mockito.doAnswer;
|
|
|
-import static org.mockito.Mockito.doNothing;
|
|
|
import static org.mockito.Mockito.doThrow;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
import static org.mockito.Mockito.never;
|
|
|
@@ -30,6 +33,7 @@ class MerchantNotificationRouterTest {
|
|
|
private IInfoUserService users;
|
|
|
private MerchantTokenSessionService sessions;
|
|
|
private PushEventService events;
|
|
|
+ private BusinessPushService pushService;
|
|
|
private MerchantNotificationRouter router;
|
|
|
|
|
|
@BeforeEach
|
|
|
@@ -39,9 +43,11 @@ class MerchantNotificationRouterTest {
|
|
|
users = mock(IInfoUserService.class);
|
|
|
sessions = mock(MerchantTokenSessionService.class);
|
|
|
events = mock(PushEventService.class);
|
|
|
- router = spy(new MerchantNotificationRouter(relations, stores, users, sessions, events));
|
|
|
+ pushService = mock(BusinessPushService.class);
|
|
|
+ when(pushService.addressKey(any(InfoUser.class)))
|
|
|
+ .thenAnswer(invocation -> ((InfoUser) invocation.getArgument(0)).getCid());
|
|
|
+ router = spy(new MerchantNotificationRouter(relations, stores, users, sessions, events, pushService));
|
|
|
doAnswer(invocation -> invocation.getArgument(0)).when(router).localize(anyString(), anyLong());
|
|
|
- doNothing().when(router).sendExternal(anyString(), anyString(), anyString(), anyString());
|
|
|
when(stores.selectPosStoreById(9L)).thenReturn(store(9, 101L));
|
|
|
when(users.getById(101L)).thenReturn(owner(101L));
|
|
|
}
|
|
|
@@ -59,8 +65,8 @@ class MerchantNotificationRouterTest {
|
|
|
verify(events).PublisherEvent(501L, "title", "content,NO:DD-1", "body");
|
|
|
verify(events).PublisherEvent(502L, "title", "content,NO:DD-1", "body");
|
|
|
verify(events, never()).PublisherEvent(101L, "title", "content,NO:DD-1", "body");
|
|
|
- verify(router).sendExternal("cid-a", "title", "content,NO:DD-1", "body");
|
|
|
- verify(router).sendExternal("cid-b", "title", "content,NO:DD-1", "body");
|
|
|
+ verify(pushService).send(RecipientApp.MERCHANT, 501L, "cid-a", "title", "content,NO:DD-1", "body");
|
|
|
+ verify(pushService).send(RecipientApp.MERCHANT, 502L, "cid-b", "title", "content,NO:DD-1", "body");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -74,7 +80,8 @@ class MerchantNotificationRouterTest {
|
|
|
|
|
|
verify(events).PublisherEvent(501L, "title", "content,NO:DD-1", "body");
|
|
|
verify(events).PublisherEvent(502L, "title", "content,NO:DD-1", "body");
|
|
|
- verify(router, times(1)).sendExternal("shared-cid", "title", "content,NO:DD-1", "body");
|
|
|
+ verify(pushService, times(1)).send(eq(RecipientApp.MERCHANT), anyLong(), eq("shared-cid"),
|
|
|
+ eq("title"), eq("content,NO:DD-1"), eq("body"));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -87,6 +94,23 @@ class MerchantNotificationRouterTest {
|
|
|
|
|
|
verify(events).PublisherEvent(101L, "title", "content,NO:DD-1", "body");
|
|
|
verify(events, never()).PublisherEvent(501L, "title", "content,NO:DD-1", "body");
|
|
|
+ verify(pushService).send(RecipientApp.MERCHANT, 101L, "owner-cid", "title", "content,NO:DD-1", "body");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void nativeTokenOnlySubaccountReceivesOrderWithoutDuplicatingOwner() {
|
|
|
+ InfoUser subaccount = subaccount(501L, null);
|
|
|
+ subaccount.setCidType("android");
|
|
|
+ subaccount.setDeviceToken("native-token");
|
|
|
+ when(relations.selectEligibleSubaccountsByStoreId(9L)).thenReturn(List.of(subaccount));
|
|
|
+ when(sessions.hasAppSession(501L)).thenReturn(true);
|
|
|
+ when(pushService.addressKey(subaccount)).thenReturn("android:native-token");
|
|
|
+
|
|
|
+ router.sendStoreNotification(9L, 101L, "title", "content", "body", "DD-1");
|
|
|
+
|
|
|
+ verify(events).PublisherEvent(501L, "title", "content,NO:DD-1", "body");
|
|
|
+ verify(events, never()).PublisherEvent(101L, "title", "content,NO:DD-1", "body");
|
|
|
+ verify(pushService).send(RecipientApp.MERCHANT, 501L, null, "title", "content,NO:DD-1", "body");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -129,13 +153,13 @@ class MerchantNotificationRouterTest {
|
|
|
when(relations.selectEligibleSubaccountsByStoreId(9L)).thenReturn(List.of(first, second));
|
|
|
when(sessions.hasAppSession(anyLong())).thenReturn(true);
|
|
|
doThrow(new IllegalStateException("push failed"))
|
|
|
- .when(router).sendExternal("cid-a", "title", "content,NO:DD-1", "body");
|
|
|
+ .when(pushService).send(RecipientApp.MERCHANT, 501L, "cid-a", "title", "content,NO:DD-1", "body");
|
|
|
|
|
|
router.sendStoreNotification(9L, 101L, "title", "content", "body", "DD-1");
|
|
|
|
|
|
verify(events).PublisherEvent(501L, "title", "content,NO:DD-1", "body");
|
|
|
verify(events).PublisherEvent(502L, "title", "content,NO:DD-1", "body");
|
|
|
- verify(router).sendExternal("cid-b", "title", "content,NO:DD-1", "body");
|
|
|
+ verify(pushService).send(RecipientApp.MERCHANT, 502L, "cid-b", "title", "content,NO:DD-1", "body");
|
|
|
}
|
|
|
|
|
|
@Test
|