Fix repository.tags() returning null

This commit is contained in:
davidoskky 2022-09-27 23:26:44 +02:00
parent 7517626ab7
commit cb4f2f02ef
2 changed files with 5 additions and 5 deletions

View File

@ -143,13 +143,13 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
return success return success
} }
suspend fun getTags(): List<SelfossModel.Tag>? { suspend fun getTags(): List<SelfossModel.Tag> {
return if (isNetworkAvailable()) { return if (isNetworkAvailable()) {
val apiTags = api.tags() val apiTags = api.tags()
if (apiTags.success && apiTags.data != null && (appSettingsService.isItemCachingEnabled() || !appSettingsService.isUpdateSourcesEnabled())) { if (apiTags.success && apiTags.data != null && (appSettingsService.isItemCachingEnabled() || !appSettingsService.isUpdateSourcesEnabled())) {
resetDBTagsWithData(apiTags.data) resetDBTagsWithData(apiTags.data)
} }
apiTags.data apiTags.data ?: emptyList()
} else { } else {
getDBTags().map { it.toView() } getDBTags().map { it.toView() }
} }

View File

@ -285,7 +285,7 @@ class RepositoryTest() {
assertSame(true, success) assertSame(true, success)
assertSame(1, repository.badgeAll) assertSame(1, repository.badgeAll)
assertSame(0, repository.badgeUnread) assertSame(1, repository.badgeUnread)
assertSame(1, repository.badgeStarred) assertSame(1, repository.badgeStarred)
coVerify(exactly = 0) { api.stats() } coVerify(exactly = 0) { api.stats() }
verify(atLeast = 1) { db.itemsQueries.items().executeAsList()} verify(atLeast = 1) { db.itemsQueries.items().executeAsList()}
@ -391,13 +391,13 @@ class RepositoryTest() {
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
val repository = Repository(api, appSettingsService, connectivityStatus, db) val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testTags: List<SelfossModel.Tag>? = null var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
} }
assertNotSame(tags, testTags) assertNotSame(tags, testTags)
assertSame(tagsDB.first().name, testTags?.first()?.tag) assertSame(tagsDB.first().name, testTags.first().tag)
coVerify(exactly = 0) { api.tags() } coVerify(exactly = 0) { api.tags() }
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() } verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
} }