|
|
@@ -73,6 +73,186 @@ class StallControllerTest {
|
|
|
assertEquals("4", inserted.getValue().getUserType());
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void editStallOwnerUpdatesProfileFieldsOnly() throws Exception {
|
|
|
+ IPosStoreService posStoreService = mock(IPosStoreService.class);
|
|
|
+ IInfoUserService infoUserService = mock(IInfoUserService.class);
|
|
|
+ BusinessPhoneService businessPhoneService = mock(BusinessPhoneService.class);
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ LambdaQueryChainWrapper<InfoUser> nameQuery = mock(LambdaQueryChainWrapper.class);
|
|
|
+ when(infoUserService.lambdaQuery()).thenReturn(nameQuery);
|
|
|
+ when(nameQuery.eq(any(SFunction.class), any())).thenReturn(nameQuery);
|
|
|
+ when(nameQuery.ne(any(SFunction.class), any())).thenReturn(nameQuery);
|
|
|
+ when(nameQuery.one()).thenReturn(null);
|
|
|
+
|
|
|
+ InfoUser existing = new InfoUser();
|
|
|
+ existing.setUserId(940L);
|
|
|
+ existing.setUserType("4");
|
|
|
+ existing.setDelFlag("0");
|
|
|
+ existing.setStoreId(8L);
|
|
|
+ when(infoUserService.selectInfoUserByUserId(940L)).thenReturn(existing);
|
|
|
+ PosStore store = new PosStore();
|
|
|
+ store.setId(8);
|
|
|
+ store.setIsStall(1);
|
|
|
+ store.setUserId(10L);
|
|
|
+ when(posStoreService.selectPosStoreById(8L)).thenReturn(store);
|
|
|
+
|
|
|
+ StallController controller = new StallController();
|
|
|
+ ReflectionTestUtils.setField(controller, "posStoreService", posStoreService);
|
|
|
+ ReflectionTestUtils.setField(controller, "infoUserService", infoUserService);
|
|
|
+ ReflectionTestUtils.setField(controller, "businessPhoneService", businessPhoneService);
|
|
|
+
|
|
|
+ InfoUser request = new InfoUser();
|
|
|
+ request.setUserId(940L);
|
|
|
+ request.setUserName("hujiaobing1");
|
|
|
+ request.setNickName("胡椒饼");
|
|
|
+ request.setPhone("0999999");
|
|
|
+ request.setStoreId(999L);
|
|
|
+
|
|
|
+ AjaxResult result;
|
|
|
+ try (MockedStatic<MessageUtils> messages = mockStatic(MessageUtils.class)) {
|
|
|
+ messages.when(() -> MessageUtils.message("no.success")).thenReturn("ok");
|
|
|
+ result = controller.editStallOwner(
|
|
|
+ JwtUtil.setToken("10", "night-market"), request);
|
|
|
+ }
|
|
|
+
|
|
|
+ assertEquals(HttpStatus.SUCCESS, result.get(AjaxResult.CODE_TAG));
|
|
|
+ verify(businessPhoneService).ensureUnique("0999999", 940L);
|
|
|
+ ArgumentCaptor<InfoUser> updated = ArgumentCaptor.forClass(InfoUser.class);
|
|
|
+ verify(infoUserService).updateInfoUser(updated.capture());
|
|
|
+ assertEquals(Long.valueOf(940L), updated.getValue().getUserId());
|
|
|
+ assertEquals("hujiaobing1", updated.getValue().getUserName());
|
|
|
+ assertEquals("胡椒饼", updated.getValue().getNickName());
|
|
|
+ assertEquals("0999999", updated.getValue().getTelPhone());
|
|
|
+ assertNull(updated.getValue().getPassword());
|
|
|
+ assertNull(updated.getValue().getStoreId());
|
|
|
+ assertNull(updated.getValue().getUserType());
|
|
|
+ assertNull(updated.getValue().getStatus());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void editStallOwnerResetsPasswordWhenProvided() throws Exception {
|
|
|
+ IPosStoreService posStoreService = mock(IPosStoreService.class);
|
|
|
+ IInfoUserService infoUserService = mock(IInfoUserService.class);
|
|
|
+ BusinessPhoneService businessPhoneService = mock(BusinessPhoneService.class);
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ LambdaQueryChainWrapper<InfoUser> nameQuery = mock(LambdaQueryChainWrapper.class);
|
|
|
+ when(infoUserService.lambdaQuery()).thenReturn(nameQuery);
|
|
|
+ when(nameQuery.eq(any(SFunction.class), any())).thenReturn(nameQuery);
|
|
|
+ when(nameQuery.ne(any(SFunction.class), any())).thenReturn(nameQuery);
|
|
|
+ when(nameQuery.one()).thenReturn(null);
|
|
|
+ InfoUser existing = new InfoUser();
|
|
|
+ existing.setUserId(940L);
|
|
|
+ existing.setUserType("4");
|
|
|
+ existing.setDelFlag("0");
|
|
|
+ existing.setStoreId(8L);
|
|
|
+ when(infoUserService.selectInfoUserByUserId(940L)).thenReturn(existing);
|
|
|
+ PosStore store = new PosStore();
|
|
|
+ store.setId(8);
|
|
|
+ store.setIsStall(1);
|
|
|
+ store.setUserId(10L);
|
|
|
+ when(posStoreService.selectPosStoreById(8L)).thenReturn(store);
|
|
|
+
|
|
|
+ StallController controller = new StallController();
|
|
|
+ ReflectionTestUtils.setField(controller, "posStoreService", posStoreService);
|
|
|
+ ReflectionTestUtils.setField(controller, "infoUserService", infoUserService);
|
|
|
+ ReflectionTestUtils.setField(controller, "businessPhoneService", businessPhoneService);
|
|
|
+
|
|
|
+ InfoUser request = new InfoUser();
|
|
|
+ request.setUserId(940L);
|
|
|
+ request.setUserName("hujiaobing1");
|
|
|
+ request.setTelPhone("0999999");
|
|
|
+ request.setPassword("rsa-cipher");
|
|
|
+
|
|
|
+ try (MockedStatic<MessageUtils> messages = mockStatic(MessageUtils.class)) {
|
|
|
+ messages.when(() -> MessageUtils.message("no.success")).thenReturn("ok");
|
|
|
+ controller.editStallOwner(JwtUtil.setToken("10", "night-market"), request);
|
|
|
+ }
|
|
|
+
|
|
|
+ ArgumentCaptor<InfoUser> updated = ArgumentCaptor.forClass(InfoUser.class);
|
|
|
+ verify(infoUserService).updateInfoUser(updated.capture());
|
|
|
+ assertEquals("rsa-cipher", updated.getValue().getPassword());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void editStallOwnerRejectsNonOwningNightMarket() throws Exception {
|
|
|
+ IPosStoreService posStoreService = mock(IPosStoreService.class);
|
|
|
+ IInfoUserService infoUserService = mock(IInfoUserService.class);
|
|
|
+ InfoUser existing = new InfoUser();
|
|
|
+ existing.setUserId(940L);
|
|
|
+ existing.setUserType("4");
|
|
|
+ existing.setDelFlag("0");
|
|
|
+ existing.setStoreId(8L);
|
|
|
+ when(infoUserService.selectInfoUserByUserId(940L)).thenReturn(existing);
|
|
|
+ PosStore store = new PosStore();
|
|
|
+ store.setId(8);
|
|
|
+ store.setIsStall(1);
|
|
|
+ store.setUserId(10L);
|
|
|
+ when(posStoreService.selectPosStoreById(8L)).thenReturn(store);
|
|
|
+
|
|
|
+ StallController controller = new StallController();
|
|
|
+ ReflectionTestUtils.setField(controller, "posStoreService", posStoreService);
|
|
|
+ ReflectionTestUtils.setField(controller, "infoUserService", infoUserService);
|
|
|
+
|
|
|
+ InfoUser request = new InfoUser();
|
|
|
+ request.setUserId(940L);
|
|
|
+ request.setUserName("hujiaobing1");
|
|
|
+ request.setTelPhone("0999999");
|
|
|
+
|
|
|
+ AjaxResult result;
|
|
|
+ try (MockedStatic<MessageUtils> messages = mockStatic(MessageUtils.class)) {
|
|
|
+ messages.when(() -> MessageUtils.message("merchant.store.access.denied")).thenReturn("无权限");
|
|
|
+ result = controller.editStallOwner(JwtUtil.setToken("20", "other"), request);
|
|
|
+ }
|
|
|
+
|
|
|
+ assertEquals(HttpStatus.ERROR, result.get(AjaxResult.CODE_TAG));
|
|
|
+ verify(infoUserService, never()).updateInfoUser(any(InfoUser.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void editStallOwnerRejectsDuplicateUserName() throws Exception {
|
|
|
+ IPosStoreService posStoreService = mock(IPosStoreService.class);
|
|
|
+ IInfoUserService infoUserService = mock(IInfoUserService.class);
|
|
|
+ BusinessPhoneService businessPhoneService = mock(BusinessPhoneService.class);
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ LambdaQueryChainWrapper<InfoUser> nameQuery = mock(LambdaQueryChainWrapper.class);
|
|
|
+ when(infoUserService.lambdaQuery()).thenReturn(nameQuery);
|
|
|
+ when(nameQuery.eq(any(SFunction.class), any())).thenReturn(nameQuery);
|
|
|
+ when(nameQuery.ne(any(SFunction.class), any())).thenReturn(nameQuery);
|
|
|
+ when(nameQuery.one()).thenReturn(new InfoUser());
|
|
|
+ InfoUser existing = new InfoUser();
|
|
|
+ existing.setUserId(940L);
|
|
|
+ existing.setUserType("4");
|
|
|
+ existing.setDelFlag("0");
|
|
|
+ existing.setStoreId(8L);
|
|
|
+ when(infoUserService.selectInfoUserByUserId(940L)).thenReturn(existing);
|
|
|
+ PosStore store = new PosStore();
|
|
|
+ store.setId(8);
|
|
|
+ store.setIsStall(1);
|
|
|
+ store.setUserId(10L);
|
|
|
+ when(posStoreService.selectPosStoreById(8L)).thenReturn(store);
|
|
|
+
|
|
|
+ StallController controller = new StallController();
|
|
|
+ ReflectionTestUtils.setField(controller, "posStoreService", posStoreService);
|
|
|
+ ReflectionTestUtils.setField(controller, "infoUserService", infoUserService);
|
|
|
+ ReflectionTestUtils.setField(controller, "businessPhoneService", businessPhoneService);
|
|
|
+
|
|
|
+ InfoUser request = new InfoUser();
|
|
|
+ request.setUserId(940L);
|
|
|
+ request.setUserName("taken-name");
|
|
|
+ request.setTelPhone("0999999");
|
|
|
+
|
|
|
+ AjaxResult result;
|
|
|
+ try (MockedStatic<MessageUtils> messages = mockStatic(MessageUtils.class)) {
|
|
|
+ messages.when(() -> MessageUtils.message("stall.owner.name.exist")).thenReturn("用户名已存在");
|
|
|
+ result = controller.editStallOwner(JwtUtil.setToken("10", "night-market"), request);
|
|
|
+ }
|
|
|
+
|
|
|
+ assertEquals(HttpStatus.ERROR, result.get(AjaxResult.CODE_TAG));
|
|
|
+ verify(businessPhoneService, never()).ensureUnique(any(), any());
|
|
|
+ verify(infoUserService, never()).updateInfoUser(any(InfoUser.class));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
void anotherNightMarketCannotEditStallOrPaymentRoutingFields() {
|
|
|
IPosStoreService stores = mock(IPosStoreService.class);
|