Coverage Summary for Class: MindboxServiceGenerator (cloud.mindbox.mobile_sdk.network)

Class Method, % Branch, % Line, % Instruction, %
MindboxServiceGenerator 80% (4/5) 90% (9/10) 83.3% (40/48)
MindboxServiceGenerator$1 100% (1/1) 100% (2/2) 100% (18/18)
MindboxServiceGenerator$1$1 100% (1/1) 100% (1/1) 100% (11/11)
MindboxServiceGenerator$addToRequestQueue$1 100% (1/1) 100% (4/4) 100% (24/24)
MindboxServiceGenerator$addToRequestQueue$2 0% (0/1) 0% (0/4) 0% (0/18)
MindboxServiceGenerator$bindRequestQueueWithMindboxScope$2$1 0% (0/1) 0% (0/1) 0% (0/6)
MindboxServiceGenerator$bindRequestQueueWithMindboxScope$2$1$1 0% (0/1) 0% (0/1) 0% (0/3)
MindboxServiceGenerator$logMindboxRequest$1 100% (1/1) 50% (2/4) 100% (8/8) 96.5% (110/114)
Total 66.7% (8/12) 50% (2/4) 77.4% (24/31) 83.9% (203/242)


 package cloud.mindbox.mobile_sdk.network
 
 import cloud.mindbox.mobile_sdk.Mindbox
 import cloud.mindbox.mobile_sdk.di.MindboxDI
 import cloud.mindbox.mobile_sdk.logger.mindboxLogD
 import cloud.mindbox.mobile_sdk.models.MindboxRequest
 import cloud.mindbox.mobile_sdk.models.withMaskedTrackingIds
 import cloud.mindbox.mobile_sdk.utils.LoggingExceptionHandler
 import com.android.volley.Request
 import com.android.volley.RequestQueue
 import com.android.volley.VolleyLog
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.suspendCancellableCoroutine
 
 internal class MindboxServiceGenerator(private val requestQueue: RequestQueue) {
 
     init {
         LoggingExceptionHandler.runCatching {
             VolleyLog.DEBUG = MindboxDI.appModule.isDebug()
             Mindbox.mindboxScope.launch {
                 bindRequestQueueWithMindboxScope()
             }
         }
     }
 
     private suspend fun bindRequestQueueWithMindboxScope() =
         suspendCancellableCoroutine<Unit> { continuation ->
             continuation.invokeOnCancellation {
                 requestQueue.cancelAll { request -> request !is WebViewContentRequest }
             }
         }
 
     internal fun addToRequestQueue(request: MindboxRequest) = LoggingExceptionHandler.runCatching {
         requestQueue.let { requestQueue ->
             requestQueue.add(request)
             logMindboxRequest(request)
         }
     }
 
     internal fun addToRequestQueue(request: Request<*>) = LoggingExceptionHandler.runCatching {
         requestQueue.add(request)
         mindboxLogD(
             """
             ---> Method: ${request.method} ${request.url}
             ---> End of request
             """.trimIndent()
         )
     }
 
     private fun logMindboxRequest(request: MindboxRequest) {
         LoggingExceptionHandler.runCatching {
             val builder = StringBuilder()
             builder.appendLine("---> Method: ${request.methodType} ${request.fullUrl}")
             builder.appendLine(request.headers
                 .map { (key, value) -> "$key: $value" }
                 .joinToString(separator = System.getProperty("line.separator") ?: "\n"))
             request.jsonRequest?.let { body -> builder.appendLine(body.toString().withMaskedTrackingIds()) }
             builder.append("---> End of request")
 
             mindboxLogD(builder.toString())
         }
     }
 }