liujie
2026-09-11 26dae811b447b0f13500a63e3a972a377f00be3c
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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 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.verify;
import static org.mockito.Mockito.when;
 
class GuideNotificationServiceTest {
    private SystemNoticeMapper noticeMapper;
    private GuideNotificationMapper notificationMapper;
    private GuidePushDeviceService pushDeviceService;
    private GuideNotificationService notificationService;
 
    @BeforeEach
    void setUp() {
        noticeMapper = mock(SystemNoticeMapper.class);
        notificationMapper = mock(GuideNotificationMapper.class);
        pushDeviceService = mock(GuidePushDeviceService.class);
        notificationService = new GuideNotificationService(
                noticeMapper, mock(GuideNoticeReadMapper.class),
                notificationMapper, pushDeviceService);
    }
 
    @Test
    void unreadCountShouldIncludePersonalNotificationsWithoutSystemNotices() {
        when(noticeMapper.selectList(any())).thenReturn(Collections.emptyList());
        when(notificationMapper.selectCount(any())).thenReturn(1L);
 
        assertThat(notificationService.unreadCount(8L)).isEqualTo(1L);
    }
 
    @Test
    void assignedOrderShouldUsePrototypeCopy() {
        TourOrder order = order();
 
        notificationService.notifyOrderAssigned(order);
 
        ArgumentCaptor<GuideNotification> captor = ArgumentCaptor.forClass(GuideNotification.class);
        verify(notificationMapper).insert(captor.capture());
        GuideNotification notification = captor.getValue();
        String content = "您有一个新的讲解订单,请查看";
        assertThat(notification.getTitle()).isEqualTo("接单提醒");
        assertThat(notification.getContent()).isEqualTo(content);
        verify(pushDeviceService).push(8L, "接单提醒", content,
                "/pages/order-detail/index?id=99");
    }
 
    @Test
    void visitorCancellationShouldUsePrototypeCopy() {
        TourOrder order = order();
 
        notificationService.notifyVisitorCancelledOrder(order);
 
        verify(pushDeviceService).push(8L, "取消提醒",
                "您有一个讲解订单被取消,请查看", "/pages/order-detail/index?id=99");
    }
 
    @Test
    void orderCancellationShouldPushGuideAlert() {
        TourOrder order = order();
 
        notificationService.notifyOrderCancelled(order);
 
        verify(pushDeviceService).push(8L, "取消提醒",
                "您有一个讲解订单被取消,请查看", "/pages/order-detail/index?id=99");
    }
 
    @Test
    void reviewedOrderShouldNotifyGuide() {
        TourOrder order = order();
 
        notificationService.notifyOrderReviewed(order);
 
        ArgumentCaptor<GuideNotification> captor = ArgumentCaptor.forClass(GuideNotification.class);
        verify(notificationMapper).insert(captor.capture());
        GuideNotification notification = captor.getValue();
        assertThat(notification.getNotificationType()).isEqualTo("ORDER_REVIEWED");
        assertThat(notification.getOrderId()).isEqualTo(99L);
        assertThat(notification.getTargetUrl()).isEqualTo("/pages/order-detail/index?id=99");
        verify(pushDeviceService).push(8L, "评价提醒", "您有一条新的订单评价,请查看",
                "/pages/order-detail/index?id=99");
    }
 
    @Test
    void auditResultShouldUsePrototypeCopy() {
        notificationService.notifyAuditResult(8L, true);
 
        ArgumentCaptor<GuideNotification> captor = ArgumentCaptor.forClass(GuideNotification.class);
        verify(notificationMapper).insert(captor.capture());
        GuideNotification notification = captor.getValue();
        assertThat(notification.getTitle()).isEqualTo("系统提醒");
        assertThat(notification.getContent()).isEqualTo("您的资料审核已通过");
    }
 
    @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;
    }
}