From 51ade339a8593130930868924ed91b6044d90773 Mon Sep 17 00:00:00 2001 From: alexandreferris Date: Wed, 14 Aug 2024 11:07:58 +0200 Subject: [PATCH 1/2] feat: add get current analytics tracking identifier usecase --- .../kalium/logic/feature/UserSessionScope.kt | 4 ++ ...rrentAnalyticsTrackingIdentifierUseCase.kt | 40 ++++++++++++ ...tAnalyticsTrackingIdentifierUseCaseTest.kt | 63 +++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/analytics/GetCurrentAnalyticsTrackingIdentifierUseCase.kt create mode 100644 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/analytics/GetCurrentAnalyticsTrackingIdentifierUseCaseTest.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt index f787659532b..d6e3e4b2581 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt @@ -153,6 +153,7 @@ import com.wire.kalium.logic.di.PlatformUserStorageProperties import com.wire.kalium.logic.di.RootPathsProvider import com.wire.kalium.logic.di.UserStorageProvider import com.wire.kalium.logic.feature.analytics.AnalyticsIdentifierManager +import com.wire.kalium.logic.feature.analytics.GetCurrentAnalyticsTrackingIdentifierUseCase import com.wire.kalium.logic.feature.analytics.ObserveAnalyticsTrackingIdentifierStatusUseCase import com.wire.kalium.logic.feature.applock.AppLockTeamFeatureConfigObserver import com.wire.kalium.logic.feature.applock.AppLockTeamFeatureConfigObserverImpl @@ -1495,6 +1496,9 @@ class UserSessionScope internal constructor( val observeAnalyticsTrackingIdentifierStatus: ObserveAnalyticsTrackingIdentifierStatusUseCase get() = ObserveAnalyticsTrackingIdentifierStatusUseCase(userConfigRepository, userScopedLogger) + val getCurrentAnalyticsTrackingIdentifier: GetCurrentAnalyticsTrackingIdentifierUseCase + get() = GetCurrentAnalyticsTrackingIdentifierUseCase(userConfigRepository) + val analyticsIdentifierManager: AnalyticsIdentifierManager get() = AnalyticsIdentifierManager( messages.messageSender, diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/analytics/GetCurrentAnalyticsTrackingIdentifierUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/analytics/GetCurrentAnalyticsTrackingIdentifierUseCase.kt new file mode 100644 index 00000000000..03896e59a41 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/analytics/GetCurrentAnalyticsTrackingIdentifierUseCase.kt @@ -0,0 +1,40 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.analytics + +import com.wire.kalium.logic.configuration.UserConfigRepository + +/** + * Use case that returns the current analytics tracking identifier + */ +interface GetCurrentAnalyticsTrackingIdentifierUseCase { + /** + * Use case [GetCurrentAnalyticsTrackingIdentifierUseCase] operation + * + * @return a [String] containing the current tracking identifier + */ + suspend operator fun invoke(): String? +} + +@Suppress("FunctionNaming") +internal fun GetCurrentAnalyticsTrackingIdentifierUseCase( + userConfigRepository: UserConfigRepository +) = object : GetCurrentAnalyticsTrackingIdentifierUseCase { + + override suspend fun invoke(): String? = userConfigRepository.getCurrentTrackingIdentifier() +} diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/analytics/GetCurrentAnalyticsTrackingIdentifierUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/analytics/GetCurrentAnalyticsTrackingIdentifierUseCaseTest.kt new file mode 100644 index 00000000000..566e174e0e6 --- /dev/null +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/analytics/GetCurrentAnalyticsTrackingIdentifierUseCaseTest.kt @@ -0,0 +1,63 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.analytics + +import com.wire.kalium.logic.util.arrangement.repository.UserConfigRepositoryArrangement +import com.wire.kalium.logic.util.arrangement.repository.UserConfigRepositoryArrangementImpl +import io.mockative.coVerify +import io.mockative.once +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.test.assertEquals + +class GetCurrentAnalyticsTrackingIdentifierUseCaseTest { + + @Test + fun givenCurrentAnalyticsTrackingId_whenGettingTrackingId_thenCurrentTrackingIdIsReturned() = runTest { + // given + val (arrangement, useCase) = Arrangement().arrange { + withGetTrackingIdentifier(CURRENT_IDENTIFIER) + } + + // when + val result = useCase() + + // then + assertEquals(CURRENT_IDENTIFIER, result) + coVerify { + arrangement.userConfigRepository.getCurrentTrackingIdentifier() + }.wasInvoked(exactly = once) + } + + private companion object { + const val CURRENT_IDENTIFIER = "efgh-5678" + } + + private class Arrangement : UserConfigRepositoryArrangement by UserConfigRepositoryArrangementImpl() { + + private val useCase: GetCurrentAnalyticsTrackingIdentifierUseCase = GetCurrentAnalyticsTrackingIdentifierUseCase( + userConfigRepository = userConfigRepository + ) + + fun arrange(block: suspend Arrangement.() -> Unit): Pair { + runBlocking { block() } + return this to useCase + } + } +} From b86814a22708c26db18ff2598f28b97308a65285 Mon Sep 17 00:00:00 2001 From: alexandreferris Date: Wed, 14 Aug 2024 15:55:32 +0200 Subject: [PATCH 2/2] feat: add dummy server config for tests --- .../logic/configuration/server/ServerConfig.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/server/ServerConfig.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/server/ServerConfig.kt index 149493abf25..3bb8a0273a8 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/server/ServerConfig.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/server/ServerConfig.kt @@ -134,6 +134,19 @@ data class ServerConfig( isOnPremises = false, apiProxy = null ) + + val DUMMY = Links( + api = """https://dummy-nginz-https.zinfra.io""", + accounts = """https://wire-account-dummy.zinfra.io""", + webSocket = """https://dummy-nginz-ssl.zinfra.io""", + teams = """https://wire-teams-dummy.zinfra.io""", + blackList = """https://clientblacklist.wire.com/dummy""", + website = """https://dummy.wire.com""", + title = "dummy", + isOnPremises = false, + apiProxy = null + ) + val DEFAULT = PRODUCTION private const val FORGOT_PASSWORD_PATH = "forgot"