|
|
@@ -99,6 +99,7 @@ class InfoUserControllerTest {
|
|
|
messageSource.addMessage("no.system.error", Locale.getDefault(), "系统错误");
|
|
|
messageSource.addMessage("no.user.jcaptcha.error", Locale.getDefault(), "验证码错误");
|
|
|
messageSource.addMessage("no.oauth.tempkey.expired", Locale.getDefault(), "登录凭证已过期");
|
|
|
+ messageSource.addMessage("no.oauth.phone.duplicate", Locale.getDefault(), "该手机号关联多个账号,请联系平台");
|
|
|
beanFactory.registerSingleton("messageSource", messageSource);
|
|
|
beanFactory.registerSingleton("redisCache", mock(RedisCache.class));
|
|
|
new SpringUtils().postProcessBeanFactory(beanFactory);
|
|
|
@@ -392,7 +393,8 @@ class InfoUserControllerTest {
|
|
|
|
|
|
InfoUser createdUser = activeUser(99L, "0");
|
|
|
createdUser.setPhone("0912345678");
|
|
|
- when(infoUserService.getOne(any(Wrapper.class))).thenReturn(null, createdUser);
|
|
|
+ when(infoUserService.list(any(Wrapper.class)))
|
|
|
+ .thenReturn(java.util.List.of(), java.util.List.of(createdUser));
|
|
|
when(infoUserService.saveOrUpdate(any(InfoUser.class))).thenReturn(true);
|
|
|
|
|
|
AjaxResult result = controller.oauthBindPhone(request);
|
|
|
@@ -488,7 +490,7 @@ class InfoUserControllerTest {
|
|
|
OAuthBindDto request = oauthRequest(provider);
|
|
|
InfoUser business = activeUser(72L, role);
|
|
|
business.setTelPhone(request.getPhone());
|
|
|
- when(infoUserService.getOne(any(Wrapper.class))).thenReturn(business);
|
|
|
+ when(infoUserService.list(any(Wrapper.class))).thenReturn(java.util.List.of(business));
|
|
|
when(infoUserService.saveOrUpdate(any(InfoUser.class))).thenReturn(true);
|
|
|
|
|
|
AjaxResult result = controller.oauthBindPhone(request);
|
|
|
@@ -503,7 +505,7 @@ class InfoUserControllerTest {
|
|
|
assertEquals(provider, binding.getValue().getProvider());
|
|
|
verify(infoUserService, never()).getuser(any());
|
|
|
ArgumentCaptor<Wrapper<InfoUser>> query = ArgumentCaptor.forClass(Wrapper.class);
|
|
|
- verify(infoUserService).getOne(query.capture());
|
|
|
+ verify(infoUserService).list(query.capture());
|
|
|
assertTrue(query.getValue().getSqlSegment().contains("tel_phone"));
|
|
|
}
|
|
|
|
|
|
@@ -589,7 +591,8 @@ class InfoUserControllerTest {
|
|
|
OAuthBindDto request = oauthRequest(provider);
|
|
|
InfoUser user = activeUser(72L, "0");
|
|
|
user.setPhone(request.getPhone());
|
|
|
- when(infoUserService.getuser(request.getPhone())).thenReturn(null, user);
|
|
|
+ when(infoUserService.list(any(Wrapper.class)))
|
|
|
+ .thenReturn(java.util.List.of(), java.util.List.of(user));
|
|
|
when(infoUserService.saveOrUpdate(any(InfoUser.class))).thenReturn(true);
|
|
|
|
|
|
AjaxResult result = controller.oauthBindPhone(request);
|
|
|
@@ -608,7 +611,7 @@ class InfoUserControllerTest {
|
|
|
OAuthBindDto request = oauthRequest(provider);
|
|
|
InfoUser user = activeUser(72L, "5");
|
|
|
user.setSubaccountStatus("0");
|
|
|
- when(infoUserService.getOne(any(Wrapper.class))).thenReturn(user);
|
|
|
+ when(infoUserService.list(any(Wrapper.class))).thenReturn(java.util.List.of(user));
|
|
|
doThrow(new ServiceException("owner unavailable")).when(merchantStoreAccessService).resolve(72L);
|
|
|
AjaxResult result = controller.oauthBindPhone(request);
|
|
|
assertEquals(HttpStatus.ERROR, result.get(AjaxResult.CODE_TAG));
|
|
|
@@ -641,6 +644,33 @@ class InfoUserControllerTest {
|
|
|
verify(infoUserOauthMapper, never()).insert(any(InfoUserOauth.class));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void oauthBindPhoneRejectsPhoneLinkedToMultipleAccounts() {
|
|
|
+ OAuthBindDto request = oauthRequest("apple");
|
|
|
+ when(infoUserService.list(any(Wrapper.class))).thenReturn(java.util.List.of(
|
|
|
+ activeUser(71L, "0"), activeUser(72L, "0")));
|
|
|
+
|
|
|
+ ServiceException exception = assertThrows(ServiceException.class,
|
|
|
+ () -> controller.oauthBindPhone(request));
|
|
|
+
|
|
|
+ assertEquals("该手机号关联多个账号,请联系平台", exception.getMessage());
|
|
|
+ verify(infoUserOauthMapper, never()).insert(any(InfoUserOauth.class));
|
|
|
+ verify(infoUserService, never()).saveOrUpdate(any(InfoUser.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void merchantOauthBindPhoneRejectsPhoneLinkedToMultipleStores() {
|
|
|
+ OAuthBindDto request = oauthRequest("line_merchant");
|
|
|
+ when(infoUserService.list(any(Wrapper.class))).thenReturn(java.util.List.of(
|
|
|
+ activeUser(71L, "1"), activeUser(72L, "1")));
|
|
|
+
|
|
|
+ ServiceException exception = assertThrows(ServiceException.class,
|
|
|
+ () -> controller.oauthBindPhone(request));
|
|
|
+
|
|
|
+ assertEquals("该手机号关联多个账号,请联系平台", exception.getMessage());
|
|
|
+ verify(infoUserOauthMapper, never()).insert(any(InfoUserOauth.class));
|
|
|
+ }
|
|
|
+
|
|
|
private OAuthBindDto oauthRequest(String provider) {
|
|
|
OAuthBindDto request = new OAuthBindDto();
|
|
|
request.setTempKey("business-key");
|