Skip to content

Commit

Permalink
added a blank check
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 committed Dec 15, 2024
1 parent b8bfb37 commit 8176723
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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 ""
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

0 comments on commit 8176723

Please sign in to comment.