liujie
2026-08-21 a7c8a8f6055e1a03414f2227d12ff2e87ec52d41
backend/src/test/java/com/tourguide/modules/order/service/MiniTourOrderCommandServiceTest.java
@@ -6,6 +6,7 @@
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.dto.PlatformSettingsResponse;
import com.tourguide.modules.operation.service.PlatformSettingsService;
import com.tourguide.modules.order.domain.OrderStatus;
import com.tourguide.modules.order.dto.MiniOrderCreateRequest;
@@ -15,11 +16,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 +41,8 @@
    private ScenicPricingMapper pricingMapper;
    private GuideUserMapper guideUserMapper;
    private PlatformSettingsService platformSettingsService;
    private GuideNotificationService notificationService;
    private OrderRefundService orderRefundService;
    private MiniTourOrderCommandService commandService;
    @BeforeEach
@@ -49,9 +54,11 @@
        pricingMapper = mock(ScenicPricingMapper.class);
        guideUserMapper = mock(GuideUserMapper.class);
        platformSettingsService = mock(PlatformSettingsService.class);
        notificationService = mock(GuideNotificationService.class);
        orderRefundService = mock(OrderRefundService.class);
        commandService = new MiniTourOrderCommandService(
                orderMapper, miniUserService, scenicSpotMapper, meetingPointMapper, pricingMapper,
                guideUserMapper, platformSettingsService);
                guideUserMapper, platformSettingsService, notificationService, orderRefundService);
    }
    @Test
@@ -83,6 +90,9 @@
        pricing.setDiscountPrice(new BigDecimal("36.00"));
        pricing.setMaxParticipants(10);
        when(pricingMapper.selectOne(any())).thenReturn(pricing);
        PlatformSettingsResponse settings = new PlatformSettingsResponse();
        settings.setSettlementDays(7);
        when(platformSettingsService.getSettings()).thenReturn(settings);
        doAnswer(invocation -> {
            TourOrder order = invocation.getArgument(0);
            order.setId(99L);
@@ -105,32 +115,8 @@
        assertThat(order.getPaymentOrderNo()).isNull();
        assertThat(order.getPaymentAmount()).isNull();
        assertThat(order.getPaymentTime()).isNull();
        assertThat(order.getSettlementDays()).isEqualTo(7);
        assertThat(response.getStatus()).isEqualTo(OrderStatus.PENDING_PAYMENT.getCode());
    }
    @Test
    void confirmPaymentShouldMovePendingOrderToPendingAccept() {
        MiniUser visitor = new MiniUser();
        visitor.setId(7L);
        when(miniUserService.findEnabledById(7L)).thenReturn(visitor);
        TourOrder order = new TourOrder();
        order.setId(99L);
        order.setOrderNo("MJ202607290001");
        order.setVisitorId(7L);
        order.setAmount(new BigDecimal("144.00"));
        order.setStatus(OrderStatus.PENDING_PAYMENT.getCode());
        when(orderMapper.selectOne(any())).thenReturn(order);
        TourOrderResponse response = commandService.confirmPayment(7L, 99L);
        assertThat(order.getStatus()).isEqualTo(OrderStatus.PENDING_ACCEPT.getCode());
        assertThat(order.getPaymentMethod()).isEqualTo("WECHAT");
        assertThat(order.getPaymentOrderNo()).isEqualTo("LOCALMJ202607290001");
        assertThat(order.getPaymentAmount()).isEqualByComparingTo("144.00");
        assertThat(order.getPaymentTime()).isNotNull();
        assertThat(response.getStatus()).isEqualTo(OrderStatus.PENDING_ACCEPT.getCode());
        verify(orderMapper).updateById(order);
    }
    @Test
@@ -146,4 +132,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.selectForUpdate(99L)).thenReturn(order);
        commandService.cancel(7L, 99L);
        assertThat(order.getStatus()).isEqualTo(OrderStatus.CANCELLED.getCode());
        verify(orderRefundService).requestRefund(order);
        verify(notificationService).notifyVisitorCancelledOrder(order);
    }
}