Improve notifications to display live progress for ongoing batch metadata fetches (#1242)

This commit is contained in:
Aditya Chandel
2025-09-30 14:31:14 -06:00
committed by GitHub
parent 131b19f49f
commit 879d147e84
19 changed files with 187 additions and 326 deletions
@@ -183,6 +183,7 @@ class MetadataTaskServiceTest {
MetadataFetchProposalEntity p2 = mock(MetadataFetchProposalEntity.class);
when(job1.getTaskId()).thenReturn("task1");
when(job1.getStatus()).thenReturn(MetadataFetchTaskStatus.COMPLETED);
when(job1.getProposals()).thenReturn(List.of(p1, p2));
when(p1.getStatus()).thenReturn(FetchedMetadataProposalStatus.ACCEPTED);
when(p2.getStatus()).thenReturn(FetchedMetadataProposalStatus.REJECTED);
@@ -190,6 +191,7 @@ class MetadataTaskServiceTest {
MetadataFetchJobEntity job2 = mock(MetadataFetchJobEntity.class);
MetadataFetchProposalEntity p3 = mock(MetadataFetchProposalEntity.class);
when(job2.getTaskId()).thenReturn("task2");
when(job2.getStatus()).thenReturn(MetadataFetchTaskStatus.COMPLETED);
when(job2.getProposals()).thenReturn(List.of(p3));
when(p3.getStatus()).thenReturn(FetchedMetadataProposalStatus.FETCHED);
@@ -204,14 +206,14 @@ class MetadataTaskServiceTest {
.findFirst().orElseThrow();
assertThat(n1.getTotal()).isEqualTo(1);
assertThat(n1.getCompleted()).isEqualTo(1);
assertThat(n1.getMessage()).contains("Metadata review pending for 0 of 1 books");
assertThat(n1.getMessage()).contains("Metadata fetch completed! 0 books need review.");
MetadataBatchProgressNotification n2 = notifications.stream()
.filter(n -> n.getTaskId().equals("task2"))
.findFirst().orElseThrow();
assertThat(n2.getTotal()).isEqualTo(1);
assertThat(n2.getCompleted()).isEqualTo(0);
assertThat(n2.getMessage()).contains("Metadata review pending for 1 of 1 books");
assertThat(n2.getMessage()).contains("Metadata fetch completed! 1 books need review.");
verify(jobRepository).findAllWithProposals();
}
@@ -221,6 +223,7 @@ class MetadataTaskServiceTest {
MetadataFetchJobEntity job = mock(MetadataFetchJobEntity.class);
MetadataFetchProposalEntity p1 = mock(MetadataFetchProposalEntity.class);
when(job.getTaskId()).thenReturn("task1");
when(job.getStatus()).thenReturn(MetadataFetchTaskStatus.COMPLETED);
when(job.getProposals()).thenReturn(List.of(p1));
when(p1.getStatus()).thenReturn(FetchedMetadataProposalStatus.REJECTED);
@@ -4,7 +4,6 @@ import com.adityachandel.booklore.mapper.BookMapper;
import com.adityachandel.booklore.model.MetadataUpdateWrapper;
import com.adityachandel.booklore.model.dto.Book;
import com.adityachandel.booklore.model.dto.BookMetadata;
import com.adityachandel.booklore.model.dto.TaskMessage;
import com.adityachandel.booklore.model.dto.request.FetchMetadataRequest;
import com.adityachandel.booklore.model.dto.request.MetadataRefreshOptions;
import com.adityachandel.booklore.model.dto.request.MetadataRefreshRequest;
@@ -32,7 +31,8 @@ import org.springframework.transaction.PlatformTransactionManager;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
@@ -243,7 +243,6 @@ class MetadataRefreshServiceTest {
metadataRefreshService.refreshMetadata(request, 1L, "job-1");
verify(notificationService, atLeastOnce()).sendMessage(eq(Topic.TASK), any(TaskMessage.class));
verify(bookRepository).findAllWithMetadataByIds(Set.of(1L));
}
@@ -281,7 +280,6 @@ class MetadataRefreshServiceTest {
metadataRefreshService.refreshMetadata(request, 1L, "job-1");
verify(bookRepository).findAllWithMetadataByIds(Set.of(1L));
verify(notificationService, atLeastOnce()).sendMessage(eq(Topic.TASK), any(TaskMessage.class));
}
@Test
@@ -329,9 +327,6 @@ class MetadataRefreshServiceTest {
setupBookRepositoryMocks();
metadataRefreshService.refreshMetadata(request, 1L, "job-1");
verify(notificationService).sendMessage(eq(Topic.TASK), argThat(msg ->
((TaskMessage) msg).getMessage().contains("Skipped locked book")));
}
@Test