liujie
2026-09-01 503f5d1ac017eebfd473459c355bd5932b7c7ca9
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
122
123
124
125
126
127
128
129
130
131
132
133
package com.tourguide.modules.user.service;
 
import com.tourguide.modules.operation.dto.PlatformSettingsResponse;
import com.tourguide.modules.operation.entity.OperationScenicSpot;
import com.tourguide.modules.operation.entity.ScenicPricing;
import com.tourguide.modules.operation.mapper.OperationScenicSpotMapper;
import com.tourguide.modules.operation.mapper.ScenicMeetingPointMapper;
import com.tourguide.modules.operation.mapper.ScenicPricingMapper;
import com.tourguide.modules.operation.service.PlatformSettingsService;
import com.tourguide.modules.order.mapper.TourOrderMapper;
import com.tourguide.modules.user.dto.GuideReceivingOptionResponse;
import com.tourguide.modules.user.entity.GuideScenicConfig;
import com.tourguide.modules.user.entity.GuideUser;
import com.tourguide.modules.user.mapper.GuideRealtimeStatusMapper;
import com.tourguide.modules.user.mapper.GuideReceivingSessionMapper;
import com.tourguide.modules.user.mapper.GuideScenicConfigMapper;
import com.tourguide.modules.user.mapper.GuideTeamScenicConfigMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
 
import java.math.BigDecimal;
import java.util.Collections;
 
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
 
class GuideReceivingServiceTest {
    private GuideUserService guideUserService;
    private GuideScenicConfigMapper guideScenicMapper;
    private OperationScenicSpotMapper scenicMapper;
    private ScenicMeetingPointMapper meetingPointMapper;
    private ScenicPricingMapper pricingMapper;
    private GuideReceivingSessionMapper sessionMapper;
    private GuideRealtimeStatusMapper realtimeStatusMapper;
    private PlatformSettingsService platformSettingsService;
    private GuideReceivingService service;
 
    @BeforeEach
    void setUp() {
        guideUserService = mock(GuideUserService.class);
        guideScenicMapper = mock(GuideScenicConfigMapper.class);
        GuideTeamScenicConfigMapper teamScenicMapper = mock(GuideTeamScenicConfigMapper.class);
        scenicMapper = mock(OperationScenicSpotMapper.class);
        meetingPointMapper = mock(ScenicMeetingPointMapper.class);
        pricingMapper = mock(ScenicPricingMapper.class);
        sessionMapper = mock(GuideReceivingSessionMapper.class);
        realtimeStatusMapper = mock(GuideRealtimeStatusMapper.class);
        platformSettingsService = mock(PlatformSettingsService.class);
        TourOrderMapper orderMapper = mock(TourOrderMapper.class);
        service = new GuideReceivingService(guideUserService, guideScenicMapper, teamScenicMapper, scenicMapper,
                meetingPointMapper, pricingMapper, sessionMapper, realtimeStatusMapper, platformSettingsService,
                orderMapper);
    }
 
    @Test
    void shouldEnablePremiumOptionsForWhitelistedGuideBelowRuleThresholds() {
        when(guideUserService.findEnabledById(8L)).thenReturn(whitelistedGuide());
        when(platformSettingsService.getSettings()).thenReturn(strictSettings());
        when(guideScenicMapper.selectList(any())).thenReturn(Collections.singletonList(scenicConfig()));
        when(scenicMapper.selectList(any())).thenReturn(Collections.singletonList(scenicSpot()));
        when(meetingPointMapper.selectList(any())).thenReturn(Collections.emptyList());
        when(pricingMapper.selectList(any())).thenReturn(Collections.singletonList(premiumPricing()));
 
        GuideReceivingOptionResponse response = service.options(8L);
 
        assertThat(response.isPremiumEnabled()).isTrue();
    }
 
    @Test
    void shouldDisablePremiumOptionsForNonWhitelistedGuideBelowRuleThresholds() {
        when(guideUserService.findEnabledById(8L)).thenReturn(nonWhitelistedGuide());
        when(platformSettingsService.getSettings()).thenReturn(strictSettings());
        when(guideScenicMapper.selectList(any())).thenReturn(Collections.singletonList(scenicConfig()));
        when(scenicMapper.selectList(any())).thenReturn(Collections.singletonList(scenicSpot()));
        when(meetingPointMapper.selectList(any())).thenReturn(Collections.emptyList());
        when(pricingMapper.selectList(any())).thenReturn(Collections.singletonList(premiumPricing()));
 
        GuideReceivingOptionResponse response = service.options(8L);
 
        assertThat(response.isPremiumEnabled()).isFalse();
    }
 
    private GuideUser whitelistedGuide() {
        GuideUser guide = new GuideUser();
        guide.setId(8L);
        guide.setAcceptedOrderCount(0L);
        guide.setRating(BigDecimal.ZERO);
        guide.setAutoDisableWhitelisted(1);
        guide.setStatus(GuideUserService.STATUS_ENABLED);
        return guide;
    }
 
    private GuideUser nonWhitelistedGuide() {
        GuideUser guide = whitelistedGuide();
        guide.setAutoDisableWhitelisted(0);
        return guide;
    }
 
    private GuideScenicConfig scenicConfig() {
        GuideScenicConfig config = new GuideScenicConfig();
        config.setGuideId(8L);
        config.setScenicName("Test Scenic");
        return config;
    }
 
    private OperationScenicSpot scenicSpot() {
        OperationScenicSpot scenic = new OperationScenicSpot();
        scenic.setId(3L);
        scenic.setScenicName("Test Scenic");
        scenic.setStatus(1);
        return scenic;
    }
 
    private ScenicPricing premiumPricing() {
        ScenicPricing pricing = new ScenicPricing();
        pricing.setId(9L);
        pricing.setScenicSpotId(3L);
        pricing.setServiceType("GROUP_PREMIUM");
        pricing.setDurationMinutes(60);
        pricing.setMinParticipants(20);
        pricing.setMaxParticipants(30);
        return pricing;
    }
 
    private PlatformSettingsResponse strictSettings() {
        PlatformSettingsResponse settings = new PlatformSettingsResponse();
        settings.setPreciseDispatchOrderCount(10);
        settings.setPreciseDispatchRating(new BigDecimal("4.8"));
        return settings;
    }
}