Skip to content

Commit

Permalink
fix: MIT Weekend Reads article can have empty descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
nicopico-dev committed Sep 4, 2024
1 parent 4f38f2f commit 13f0aa8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package fr.nicopico.n2rss.newsletter.handlers

import fr.nicopico.n2rss.newsletter.models.Article
import fr.nicopico.n2rss.mail.models.Email
import fr.nicopico.n2rss.newsletter.models.Article
import fr.nicopico.n2rss.newsletter.models.Newsletter
import org.jsoup.Jsoup
import org.jsoup.safety.Safelist
Expand Down Expand Up @@ -56,7 +56,8 @@ class MITWeekendReadsNewsletterHandler : NewsletterHandlerSingleFeed {
?: return@mapNotNull null
val title = h2.text().trim()
val description = h2.nextElementSiblings().select("p").firstOrNull()?.ownText()
?: throw NewsletterParsingException("Cannot find description for article \"$title\"")
// Articles can have no description
?: ""

Article(
title = title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,40 @@ class MITWeekendReadsNewsletterHandlerTest {
}
}
}

@Test
fun `should process email without article's descriptions correctly`() {
// GIVEN
val email: Email =
loadEmail("stubs/emails/MIT/Weekend Reads/NEW Our ambitious stories, narrated by real voice actors.eml")

// WHEN
val publication = handler.process(email)

// THEN
publication.articles shouldHaveSize 8
assertSoftly(publication.articles[0]) {
withClue("title") {
title shouldBe "What are AI agents?"
}
withClue("link") {
link shouldBe URL("https://technologyreview.us11.list-manage.com/track/click?u=47c1a9cec9749a8f8cbc83e78&id=35c51e4e4a&e=4fc74d6331")
}
withClue("description") {
description shouldBe ""
}
}

publication.articles.map { it.title } shouldBe listOf(
"What are AI agents?",
"Is this the end of animal testing?",
"How generative AI could reinvent what it means to play",
"Is robotics about to have its own ChatGPT moment?",
"This architect is cutting up materials to make them stronger and lighter",
"The great commercial takeover of low Earth orbit",
"It’s time to retire the term “user”",
"The cost of building the perfect wave",
)
}
}
}

0 comments on commit 13f0aa8

Please sign in to comment.