|
|
@@ -1,22 +1,30 @@
|
|
|
package com.ruoyi.app.user;
|
|
|
|
|
|
import com.ruoyi.app.user.dto.MerchantSubaccountCreateRequest;
|
|
|
+import com.ruoyi.app.user.dto.StoreAccountsView;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.MessageUtils;
|
|
|
import com.ruoyi.system.domain.InfoUser;
|
|
|
+import com.ruoyi.system.domain.PosStore;
|
|
|
import com.ruoyi.system.mapper.PosStoreMapper;
|
|
|
import com.ruoyi.system.service.IInfoUserService;
|
|
|
import com.ruoyi.system.service.IMerchantSubaccountStoreService;
|
|
|
import com.ruoyi.system.service.MerchantStoreAccessService;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.mockito.ArgumentCaptor;
|
|
|
+import org.mockito.MockedStatic;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
+import static org.mockito.ArgumentMatchers.anyString;
|
|
|
import static org.mockito.Mockito.doAnswer;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
+import static org.mockito.Mockito.mockStatic;
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
@@ -55,4 +63,107 @@ class MerchantSubaccountApplicationServiceTest {
|
|
|
assertNull(captor.getValue().getPhone());
|
|
|
verify(businessPhoneService).ensureUnique("0912345678", null);
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void listStoreAccountsRejectsMissingOrDeletedStore() {
|
|
|
+ PosStoreMapper posStoreMapper = mock(PosStoreMapper.class);
|
|
|
+ MerchantSubaccountApplicationService service = newService(posStoreMapper);
|
|
|
+ when(posStoreMapper.selectPosStoreById(7L)).thenReturn(null);
|
|
|
+ PosStore deleted = new PosStore();
|
|
|
+ deleted.setDelFlag("1");
|
|
|
+ when(posStoreMapper.selectPosStoreById(8L)).thenReturn(deleted);
|
|
|
+
|
|
|
+ try (MockedStatic<MessageUtils> messages = mockStatic(MessageUtils.class)) {
|
|
|
+ messages.when(() -> MessageUtils.message(anyString()))
|
|
|
+ .thenAnswer(invocation -> invocation.getArgument(0));
|
|
|
+ ServiceException missing = assertThrows(ServiceException.class,
|
|
|
+ () -> service.listStoreAccounts(7L));
|
|
|
+ assertEquals("merchant.store.not.found", missing.getMessage());
|
|
|
+ ServiceException deletedStore = assertThrows(ServiceException.class,
|
|
|
+ () -> service.listStoreAccounts(8L));
|
|
|
+ assertEquals("merchant.store.not.found", deletedStore.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void listStoreAccountsReturnsOwnerAndEligibleSubaccountsWithContactFields() {
|
|
|
+ IInfoUserService infoUserService = mock(IInfoUserService.class);
|
|
|
+ IMerchantSubaccountStoreService relationService = mock(IMerchantSubaccountStoreService.class);
|
|
|
+ PosStoreMapper posStoreMapper = mock(PosStoreMapper.class);
|
|
|
+ MerchantSubaccountApplicationService service = newService(infoUserService, relationService, posStoreMapper);
|
|
|
+ PosStore store = new PosStore();
|
|
|
+ store.setDelFlag("0");
|
|
|
+ store.setUserId(10L);
|
|
|
+ when(posStoreMapper.selectPosStoreById(7L)).thenReturn(store);
|
|
|
+ when(infoUserService.selectInfoUserByUserId(10L)).thenReturn(contactUser(10L, "1", "0"));
|
|
|
+ when(relationService.selectEligibleSubaccountsByStoreId(7L))
|
|
|
+ .thenReturn(List.of(contactUser(20L, "5", "0")));
|
|
|
+
|
|
|
+ StoreAccountsView view = service.listStoreAccounts(7L);
|
|
|
+
|
|
|
+ assertEquals(10L, view.getOwner().getUserId());
|
|
|
+ assertEquals("1", view.getOwner().getUserType());
|
|
|
+ assertEquals("nick-10", view.getOwner().getNickName());
|
|
|
+ assertEquals("tel-10", view.getOwner().getPhone());
|
|
|
+ assertEquals("avatar-10", view.getOwner().getAvatar());
|
|
|
+ assertEquals("imKey-10", view.getOwner().getImApiKey());
|
|
|
+ assertEquals("900010", view.getOwner().getImUserId());
|
|
|
+ assertEquals("cid-10", view.getOwner().getCid());
|
|
|
+ assertEquals("ios", view.getOwner().getCidType());
|
|
|
+ assertEquals("device-10", view.getOwner().getDeviceToken());
|
|
|
+ assertEquals("voip-10", view.getOwner().getVoIPToken());
|
|
|
+ assertEquals(1, view.getSubaccounts().size());
|
|
|
+ assertEquals(20L, view.getSubaccounts().get(0).getUserId());
|
|
|
+ assertEquals("5", view.getSubaccounts().get(0).getUserType());
|
|
|
+ assertEquals("nick-20", view.getSubaccounts().get(0).getNickName());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void listStoreAccountsOmitsUnavailableOwner() {
|
|
|
+ IInfoUserService infoUserService = mock(IInfoUserService.class);
|
|
|
+ IMerchantSubaccountStoreService relationService = mock(IMerchantSubaccountStoreService.class);
|
|
|
+ PosStoreMapper posStoreMapper = mock(PosStoreMapper.class);
|
|
|
+ MerchantSubaccountApplicationService service = newService(infoUserService, relationService, posStoreMapper);
|
|
|
+ PosStore store = new PosStore();
|
|
|
+ store.setDelFlag("0");
|
|
|
+ store.setUserId(10L);
|
|
|
+ when(posStoreMapper.selectPosStoreById(7L)).thenReturn(store);
|
|
|
+ when(infoUserService.selectInfoUserByUserId(10L)).thenReturn(contactUser(10L, "1", "1"));
|
|
|
+ when(relationService.selectEligibleSubaccountsByStoreId(7L)).thenReturn(List.of());
|
|
|
+
|
|
|
+ StoreAccountsView view = service.listStoreAccounts(7L);
|
|
|
+
|
|
|
+ assertNull(view.getOwner());
|
|
|
+ assertEquals(List.of(), view.getSubaccounts());
|
|
|
+ }
|
|
|
+
|
|
|
+ private MerchantSubaccountApplicationService newService(PosStoreMapper posStoreMapper) {
|
|
|
+ return newService(mock(IInfoUserService.class), mock(IMerchantSubaccountStoreService.class), posStoreMapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ private MerchantSubaccountApplicationService newService(IInfoUserService infoUserService,
|
|
|
+ IMerchantSubaccountStoreService relationService,
|
|
|
+ PosStoreMapper posStoreMapper) {
|
|
|
+ return new MerchantSubaccountApplicationService(infoUserService, relationService,
|
|
|
+ mock(MerchantStoreAccessService.class), posStoreMapper,
|
|
|
+ mock(MerchantTokenSessionService.class), mock(BusinessPhoneService.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ private InfoUser contactUser(Long userId, String userType, String status) {
|
|
|
+ InfoUser user = new InfoUser();
|
|
|
+ user.setUserId(userId);
|
|
|
+ user.setUserType(userType);
|
|
|
+ user.setStatus(status);
|
|
|
+ user.setDelFlag("0");
|
|
|
+ user.setNickName("nick-" + userId);
|
|
|
+ user.setTelPhone("tel-" + userId);
|
|
|
+ user.setAvatar("avatar-" + userId);
|
|
|
+ user.setImApiKey("imKey-" + userId);
|
|
|
+ user.setImUserId(900000L + userId);
|
|
|
+ user.setCid("cid-" + userId);
|
|
|
+ user.setCidType("ios");
|
|
|
+ user.setDeviceToken("device-" + userId);
|
|
|
+ user.setVoIPToken("voip-" + userId);
|
|
|
+ return user;
|
|
|
+ }
|
|
|
}
|