package com.talentcard.server.business.portal; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import java.util.List; import java.util.Map; 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; @ExtendWith(MockitoExtension.class) class ChildrenEntrustmentPortalServiceTests { @Mock private JdbcTemplate jdbc; @InjectMocks private ChildrenEntrustmentPortalService service; @Test void returnsSchoolDetailFromMerchantConfiguration() { Long serviceId = 91L; when(jdbc.queryForList(anyString(), eq(serviceId))).thenReturn(List.of(Map.of( "id", serviceId, "merchant_type_code", "children", "usage_instructions", "[{\"name\":\"第一中学\",\"address\":\"学校地址\",\"detail\":\"
后台配置的学校详情
\"}]"))); Map后台配置的学校详情
"); } @Test void unconfiguredMerchantHasNoSchools() { Long serviceId = 91L; // 新添加、还没配学校的商家:不能回落到历史全局学校表(否则会显示别人的学校)。 when(jdbc.queryForList(anyString(), eq(serviceId))).thenReturn(List.of(Map.of( "id", serviceId, "merchant_type_code", "children", "usage_instructions", ""))); assertThat(service.schools(serviceId)).isEmpty(); } }