Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/main/kotlin/com/mparticle/kits/RoktKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class RoktKit :
val userAttributes = mutableMapOf<String, String>()
for ((key, value) in attributes) {
val hashKey = KitUtils.hashForFiltering(key)
if (!kitConfiguration.mUserAttributeFilters.get(hashKey)) {
if (kitConfiguration.mUserAttributeFilters.get(hashKey, true)) {
userAttributes[key] = value
}
}
Expand Down
79 changes: 77 additions & 2 deletions src/test/kotlin/com/mparticle/kits/RoktKitTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class RoktKitTests {
val filteredKey: String = KitUtils.hashForFiltering("ShouldFilter").toString()
val filteredKey2: String = KitUtils.hashForFiltering("ShouldFilter_key_2").toString()
jsonObject.put(filteredKey, 0)
jsonObject.put(filteredKey2, 1)
jsonObject.put(filteredKey2, 0)
} catch (e: Exception) {
println("Exception occurred: ${e.message}")
}
Expand Down Expand Up @@ -402,6 +402,81 @@ class RoktKitTests {
unmockkObject(Rokt)
}

@Test
fun test_prepareFinalAttributes_includesAttributeWhenFilterValueIsTrue() {
// Arrange
mockkObject(Rokt)
val capturedAttributesSlot = slot<Map<String, String>>()
every {
Rokt.execute(
any<String>(),
capture(capturedAttributesSlot),
any<Rokt.RoktCallback>(),
null,
null,
null,
)
} just runs

val mockFilterUser = mock(FilteredMParticleUser::class.java)
Mockito.`when`(mockFilterUser.userIdentities).thenReturn(HashMap())
Mockito.`when`(mockFilterUser.id).thenReturn(12345L)

val userAttributes = HashMap<String, Any?>()
userAttributes["attr_non_null_string"] = "value"
userAttributes["attr_null"] = null
userAttributes["attr_non_string"] = 123
userAttributes["user_key"] = "1231545"
Mockito.`when`(mockFilterUser.userAttributes).thenReturn(userAttributes)
// Set up the configuration with our test filters
val jsonObject = JSONObject()
try {
val filteredKey: String = KitUtils.hashForFiltering("ShouldFilter").toString()
val filteredKey2: String = KitUtils.hashForFiltering("ShouldFilter_key_2").toString()
jsonObject.put(filteredKey, 1)
jsonObject.put(filteredKey2, 0)
} catch (e: Exception) {
println("Exception occurred: ${e.message}")
}
val json = JSONObject()
json.put("ua", jsonObject)
roktKit.configuration = MockKitConfiguration.createKitConfiguration(JSONObject().put("hs", json))
val inputAttributes: Map<String, String> = mapOf(
"key1" to "value1",
"key2" to "value2",
"key3" to "value3",
"user_key" to "2223333",
"ShouldFilter" to "testData"
)
// Act
roktKit.execute(
viewName = "test",
attributes = inputAttributes,
mpRoktEventCallback = null,
placeHolders = null,
fontTypefaces = null,
filterUser = mockFilterUser,
mpRoktConfig = null,
)

// Assert
val capturedAttributes = capturedAttributesSlot.captured


assertEquals(8, capturedAttributes.size)
assertEquals("value", capturedAttributes["attr_non_null_string"])
assertEquals("123", capturedAttributes["attr_non_string"])
assertEquals("2223333", capturedAttributes["user_key"])
assertEquals("value1", capturedAttributes["key1"])
assertEquals("value2", capturedAttributes["key2"])
assertEquals("value3", capturedAttributes["key3"])
assertEquals("12345", capturedAttributes["mpid"])

assertTrue(capturedAttributes.containsKey("ShouldFilter"))
assertFalse(capturedAttributes.containsKey("ShouldFilter_key_2"))
unmockkObject(Rokt)
}

private inner class TestKitManager :
KitManagerImpl(context, null, TestCoreCallbacks(), mock(MParticleOptions::class.java)) {
var attributes = HashMap<String, String>()
Expand Down Expand Up @@ -1012,7 +1087,7 @@ class RoktKitTests {
val filteredKey: String = KitUtils.hashForFiltering("ShouldFilter").toString()
val filteredKey2: String = KitUtils.hashForFiltering("ShouldFilter_key_2").toString()
jsonObject.put(filteredKey, 0)
jsonObject.put(filteredKey2, 1)
jsonObject.put(filteredKey2, 0)
} catch (e: Exception) {
println("Exception occurred: ${e.message}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ open class MockKitConfiguration : KitConfiguration() {
override fun get(key: Int, valueIfKeyNotFound: Boolean): Boolean {
print("SparseArray getting: $key")
return if (map.containsKey(key)) {
true
map[key] ?: valueIfKeyNotFound
} else {
valueIfKeyNotFound
}
Expand Down
Loading