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 71c0a4d340 - Show all commits

View File

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