|
|
@@ -7,22 +7,31 @@ import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
|
|
import com.ruoyi.common.constant.HttpStatus;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.system.domain.InfoUser;
|
|
|
import com.ruoyi.system.domain.PosOrder;
|
|
|
import com.ruoyi.system.service.IInfoUserService;
|
|
|
import com.ruoyi.system.service.IPosOrderService;
|
|
|
+import com.ruoyi.system.service.IUserWalletService;
|
|
|
import com.ruoyi.system.utils.JwtUtil;
|
|
|
+import com.ruoyi.common.utils.spring.SpringUtils;
|
|
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
|
-import org.junit.jupiter.api.BeforeEach;
|
|
|
+import org.junit.jupiter.api.AfterAll;
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.mockito.ArgumentCaptor;
|
|
|
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|
|
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
|
|
+import org.springframework.context.support.StaticMessageSource;
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.Locale;
|
|
|
|
|
|
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.junit.jupiter.api.Assertions.assertTrue;
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
@@ -36,11 +45,27 @@ class InfoUserControllerTest {
|
|
|
private InfoUserController controller;
|
|
|
private IPosOrderService posOrderService;
|
|
|
private IInfoUserService infoUserService;
|
|
|
+ private IUserWalletService userWalletService;
|
|
|
+ private static ConfigurableListableBeanFactory originalBeanFactory;
|
|
|
|
|
|
@BeforeAll
|
|
|
static void initializeTableMetadata() {
|
|
|
TableInfoHelper.initTableInfo(
|
|
|
new MapperBuilderAssistant(new MybatisConfiguration(), ""), PosOrder.class);
|
|
|
+ originalBeanFactory = (ConfigurableListableBeanFactory)
|
|
|
+ ReflectionTestUtils.getField(SpringUtils.class, "beanFactory");
|
|
|
+ DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
|
|
+ StaticMessageSource messageSource = new StaticMessageSource();
|
|
|
+ messageSource.addMessage("no.user.audit.reject.reason.required", Locale.getDefault(),
|
|
|
+ "审核不通过时必须填写审核不通过原因");
|
|
|
+ messageSource.addMessage("no.action.success", Locale.getDefault(), "操作成功");
|
|
|
+ beanFactory.registerSingleton("messageSource", messageSource);
|
|
|
+ new SpringUtils().postProcessBeanFactory(beanFactory);
|
|
|
+ }
|
|
|
+
|
|
|
+ @AfterAll
|
|
|
+ static void restoreBeanFactory() {
|
|
|
+ new SpringUtils().postProcessBeanFactory(originalBeanFactory);
|
|
|
}
|
|
|
|
|
|
@BeforeEach
|
|
|
@@ -48,8 +73,10 @@ class InfoUserControllerTest {
|
|
|
controller = new TestInfoUserController();
|
|
|
posOrderService = mock(IPosOrderService.class);
|
|
|
infoUserService = mock(IInfoUserService.class);
|
|
|
+ userWalletService = mock(IUserWalletService.class);
|
|
|
ReflectionTestUtils.setField(controller, "posOrderService", posOrderService);
|
|
|
ReflectionTestUtils.setField(controller, "infoUserService", infoUserService);
|
|
|
+ ReflectionTestUtils.setField(controller, "userWalletService", userWalletService);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -89,6 +116,71 @@ class InfoUserControllerTest {
|
|
|
assertTrue(sql.contains("sh_id"));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void rejectsAuditRejectionWithoutReason() {
|
|
|
+ InfoUser user = new InfoUser();
|
|
|
+ user.setAuditStatus("2");
|
|
|
+ user.setAuditRejectReason(" ");
|
|
|
+
|
|
|
+ AjaxResult result = controller.edit(user);
|
|
|
+
|
|
|
+ assertEquals(HttpStatus.ERROR, result.get(AjaxResult.CODE_TAG));
|
|
|
+ verify(infoUserService, never()).updateInfoUser(any(InfoUser.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void rejectsNewAuditRejectionWithoutReason() {
|
|
|
+ InfoUser user = new InfoUser();
|
|
|
+ user.setUserName("merchant");
|
|
|
+ user.setPhone("0912345678");
|
|
|
+ user.setAuditStatus("2");
|
|
|
+ user.setAuditRejectReason(" ");
|
|
|
+
|
|
|
+ AjaxResult result = controller.add(user);
|
|
|
+
|
|
|
+ assertEquals(HttpStatus.ERROR, result.get(AjaxResult.CODE_TAG));
|
|
|
+ verify(infoUserService, never()).insertInfoUser(any(InfoUser.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void profileUpdateCannotChangeAuditStatus() {
|
|
|
+ InfoUser request = new InfoUser();
|
|
|
+ request.setAuditStatus("1");
|
|
|
+ when(infoUserService.saveOrUpdate(any(InfoUser.class))).thenReturn(true);
|
|
|
+
|
|
|
+ controller.setuser(tokenFor(42L), request);
|
|
|
+
|
|
|
+ ArgumentCaptor<InfoUser> captor = ArgumentCaptor.forClass(InfoUser.class);
|
|
|
+ verify(infoUserService).saveOrUpdate(captor.capture());
|
|
|
+ assertNull(captor.getValue().getAuditStatus());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void trimsAndSavesAuditRejectionReason() {
|
|
|
+ InfoUser user = new InfoUser();
|
|
|
+ user.setAuditStatus("2");
|
|
|
+ user.setAuditRejectReason(" 证件照片模糊 ");
|
|
|
+ when(infoUserService.updateInfoUser(user)).thenReturn(1);
|
|
|
+
|
|
|
+ controller.edit(user);
|
|
|
+
|
|
|
+ assertEquals("证件照片模糊", user.getAuditRejectReason());
|
|
|
+ verify(infoUserService).updateInfoUser(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void clearsOldReasonWhenAuditPasses() {
|
|
|
+ InfoUser user = new InfoUser();
|
|
|
+ user.setAuditStatus("1");
|
|
|
+ user.setAuditRejectReason("旧原因");
|
|
|
+ when(infoUserService.updateInfoUser(user)).thenReturn(1);
|
|
|
+
|
|
|
+ controller.edit(user);
|
|
|
+
|
|
|
+ assertNull(user.getAuditRejectReason());
|
|
|
+ verify(infoUserService).updateInfoUser(user);
|
|
|
+ }
|
|
|
+
|
|
|
private String tokenFor(Long userId) {
|
|
|
return JwtUtil.setToken(String.valueOf(userId), "test-user");
|
|
|
}
|