@@ -25,6 +25,7 @@ import kotlinx.coroutines.flow.toList
25
25
import kotlinx.coroutines.test.runTest
26
26
import org.json.JSONArray
27
27
import org.junit.Assert.assertEquals
28
+ import org.junit.Assert.assertFalse
28
29
import org.junit.Assert.assertTrue
29
30
import org.junit.Before
30
31
import org.junit.Test
@@ -238,6 +239,34 @@ class RoktKitTests {
238
239
assertTrue(result.containsKey(" key3" ))
239
240
}
240
241
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 ,
" [email protected] " )
247
+ userIdentities.put(
IdentityType .
Other ,
" [email protected] " )
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
+
241
270
@Test
242
271
fun testSetSdkWrapper_correctlySetsRoktFramework () {
243
272
mockkObject(Rokt )
@@ -530,6 +559,44 @@ class RoktKitTests {
530
559
unmockkObject(Rokt )
531
560
}
532
561
562
+ @Test
563
+ fun TestverifyHashedEmail_removes_when_emailsha256_is_present () {
564
+ val attributes = mutableMapOf (
565
+
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
+
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(
" [email protected] " , attributes[
" email" ])
597
+ assertFalse(attributes.containsKey(" emailsha256" ))
598
+ }
599
+
533
600
internal inner class TestCoreCallbacks : CoreCallbacks {
534
601
override fun isBackgrounded (): Boolean = false
535
602
override fun getUserBucket (): Int = 0
0 commit comments