diff --git a/build.gradle b/build.gradle index 65f8cef..dc021ed 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { if (!maven_variant.isEmpty()) { maven_artifact_id = maven_artifact_id + '-' + maven_variant } - flagship_version_name = System.getenv('FLAGSHIP_VERSION_NAME') ?: "4.0.0-beta3" + flagship_version_name = System.getenv('FLAGSHIP_VERSION_NAME') ?: "4.0.0-beta4" flagship_version_code = System.getenv('FLAGSHIP_VERSION_CODE') ?: 24 } diff --git a/flagship/build.gradle b/flagship/build.gradle index 559f996..6f00cd5 100644 --- a/flagship/build.gradle +++ b/flagship/build.gradle @@ -4,7 +4,7 @@ plugins { id 'kotlin-android' id 'kotlin-parcelize' id 'com.google.devtools.ksp' - id 'com.vanniktech.maven.publish' version "0.34.0" + id 'com.vanniktech.maven.publish' version "0.35.0" id 'jacoco' } @@ -81,7 +81,6 @@ dependencies { implementation 'androidx.room:room-runtime:2.7.2' implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2") implementation 'androidx.appcompat:appcompat:1.7.1' - testImplementation 'junit:junit:4.13.2' testImplementation 'androidx.test:core:1.7.0' testImplementation 'org.robolectric:robolectric:4.16' diff --git a/flagship/src/main/java/com/abtasty/flagship/hits/Segment.kt b/flagship/src/main/java/com/abtasty/flagship/hits/Segment.kt index 3603ba5..dbda11e 100644 --- a/flagship/src/main/java/com/abtasty/flagship/hits/Segment.kt +++ b/flagship/src/main/java/com/abtasty/flagship/hits/Segment.kt @@ -1,19 +1,24 @@ package com.abtasty.flagship.hits import com.abtasty.flagship.utils.FlagshipConstants +import com.abtasty.flagship.utils.FlagshipLogManager import org.json.JSONObject import java.util.HashMap internal class Segment: Hit { constructor(visitorId: String, context: HashMap): super(Companion.Type.SEGMENT) { - val obj = JSONObject() - for (c in context) { - obj.put(c.key, c.value) + try { + val obj = JSONObject() + for (c in context) { + obj.put(c.key, c.value.toString()) + } + this.data.put(FlagshipConstants.HitKeyMap.VISITOR_ID, visitorId) + if (obj.length() > 0) + this.data.put(FlagshipConstants.HitKeyMap.SEGMENT_LIST, obj) + } catch (e: Exception) { + FlagshipLogManager.exception(FlagshipConstants.Exceptions.Companion.FlagshipException(e)) } - this.data.put(FlagshipConstants.HitKeyMap.VISITOR_ID, visitorId) - if (obj.length() > 0) - this.data.put(FlagshipConstants.HitKeyMap.SEGMENT_LIST, obj) } internal constructor(jsonObject: JSONObject): super(Companion.Type.SEGMENT, jsonObject) diff --git a/flagship/src/main/java/com/abtasty/flagship/utils/FlagshipContext.kt b/flagship/src/main/java/com/abtasty/flagship/utils/FlagshipContext.kt index 01d731f..084c09f 100644 --- a/flagship/src/main/java/com/abtasty/flagship/utils/FlagshipContext.kt +++ b/flagship/src/main/java/com/abtasty/flagship/utils/FlagshipContext.kt @@ -61,10 +61,6 @@ abstract class FlagshipContext( } override fun load(applicationContext: Context): String? { -// return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) -// applicationContext.resources.configuration.locales.get(0).isO3Language -// else -// applicationContext.resources.configuration.locale.isO3Language return Utils.getCurrentLocale(applicationContext).isO3Language } } diff --git a/flagship/src/test/java/com/abtasty/flagship/FlagshipTestsHits.kt b/flagship/src/test/java/com/abtasty/flagship/FlagshipTestsHits.kt index 9c4b5dc..d10f68c 100644 --- a/flagship/src/test/java/com/abtasty/flagship/FlagshipTestsHits.kt +++ b/flagship/src/test/java/com/abtasty/flagship/FlagshipTestsHits.kt @@ -199,6 +199,64 @@ class FlagshipTestsHits : AFlagshipTest() { } } + @Test + fun test_segment_hit() { +// + val jsonResponse = + FlagshipTestsHelper.jsonObjectFromAssets(getApplication(), "bucketing_response_3.json") + jsonResponse + .getJSONObject("accountSettings") + + FlagshipTestsHelper.interceptor().intercept( + BUCKETING_URL.format(_ENV_ID_), + FlagshipTestsHelper.responseFromString(getApplication(), jsonResponse.toString(), 200) + ) + .intercept( + ARIANE_URL.format(_ENV_ID_), + FlagshipTestsHelper.response("", 200) + ) + + runBlocking { + Flagship.start( + getApplication(), + _ENV_ID_, + _API_KEY_, + FlagshipConfig.Bucketing().withTrackingManagerConfig( + TrackingManagerConfig(disablePolling = true) + ) + ).await() + } + + val visitor = Flagship.newVisitor("visitor_1", true) + .context(hashMapOf( + "boolValue" to true, + "doubleValue" to 3.14, + "stringValue" to "string", + "intValue" to 434, + "jsonValue" to JSONObject("{}") + )) + .build() + Thread.sleep(100) + visitor.fetchFlags() + Thread.sleep(100) + FlagshipTestsHelper.interceptor().calls[ARIANE_URL]?.get(1)?.let { + val jsonHit = HttpCompat.requestJson(it.first) + Assert.assertEquals("BATCH", jsonHit.getString("t")) + Assert.assertEquals(_ENV_ID_, jsonHit.getString("cid")) + Assert.assertEquals("APP", jsonHit.getString("ds")) + val content = jsonHit.getJSONArray("h").getJSONObject(0) + Assert.assertEquals(content.getString("vid"), "visitor_1") + Assert.assertEquals(content.getString("ds"), "APP") + Assert.assertEquals(content.get("t"), "SEGMENT") + Assert.assertEquals(content.getJSONObject("s").get("boolValue"), "true") + Assert.assertEquals(content.getJSONObject("s").get("doubleValue"), "3.14") + Assert.assertEquals(content.getJSONObject("s").get("stringValue"), "string") + Assert.assertEquals(content.getJSONObject("s").get("intValue"), "434") + Assert.assertFalse(content.getJSONObject("s").has("jsonValue")) +// Assert.assertEquals(content.get("dl"), "https://location.com") + } + } + @Test fun test_event_hit() { @@ -1044,6 +1102,7 @@ class FlagshipTestsHits : AFlagshipTest() { FlagshipTestsHelper.interceptor().calls[TROUBLESHOOTING_URL]?.size ) // 1 Bucketing, 1 Fetch, 1 Segment, 1 consent + FlagshipTestsHelper.interceptor().calls[TROUBLESHOOTING_URL]!![0].let { val jsonHit = HttpCompat.requestJson(it.first) val cv = jsonHit.getJSONObject(CUSTOM_VALUE)