From 9b3efeb3ae0314a1bfc072ec89c56b756dd67ba3 Mon Sep 17 00:00:00 2001 From: Shahroz Khan Date: Tue, 17 Dec 2024 23:46:00 +0500 Subject: [PATCH] chore: handle the case of empty identifier (#476) --- .../main/kotlin/io/customer/sdk/CustomerIO.kt | 2 +- .../DataPipelinesInteractionTests.kt | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/datapipelines/src/main/kotlin/io/customer/sdk/CustomerIO.kt b/datapipelines/src/main/kotlin/io/customer/sdk/CustomerIO.kt index 5d4dd245..44f0e2b0 100644 --- a/datapipelines/src/main/kotlin/io/customer/sdk/CustomerIO.kt +++ b/datapipelines/src/main/kotlin/io/customer/sdk/CustomerIO.kt @@ -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 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