Skip to content
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

chore: handle the case of empty identifier #476

Merged
merged 1 commit into from
Dec 17, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class CustomerIO private constructor(
}

// this is the current userId that is identified in the SDK
val currentlyIdentifiedProfile = this.userId
val currentlyIdentifiedProfile = this.userId.takeUnless { it.isNullOrBlank() }
val isChangingIdentifiedProfile = currentlyIdentifiedProfile != null && currentlyIdentifiedProfile != userId
val isFirstTimeIdentifying = currentlyIdentifiedProfile == null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,29 @@ class DataPipelinesInteractionTests : JUnitTest() {
identifyEvent.traits.shouldBeEqualTo(emptyJsonObject)
}

@Test
fun identify_givenProfileAttributesAndNoIdentifier_expectSetNewProfileWithoutAttributes() {
val givenIdentifier = String.random

analytics.userId().shouldBeNull()
every { globalPreferenceStore.getDeviceToken() } returns String.random

sdkInstance.profileAttributes = mapOf("first_name" to "Dana", "ageInYears" to 30)
analytics.userId() shouldBe ""
mahmoud-elmorabea marked this conversation as resolved.
Show resolved Hide resolved
sdkInstance.identify(givenIdentifier)

analytics.userId().shouldBeEqualTo(givenIdentifier)
analytics.traits().shouldBeEqualTo(emptyJsonObject)

outputReaderPlugin.identifyEvents.size shouldBeEqualTo 2
val identifyEvent = outputReaderPlugin.identifyEvents.lastOrNull()
identifyEvent.shouldNotBeNull()
identifyEvent.userId.shouldBeEqualTo(givenIdentifier)
identifyEvent.traits.shouldBeEqualTo(emptyJsonObject)

outputReaderPlugin.trackEvents.size shouldBeEqualTo 1
}

@Test
fun identify_givenIdentifierWithMap_expectSetNewProfileWithAttributes() {
val givenIdentifier = String.random
Expand Down
Loading