|
| 1 | +package com.somemore.notification.handler; |
| 2 | + |
| 3 | +import com.somemore.IntegrationTestSupport; |
| 4 | +import com.somemore.notification.converter.MessageConverter; |
| 5 | +import com.somemore.notification.domain.Notification; |
| 6 | +import com.somemore.notification.domain.NotificationSubType; |
| 7 | +import com.somemore.notification.repository.NotificationRepository; |
| 8 | +import org.junit.jupiter.api.DisplayName; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import org.springframework.beans.factory.annotation.Autowired; |
| 11 | +import org.springframework.transaction.annotation.Transactional; |
| 12 | + |
| 13 | +import java.util.List; |
| 14 | +import java.util.UUID; |
| 15 | + |
| 16 | +import static org.assertj.core.api.Assertions.assertThat; |
| 17 | + |
| 18 | +@Transactional |
| 19 | +class NotificationHandlerTest extends IntegrationTestSupport { |
| 20 | + |
| 21 | + @Autowired |
| 22 | + private NotificationHandlerImpl notificationHandler; |
| 23 | + |
| 24 | + @Autowired |
| 25 | + private MessageConverter messageConverter; |
| 26 | + |
| 27 | + @Autowired |
| 28 | + private NotificationRepository notificationRepository; |
| 29 | + |
| 30 | + @Test |
| 31 | + @DisplayName("handle 호출 시 Notification이 저장된다") |
| 32 | + void handle() { |
| 33 | + // given |
| 34 | + String message = """ |
| 35 | + { |
| 36 | + "type": "NOTIFICATION", |
| 37 | + "subType": "VOLUNTEER_APPLY_STATUS_CHANGE", |
| 38 | + "receiverId": "123e4567-e89b-12d3-a456-426614174000", |
| 39 | + "volunteerApplyId": 123, |
| 40 | + "centerId": "123e4567-e89b-12d3-a456-426614174001", |
| 41 | + "recruitBoardId": 456, |
| 42 | + "newStatus": "APPROVED", |
| 43 | + "createdAt": "2024-12-05T10:00:00" |
| 44 | + } |
| 45 | + """; |
| 46 | + |
| 47 | + UUID receiverId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000"); |
| 48 | + |
| 49 | + Notification notification = messageConverter.ToNotification(message); |
| 50 | + // when |
| 51 | + notificationHandler.handle(notification); |
| 52 | + |
| 53 | + // then |
| 54 | + List<Notification> notifications = notificationRepository.findByReceiverIdAndUnread(receiverId); |
| 55 | + assertThat(notifications).hasSize(1); |
| 56 | + |
| 57 | + Notification savedNotification = notifications.getFirst(); |
| 58 | + assertThat(savedNotification.getReceiverId()).isEqualTo(receiverId); |
| 59 | + assertThat(savedNotification.getTitle()).isEqualTo("봉사 활동 신청이 승인되었습니다."); |
| 60 | + assertThat(savedNotification.getType()).isEqualTo(NotificationSubType.VOLUNTEER_APPLY_STATUS_CHANGE); |
| 61 | + assertThat(savedNotification.getRelatedId()).isEqualTo(456L); // 프론트 요구사항: 123L(봉사신청아이디), 456L(모집글아이디) |
| 62 | + assertThat(savedNotification.isRead()).isFalse(); |
| 63 | + assertThat(savedNotification.getCreatedAt()).isEqualTo(notification.getCreatedAt()); |
| 64 | + } |
| 65 | +} |
0 commit comments