This commit is contained in:
2026-08-07 14:46:55 +08:00
parent 830575cc92
commit b0ea1a0c5c
109 changed files with 5774 additions and 339 deletions
@@ -76,7 +76,7 @@ class TenantAdministratorProvisioningServiceTest {
var result = service.initialize(context());
assertTrue(result.created());
assertTrue(result.username().matches("^merchant_190000000000000001_[a-z]{8}$"));
assertEquals("13800138000", result.username());
assertNotNull(result.temporaryPassword());
assertEquals(16, result.temporaryPassword().length());
assertTrue(result.temporaryPassword().matches("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z0-9]+$"));
@@ -208,23 +208,16 @@ class TenantAdministratorProvisioningServiceTest {
}
@Test
void usernameConflictGeneratesAnotherUsernameBeforeCreatingOwner() {
void usernameConflictStopsProvisioningInsteadOfChangingTheContactPhoneUsername() {
org.mockito.Mockito.doReturn(ApiResponse.failure(com.baiyue.common.core.api.ResultCode.CONFLICT,
"登录账号已存在", null, null))
.doAnswer(invocation -> {
AuthAccountClient.CreateAccountRequest request = invocation.getArgument(1);
return ApiResponse.success(new AuthAccountClient.AccountSummary(
request.accountId(), request.username(), request.displayName(), "ACTIVE"));
}).when(auth).create(anyString(), any());
"登录账号已存在", null, null)).when(auth).create(anyString(), any());
var result = service.initialize(context());
var exception = assertThrows(com.baiyue.common.core.exception.BizException.class,
() -> service.initialize(context()));
assertTrue(result.created());
ArgumentCaptor<AuthAccountClient.CreateAccountRequest> accounts =
ArgumentCaptor.forClass(AuthAccountClient.CreateAccountRequest.class);
verify(auth, times(2)).create(eq("internal-token"), accounts.capture());
assertFalse(accounts.getAllValues().get(0).username().equals(accounts.getAllValues().get(1).username()));
assertEquals(accounts.getAllValues().get(1).username(), result.username());
assertEquals(com.baiyue.common.core.api.ResultCode.CONFLICT, exception.getResultCode());
verify(auth).create(eq("internal-token"), any());
verify(members, never()).insertUser(any());
}
private TenantApprovalInitializer.ApprovalContext context() {
@@ -92,7 +92,7 @@ class TenantServiceTest {
when(repository.findTenant(10001L)).thenReturn(tenant);
var updated = service.updateMerchant(10001L,
new UpdateTenantRequest("New name", "New legal", "Bob", "Alice", "13900139000", "alice@example.com",
new UpdateTenantRequest("New name", "New legal", "Bob", "Alice", "13800138000", "alice@example.com",
"专业版", "alice_wechat", "Sales Zhang", 45, "LIMITED_COMPANY", LocalDate.of(2020, 1, 2),
new BigDecimal("5000000.00"), "CNY", "深圳市南山区示例路 1 号", "一期重点客户"));
var disabled = service.changeMerchantStatus(10001L, new ChangeTenantStatusRequest("DISABLED"));
@@ -113,6 +113,29 @@ class TenantServiceTest {
verify(repository, org.mockito.Mockito.times(2)).saveTenant(tenant);
}
@Test
void activeCustomerCannotChangeTheContactPhoneUsedAsItsLoginUsername() {
IamTenant tenant = merchant(10001L, "ACTIVE");
when(repository.findTenant(10001L)).thenReturn(tenant);
BizException exception = assertThrows(BizException.class, () -> service.updateMerchant(10001L,
new UpdateTenantRequest("New name", "New legal", "Bob", "Alice", "13900139000", null,
"基础版", null, null, 30, null, null, null, "CNY", null, null)));
assertEquals(ResultCode.CONFLICT, exception.getResultCode());
assertEquals("13800138000", tenant.getContactPhone());
verify(repository, never()).saveTenant(tenant);
}
@Test
void contactPhoneAvailabilityAlsoChecksTheAuthUsernameFactSource() {
when(authClient.availability("internal-token", "13800138000"))
.thenReturn(com.baiyue.common.core.api.ApiResponse.success(false));
assertEquals(false, service.contactPhoneAndUsernameAvailable("13800138000", null));
verify(authClient).availability("internal-token", "13800138000");
}
@Test
void platformCannotBypassReviewToActivatePendingTenant() {
when(repository.findTenant(10001L)).thenReturn(merchant(10001L, "PENDING"));