Repository Unit Tests #50
@ -8,6 +8,7 @@ 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
|
||||
@ -345,19 +346,20 @@ class RepositoryTest() {
|
||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag>? = null
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
runBlocking {
|
||||
testTags = repository.getTags()
|
||||
testTags = repository.getTags()
|
||||
AmineB marked this conversation as resolved
Outdated
|
||||
}
|
||||
|
||||
assertNotSame(tags, testTags)
|
||||
assertSame(tagsDB.first().name, testTags?.first()?.tag)
|
||||
coVerify(exactly = 0) { api.tags() }
|
||||
assertContentEquals(tagsDB.map { it.toView() }, testTags)
|
||||
coVerify(exactly = 1) { api.tags() }
|
||||
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Get tags with sources update and db disabled`() {
|
||||
fun `Get tags with sources update and items caching disabled`() {
|
||||
val tags = listOf(SelfossModel.Tag("test", "red", 6),
|
||||
SelfossModel.Tag("second", "yellow", 0))
|
||||
val tagsDB = listOf(TAG("test_DB", "red", 6),
|
||||
@ -369,12 +371,12 @@ class RepositoryTest() {
|
||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag>? = null
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
runBlocking {
|
||||
testTags = repository.getTags()
|
||||
}
|
||||
|
||||
assertSame(null, testTags)
|
||||
assertSame(emptyList(), testTags)
|
||||
coVerify(exactly = 0) { api.tags() }
|
||||
verify(exactly = 0) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
@ -415,14 +417,38 @@ class RepositoryTest() {
|
||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag>? = null
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
runBlocking {
|
||||
testTags = repository.getTags()
|
||||
}
|
||||
|
||||
assertSame(null, testTags)
|
||||
assertContentEquals(tagsDB.map { it.toView() }, testTags)
|
||||
coVerify(exactly = 0) { api.tags() }
|
||||
verify(exactly = 0) { db.tagsQueries.tags().executeAsList() }
|
||||
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()
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
The same comments about The same comments about `Get tags without connection and items caching disabled` should be considered here.
|
||||
}
|
||||
|
||||
assertNotSame(tags, testTags)
|
||||
assertContentEquals(tagsDB.map { it.toView() }, testTags)
|
||||
coVerify(exactly = 0) { api.tags() }
|
||||
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user
Why is this called twice ?
To test that api.tags() gets called only once regardless of how many calls are made to the repository.