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 51 additions and 1 deletions
Showing only changes of commit 63c550ead3 - Show all commits

View File

@ -181,6 +181,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
}
}
// TODO: Add tests
suspend fun markAsRead(item: SelfossModel.Item): Boolean {
val success = markAsReadById(item.id)
@ -199,7 +200,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
}
}
// TODO: Add tests
suspend fun unmarkAsRead(item: SelfossModel.Item): Boolean {
val success = unmarkAsReadById(item.id)
@ -218,6 +219,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
}
}
// TODO: Add tests
suspend fun starr(item: SelfossModel.Item): Boolean {
val success = starrById(item.id)
@ -236,6 +238,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
}
}
// TODO: Add tests
suspend fun unstarr(item: SelfossModel.Item): Boolean {
val success = unstarrById(item.id)
@ -254,6 +257,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
}
}
// TODO: Add tests
suspend fun markAllAsRead(items: ArrayList<SelfossModel.Item>): Boolean {
var success = false

View File

@ -505,6 +505,52 @@ class RepositoryTest() {
coVerify(exactly = 0) { api.sources() }
verify(exactly = 0) { db.sourcesQueries.sources().executeAsList() }
}
@Test
fun `create source`() {
coEvery { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) } returns
SelfossModel.SuccessResponse(true)
val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false
runBlocking {
response = repository.createSource("test", "https://test.com/feed", "spouts\\rss\\fulltextrss", "Test, New", "")
}
coVerify(exactly = 1) { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) }
assertSame(true, response)
}
@Test
fun `create source but response fails`() {
coEvery { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) } returns
SelfossModel.SuccessResponse(false)
val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false
runBlocking {
response = repository.createSource("test", "https://test.com/feed", "spouts\\rss\\fulltextrss", "Test, New", "")
}
coVerify(exactly = 1) { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) }
assertSame(false, response)
}
@Test
fun `create source without connection`() {
coEvery { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) } returns
SelfossModel.SuccessResponse(true)
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false
runBlocking {
response = repository.createSource("test", "https://test.com/feed", "spouts\\rss\\fulltextrss", "Test, New", "")
}
coVerify(exactly = 0) { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) }
assertSame(false, response)
}
}
fun generateTestDBItems(item : FakeItemParameters = FakeItemParameters()) : List<ITEM> {