Skip to content

Commit

Permalink
Fix for empty metadata bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nylonee committed Feb 26, 2024
1 parent 527aaaf commit cd6686a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/scala/plex/MediaContainer.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package plex

private[plex] case class MediaContainer(Metadata: List[TokenWatchlistItem], totalSize: Int)
private[plex] case class MediaContainer(Metadata: List[TokenWatchlistItem] = List.empty, totalSize: Int)
10 changes: 10 additions & 0 deletions src/test/resources/empty-watchlist-from-token.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"MediaContainer": {
"librarySectionID": "watchlist",
"librarySectionTitle": "Watchlist",
"offset": 300,
"totalSize": 16,
"identifier": "tv.plex.provider.discover",
"size": 0
}
}
18 changes: 18 additions & 0 deletions src/test/scala/plex/PlexUtilsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ class PlexUtilsSpec extends AnyFlatSpec with Matchers with PlexUtils with MockFa
result.head shouldBe Item("The Test", List("imdb://tt11347692", "tmdb://95837", "tvdb://372848"), "show")
}


it should "successfully fetch an empty watchlist using the plex token" in {
val mockClient = mock[HttpClient]
val config = createConfiguration(Set("test-token"))
(mockClient.httpRequest _).expects(
Method.GET,
Uri.unsafeFromString("https://metadata.provider.plex.tv/library/sections/watchlist/all?X-Plex-Token=test-token&X-Plex-Container-Start=0&X-Plex-Container-Size=300"),
None,
None
).returning(IO.pure(parse(Source.fromResource("empty-watchlist-from-token.json").getLines().mkString("\n")))).once()

val eitherResult = getSelfWatchlist(config, mockClient).value.unsafeRunSync()

eitherResult shouldBe a[Right[_, _]]
val result = eitherResult.getOrElse(Set.empty[Item])
result.size shouldBe 0
}

it should "fetch the healthy part of a watchlist using the plex token" in {
val mockClient = mock[HttpClient]
val config = createConfiguration(Set("test-token"))
Expand Down

0 comments on commit cd6686a

Please sign in to comment.