Correctly implement disabling sources update
This commit is contained in:
@ -342,12 +342,35 @@ class RepositoryTest() {
|
||||
testTags = repository.getTags()
|
||||
}
|
||||
|
||||
coVerify(exactly = 1) { api.tags() }
|
||||
assertNotSame(tags, testTags)
|
||||
assertContentEquals(tagsDB.map { it.toView() }, testTags)
|
||||
coVerify(exactly = 1) { api.tags() }
|
||||
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Get tags with items caching 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 { appSettingsService.isUpdateSourcesEnabled() } returns true
|
||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
runBlocking {
|
||||
testTags = repository.getTags()
|
||||
}
|
||||
|
||||
assertSame(tags, testTags)
|
||||
coVerify(exactly = 1) { api.tags() }
|
||||
verify(exactly = 0) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Get tags with sources update and items caching disabled`() {
|
||||
val tags = listOf(SelfossModel.Tag("test", "red", 6),
|
||||
@ -364,11 +387,13 @@ class RepositoryTest() {
|
||||
var testTags: List<SelfossModel.Tag> = emptyList()
|
||||
runBlocking {
|
||||
testTags = repository.getTags()
|
||||
testTags = repository.getTags()
|
||||
}
|
||||
|
||||
assertSame(tags, testTags)
|
||||
coVerify(exactly = 1) { api.tags() }
|
||||
verify(exactly = 0) { db.tagsQueries.tags().executeAsList() }
|
||||
assertNotSame(tags, testTags)
|
||||
assertContentEquals(tagsDB.map { it.toView() }, testTags)
|
||||
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -415,9 +440,9 @@ class RepositoryTest() {
|
||||
testTags = repository.getTags()
|
||||
}
|
||||
|
||||
assertContentEquals(tagsDB.map { it.toView() }, testTags)
|
||||
assertSame(emptyList(), testTags)
|
||||
coVerify(exactly = 0) { api.tags() }
|
||||
verify(atLeast = 1) { db.tagsQueries.tags().executeAsList() }
|
||||
verify(exactly = 0) { db.tagsQueries.tags().executeAsList() }
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -464,9 +489,9 @@ class RepositoryTest() {
|
||||
testTags = repository.getTags()
|
||||
}
|
||||
|
||||
assertSame(emptyList(), 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
|
||||
@ -497,6 +522,7 @@ class RepositoryTest() {
|
||||
SOURCE("2", "Second source", "second","spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png"))
|
||||
|
||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||
every { appSettingsService.isItemCachingEnabled() } returns true
|
||||
coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources)
|
||||
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
@ -507,12 +533,34 @@ class RepositoryTest() {
|
||||
testSources = repository.getSources()
|
||||
}
|
||||
|
||||
coVerify(exactly = 1) { api.sources() }
|
||||
assertNotSame(sources, testSources)
|
||||
assertContentEquals(sourcesDB.map { it.toView() }, testSources)
|
||||
coVerify(exactly = 1) { api.sources() }
|
||||
verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get sources with 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 true
|
||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||
coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = 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(sources, testSources)
|
||||
coVerify(exactly = 1) { api.sources() }
|
||||
verify(exactly = 0) { db.sourcesQueries }
|
||||
}
|
||||
|
||||
@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"),
|
||||
@ -532,7 +580,7 @@ class RepositoryTest() {
|
||||
|
||||
assertSame(sources, testSources)
|
||||
coVerify(exactly = 1) { api.sources() }
|
||||
verify(exactly = 0) { db.sourcesQueries.sources().executeAsList() }
|
||||
verify(atLeast = 1) { db.sourcesQueries }
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -574,9 +622,9 @@ class RepositoryTest() {
|
||||
testSources = repository.getSources()
|
||||
}
|
||||
|
||||
assertContentEquals(sourcesDB.map { it.toView() }, testSources)
|
||||
assertContentEquals(ArrayList(), testSources)
|
||||
coVerify(exactly = 0) { api.sources() }
|
||||
verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() }
|
||||
verify(exactly = 0) { db.sourcesQueries.sources().executeAsList() }
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -620,9 +668,9 @@ class RepositoryTest() {
|
||||
testSources = repository.getSources()
|
||||
}
|
||||
|
||||
assertContentEquals(ArrayList(), testSources)
|
||||
assertContentEquals(sourcesDB.map { it.toView() }, testSources)
|
||||
coVerify(exactly = 0) { api.sources() }
|
||||
verify(exactly = 0) { db.sourcesQueries.sources().executeAsList() }
|
||||
verify(atLeast = 1) { db.sourcesQueries.sources().executeAsList() }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user