Skip to content

Commit

Permalink
Add test for default eventname and trackerversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mscwilson committed Dec 12, 2024
1 parent 1e043ee commit df44568
Showing 1 changed file with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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++
}
}
}

0 comments on commit df44568

Please sign in to comment.