Repository Unit Tests #50
@ -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
|
||||
apiTags.data ?: emptyList()
|
||||
} else {
|
||||
getDBTags().map { it.toView() }
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ class RepositoryTest() {
|
||||
|
||||
assertSame(true, success)
|
||||
assertSame(1, repository.badgeAll)
|
||||
assertSame(0, repository.badgeUnread)
|
||||
assertSame(1, repository.badgeUnread)
|
||||
assertSame(1, repository.badgeStarred)
|
||||
coVerify(exactly = 0) { api.stats() }
|
||||
AmineB marked this conversation as resolved
|
||||
verify(atLeast = 1) { db.itemsQueries.items().executeAsList()}
|
||||
@ -391,13 +391,13 @@ class RepositoryTest() {
|
||||
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
Tags and sources caching is handled via the update_sources setting. Also, disabling that setting should clear the DB (this is not the case yet) So this line should return null, as we won't check for the update_sources setting every time we try to fetch the db data. Tags and sources caching is handled via the update_sources setting.
Also, disabling that setting should clear the DB (this is not the case yet)
So this line should return null, as we won't check for the update_sources setting every time we try to fetch the db data.
AmineB
commented
Returning Returning `null` isn't possible, so it should be an empty list.
davidoskky
commented
Why is tags caching handled by update_sources? Why is tags caching handled by update_sources?
AmineB
commented
Because it's handled separatly, so users can cache the sources/tags without caching anything else. Because it's handled separatly, so users can cache the sources/tags without caching anything else.
davidoskky
commented
I don't think sources and tags should be cached if items are not cached; what would be the use of such a function? I don't think sources and tags should be cached if items are not cached; what would be the use of such a function?
AmineB
commented
As mentionnend by you in a previous comment, it is used to limit the ammount of calls to the selfoss instance, by limiting the call to tags/sources routes. > I don't think sources and tags should be cached if items are not cached; what would be the use of such a function?
As mentionnend by you in a previous comment, it is used to limit the ammount of calls to the selfoss instance, by limiting the call to tags/sources routes.
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag>? = null
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
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() }
|
||||
AmineB marked this conversation as resolved
AmineB
commented
this should be this should be `assertEquals(emptyList(), testTags)`
|
||||
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
AmineB marked this conversation as resolved
AmineB
commented
This will be called once. This will be called once.
|
||||
|
Be cause of the line 40 of the
setup
function you have an unread/starred item in your DB.Yes, this is intended.
Since items caching is disabled I would expect the function not to access items in the database.
Maybe it's better if I define that item within this function to avoid ambiguity.
I answerd this in another comment.
The DB should be empty when the setting is disabled, so this should never happen.
Even if the DB is empty, there is no reason to call it if the setting is disabled.
I placed something in the DB just to test that it was not called.
I find it useless to test if caching is enabled to check if there is something in the DB.
It should be quicker and prevents errors in case some problems with DB clearing happens.
Still, db cleaning should be done on setting change.