From 63c550ead38c689ccefb4f5c87a48cf3cd810351 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Mon, 26 Sep 2022 22:21:48 +0200 Subject: [PATCH] Test create source --- .../repository/RepositoryImpl.kt | 6 ++- .../repository/RepositoryTest.kt | 46 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt index 65fbfbe..22d9a7f 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt @@ -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): Boolean { var success = false diff --git a/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt b/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt index 73f6cb0..34891bf 100644 --- a/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt +++ b/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt @@ -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 {