diff --git a/emarsys-e2e-test/src/androidTest/java/com/emarsys/EmarsysE2ETests.kt b/emarsys-e2e-test/src/androidTest/java/com/emarsys/EmarsysE2ETests.kt index 23403c7d..ad714210 100644 --- a/emarsys-e2e-test/src/androidTest/java/com/emarsys/EmarsysE2ETests.kt +++ b/emarsys-e2e-test/src/androidTest/java/com/emarsys/EmarsysE2ETests.kt @@ -2,30 +2,20 @@ package com.emarsys import android.app.Application -import android.location.Location -import android.location.LocationManager -import android.os.Build -import android.os.SystemClock import com.emarsys.config.EmarsysConfig import com.emarsys.core.util.RetryUtil -import com.emarsys.di.emarsys -import com.emarsys.mobileengage.api.geofence.Trigger -import com.emarsys.mobileengage.api.geofence.TriggerType import com.emarsys.mobileengage.api.inbox.Message import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.E2ETestUtils import com.emarsys.testUtil.InstrumentationRegistry -import com.emarsys.testUtil.ReflectionTestUtils import com.emarsys.testUtil.RetryUtils import com.emarsys.testUtil.rules.DuplicatedThreadRule import com.emarsys.testUtil.rules.RetryRule import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import org.json.JSONObject import org.junit.Rule import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit -import com.emarsys.mobileengage.api.geofence.Geofence as MEGeofence class EmarsysE2ETests : AnnotationSpec() { @@ -160,68 +150,6 @@ class EmarsysE2ETests : AnnotationSpec() { } } - @Test - @Ignore - fun testGeofence() { - setup(APPLICATION_CODE) - RetryUtil.retry { - val fusedLocationProviderClient = emarsys().fusedLocationProviderClient - fusedLocationProviderClient.setMockMode(true) - val mockLocation = Location(LocationManager.GPS_PROVIDER).apply { - longitude = 30.0 - latitude = 30.0 - accuracy = 30.0f - altitude = 100.0 - time = System.currentTimeMillis() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos() - } - } - fusedLocationProviderClient.setMockLocation(mockLocation) - Emarsys.geofence.enable() - Emarsys.geofence.setInitialEnterTriggerEnabled(true) - - - val latch = CountDownLatch(1) - emarsys().concurrentHandlerHolder.coreHandler.post { - fusedLocationProviderClient.lastLocation.addOnSuccessListener { currentLocation -> - val testAction = JSONObject( - mapOf( - "id" to "geofenceActionId", - "type" to "MEAppEvent", - "name" to "geofence", - "payload" to mapOf( - "name" to "Home", - "trigger_type" to "enter" - ) - ) - ) - val geofence = MEGeofence( - "testGeofence", currentLocation.latitude, currentLocation.longitude, - 400.0, 0.0, listOf(Trigger("testAction", TriggerType.ENTER, 0, testAction)) - ) - - val geofenceInternal = emarsys().geofenceInternal - ReflectionTestUtils.setInstanceField( - geofenceInternal, - "nearestGeofences", - listOf(geofence) - ) - geofenceInternal.registerGeofences(listOf(geofence)) - } - - } - Emarsys.geofence.setEventHandler { _, name, payload -> - name shouldBe "geofence" - (payload?.get("name") ?: "") shouldBe "Home" - (payload?.get("trigger_type") ?: "") shouldBe "enter" - - latch.countDown() - } - latch.await(3, TimeUnit.SECONDS) - } - } - private fun changeApplicationCode(appCode: String?) { val changeApplicationCodeLatch = CountDownLatch(1) Emarsys.config.changeApplicationCode(appCode) { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/RemoteMessageMapperV2Test.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/RemoteMessageMapperV2Test.kt index c2080c6f..b23c9bd2 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/RemoteMessageMapperV2Test.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/RemoteMessageMapperV2Test.kt @@ -219,7 +219,7 @@ class RemoteMessageMapperV2Test : AnnotationSpec() { val input: MutableMap = createRemoteMessage() input["ems.tap_actions.default_action.name"] = "test name" input["ems.tap_actions.default_action.url"] = "test url" - input["ems.tap_actions.default_action.payload"] = " test payload" + input["ems.tap_actions.default_action.payload"] = """{"key":"test payload"}""" val notificationData = remoteMessageMapperV2.map(input) @@ -232,10 +232,10 @@ class RemoteMessageMapperV2Test : AnnotationSpec() { input["ems.tap_actions.default_action.name"] = "test name" input["ems.tap_actions.default_action.type"] = "MECustomEvent" input["ems.tap_actions.default_action.url"] = "test url" - input["ems.tap_actions.default_action.payload"] = "test payload" + input["ems.tap_actions.default_action.payload"] = """{"key":"test payload"}""" val expectedDefaultAction = - """{"name":"test name","type":"MECustomEvent","url":"test url","payload":"test payload"}""" + """{"name":"test name","type":"MECustomEvent","url":"test url","payload":{"key":"test payload"}}""" val notificationData = remoteMessageMapperV2.map(input) diff --git a/mobile-engage/src/main/java/com/emarsys/mobileengage/service/mapper/RemoteMessageMapperV2.kt b/mobile-engage/src/main/java/com/emarsys/mobileengage/service/mapper/RemoteMessageMapperV2.kt index 52ab953a..7eabcbc7 100644 --- a/mobile-engage/src/main/java/com/emarsys/mobileengage/service/mapper/RemoteMessageMapperV2.kt +++ b/mobile-engage/src/main/java/com/emarsys/mobileengage/service/mapper/RemoteMessageMapperV2.kt @@ -96,13 +96,14 @@ class RemoteMessageMapperV2( val url = remoteMessageData.getOrDefault("ems.tap_actions.default_action.url", null) val payload = remoteMessageData.getOrDefault("ems.tap_actions.default_action.payload", null) + val payloadObject = payload?.let { JSONObject(payload) } val defaultAction = if (type != null) { JSONObject() .put("name", name) .put("type", type) .put("url", url) - .put("payload", payload) + .put("payload", payloadObject) } else null return defaultAction?.toString()