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;
|
}
|
}
|