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
Showing only changes of commit bf6f1a917e - Show all commits

View File

@ -594,6 +594,49 @@ class RepositoryTest() {
coVerify(exactly = 0) { api.deleteSource(5) }
assertSame(false, response)
}
@Test
fun `update remote`() {
coEvery { api.update()} returns SelfossModel.StatusAndData(success = true, data = "finished")
val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false
runBlocking {
response = repository.updateRemote()
AmineB marked this conversation as resolved Outdated

Update remote should be changed to.

    suspend fun updateRemote(): Boolean {
        return if (isNetworkAvailable()) {
            api.update().data.equals("finished")
        } else {
            false
        }
    }
Update remote should be changed to. ``` suspend fun updateRemote(): Boolean { return if (isNetworkAvailable()) { api.update().data.equals("finished") } else { false } } ```
}
coVerify(exactly = 1) { api.update() }
assertSame(true, response)
}
@Test
fun `update remote but response fails`() {
coEvery { api.update()} returns SelfossModel.StatusAndData(success = false, data = "undocumented...")
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 without connection`() {
coEvery { api.update()} returns SelfossModel.StatusAndData(success = true, data = "undocumented...")
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false
runBlocking {
response = repository.updateRemote()
}
coVerify(exactly = 0) { api.update() }
assertSame(false, response)
}
}
fun generateTestDBItems(item : FakeItemParameters = FakeItemParameters()) : List<ITEM> {