diff --git a/src/main/java/com/moabam/api/application/NotificationService.java b/src/main/java/com/moabam/api/application/NotificationService.java index 36d30a67..4454d896 100644 --- a/src/main/java/com/moabam/api/application/NotificationService.java +++ b/src/main/java/com/moabam/api/application/NotificationService.java @@ -44,9 +44,9 @@ public void sendKnockNotification(MemberTest member, Long targetId, Long roomId) notificationRepository.saveKnockNotification(knockKey); } - @Scheduled(cron = CRON_CERTIFY_TIME_EXPRESSION) + @Scheduled(cron = "0 50 * * * *") public void sendCertificationTimeNotification() { - int certificationTime = (LocalDateTime.now().getHour() + ONE) % HOURS_IN_A_DAY; + int certificationTime = (LocalDateTime.now().getHour() + ONE_HOUR) % HOURS_IN_A_DAY; List participants = participantSearchRepository.findAllByRoomCertifyTime(certificationTime); participants.parallelStream().forEach(participant -> { @@ -58,9 +58,11 @@ public void sendCertificationTimeNotification() { private void sendAsyncFcm(Long fcmTokenKey, Notification notification) { String fcmToken = notificationRepository.findFcmTokenByMemberId(fcmTokenKey); - Message message = NotificationMapper.toMessageEntity(notification, fcmToken); - firebaseMessaging.sendAsync(message); + if (fcmToken != null) { + Message message = NotificationMapper.toMessageEntity(notification, fcmToken); + firebaseMessaging.sendAsync(message); + } } private void validateConflictKnockNotification(String knockKey) { diff --git a/src/main/java/com/moabam/global/common/constant/GlobalConstant.java b/src/main/java/com/moabam/global/common/constant/GlobalConstant.java index 9818b4ca..a3cafbd3 100644 --- a/src/main/java/com/moabam/global/common/constant/GlobalConstant.java +++ b/src/main/java/com/moabam/global/common/constant/GlobalConstant.java @@ -8,9 +8,8 @@ public class GlobalConstant { public static final String BLANK = ""; public static final String COMMA = ","; - public static final String UNDER_BAR = "_"; public static final String CHARSET_UTF_8 = ";charset=UTF-8"; public static final String SPACE = " "; - public static final int ONE = 1; + public static final int ONE_HOUR = 1; public static final int HOURS_IN_A_DAY = 24; } diff --git a/src/test/java/com/moabam/api/application/NotificationServiceTest.java b/src/test/java/com/moabam/api/application/NotificationServiceTest.java index 322b38da..98e9e895 100644 --- a/src/test/java/com/moabam/api/application/NotificationServiceTest.java +++ b/src/test/java/com/moabam/api/application/NotificationServiceTest.java @@ -108,6 +108,21 @@ void notificationService_sendCertificationTimeNotification(List par verify(firebaseMessaging, times(3)).sendAsync(any(Message.class)); } + @DisplayName("특정 인증 시간에 해당하는 방 사용자들의 토큰값이 없을 때, - Void") + @MethodSource("provideParticipants") + @ParameterizedTest + void notificationService_sendCertificationTimeNotification_NoFirebaseMessaging(List participants) { + // Given + given(participantSearchRepository.findAllByRoomCertifyTime(any(Integer.class))).willReturn(participants); + given(notificationRepository.findFcmTokenByMemberId(any(Long.class))).willReturn(null); + + // When + notificationService.sendCertificationTimeNotification(); + + // Then + verify(firebaseMessaging, times(0)).sendAsync(any(Message.class)); + } + static Stream provideParticipants() { Room room = RoomFixture.room(10);