Use /sources/stats in the home #133

Merged
AmineB merged 9 commits from davidoskky/ReaderForSelfoss-multiplatform:sources into master 2023-03-13 16:26:57 +00:00
Showing only changes of commit bb45820ae8 - Show all commits

View File

@ -303,6 +303,7 @@ class RepositoryTest {
repository.setSourceFilter(SelfossModel.Source(
1,
"Test",
0,
listOf("tags"),
SPOUT,
"",
@ -609,19 +610,19 @@ class RepositoryTest {
fun get_sources() {
val (sources, sourcesDB) = prepareSources()
initializeRepository()
var testSources: List<SelfossModel.Source>?
var testSources: List<SelfossModel.Source>
runBlocking {
testSources = repository.getSources()
testSources = repository.getSourcesDetails()
}
assertSame(sources, testSources)
assertEquals(sources.map { SelfossModel.Source(it) }, testSources)
assertNotEquals(sourcesDB.map { it.toView() }, testSources)
coVerify(exactly = 1) { api.sources() }
coVerify(exactly = 1) { api.sourcesDetailed() }
}
private fun prepareSources(): Pair<ArrayList<SelfossModel.Source>, List<SOURCE>> {
private fun prepareSources(): Pair<ArrayList<SelfossModel.SourceDetail>, List<SOURCE>> {
val sources = arrayListOf(
SelfossModel.Source(
SelfossModel.SourceDetail(
1,
"First source",
listOf("Test", "second"),
@ -630,7 +631,7 @@ class RepositoryTest {
IMAGE_URL_2,
SelfossModel.SourceParams("url")
),
SelfossModel.Source(
SelfossModel.SourceDetail(
2,
"Second source",
listOf("second"),
@ -644,6 +645,7 @@ class RepositoryTest {
SOURCE(
"1",
"First DB source",
3,
"Test,second",
SPOUT,
"",
@ -653,6 +655,7 @@ class RepositoryTest {
SOURCE(
"2",
"Second source",
null,
"second",
SPOUT,
"",
@ -661,7 +664,7 @@ class RepositoryTest {
)
)
coEvery { api.sources() } returns StatusAndData(success = true, data = sources)
coEvery { api.sourcesDetailed() } returns StatusAndData(success = true, data = sources)
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
return Pair(sources, sourcesDB)
}
@ -675,13 +678,13 @@ class RepositoryTest {
initializeRepository()
var testSources: List<SelfossModel.Source>?
runBlocking {
testSources = repository.getSources()
testSources = repository.getSourcesDetails()
// Sources will be fetched from the database on the second call, thus testSources != sources
testSources = repository.getSources()
testSources = repository.getSourcesDetails()
}
coVerify(exactly = 1) { api.sources() }
assertNotSame(sources, testSources)
coVerify(exactly = 1) { api.sourcesDetailed() }
assertNotEquals(sources.map { SelfossModel.Source(it) }, testSources)
assertEquals(sourcesDB.map { it.toView() }, testSources)
verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() }
}
@ -693,13 +696,13 @@ class RepositoryTest {
every { appSettingsService.isUpdateSourcesEnabled() } returns true
every { appSettingsService.isItemCachingEnabled() } returns false
initializeRepository()
var testSources: List<SelfossModel.Source>?
var testSources: List<SelfossModel.Source>
runBlocking {
testSources = repository.getSources()
testSources = repository.getSourcesDetails()
}
assertSame(sources, testSources)
coVerify(exactly = 1) { api.sources() }
assertEquals(sources.map { SelfossModel.Source(it) }, testSources)
coVerify(exactly = 1) { api.sourcesDetailed() }
verify(exactly = 0) { db.sourcesQueries }
}
@ -710,13 +713,13 @@ class RepositoryTest {
every { appSettingsService.isUpdateSourcesEnabled() } returns false
every { appSettingsService.isItemCachingEnabled() } returns false
initializeRepository()
var testSources: List<SelfossModel.Source>?
var testSources: List<SelfossModel.Source>
runBlocking {
testSources = repository.getSources()
testSources = repository.getSourcesDetails()
}
assertSame(sources, testSources)
coVerify(exactly = 1) { api.sources() }
assertEquals(sources.map { SelfossModel.Source(it) }, testSources)
coVerify(exactly = 1) { api.sourcesDetailed() }
verify(atLeast = 1) { db.sourcesQueries }
}
@ -724,13 +727,13 @@ class RepositoryTest {
fun get_sources_without_connection() {
val (_, sourcesDB) = prepareSources()
initializeRepository(MutableStateFlow(false))
var testSources: List<SelfossModel.Source>?
var testSources: List<SelfossModel.Source>
runBlocking {
testSources = repository.getSources()
testSources = repository.getSourcesDetails()
}
assertEquals(sourcesDB.map { it.toView() }, testSources)
coVerify(exactly = 0) { api.sources() }
coVerify(exactly = 0) { api.sourcesDetailed() }
verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() }
}
@ -741,13 +744,13 @@ class RepositoryTest {
every { appSettingsService.isItemCachingEnabled() } returns false
every { appSettingsService.isUpdateSourcesEnabled() } returns true
initializeRepository(MutableStateFlow(false))
var testSources: List<SelfossModel.Source>?
var testSources: List<SelfossModel.Source>
runBlocking {
testSources = repository.getSources()
testSources = repository.getSourcesDetails()
}
assertEquals(emptyList<SelfossModel.Source>(), testSources)
coVerify(exactly = 0) { api.sources() }
coVerify(exactly = 0) { api.sourcesDetailed() }
verify(exactly = 0) { db.sourcesQueries.sources().executeAsList() }
}
@ -758,13 +761,13 @@ class RepositoryTest {
every { appSettingsService.isItemCachingEnabled() } returns true
every { appSettingsService.isUpdateSourcesEnabled() } returns false
initializeRepository(MutableStateFlow(false))
var testSources: List<SelfossModel.Source>?
var testSources: List<SelfossModel.Source>
runBlocking {
testSources = repository.getSources()
testSources = repository.getSourcesDetails()
}
assertEquals(sourcesDB.map { it.toView() }, testSources)
coVerify(exactly = 0) { api.sources() }
coVerify(exactly = 0) { api.sourcesDetailed() }
verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() }
}
@ -775,13 +778,13 @@ class RepositoryTest {
every { appSettingsService.isItemCachingEnabled() } returns false
every { appSettingsService.isUpdateSourcesEnabled() } returns false
initializeRepository(MutableStateFlow(false))
var testSources: List<SelfossModel.Source>?
var testSources: List<SelfossModel.Source>
runBlocking {
testSources = repository.getSources()
testSources = repository.getSourcesDetails()
}
assertEquals(sourcesDB.map { it.toView() }, testSources)
coVerify(exactly = 0) { api.sources() }
coVerify(exactly = 0) { api.sourcesDetailed() }
verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() }
}
@ -1105,6 +1108,7 @@ class RepositoryTest {
SelfossModel.Source(
1,
"First source",
5,
listOf("Test", "second"),
SPOUT,
"",