diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SelectionRepo.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SelectionRepo.kt index a69f74d3..2f961397 100644 --- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SelectionRepo.kt +++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SelectionRepo.kt @@ -51,7 +51,15 @@ class SelectionRepo( null // null = no filtering } else { val ids = resolveTypeIds(types) - if (ids.isEmpty()) emptySet() else ids.toHashSet() + when { + ids.isNotEmpty() -> ids.toHashSet() + // "All" is the CelesTrak active group, i.e. the whole catalogue: an empty + // persisted list must mean "no filtering" (show every satellite), not an + // empty list. Its list can be empty simply because CelesTrak answered 403 + // to a repeated download inside the 2-hour update window. + Sources.allSourceType in types -> null + else -> emptySet() + } } currentItems.map { items -> if (catnumSet == null) items else items.filter { it.catnum in catnumSet } diff --git a/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/SelectionRepoSearchTest.kt b/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/SelectionRepoSearchTest.kt index 8a961265..5ad6d52f 100644 --- a/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/SelectionRepoSearchTest.kt +++ b/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/SelectionRepoSearchTest.kt @@ -23,6 +23,7 @@ import com.rtbishop.look4sat.core.domain.predict.OrbitalObject import com.rtbishop.look4sat.core.domain.repository.ISelectionRepo import com.rtbishop.look4sat.core.domain.repository.ISettingsRepo import com.rtbishop.look4sat.core.domain.source.ILocalSource +import com.rtbishop.look4sat.core.domain.source.Sources import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow @@ -241,6 +242,26 @@ class SelectionRepoSearchTest { assertEquals(sampleItems.map { it.catnum }.toSet(), results.map { it.catnum }.toSet()) } + @Test + fun `All with empty persisted ids falls back to no filtering`() = runTest { + // CelesTrak answers 403 to a repeated download inside its 2-hour update window, + // so the persisted "All" id list can be empty. Selecting All then means "all + // satellites" (no filtering) instead of blanking the list. + val repo = createRepo(sampleItems) + repo.setTypes(listOf(Sources.allSourceType)) + val results = repo.getEntriesFlow().first() + assertEquals(sampleItems.map { it.catnum }.toSet(), results.map { it.catnum }.toSet()) + } + + @Test + fun `other source type with empty persisted ids still shows empty`() = runTest { + // Only "All" falls back to no filtering; a regular source without persisted ids + // keeps the previous behaviour (empty list). + val repo = createRepo(sampleItems) + repo.setTypes(listOf("Amateur")) + assertTrue(repo.getEntriesFlow().first().isEmpty()) + } + @Test fun `getTypesList excludes only the Other placeholder`() = runTest { val repo = createRepo(sampleItems)