From c4b6874e7c3647233784bc6ab94c2830d2174fb0 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 26 Jan 2023 17:20:29 +0100 Subject: [PATCH] Add tests for the public access determination logic --- androidApp/src/test/kotlin/RepositoryTest.kt | 60 ++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/androidApp/src/test/kotlin/RepositoryTest.kt b/androidApp/src/test/kotlin/RepositoryTest.kt index 950b07e..ec307b9 100644 --- a/androidApp/src/test/kotlin/RepositoryTest.kt +++ b/androidApp/src/test/kotlin/RepositoryTest.kt @@ -113,6 +113,66 @@ class RepositoryTest { verify(exactly = 1) { appSettingsService.updateApiVersion(4) } } + @Test + fun get_public_access() { + every { appSettingsService.updatePublicAccess(any()) } returns Unit + coEvery { api.apiInformation() } returns StatusAndData( + success = true, + data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(true, true)) + ) + every { appSettingsService.getUserName() } returns "" + + initializeRepository() + + coVerify(exactly = 1) { api.apiInformation() } + coVerify(exactly = 1) { appSettingsService.updatePublicAccess(true) } + } + + @Test + fun get_public_access_username_not_empty() { + every { appSettingsService.updatePublicAccess(any()) } returns Unit + coEvery { api.apiInformation() } returns StatusAndData( + success = true, + data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(true, true)) + ) + every { appSettingsService.getUserName() } returns "username" + + initializeRepository() + + coVerify(exactly = 1) { api.apiInformation() } + coVerify(exactly = 0) { appSettingsService.updatePublicAccess(true) } + } + + @Test + fun get_public_access_no_auth() { + every { appSettingsService.updatePublicAccess(any()) } returns Unit + coEvery { api.apiInformation() } returns StatusAndData( + success = true, + data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(true, false)) + ) + every { appSettingsService.getUserName() } returns "" + + initializeRepository() + + coVerify(exactly = 1) { api.apiInformation() } + coVerify(exactly = 0) { appSettingsService.updatePublicAccess(true) } + } + + @Test + fun get_public_access_disabled() { + every { appSettingsService.updatePublicAccess(any()) } returns Unit + coEvery { api.apiInformation() } returns StatusAndData( + success = true, + data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(false, true)) + ) + every { appSettingsService.getUserName() } returns "" + + initializeRepository() + + coVerify(exactly = 1) { api.apiInformation() } + coVerify(exactly = 0) { appSettingsService.updatePublicAccess(true) } + } + @Test fun get_api_1_date_with_api_4_version_stored() { every { appSettingsService.getApiVersion() } returns 4