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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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 ShoppingMerchantPortalServiceTests {
    @Mock
    private JdbcTemplate jdbc;
 
    @Mock
    private PortalService portalService;
 
    @Mock
    private TalentCardPortalService talentCardPortalService;
 
    @InjectMocks
    private ShoppingMerchantPortalService service;
 
    @Test
    void usesCardLevelRightTagAndDetailConfiguredForTalent() {
        Long merchantId = 102L;
        Long talentId = 1015L;
        when(jdbc.queryForList(anyString(), eq(merchantId))).thenReturn(List.of(Map.ofEntries(
                Map.entry("id", merchantId),
                Map.entry("merchant_name", "喜望数码服务"),
                Map.entry("merchant_status", 1),
                Map.entry("category_key", "digital"),
                Map.entry("service_label", ""),
                Map.entry("talent_levels", "请咨询服务专员"),
                Map.entry("address", "成都市天府新谷"),
                Map.entry("contact_mobile", "13540211247"),
                Map.entry("rights_text", "旧权益说明"))));
        when(portalService.merchantDetail(merchantId, talentId)).thenReturn(Map.of(
                "rightsStatus", "AVAILABLE",
                "rightsTag", "后台配置的购车权益标签",
                "applicableCards", "后台配置的购车权益标签",
                "rightsText", "后台配置的数码服务权益详情"));
        when(talentCardPortalService.profile(talentId)).thenReturn(Map.of(
                "advisor", Map.of(
                        "name", "账号服务专员",
                        "mobile", "13911112222")));
 
        Map<String, Object> detail = service.detail(merchantId, talentId);
 
        assertThat(detail)
                .containsEntry("applicableCards", "后台配置的购车权益标签")
                .containsEntry("benefitDetail", "后台配置的数码服务权益详情")
                .containsEntry("discountText", "")
                .containsEntry("address", "成都市天府新谷")
                .containsEntry("available", true);
        assertThat(detail.get("advisor")).isInstanceOfSatisfying(Map.class, advisor -> assertThat(advisor)
                .containsEntry("name", "账号服务专员")
                .containsEntry("mobile", "13911112222")
                .containsEntry("available", true)
                .doesNotContainValue("13540211247"));
    }
 
    @Test
    void doesNotFallbackToMerchantPhoneWhenTalentHasNoAdvisor() {
        Long merchantId = 102L;
        Long talentId = 1015L;
        when(jdbc.queryForList(anyString(), eq(merchantId))).thenReturn(List.of(Map.ofEntries(
                Map.entry("id", merchantId),
                Map.entry("merchant_name", "购房优惠商家"),
                Map.entry("merchant_status", 1),
                Map.entry("category_key", "housing"),
                Map.entry("contact_mobile", "13540211247"))));
        when(portalService.merchantDetail(merchantId, talentId)).thenReturn(Map.of(
                "rightsStatus", "AVAILABLE"));
        when(talentCardPortalService.profile(talentId)).thenReturn(Map.of());
 
        Map<String, Object> detail = service.detail(merchantId, talentId);
 
        assertThat(detail.get("advisor")).isEqualTo(Map.of("available", false));
    }
}