From 667e9c1a5d849d94cf0fdbeb24a8aa5c00056dab Mon Sep 17 00:00:00 2001 From: davidoskky Date: Fri, 21 Oct 2022 22:56:35 +0200 Subject: [PATCH] Adjust tests to changes in the repository --- .../repository/RepositoryTest.kt | 123 +++++++++--------- 1 file changed, 59 insertions(+), 64 deletions(-) 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 61109d5..26394a2 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 @@ -24,6 +24,7 @@ class RepositoryTest() { private val NUMBER_ARTICLES = 100 private val NUMBER_UNREAD = 50 private val NUMBER_STARRED = 20 + private lateinit var repository: Repository @BeforeTest fun setup() { @@ -48,10 +49,9 @@ class RepositoryTest() { @Test fun `Instantiate repository`() { - Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() coVerify(exactly = 1) { api.version() } - coVerify(exactly = 1) { api.stats() } } @Test @@ -59,25 +59,12 @@ class RepositoryTest() { every { appSettingsService.getApiVersion() } returns -1 every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) - Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() coVerify(exactly = 0) { api.version() } coVerify(exactly = 0) { api.stats() } } - @Test - fun `Instantiate repository with negative stats`() { - coEvery { api.stats() } returns SelfossModel.StatusAndData(success = true, data = SelfossModel.Stats(-100, -50, -20)) - - val repository = Repository(api, appSettingsService, connectivityStatus, db) - - assertEquals(0, repository.badgeAll) - assertEquals(0, repository.badgeStarred) - assertEquals(0, repository.badgeUnread) - coVerify(exactly = 1) { api.version() } - coVerify(exactly = 1) { api.stats() } - } - @Test fun `Get api 4 date with api 1 version stored`() { every { appSettingsService.getApiVersion() } returns 1 @@ -85,7 +72,7 @@ class RepositoryTest() { SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) every { appSettingsService.updateApiVersion(any()) } returns Unit - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() runBlocking { repository.getNewerItems() } @@ -103,7 +90,7 @@ class RepositoryTest() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns SelfossModel.StatusAndData(success = true, data = generateTestApiItem(itemParameters)) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() runBlocking { repository.getNewerItems() } @@ -116,7 +103,7 @@ class RepositoryTest() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() runBlocking { repository.getNewerItems() } @@ -131,7 +118,7 @@ class RepositoryTest() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() repository.displayedItems = ItemType.ALL runBlocking { repository.getNewerItems() @@ -147,7 +134,7 @@ class RepositoryTest() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() repository.displayedItems = ItemType.STARRED runBlocking { repository.getNewerItems() @@ -163,7 +150,7 @@ class RepositoryTest() { every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { appSettingsService.isItemCachingEnabled() } returns true - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() runBlocking { repository.getNewerItems() } @@ -189,7 +176,7 @@ class RepositoryTest() { every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { appSettingsService.isItemCachingEnabled() } returns true - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() repository.tagFilter = SelfossModel.Tag("Test", "red", 3) runBlocking { repository.getNewerItems() @@ -216,7 +203,7 @@ class RepositoryTest() { every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { appSettingsService.isItemCachingEnabled() } returns true - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() repository.sourceFilter = SelfossModel.Source(1, "Test", listOf("tags"),"spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png") runBlocking { repository.getNewerItems() @@ -232,7 +219,7 @@ class RepositoryTest() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() repository.items = ArrayList(generateTestApiItem()) runBlocking { repository.getOlderItems() @@ -248,7 +235,7 @@ class RepositoryTest() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() repository.items = ArrayList(generateTestApiItem()) repository.displayedItems = ItemType.ALL runBlocking { @@ -265,7 +252,7 @@ class RepositoryTest() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() repository.displayedItems = ItemType.STARRED repository.items = ArrayList(generateTestApiItem()) runBlocking { @@ -281,7 +268,7 @@ class RepositoryTest() { fun `Reload badges`() { var success = false - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() runBlocking { success = repository.reloadBadges() } @@ -300,7 +287,7 @@ class RepositoryTest() { var success = false - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() runBlocking { success = repository.reloadBadges() } @@ -321,7 +308,7 @@ class RepositoryTest() { var success = false - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() runBlocking { success = repository.reloadBadges() } @@ -342,7 +329,7 @@ class RepositoryTest() { var success = false - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() runBlocking { success = repository.reloadBadges() } @@ -367,7 +354,7 @@ class RepositoryTest() { every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testTags: List? = null runBlocking { testTags = repository.getTags() @@ -390,7 +377,7 @@ class RepositoryTest() { every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns true - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testTags: List = emptyList() runBlocking { testTags = repository.getTags() @@ -416,7 +403,7 @@ class RepositoryTest() { every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns false - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testTags: List = emptyList() runBlocking { testTags = repository.getTags() @@ -439,7 +426,7 @@ class RepositoryTest() { every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testTags: List = emptyList() runBlocking { testTags = repository.getTags() @@ -465,7 +452,7 @@ class RepositoryTest() { every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testTags: List = emptyList() runBlocking { testTags = repository.getTags() @@ -490,7 +477,7 @@ class RepositoryTest() { every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns true - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testTags: List = emptyList() runBlocking { testTags = repository.getTags() @@ -514,7 +501,7 @@ class RepositoryTest() { every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns true - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testTags: List = emptyList() runBlocking { testTags = repository.getTags() @@ -539,7 +526,7 @@ class RepositoryTest() { every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testTags: List = emptyList() runBlocking { testTags = repository.getTags() @@ -559,7 +546,7 @@ class RepositoryTest() { coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testSources: List? = null runBlocking { testSources = repository.getSources() @@ -581,7 +568,7 @@ class RepositoryTest() { every { appSettingsService.isItemCachingEnabled() } returns true coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testSources: List? = null runBlocking { testSources = repository.getSources() @@ -606,7 +593,7 @@ class RepositoryTest() { every { appSettingsService.isItemCachingEnabled() } returns false coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testSources: List? = null runBlocking { testSources = repository.getSources() @@ -628,7 +615,7 @@ class RepositoryTest() { every { appSettingsService.isItemCachingEnabled() } returns false coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testSources: List? = null runBlocking { testSources = repository.getSources() @@ -649,7 +636,7 @@ class RepositoryTest() { every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testSources: List? = null runBlocking { testSources = repository.getSources() @@ -672,7 +659,7 @@ class RepositoryTest() { every { appSettingsService.isUpdateSourcesEnabled() } returns true coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testSources: List? = null runBlocking { testSources = repository.getSources() @@ -695,7 +682,7 @@ class RepositoryTest() { every { appSettingsService.isUpdateSourcesEnabled() } returns false coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testSources: List? = null runBlocking { testSources = repository.getSources() @@ -718,7 +705,7 @@ class RepositoryTest() { every { appSettingsService.isUpdateSourcesEnabled() } returns false coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var testSources: List? = null runBlocking { testSources = repository.getSources() @@ -734,7 +721,7 @@ class RepositoryTest() { coEvery { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) } returns SelfossModel.SuccessResponse(true) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.createSource("test", "https://test.com/feed", "spouts\\rss\\fulltextrss", "Test, New", "") @@ -749,7 +736,7 @@ class RepositoryTest() { coEvery { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) } returns SelfossModel.SuccessResponse(false) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.createSource("test", "https://test.com/feed", "spouts\\rss\\fulltextrss", "Test, New", "") @@ -765,7 +752,7 @@ class RepositoryTest() { SelfossModel.SuccessResponse(true) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.createSource("test", "https://test.com/feed", "spouts\\rss\\fulltextrss", "Test, New", "") @@ -779,7 +766,7 @@ class RepositoryTest() { fun `delete source`() { coEvery { api.deleteSource(any())} returns SelfossModel.SuccessResponse(true) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.deleteSource(5) @@ -793,7 +780,7 @@ class RepositoryTest() { fun `delete source but response fails`() { coEvery { api.deleteSource(any())} returns SelfossModel.SuccessResponse(false) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.deleteSource(5) @@ -808,7 +795,7 @@ class RepositoryTest() { coEvery { api.deleteSource(any())} returns SelfossModel.SuccessResponse(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.deleteSource(5) @@ -822,7 +809,7 @@ class RepositoryTest() { fun `update remote`() { coEvery { api.update()} returns SelfossModel.StatusAndData(success = true, data = "finished") - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.updateRemote() @@ -836,7 +823,7 @@ class RepositoryTest() { fun `update remote but response fails`() { coEvery { api.update()} returns SelfossModel.StatusAndData(success = false, data = "unallowed access") - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.updateRemote() @@ -850,7 +837,7 @@ class RepositoryTest() { fun `update remote with unallowed access`() { coEvery { api.update()} returns SelfossModel.StatusAndData(success = true, data = "unallowed access") - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.updateRemote() @@ -865,7 +852,7 @@ class RepositoryTest() { coEvery { api.update()} returns SelfossModel.StatusAndData(success = true, data = "undocumented...") every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.updateRemote() @@ -879,7 +866,7 @@ class RepositoryTest() { fun login() { coEvery { api.login() } returns SelfossModel.SuccessResponse(success = true) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.login() @@ -893,7 +880,7 @@ class RepositoryTest() { fun `login but response fails`() { coEvery { api.login() } returns SelfossModel.SuccessResponse(success = false) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.login() @@ -908,7 +895,7 @@ class RepositoryTest() { coEvery { api.login() } returns SelfossModel.SuccessResponse(success = true) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() var response = false runBlocking { response = repository.login() @@ -923,7 +910,7 @@ class RepositoryTest() { coEvery { api.refreshLoginInformation() } returns Unit coEvery { appSettingsService.refreshLoginInformation(any(), any(), any()) } returns Unit - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() repository.refreshLoginInformation("https://test.com/selfoss/", "login", "password") coVerify(exactly = 1) { api.refreshLoginInformation() } @@ -943,7 +930,7 @@ class RepositoryTest() { SelfossModel.StatusAndData(success = true, data = generateTestApiItem(itemParameter1)), ) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() repository.tagFilter = SelfossModel.Tag("Tag", "read", 0) repository.sourceFilter = SelfossModel.Source( 1, @@ -966,7 +953,7 @@ class RepositoryTest() { coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns SelfossModel.StatusAndData(success = false, data = generateTestApiItem()) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() repository.tagFilter = SelfossModel.Tag("Tag", "read", 0) repository.sourceFilter = SelfossModel.Source( 1, @@ -990,7 +977,7 @@ class RepositoryTest() { SelfossModel.StatusAndData(success = false, data = generateTestApiItem()) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) - val repository = Repository(api, appSettingsService, connectivityStatus, db) + initializeRepository() repository.tagFilter = SelfossModel.Tag("Tag", "read", 0) repository.sourceFilter = SelfossModel.Source( 1, @@ -1007,6 +994,14 @@ class RepositoryTest() { coVerify(exactly = 0) { api.getItems(any(), 0, null, null, null, null, 200) } } + + fun initializeRepository() { + repository = Repository(api, appSettingsService, connectivityStatus, db) + + runBlocking { + repository.updateApiVersion() + } + } } fun generateTestDBItems(item : FakeItemParameters = FakeItemParameters()) : List {