优化
This commit is contained in:
@@ -23,6 +23,7 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
||||
@SpringJUnitConfig(MerchantRegistrationService.class)
|
||||
@TestPropertySource(properties = "baiyue.security.internal-service-token=internal-token")
|
||||
@@ -61,6 +62,49 @@ class MerchantRegistrationServiceTest {
|
||||
assertEquals("PENDING", result.dimensionInitializationStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void exactIncompleteRegistrationRetryReturnsTheExistingRegistration() {
|
||||
AuthAccount account = new AuthAccount();
|
||||
account.setId(9001L);
|
||||
account.setUsername("registered_owner");
|
||||
account.setPhone("13800138000");
|
||||
account.setPasswordHash("encoded-password");
|
||||
account.setAccountStatus("ACTIVE");
|
||||
account.setDefaultAppCode("MERCHANT");
|
||||
when(accounts.findByUsername("registered_owner")).thenReturn(account);
|
||||
when(accounts.findByPhone("13800138000")).thenReturn(account);
|
||||
when(encoder.matches("Password123", "encoded-password")).thenReturn(true);
|
||||
when(onboarding.registration("internal-token", 9001L)).thenReturn(ApiResponse.success(
|
||||
new IamOnboardingClient.OnboardingResponse(10001L, 30001L, "PROFILE_REQUIRED", "READY")));
|
||||
|
||||
var result = service.register(new MerchantRegisterRequest(
|
||||
"registered_owner", "Password123", "注册人", "测试企业", null,
|
||||
"13800138000", "owner@example.com", "CN", "深圳市宝安区"));
|
||||
|
||||
assertEquals(9001L, result.accountId());
|
||||
assertEquals(10001L, result.tenantId());
|
||||
assertEquals("READY", result.dimensionInitializationStatus());
|
||||
verify(onboarding, never()).register(eq("internal-token"), any());
|
||||
verify(accounts, never()).insert(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void phoneOwnedByAnotherUsernameDirectsTheUserBackToLogin() {
|
||||
AuthAccount account = new AuthAccount();
|
||||
account.setId(9001L);
|
||||
account.setUsername("registered_owner");
|
||||
account.setPhone("13800138000");
|
||||
when(accounts.findByPhone("13800138000")).thenReturn(account);
|
||||
|
||||
var failure = assertThrows(com.baiyue.common.core.exception.BizException.class,
|
||||
() -> service.register(new MerchantRegisterRequest(
|
||||
"another_owner", "Password123", "注册人", "测试企业", null,
|
||||
"13800138000", "owner@example.com", "CN", "深圳市宝安区")));
|
||||
|
||||
assertEquals("该手机号已注册,请直接登录后继续完善企业资质", failure.getMessage());
|
||||
verify(onboarding, never()).register(eq("internal-token"), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedAuthInsertCompensatesTheIamRegistration() {
|
||||
when(encoder.encode("Password123")).thenReturn("encoded-password");
|
||||
|
||||
Reference in New Issue
Block a user