Skip to content

Commit

Permalink
fix: Add missing staging backend verification for analytics (WPB-1073…
Browse files Browse the repository at this point in the history
…6) (#3366)

Signed-off-by: alexandreferris <[email protected]>
  • Loading branch information
alexandreferris authored and github-actions[bot] committed Aug 23, 2024
1 parent 8ace2c0 commit 35df42e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnalyticsIdentifierResult.ExistingIdentifier>(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
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -274,6 +295,12 @@ class ObserveCurrentSessionAnalyticsUseCaseTest {
)
)
)

val SERVER_CONFIG_STAGING = SERVER_CONFIG_PRODUCTION.copy(
serverLinks = SERVER_CONFIG_PRODUCTION.serverLinks.copy(
links = ServerConfig.STAGING
)
)
}
}
}

0 comments on commit 35df42e

Please sign in to comment.