Test that a failed provided image falls back to a thumbnail found in HTML.

This commit is contained in:
Brent Simmons committed 2026-10-30 22:07:58 -07:00
1 parent 521f00be18
commit 2c56df2373
1 file changed
+18
@@ -75,6 +75,24 @@ private typealias ArticleAttachment = Articles.Attachment
#expect(finder.thumbnailURL(for: articleWithImage, mode: .small) == "https://example.com/uploads/second-photo.jpg")
}
@Test func failedProvidedImageFallsBackToHTMLThumbnail() async {
let imageDatabase = ImageDatabase(databasePath: ":memory:")
let finder = ArticleThumbnailFinder(imageDatabase: imageDatabase)
let article = makeArticle(contentHTML: #"<p><img src="/uploads/photo.jpg" width="640" height="480"></p>"#, thumbnailURL: "https://example.com/thumbnail.jpg")
// The HTML isn’t parsed while the provided image is usable.
await finder.discoverThumbnailURLs(for: [article])
#expect(finder.thumbnailURL(for: article, mode: .small) == "https://example.com/thumbnail.jpg")
#expect(await imageDatabase.fetchArticleThumbnails(articleIDs: ["1"]).isEmpty)
imageDatabase.recordFailure(url: "https://example.com/thumbnail.jpg", statusCode: 404)
finder.thumbnailURLDidFail("https://example.com/thumbnail.jpg")
#expect(finder.thumbnailURL(for: article, mode: .small) == nil)
await finder.discoverThumbnailURLs(for: [article])
#expect(finder.thumbnailURL(for: article, mode: .small) == "https://example.com/uploads/photo.jpg")
}
@Test func savedHTMLThumbnailIsLoadedWithoutDiscovery() async {
let imageDatabase = ImageDatabase(databasePath: ":memory:")
let article = makeArticle(contentHTML: #"<p><img src="/uploads/photo.jpg" width="640" height="480"></p>"#)