Skip to content

Commit 29ee4a3

Browse files
feat: Map selected identity to emailsha256 (#58)
1 parent d7fb426 commit 29ee4a3

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

src/main/kotlin/com/mparticle/kits/RoktKit.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class RoktKit :
5757
Rokt.RoktCallback {
5858
private var applicationContext: Context? = null
5959
private var mpRoktEventCallback: MpRoktEventCallback? = null
60+
private var hashedEmailUserIdentityType: String? = null
6061
override fun getName(): String = NAME
6162

6263
override fun getInstance(): RoktKit = this
@@ -70,6 +71,7 @@ class RoktKit :
7071
if (KitUtils.isEmpty(roktTagId)) {
7172
throwOnKitCreateError(NO_ROKT_ACCOUNT_ID)
7273
}
74+
hashedEmailUserIdentityType = settings[HASHED_EMAIL_USER_IDENTITY_TYPE]
7375
applicationContext?.let {
7476
val manager = context.packageManager
7577
if (roktTagId != null) {
@@ -343,7 +345,11 @@ class RoktKit :
343345
if (filterUser != null) {
344346
for ((identityNumberKey, identityValue) in filterUser.userIdentities) {
345347
val identityType = getStringForIdentity(identityNumberKey)
346-
identityAttributes[identityType] = identityValue
348+
if (identityType.equals(hashedEmailUserIdentityType)) {
349+
identityAttributes["emailsha256"] = identityValue
350+
} else {
351+
identityAttributes[identityType] = identityValue
352+
}
347353
}
348354
}
349355
if (attributes != null) {
@@ -377,7 +383,7 @@ class RoktKit :
377383
}
378384

379385
private fun getStringForIdentity(identityType: IdentityType): String = when (identityType) {
380-
IdentityType.Other -> "emailsha256"
386+
IdentityType.Other -> "other"
381387
IdentityType.CustomerId -> "customerid"
382388
IdentityType.Facebook -> "facebook"
383389
IdentityType.Twitter -> "twitter"
@@ -413,6 +419,7 @@ class RoktKit :
413419

414420
const val NAME = "Rokt"
415421
const val ROKT_ACCOUNT_ID = "accountId"
422+
const val HASHED_EMAIL_USER_IDENTITY_TYPE = "hashedEmailUserIdentityType"
416423
const val MPID = "mpid"
417424
const val NO_ROKT_ACCOUNT_ID = "No Rokt account ID provided, can't initialize kit."
418425
const val NO_APP_VERSION_FOUND = "No App version found, can't initialize kit."

src/test/kotlin/com/mparticle/kits/RoktKitTests.kt

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,69 @@ class RoktKitTests {
265265
assertTrue(result.containsKey("key2"))
266266
assertTrue(result.containsKey("key3"))
267267
assertTrue(result.containsKey("email"))
268-
assertTrue(result.containsKey("emailsha256"))
268+
assertTrue(result.containsKey("other"))
269+
}
270+
271+
@Test
272+
fun test_addIdentityAttributes_When_userIdentities_Other_map_To_Identity() {
273+
val mockFilterUser = mock(FilteredMParticleUser::class.java)
274+
val userIdentities = HashMap<IdentityType, String>()
275+
userIdentities.put(IdentityType.Email, "TestEmail@gamil.com")
276+
userIdentities.put(IdentityType.Other, "hashedEmail@123.com")
277+
Mockito.`when`(mockFilterUser.userIdentities).thenReturn(userIdentities)
278+
val attributes: Map<String, String> = mapOf(
279+
"key1" to "value1",
280+
"key2" to "value2",
281+
"key3" to "value3",
282+
)
283+
val hashedField = RoktKit::class.java.getDeclaredField("hashedEmailUserIdentityType")
284+
hashedField.isAccessible = true
285+
hashedField.set(roktKit, "Other")
286+
val method: Method = RoktKit::class.java.getDeclaredMethod(
287+
"addIdentityAttributes",
288+
Map::class.java,
289+
FilteredMParticleUser::class.java,
290+
)
291+
method.isAccessible = true
292+
val result = method.invoke(roktKit, attributes, mockFilterUser) as Map<String, String>
293+
assertEquals(5, result.size)
294+
295+
assertTrue(result.containsKey("key1"))
296+
assertTrue(result.containsKey("key2"))
297+
assertTrue(result.containsKey("key3"))
298+
assertTrue(result.containsKey("email"))
299+
assertTrue(result.containsKey("other"))
300+
}
301+
302+
@Test
303+
fun test_addIdentityAttributes_When_userIdentities_Unknown_map_To_Identity() {
304+
val mockFilterUser = mock(FilteredMParticleUser::class.java)
305+
val userIdentities = HashMap<IdentityType, String>()
306+
userIdentities.put(IdentityType.Email, "TestEmail@gamil.com")
307+
userIdentities.put(IdentityType.Other, "hashedEmail@123.com")
308+
Mockito.`when`(mockFilterUser.userIdentities).thenReturn(userIdentities)
309+
val attributes: Map<String, String> = mapOf(
310+
"key1" to "value1",
311+
"key2" to "value2",
312+
"key3" to "value3",
313+
)
314+
val hashedField = RoktKit::class.java.getDeclaredField("hashedEmailUserIdentityType")
315+
hashedField.isAccessible = true
316+
hashedField.set(roktKit, "Unknown")
317+
val method: Method = RoktKit::class.java.getDeclaredMethod(
318+
"addIdentityAttributes",
319+
Map::class.java,
320+
FilteredMParticleUser::class.java,
321+
)
322+
method.isAccessible = true
323+
val result = method.invoke(roktKit, attributes, mockFilterUser) as Map<String, String>
324+
assertEquals(5, result.size)
325+
326+
assertTrue(result.containsKey("key1"))
327+
assertTrue(result.containsKey("key2"))
328+
assertTrue(result.containsKey("key3"))
329+
assertTrue(result.containsKey("email"))
330+
assertTrue(result.containsKey("other"))
269331
}
270332

271333
@Test
@@ -672,7 +734,7 @@ class RoktKitTests {
672734

673735
override fun setIntegrationAttributes(kitId: Int, integrationAttributes: Map<String, String>) {}
674736

675-
override fun getIntegrationAttributes(kitId: Int): Map<String, String>? = null
737+
override fun getIntegrationAttributes(i: Int): Map<String, String>? = null
676738

677739
override fun getCurrentActivity(): WeakReference<Activity> = WeakReference(activity)
678740

0 commit comments

Comments
 (0)