Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(SDK-4183): changes normalisation to follow LP logic #700

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -81,11 +81,20 @@ class EventAdapter(
return items
.filterNotNull()
.map { productMap: Map<String, Any> ->
val normalisedMap = productMap.map {
Utils.getNormalizedName(it.key) to it.value
}.toMap()

TriggerValue(normalisedMap[Utils.getNormalizedName(propertyName)])
var op = productMap[propertyName]
CTLalit marked this conversation as resolved.
Show resolved Hide resolved
CTLalit marked this conversation as resolved.
Show resolved Hide resolved

if (op == null) {
op = productMap[Utils.getNormalizedName(propertyName)]
}

if (op == null) {
val normalisedMap = productMap.map {
Utils.getNormalizedName(it.key) to it.value
}.toMap()
op = normalisedMap[Utils.getNormalizedName(propertyName)]
}
TriggerValue(op)
}.filter { it.value != null }
}

Expand All @@ -110,22 +119,35 @@ class EventAdapter(

@VisibleForTesting
internal fun getActualPropertyValue(propertyName: String): Any? {
val normalisedMap = eventProperties.map { item ->
Utils.getNormalizedName(item.key) to item.value
}.toMap()

var value = normalisedMap[Utils.getNormalizedName(propertyName)]
var value = evaluateActualPropertyValue(propertyName)

if (value == null) {
value = when (propertyName) {
CLTAP_PROP_CAMPAIGN_ID -> eventProperties[NOTIFICATION_ID_TAG]
NOTIFICATION_ID_TAG -> eventProperties[CLTAP_PROP_CAMPAIGN_ID]
CLTAP_PROP_VARIANT -> eventProperties[INAPP_WZRK_PIVOT]
INAPP_WZRK_PIVOT -> eventProperties[CLTAP_PROP_VARIANT]
else -> systemPropToKey[propertyName]?.let { eventProperties[it] }
CLTAP_PROP_CAMPAIGN_ID -> evaluateActualPropertyValue(NOTIFICATION_ID_TAG)
NOTIFICATION_ID_TAG -> evaluateActualPropertyValue(CLTAP_PROP_CAMPAIGN_ID)
CLTAP_PROP_VARIANT -> evaluateActualPropertyValue(INAPP_WZRK_PIVOT)
INAPP_WZRK_PIVOT -> evaluateActualPropertyValue(CLTAP_PROP_VARIANT)
else -> systemPropToKey[propertyName]?.let { evaluateActualPropertyValue(it) }
}
}

return value
}

private fun evaluateActualPropertyValue(propertyName: String): Any? {
CTLalit marked this conversation as resolved.
Show resolved Hide resolved
var value = eventProperties[propertyName]

if (value == null) {
value = eventProperties[Utils.getNormalizedName(propertyName)]
CTLalit marked this conversation as resolved.
Show resolved Hide resolved
}

if (value == null) {
val normalisedMap = eventProperties.map { item ->
Utils.getNormalizedName(item.key) to item.value
}.toMap()
value = normalisedMap[Utils.getNormalizedName(propertyName)]
}
return value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,40 @@ class EventAdapterTest : BaseTestCase() {
assertTrue { expected1.isList() }
}

@Test
fun testGetPropertyPresentNormalisationsExactMatch() {
// Arrange
val eventProperties = mapOf(
"fullname" to "John",
"full name" to "Lenon",
"FullName" to "Augustus",
"age" to 30
)
val eventAdapter = EventAdapter("eventName", eventProperties)

// Act
val result = eventAdapter.getPropertyValue("fullname")
val expected = TriggerValue("John")

// Assert
assertNotNull(result)
assertEquals(expected.stringValue(), result.stringValue())
assertNull(result.numberValue())
assertNull(result.listValue())
assertFalse { expected.isList() }

// Act
val result1 = eventAdapter.getPropertyValue("full name")
val expected1 = TriggerValue("Lenon")

// Assert
assertNotNull(result1)
assertEquals(expected1.stringValue(), result1.stringValue())
assertNull(result1.numberValue())
assertNull(result1.listValue())
assertFalse { expected1.isList() }
}

@Test
fun testGetPropertyMissing() {
// Arrange
Expand Down
Loading