Test login

This commit is contained in:
davidoskky 2022-09-26 22:46:37 +02:00
parent bf6f1a917e
commit f46f98cef0

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> {