Skip to content

Commit

Permalink
Add PlayLog test 23
Browse files Browse the repository at this point in the history
  • Loading branch information
stoyicker committed Jul 1, 2024
1 parent 0aecea8 commit 8c2f6b7
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,57 @@ internal class TwoMediaProductsPlayLogTest {
},
)
}

@Suppress("CyclomaticComplexMethod")
@Test
fun playSequentiallyWithoutRepeatOne() = runTest {
val gson = Gson()
val payloadCaptor = argumentCaptor<String>()

player.playbackEngine.load(mediaProduct1)
player.playbackEngine.play()
withContext(Dispatchers.Default.limitedParallelism(1)) {
delay(2.seconds)
while (player.playbackEngine.assetPosition < 2) {
delay(10.milliseconds)
}
player.playbackEngine.load(mediaProduct2)
player.playbackEngine.play()
delay(1.seconds)
while (player.playbackEngine.assetPosition < 1) {
delay(10.milliseconds)
}
player.playbackEngine.reset()
}

eventReporterCoroutineScope.advanceUntilIdle()

eventReporterCoroutineScope.advanceUntilIdle()
verify(eventSender, times(2)).sendEvent(
eq("playback_session"),
eq(ConsentCategory.NECESSARY),
payloadCaptor.capture(),
eq(emptyMap()),
)
payloadCaptor.allValues.map {
gson.fromJson(it, JsonObject::class.java)["payload"].asJsonObject
}.combinedPassAllOf(
1 to {
assertThat(get("startAssetPosition").asDouble).isAssetPositionEqualTo(0.0)
assertThat(get("endAssetPosition").asDouble).isAssetPositionEqualTo(2.0)
assertThat(get("actualProductId")?.asString).isEqualTo(mediaProduct1.productId)
assertThat(get("sourceType")?.asString).isEqualTo(mediaProduct1.sourceType)
assertThat(get("sourceId")?.asString).isEqualTo(mediaProduct1.sourceId)
assertThat(get("actions").asJsonArray).isEmpty()
},
1 to {
assertThat(get("startAssetPosition").asDouble).isAssetPositionEqualTo(0.0)
assertThat(get("endAssetPosition").asDouble).isAssetPositionEqualTo(1.0)
assertThat(get("actualProductId")?.asString).isEqualTo(mediaProduct2.productId)
assertThat(get("sourceType")?.asString).isEqualTo(mediaProduct2.sourceType)
assertThat(get("sourceId")?.asString).isEqualTo(mediaProduct2.sourceId)
assertThat(get("actions").asJsonArray).isEmpty()
},
)
}
}

0 comments on commit 8c2f6b7

Please sign in to comment.