From 04f30791a35bbfd0c0ba3c1cc0bcb6f648d0a5e9 Mon Sep 17 00:00:00 2001
From: chris-cwa <69595386+chris-cwa@users.noreply.github.com>
Date: Tue, 8 Jun 2021 13:23:20 +0200
Subject: [PATCH] Fixed DCC Server Module (EXPOSUREAPP-7457) (#3374)

* fixed components path

* fixed dcc server di

* + api test

Co-authored-by: Matthias Urhahn <matthias.urhahn@sap.com>
---
 .../server/CovidCertificateApiV1.kt           |  2 +-
 .../server/CovidCertificateModule.kt          |  3 +
 .../server/CovidCertificateApiV1Test.kt       | 67 +++++++++++++++++++
 3 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 Corona-Warn-App/src/test/java/de/rki/coronawarnapp/covidcertificate/server/CovidCertificateApiV1Test.kt

diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/server/CovidCertificateApiV1.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/server/CovidCertificateApiV1.kt
index 29e2b32e8..a8ec6a371 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/server/CovidCertificateApiV1.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/server/CovidCertificateApiV1.kt
@@ -34,7 +34,7 @@ interface CovidCertificateApiV1 {
         }
     }
 
-    @POST("/version/v1/publicKey")
+    @POST("/version/v1/dcc")
     suspend fun getComponents(
         @Body requestBody: ComponentsRequest
     ): Response<ComponentsResponse>
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/server/CovidCertificateModule.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/server/CovidCertificateModule.kt
index 47ca09e5f..16ff646f6 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/server/CovidCertificateModule.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/server/CovidCertificateModule.kt
@@ -7,6 +7,7 @@ import de.rki.coronawarnapp.environment.covidcertificate.DCCHttpClient
 import de.rki.coronawarnapp.environment.covidcertificate.DCCServerUrl
 import okhttp3.OkHttpClient
 import retrofit2.Retrofit
+import retrofit2.converter.gson.GsonConverterFactory
 
 @Module
 class CovidCertificateModule {
@@ -16,10 +17,12 @@ class CovidCertificateModule {
     fun apiV1(
         @DCCHttpClient httpClient: OkHttpClient,
         @DCCServerUrl url: String,
+        gsonConverterFactory: GsonConverterFactory
     ): CovidCertificateApiV1 {
         return Retrofit.Builder()
             .client(httpClient)
             .baseUrl(url)
+            .addConverterFactory(gsonConverterFactory)
             .build()
             .create(CovidCertificateApiV1::class.java)
     }
diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/covidcertificate/server/CovidCertificateApiV1Test.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/covidcertificate/server/CovidCertificateApiV1Test.kt
new file mode 100644
index 000000000..07a535264
--- /dev/null
+++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/covidcertificate/server/CovidCertificateApiV1Test.kt
@@ -0,0 +1,67 @@
+package de.rki.coronawarnapp.covidcertificate.server
+
+import de.rki.coronawarnapp.http.HttpModule
+import io.kotest.matchers.shouldBe
+import io.mockk.MockKAnnotations
+import kotlinx.coroutines.runBlocking
+import okhttp3.mockwebserver.MockWebServer
+import org.junit.jupiter.api.AfterEach
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+import testhelpers.BaseTest
+import testhelpers.extensions.toJsonResponse
+import java.util.concurrent.TimeUnit
+
+class CovidCertificateApiV1Test : BaseTest() {
+
+    private lateinit var webServer: MockWebServer
+    private lateinit var serverAddress: String
+
+    @BeforeEach
+    fun setup() {
+        MockKAnnotations.init(this)
+
+        webServer = MockWebServer()
+        webServer.start()
+        serverAddress = "http://${webServer.hostName}:${webServer.port}"
+    }
+
+    @AfterEach
+    fun teardown() {
+        webServer.shutdown()
+    }
+
+    private fun createAPI(): CovidCertificateApiV1 {
+        val httpModule = HttpModule()
+
+        return CovidCertificateModule().let {
+            val downloadHttpClient = httpModule.defaultHttpClient()
+            it.apiV1(
+                httpClient = downloadHttpClient,
+                url = serverAddress,
+                gsonConverterFactory = httpModule.provideGSONConverter()
+            )
+        }
+    }
+
+    @Test
+    fun `test upload`(): Unit = runBlocking {
+        val api = createAPI()
+        """
+            {
+            
+            }
+        """.toJsonResponse().apply { webServer.enqueue(this) }
+
+        api.sendPublicKey(
+            CovidCertificateApiV1.PublicKeyUploadRequest(
+                registrationToken = "token1",
+                publicKey = "key1"
+            )
+        )
+
+        webServer.takeRequest(5, TimeUnit.SECONDS)!!.apply {
+            path shouldBe "/version/v1/publicKey"
+        }
+    }
+}
-- 
GitLab