diff --git a/src/main/java/com/chooz/notification/persistence/NotificationQueryDslRepository.java b/src/main/java/com/chooz/notification/persistence/NotificationQueryDslRepository.java index 9761b24..b7f84d3 100644 --- a/src/main/java/com/chooz/notification/persistence/NotificationQueryDslRepository.java +++ b/src/main/java/com/chooz/notification/persistence/NotificationQueryDslRepository.java @@ -19,9 +19,11 @@ import org.springframework.data.domain.SliceImpl; import org.springframework.stereotype.Repository; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; import static com.chooz.comment.domain.QComment.comment; import static com.chooz.notification.domain.QNotification.notification; @@ -81,7 +83,7 @@ private List findNotificationsWithTarget(List new NotificationDto( row, targetsByNotificationId.getOrDefault(row.id(), List.of()) - )).toList(); + )).collect(Collectors.toCollection(ArrayList::new)); } public Optional findPostByCommentId(Long commentId) { diff --git a/src/test/java/com/chooz/notification/application/NotificationQueryServiceTest.java b/src/test/java/com/chooz/notification/application/NotificationQueryServiceTest.java index ae94737..48ce32e 100644 --- a/src/test/java/com/chooz/notification/application/NotificationQueryServiceTest.java +++ b/src/test/java/com/chooz/notification/application/NotificationQueryServiceTest.java @@ -1,5 +1,6 @@ package com.chooz.notification.application; +import com.chooz.common.dto.CursorBasePaginatedResponse; import com.chooz.notification.application.dto.NotificationContent; import com.chooz.notification.application.service.NotificationCommandService; import com.chooz.notification.application.service.NotificationQueryService; @@ -86,6 +87,48 @@ void notifications() throws Exception { ); } @Test + @DisplayName("알림 10개 이상 조회") + void notificationsOver10() throws Exception { + //given + Long receiverId = 1L; + Long actorId = 2L; + String title = "숨겨진 츄님이 좋아요를 눌렀어요!"; + String content = "지금 바로 확인해보세요."; + String profileUrl = "https://cdn.chooz.site/default_profile.png"; + List targets = List.of(Target.of(3L, TargetType.POST)); + String imageUrl = "https://cdn.chooz.site/images/20865b3c-4e2c-454a-81a1-9ca31bbaf77d"; + LocalDateTime eventAt = LocalDateTime.now(); + NotificationType notificationType = NotificationType.COMMENT_LIKED; + for(long i = 0 ; i < 11 ; i++) { + Notification notification = Notification.create( + notificationType, + eventAt, + NotificationContent.of( + receiverId, + actorId + i, + title, + content, + profileUrl, + imageUrl, + targets + ) + ).get(); + notificationCommandService.create(notification); + } + //when + CursorBasePaginatedResponse notifications = notificationQueryService.findNotifications( + receiverId, + null, + 10 + ); + + //then + assertAll( + () -> assertThat(notifications.data().size()).isEqualTo(10), + () -> assertThat(notifications.hasNext()).isTrue() + ); + } + @Test @DisplayName("알림 상태 확인") void present() throws Exception { //given