get sources tests
This commit is contained in:
parent
758708e18d
commit
ef994460c1
@ -148,6 +148,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Add tests
|
||||||
suspend fun getSpouts(): Map<String, SelfossModel.Spout>? {
|
suspend fun getSpouts(): Map<String, SelfossModel.Spout>? {
|
||||||
return if (isNetworkAvailable()) {
|
return if (isNetworkAvailable()) {
|
||||||
api.spouts()
|
api.spouts()
|
||||||
|
@ -2,20 +2,19 @@ package bou.amine.apps.readerforselfossv2.repository
|
|||||||
|
|
||||||
import bou.amine.apps.readerforselfossv2.dao.ITEM
|
import bou.amine.apps.readerforselfossv2.dao.ITEM
|
||||||
import bou.amine.apps.readerforselfossv2.dao.ReaderForSelfossDB
|
import bou.amine.apps.readerforselfossv2.dao.ReaderForSelfossDB
|
||||||
|
import bou.amine.apps.readerforselfossv2.dao.SOURCE
|
||||||
import bou.amine.apps.readerforselfossv2.dao.TAG
|
import bou.amine.apps.readerforselfossv2.dao.TAG
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.rest.SelfossApi
|
import bou.amine.apps.readerforselfossv2.rest.SelfossApi
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
import bou.amine.apps.readerforselfossv2.utils.ItemType
|
import bou.amine.apps.readerforselfossv2.utils.ItemType
|
||||||
import bou.amine.apps.readerforselfossv2.utils.toEntity
|
import bou.amine.apps.readerforselfossv2.utils.toEntity
|
||||||
|
import bou.amine.apps.readerforselfossv2.utils.toView
|
||||||
import com.github.ln_12.library.ConnectivityStatus
|
import com.github.ln_12.library.ConnectivityStatus
|
||||||
import io.mockk.*
|
import io.mockk.*
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlin.test.BeforeTest
|
import kotlin.test.*
|
||||||
import kotlin.test.Test
|
|
||||||
import kotlin.test.assertNotSame
|
|
||||||
import kotlin.test.assertSame
|
|
||||||
|
|
||||||
class RepositoryTest() {
|
class RepositoryTest() {
|
||||||
private val connectivityStatus = mockk<ConnectivityStatus>()
|
private val connectivityStatus = mockk<ConnectivityStatus>()
|
||||||
@ -397,6 +396,109 @@ class RepositoryTest() {
|
|||||||
coVerify(exactly = 0) { api.tags() }
|
coVerify(exactly = 0) { api.tags() }
|
||||||
verify(exactly = 0) { db.tagsQueries.tags().executeAsList() }
|
verify(exactly = 0) { db.tagsQueries.tags().executeAsList() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `get sources`() {
|
||||||
|
val sources = arrayListOf(SelfossModel.Source(1, "First source", listOf("Test", "second"),"spouts\\rss\\fulltextrss", "", "d8c92cdb1ef119ea85c4b9205c879ca7.png"),
|
||||||
|
SelfossModel.Source(2, "Second source", listOf("second"),"spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png"))
|
||||||
|
|
||||||
|
coEvery { api.sources() } returns sources
|
||||||
|
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||||
|
var testSources: List<SelfossModel.Source>? = null
|
||||||
|
runBlocking {
|
||||||
|
testSources = repository.getSources()
|
||||||
|
}
|
||||||
|
|
||||||
|
assertSame(sources, testSources)
|
||||||
|
coVerify(exactly = 1) { api.sources() }
|
||||||
|
verify(exactly = 0) { db.sourcesQueries.sources().executeAsList() }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `get sources without connection`() {
|
||||||
|
val sources = arrayListOf(SelfossModel.Source(1, "First source", listOf("Test", "second"),"spouts\\rss\\fulltextrss", "", "d8c92cdb1ef119ea85c4b9205c879ca7.png"),
|
||||||
|
SelfossModel.Source(2, "Second source", listOf("second"),"spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png"))
|
||||||
|
val sourcesDB = listOf<SOURCE>(SOURCE("1", "First source", "Test,second","spouts\\rss\\fulltextrss", "", "d8c92cdb1ef119ea85c4b9205c879ca7.png"),
|
||||||
|
SOURCE("2", "Second source", "second","spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png"))
|
||||||
|
|
||||||
|
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
||||||
|
coEvery { api.sources() } returns sources
|
||||||
|
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
||||||
|
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||||
|
var testSources: List<SelfossModel.Source>? = null
|
||||||
|
runBlocking {
|
||||||
|
testSources = repository.getSources()
|
||||||
|
}
|
||||||
|
|
||||||
|
assertContentEquals(sources, testSources)
|
||||||
|
coVerify(exactly = 0) { api.sources() }
|
||||||
|
verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `get sources without connection and items caching disabled`() {
|
||||||
|
val sources = arrayListOf(SelfossModel.Source(1, "First source", listOf("Test", "second"),"spouts\\rss\\fulltextrss", "", "d8c92cdb1ef119ea85c4b9205c879ca7.png"),
|
||||||
|
SelfossModel.Source(2, "Second source", listOf("second"),"spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png"))
|
||||||
|
val sourcesDB = listOf<SOURCE>(SOURCE("1", "First source", "Test,second","spouts\\rss\\fulltextrss", "", "d8c92cdb1ef119ea85c4b9205c879ca7.png"),
|
||||||
|
SOURCE("2", "Second source", "second","spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png"))
|
||||||
|
|
||||||
|
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
||||||
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
|
coEvery { api.sources() } returns sources
|
||||||
|
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
||||||
|
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||||
|
var testSources: List<SelfossModel.Source>? = null
|
||||||
|
runBlocking {
|
||||||
|
testSources = repository.getSources()
|
||||||
|
}
|
||||||
|
|
||||||
|
assertSame(null, testSources)
|
||||||
|
coVerify(exactly = 0) { api.sources() }
|
||||||
|
verify(exactly = 0) { db.sourcesQueries.sources().executeAsList() }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `get sources with sources update disabled`() {
|
||||||
|
val sources = arrayListOf(SelfossModel.Source(1, "First source", listOf("Test", "second"),"spouts\\rss\\fulltextrss", "", "d8c92cdb1ef119ea85c4b9205c879ca7.png"),
|
||||||
|
SelfossModel.Source(2, "Second source", listOf("second"),"spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png"))
|
||||||
|
val sourcesDB = listOf<SOURCE>(SOURCE("1", "First source", "Test,second","spouts\\rss\\fulltextrss", "", "d8c92cdb1ef119ea85c4b9205c879ca7.png"),
|
||||||
|
SOURCE("2", "Second source", "second","spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png"))
|
||||||
|
|
||||||
|
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||||
|
coEvery { api.sources() } returns sources
|
||||||
|
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
||||||
|
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||||
|
var testSources: List<SelfossModel.Source>? = null
|
||||||
|
runBlocking {
|
||||||
|
testSources = repository.getSources()
|
||||||
|
}
|
||||||
|
|
||||||
|
assertContentEquals(sources, testSources)
|
||||||
|
coVerify(exactly = 0) { api.sources() }
|
||||||
|
verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `get sources with sources update and items caching disabled`() {
|
||||||
|
val sources = arrayListOf(SelfossModel.Source(1, "First source", listOf("Test", "second"),"spouts\\rss\\fulltextrss", "", "d8c92cdb1ef119ea85c4b9205c879ca7.png"),
|
||||||
|
SelfossModel.Source(2, "Second source", listOf("second"),"spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png"))
|
||||||
|
val sourcesDB = listOf<SOURCE>(SOURCE("1", "First source", "Test,second","spouts\\rss\\fulltextrss", "", "d8c92cdb1ef119ea85c4b9205c879ca7.png"),
|
||||||
|
SOURCE("2", "Second source", "second","spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png"))
|
||||||
|
|
||||||
|
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||||
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
|
coEvery { api.sources() } returns sources
|
||||||
|
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
||||||
|
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||||
|
var testSources: List<SelfossModel.Source>? = null
|
||||||
|
runBlocking {
|
||||||
|
testSources = repository.getSources()
|
||||||
|
}
|
||||||
|
|
||||||
|
assertSame(null, testSources)
|
||||||
|
coVerify(exactly = 0) { api.sources() }
|
||||||
|
verify(exactly = 0) { db.sourcesQueries.sources().executeAsList() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateTestDBItems(item : FakeItemParameters = FakeItemParameters()) : List<ITEM> {
|
fun generateTestDBItems(item : FakeItemParameters = FakeItemParameters()) : List<ITEM> {
|
||||||
|
Loading…
Reference in New Issue
Block a user