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

fix: Add missing staging backend verification for analytics (WPB-10736) #3366

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 @@ -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
alexandreferris marked this conversation as resolved.
Show resolved Hide resolved
}

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
)
)
}
}
}
Loading