Skip to content

Commit

Permalink
feat(visitor-id): keep visitor id during contact change and merchantI…
Browse files Browse the repository at this point in the history
…d change

SUITEDEV-36722

Co-authored-by: matusekma <[email protected]>
  • Loading branch information
LordAndras and matusekma committed Oct 3, 2024
1 parent 86e2bf0 commit f3bb2d7
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 50 deletions.
3 changes: 0 additions & 3 deletions emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ import io.mockk.spyk
import io.mockk.verify
import io.mockk.verifyOrder
import org.junit.Rule
import org.mockito.kotlin.mock
import java.util.concurrent.CountDownLatch

class EmarsysTest : AnnotationSpec() {
Expand Down Expand Up @@ -876,7 +875,6 @@ class EmarsysTest : AnnotationSpec() {
runBlockingOnCoreSdkThread {
verify {
mockMobileEngageApi.clearContact(completionListener)
mockPredictRestricted.clearVisitorId()
}
}
}
Expand All @@ -891,7 +889,6 @@ class EmarsysTest : AnnotationSpec() {
}
verify {
mockLoggingMobileEngageApi.clearContact(completionListener)
mockLoggingPredictRestricted.clearVisitorId()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ class PredictRestrictedTest : AnnotationSpec() {
Mockito.verify(mockPredictInternal).setContact(CONTACT_FIELD_ID, "contactId", null)
}

@Test
fun testPredict_clearContact_delegatesTo_Predict_Internal() {
predictRestricted.clearVisitorId()
Mockito.verify(mockPredictInternal).clearVisitorId()
}

@Test
fun testPredict_clearPredictOnlyContact_delegatesTo_Predict_Internal() {
val mockCompletionListener = mock<CompletionListener>()
Expand Down
3 changes: 0 additions & 3 deletions emarsys-sdk/src/main/java/com/emarsys/Emarsys.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ object Emarsys {
EmarsysDependencyInjection.mobileEngageApi()
.proxyApi(mobileEngage().concurrentHandlerHolder)
.clearContact(completionListener)
EmarsysDependencyInjection.predictRestrictedApi()
.proxyApi(mobileEngage().concurrentHandlerHolder)
.clearVisitorId()
}

private fun clearPredictOnlyContact(completionListener: CompletionListener?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,4 @@ class PredictRestricted(private val loggingInstance: Boolean = false) : PredictR
(if (loggingInstance) predict().loggingPredictInternal else predict().predictInternal)
.clearPredictOnlyContact(completionListener)
}

override fun clearVisitorId() {
(if (loggingInstance) predict().loggingPredictInternal else predict().predictInternal)
.clearVisitorId()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ interface PredictRestrictedApi {
fun setContact(contactFieldId: Int, contactFieldValue: String, completionListener: CompletionListener?)

fun clearPredictOnlyContact(completionListener: CompletionListener?)

fun clearVisitorId()
}
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@ class DefaultConfigInternalTest : AnnotationSpec() {

FeatureRegistry.isFeatureEnabled(InnerFeature.PREDICT) shouldBe true
verify(mockMobileEngageInternal).clearContact(null)
verify(mockPredictInternal).clearVisitorId()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ class DefaultConfigInternal(
override fun changeMerchantId(merchantId: String?, completionListener: CompletionListener?) {
if (FeatureRegistry.isFeatureEnabled(InnerFeature.MOBILE_ENGAGE)) {
mobileEngageInternal.clearContact(null)
predictInternal.clearVisitorId()
} else if (FeatureRegistry.isFeatureEnabled(InnerFeature.PREDICT)) {
predictInternal.clearPredictOnlyContact(null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,15 @@ class DefaultPredictInternalTest : AnnotationSpec() {
}

@Test
fun testClearContact_shouldRemove_visitorIdFromKeyValueStore() {
predictInternal.clearVisitorId()

verify(mockKeyValueStore).remove("predict_visitor_id")
}

@Test
fun testClearPredictOnlyContact_shouldCall_requestManager() {
fun testClearPredictOnlyContact_shouldCall_requestManager_andShouldNotRemoveVisitorId() {
whenever(
mockPredictMultiIdRequestModelFactory.createClearContactRequestModel()
).thenReturn(mockRequestModel)

predictInternal.clearPredictOnlyContact(mockCompletionListener)

verify(mockRequestManager).submit(mockRequestModel, mockCompletionListener)
verifyNoInteractions(mockKeyValueStore)
}

@Test
Expand Down Expand Up @@ -250,13 +244,6 @@ class DefaultPredictInternalTest : AnnotationSpec() {
verifyNoInteractions(mockCompletionListener)
}

@Test
fun testClearPredictOnlyContact_shouldRemove_visitorIdFromKeyValueStore() {
predictInternal.clearPredictOnlyContact(mockCompletionListener)

verify(mockKeyValueStore).remove("predict_visitor_id")
}

@Test
fun testTrackCart_returnsShardId() {
predictInternal.trackCart(listOf()) shouldBe ID1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.emarsys.core.provider.uuid.UUIDProvider
import com.emarsys.core.request.RequestManager
import com.emarsys.core.response.ResponseModel
import com.emarsys.core.shard.ShardModel
import com.emarsys.core.storage.KeyValueStore
import com.emarsys.core.util.Assert
import com.emarsys.core.util.JsonUtils.fromMap
import com.emarsys.predict.api.model.CartItem
Expand Down Expand Up @@ -50,7 +49,6 @@ class DefaultPredictInternal(

private val uuidProvider: UUIDProvider = requestContext.uuidProvider
private val timestampProvider: TimestampProvider = requestContext.timestampProvider
private val keyValueStore: KeyValueStore = requestContext.keyValueStore

override fun setContact(
contactFieldId: Int,
Expand All @@ -73,17 +71,11 @@ class DefaultPredictInternal(
try {
val requestModel = predictMultiIdRequestModelFactory.createClearContactRequestModel()
requestManager.submit(requestModel, completionListener)

keyValueStore.remove(VISITOR_ID_KEY)
} catch (e: Exception) {
completionListener?.onCompleted(e)
}
}

override fun clearVisitorId() {
keyValueStore.remove(VISITOR_ID_KEY)
}

override fun trackCart(items: List<CartItem>): String {
val shard = ShardModel.Builder(timestampProvider, uuidProvider)
.type(TYPE_CART)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ class LoggingPredictInternal(private val klass: Class<*>) : PredictInternal {
debug(MethodNotAllowed(klass, callerMethodName, parameters))
}

override fun clearVisitorId() {
val callerMethodName = SystemUtils.getCallerMethodName()
debug(MethodNotAllowed(klass, callerMethodName, null))
}

override fun trackCart(items: List<CartItem>): String {
val parameters: Map<String, Any?> = mapOf(
"items" to items.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.emarsys.predict.api.model.RecommendationFilter
interface PredictInternal {
fun setContact(contactFieldId: Int, contactFieldValue: String, completionListener: CompletionListener?)
fun clearPredictOnlyContact(completionListener: CompletionListener?)
fun clearVisitorId()
fun trackCart(items: List<CartItem>): String
fun trackPurchase(orderId: String, items: List<CartItem>): String
fun trackItemView(itemId: String): String
Expand Down

0 comments on commit f3bb2d7

Please sign in to comment.