This commit is contained in:
@ -692,6 +692,82 @@ class RepositoryTest() {
|
||||
coVerify(exactly = 1) { api.refreshLoginInformation() }
|
||||
coVerify(exactly = 1) {appSettingsService.refreshLoginInformation("https://test.com/selfoss/", "login", "password")}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cache items`() {
|
||||
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
|
||||
SelfossModel.StatusAndData(success = true, data = generateTestApiItem())
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
repository.tagFilter = SelfossModel.Tag("Tag", "read", 0)
|
||||
repository.sourceFilter = SelfossModel.Source(
|
||||
1,
|
||||
"First source",
|
||||
listOf("Test", "second"),
|
||||
"spouts\\rss\\fulltextrss",
|
||||
"",
|
||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
||||
)
|
||||
repository.searchFilter = "search"
|
||||
var items = emptyList<SelfossModel.Item>()
|
||||
runBlocking {
|
||||
items = repository.tryToCacheItemsAndGetNewOnes()
|
||||
}
|
||||
|
||||
coVerify(exactly = 3) { api.getItems(any(), 0, null, null, null, null, 200) }
|
||||
assertSame(3, items.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cache items but response fails`() {
|
||||
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
|
||||
SelfossModel.StatusAndData(success = false, data = generateTestApiItem())
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
repository.tagFilter = SelfossModel.Tag("Tag", "read", 0)
|
||||
repository.sourceFilter = SelfossModel.Source(
|
||||
1,
|
||||
"First source",
|
||||
listOf("Test", "second"),
|
||||
"spouts\\rss\\fulltextrss",
|
||||
"",
|
||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
||||
)
|
||||
repository.searchFilter = "search"
|
||||
var items = emptyList<SelfossModel.Item>()
|
||||
runBlocking {
|
||||
items = repository.tryToCacheItemsAndGetNewOnes()
|
||||
}
|
||||
|
||||
coVerify(exactly = 3) { api.getItems(any(), 0, null, null, null, null, 200) }
|
||||
assertSame(0, items.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cache items without connection`() {
|
||||
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
|
||||
SelfossModel.StatusAndData(success = false, data = generateTestApiItem())
|
||||
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
||||
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
repository.tagFilter = SelfossModel.Tag("Tag", "read", 0)
|
||||
repository.sourceFilter = SelfossModel.Source(
|
||||
1,
|
||||
"First source",
|
||||
listOf("Test", "second"),
|
||||
"spouts\\rss\\fulltextrss",
|
||||
"",
|
||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
||||
)
|
||||
repository.searchFilter = "search"
|
||||
var items = emptyList<SelfossModel.Item>()
|
||||
runBlocking {
|
||||
items = repository.tryToCacheItemsAndGetNewOnes()
|
||||
}
|
||||
|
||||
coVerify(exactly = 0) { api.getItems(any(), 0, null, null, null, null, 200) }
|
||||
assertSame(emptyList<SelfossModel.Item>(), items)
|
||||
}
|
||||
}
|
||||
|
||||
fun generateTestDBItems(item : FakeItemParameters = FakeItemParameters()) : List<ITEM> {
|
||||
|
Reference in New Issue
Block a user