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
53 changes: 30 additions & 23 deletions src/main/kotlin/com/mparticle/kits/RoktKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class RoktKit :
Rokt.RoktCallback {
private var applicationContext: Context? = null
private var mpRoktEventCallback: MpRoktEventCallback? = null
private var hashedEmailUserIdentityType: String? = null
override fun getName(): String = NAME

override fun getInstance(): RoktKit = this
Expand All @@ -70,6 +71,7 @@ class RoktKit :
if (KitUtils.isEmpty(roktTagId)) {
throwOnKitCreateError(NO_ROKT_ACCOUNT_ID)
}
hashedEmailUserIdentityType = settings[HASHED_EMAIL_USER_IDENTITY_TYPE]
applicationContext?.let {
val manager = context.packageManager
if (roktTagId != null) {
Expand Down Expand Up @@ -343,7 +345,11 @@ class RoktKit :
if (filterUser != null) {
for ((identityNumberKey, identityValue) in filterUser.userIdentities) {
val identityType = getStringForIdentity(identityNumberKey)
identityAttributes[identityType] = identityValue
if (identityType.equals(hashedEmailUserIdentityType)) {
identityAttributes["emailsha256"] = identityValue
} else {
identityAttributes[identityType] = identityValue
}
}
}
if (attributes != null) {
Expand Down Expand Up @@ -377,28 +383,28 @@ class RoktKit :
}

private fun getStringForIdentity(identityType: IdentityType): String = when (identityType) {
IdentityType.Other -> "emailsha256"
IdentityType.CustomerId -> "customerid"
IdentityType.Facebook -> "facebook"
IdentityType.Twitter -> "twitter"
IdentityType.Google -> "google"
IdentityType.Microsoft -> "microsoft"
IdentityType.Yahoo -> "yahoo"
IdentityType.Email -> "email"
IdentityType.Alias -> "alias"
IdentityType.FacebookCustomAudienceId -> "facebookcustomaudienceid"
IdentityType.Other2 -> "other2"
IdentityType.Other3 -> "other3"
IdentityType.Other4 -> "other4"
IdentityType.Other5 -> "other5"
IdentityType.Other6 -> "other6"
IdentityType.Other7 -> "other7"
IdentityType.Other8 -> "other8"
IdentityType.Other9 -> "other9"
IdentityType.Other10 -> "other10"
IdentityType.MobileNumber -> "mobilenumber"
IdentityType.PhoneNumber2 -> "phonenumber2"
IdentityType.PhoneNumber3 -> "phonenumber3"
IdentityType.Other -> "Other"
IdentityType.CustomerId -> "CustomerId"
IdentityType.Facebook -> "Facebook"
IdentityType.Twitter -> "Twitter"
IdentityType.Google -> "Google"
IdentityType.Microsoft -> "Microsoft"
IdentityType.Yahoo -> "Yahoo"
IdentityType.Email -> "Email"
IdentityType.Alias -> "Alias"
IdentityType.FacebookCustomAudienceId -> "FacebookCustomAudienceId"
IdentityType.Other2 -> "Other2"
IdentityType.Other3 -> "Other3"
IdentityType.Other4 -> "Other4"
IdentityType.Other5 -> "Other5"
IdentityType.Other6 -> "Other6"
IdentityType.Other7 -> "Other7"
IdentityType.Other8 -> "Other8"
IdentityType.Other9 -> "Other9"
IdentityType.Other10 -> "Other10"
IdentityType.MobileNumber -> "MobileNumber"
IdentityType.PhoneNumber2 -> "PhoneNumber2"
IdentityType.PhoneNumber3 -> "PhoneNumber3"
Comment on lines +386 to +407
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you reverted to capitalizing?

the attributes on rokt's site are all lowercase (and I'm not sure if casing matters)

https://docs.rokt.com/developers/integration-guides/rokt-ads/web-sdk/attributes/

else -> ""
}

Expand All @@ -413,6 +419,7 @@ class RoktKit :

const val NAME = "Rokt"
const val ROKT_ACCOUNT_ID = "accountId"
const val HASHED_EMAIL_USER_IDENTITY_TYPE = "hashedEmailUserIdentityType"
const val MPID = "mpid"
const val NO_ROKT_ACCOUNT_ID = "No Rokt account ID provided, can't initialize kit."
const val NO_APP_VERSION_FOUND = "No App version found, can't initialize kit."
Expand Down
76 changes: 69 additions & 7 deletions src/test/kotlin/com/mparticle/kits/RoktKitTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class RoktKitTests {
assertTrue(result.containsKey("key1"))
assertTrue(result.containsKey("key2"))
assertTrue(result.containsKey("key3"))
assertTrue(result.containsKey("email"))
assertTrue(result.containsKey("Email"))
}

@Test
Expand All @@ -165,7 +165,7 @@ class RoktKitTests {
"key1" to "value1",
"key2" to "value2",
"key3" to "value3",
"email" to "[email protected]",
"Email" to "[email protected]",
)
val method: Method = RoktKit::class.java.getDeclaredMethod(
"addIdentityAttributes",
Expand All @@ -179,13 +179,13 @@ class RoktKitTests {
assertTrue(result.containsKey("key1"))
assertTrue(result.containsKey("key2"))
assertTrue(result.containsKey("key3"))
assertTrue(result.containsKey("email"))
assertTrue(result.containsKey("Email"))
assertEquals(
mapOf(
"key1" to "value1",
"key2" to "value2",
"key3" to "value3",
"email" to "[email protected]",
"Email" to "[email protected]",
),
result,
)
Expand Down Expand Up @@ -217,7 +217,7 @@ class RoktKitTests {
method.isAccessible = true
val result = method.invoke(roktKit, null, mockFilterUser) as Map<String, String>
assertEquals(1, result.size)
assertEquals(mapOf("email" to "[email protected]"), result)
assertEquals(mapOf("Email" to "[email protected]"), result)
}

@Test
Expand Down Expand Up @@ -264,10 +264,72 @@ class RoktKitTests {
assertTrue(result.containsKey("key1"))
assertTrue(result.containsKey("key2"))
assertTrue(result.containsKey("key3"))
assertTrue(result.containsKey("email"))
assertTrue(result.containsKey("Email"))
assertTrue(result.containsKey("Other"))
}

@Test
fun test_addIdentityAttributes_When_userIdentities_Other_map_To_Identity() {
val mockFilterUser = mock(FilteredMParticleUser::class.java)
val userIdentities = HashMap<IdentityType, String>()
userIdentities.put(IdentityType.Email, "[email protected]")
userIdentities.put(IdentityType.Other, "[email protected]")
Mockito.`when`(mockFilterUser.userIdentities).thenReturn(userIdentities)
val attributes: Map<String, String> = mapOf(
"key1" to "value1",
"key2" to "value2",
"key3" to "value3",
)
val hashedField = RoktKit::class.java.getDeclaredField("hashedEmailUserIdentityType")
hashedField.isAccessible = true
hashedField.set(roktKit, "Other")
val method: Method = RoktKit::class.java.getDeclaredMethod(
"addIdentityAttributes",
Map::class.java,
FilteredMParticleUser::class.java,
)
method.isAccessible = true
val result = method.invoke(roktKit, attributes, mockFilterUser) as Map<String, String>
assertEquals(5, result.size)

assertTrue(result.containsKey("key1"))
assertTrue(result.containsKey("key2"))
assertTrue(result.containsKey("key3"))
assertTrue(result.containsKey("Email"))
assertTrue(result.containsKey("emailsha256"))
}

@Test
fun test_addIdentityAttributes_When_userIdentities_UNASSIGNED_map_To_Identity() {
val mockFilterUser = mock(FilteredMParticleUser::class.java)
val userIdentities = HashMap<IdentityType, String>()
userIdentities.put(IdentityType.Email, "[email protected]")
userIdentities.put(IdentityType.Other, "[email protected]")
Mockito.`when`(mockFilterUser.userIdentities).thenReturn(userIdentities)
val attributes: Map<String, String> = mapOf(
"key1" to "value1",
"key2" to "value2",
"key3" to "value3",
)
val hashedField = RoktKit::class.java.getDeclaredField("hashedEmailUserIdentityType")
hashedField.isAccessible = true
hashedField.set(roktKit, "UNASSIGNED")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be Unknown

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/mparticle-by-rokt/mPServer/pull/35784/files

I copied from Brian's PR in order to keep it consistent

val method: Method = RoktKit::class.java.getDeclaredMethod(
"addIdentityAttributes",
Map::class.java,
FilteredMParticleUser::class.java,
)
method.isAccessible = true
val result = method.invoke(roktKit, attributes, mockFilterUser) as Map<String, String>
assertEquals(5, result.size)

assertTrue(result.containsKey("key1"))
assertTrue(result.containsKey("key2"))
assertTrue(result.containsKey("key3"))
assertTrue(result.containsKey("Email"))
assertTrue(result.containsKey("Other"))
}

@Test
fun testSetSdkWrapper_correctlySetsRoktFramework() {
mockkObject(Rokt)
Expand Down Expand Up @@ -672,7 +734,7 @@ class RoktKitTests {

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

override fun getIntegrationAttributes(kitId: Int): Map<String, String>? = null
override fun getIntegrationAttributes(i: Int): Map<String, String>? = null

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

Expand Down
Loading