refactor(metadata): add external url to all metadata sources (#2670)

This commit is contained in:
James Ward
2026-09-18 12:59:59 +01:00
committed by GitHub
parent a1eaa6815a
commit b2fa4b7461
10 changed files with 83 additions and 4 deletions
@@ -161,4 +161,20 @@ public class DoubanBookParserTest {
assertThat(results).hasSize(3);
}
@Test
public void parsesSearchResults_includesExternalUrl() throws Exception {
mockJsoupConnect("https://search.douban.com/book/subject_search?search_text=Example", readFixture("match-search.html"));
mockJsoupConnect("https://book.douban.com/subject/36939359", readFixture("book.html"));
mockJsoupConnect("https://book.douban.com/subject/35297655", readFixture("book.html"));
mockJsoupConnect("https://book.douban.com/subject/26328534", readFixture("book.html"));
var book = getBook();
var fetchMetadataRequest = FetchMetadataRequest.builder().title("Example").build();
var results = doubanBookParser.fetchMetadata(book, fetchMetadataRequest);
assertThat(results).hasSize(3);
assertThat(results.getFirst().getExternalUrl()).isEqualTo("https://book.douban.com/subject/36939359");
}
}
@@ -168,6 +168,36 @@ public class GoodReadsParserTest {
assertThat(result.getDescription()).hasSize(511);
}
@Test
void testFetchMetadata_addsExternalUrl() throws Exception {
// Given
Book book = Book.builder()
.title("A Clockwork Orange")
.build();
FetchMetadataRequest request = FetchMetadataRequest.builder()
.title("A Clockwork Orange")
.author("Anthony Burgess")
.build();
// Mock enabled provider
mockSettings(true);
// Two expected URLs: search + GraphQL
mockHttpClientResponse("https://www.goodreads.com/book/auto_complete", 200, exampleSearchJsonFixture);
mockHttpClientResponse("https://kxbwmqov6jgg3daaamb744ycu4.appsync-api.us-east-1.amazonaws.com/graphql", 200, exampleGraphqlResponseFixture);
// When
List<BookMetadata> results = parser.fetchMetadata(book, request);
// Then
assertThat(results).isNotNull();
assertThat(results).as("Should return results for real book").isNotEmpty();
BookMetadata result = results.getFirst();
assertThat(result.getExternalUrl()).isEqualTo("https://www.goodreads.com/book/show/41817486");
}
@Test
void testFetchMetadata_withRateLimitingError() throws Exception {
// Given
@@ -578,6 +578,7 @@ class HardcoverParserTest {
assertThat(metadata.getSubtitle()).isNull();
assertThat(metadata.getDescription()).isEqualTo("In the year 2045, reality is an ugly place. The only time Wade Watts really feels alive is when he’s jacked into the OASIS, a vast virtual world where most of humanity spends their days.\n\nWhen the eccentric creator of the OASIS dies, he leaves behind a series of fiendish puzzles, based on his obsession with the pop culture of decades past. Whoever is first to solve them will inherit his vast fortune—and control of the OASIS itself. \n\nThen Wade cracks the first clue. Suddenly he’s beset by rivals who’ll kill to take this prize. The race is on—and the only way to survive is to win.\n");
assertThat(metadata.getHardcoverId()).isEqualTo("ready-player-one");
assertThat(metadata.getExternalUrl()).isEqualTo("https://hardcover.app/books/ready-player-one");
assertThat(metadata.getHardcoverBookId()).isEqualTo("26363");
assertThat(metadata.getHardcoverRating()).isEqualTo(4.03);
assertThat(metadata.getHardcoverReviewCount()).isEqualTo(495);
@@ -184,6 +184,7 @@ class LubimyCzytacParserTest {
assertNotNull(result.getAuthors());
assertEquals(1, result.getAuthors().size());
assertEquals("Bruno Schulz", result.getAuthors().getFirst());
assertEquals("https://lubimyczytac.pl/ksiazka/5223841/sklepy-cynamonowe", result.getExternalUrl());
// The description is very long, but we need to make sure we're in the right ballpark.
assertEquals("Jedno z najoryginalniejszych", result.getDescription().substring(0, 28));
@@ -116,6 +116,7 @@ class RanobeDbParserTest {
BookMetadata firstResult = results.getFirst();
assertThat(firstResult.getTitle()).withFailMessage("Title should be present").isNotNull();
assertThat(firstResult.getRanobedbId()).withFailMessage("RanobeDB ID should be present").isNotNull();
assertThat(firstResult.getExternalUrl()).isEqualTo("https://ranobedb.org/book/47136");
var authors = firstResult.getAuthors();
assertThat(authors).withFailMessage("Authors should be present").isNotEmpty();