shinnosuke
2026-09-11 b36f4c2800e88f8c5060ae926d3eb25d4bcb69c0
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.talentcard.server.business.portal;
 
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 java.lang.reflect.Method;
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 PortalServiceTests {
 
    @Mock
    private JdbcTemplate jdbc;
 
    @InjectMocks
    private PortalService service;
 
    @Test
    void cinemaMerchantOnlyShowsCouponTagWhenAnActiveCouponExists() {
        when(jdbc.queryForList(anyString(), any(Object[].class))).thenReturn(List.of(
                Map.of("id", 1L, "merchant_name", "有券影院", "merchant_type", "cinema", "status", 1, "coupon_available", 1),
                Map.of("id", 2L, "merchant_name", "无券影院", "merchant_type", "cinema", "status", 1, "coupon_available", 0)));
        when(jdbc.queryForObject(anyString(), eq(Long.class), any(Object[].class))).thenReturn(2L);
 
        var result = service.entertainmentMerchants(1, 4);
 
        assertThat(result.records().get(0))
                .containsEntry("couponAvailable", true)
                .containsEntry("discountText", "券");
        assertThat(result.records().get(1))
                .containsEntry("couponAvailable", false)
                .containsEntry("discountText", "");
    }
 
    @Test
    void shoppingMerchantUsesConfiguredStoreDiscountInsteadOfRightsTag() throws Exception {
        Method method = PortalService.class.getDeclaredMethod("merchantRightDiscountText", Map.class);
        method.setAccessible(true);
 
        String discount = (String) method.invoke(service, Map.of(
                "enabled", true,
                "tag", "卓越人才到店消费可用",
                "storeConsume", true,
                "consumeEnabled", true,
                "discount", "8.50"));
 
        assertThat(discount).isEqualTo("8.5折");
    }
 
    @Test
    void carWashListHidesMiniProgramTagAndShowsNormalConfiguredDiscount() throws Exception {
        Method method = PortalService.class.getDeclaredMethod("carWashListDiscountText", String.class, Map.class);
        method.setAccessible(true);
        Map<String, Object> right = Map.of(
                "enabled", true,
                "storeConsume", true,
                "consumeEnabled", true,
                "discount", "8.50");
 
        assertThat(method.invoke(service, "miniProgram", right)).isEqualTo("");
        assertThat(method.invoke(service, "normal", right)).isEqualTo("8.5折");
    }
 
    @Test
    @SuppressWarnings("unchecked")
    void recommendedMerchantTagsFollowCategoryListRules() throws Exception {
        Method method = PortalService.class.getDeclaredMethod(
                "merchantListBenefitTags", Map.class, Map.class, Long.class);
        method.setAccessible(true);
 
        List<String> foodTags = (List<String>) method.invoke(service,
                Map.of("merchantType", "food", "couponAvailable", true, "discountText", "8.5折"),
                Map.of(), null);
        List<String> cinemaTags = (List<String>) method.invoke(service,
                Map.of("merchantType", "cinema", "couponAvailable", false, "discountText", "7折"),
                Map.of(), null);
 
        assertThat(foodTags).containsExactly("券", "8.5折");
        assertThat(cinemaTags).isEmpty();
 
        List<String> scenicTags = (List<String>) method.invoke(service,
                Map.of("merchantType", "scenic", "couponAvailable", true, "discountText", "8.8折"),
                Map.of(), null);
        List<String> cultureTags = (List<String>) method.invoke(service,
                Map.of("merchantType", "culture", "couponAvailable", true, "discountText", ""),
                Map.of(), null);
        assertThat(scenicTags).containsExactly("券", "8.8折");
        assertThat(cultureTags).containsExactly("券");
    }
 
    @Test
    @SuppressWarnings("unchecked")
    void merchantDetailHeaderTagsDriveListTags() throws Exception {
        Method method = PortalService.class.getDeclaredMethod(
                "merchantBenefitTags", String.class, boolean.class, String.class, Map.class);
        method.setAccessible(true);
 
        List<String> foodTags = (List<String>) method.invoke(service, "food", true, "8.8折", null);
        List<String> hotelTags = (List<String>) method.invoke(service, "hotel", true, "7折", Map.of(
                "freeVoucherEnabled", true,
                "freeVoucherTimes", "2",
                "storeConsume", true,
                "consumeEnabled", true,
                "consumeType", "折扣",
                "consumeDiscount", "8.5"));
 
        assertThat(foodTags).containsExactly("券", "8.8折");
        assertThat(hotelTags).containsExactly("券", "免费2次", "8.5折");
    }
}