From 2968aee3094a83b0a34e05da6d4eb146f54ada4d Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 28 Sep 2022 09:43:28 +0200 Subject: [PATCH] Fix badges tests --- .../repository/RepositoryImpl.kt | 5 +++-- .../repository/RepositoryTest.kt | 21 ++++++------------- 2 files changed, 9 insertions(+), 17 deletions(-) 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 bb2519e..f235771 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 @@ -132,12 +132,13 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap badgeStarred = response.data.starred success = true } - } else { + } else if (appSettingsService.isItemCachingEnabled()) { // TODO: do this differently, because it's not efficient val dbItems = getDBItems() badgeUnread = dbItems.filter { item -> item.unread }.size badgeStarred = dbItems.filter { item -> item.starred }.size - badgeAll = items.size + badgeAll = dbItems.size + success = true } return success } 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 d2c9044..094def3 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 @@ -31,7 +31,7 @@ class RepositoryTest() { every { appSettingsService.getApiVersion() } returns 4 every { appSettingsService.getBaseUrl() } returns "https://test.com/selfoss/" every { appSettingsService.isItemCachingEnabled() } returns false - every { appSettingsService.isUpdateSourcesEnabled() } returns true + every { appSettingsService.isUpdateSourcesEnabled() } returns false every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(true) @@ -258,24 +258,19 @@ class RepositoryTest() { } @Test - fun `Reload badges with items caching`() { + fun `Reload badges without connection`() { every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { appSettingsService.isItemCachingEnabled() } returns true every { db.itemsQueries.items().executeAsList() } returns generateTestDBItems() - val itemParameter = FakeItemParameters() - itemParameter.starred = true - itemParameter.unread = false - var success = false val repository = Repository(api, appSettingsService, connectivityStatus, db) - repository.items = ArrayList(generateTestApiItem(itemParameter)) runBlocking { success = repository.reloadBadges() } - assertSame(true, success) + assertTrue(success) assertSame(1, repository.badgeAll) assertSame(1, repository.badgeUnread) assertSame(1, repository.badgeStarred) @@ -284,23 +279,19 @@ class RepositoryTest() { } @Test - fun `Reload badges without items caching`() { + fun `Reload badges without connection and items caching disabled`() { every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { appSettingsService.isItemCachingEnabled() } returns false - - val itemParameter = FakeItemParameters() - itemParameter.starred = true - itemParameter.unread = false + every { appSettingsService.isUpdateSourcesEnabled() } returns true var success = false val repository = Repository(api, appSettingsService, connectivityStatus, db) - repository.items = ArrayList(generateTestApiItem(itemParameter)) runBlocking { success = repository.reloadBadges() } - assertSame(false, success) + assertFalse(success) assertSame(0, repository.badgeAll) assertSame(0, repository.badgeUnread) assertSame(0, repository.badgeStarred)