Compare commits
No commits in common. "c8759cc0358df4cee29f0157dfd4b218319911a7" and "41c951b6593087a939f19215dd45f011f6209b9a" have entirely different histories.
c8759cc035
...
41c951b659
@ -143,13 +143,13 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
||||
return success
|
||||
}
|
||||
|
||||
suspend fun getTags(): List<SelfossModel.Tag> {
|
||||
suspend fun getTags(): List<SelfossModel.Tag>? {
|
||||
return if (isNetworkAvailable()) {
|
||||
val apiTags = api.tags()
|
||||
if (apiTags.success && apiTags.data != null && (appSettingsService.isItemCachingEnabled() || !appSettingsService.isUpdateSourcesEnabled())) {
|
||||
resetDBTagsWithData(apiTags.data)
|
||||
}
|
||||
apiTags.data ?: emptyList()
|
||||
apiTags.data
|
||||
} else {
|
||||
getDBTags().map { it.toView() }
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||
import bou.amine.apps.readerforselfossv2.rest.SelfossApi
|
||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||
import bou.amine.apps.readerforselfossv2.utils.ItemType
|
||||
import bou.amine.apps.readerforselfossv2.utils.toView
|
||||
import com.github.ln_12.library.ConnectivityStatus
|
||||
import io.mockk.*
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@ -270,7 +269,6 @@ class RepositoryTest() {
|
||||
fun `Reload badges with items caching`() {
|
||||
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
||||
every { appSettingsService.isItemCachingEnabled() } returns true
|
||||
every { db.itemsQueries.items().executeAsList() } returns generateTestDBItems()
|
||||
|
||||
val itemParameter = FakeItemParameters()
|
||||
itemParameter.starred = true
|
||||
@ -286,7 +284,7 @@ class RepositoryTest() {
|
||||
|
||||
assertSame(true, success)
|
||||
assertSame(1, repository.badgeAll)
|
||||
assertSame(1, repository.badgeUnread)
|
||||
assertSame(0, repository.badgeUnread)
|
||||
assertSame(1, repository.badgeStarred)
|
||||
coVerify(exactly = 0) { api.stats() }
|
||||
verify(atLeast = 1) { db.itemsQueries.items().executeAsList()}
|
||||
@ -346,20 +344,19 @@ class RepositoryTest() {
|
||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
var testTags: List<SelfossModel.Tag>? = null
|
||||
runBlocking {
|
||||
testTags = repository.getTags()
|
||||
testTags = repository.getTags()
|
||||
}
|
||||
|
||||
assertNotSame(tags, testTags)
|
||||
assertContentEquals(tagsDB.map { it.toView() }, testTags)
|
||||
coVerify(exactly = 1) { api.tags() }
|
||||
assertSame(tagsDB.first().name, testTags?.first()?.tag)
|
||||
coVerify(exactly = 0) { api.tags() }
|
||||
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Get tags with sources update and items caching disabled`() {
|
||||
fun `Get tags with sources update and db disabled`() {
|
||||
val tags = listOf(SelfossModel.Tag("test", "red", 6),
|
||||
SelfossModel.Tag("second", "yellow", 0))
|
||||
val tagsDB = listOf(TAG("test_DB", "red", 6),
|
||||
@ -371,12 +368,12 @@ class RepositoryTest() {
|
||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
var testTags: List<SelfossModel.Tag>? = null
|
||||
runBlocking {
|
||||
testTags = repository.getTags()
|
||||
}
|
||||
|
||||
assertSame(emptyList(), testTags)
|
||||
assertSame(null, testTags)
|
||||
coVerify(exactly = 0) { api.tags() }
|
||||
verify(exactly = 0) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
@ -393,13 +390,13 @@ class RepositoryTest() {
|
||||
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
var testTags: List<SelfossModel.Tag>? = null
|
||||
runBlocking {
|
||||
testTags = repository.getTags()
|
||||
}
|
||||
|
||||
assertNotSame(tags, testTags)
|
||||
assertSame(tagsDB.first().name, testTags.first().tag)
|
||||
assertSame(tagsDB.first().name, testTags?.first()?.tag)
|
||||
coVerify(exactly = 0) { api.tags() }
|
||||
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
@ -417,38 +414,14 @@ class RepositoryTest() {
|
||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
var testTags: List<SelfossModel.Tag>? = null
|
||||
runBlocking {
|
||||
testTags = repository.getTags()
|
||||
}
|
||||
|
||||
assertContentEquals(tagsDB.map { it.toView() }, testTags)
|
||||
assertSame(null, testTags)
|
||||
coVerify(exactly = 0) { api.tags() }
|
||||
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Get tags without connection and sources update disabled`() {
|
||||
val tags = listOf(SelfossModel.Tag("test", "red", 6),
|
||||
SelfossModel.Tag("second", "yellow", 0))
|
||||
val tagsDB = listOf(TAG("test_DB", "red", 6),
|
||||
TAG("second_DB", "yellow", 0))
|
||||
|
||||
coEvery { api.tags() } returns SelfossModel.StatusAndData(success = true, data = tags)
|
||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
||||
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
runBlocking {
|
||||
testTags = repository.getTags()
|
||||
}
|
||||
|
||||
assertNotSame(tags, testTags)
|
||||
assertContentEquals(tagsDB.map { it.toView() }, testTags)
|
||||
coVerify(exactly = 0) { api.tags() }
|
||||
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
||||
verify(exactly = 0) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user