mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 16:11:20 +02:00
Fix suggestions cache miss handling for missing files (#880)
## Description Fix a bug where movie suggestions would get stuck loading when the on-disk cache file doesn't exist. ### Related issues Fixes #876 ### Testing Ran unit tests locally. ## Screenshots N/A ## AI or LLM usage Used AI to add testing for this scenario to unit test --------- Co-authored-by: Ray <154766448+damontecres@users.noreply.github.com>
This commit is contained in:
parent
4161ea418c
commit
11fd780b31
5 changed files with 76 additions and 21 deletions
|
|
@ -10,6 +10,7 @@ import com.github.damontecres.wholphin.util.GetItemsRequestHandler
|
|||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.first
|
||||
|
|
@ -150,6 +151,44 @@ class SuggestionServiceTest {
|
|||
assertEquals(SuggestionsResource.Empty, result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSuggestionsFlow_returnsEmpty_whenCachedIdsEmpty_evenIfWorkIsEnqueued() =
|
||||
runTest {
|
||||
val userId = UUID.randomUUID()
|
||||
val parentId = UUID.randomUUID()
|
||||
val currentUser = MutableLiveData<JellyfinUser?>(mockUser(userId))
|
||||
|
||||
every { mockServerRepository.currentUser } returns currentUser
|
||||
coEvery { mockCache.get(userId, parentId, BaseItemKind.MOVIE) } returns CachedSuggestions(emptyList())
|
||||
every { mockWorkManager.getWorkInfosForUniqueWorkFlow(any()) } returns
|
||||
flowOf(listOf(mockWorkInfo(WorkInfo.State.ENQUEUED)))
|
||||
|
||||
val service = createService()
|
||||
val result = service.getSuggestionsFlow(parentId, BaseItemKind.MOVIE).first()
|
||||
|
||||
assertEquals(SuggestionsResource.Empty, result)
|
||||
verify(exactly = 0) { mockWorkManager.getWorkInfosForUniqueWorkFlow(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSuggestionsFlow_returnsLoading_whenCacheMissing_andWorkIsEnqueued() =
|
||||
runTest {
|
||||
val userId = UUID.randomUUID()
|
||||
val parentId = UUID.randomUUID()
|
||||
val currentUser = MutableLiveData<JellyfinUser?>(mockUser(userId))
|
||||
|
||||
every { mockServerRepository.currentUser } returns currentUser
|
||||
coEvery { mockCache.get(userId, parentId, BaseItemKind.MOVIE) } returns null
|
||||
every { mockWorkManager.getWorkInfosForUniqueWorkFlow(any()) } returns
|
||||
flowOf(listOf(mockWorkInfo(WorkInfo.State.ENQUEUED)))
|
||||
|
||||
val service = createService()
|
||||
val result = service.getSuggestionsFlow(parentId, BaseItemKind.MOVIE).first()
|
||||
|
||||
assertEquals(SuggestionsResource.Loading, result)
|
||||
verify(exactly = 1) { mockWorkManager.getWorkInfosForUniqueWorkFlow(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun passes_correct_arguments_to_cache() =
|
||||
runTest {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue