Skip to content

Commit

Permalink
feat: add get current analytics tracking identifier usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandreferris committed Aug 14, 2024
1 parent 58d7ee8 commit 51ade33
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
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(
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
}
}
}

0 comments on commit 51ade33

Please sign in to comment.