Skip to content

Commit

Permalink
fix unit tests and add Track#copyWithUserData
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Nov 26, 2023
1 parent 0ce1ed2 commit 4720192
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ data class Track(
val info: TrackInfo,
val pluginInfo: JsonObject,
val userData: JsonObject
) : LoadResult.Data
) : LoadResult.Data {
fun copyWithUserData(userData: JsonObject): Track {
return copy(userData = userData)
}
}

@Serializable
@JvmInline
Expand Down
3 changes: 2 additions & 1 deletion protocol/src/commonTest/kotlin/LoadResultSerializerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class LoadResultSerializerTest {
"isrc": null,
"sourceName": "youtube"
},
"pluginInfo": {}
"pluginInfo": {},
"userData": {}
},
"exception": null
}
Expand Down
12 changes: 8 additions & 4 deletions protocol/src/commonTest/kotlin/MessageSerializerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class MessageSerializerTest {
"isrc": null,
"sourceName": "youtube"
},
"pluginInfo": {}
"pluginInfo": {},
"userData": {}
}
}
""".trimIndent()
Expand Down Expand Up @@ -183,7 +184,8 @@ class MessageSerializerTest {
"isrc": null,
"sourceName": "youtube"
},
"pluginInfo": {}
"pluginInfo": {},
"userData": {}
},
"reason": "finished"
}
Expand Down Expand Up @@ -238,7 +240,8 @@ class MessageSerializerTest {
"isrc": null,
"sourceName": "youtube"
},
"pluginInfo": {}
"pluginInfo": {},
"userData": {}
},
"exception": {
"message": "...",
Expand Down Expand Up @@ -301,7 +304,8 @@ class MessageSerializerTest {
"isrc": null,
"sourceName": "youtube"
},
"pluginInfo": {}
"pluginInfo": {},
"userData": {}
},
"thresholdMs": 123456789
}
Expand Down
16 changes: 10 additions & 6 deletions protocol/src/commonTest/kotlin/PlayerSerializerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ private const val json = """
"artworkUrl": null,
"isrc": null
},
"pluginInfo": {}
"pluginInfo": {},
"userData": {}
},
"volume": 100,
"paused": false,
Expand All @@ -52,7 +53,9 @@ private const val json = """
//language=json
const val updateJson = """
{
"identifier": "...",
"track": {
"identifier": "..."
},
"endTime": 0,
"volume": 100,
"position": 32400,
Expand Down Expand Up @@ -112,8 +115,7 @@ class PlayerSerializerTest {
val json = """{}"""

test<PlayerUpdate>(json) {
assertIs<Omissible.Omitted<*>>(encodedTrack)
assertIs<Omissible.Omitted<*>>(identifier)
assertIs<Omissible.Omitted<*>>(track)
assertIs<Omissible.Omitted<*>>(position)
assertIs<Omissible.Omitted<*>>(endTime)
assertIs<Omissible.Omitted<*>>(volume)
Expand All @@ -127,7 +129,7 @@ class PlayerSerializerTest {
@JsName("test3")
fun `test encodedTrack and identifier exclusivity`() {
//language=json
val json = """{"encodedTrack": "", "identifier": ""}"""
val json = """{"track": {"encodedTrack": "", "identifier": ""}}"""

assertFailsWith<IllegalArgumentException> { Json.decodeFromString(json) }
}
Expand All @@ -136,7 +138,9 @@ class PlayerSerializerTest {
@JsName("test4")
fun `test update player serialization`() {
test<PlayerUpdate>(updateJson) {
identifier shouldBe "..."
track.requirePresent {
identifier shouldBe "..."
}
endTime shouldBe 0
volume shouldBe 100
position shouldBe 32400
Expand Down

0 comments on commit 4720192

Please sign in to comment.