From dc5dac379cf88e904235f3f16f9e168bcfca4047 Mon Sep 17 00:00:00 2001 From: Adhiambo Peres Date: Tue, 1 Aug 2023 10:21:55 +0300 Subject: [PATCH] Fix failing eventlog test Switch out logger for controller which should swap debug vs real event loggers --- .../vieweventlogs/ViewEventLogsViewModel.kt | 4 +- .../devoptions/ViewEventLogsFragmentTest.kt | 41 ++++++++++++++++--- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsViewModel.kt b/app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsViewModel.kt index ee1b4acc159..10e21fb987f 100644 --- a/app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/devoptions/vieweventlogs/ViewEventLogsViewModel.kt @@ -20,9 +20,9 @@ class ViewEventLogsViewModel @Inject constructor( private val resourceHandler: AppLanguageResourceHandler ) : ObservableViewModel() { - // Retrieves events from cache that are meant to be unloaded to Firebase Analytics. + // Retrieves events from cache that are meant to be uploaded to Firebase Analytics. private val analyticsEvents = debugAnalyticsEventLogger.getEventList() - // Retrieves events from cache that are meant to be unloaded to Firebase Firestore. + // Retrieves events from cache that are meant to be uploaded to Firebase Firestore. private val firestoreEvents = debugFirestoreEventLogger.getEventList() private val eventList = analyticsEvents + firestoreEvents diff --git a/app/src/sharedTest/java/org/oppia/android/app/devoptions/ViewEventLogsFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/devoptions/ViewEventLogsFragmentTest.kt index 6b4ac2eb134..f37711067f4 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/devoptions/ViewEventLogsFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/devoptions/ViewEventLogsFragmentTest.kt @@ -33,6 +33,8 @@ import org.oppia.android.app.application.ApplicationModule import org.oppia.android.app.application.ApplicationStartupListenerModule import org.oppia.android.app.application.testing.TestingBuildFlavorModule import org.oppia.android.app.devoptions.vieweventlogs.testing.ViewEventLogsTestActivity +import org.oppia.android.app.model.EventLog +import org.oppia.android.app.model.ProfileId import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositionOnView import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.hasItemCount @@ -66,9 +68,9 @@ import org.oppia.android.domain.oppialogger.OppiaLogger import org.oppia.android.domain.oppialogger.analytics.AnalyticsController import org.oppia.android.domain.oppialogger.analytics.ApplicationLifecycleModule import org.oppia.android.domain.oppialogger.analytics.CpuPerformanceSnapshotterModule +import org.oppia.android.domain.oppialogger.analytics.FirestoreDataController import org.oppia.android.domain.oppialogger.logscheduler.MetricLogSchedulerModule import org.oppia.android.domain.oppialogger.loguploader.LogReportWorkerModule -import org.oppia.android.domain.oppialogger.survey.SurveyEventsLogger import org.oppia.android.domain.platformparameter.PlatformParameterModule import org.oppia.android.domain.platformparameter.PlatformParameterSingletonModule import org.oppia.android.domain.question.QuestionModule @@ -139,7 +141,7 @@ class ViewEventLogsFragmentTest { lateinit var fakeOppiaClock: FakeOppiaClock @Inject - lateinit var surveyLogger: SurveyEventsLogger + lateinit var dataController: FirestoreDataController @Before fun setUp() { @@ -582,12 +584,39 @@ class ViewEventLogsFragmentTest { oppiaLogger.createOpenRevisionCardContext(TEST_TOPIC_ID, TEST_SUB_TOPIC_ID), profileId = null ) - fakeOppiaClock.setCurrentTimeMs(TEST_TIMESTAMP + 50000) - surveyLogger.logOptionalResponse( - "survey_id", + logOptionalSurveyResponseEvent() + } + + private fun logOptionalSurveyResponseEvent() { + dataController.logEvent( + createOptionalSurveyResponseContext( + "survey_id", + profileId = null, + answer = "some response" + ), profileId = null, - answer = "some response" + TEST_TIMESTAMP + 50000 ) + testCoroutineDispatchers.runCurrent() + } + + private fun createOptionalSurveyResponseContext( + surveyId: String, + profileId: ProfileId?, + answer: String + ): EventLog.Context { + return EventLog.Context.newBuilder() + .setOptionalResponse( + EventLog.OptionalSurveyResponseContext.newBuilder() + .setFeedbackAnswer(answer) + .setSurveyDetails( + EventLog.SurveyResponseContext.newBuilder() + .setProfileId(profileId?.internalId.toString()) + .setSurveyId(surveyId) + .build() + ) + ) + .build() } private fun verifyTextOnEventLogItemViewAtPosition(