From cd6686a00181f072bf530c1886dde2f7d9b58de5 Mon Sep 17 00:00:00 2001 From: Nihal Mirpuri Date: Mon, 26 Feb 2024 13:02:35 +0000 Subject: [PATCH] Fix for empty metadata bug --- src/main/scala/plex/MediaContainer.scala | 2 +- .../resources/empty-watchlist-from-token.json | 10 ++++++++++ src/test/scala/plex/PlexUtilsSpec.scala | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/empty-watchlist-from-token.json diff --git a/src/main/scala/plex/MediaContainer.scala b/src/main/scala/plex/MediaContainer.scala index fbb4357..b35cb2a 100644 --- a/src/main/scala/plex/MediaContainer.scala +++ b/src/main/scala/plex/MediaContainer.scala @@ -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) diff --git a/src/test/resources/empty-watchlist-from-token.json b/src/test/resources/empty-watchlist-from-token.json new file mode 100644 index 0000000..4840225 --- /dev/null +++ b/src/test/resources/empty-watchlist-from-token.json @@ -0,0 +1,10 @@ +{ + "MediaContainer": { + "librarySectionID": "watchlist", + "librarySectionTitle": "Watchlist", + "offset": 300, + "totalSize": 16, + "identifier": "tv.plex.provider.discover", + "size": 0 + } +} diff --git a/src/test/scala/plex/PlexUtilsSpec.scala b/src/test/scala/plex/PlexUtilsSpec.scala index 17f0c80..84df2bd 100644 --- a/src/test/scala/plex/PlexUtilsSpec.scala +++ b/src/test/scala/plex/PlexUtilsSpec.scala @@ -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"))