From 35df42ef6b04ab4bf30730778b35c2c1a043bf6f Mon Sep 17 00:00:00 2001 From: Alexandre Ferris Date: Fri, 23 Aug 2024 15:43:17 +0000 Subject: [PATCH] fix: Add missing staging backend verification for analytics (WPB-10736) (#3366) Signed-off-by: alexandreferris --- .../ObserveCurrentSessionAnalyticsUseCase.kt | 4 +- ...serveCurrentSessionAnalyticsUseCaseTest.kt | 41 +++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCase.kt b/app/src/main/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCase.kt index c0c7aa79c28..4cada52b9e9 100644 --- a/app/src/main/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCase.kt +++ b/app/src/main/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCase.kt @@ -78,7 +78,9 @@ fun ObserveCurrentSessionAnalyticsUseCase( previousAnalyticsResult = identifierResult val isProdBackend = when (val serverConfig = currentBackend(userId)) { - is SelfServerConfigUseCase.Result.Success -> serverConfig.serverLinks.links.api == ServerConfig.PRODUCTION.api + is SelfServerConfigUseCase.Result.Success -> + serverConfig.serverLinks.links.api == ServerConfig.PRODUCTION.api + || serverConfig.serverLinks.links.api == ServerConfig.STAGING.api is SelfServerConfigUseCase.Result.Failure -> false } diff --git a/app/src/test/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCaseTest.kt b/app/src/test/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCaseTest.kt index 50e963991b8..ca69a7bce64 100644 --- a/app/src/test/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCaseTest.kt +++ b/app/src/test/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCaseTest.kt @@ -70,7 +70,28 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { setCurrentSession(CurrentSessionResult.Success(AccountInfo.Valid(TestUser.SELF_USER.id))) setIsTeamMember(TestUser.SELF_USER.id) setObservingTrackingIdentifierStatus(AnalyticsIdentifierResult.ExistingIdentifier(Arrangement.CURRENT_TRACKING_IDENTIFIER)) - setSelfServerConfig(Arrangement.SEVER_CONFIG_PRODUCTION) + setSelfServerConfig(Arrangement.SERVER_CONFIG_PRODUCTION) + }.arrange() + + // when + useCase.invoke().test { + // then + val item = awaitItem() + assertIs(item.identifierResult) + assertEquals(true, item.isTeamMember) + } + } + + @Test + fun givenStagingBackendApi_whenObservingCurrentSessionAnalytics_thenExistingIdentifierAnalyticsResultIsReturned() = runTest { + // given + val (_, useCase) = Arrangement() + .withIsAnonymousUsageDataEnabled(true) + .apply { + setCurrentSession(CurrentSessionResult.Success(AccountInfo.Valid(TestUser.SELF_USER.id))) + setIsTeamMember(TestUser.SELF_USER.id) + setObservingTrackingIdentifierStatus(AnalyticsIdentifierResult.ExistingIdentifier(Arrangement.CURRENT_TRACKING_IDENTIFIER)) + setSelfServerConfig(Arrangement.SERVER_CONFIG_STAGING) }.arrange() // when @@ -94,7 +115,7 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { setObservingTrackingIdentifierStatus( AnalyticsIdentifierResult.ExistingIdentifier(Arrangement.CURRENT_TRACKING_IDENTIFIER) ) - setSelfServerConfig(Arrangement.SEVER_CONFIG_PRODUCTION) + setSelfServerConfig(Arrangement.SERVER_CONFIG_PRODUCTION) }.arrange() // when @@ -120,8 +141,8 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { AnalyticsIdentifierResult.ExistingIdentifier(Arrangement.CURRENT_TRACKING_IDENTIFIER) ) setSelfServerConfig( - Arrangement.SEVER_CONFIG_PRODUCTION.copy( - serverLinks = Arrangement.SEVER_CONFIG_PRODUCTION.serverLinks.copy(links = ServerConfig.STAGING) + Arrangement.SERVER_CONFIG_PRODUCTION.copy( + serverLinks = Arrangement.SERVER_CONFIG_PRODUCTION.serverLinks.copy(links = ServerConfig.DUMMY) ) ) }.arrange() @@ -170,7 +191,7 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { setCurrentSession(CurrentSessionResult.Success(AccountInfo.Valid(TestUser.SELF_USER.id))) setIsTeamMember(TestUser.SELF_USER.id) setObservingTrackingIdentifierStatus(AnalyticsIdentifierResult.ExistingIdentifier(Arrangement.CURRENT_TRACKING_IDENTIFIER)) - setSelfServerConfig(Arrangement.SEVER_CONFIG_PRODUCTION) + setSelfServerConfig(Arrangement.SERVER_CONFIG_PRODUCTION) }.arrange() // when @@ -185,7 +206,7 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { arrangement.setObservingTrackingIdentifierStatus( AnalyticsIdentifierResult.ExistingIdentifier(Arrangement.OTHER_TRACKING_IDENTIFIER) ) - arrangement.setSelfServerConfig(Arrangement.SEVER_CONFIG_PRODUCTION) + arrangement.setSelfServerConfig(Arrangement.SERVER_CONFIG_PRODUCTION) arrangement.withIsAnonymousUsageDataEnabled(true) // then @@ -263,7 +284,7 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { const val CURRENT_TRACKING_IDENTIFIER = "abcd-1234" const val OTHER_TRACKING_IDENTIFIER = "aaaa-bbbb-1234" - val SEVER_CONFIG_PRODUCTION = SelfServerConfigUseCase.Result.Success( + val SERVER_CONFIG_PRODUCTION = SelfServerConfigUseCase.Result.Success( serverLinks = ServerConfig( id = "server_id", links = ServerConfig.PRODUCTION, @@ -274,6 +295,12 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { ) ) ) + + val SERVER_CONFIG_STAGING = SERVER_CONFIG_PRODUCTION.copy( + serverLinks = SERVER_CONFIG_PRODUCTION.serverLinks.copy( + links = ServerConfig.STAGING + ) + ) } } }