Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class ImprovedSearchManagerImpl @Inject constructor(
publishedDate = it.publishedDate,
duration = it.duration.seconds,
)

CombinedResult.Unknown -> null
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,24 @@ class ImprovedSearchManagerImplTest {
val episode = results.filterIsInstance<ImprovedSearchResultItem.EpisodeItem>().single()
assertEquals("Business Daily", episode.podcastTitle)
}

@Test
fun `combined search drops unknown result types`() = runTest {
whenever(combinedSearchService.combinedSearch(any())) doReturn CombinedSearchResponse(
results = listOf(
CombinedResult.PodcastResult(
uuid = "podcast-uuid",
title = "Big Sugar",
author = "Weekday Fun Productions",
slug = "big-sugar",
explicit = false,
),
CombinedResult.Unknown,
),
)

val results = manager.combinedSearch("big sugar")

assertEquals(listOf("podcast-uuid"), results.map { it.uuid })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ sealed interface CombinedResult {
val podcastSlug: String,
) : CombinedResult

data object Unknown : CombinedResult

companion object {
val jsonAdapter = PolymorphicJsonAdapterFactory.of(CombinedResult::class.java, "type")
.withSubtype(PodcastResult::class.java, "podcast")
.withSubtype(EpisodeResult::class.java, "episode")
.withDefaultValue(Unknown)
Comment thread
sztomek marked this conversation as resolved.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package au.com.shiftyjelly.pocketcasts.servers.search

import com.squareup.moshi.Moshi
import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter
import java.util.Date
import org.junit.Assert.assertEquals
import org.junit.Test

class CombinedSearchResponseTest {
private val adapter = Moshi.Builder()
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
.add(CombinedResult.jsonAdapter)
.build()
.adapter(CombinedSearchResponse::class.java)

@Test
fun `unknown result types map to Unknown without failing the whole response`() {
val response = adapter.fromJson(
"""
{"results":[
{"uuid":"p1","title":"Freakonomics Radio","slug":"freakonomics-radio","type":"podcast"},
{"uuid":"n1","title":"Some Network","type":"network"},
{"uuid":"p2","title":"Another Show","slug":"another-show","type":"podcast"}
]}
""".trimIndent(),
)

val types = response?.results?.map { it::class.simpleName }
assertEquals(listOf("PodcastResult", "Unknown", "PodcastResult"), types)
}
Comment thread
sztomek marked this conversation as resolved.
Comment thread
sztomek marked this conversation as resolved.
}