liujie
2026-09-09 39f6fca28e3f78abe48f08e474ec011abb990b36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.tourguide.modules.system.service;
 
import com.tourguide.modules.order.entity.TourOrder;
import com.tourguide.modules.system.entity.GuideNotification;
import com.tourguide.modules.system.mapper.GuideNotificationMapper;
import com.tourguide.modules.system.mapper.GuideNoticeReadMapper;
import com.tourguide.modules.system.mapper.SystemNoticeMapper;
import com.tourguide.modules.user.service.GuidePushDeviceService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
 
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
 
class GuideNotificationServiceTest {
    private GuideNotificationMapper notificationMapper;
    private GuidePushDeviceService pushDeviceService;
    private GuideNotificationService notificationService;
 
    @BeforeEach
    void setUp() {
        notificationMapper = mock(GuideNotificationMapper.class);
        pushDeviceService = mock(GuidePushDeviceService.class);
        notificationService = new GuideNotificationService(
                mock(SystemNoticeMapper.class), mock(GuideNoticeReadMapper.class),
                notificationMapper, pushDeviceService);
    }
 
    @Test
    void assignedOrderShouldUseSpecifiedPushCopy() {
        TourOrder order = order();
 
        notificationService.notifyOrderAssigned(order);
 
        ArgumentCaptor<GuideNotification> captor = ArgumentCaptor.forClass(GuideNotification.class);
        verify(notificationMapper).insert(captor.capture());
        GuideNotification notification = captor.getValue();
        String content = "景区:青城山;汇合点:景区正门;服务类型:精品拼团;人数:4。请及时接单。";
        assertThat(notification.getTitle()).isEqualTo("您有新的讲解订单");
        assertThat(notification.getContent()).isEqualTo(content);
        verify(pushDeviceService).push(8L, "您有新的讲解订单", content,
                "/pages/order-detail/index?id=99");
    }
 
    @Test
    void visitorCancellationShouldUseSpecifiedPushCopy() {
        TourOrder order = order();
 
        notificationService.notifyVisitorCancelledOrder(order);
 
        verify(pushDeviceService).push(8L, "订单已取消",
                "游客已取消订单,该订单无需再前往服务。", "/pages/order-detail/index?id=99");
    }
 
    @Test
    void serviceReminderShouldPointToMeetingPoint() {
        TourOrder order = order();
 
        notificationService.pushServiceReminder(order);
 
        verify(pushDeviceService).push(8L, "请准备前往汇合点",
                "您的讲解服务即将开始,请提前到达 景区正门。", "/pages/order-detail/index?id=99");
    }
 
    private TourOrder order() {
        TourOrder order = new TourOrder();
        order.setId(99L);
        order.setGuideId(8L);
        order.setScenicName("青城山");
        order.setMeetingPointName("景区正门");
        order.setPackageName("精品拼团");
        order.setPeopleCount(4);
        return order;
    }
}