Repository Unit Tests #50
@ -308,6 +308,8 @@ class RepositoryTest() {
|
||||
|
||||
coEvery { api.tags() } returns SelfossModel.StatusAndData(success = true, data = tags)
|
||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
||||
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
||||
every { appSettingsService.isItemCachingEnabled() } returns true
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag>? = null
|
||||
@ -330,6 +332,7 @@ class RepositoryTest() {
|
||||
coEvery { api.tags() } returns SelfossModel.StatusAndData(success = true, data = tags)
|
||||
AmineB marked this conversation as resolved
Outdated
|
||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
||||
AmineB marked this conversation as resolved
AmineB
commented
The network is available, so this will be called. And the next one won't. The network is available, so this will be called. And the next one won't.
davidoskky
commented
If update_sources handles tag fetching then it shouldn't. If update_sources handles tag fetching then it shouldn't.
Maybe it would be better to rename update_sources so that it becomes more clear that it handles tags as well?
I do get confused at times.
AmineB
commented
The setting name IS confusing. But but it handles the tags/sources caching. The setting name IS confusing. But but it handles the tags/sources caching.
|
||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||
every { appSettingsService.isItemCachingEnabled() } returns true
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
@ -378,6 +381,8 @@ class RepositoryTest() {
|
||||
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 true
|
||||
every { appSettingsService.isItemCachingEnabled() } returns true
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
@ -386,7 +391,7 @@ class RepositoryTest() {
|
||||
}
|
||||
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.
|
||||
|
||||
assertNotSame(tags, testTags)
|
||||
assertSame(tagsDB.first().name, testTags.first().tag)
|
||||
assertContentEquals(tagsDB.map { it.toView() }, testTags)
|
||||
coVerify(exactly = 0) { api.tags() }
|
||||
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
@ -402,6 +407,7 @@ class RepositoryTest() {
|
||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
||||
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||
every { appSettingsService.isUpdateSourcesEnabled() } returns true
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
@ -425,6 +431,7 @@ class RepositoryTest() {
|
||||
coEvery { db.tagsQueries.tags().executeAsList() } returns tagsDB
|
||||
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||
every { appSettingsService.isItemCachingEnabled() } returns true
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
|
Same here, the two values are different in the initialization, they couldn't be the same after.
I would expect tags to be fetched from the database, since the api should not be used.
The network is available. The api call will be done. update_sources handles the tags/sources caching.