Skip to content

Commit

Permalink
fix: Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmurerwa committed Nov 22, 2023
1 parent 2b7aad4 commit fd81350
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import org.oppia.android.util.platformparameter.SPOTLIGHT_UI
import javax.inject.Inject
import javax.inject.Singleton

/**
* Convenience logger for feature flags.
*
* This logger is meant to be used to log the current status of all feature flags once after the app
* has been launched.
*/
@Singleton
class FeatureFlagsLogger @Inject constructor(
private val analyticsController: AnalyticsController,
Expand All @@ -53,6 +59,8 @@ class FeatureFlagsLogger @Inject constructor(
) {
/**
* This method logs all the configured feature flags to firebase.
*
* @param sessionId denotes the id of the current appInForeground session
*/
fun logAllFeatureFlags(sessionId: String) {
analyticsController.logImportantEvent(
Expand All @@ -61,6 +69,12 @@ class FeatureFlagsLogger @Inject constructor(
)
}

/**
* Collects all the feature flags in the app, creates a FeatureFlagItem for them and adds them to
* a list that is returned to the calling object.
*
* @return a list of [FeatureFlagItem]s
*/
private fun compileFeatureFlagsForLogging(): List<FeatureFlagItem> {
val listOfFlags = arrayListOf<FeatureFlagItem>()

Expand Down Expand Up @@ -137,12 +151,17 @@ class FeatureFlagsLogger @Inject constructor(
return listOfFlags
}

/**
* Creates an [EventLog] context for the feature flags to be logged.
*
* @param sessionId denotes the session id of the current appInForeground session
* @return an [EventLog.Context] for the feature flags to be logged
*/
private fun createFeatureFlagContext(sessionId: String): EventLog.Context {
return EventLog.Context.newBuilder()
.setFeatureFlagContext(
FeatureFlagContext.newBuilder()
// TODO: Add uuid
.setUuid("My UUID")
.setUuid("")
.setSessionId(sessionId)
.addAllFeatureFlag(
compileFeatureFlagsForLogging()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ class FeatureFlagsLoggerTest {
@Singleton
@Component(
modules = [
PerformanceMetricsLoggerTest.TestModule::class, TestLogReportingModule::class,
RobolectricModule::class, TestDispatcherModule::class,
PerformanceMetricsLoggerTest.TestLogStorageModule::class,
TestModule::class, TestLogReportingModule::class, RobolectricModule::class,
TestDispatcherModule::class, TestLogStorageModule::class,
NetworkConnectionUtilDebugModule::class, LocaleProdModule::class, FakeOppiaClockModule::class,
TestPlatformParameterModule::class, PlatformParameterSingletonModule::class,
LoggingIdentifierModule::class, SyncStatusTestModule::class, AssetModule::class,
Expand Down
2 changes: 1 addition & 1 deletion model/src/main/proto/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ oppia_proto_library(
deps = [
":exploration_proto",
":languages_proto",
":platform_parameter_proto",
":profile_proto",
":survey_proto",
":platform_parameter_proto",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1047,12 +1047,19 @@ class EventLogSubject private constructor(
hasBeginSurveyContextThat().block()
}

/**
* Verifies the [EventLog]'s context and returns a [FeatureFlagContextSubject] to test the
* corresponding context.
*/
fun hasFeatureFlagContextThat(): FeatureFlagContextSubject {
return FeatureFlagContextSubject.assertThat(
actual.context.featureFlagContext
)
}

/**
* Verifies the [EventLog]'s context and executes [block].
*/
fun hasFeatureFlagContextThat(
block: FeatureFlagContextSubject.() -> Unit
) {
Expand Down Expand Up @@ -1958,28 +1965,41 @@ class EventLogSubject private constructor(
}

/**
* Truth subject for verifying properties of [EventLog.SurveyContext]s.
* Truth subject for verifying properties of [EventLog.FeatureFlagContext]s.
*
* Note that this class is also a [LiteProtoSubject] so other aspects of the underlying
* [EventLog.SurveyContext] proto can be verified through inherited methods.
* [EventLog.FeatureFlagContext] proto can be verified through inherited methods.
*
* Call [SurveyContextSubject.assertThat] to create the subject.
* Call [FeatureFlagContextSubject.assertThat] to create the subject.
*/
class FeatureFlagContextSubject private constructor(
metadata: FailureMetadata,
private val actual: EventLog.FeatureFlagContext
) : LiteProtoSubject(metadata, actual) {
/**
* Returns a [StringSubject] to test [EventLog.SurveyContext.getExplorationId].
* Returns a [StringSubject] to test [EventLog.FeatureFlagContext.getSessionId].
*
* This method never fails since the underlying property defaults to empty string if it's not
* defined in the context.
*/
fun hasSessionIdThat(): StringSubject = assertThat(actual.sessionId)

/**
* Returns a [BooleanSubject] to test the flagEnabledState of the [EventLog.FeatureFlagContext].
*
* This method never fails since the underlying property defaults to empty string if it's not
* defined in the context.
*/
fun hasFeatureEnabledStateThat(): BooleanSubject =
assertThat(actual.getFeatureFlag(0).flagEnabledState)

/**
* Returns a [ComparableSubject] to test the flagSyncStatus of the
* [EventLog.FeatureFlagContext].
*
* This method never fails since the underlying property defaults to empty string if it's not
* defined in the context.
*/
fun hasSyncStatusThat(): ComparableSubject<PlatformParameter.SyncStatus> =
assertThat(actual.getFeatureFlag(0).flagSyncStatus)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ class EventBundleCreator @Inject constructor(
}
}

/** The [EventActivityContext] corresponding to [FeatureFlagEventContext]s. */
/** The [EventActivityContext] corresponding to [FeatureFlagEventContext]s. */
class FeatureFlagContext(
activityName: String,
value: FeatureFlagEventContext
Expand Down

0 comments on commit fd81350

Please sign in to comment.