diff --git a/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiUpdatePlaylistTest.kt b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiUpdatePlaylistTest.kt new file mode 100644 index 00000000..19369665 --- /dev/null +++ b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiUpdatePlaylistTest.kt @@ -0,0 +1,85 @@ +package org.moire.ultrasonic.api.subsonic + +import org.junit.Test + +/** + * Integration test for [SubsonicAPIClient] for updatePlaylist call. + */ +class SubsonicApiUpdatePlaylistTest : SubsonicAPIClientTest() { + @Test + fun `Should handle error response`() { + checkErrorCallParsed(mockWebServerRule) { + client.api.updatePlaylist(10).execute() + } + } + + @Test + fun `Should handle ok response`() { + mockWebServerRule.enqueueResponse("ping_ok.json") + + val response = client.api.updatePlaylist(15).execute() + + assertResponseSuccessful(response) + } + + @Test + fun `Should pass playlist id param in request`() { + val id = 5453L + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "playlistId=$id") { + client.api.updatePlaylist(id = id).execute() + } + } + + @Test + fun `Should pass name param in request`() { + val name = "some-name" + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "name=$name") { + client.api.updatePlaylist(22, name = name).execute() + } + } + + @Test + fun `Should pass comment param in request`() { + val comment = "some-unusual-comment" + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "comment=$comment") { + client.api.updatePlaylist(42, comment = comment).execute() + } + } + + @Test + fun `Should pass public param in request`() { + val public = true + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "public=$public") { + client.api.updatePlaylist(53, public = public).execute() + } + } + + @Test + fun `Should pass song ids to update in request`() { + val songIds = listOf(45L, 81L) + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "songIdToAdd=${songIds[0]}&songIdToAdd=${songIds[1]}") { + client.api.updatePlaylist(25, songIdsToAdd = songIds).execute() + } + } + + @Test + fun `Should pass song indexes to remove in request`() { + val songIndexesToRemove = listOf(129, 1) + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "songIndexToRemove=${songIndexesToRemove[0]}&" + + "songIndexToRemove=${songIndexesToRemove[1]}") { + client.api.updatePlaylist(49, songIndexesToRemove = songIndexesToRemove).execute() + } + } +} diff --git a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt index 8bcba487..322e0a3f 100644 --- a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt +++ b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt @@ -99,4 +99,13 @@ interface SubsonicAPIDefinition { @GET("deletePlaylist.view") fun deletePlaylist(@Query("id") id: Long): Call + + @GET("updatePlaylist.view") + fun updatePlaylist( + @Query("playlistId") id: Long, + @Query("name") name: String? = null, + @Query("comment") comment: String? = null, + @Query("public") public: Boolean? = null, + @Query("songIdToAdd") songIdsToAdd: List? = null, + @Query("songIndexToRemove") songIndexesToRemove: List? = null) : Call }