优化
This commit is contained in:
@@ -4,6 +4,7 @@ import com.baiyue.auth.dto.AccountManagementDtos.ChangePasswordRequest;
|
||||
import com.baiyue.auth.dto.AccountManagementDtos.CreateAccountRequest;
|
||||
import com.baiyue.auth.dto.AccountManagementDtos.UpdateAccountProfileRequest;
|
||||
import com.baiyue.auth.dto.AccountManagementDtos.UpdateAccountStatusRequest;
|
||||
import com.baiyue.auth.dto.AccountManagementDtos.UpdateAccountScopeRequest;
|
||||
import com.baiyue.auth.entity.AuthAccount;
|
||||
import com.baiyue.auth.repository.AuthAccountRepository;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
@@ -15,6 +16,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@DisplayName("账号管理服务")
|
||||
class AccountManagementServiceTest {
|
||||
@@ -69,6 +71,37 @@ class AccountManagementServiceTest {
|
||||
assertNotEquals("Password1", captor.getValue().getPasswordHash());
|
||||
}
|
||||
|
||||
@Test void createDisabledAccountAndSummaryExposeLastLoginAndScope() {
|
||||
when(repository.findById(20L)).thenReturn(null);
|
||||
when(repository.existsByUsername("merchant.user")).thenReturn(false);
|
||||
|
||||
var created = service.create(new CreateAccountRequest(20L, "merchant.user", "Password1",
|
||||
"企业用户", 10001L, 30L, "MERCHANT", "DISABLED"));
|
||||
var captor = org.mockito.ArgumentCaptor.forClass(AuthAccount.class);
|
||||
verify(repository).insert(captor.capture());
|
||||
AuthAccount stored = captor.getValue();
|
||||
stored.setLastLoginAt(LocalDateTime.of(2026, 6, 1, 10, 30));
|
||||
when(repository.findById(20L)).thenReturn(stored);
|
||||
|
||||
var summary = service.summary(20L);
|
||||
assertEquals("DISABLED", created.status());
|
||||
assertEquals(10001L, summary.tenantId());
|
||||
assertEquals(30L, summary.membershipId());
|
||||
assertEquals(LocalDateTime.of(2026, 6, 1, 10, 30), summary.lastLoginAt());
|
||||
}
|
||||
|
||||
@Test void updateScopeChangesTenantAndRevokesExistingSessions() {
|
||||
account.setDefaultTenantId(10001L); account.setOperatorTenantId(10001L);
|
||||
account.setDefaultMembershipId(30L); account.setDefaultAppCode("MERCHANT");
|
||||
|
||||
service.updateScope(10L, new UpdateAccountScopeRequest(10002L, 30L, "MERCHANT"));
|
||||
|
||||
assertEquals(10002L, account.getDefaultTenantId());
|
||||
assertEquals(10002L, account.getOperatorTenantId());
|
||||
verify(repository).save(account);
|
||||
verify(sessions).revokeAll(10L);
|
||||
}
|
||||
|
||||
@Test void createAccountRetriesIdempotentlyForSameAccountAndOwner() {
|
||||
account.setUsername("platform.user"); account.setDisplayName("平台用户");
|
||||
account.setDefaultTenantId(0L); account.setOperatorTenantId(0L);
|
||||
|
||||
Reference in New Issue
Block a user