From 8ecd77067e1370dc756afca3c6250ae38fe41435 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 8 Jun 2026 18:27:12 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../core/analytics/models/AnalyticsEvent.kt | 15 +++++- .../filter/AppsFlyerEventFilterRoutingTest.kt | 52 +++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 core/analytics/src/test/kotlin/com/tangem/core/analytics/filter/AppsFlyerEventFilterRoutingTest.kt diff --git a/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsEvent.kt b/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsEvent.kt index d259b2ba00..d890ac79f6 100644 --- a/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsEvent.kt +++ b/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsEvent.kt @@ -6,11 +6,22 @@ package com.tangem.core.analytics.models open class AnalyticsEvent( val category: String, val event: String, - val params: Map = mapOf(), + params: Map = mapOf(), ) { + var params: Map = params + private set + val id: String = "[$category] $event" - fun withParams(newParams: Map) = 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): AnalyticsEvent { + params = newParams + return this + } override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/core/analytics/src/test/kotlin/com/tangem/core/analytics/filter/AppsFlyerEventFilterRoutingTest.kt b/core/analytics/src/test/kotlin/com/tangem/core/analytics/filter/AppsFlyerEventFilterRoutingTest.kt new file mode 100644 index 0000000000..120c6fbd1e --- /dev/null +++ b/core/analytics/src/test/kotlin/com/tangem/core/analytics/filter/AppsFlyerEventFilterRoutingTest.kt @@ -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 { every { id() } returns "AppsFlyer" } + val otherHandler = mockk { every { id() } returns "Amplitude" } + + assertThat(filter.canBeConsumedByHandler(appsFlyerHandler, enriched)).isTrue() + assertThat(filter.canBeConsumedByHandler(otherHandler, enriched)).isFalse() + } +} \ No newline at end of file