Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for empty metadata bug #104

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading