feat(kobo): add subtitle to KoboBookMetadata (#1543)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package org.booklore.model.dto.kobo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class KoboBookMetadataTest {
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
void shouldIncludeSubtitleWhenNotNull() {
|
||||
// Given: Book has a subtitle
|
||||
KoboBookMetadata metadata = KoboBookMetadata.builder()
|
||||
.title("Test Book")
|
||||
.subtitle("A Subtitle")
|
||||
.build();
|
||||
|
||||
// When: Serializing to JSON
|
||||
String json = objectMapper.writeValueAsString(metadata);
|
||||
Map<String, Object> result = objectMapper.readValue(json, Map.class);
|
||||
|
||||
// Then: Subtitle should be included
|
||||
assertThat(result)
|
||||
.containsKey("Title")
|
||||
.containsKey("Subtitle");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExcludeSubtitleWhenNull() {
|
||||
// Given: Book does not have a subtitle
|
||||
KoboBookMetadata metadata = KoboBookMetadata.builder()
|
||||
.title("Test Book")
|
||||
.subtitle(null)
|
||||
.build();
|
||||
|
||||
// When: Serializing to JSON
|
||||
String json = objectMapper.writeValueAsString(metadata);
|
||||
Map<String, Object> result = objectMapper.readValue(json, Map.class);
|
||||
|
||||
// Then: Subtitle should be excluded
|
||||
assertThat(result)
|
||||
.containsKey("Title")
|
||||
.doesNotContainKey("Subtitle");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.booklore.service;
|
||||
|
||||
import org.booklore.config.security.service.AuthenticationService;
|
||||
import org.booklore.model.dto.Book;
|
||||
import org.booklore.model.dto.BookLoreUser;
|
||||
import org.booklore.model.dto.settings.AppSettings;
|
||||
import org.booklore.model.dto.kobo.KoboBookMetadata;
|
||||
@@ -219,6 +218,51 @@ class KoboEntitlementServiceTest {
|
||||
assertEquals(KoboBookFormat.KEPUB.toString(), result.getDownloadUrls().getFirst().getFormat());
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapToKoboMetadata_subtitleNull() {
|
||||
long bookId = 1L;
|
||||
BookEntity epubBook = createEpubBookEntity(bookId);
|
||||
epubBook.getMetadata().setSubtitle(null);
|
||||
String token = "test-token";
|
||||
|
||||
when(bookQueryService.findAllWithMetadataByIds(Set.of(bookId)))
|
||||
.thenReturn(List.of(epubBook));
|
||||
when(koboCompatibilityService.isBookSupportedForKobo(epubBook))
|
||||
.thenReturn(true);
|
||||
when(koboUrlBuilder.downloadUrl(token, epubBook.getId()))
|
||||
.thenReturn("http://test.com/download/" + epubBook.getId());
|
||||
when(appSettingService.getAppSettings())
|
||||
.thenReturn(createAppSettingsWithKoboSettings());
|
||||
|
||||
KoboBookMetadata result = koboEntitlementService.getMetadataForBook(bookId, token);
|
||||
|
||||
assertNotNull(result);
|
||||
assertNull(result.getSubtitle());
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapToKoboMetadata_shouldIncludeSubtitleWhenNotNull() {
|
||||
long bookId = 1L;
|
||||
String subtitle = "A test subtitle";
|
||||
BookEntity epubBook = createEpubBookEntity(bookId);
|
||||
epubBook.getMetadata().setSubtitle(subtitle);
|
||||
String token = "test-token";
|
||||
|
||||
when(bookQueryService.findAllWithMetadataByIds(Set.of(bookId)))
|
||||
.thenReturn(List.of(epubBook));
|
||||
when(koboCompatibilityService.isBookSupportedForKobo(epubBook))
|
||||
.thenReturn(true);
|
||||
when(koboUrlBuilder.downloadUrl(token, epubBook.getId()))
|
||||
.thenReturn("http://test.com/download/" + epubBook.getId());
|
||||
when(appSettingService.getAppSettings())
|
||||
.thenReturn(createAppSettingsWithKoboSettings());
|
||||
|
||||
KoboBookMetadata result = koboEntitlementService.getMetadataForBook(bookId, token);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(subtitle, result.getSubtitle());
|
||||
}
|
||||
|
||||
private BookEntity createCbxBookEntity(Long id) {
|
||||
BookEntity book = new BookEntity();
|
||||
book.setId(id);
|
||||
|
||||
Reference in New Issue
Block a user