Merge remote-tracking branch 'origin/test' into dev

This commit is contained in:
2026-09-01 19:25:16 +08:00
56 changed files with 1478 additions and 117 deletions
@@ -161,6 +161,8 @@ class MemberServiceTest {
@Test void shouldHandleCase08() {
IamRole role = activeMerchantRole(50L, 100L);
when(roleMapper.selectById(50L)).thenReturn(role);
when(auth.phone(eq("internal-token"), eq(40L), any()))
.thenReturn(ApiResponse.success(null));
UpdateMemberRequest request = new UpdateMemberRequest("新姓名", "13800138000", null,
"EMPLOYEE", "M-001", List.of(50L));
@@ -169,6 +171,7 @@ class MemberServiceTest {
assertEquals("新姓名", result.displayName());
verify(repository).saveUser(user);
verify(repository).replaceRoles(100L, 20L, List.of(50L));
verify(auth).phone(eq("internal-token"), eq(40L), any());
}
@Test void shouldHandleCase09() {
@@ -83,6 +83,25 @@ class MerchantQualificationUploadTest {
verify(tenantRepository).saveTenant(tenant);
}
@Test
void requiredPackageAcceptsAnEmptyOptionalLegalPersonId() {
IamTenant tenant = new IamTenant();
tenant.setId(10001L);
tenant.setTenantType("MERCHANT");
tenant.setStatus("PROFILE_REQUIRED");
when(tenantRepository.findTenantForUpdate(10001L)).thenReturn(tenant);
when(profileRepository.findQualificationsForUpdate(10001L)).thenReturn(List.of());
var response = service.submitRequiredQualificationPackage(new RequiredQualificationPackageRequest(
10001L, "91310101abcde12345",
"/api/merchant/v1/files/qualifications/license.png", null, false,
null, null, null));
assertNull(response.legalPersonIdQualificationId());
verify(profileRepository, times(1)).insertQualification(any());
verify(tenantRepository).saveTenant(tenant);
}
@Test
void requiredPackageCannotOverwriteAnEstablishedCreditCode() {
IamTenant tenant = new IamTenant();
@@ -2,6 +2,9 @@ package com.baiyue.iam.service;
import com.baiyue.common.core.exception.BizException;
import com.baiyue.iam.dto.ProfileDtos.UpdatePersonalProfileRequest;
import com.baiyue.iam.dto.ProfileDtos.ChangeLoginIdentifiersRequest;
import com.baiyue.iam.client.AuthAccountClient;
import com.baiyue.common.core.api.ApiResponse;
import com.baiyue.iam.entity.IamMembership;
import com.baiyue.iam.entity.IamUser;
import com.baiyue.iam.repository.MemberRepository;
@@ -10,14 +13,17 @@ import org.junit.jupiter.api.Test;
import jakarta.annotation.Resource;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.context.TestPropertySource;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@DisplayName("个人资料服务")
@SpringJUnitConfig(PersonalProfileService.class)
@TestPropertySource(properties = "baiyue.security.internal-service-token=test-internal-token")
class PersonalProfileServiceTest {
@MockBean private MemberRepository repository;
@MockBean private AuthAccountClient authClient;
@Resource private PersonalProfileService service;
@Test void canOnlyModifyOwnProfileWithinCurrentTenant() {
@@ -26,11 +32,29 @@ class PersonalProfileServiceTest {
when(repository.findByTenantAndAuthUser(1L, 2L)).thenReturn(membership);
when(repository.findUser(3L)).thenReturn(user);
var result = service.update(1L, 2L, "tester",
new UpdatePersonalProfileRequest("新姓名", "13800138000", "a@example.com"));
new UpdatePersonalProfileRequest("新姓名", "a@example.com"));
assertEquals("新姓名", result.displayName());
verify(repository).saveUser(user);
}
@Test void sensitiveLoginIdentifiersAreChangedOnlyThroughAuthReauthentication() {
IamMembership membership = new IamMembership(); membership.setUserId(3L); membership.setStatus("ACTIVE");
IamUser user = new IamUser(); user.setId(3L); user.setAuthUserId(2L); user.setDisplayName("测试用户");
when(repository.findByTenantAndAuthUser(1L, 2L)).thenReturn(membership);
when(repository.findUser(3L)).thenReturn(user);
when(authClient.changeLoginIdentifiers(any(), eq(2L), any())).thenReturn(ApiResponse.success(
new AuthAccountClient.AccountSummary(2L, "new.user", "13900139000", "测试用户", "ACTIVE",
null, 1L, 4L, "MERCHANT")));
var result = service.changeLoginIdentifiers(1L, 2L,
new ChangeLoginIdentifiersRequest("new.user", "13900139000", "CurrentPass1"));
assertEquals("new.user", result.username());
assertEquals("13900139000", result.phone());
verify(repository).saveUser(user);
}
@Test void crossTenantIdentityIsRejected() {
assertThrows(BizException.class, () -> service.get(9L, 2L, "tester"));
}
@@ -369,11 +369,11 @@ class TenantServiceTest {
}
@Test
void explicitSubmissionRequiresOnlyBusinessLicenseAndLegalPersonIdAndCreatesReview() {
void explicitSubmissionRequiresBusinessLicenseAndCreatesReview() {
IamTenant tenant = merchant(10001L, "PROFILE_REQUIRED");
when(repository.findTenantForUpdate(10001L)).thenReturn(tenant);
when(profileRepository.findQualifications(10001L)).thenReturn(List.of(
qualification("BUSINESS_LICENSE"), qualification("LEGAL_PERSON_ID")));
qualification("BUSINESS_LICENSE")));
var submitted = service.submitMerchantReview(10001L);
@@ -383,10 +383,10 @@ class TenantServiceTest {
}
@Test
void explicitSubmissionRejectsAnIncompleteQualificationSet() {
void explicitSubmissionRejectsMissingBusinessLicense() {
when(repository.findTenantForUpdate(10001L)).thenReturn(merchant(10001L, "PROFILE_REQUIRED"));
when(profileRepository.findQualifications(10001L)).thenReturn(List.of(
qualification("BUSINESS_LICENSE")));
qualification("LEGAL_PERSON_ID")));
BizException exception = assertThrows(BizException.class, () -> service.submitMerchantReview(10001L));
@@ -480,8 +480,8 @@ class TenantServiceTest {
void shouldHandleCase01() {
when(repository.findTenant(10001L)).thenReturn(merchant(10001L, "ACTIVE"));
when(profileRepository.findQualifications(10001L)).thenReturn(
List.of(approvedQualification("BUSINESS_LICENSE")),
List.of(approvedQualification("BUSINESS_LICENSE"), approvedQualification("LEGAL_PERSON_ID"),
List.of(),
List.of(approvedQualification("BUSINESS_LICENSE"),
rejectedQualification("FREIGHT_FORWARDER_CERTIFICATE")));
var withoutQualification = service.orderEligibility(10001L);