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 17 additions and 3 deletions
Showing only changes of commit 7211fdb1a3 - Show all commits

View File

@ -352,7 +352,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
suspend fun updateRemote(): Boolean {
return if (isNetworkAvailable()) {
api.update().equals("finished")
api.update().data.equals("finished")
} else {
false
}

View File

@ -718,12 +718,26 @@ class RepositoryTest() {
}
AmineB marked this conversation as resolved Outdated

tryToCacheItemsAndGetNewOnes will only return 1 item as it only returns new items.

You will also need to add every { db.itemsQueries.transaction(any(), any()) } returns Unit to the setup.

`tryToCacheItemsAndGetNewOnes` will only return `1` item as it only returns new items. You will also need to add `every { db.itemsQueries.transaction(any(), any()) } returns Unit` to the setup.
coVerify(exactly = 1) { api.update() }
assertSame(true, response)
assertTrue(response)
}
@Test
fun `update remote but response fails`() {
coEvery { api.update()} returns SelfossModel.StatusAndData(success = false, data = "undocumented...")
coEvery { api.update()} returns SelfossModel.StatusAndData(success = false, data = "unallowed access")
val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false
runBlocking {
response = repository.updateRemote()
}
coVerify(exactly = 1) { api.update() }
assertSame(false, response)
}
@Test
fun `update remote with unallowed access`() {
coEvery { api.update()} returns SelfossModel.StatusAndData(success = true, data = "unallowed access")
val repository = Repository(api, appSettingsService, connectivityStatus, db)
AmineB marked this conversation as resolved Outdated

This should be coVerify(exactly = 3) { api.getItems(any(), 0, "Tag", 1, "search", null, 200) }

This should be `coVerify(exactly = 3) { api.getItems(any(), 0, "Tag", 1, "search", null, 200) }`

As above

As above

As above.

I don't know what you wanted to test.

The thing is, passing null, null, null, null in the function will make it fail, because in your calls, you pass data.

As above. I don't know what you wanted to test. The thing is, passing null, null, null, null in the function will make it fail, because in your calls, you pass data.
var response = false