package com.talentcard.server.business.talent; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import com.talentcard.server.common.BusinessException; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.jdbc.core.JdbcTemplate; import java.util.List; @ExtendWith(MockitoExtension.class) class TalentServiceTests { @Mock private JdbcTemplate jdbcTemplate; @InjectMocks private TalentService service; private TalentCreateRequest request(String mobile) { return new TalentCreateRequest(null, "测试持卡人", mobile, "51010119900101001X", (byte) 1, "测试单位", "卓越人才卡", "TC-TEST-0001", "LOCAL", "工作地址", "联系地址"); } @Test void createRejectsMobileThatAlreadyHasAnAccount() { // 第一次查人才卡号(不存在),第二次查手机号(已存在 1 条)——一个手机号只能存在一个账号。 when(jdbcTemplate.queryForObject(anyString(), eq(Integer.class), any(Object[].class))).thenReturn(0, 1); assertThatThrownBy(() -> service.create(request("18782105413"))) .isInstanceOf(BusinessException.class) .hasMessageContaining("一个手机号只能存在一个账号"); } @Test void importLooksUpServiceStaffInStaffManagement() { // 导入 Excel 里的"服务专员"是「系统管理-员工管理」里的员工姓名(admin_operator), // 不是老的顾问表 talent_card_advisor。 when(jdbcTemplate.queryForList(anyString(), eq(Long.class), eq("7"))).thenReturn(List.of(11L)); when(jdbcTemplate.queryForList(anyString(), eq(Long.class), eq("查不到的人"))).thenReturn(List.of()); assertThat(service.serviceStaffIdByName("7")).isEqualTo(11L); assertThat(service.serviceStaffIdByName("查不到的人")).isNull(); assertThat(service.serviceStaffIdByName(" ")).isNull(); } }