Repository Unit Tests #50
@ -456,17 +456,16 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
||||
db.itemsQueries.updateItem(item.datetime, item.title.getHtmlDecoded(), item.content, item.unread, item.starred, item.thumbnail, item.icon, item.link, item.sourcetitle, item.tags.joinToString(","), item.id.toString())
|
||||
|
||||
// TODO: This function should check for duplicate items
|
||||
AmineB marked this conversation as resolved
Outdated
|
||||
suspend fun tryToCacheItemsAndGetNewOnes(): List<SelfossModel.Item> {
|
||||
suspend fun tryToCacheItemsAndGetNewOnes() {
|
||||
try {
|
||||
val newItems = getMaxItemsForBackground(ItemType.UNREAD)
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
This is useless. This is useless.
|
||||
val allItems = getMaxItemsForBackground(ItemType.ALL)
|
||||
val starredItems = getMaxItemsForBackground(ItemType.STARRED)
|
||||
insertDBItems(newItems + allItems + starredItems)
|
||||
return newItems
|
||||
val fullItemsList = newItems + allItems + starredItems
|
||||
AmineB
commented
As the function name describes, this must only return the new items. As the function name describes, this must only return the new items.
davidoskky
commented
Ops, you're right I made a mistake while changing things... Ops, you're right I made a mistake while changing things...
|
||||
insertDBItems(fullItemsList)
|
||||
} catch (e: Throwable) {
|
||||
// We do nothing
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
// TODO: Add tests
|
||||
|
@ -899,9 +899,8 @@ class RepositoryTest() {
|
||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
||||
)
|
||||
repository.searchFilter = "search"
|
||||
var items = emptyList<SelfossModel.Item>()
|
||||
runBlocking {
|
||||
items = repository.tryToCacheItemsAndGetNewOnes()
|
||||
repository.tryToCacheItemsAndGetNewOnes()
|
||||
}
|
||||
|
||||
coVerify(exactly = 3) { api.getItems(any(), 0, null, null, null, null, 200) }
|
||||
@ -923,13 +922,11 @@ class RepositoryTest() {
|
||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
||||
)
|
||||
repository.searchFilter = "search"
|
||||
var items = emptyList<SelfossModel.Item>()
|
||||
runBlocking {
|
||||
items = repository.tryToCacheItemsAndGetNewOnes()
|
||||
repository.tryToCacheItemsAndGetNewOnes()
|
||||
}
|
||||
|
||||
coVerify(exactly = 3) { api.getItems(any(), 0, null, null, null, null, 200) }
|
||||
assertSame(0, items.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -949,13 +946,11 @@ class RepositoryTest() {
|
||||
"d8c92cdb1ef119ea85c4b9205c879ca7.png"
|
||||
)
|
||||
repository.searchFilter = "search"
|
||||
var items = emptyList<SelfossModel.Item>()
|
||||
runBlocking {
|
||||
items = repository.tryToCacheItemsAndGetNewOnes()
|
||||
repository.tryToCacheItemsAndGetNewOnes()
|
||||
}
|
||||
|
||||
coVerify(exactly = 0) { api.getItems(any(), 0, null, null, null, null, 200) }
|
||||
assertSame(emptyList<SelfossModel.Item>(), items)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
I think that the DB handles the duplicates.
Does it use the id to check for duplicates? If that is the case then all is good.