Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Delete stored CheckIns on app data reset (EXPOSUREAPP-5902) #2670

Merged
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 @@ -11,6 +11,7 @@ import de.rki.coronawarnapp.datadonation.analytics.storage.AnalyticsSettings
import de.rki.coronawarnapp.datadonation.survey.SurveySettings
import de.rki.coronawarnapp.diagnosiskeys.download.DownloadDiagnosisKeysSettings
import de.rki.coronawarnapp.diagnosiskeys.storage.KeyCacheRepository
import de.rki.coronawarnapp.eventregistration.checkins.CheckInRepository
import de.rki.coronawarnapp.eventregistration.storage.repo.TraceLocationRepository
import de.rki.coronawarnapp.main.CWASettings
import de.rki.coronawarnapp.nearby.modules.detectiontracker.ExposureDetectionTracker
Expand Down Expand Up @@ -52,6 +53,7 @@ class DataReset @Inject constructor(
private val onboardingSettings: OnboardingSettings,
private val submissionSettings: SubmissionSettings,
private val traceLocationRepository: TraceLocationRepository,
private val checkInRepository: CheckInRepository
) {

private val mutex = Mutex()
Expand Down Expand Up @@ -89,6 +91,7 @@ class DataReset @Inject constructor(
bugReportingSettings.clear()

traceLocationRepository.deleteAllTraceLocations()
checkInRepository.clear()

Timber.w("CWA LOCAL DATA DELETION COMPLETED.")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package de.rki.coronawarnapp.util

import android.content.Context
import de.rki.coronawarnapp.appconfig.AppConfigProvider
import de.rki.coronawarnapp.bugreporting.BugReportingSettings
import de.rki.coronawarnapp.contactdiary.storage.ContactDiaryPreferences
import de.rki.coronawarnapp.contactdiary.storage.repo.ContactDiaryRepository
import de.rki.coronawarnapp.datadonation.analytics.Analytics
import de.rki.coronawarnapp.datadonation.analytics.storage.AnalyticsSettings
import de.rki.coronawarnapp.datadonation.survey.SurveySettings
import de.rki.coronawarnapp.diagnosiskeys.download.DownloadDiagnosisKeysSettings
import de.rki.coronawarnapp.diagnosiskeys.storage.KeyCacheRepository
import de.rki.coronawarnapp.eventregistration.checkins.CheckInRepository
import de.rki.coronawarnapp.eventregistration.storage.repo.TraceLocationRepository
import de.rki.coronawarnapp.main.CWASettings
import de.rki.coronawarnapp.nearby.modules.detectiontracker.ExposureDetectionTracker
import de.rki.coronawarnapp.risk.storage.RiskLevelStorage
import de.rki.coronawarnapp.statistics.source.StatisticsProvider
import de.rki.coronawarnapp.storage.OnboardingSettings
import de.rki.coronawarnapp.storage.TracingSettings
import de.rki.coronawarnapp.submission.SubmissionRepository
import de.rki.coronawarnapp.submission.SubmissionSettings
import io.mockk.MockKAnnotations
import io.mockk.coVerify
import io.mockk.impl.annotations.MockK
import kotlinx.coroutines.test.runBlockingTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import testhelpers.BaseTest

internal class DataResetTest : BaseTest() {

@MockK lateinit var context: Context
@MockK lateinit var keyCacheRepository: KeyCacheRepository
@MockK lateinit var appConfigProvider: AppConfigProvider
@MockK lateinit var submissionRepository: SubmissionRepository
@MockK lateinit var exposureDetectionTracker: ExposureDetectionTracker
@MockK lateinit var downloadDiagnosisKeysSettings: DownloadDiagnosisKeysSettings
@MockK lateinit var riskLevelStorage: RiskLevelStorage
@MockK lateinit var contactDiaryRepository: ContactDiaryRepository
@MockK lateinit var contactDiaryPreferences: ContactDiaryPreferences
@MockK lateinit var cwaSettings: CWASettings
@MockK lateinit var statisticsProvider: StatisticsProvider
@MockK lateinit var surveySettings: SurveySettings
@MockK lateinit var analyticsSettings: AnalyticsSettings
@MockK lateinit var analytics: Analytics
@MockK lateinit var bugReportingSettings: BugReportingSettings
@MockK lateinit var tracingSettings: TracingSettings
@MockK lateinit var onboardingSettings: OnboardingSettings
@MockK lateinit var submissionSettings: SubmissionSettings
@MockK lateinit var traceLocationRepository: TraceLocationRepository
@MockK lateinit var checkInRepository: CheckInRepository

@BeforeEach
fun setUp() {
MockKAnnotations.init(this, relaxed = true)
}

fun createInstance() = DataReset(
context = context,
keyCacheRepository = keyCacheRepository,
appConfigProvider = appConfigProvider,
submissionRepository = submissionRepository,
exposureDetectionTracker = exposureDetectionTracker,
downloadDiagnosisKeysSettings = downloadDiagnosisKeysSettings,
riskLevelStorage = riskLevelStorage,
contactDiaryRepository = contactDiaryRepository,
contactDiaryPreferences = contactDiaryPreferences,
cwaSettings = cwaSettings,
statisticsProvider = statisticsProvider,
surveySettings = surveySettings,
analyticsSettings = analyticsSettings,
analytics = analytics,
bugReportingSettings = bugReportingSettings,
tracingSettings = tracingSettings,
onboardingSettings = onboardingSettings,
submissionSettings = submissionSettings,
traceLocationRepository = traceLocationRepository,
checkInRepository = checkInRepository
)

@Test
fun `clearAllLocalData() should clear all data`() = runBlockingTest {
createInstance().clearAllLocalData()

coVerify(exactly = 1) { analytics.setAnalyticsEnabled(false) }

coVerify(exactly = 1) { submissionRepository.reset() }
coVerify(exactly = 1) { keyCacheRepository.clear() }
coVerify(exactly = 1) { appConfigProvider.clear() }
coVerify(exactly = 1) { exposureDetectionTracker.clear() }
coVerify(exactly = 1) { downloadDiagnosisKeysSettings.clear() }
coVerify(exactly = 1) { riskLevelStorage.clear() }
coVerify(exactly = 1) { contactDiaryPreferences.clear() }
coVerify(exactly = 1) { cwaSettings.clear() }
coVerify(exactly = 1) { surveySettings.clear() }
coVerify(exactly = 1) { analyticsSettings.clear() }
coVerify(exactly = 1) { tracingSettings.clear() }
coVerify(exactly = 1) { onboardingSettings.clear() }
coVerify(exactly = 1) { submissionSettings.clear() }

coVerify(exactly = 1) { contactDiaryRepository.clear() }

coVerify(exactly = 1) { statisticsProvider.clear() }

coVerify(exactly = 1) { bugReportingSettings.clear() }

coVerify(exactly = 1) { traceLocationRepository.deleteAllTraceLocations() }
coVerify(exactly = 1) { checkInRepository.clear() }
}
}