Skip to content

Commit

Permalink
Fix TmdbSeasonDetail images parsing
Browse files Browse the repository at this point in the history
It currently expects the images to be within a nested `result` list but the API provides a top level block roughly matching the TmdbImages class.
  • Loading branch information
DrewCarlson authored and ChrisKruegerDev committed Nov 18, 2023
1 parent f58de31 commit 6d23372
Show file tree
Hide file tree
Showing 4 changed files with 2,360 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ data class TmdbVideo(
@Serializable
data class TmdbImages(
@SerialName("id") val id: Int? = null,
@SerialName("posters") val posters: List<TmdbFileImage>,
@SerialName("backdrops") val backdrops: List<TmdbFileImage>
@SerialName("posters") val posters: List<TmdbFileImage> = emptyList(),
@SerialName("backdrops") val backdrops: List<TmdbFileImage> = emptyList()
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ data class TmdbSeasonDetail(
val episodes: List<TmdbEpisode>? = null,
@SerialName("external_ids") val externalIds: TmdbExternalIds? = null,
@SerialName("videos") val videos: TmdbResult<TmdbVideo>? = null,
@SerialName("images") val images: TmdbResult<TmdbImages>? = null
@SerialName("images") val images: TmdbImages? = null
) : TmdbAnyMedia, TmdbPosterMedia {

val numberOfEpisodes get() = episodeCount ?: episodes?.size ?: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package app.moviebase.tmdb.api

import app.moviebase.tmdb.core.mockHttpClient
import app.moviebase.tmdb.model.AppendResponse
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test

class TmdbSeasonApiTest {

val client = mockHttpClient(
version = 3,
responses = mapOf(
"tv/63333/season/1?append_to_response=release_dates,images,credits,tv_credits,external_ids&include_image_language=" to "tv/tv_season_63333_season_1.json",
),
)
val classToTest = TmdbShowSeasonsApi(client)

@Test
fun `it can fetch season details with images`() = runTest {
val seasonDetails = classToTest.getDetails(
63333,
1,
null,
listOf(
AppendResponse.RELEASES_DATES,
AppendResponse.IMAGES,
AppendResponse.CREDITS,
AppendResponse.TV_CREDITS,
AppendResponse.EXTERNAL_IDS,
),
"",
)

assertEquals(68878, seasonDetails.id)
assertNotNull(seasonDetails.images)

val imageFile = seasonDetails.images?.posters?.firstOrNull()
assertEquals("/oQasSKPcBLcEG5rOUg3s1Ozpr4s.jpg", imageFile?.filePath)
}
}
Loading

0 comments on commit 6d23372

Please sign in to comment.