liujie
2026-09-11 4f6f15b818704079ff2e4e4719b798f48d68a335
backend/src/test/java/com/tourguide/modules/user/service/GuideReceivingServiceTest.java
@@ -9,6 +9,7 @@
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.dto.GuideReceivingStartRequest;
import com.tourguide.modules.user.entity.GuideScenicConfig;
import com.tourguide.modules.user.entity.GuideUser;
import com.tourguide.modules.user.mapper.GuideRealtimeStatusMapper;
@@ -22,6 +23,7 @@
import java.util.Collections;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -55,7 +57,40 @@
    }
    @Test
    void shouldEnablePremiumOptionsForWhitelistedGuideBelowRuleThresholds() {
    void shouldEnablePremiumOptionsForGuideWithExplicitPermission() {
        when(guideUserService.findEnabledById(8L)).thenReturn(explicitPremiumGuide());
        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 shouldExposeConfiguredServicePricesForGuideOptions() {
        when(guideUserService.findEnabledById(8L)).thenReturn(explicitPremiumGuide());
        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());
        ScenicPricing pricing = premiumPricing();
        pricing.setOriginalPrice(new BigDecimal("860.00"));
        pricing.setDiscountPrice(new BigDecimal("836.00"));
        when(pricingMapper.selectList(any())).thenReturn(Collections.singletonList(pricing));
        GuideReceivingOptionResponse response = service.options(8L);
        GuideReceivingOptionResponse.ServiceOption option = response.getScenics().get(0).getServices().get(0);
        assertThat(option.getOriginalPrice()).isEqualByComparingTo("860.00");
        assertThat(option.getDiscountPrice()).isEqualByComparingTo("836.00");
    }
    @Test
    void shouldEnablePremiumOptionsForLegacyWhitelistedGuideBelowRuleThresholds() {
        when(guideUserService.findEnabledById(8L)).thenReturn(whitelistedGuide());
        when(platformSettingsService.getSettings()).thenReturn(strictSettings());
        when(guideScenicMapper.selectList(any())).thenReturn(Collections.singletonList(scenicConfig()));
@@ -66,6 +101,26 @@
        GuideReceivingOptionResponse response = service.options(8L);
        assertThat(response.isPremiumEnabled()).isTrue();
    }
    @Test
    void shouldRejectStartingPremiumServiceWithoutPermission() {
        when(guideUserService.findEnabledById(8L)).thenReturn(nonWhitelistedGuide());
        when(platformSettingsService.getSettings()).thenReturn(strictSettings());
        when(scenicMapper.selectOne(any())).thenReturn(scenicSpot());
        when(guideScenicMapper.selectList(any())).thenReturn(Collections.singletonList(scenicConfig()));
        when(meetingPointMapper.selectCount(any())).thenReturn(1L);
        when(pricingMapper.selectList(any())).thenReturn(Collections.singletonList(premiumPricing()));
        GuideReceivingStartRequest request = new GuideReceivingStartRequest();
        request.setScenicSpotId(3L);
        request.setMeetingPointId(4L);
        request.setReceivingMode("GROUP");
        request.setServiceTypes(Collections.singletonList("GROUP_PREMIUM"));
        assertThatThrownBy(() -> service.start(8L, request))
                .isInstanceOf(com.tourguide.common.exception.BusinessException.class)
                .hasMessage("premium service requirements are not met");
    }
    @Test
@@ -92,6 +147,12 @@
        return guide;
    }
    private GuideUser explicitPremiumGuide() {
        GuideUser guide = nonWhitelistedGuide();
        guide.setPremiumEnabled(1);
        return guide;
    }
    private GuideUser nonWhitelistedGuide() {
        GuideUser guide = whitelistedGuide();
        guide.setAutoDisableWhitelisted(0);