|
@@ -308,6 +308,74 @@ class TaskReminderDailyScheduledTaskContractTest {
|
|
|
any(), anyLong(), any(), any());
|
|
any(), anyLong(), any(), any());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // ==================== 晚默认开 / 早不变 拆开关(2026-11-29 增强) ====================
|
|
|
|
|
+
|
|
|
|
|
+ /** 装配一个带 wechat channel + 指定 config service 的 host */
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ private Object hostWithConfigAndChannel(TaskReminderConfigService cfgService,
|
|
|
|
|
+ com.etotem.cfc.service.notification.NotificationChannel wechat) {
|
|
|
|
|
+ Object host = contractHost();
|
|
|
|
|
+ inject(host, "taskReminderConfigService", cfgService);
|
|
|
|
|
+ inject(host, "userMapper", mock(com.etotem.cfc.mapper.UserMapper.class));
|
|
|
|
|
+ inject(host, "notificationChannels", new ArrayList<>(
|
|
|
|
|
+ java.util.Collections.singletonList(wechat)));
|
|
|
|
|
+ return host;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ @DisplayName("晚默认开-1:无配置记录用户(configService 返回空map)→ 晚提醒仍发送")
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ void eveningDefaultOn_noConfig() throws Exception {
|
|
|
|
|
+ TaskReminderConfigService cfg = mock(TaskReminderConfigService.class);
|
|
|
|
|
+ when(cfg.loadAllConfigs()).thenReturn(new java.util.HashMap<>());
|
|
|
|
|
+ com.etotem.cfc.service.notification.NotificationChannel wechat =
|
|
|
|
|
+ mock(com.etotem.cfc.service.notification.NotificationChannel.class);
|
|
|
|
|
+ when(wechat.getChannelType()).thenReturn("wechat");
|
|
|
|
|
+ when(wechat.isEnabled()).thenReturn(true);
|
|
|
|
|
+ Object host = hostWithConfigAndChannel(cfg, wechat);
|
|
|
|
|
+
|
|
|
|
|
+ TaskMapper tm = mock(TaskMapper.class);
|
|
|
|
|
+ UserNotificationMapper un = mock(UserNotificationMapper.class);
|
|
|
|
|
+ inject(host, "taskMapper", tm);
|
|
|
|
|
+ inject(host, "userNotificationMapper", un);
|
|
|
|
|
+ Task done = doneToday(20L, "任务");
|
|
|
|
|
+ done.setExecutorId(200L);
|
|
|
|
|
+ when(tm.selectList(any())).thenReturn(new ArrayList<>(java.util.Collections.singletonList(done)));
|
|
|
|
|
+ when(un.selectCount(any())).thenReturn(0L);
|
|
|
|
|
+
|
|
|
|
|
+ call(host, "sendEveningSummary");
|
|
|
|
|
+ verify(wechat, atLeastOnce()).send(any(com.etotem.cfc.dto.NotificationMessage.class));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ @DisplayName("晚默认开-2:显式 daily_enabled=0 → 晚提醒跳过")
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ void eveningOff_explicitZero() throws Exception {
|
|
|
|
|
+ TaskReminderConfigService cfg = mock(TaskReminderConfigService.class);
|
|
|
|
|
+ com.etotem.cfc.entity.TaskReminderConfig conf = new com.etotem.cfc.entity.TaskReminderConfig();
|
|
|
|
|
+ conf.setUserId(300L);
|
|
|
|
|
+ conf.setDailyEnabled(0);
|
|
|
|
|
+ when(cfg.loadAllConfigs()).thenReturn(new java.util.HashMap<>(
|
|
|
|
|
+ java.util.Collections.singletonMap(300L, conf)));
|
|
|
|
|
+ com.etotem.cfc.service.notification.NotificationChannel wechat =
|
|
|
|
|
+ mock(com.etotem.cfc.service.notification.NotificationChannel.class);
|
|
|
|
|
+ when(wechat.getChannelType()).thenReturn("wechat");
|
|
|
|
|
+ when(wechat.isEnabled()).thenReturn(true);
|
|
|
|
|
+ Object host = hostWithConfigAndChannel(cfg, wechat);
|
|
|
|
|
+
|
|
|
|
|
+ TaskMapper tm = mock(TaskMapper.class);
|
|
|
|
|
+ UserNotificationMapper un = mock(UserNotificationMapper.class);
|
|
|
|
|
+ inject(host, "taskMapper", tm);
|
|
|
|
|
+ inject(host, "userNotificationMapper", un);
|
|
|
|
|
+ Task done = doneToday(30L, "任务");
|
|
|
|
|
+ done.setExecutorId(300L);
|
|
|
|
|
+ when(tm.selectList(any())).thenReturn(new ArrayList<>(java.util.Collections.singletonList(done)));
|
|
|
|
|
+ when(un.selectCount(any())).thenReturn(0L);
|
|
|
|
|
+
|
|
|
|
|
+ call(host, "sendEveningSummary");
|
|
|
|
|
+ verify(wechat, never()).send(any(com.etotem.cfc.dto.NotificationMessage.class));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ==================== 晚间 webhook 分发(2026-11-29 增强) ====================
|
|
// ==================== 晚间 webhook 分发(2026-11-29 增强) ====================
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|