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 5b1b6b1 commit 7e85842
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
@Transactional(readOnly = true)
public class NotificationService {

private final RoomService roomService;
private final FirebaseMessaging firebaseMessaging;
private final NotificationRepository notificationRepository;
private final ParticipantSearchRepository participantSearchRepository;

@Transactional
public void sendKnockNotification(MemberTest member, Long targetId, Long roomId) {
roomService.validateRoomById(roomId);

String knockKey = generateKnockKey(member.memberId(), targetId, roomId);
validateConflictKnockNotification(knockKey);
validateFcmToken(targetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ class NotificationServiceTest {
private NotificationService notificationService;

@Mock
private NotificationRepository notificationRepository;
private RoomService roomService;

@Mock
private ParticipantSearchRepository participantSearchRepository;
private FirebaseMessaging firebaseMessaging;

@Mock
private FirebaseMessaging firebaseMessaging;
private NotificationRepository notificationRepository;

@Mock
private ParticipantSearchRepository participantSearchRepository;

private MemberTest memberTest;

Expand All @@ -56,6 +59,7 @@ void setUp() {
@Test
void notificationService_sendKnockNotification() {
// Given
willDoNothing().given(roomService).validateRoomById(any(Long.class));
given(notificationRepository.existsFcmTokenByMemberId(any(Long.class))).willReturn(true);
given(notificationRepository.existsByKey(any(String.class))).willReturn(false);
given(notificationRepository.findFcmTokenByMemberId(any(Long.class))).willReturn("FCM-TOKEN");
Expand All @@ -68,10 +72,22 @@ void notificationService_sendKnockNotification() {
verify(notificationRepository).saveKnockNotification(any(String.class));
}

@DisplayName("콕 찌를 상대의 방이 존재하지 않을 때, - NotFoundException")
@Test
void notificationService_sendKnockNotification_Room_NotFoundException() {
// Given
willThrow(NotFoundException.class).given(roomService).validateRoomById(any(Long.class));

// When & Then
assertThatThrownBy(() -> notificationService.sendKnockNotification(memberTest, 1L, 1L))
.isInstanceOf(NotFoundException.class);
}

@DisplayName("콕 찌를 상대의 FCM 토큰이 존재하지 않을 때, - NotFoundException")
@Test
void notificationService_sendKnockNotification_NotFoundException() {
void notificationService_sendKnockNotification_FcmToken_NotFoundException() {
// Given
willDoNothing().given(roomService).validateRoomById(any(Long.class));
given(notificationRepository.existsByKey(any(String.class))).willReturn(false);
given(notificationRepository.existsFcmTokenByMemberId(any(Long.class))).willReturn(false);

Expand All @@ -85,6 +101,7 @@ void notificationService_sendKnockNotification_NotFoundException() {
@Test
void notificationService_sendKnockNotification_ConflictException() {
// Given
willDoNothing().given(roomService).validateRoomById(any(Long.class));
given(notificationRepository.existsByKey(any(String.class))).willReturn(true);

// When & Then
Expand Down

0 comments on commit 7e85842

Please sign in to comment.