mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-19 05:21:15 +08:00
feat: add paginated notification API and frontend support
This commit is contained in:
@@ -45,7 +45,7 @@ class NotificationControllerTest {
|
||||
p.setId(2L);
|
||||
n.setPost(p);
|
||||
n.setCreatedAt(LocalDateTime.now());
|
||||
when(notificationService.listNotifications("alice", null))
|
||||
when(notificationService.listNotifications("alice", null, 0))
|
||||
.thenReturn(List.of(n));
|
||||
|
||||
NotificationDto dto = new NotificationDto();
|
||||
@@ -62,6 +62,23 @@ class NotificationControllerTest {
|
||||
.andExpect(jsonPath("$[0].post.id").value(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listUnreadNotifications() throws Exception {
|
||||
Notification n = new Notification();
|
||||
n.setId(3L);
|
||||
n.setType(NotificationType.POST_VIEWED);
|
||||
when(notificationService.listNotifications("alice", false, 0)).thenReturn(List.of(n));
|
||||
|
||||
NotificationDto dto = new NotificationDto();
|
||||
dto.setId(3L);
|
||||
when(notificationMapper.toDto(n)).thenReturn(dto);
|
||||
|
||||
mockMvc.perform(get("/api/notifications/unread")
|
||||
.principal(new UsernamePasswordAuthenticationToken("alice", "p")))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$[0].id").value(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void markReadEndpoint() throws Exception {
|
||||
mockMvc.perform(post("/api/notifications/read")
|
||||
|
||||
@@ -65,12 +65,15 @@ class NotificationServiceTest {
|
||||
when(uRepo.findByUsername("bob")).thenReturn(Optional.of(user));
|
||||
|
||||
Notification n = new Notification();
|
||||
when(nRepo.findByUserOrderByCreatedAtDesc(user)).thenReturn(List.of(n));
|
||||
org.springframework.data.domain.Page<Notification> page =
|
||||
new org.springframework.data.domain.PageImpl<>(List.of(n));
|
||||
when(nRepo.findByUserOrderByCreatedAtDesc(eq(user), any(org.springframework.data.domain.Pageable.class)))
|
||||
.thenReturn(page);
|
||||
|
||||
List<Notification> list = service.listNotifications("bob", null);
|
||||
|
||||
assertEquals(1, list.size());
|
||||
verify(nRepo).findByUserOrderByCreatedAtDesc(user);
|
||||
verify(nRepo).findByUserOrderByCreatedAtDesc(eq(user), any(org.springframework.data.domain.Pageable.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user