diff --git a/datapipelines/src/main/kotlin/io/customer/sdk/CustomerIO.kt b/datapipelines/src/main/kotlin/io/customer/sdk/CustomerIO.kt index 3577d83f..b891ca24 100644 --- a/datapipelines/src/main/kotlin/io/customer/sdk/CustomerIO.kt +++ b/datapipelines/src/main/kotlin/io/customer/sdk/CustomerIO.kt @@ -198,7 +198,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 diff --git a/datapipelines/src/test/java/io/customer/datapipelines/DataPipelinesInteractionTests.kt b/datapipelines/src/test/java/io/customer/datapipelines/DataPipelinesInteractionTests.kt index cf4fe81f..d5af7174 100644 --- a/datapipelines/src/test/java/io/customer/datapipelines/DataPipelinesInteractionTests.kt +++ b/datapipelines/src/test/java/io/customer/datapipelines/DataPipelinesInteractionTests.kt @@ -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