Repository Unit Tests #50

Merged
AmineB merged 38 commits from davidoskky/ReaderForSelfoss-multiplatform:repository_tests into master 2022-09-30 11:31:55 +00:00
2 changed files with 6 additions and 12 deletions
Showing only changes of commit 6f60ef4346 - Show all commits
6
@@ -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
Outdated
Review

I think that the DB handles the duplicates.

I think that the DB handles the duplicates.
Outdated
Review

Does it use the id to check for duplicates? If that is the case then all is good.

Does it use the id to check for duplicates? If that is the case then all is good.
suspend fun tryToCacheItemsAndGetNewOnes(): List<SelfossModel.Item> {
suspend fun tryToCacheItemsAndGetNewOnes() {
try {
val newItems = getMaxItemsForBackground(ItemType.UNREAD)
AmineB marked this conversation as resolved Outdated
Outdated
Review

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
Outdated
Review

As the function name describes, this must only return the new items.

As the function name describes, this must only return the new items.
Outdated
Review

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
57
@@ -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)
}
}