| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @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())); |
| | |
| | | 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 |
| | |
| | | return guide; |
| | | } |
| | | |
| | | private GuideUser explicitPremiumGuide() { |
| | | GuideUser guide = nonWhitelistedGuide(); |
| | | guide.setPremiumEnabled(1); |
| | | return guide; |
| | | } |
| | | |
| | | private GuideUser nonWhitelistedGuide() { |
| | | GuideUser guide = whitelistedGuide(); |
| | | guide.setAutoDisableWhitelisted(0); |