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; } }