Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Get Current Analytics Tracking Identifier (WPB-10600) #2949

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
alexandreferris marked this conversation as resolved.
Show resolved Hide resolved
userConfigRepository: UserConfigRepository
) = object : GetCurrentAnalyticsTrackingIdentifierUseCase {

override suspend fun invoke(): String? = userConfigRepository.getCurrentTrackingIdentifier()
}
Original file line number Diff line number Diff line change
@@ -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<Arrangement, GetCurrentAnalyticsTrackingIdentifierUseCase> {
runBlocking { block() }
return this to useCase
}
}
}
Loading