Skip to content

Commit

Permalink
refactor: 코드 리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
hongdosan committed Nov 7, 2023
1 parent 858ca88 commit 5b1b6b1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Participant> participants = participantSearchRepository.findAllByRoomCertifyTime(certificationTime);

participants.parallelStream().forEach(participant -> {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ void notificationService_sendCertificationTimeNotification(List<Participant> par
verify(firebaseMessaging, times(3)).sendAsync(any(Message.class));
}

@DisplayName("특정 인증 시간에 해당하는 방 사용자들의 토큰값이 없을 때, - Void")
@MethodSource("provideParticipants")
@ParameterizedTest
void notificationService_sendCertificationTimeNotification_NoFirebaseMessaging(List<Participant> 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<Arguments> provideParticipants() {
Room room = RoomFixture.room(10);

Expand Down

0 comments on commit 5b1b6b1

Please sign in to comment.