From 49dcaad36b4a1bcd55084907f67de0953db156ce Mon Sep 17 00:00:00 2001 From: yongsuk44 Date: Fri, 19 Apr 2024 15:24:16 +0900 Subject: [PATCH] [Jetcaster] Add tests for category filter limit --- .../domain/PodcastCategoryFilterUseCaseTest.kt | 18 ++++++++++++++++++ .../core/data/repository/TestCategoryStore.kt | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/data/domain/PodcastCategoryFilterUseCaseTest.kt b/Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/data/domain/PodcastCategoryFilterUseCaseTest.kt index 2f2d5a3b5b..9c4d3b84f6 100644 --- a/Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/data/domain/PodcastCategoryFilterUseCaseTest.kt +++ b/Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/data/domain/PodcastCategoryFilterUseCaseTest.kt @@ -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( diff --git a/Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/data/repository/TestCategoryStore.kt b/Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/data/repository/TestCategoryStore.kt index 9b867f0f9e..56ceff9642 100644 --- a/Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/data/repository/TestCategoryStore.kt +++ b/Jetcaster/core/src/test/kotlin/com/example/jetcaster/core/data/repository/TestCategoryStore.kt @@ -42,14 +42,14 @@ class TestCategoryStore : CategoryStore { categoryId: Long, limit: Int ): Flow> = podcastsInCategoryFlow.map { - it[categoryId] ?: emptyList() + it[categoryId]?.take(limit) ?: emptyList() } override fun episodesFromPodcastsInCategory( categoryId: Long, limit: Int ): Flow> = episodesFromPodcasts.map { - it[categoryId] ?: emptyList() + it[categoryId]?.take(limit) ?: emptyList() } override suspend fun addCategory(category: Category): Long = -1