| | |
| | | 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( |
| | | mock(SystemNoticeMapper.class), mock(GuideNoticeReadMapper.class), |
| | | noticeMapper, mock(GuideNoticeReadMapper.class), |
| | | notificationMapper, pushDeviceService); |
| | | } |
| | | |
| | | @Test |
| | | void assignedOrderShouldUseSpecifiedPushCopy() { |
| | | 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 = "景区:青城山;汇合点:景区正门;服务类型:精品拼团;人数:4。请及时接单。"; |
| | | assertThat(notification.getTitle()).isEqualTo("您有新的讲解订单"); |
| | | String content = "您有一个新的讲解订单,请查看"; |
| | | assertThat(notification.getTitle()).isEqualTo("接单提醒"); |
| | | assertThat(notification.getContent()).isEqualTo(content); |
| | | verify(pushDeviceService).push(8L, "您有新的讲解订单", content, |
| | | verify(pushDeviceService).push(8L, "接单提醒", content, |
| | | "/pages/order-detail/index?id=99"); |
| | | } |
| | | |
| | | @Test |
| | | void visitorCancellationShouldUseSpecifiedPushCopy() { |
| | | void visitorCancellationShouldUsePrototypeCopy() { |
| | | TourOrder order = order(); |
| | | |
| | | notificationService.notifyVisitorCancelledOrder(order); |
| | | |
| | | verify(pushDeviceService).push(8L, "订单已取消", |
| | | "游客已取消订单,该订单无需再前往服务。", "/pages/order-detail/index?id=99"); |
| | | 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 |