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:
Justin Caveda 2026-02-12 17:27:59 -06:00 committed by GitHub
parent 4161ea418c
commit 11fd780b31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 76 additions and 21 deletions

View file

@ -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 {