Skip to content

Commit

Permalink
MF-171: Add PlayLog test 24
Browse files Browse the repository at this point in the history
  • Loading branch information
stoyicker committed Aug 30, 2024
1 parent db2266c commit 7ee46d4
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -716,4 +716,61 @@ internal class TwoMediaProductsPlayLogTest {
},
)
}

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

player.playbackEngine.load(mediaProduct1)
player.playbackEngine.play()
withContext(Dispatchers.Default.limitedParallelism(1)) {
withTimeout(8.seconds) {
player.playbackEngine.events.filter { it is Event.MediaProductTransition }.first()
}
delay(2.seconds)
while (player.playbackEngine.assetPosition < 2) {
delay(10.milliseconds)
}
player.playbackEngine.load(mediaProduct1)
player.playbackEngine.play()
withTimeout(8.seconds) {
player.playbackEngine.events.filter { it is Event.MediaProductTransition }.first()
}
delay(1.seconds)
while (player.playbackEngine.assetPosition < 1) {
delay(10.milliseconds)
}
player.playbackEngine.reset()
}

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(mediaProduct1.productId)
assertThat(get("sourceType")?.asString).isEqualTo(mediaProduct1.sourceType)
assertThat(get("sourceId")?.asString).isEqualTo(mediaProduct1.sourceId)
assertThat(get("actions").asJsonArray).isEmpty()
},
)
}
}

0 comments on commit 7ee46d4

Please sign in to comment.