Skip to content

Commit dc966ea

Browse files
committed
test(NotificationRepository): 알림 조회 테스트 추가
1 parent 57f930b commit dc966ea

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/test/java/com/somemore/notification/repository/NotificationRepositoryTest.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import org.springframework.beans.factory.annotation.Autowired;
1010
import org.springframework.transaction.annotation.Transactional;
1111

12+
import java.util.ArrayList;
1213
import java.util.List;
14+
import java.util.Optional;
1315
import java.util.UUID;
1416

1517
import static org.assertj.core.api.Assertions.assertThat;
@@ -22,29 +24,34 @@ class NotificationRepositoryTest extends IntegrationTestSupport {
2224

2325
private UUID receiverId;
2426

27+
private List<Long> savedNotificationIds;
28+
2529
@BeforeEach
2630
void setup() {
2731
receiverId = UUID.randomUUID();
32+
savedNotificationIds = new ArrayList<>();
2833

29-
for (int i = 0; i < 10; i++) {
34+
for (long i = 1; i <= 10; i++) {
3035
Notification unreadNotification = Notification.builder()
3136
.title("Unread Notification")
3237
.type(NotificationSubType.NOTE_BLAH_BLAH)
3338
.receiverId(receiverId)
34-
.relatedId(1L)
39+
.relatedId(i + 1)
3540
.build();
3641

3742
Notification readNotification = Notification.builder()
3843
.title("Read Notification")
3944
.type(NotificationSubType.REVIEW_BLAH_BLAH)
4045
.receiverId(receiverId)
41-
.relatedId(2L)
46+
.relatedId(i + 100)
4247
.build();
4348

4449
readNotification.markAsRead();
4550

4651
notificationRepository.save(unreadNotification);
4752
notificationRepository.save(readNotification);
53+
54+
savedNotificationIds.add(unreadNotification.getId()); // 저장된 ID 캡처
4855
}
4956
}
5057

@@ -85,16 +92,25 @@ void findByReceiverIdAndUnread_noNotifications() {
8592
assertThat(notifications).isEmpty();
8693
}
8794

88-
@DisplayName("알림이 없는 사용자의 읽은 알림을 조회하면 빈 리스트를 반환한다.")
95+
@DisplayName("알림 아이디로 알림을 조회한다.")
8996
@Test
90-
void findByReceiverIdAndRead_noNotifications() {
97+
void findById() {
9198
// given
92-
UUID unknownReceiverId = UUID.randomUUID();
99+
// when
100+
Optional<Notification> notifications = notificationRepository.findById(savedNotificationIds.getFirst());
93101

102+
// then
103+
assertThat(notifications).isNotEmpty();
104+
}
105+
106+
@DisplayName("알림이 없는 사용자의 읽은 알림을 조회하면 빈 리스트를 반환한다.")
107+
@Test
108+
void findAllByIds() {
109+
// given
94110
// when
95-
List<Notification> notifications = notificationRepository.findByReceiverIdAndRead(unknownReceiverId);
111+
List<Notification> notifications = notificationRepository.findAllByIds(savedNotificationIds);
96112

97113
// then
98-
assertThat(notifications).isEmpty();
114+
assertThat(notifications).hasSize(10);
99115
}
100116
}

0 commit comments

Comments
 (0)