diff --git a/snowplow-tracker/src/androidTest/java/com/snowplowanalytics/snowplow/tracker/TrackerWebViewInterfaceV2Test.kt b/snowplow-tracker/src/androidTest/java/com/snowplowanalytics/snowplow/tracker/TrackerWebViewInterfaceV2Test.kt index 5521dfbca..617004c10 100644 --- a/snowplow-tracker/src/androidTest/java/com/snowplowanalytics/snowplow/tracker/TrackerWebViewInterfaceV2Test.kt +++ b/snowplow-tracker/src/androidTest/java/com/snowplowanalytics/snowplow/tracker/TrackerWebViewInterfaceV2Test.kt @@ -74,12 +74,7 @@ class TrackerWebViewInterfaceV2Test { atomicProperties = atomic ) - var i = 0 - while (i < 10 && networkConnection.countRequests() == 0) { - Thread.sleep(1000) - i++ - } - + waitForEvents(networkConnection) assertEquals(1, networkConnection.countRequests()) val request = networkConnection.allRequests[0] @@ -107,6 +102,31 @@ class TrackerWebViewInterfaceV2Test { assertEquals(data, selfDescJson.getString("data")) } + @Test + @Throws(JSONException::class, InterruptedException::class) + fun addsDefaultPropertiesIfNotProvided() { + val networkConnection = MockNetworkConnection(HttpMethod.GET, 200) + createTracker( + context, + "ns${Math.random()}", + NetworkConfiguration(networkConnection), + TrackerConfiguration("appId").base64encoding(false) + ) + + webInterface!!.trackWebViewEvent(atomicProperties = "{}") + + waitForEvents(networkConnection) + assertEquals(1, networkConnection.countRequests()) + + val request = networkConnection.allRequests[0] + val payload = request.payload.map + + assertEquals("ue", payload[Parameters.EVENT]) + + val trackerVersion = payload[Parameters.TRACKER_VERSION] as String? + assertTrue(trackerVersion?.startsWith("andr") ?: false) + } + @Test @Throws(JSONException::class, InterruptedException::class) fun tracksEventWithCorrectTracker() { @@ -192,4 +212,12 @@ class TrackerWebViewInterfaceV2Test { configurations = arrayOf(eventSink) ) } + + private fun waitForEvents(networkConnection: MockNetworkConnection) { + var i = 0 + while (i < 10 && networkConnection.countRequests() == 0) { + Thread.sleep(1000) + i++ + } + } }