Skip to content
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 @@ -77,7 +77,7 @@ class ClientApiViewModel @Inject internal constructor(
action: String,
extras: Bundle,
): ActionRequest? {
val extrasMap: Map<String, String> = extras.toMap().mapValues { it.value.toString() }
val extrasMap = extras.toMap()
return try {
// Session must be created to be able to report invalid intents if mapping fails
if (createSessionIfRequiredUseCase(action)) {
Expand All @@ -86,7 +86,7 @@ class ClientApiViewModel @Inject internal constructor(
intentMapper(action = action, extras = extrasMap, project = getProject())
} catch (validationException: InvalidRequestException) {
Simber.e("Cannot parse intent data", validationException, tag = ORCHESTRATION)
simpleEventReporter.addInvalidIntentEvent(action, extrasMap)
simpleEventReporter.addInvalidIntentEvent(action, extrasMap.mapValues { it.value.toString() })
_showAlert.send(validationException.error)
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.simprints.feature.clientapi

import android.os.Bundle
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.core.os.bundleOf
import androidx.test.ext.junit.runners.*
import com.jraska.livedata.test
import com.simprints.core.domain.externalcredential.ExternalCredential
Expand Down Expand Up @@ -128,6 +129,22 @@ internal class ClientApiViewModelTest {
viewModel.newSessionCreated.test().assertHasValue()
}

@Test
fun `handleIntent ensures that contract version is preserved`() = runTest {
coEvery { createSessionIfRequiredUseCase.invoke(any()) } returns true
coEvery {
intentMapper.invoke(
action = any(),
extras = any(),
project = any(),
)
} returns mockk()

viewModel.handleIntent("action", bundleOf("contractVersion" to 42))

coVerify { intentMapper.invoke(any(), match { it["contractVersion"] == 42 }, any()) }
}

@Test
fun `handleIntent handles invalid intent`() = runTest {
coEvery { createSessionIfRequiredUseCase.invoke(any()) } returns false
Expand All @@ -139,9 +156,9 @@ internal class ClientApiViewModelTest {
)
} throws InvalidRequestException("Invalid intent")

viewModel.handleIntent("action", Bundle())
viewModel.handleIntent("action", bundleOf("contractVersion" to 42))

verify { simpleEventReporter.addInvalidIntentEvent("action", any()) }
verify { simpleEventReporter.addInvalidIntentEvent("action", any<Map<String, String>>()) }
viewModel.showAlert.test().assertHasValue()
}

Expand Down
Loading