liujie
2026-07-30 280ef5100bece9b40ac51736aef037704a52a4ca
backend/src/test/java/com/tourguide/modules/order/service/MiniTourOrderCommandServiceTest.java
@@ -15,11 +15,13 @@
import com.tourguide.modules.user.entity.MiniUser;
import com.tourguide.modules.user.mapper.GuideUserMapper;
import com.tourguide.modules.user.service.MiniUserService;
import com.tourguide.modules.system.service.GuideNotificationService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -38,6 +40,8 @@
    private ScenicPricingMapper pricingMapper;
    private GuideUserMapper guideUserMapper;
    private PlatformSettingsService platformSettingsService;
    private GuideOrderMatchingService matchingService;
    private GuideNotificationService notificationService;
    private MiniTourOrderCommandService commandService;
    @BeforeEach
@@ -49,9 +53,11 @@
        pricingMapper = mock(ScenicPricingMapper.class);
        guideUserMapper = mock(GuideUserMapper.class);
        platformSettingsService = mock(PlatformSettingsService.class);
        matchingService = mock(GuideOrderMatchingService.class);
        notificationService = mock(GuideNotificationService.class);
        commandService = new MiniTourOrderCommandService(
                orderMapper, miniUserService, scenicSpotMapper, meetingPointMapper, pricingMapper,
                guideUserMapper, platformSettingsService);
                guideUserMapper, platformSettingsService, matchingService, notificationService);
    }
    @Test
@@ -121,6 +127,7 @@
        order.setAmount(new BigDecimal("144.00"));
        order.setStatus(OrderStatus.PENDING_PAYMENT.getCode());
        when(orderMapper.selectOne(any())).thenReturn(order);
        when(orderMapper.selectById(99L)).thenReturn(order);
        TourOrderResponse response = commandService.confirmPayment(7L, 99L);
@@ -146,4 +153,27 @@
        verify(orderMapper, never()).insert(any(TourOrder.class));
    }
    @Test
    void cancelPendingMeetingOrderShouldNotifyAssignedGuide() {
        MiniUser visitor = new MiniUser();
        visitor.setId(7L);
        when(miniUserService.findEnabledById(7L)).thenReturn(visitor);
        TourOrder order = new TourOrder();
        order.setId(99L);
        order.setOrderNo("MJ202607300001");
        order.setVisitorId(7L);
        order.setGuideId(8L);
        order.setStatus(OrderStatus.PENDING_MEETING.getCode());
        order.setPaymentTime(LocalDateTime.now());
        order.setPaymentAmount(new BigDecimal("36.00"));
        when(orderMapper.selectOne(any())).thenReturn(order);
        commandService.cancel(7L, 99L);
        assertThat(order.getStatus()).isEqualTo(OrderStatus.CANCELLED.getCode());
        verify(orderMapper).updateById(order);
        verify(notificationService).notifyOrderCancelled(order);
    }
}