Updated on 2026-08-14
This commit is contained in:
commit
a7d501adc9
2 changed files with 65 additions and 2 deletions
|
|
@ -6,11 +6,22 @@ package com.tangem.core.analytics.models
|
|||
open class AnalyticsEvent(
|
||||
val category: String,
|
||||
val event: String,
|
||||
val params: Map<String, String> = mapOf(),
|
||||
params: Map<String, String> = mapOf(),
|
||||
) {
|
||||
var params: Map<String, String> = params
|
||||
private set
|
||||
|
||||
val id: String = "[$category] $event"
|
||||
|
||||
fun withParams(newParams: Map<String, String>) = AnalyticsEvent(category, event, newParams)
|
||||
/**
|
||||
* Enriches this event with [newParams] and returns the same instance, preserving the concrete
|
||||
* runtime type so that marker interfaces survive enrichment and the event can still be routed
|
||||
* by the analytics filters and handlers.
|
||||
*/
|
||||
fun withParams(newParams: Map<String, String>): AnalyticsEvent {
|
||||
params = newParams
|
||||
return this
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
package com.tangem.core.analytics.filter
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.tangem.core.analytics.api.AnalyticsHandler
|
||||
import com.tangem.core.analytics.models.AnalyticsEvent
|
||||
import com.tangem.core.analytics.models.AppsFlyerIncludedEvent
|
||||
import com.tangem.core.analytics.models.AppsFlyerOnlyEvent
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
internal class AppsFlyerEventFilterRoutingTest {
|
||||
|
||||
private val filter = AppsFlyerEventFilter()
|
||||
|
||||
private class AppsFlyerOnlyTestEvent :
|
||||
AnalyticsEvent(category = "Test", event = "OnlyEvent"), AppsFlyerOnlyEvent
|
||||
|
||||
private class AppsFlyerIncludedTestEvent :
|
||||
AnalyticsEvent(category = "Test", event = "IncludedEvent"), AppsFlyerIncludedEvent
|
||||
|
||||
@Test
|
||||
fun `withParams keeps AppsFlyerOnlyEvent routable to AppsFlyer`() {
|
||||
val event: AnalyticsEvent = AppsFlyerOnlyTestEvent()
|
||||
|
||||
val enriched = event.withParams(mapOf("key" to "value"))
|
||||
|
||||
assertThat(filter.canBeAppliedTo(enriched)).isTrue()
|
||||
assertThat(enriched.params).containsEntry("key", "value")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `withParams keeps AppsFlyerIncludedEvent routable to AppsFlyer`() {
|
||||
val event: AnalyticsEvent = AppsFlyerIncludedTestEvent()
|
||||
|
||||
val enriched = event.withParams(mapOf("key" to "value"))
|
||||
|
||||
assertThat(filter.canBeAppliedTo(enriched)).isTrue()
|
||||
assertThat(enriched.params).containsEntry("key", "value")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `enriched AppsFlyerOnlyEvent is consumable only by the AppsFlyer handler`() {
|
||||
val enriched = (AppsFlyerOnlyTestEvent() as AnalyticsEvent).withParams(emptyMap())
|
||||
|
||||
val appsFlyerHandler = mockk<AnalyticsHandler> { every { id() } returns "AppsFlyer" }
|
||||
val otherHandler = mockk<AnalyticsHandler> { every { id() } returns "Amplitude" }
|
||||
|
||||
assertThat(filter.canBeConsumedByHandler(appsFlyerHandler, enriched)).isTrue()
|
||||
assertThat(filter.canBeConsumedByHandler(otherHandler, enriched)).isFalse()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue