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 f46f98cef0 - Show all commits

View File

@ -637,6 +637,49 @@ class RepositoryTest() {
coVerify(exactly = 0) { api.update() }
assertSame(false, response)
}
@Test
fun login() {
coEvery { api.login() } returns SelfossModel.SuccessResponse(success = true)
val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false
runBlocking {
response = repository.login()
}
coVerify(exactly = 1) { api.login() }
assertSame(true, response)
}
@Test
fun `login but response fails`() {
coEvery { api.login() } returns SelfossModel.SuccessResponse(success = false)
val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false
runBlocking {
response = repository.login()
}
coVerify(exactly = 1) { api.login() }
assertSame(false, response)
}
@Test
fun `login but without connection`() {
coEvery { api.login() } returns SelfossModel.SuccessResponse(success = true)
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false
runBlocking {
response = repository.login()
}
coVerify(exactly = 0) { api.login() }
assertSame(false, response)
}
}
fun generateTestDBItems(item : FakeItemParameters = FakeItemParameters()) : List<ITEM> {