Commit f838a4b9f03e27d5decaf47febd4446d0d7be63c
1 parent
c452b072
fix(system): 修正站内信模板缺失时误报通知公告不存在
Showing
2 changed files
with
22 additions
and
4 deletions
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java
| ... | ... | @@ -63,7 +63,7 @@ public class NotifySendServiceImpl implements NotifySendService { |
| 63 | 63 | NotifyTemplateDO template = notifyTemplateService.getNotifyTemplateByCodeFromCache(templateCode); |
| 64 | 64 | // 站内信模板不存在 |
| 65 | 65 | if (template == null) { |
| 66 | - throw exception(NOTICE_NOT_FOUND); | |
| 66 | + throw exception(NOTIFY_TEMPLATE_NOT_EXISTS); | |
| 67 | 67 | } |
| 68 | 68 | return template; |
| 69 | 69 | } | ... | ... |
yudao-module-system/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImplTest.java
| ... | ... | @@ -17,8 +17,8 @@ import java.util.Map; |
| 17 | 17 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 18 | 18 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 19 | 19 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 20 | -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; | |
| 21 | 20 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTIFY_SEND_TEMPLATE_PARAM_MISS; |
| 21 | +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTIFY_TEMPLATE_NOT_EXISTS; | |
| 22 | 22 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 23 | 23 | import static org.junit.jupiter.api.Assertions.assertNull; |
| 24 | 24 | import static org.mockito.ArgumentMatchers.eq; |
| ... | ... | @@ -150,14 +150,32 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest { |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | @Test |
| 153 | - public void testCheckMailTemplateValid_notExists() { | |
| 153 | + public void testSendSingleNotifyToAdmin_templateNotExists() { | |
| 154 | + // 准备参数 | |
| 155 | + Long userId = randomLongId(); | |
| 156 | + String templateCode = randomString(); | |
| 157 | + Map<String, Object> templateParams = MapUtil.<String, Object>builder().put("code", "1234") | |
| 158 | + .put("op", "login").build(); | |
| 159 | + // mock NotifyTemplateService 的方法 | |
| 160 | + when(notifyTemplateService.getNotifyTemplateByCodeFromCache(eq(templateCode))).thenReturn(null); | |
| 161 | + | |
| 162 | + // 调用,并断言异常 | |
| 163 | + assertServiceException(() -> notifySendService.sendSingleNotifyToAdmin(userId, templateCode, templateParams), | |
| 164 | + NOTIFY_TEMPLATE_NOT_EXISTS); | |
| 165 | + // 断言 | |
| 166 | + verify(notifyTemplateService, never()).formatNotifyTemplateContent(anyString(), anyMap()); | |
| 167 | + verify(notifyMessageService, never()).createNotifyMessage(anyLong(), anyInt(), any(), anyString(), anyMap()); | |
| 168 | + } | |
| 169 | + | |
| 170 | + @Test | |
| 171 | + public void testValidateNotifyTemplate_notExists() { | |
| 154 | 172 | // 准备参数 |
| 155 | 173 | String templateCode = randomString(); |
| 156 | 174 | // mock 方法 |
| 157 | 175 | |
| 158 | 176 | // 调用,并断言异常 |
| 159 | 177 | assertServiceException(() -> notifySendService.validateNotifyTemplate(templateCode), |
| 160 | - NOTICE_NOT_FOUND); | |
| 178 | + NOTIFY_TEMPLATE_NOT_EXISTS); | |
| 161 | 179 | } |
| 162 | 180 | |
| 163 | 181 | @Test | ... | ... |