@@ -25,6 +25,7 @@ import kotlinx.coroutines.flow.toList
2525import kotlinx.coroutines.test.runTest
2626import org.json.JSONArray
2727import org.junit.Assert.assertEquals
28+ import org.junit.Assert.assertFalse
2829import org.junit.Assert.assertTrue
2930import org.junit.Before
3031import org.junit.Test
@@ -238,6 +239,34 @@ class RoktKitTests {
238239 assertTrue(result.containsKey(" key3" ))
239240 }
240241
242+ @Test
243+ fun test_addIdentityAttributes_When_userIdentities_Contain_other () {
244+ val mockFilterUser = mock(FilteredMParticleUser ::class .java)
245+ val userIdentities = HashMap <IdentityType , String >()
246+ userIdentities.put(IdentityType .Email , " TestEmail@gamil.com" )
247+ userIdentities.put(IdentityType .Other , " hashedEmail@123.com" )
248+ Mockito .`when `(mockFilterUser.userIdentities).thenReturn(userIdentities)
249+ val attributes: Map <String , String > = mapOf (
250+ " key1" to " value1" ,
251+ " key2" to " value2" ,
252+ " key3" to " value3"
253+ )
254+ val method: Method = RoktKit ::class .java.getDeclaredMethod(
255+ " addIdentityAttributes" ,
256+ Map ::class .java,
257+ FilteredMParticleUser ::class .java
258+ )
259+ method.isAccessible = true
260+ val result = method.invoke(roktKit, attributes, mockFilterUser) as Map <String , String >
261+ assertEquals(5 , result.size)
262+
263+ assertTrue(result.containsKey(" key1" ))
264+ assertTrue(result.containsKey(" key2" ))
265+ assertTrue(result.containsKey(" key3" ))
266+ assertTrue(result.containsKey(" email" ))
267+ assertTrue(result.containsKey(" emailsha256" ))
268+ }
269+
241270 @Test
242271 fun testSetSdkWrapper_correctlySetsRoktFramework () {
243272 mockkObject(Rokt )
@@ -530,6 +559,44 @@ class RoktKitTests {
530559 unmockkObject(Rokt )
531560 }
532561
562+ @Test
563+ fun TestverifyHashedEmail_removes_when_emailsha256_is_present () {
564+ val attributes = mutableMapOf (
565+ " email" to " user@example.com" ,
566+ " emailsha256" to " hashed_email_value" ,
567+ " other" to " Test"
568+ )
569+ val method: Method = RoktKit ::class .java.getDeclaredMethod(
570+ " verifyHashedEmail" ,
571+ MutableMap ::class .java
572+ )
573+ method.isAccessible = true
574+ method.invoke(roktKit, attributes)
575+
576+
577+ assertFalse(attributes.containsKey(" email" ))
578+ assertEquals(" hashed_email_value" , attributes[" emailsha256" ])
579+ assertEquals(" Test" , attributes[" other" ])
580+ }
581+
582+
583+ @Test
584+ fun TestverifyHashedEmail_removes_when_neither_emailsha256_nor_other_is_present () {
585+ val attributes = mutableMapOf (
586+ " email" to " user@example.com"
587+ )
588+
589+ val method: Method = RoktKit ::class .java.getDeclaredMethod(
590+ " verifyHashedEmail" ,
591+ MutableMap ::class .java
592+ )
593+ method.isAccessible = true
594+ method.invoke(roktKit, attributes)
595+
596+ assertEquals(" user@example.com" , attributes[" email" ])
597+ assertFalse(attributes.containsKey(" emailsha256" ))
598+ }
599+
533600 internal inner class TestCoreCallbacks : CoreCallbacks {
534601 override fun isBackgrounded (): Boolean = false
535602 override fun getUserBucket (): Int = 0
0 commit comments