From a2dce0f2b8b9f8ab4225911c17f2180ab8e15a79 Mon Sep 17 00:00:00 2001
From: Chilja Gossow <49635654+chiljamgossow@users.noreply.github.com>
Date: Wed, 2 Jun 2021 19:48:21 +0200
Subject: [PATCH] Fix RA test result mapping (DEV) (#3351)

* fix ra test result mapping

* fix test

Co-authored-by: Mohamed Metwalli <mohamed.metwalli@sap.com>
---
 .../testresult/AnalyticsTestResultDonor.kt    | 18 ++++++++++++---
 .../AnalyticsRATestResultDonorTest.kt         | 22 +++++++++----------
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/datadonation/analytics/modules/testresult/AnalyticsTestResultDonor.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/datadonation/analytics/modules/testresult/AnalyticsTestResultDonor.kt
index 8ec58e107..33720b0c9 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/datadonation/analytics/modules/testresult/AnalyticsTestResultDonor.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/datadonation/analytics/modules/testresult/AnalyticsTestResultDonor.kt
@@ -1,6 +1,7 @@
 package de.rki.coronawarnapp.datadonation.analytics.modules.testresult
 
 import de.rki.coronawarnapp.coronatest.server.CoronaTestResult
+import de.rki.coronawarnapp.coronatest.type.CoronaTest
 import de.rki.coronawarnapp.datadonation.analytics.common.isFinal
 import de.rki.coronawarnapp.datadonation.analytics.common.isPending
 import de.rki.coronawarnapp.datadonation.analytics.modules.DonorModule
@@ -16,19 +17,25 @@ import javax.inject.Singleton
 class AnalyticsPCRTestResultDonor @Inject constructor(
     testResultSettings: AnalyticsPCRTestResultSettings,
     timeStamper: TimeStamper,
-) : AnalyticsTestResultDonor(testResultSettings, timeStamper)
+) : AnalyticsTestResultDonor(testResultSettings, timeStamper) {
+    override val type = CoronaTest.Type.PCR
+}
 
 @Singleton
 class AnalyticsRATestResultDonor @Inject constructor(
     testResultSettings: AnalyticsRATestResultSettings,
     timeStamper: TimeStamper,
-) : AnalyticsTestResultDonor(testResultSettings, timeStamper)
+) : AnalyticsTestResultDonor(testResultSettings, timeStamper) {
+    override val type = CoronaTest.Type.RAPID_ANTIGEN
+}
 
 abstract class AnalyticsTestResultDonor(
     private val testResultSettings: AnalyticsTestResultSettings,
     private val timeStamper: TimeStamper,
 ) : DonorModule {
 
+    abstract val type: CoronaTest.Type
+
     override suspend fun beginDonation(request: DonorModule.Request): DonorModule.Contribution {
         val timestampAtRegistration = testResultSettings.testRegisteredAt.value
         if (timestampAtRegistration == null) {
@@ -145,9 +152,14 @@ abstract class AnalyticsTestResultDonor(
 
     private fun CoronaTestResult.toPPATestResult(): PpaData.PPATestResult {
         return when (this) {
-            CoronaTestResult.PCR_OR_RAT_PENDING -> PpaData.PPATestResult.TEST_RESULT_PENDING
+            CoronaTestResult.PCR_OR_RAT_PENDING -> when (type) {
+                CoronaTest.Type.PCR -> PpaData.PPATestResult.TEST_RESULT_PENDING
+                CoronaTest.Type.RAPID_ANTIGEN -> PpaData.PPATestResult.TEST_RESULT_RAT_PENDING
+            }
             CoronaTestResult.PCR_POSITIVE -> PpaData.PPATestResult.TEST_RESULT_POSITIVE
             CoronaTestResult.PCR_NEGATIVE -> PpaData.PPATestResult.TEST_RESULT_NEGATIVE
+            CoronaTestResult.RAT_NEGATIVE -> PpaData.PPATestResult.TEST_RESULT_RAT_NEGATIVE
+            CoronaTestResult.RAT_POSITIVE -> PpaData.PPATestResult.TEST_RESULT_RAT_POSITIVE
             else -> PpaData.PPATestResult.TEST_RESULT_UNKNOWN
         }
     }
diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/datadonation/analytics/modules/testresult/AnalyticsRATestResultDonorTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/datadonation/analytics/modules/testresult/AnalyticsRATestResultDonorTest.kt
index c2cd808c3..5557a2ee4 100644
--- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/datadonation/analytics/modules/testresult/AnalyticsRATestResultDonorTest.kt
+++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/datadonation/analytics/modules/testresult/AnalyticsRATestResultDonorTest.kt
@@ -65,13 +65,13 @@ class AnalyticsRATestResultDonorTest : BaseTest() {
 
     @Test
     fun `No donation when test result is INVALID`() = runBlockingTest {
-        every { testResultSettings.testResultAtRegistration } returns mockFlowPreference(CoronaTestResult.PCR_INVALID)
+        every { testResultSettings.testResultAtRegistration } returns mockFlowPreference(CoronaTestResult.RAT_INVALID)
         testResultDonor.beginDonation(TestRequest) shouldBe AnalyticsTestResultDonor.TestResultMetadataNoContribution
     }
 
     @Test
     fun `No donation when test result is REDEEMED`() = runBlockingTest {
-        every { testResultSettings.testResultAtRegistration } returns mockFlowPreference(CoronaTestResult.PCR_REDEEMED)
+        every { testResultSettings.testResultAtRegistration } returns mockFlowPreference(CoronaTestResult.RAT_REDEEMED)
         testResultDonor.beginDonation(TestRequest) shouldBe AnalyticsTestResultDonor.TestResultMetadataNoContribution
     }
 
@@ -98,7 +98,7 @@ class AnalyticsRATestResultDonorTest : BaseTest() {
                 testResultDonor.beginDonation(TestRequest) as AnalyticsTestResultDonor.TestResultMetadataContribution
             with(donation.testResultMetadata) {
                 riskLevelAtTestRegistration shouldBe PpaData.PPARiskLevel.RISK_LEVEL_LOW
-                testResult shouldBe PpaData.PPATestResult.TEST_RESULT_PENDING
+                testResult shouldBe PpaData.PPATestResult.TEST_RESULT_RAT_PENDING
                 hoursSinceTestRegistration shouldBe 24
                 hoursSinceHighRiskWarningAtTestRegistration shouldBe 1
                 daysSinceMostRecentDateAtRiskLevelAtTestRegistration shouldBe 1
@@ -110,14 +110,14 @@ class AnalyticsRATestResultDonorTest : BaseTest() {
     fun `Donation is collected when test result is POSITIVE`() {
         runBlockingTest {
             every { testResultSettings.testResultAtRegistration } returns
-                mockFlowPreference(CoronaTestResult.PCR_POSITIVE)
+                mockFlowPreference(CoronaTestResult.RAT_POSITIVE)
             every { testResultSettings.finalTestResultReceivedAt } returns mockFlowPreference(baseTime)
 
             val donation =
                 testResultDonor.beginDonation(TestRequest) as AnalyticsTestResultDonor.TestResultMetadataContribution
             with(donation.testResultMetadata) {
                 riskLevelAtTestRegistration shouldBe PpaData.PPARiskLevel.RISK_LEVEL_LOW
-                testResult shouldBe PpaData.PPATestResult.TEST_RESULT_POSITIVE
+                testResult shouldBe PpaData.PPATestResult.TEST_RESULT_RAT_POSITIVE
                 hoursSinceTestRegistration shouldBe 0
                 hoursSinceHighRiskWarningAtTestRegistration shouldBe 1
                 daysSinceMostRecentDateAtRiskLevelAtTestRegistration shouldBe 1
@@ -129,14 +129,14 @@ class AnalyticsRATestResultDonorTest : BaseTest() {
     fun `Donation is collected when test result is NEGATIVE`() {
         runBlockingTest {
             every { testResultSettings.testResultAtRegistration } returns
-                mockFlowPreference(CoronaTestResult.PCR_NEGATIVE)
+                mockFlowPreference(CoronaTestResult.RAT_NEGATIVE)
             every { testResultSettings.finalTestResultReceivedAt } returns mockFlowPreference(baseTime)
 
             val donation =
                 testResultDonor.beginDonation(TestRequest) as AnalyticsTestResultDonor.TestResultMetadataContribution
             with(donation.testResultMetadata) {
                 riskLevelAtTestRegistration shouldBe PpaData.PPARiskLevel.RISK_LEVEL_LOW
-                testResult shouldBe PpaData.PPATestResult.TEST_RESULT_NEGATIVE
+                testResult shouldBe PpaData.PPATestResult.TEST_RESULT_RAT_NEGATIVE
                 hoursSinceTestRegistration shouldBe 0
                 hoursSinceHighRiskWarningAtTestRegistration shouldBe 1
                 daysSinceMostRecentDateAtRiskLevelAtTestRegistration shouldBe 1
@@ -147,7 +147,7 @@ class AnalyticsRATestResultDonorTest : BaseTest() {
     @Test
     fun `Scenario 1 LowRisk`() = runBlockingTest {
         with(testResultSettings) {
-            every { testResultAtRegistration } returns mockFlowPreference(CoronaTestResult.PCR_NEGATIVE)
+            every { testResultAtRegistration } returns mockFlowPreference(CoronaTestResult.RAT_NEGATIVE)
             every { finalTestResultReceivedAt } returns mockFlowPreference(
                 Instant.parse("2021-03-20T20:00:00Z")
             )
@@ -161,7 +161,7 @@ class AnalyticsRATestResultDonorTest : BaseTest() {
         val donation =
             testResultDonor.beginDonation(TestRequest) as AnalyticsTestResultDonor.TestResultMetadataContribution
         with(donation.testResultMetadata) {
-            testResult shouldBe PpaData.PPATestResult.TEST_RESULT_NEGATIVE
+            testResult shouldBe PpaData.PPATestResult.TEST_RESULT_RAT_NEGATIVE
             hoursSinceTestRegistration shouldBe 20
             riskLevelAtTestRegistration shouldBe PpaData.PPARiskLevel.RISK_LEVEL_LOW
             hoursSinceHighRiskWarningAtTestRegistration shouldBe 1
@@ -172,7 +172,7 @@ class AnalyticsRATestResultDonorTest : BaseTest() {
     @Test
     fun `Scenario 2 HighRisk`() = runBlockingTest {
         with(testResultSettings) {
-            every { testResultAtRegistration } returns mockFlowPreference(CoronaTestResult.PCR_POSITIVE)
+            every { testResultAtRegistration } returns mockFlowPreference(CoronaTestResult.RAT_POSITIVE)
             every { finalTestResultReceivedAt } returns mockFlowPreference(
                 Instant.parse("2021-03-20T20:00:00Z")
             )
@@ -187,7 +187,7 @@ class AnalyticsRATestResultDonorTest : BaseTest() {
         val donation =
             testResultDonor.beginDonation(TestRequest) as AnalyticsTestResultDonor.TestResultMetadataContribution
         with(donation.testResultMetadata) {
-            testResult shouldBe PpaData.PPATestResult.TEST_RESULT_POSITIVE
+            testResult shouldBe PpaData.PPATestResult.TEST_RESULT_RAT_POSITIVE
             hoursSinceTestRegistration shouldBe 20 // hours
             riskLevelAtTestRegistration shouldBe PpaData.PPARiskLevel.RISK_LEVEL_HIGH
             hoursSinceHighRiskWarningAtTestRegistration shouldBe 1
-- 
GitLab