yeg
2026-09-18 70ea0911ce7519ca802266078624e9fed3559a2c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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\":\"<p>后台配置的学校详情</p>\"}]")));
 
        Map<String, Object> detail = service.school(serviceId, "第一中学");
 
        assertThat(detail)
                .containsEntry("id", "第一中学")
                .containsEntry("name", "第一中学")
                .containsEntry("address", "学校地址")
                .containsEntry("content", "<p>后台配置的学校详情</p>");
    }
 
    @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();
    }
}