-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add all identities from mp user to rokt attributes #24
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
Merged
Mansi-mParticle
merged 2 commits into
development
from
feat/SQDSDKS-7187-add-Identities-to-rokt
May 16, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import android.os.Build.VERSION | |
| import com.mparticle.AttributionError | ||
| import com.mparticle.AttributionResult | ||
| import com.mparticle.MParticle | ||
| import com.mparticle.MParticle.IdentityType | ||
| import com.mparticle.MParticleOptions | ||
| import com.mparticle.MParticleOptions.DataplanOptions | ||
| import com.mparticle.identity.IdentityApi | ||
|
|
@@ -98,186 +99,144 @@ class RoktKitTests { | |
| } | ||
|
|
||
| @Test | ||
| fun testFilterAttributes() { | ||
|
|
||
| // Create test attributes | ||
| fun test_addIdentityAttributes_When_userIdentities_IS_Null(){ | ||
| val mockFilterUser = Mockito.mock(FilteredMParticleUser::class.java) | ||
| val userIdentities = HashMap<IdentityType, String>() | ||
| Mockito.`when`(mockFilterUser.userIdentities).thenReturn(userIdentities) | ||
| val attributes: Map<String, String> = mapOf( | ||
| "ShouldFilter" to "shoudl_filter_value", | ||
| "ShouldFilter_key_2" to "ShouldFilter_value", | ||
| "allowed_key" to "allowed_value" | ||
| "key1" to "value1", | ||
| "key2" to "value2", | ||
| "key3" to "value3" | ||
| ) | ||
|
|
||
| // Get the private filterAttributes method using reflection | ||
| val method: Method = RoktKit::class.java.getDeclaredMethod( | ||
| "filterAttributes", | ||
| "addIdentityAttributes", | ||
| Map::class.java, | ||
| KitConfiguration::class.java | ||
| FilteredMParticleUser::class.java | ||
| ) | ||
| method.isAccessible = true | ||
| val result = method.invoke(roktKit, attributes, mockFilterUser) as Map<String, String> | ||
| assertEquals(3, result.size) | ||
|
|
||
| // Set up the configuration with our test filters | ||
| val jsonObject = JSONObject() | ||
| try { | ||
| val filteredKey:String =KitUtils.hashForFiltering("ShouldFilter").toString() | ||
| val allowedKey:String = KitUtils.hashForFiltering("ShouldFilter_key_2").toString() | ||
| jsonObject.put(filteredKey, 0) | ||
| jsonObject.put(allowedKey, 1) | ||
| } catch (e: Exception) { | ||
| println("Exception occurred: ${e.message}") | ||
| } | ||
|
|
||
| val json = JSONObject() | ||
| json.put("ea", jsonObject) | ||
|
|
||
|
|
||
| roktKit.configuration = MockKitConfiguration.createKitConfiguration(JSONObject().put("hs",json)) | ||
|
|
||
| // Invoke the method and get the result | ||
| val result = method.invoke(roktKit, attributes, roktKit.configuration) as Map<String, String> | ||
|
|
||
| // Verify the results | ||
| assertEquals(1, result.size) | ||
| assertTrue(result.containsKey("key1")) | ||
| assertTrue(result.containsKey("key2")) | ||
| assertTrue(result.containsKey("key3")) | ||
|
Comment on lines
+120
to
+122
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also have a test that checks the value as well? |
||
|
|
||
| assertFalse(result.containsKey("ShouldFilter")) | ||
| assertFalse(result.containsKey("ShouldFilter_key_2")) | ||
| assertTrue(result.containsKey("allowed_key")) | ||
| assertEquals("allowed_value", result["allowed_key"]) | ||
| } | ||
|
|
||
| @Test | ||
| fun testFilterAttributes_When_kitConfig_Attributes_IS_NULL() { | ||
|
|
||
| // Create test attributes | ||
| fun test_addIdentityAttributes_When_userIdentities_Contain_value(){ | ||
| val mockFilterUser = Mockito.mock(FilteredMParticleUser::class.java) | ||
| val userIdentities = HashMap<IdentityType, String>() | ||
| userIdentities.put(IdentityType.Email,"TestEmail@gamil.com") | ||
| Mockito.`when`(mockFilterUser.userIdentities).thenReturn(userIdentities) | ||
| val attributes: Map<String, String> = mapOf( | ||
| "filtered_key" to "filtered_value", | ||
| "allowed_key" to "allowed_value", | ||
| "another_allowed_key" to "another_allowed_value" | ||
| "key1" to "value1", | ||
| "key2" to "value2", | ||
| "key3" to "value3" | ||
| ) | ||
|
|
||
| // Get the private filterAttributes method using reflection | ||
| val method: Method = RoktKit::class.java.getDeclaredMethod( | ||
| "filterAttributes", | ||
| "addIdentityAttributes", | ||
| Map::class.java, | ||
| KitConfiguration::class.java | ||
| FilteredMParticleUser::class.java | ||
| ) | ||
| method.isAccessible = true | ||
| val result = method.invoke(roktKit, attributes, mockFilterUser) as Map<String, String> | ||
| assertEquals(4, result.size) | ||
|
|
||
| // Set up the configuration with our test filters | ||
| val jsonObject = JSONObject() | ||
| try { | ||
| val filteredKey:String =KitUtils.hashForFiltering("filtered_key").toString() | ||
| val allowedKey:String = KitUtils.hashForFiltering("allowed_key").toString() | ||
| jsonObject.put(filteredKey, 0) | ||
| jsonObject.put(allowedKey, 1) | ||
| } catch (e: Exception) { | ||
| println("Exception occurred: ${e.message}") | ||
| } | ||
|
|
||
| val json = JSONObject() | ||
| //here is invalid json key for filtering | ||
| json.put("aaa", jsonObject) | ||
| assertTrue(result.containsKey("key1")) | ||
| assertTrue(result.containsKey("key2")) | ||
| assertTrue(result.containsKey("key3")) | ||
| assertTrue(result.containsKey("email")) | ||
|
Comment on lines
+146
to
+149
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also have a test that checks the value as well? |
||
|
|
||
|
|
||
| roktKit.configuration = MockKitConfiguration.createKitConfiguration(JSONObject().put("hs",json)) | ||
|
|
||
| // Invoke the method and get the result | ||
| val result = method.invoke(roktKit, attributes, roktKit.configuration) as Map<String, String> | ||
|
|
||
| assertEquals(3, result.size) | ||
|
|
||
| assertTrue(result.containsKey("allowed_key")) | ||
| assertTrue(result.containsKey("filtered_key")) | ||
| assertTrue(result.containsKey("another_allowed_key")) | ||
| assertEquals("another_allowed_value", result["another_allowed_key"]) | ||
| } | ||
|
|
||
| @Test | ||
| fun testFilterAttributes_When_Attributes_IS_Empty() { | ||
|
|
||
| // Create test attributes | ||
| val emptyAttributes: Map<String, String> = emptyMap() | ||
|
|
||
|
|
||
| // Get the private filterAttributes method using reflection | ||
| fun test_addIdentityAttributes_When_userIdentities_And_attributes_contains_same_key(){ | ||
| val mockFilterUser = Mockito.mock(FilteredMParticleUser::class.java) | ||
| val userIdentities = HashMap<IdentityType, String>() | ||
| userIdentities.put(IdentityType.Email,"TestEmail@gamil.com") | ||
| Mockito.`when`(mockFilterUser.userIdentities).thenReturn(userIdentities) | ||
| val attributes: Map<String, String> = mapOf( | ||
| "key1" to "value1", | ||
| "key2" to "value2", | ||
| "key3" to "value3", | ||
| "email" to "abc@gmail.com" | ||
| ) | ||
| val method: Method = RoktKit::class.java.getDeclaredMethod( | ||
| "filterAttributes", | ||
| "addIdentityAttributes", | ||
| Map::class.java, | ||
| KitConfiguration::class.java | ||
| FilteredMParticleUser::class.java | ||
| ) | ||
| method.isAccessible = true | ||
| val result = method.invoke(roktKit, attributes, mockFilterUser) as Map<String, String> | ||
| assertEquals(4, result.size) | ||
|
|
||
| assertTrue(result.containsKey("key1")) | ||
| assertTrue(result.containsKey("key2")) | ||
| assertTrue(result.containsKey("key3")) | ||
| assertTrue(result.containsKey("email")) | ||
| assertEquals( | ||
| mapOf( | ||
| "key1" to "value1", | ||
| "key2" to "value2", | ||
| "key3" to "value3", | ||
| "email" to "TestEmail@gamil.com" | ||
| ), | ||
| result | ||
| ) | ||
| } | ||
|
|
||
| // Set up the configuration with our test filters | ||
| val jsonObject = JSONObject() | ||
| try { | ||
| val filteredKey:String =KitUtils.hashForFiltering("filtered_key").toString() | ||
| val allowedKey:String = KitUtils.hashForFiltering("allowed_key").toString() | ||
| jsonObject.put(filteredKey, 0) | ||
| jsonObject.put(allowedKey, 1) | ||
| } catch (e: Exception) { | ||
| println("Exception occurred: ${e.message}") | ||
| } | ||
|
|
||
| val json = JSONObject() | ||
| json.put("aaa", jsonObject) | ||
|
|
||
|
|
||
| roktKit.configuration = MockKitConfiguration.createKitConfiguration(JSONObject().put("hs",json)) | ||
|
|
||
| // Invoke the method and get the result | ||
| val result = method.invoke(roktKit, emptyAttributes, roktKit.configuration) as Map<String, String> | ||
|
|
||
| assertEquals(0, result.size) | ||
| @Test | ||
| fun testAddIdentityAttributes_bothNull() { | ||
| val method: Method = RoktKit::class.java.getDeclaredMethod( | ||
| "addIdentityAttributes", | ||
| Map::class.java, | ||
| FilteredMParticleUser::class.java | ||
| ) | ||
| method.isAccessible = true | ||
| val result = method.invoke(roktKit, null, null) as Map<String, String> | ||
| assertTrue(result.isEmpty()) | ||
| } | ||
|
|
||
| @Test | ||
| fun testFilterAttributes_When_attribute_different_value() { | ||
| fun testAddIdentityAttributes_nullAttributes_validUser() { | ||
| val mockFilterUser = Mockito.mock(FilteredMParticleUser::class.java) | ||
| val userIdentities = HashMap<IdentityType, String>() | ||
| userIdentities.put(IdentityType.Email,"TestEmail@gamil.com") | ||
| Mockito.`when`(mockFilterUser.userIdentities).thenReturn(userIdentities) | ||
| val method: Method = RoktKit::class.java.getDeclaredMethod( | ||
| "addIdentityAttributes", | ||
| Map::class.java, | ||
| FilteredMParticleUser::class.java | ||
| ) | ||
| method.isAccessible = true | ||
| val result = method.invoke(roktKit, null, mockFilterUser) as Map<String, String> | ||
| assertEquals(1, result.size) | ||
| assertEquals(mapOf("email" to "TestEmail@gamil.com"), result) | ||
| } | ||
|
|
||
| // Create test attributes | ||
| @Test | ||
| fun testAddIdentityAttributes_nullUser_returnsSameAttributes() { | ||
| val attributes: Map<String, String> = mapOf( | ||
| "filtered_key" to "filtered_value", | ||
| "allowed_key" to "allowed_value", | ||
| "another_allowed_key" to "another_allowed_value" | ||
| "key1" to "value1", | ||
| "key2" to "value2", | ||
| "key3" to "value3" | ||
| ) | ||
|
|
||
| // Get the private filterAttributes method using reflection | ||
| val method: Method = RoktKit::class.java.getDeclaredMethod( | ||
| "filterAttributes", | ||
| "addIdentityAttributes", | ||
| Map::class.java, | ||
| KitConfiguration::class.java | ||
| FilteredMParticleUser::class.java | ||
| ) | ||
| method.isAccessible = true | ||
|
|
||
| // Set up the configuration with our test filters | ||
| val jsonObject = JSONObject() | ||
| try { | ||
| val filteredKey:String =KitUtils.hashForFiltering("Test1").toString() | ||
| val allowedKey:String = KitUtils.hashForFiltering("Test2").toString() | ||
| jsonObject.put(filteredKey, 0) | ||
| jsonObject.put(allowedKey, 1) | ||
| } catch (e: Exception) { | ||
| println("Exception occurred: ${e.message}") | ||
| } | ||
|
|
||
| val json = JSONObject() | ||
| json.put("ea", jsonObject) | ||
|
|
||
|
|
||
| roktKit.configuration = MockKitConfiguration.createKitConfiguration(JSONObject().put("hs",json)) | ||
|
|
||
| // Invoke the method and get the result | ||
| val result = method.invoke(roktKit, attributes, roktKit.configuration) as Map<String, String> | ||
|
|
||
| // Verify the results | ||
| val result = method.invoke(roktKit, attributes, null) as Map<String, String> | ||
| assertEquals(3, result.size) | ||
|
|
||
| assertTrue(result.containsKey("filtered_key")) | ||
| assertTrue(result.containsKey("allowed_key")) | ||
| assertTrue(result.containsKey("another_allowed_key")) | ||
| assertEquals("another_allowed_value", result["another_allowed_key"]) | ||
| assertEquals("filtered_value", result["filtered_key"]) | ||
| assertEquals("allowed_value", result["allowed_key"]) | ||
| assertTrue(result.containsKey("key1")) | ||
| assertTrue(result.containsKey("key2")) | ||
| assertTrue(result.containsKey("key3")) | ||
| } | ||
|
|
||
|
|
||
|
|
||
| internal inner class TestCoreCallbacks : CoreCallbacks { | ||
| override fun isBackgrounded(): Boolean = false | ||
| override fun getUserBucket(): Int = 0 | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.