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
4 changes: 3 additions & 1 deletion src/main/kotlin/com/mparticle/kits/RoktKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ class RoktKit :
val finalAttributes = mutableMapOf<String, String>()
filterUser?.userAttributes?.let { userAttrs ->
for ((key, value) in userAttrs) {
finalAttributes[key] = value.toString()
if (value != null) {
finalAttributes[key] = value.toString()
}
Comment on lines +219 to +221
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @jamesnrokt . One question - In MP, we can set an attribute directly to be null using these user tags. In the example on our docs, https://docs.mparticle.com/developers/client-sdks/android/users/#set-user-tags, it uses platinum_member: NULL as the example.

In Rokt, is null not a valid value, and so we skip the setting of those attributes, as opposed to having the option to set them as null?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test for passing a null value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test for passing in a null value

I believe Rokt doesn't use null values. For something like platinum_member we'd do key value "membershipLevel": "platinum"

}
}

Expand Down
32 changes: 32 additions & 0 deletions src/test/kotlin/com/mparticle/kits/RoktKitTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,38 @@ class RoktKitTests {
// roktKit.configuration = KitConfiguration.createKitConfiguration(JSONObject().put("id", "-1"))
}

@Test
fun test_prepareFinalAttributes_filters_out_null_user_attributes() {
val mockFilterUser = mock(FilteredMParticleUser::class.java)
Mockito.`when`(mockFilterUser.userIdentities).thenReturn(HashMap())

// Include a null value and a non-null non-string value to verify toString() behavior
val userAttributes = HashMap<String, Any?>()
userAttributes["attr_non_null_string"] = "value"
userAttributes["attr_null"] = null
userAttributes["attr_non_string"] = 123
Mockito.`when`(mockFilterUser.userAttributes).thenReturn(userAttributes)

val method: Method = RoktKit::class.java.getDeclaredMethod(
"prepareFinalAttributes",
FilteredMParticleUser::class.java,
Map::class.java,
)
method.isAccessible = true

val inputAttributes: Map<String, String> = emptyMap()
val result = method.invoke(roktKit, mockFilterUser, inputAttributes) as Map<*, *>

// Should include only non-null user attributes, and convert non-string values via toString()
assertTrue(result.containsKey("attr_non_null_string"))
assertEquals("value", result["attr_non_null_string"])

assertFalse(result.containsKey("attr_null"))

assertTrue(result.containsKey("attr_non_string"))
assertEquals("123", result["attr_non_string"])
}

private inner class TestKitManager :
KitManagerImpl(context, null, TestCoreCallbacks(), mock(MParticleOptions::class.java)) {
var attributes = HashMap<String, String>()
Expand Down
Loading