Skip to content

Commit

Permalink
[Jetcaster] Add tests for podcast category filter limit (#1355)
Browse files Browse the repository at this point in the history
Although this test case may become unnecessary once the `limit`
parameters in each method of the `CategoryStore` are explicitly
specified, I added it because it seems that there was no test code to
verify the limits currently used in the `PodcastCategoryFilterUseCase`.
  • Loading branch information
arriolac committed Apr 25, 2024
2 parents ae41864 + 49dcaad commit 866febc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ class PodcastCategoryFilterUseCaseTest {
result.episodes
)
}

@Test
fun whenCategoryInfoNotNull_verifyLimitFlow() = runTest {
val resultFlow = useCase(testCategory.asExternalModel())

categoriesStore.setEpisodesFromPodcast(
testCategory.id,
List(8) { testEpisodeToPodcast }.flatten()
)
categoriesStore.setPodcastsInCategory(
testCategory.id,
List(4) { testPodcasts }.flatten()
)

val result = resultFlow.first()
assertEquals(20, result.episodes.size)
assertEquals(10, result.topPodcasts.size)
}
}

val testPodcasts = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class TestCategoryStore : CategoryStore {
categoryId: Long,
limit: Int
): Flow<List<PodcastWithExtraInfo>> = podcastsInCategoryFlow.map {
it[categoryId] ?: emptyList()
it[categoryId]?.take(limit) ?: emptyList()
}

override fun episodesFromPodcastsInCategory(
categoryId: Long,
limit: Int
): Flow<List<EpisodeToPodcast>> = episodesFromPodcasts.map {
it[categoryId] ?: emptyList()
it[categoryId]?.take(limit) ?: emptyList()
}

override suspend fun addCategory(category: Category): Long = -1
Expand Down

0 comments on commit 866febc

Please sign in to comment.