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