Co-authored-by: blitzar3k <263961889+blitzar3k@users.noreply.github.com>
This commit is contained in:
@@ -515,6 +515,46 @@ class BookMetadataUpdaterTest {
|
||||
"Title should be replaced when using REPLACE_ALL mode");
|
||||
}
|
||||
|
||||
@Test
|
||||
void setBookMetadata_shouldUpdateAudibleFields() {
|
||||
BookEntity bookEntity = new BookEntity();
|
||||
bookEntity.setId(1L);
|
||||
BookMetadataEntity metadataEntity = new BookMetadataEntity();
|
||||
metadataEntity.setBook(bookEntity);
|
||||
bookEntity.setMetadata(metadataEntity);
|
||||
|
||||
BookFileEntity primaryFile = new BookFileEntity();
|
||||
primaryFile.setBook(bookEntity);
|
||||
primaryFile.setBookType(BookFileType.EPUB);
|
||||
primaryFile.setBookFormat(true);
|
||||
primaryFile.setFileSubPath("sub");
|
||||
primaryFile.setFileName("file.epub");
|
||||
bookEntity.setBookFiles(List.of(primaryFile));
|
||||
|
||||
BookMetadata newMetadata = new BookMetadata();
|
||||
newMetadata.setAsin("B0EXAMPLE1");
|
||||
newMetadata.setAudibleId("B0EXAMPLE1");
|
||||
newMetadata.setAudibleRating(4.5);
|
||||
newMetadata.setAudibleReviewCount(1200);
|
||||
|
||||
MetadataUpdateWrapper wrapper = MetadataUpdateWrapper.builder()
|
||||
.metadata(newMetadata)
|
||||
.build();
|
||||
|
||||
MetadataUpdateContext context = MetadataUpdateContext.builder()
|
||||
.bookEntity(bookEntity)
|
||||
.metadataUpdateWrapper(wrapper)
|
||||
.replaceMode(MetadataReplaceMode.REPLACE_ALL)
|
||||
.build();
|
||||
|
||||
bookMetadataUpdater.setBookMetadata(context);
|
||||
|
||||
assertEquals("B0EXAMPLE1", bookEntity.getMetadata().getAsin());
|
||||
assertEquals("B0EXAMPLE1", bookEntity.getMetadata().getAudibleId());
|
||||
assertEquals(4.5, bookEntity.getMetadata().getAudibleRating());
|
||||
assertEquals(1200, bookEntity.getMetadata().getAudibleReviewCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void setBookMetadata_withReplaceMissingMode_shouldNotReplaceExistingTitle() {
|
||||
// This test verifies the old behavior that was causing the bug
|
||||
|
||||
@@ -205,7 +205,10 @@ public class MetadataChangeDetectorTest {
|
||||
Arguments.of("goodreadsRating", (Consumer<BookMetadata>) m -> m.setGoodreadsRating(4.3)),
|
||||
Arguments.of("goodreadsReviewCount", (Consumer<BookMetadata>) m -> m.setGoodreadsReviewCount(30000)),
|
||||
Arguments.of("hardcoverRating", (Consumer<BookMetadata>) m -> m.setHardcoverRating(4.2)),
|
||||
Arguments.of("hardcoverReviewCount", (Consumer<BookMetadata>) m -> m.setHardcoverReviewCount(750))
|
||||
Arguments.of("hardcoverReviewCount", (Consumer<BookMetadata>) m -> m.setHardcoverReviewCount(750)),
|
||||
Arguments.of("audibleId", (Consumer<BookMetadata>) m -> m.setAudibleId("B098765432")),
|
||||
Arguments.of("audibleRating", (Consumer<BookMetadata>) m -> m.setAudibleRating(4.6)),
|
||||
Arguments.of("audibleReviewCount", (Consumer<BookMetadata>) m -> m.setAudibleReviewCount(3000))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -551,6 +554,8 @@ public class MetadataChangeDetectorTest {
|
||||
newMeta.setAmazonReviewCount(2000);
|
||||
newMeta.setGoodreadsReviewCount(35000);
|
||||
newMeta.setHardcoverReviewCount(800);
|
||||
newMeta.setAudibleRating(4.6);
|
||||
newMeta.setAudibleReviewCount(3000);
|
||||
boolean result = MetadataChangeDetector.hasValueChangesForFileWrite(newMeta, existingMeta, clearFlags);
|
||||
assertFalse(result, "Rating and review count fields should not trigger file write");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user