shinnosuke
2026-08-27 b0edd6c4bd7912e706ef3af5a221caf0d6c78fac
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
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.Mockito.when;
 
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
 
import com.talentcard.server.service.TicketPackagePortalService;
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 CinemaPortalServiceTests {
    @Mock
    private JdbcTemplate jdbc;
 
    @Mock
    private TicketPackagePortalService ticketPackageService;
 
    @InjectMocks
    private CinemaPortalService service;
 
    @Test
    void usesConfiguredRightsDescriptionWhenCinemaHasTicketPackage() {
        when(jdbc.queryForList(anyString(), any(Object[].class))).thenAnswer(invocation -> {
            String sql = invocation.getArgument(0);
            if (sql.contains("from merchant where")) {
                return List.of(Map.ofEntries(
                        Map.entry("id", 87L),
                        Map.entry("merchant_name", "电影院1"),
                        Map.entry("merchant_type", "cinema"),
                        Map.entry("status", 1),
                        Map.entry("merchant_rights_config", "[{\"level\":\"卓越人才卡\",\"tag\":\"人才专享\",\"detail\":\"后台配置的权益详情描述\",\"enabled\":true}]")));
            }
            if (sql.contains("from talent_card c join talent_user")) {
                return List.of(Map.of(
                        "card_id", 15L,
                        "card_level", "卓越人才卡",
                        "card_type", "PERSONAL"));
            }
            if (sql.contains("from ticket_package p")) {
                return List.of(Map.ofEntries(
                        Map.entry("id", 23L),
                        Map.entry("package_name", "电影票包"),
                        Map.entry("claim_price", BigDecimal.ZERO),
                        Map.entry("talent_levels", "卓越人才卡"),
                        Map.entry("usage_text", "电影票包使用说明"),
                        Map.entry("merchant_names", "电影院1")));
            }
            return List.of();
        });
 
        Map<String, Object> detail = service.detail(87L, 5L, 15L);
 
        assertThat(detail)
                .containsEntry("rightsDescription", "后台配置的权益详情描述")
                .containsEntry("usage", "电影票包使用说明");
    }
}