From bb64b9e3ca07ad506428c7bbf2f643755d291e2e Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Sat, 2 Sep 2017 20:27:32 +0200 Subject: [PATCH] Add createPlaylist api call. Signed-off-by: Yahor Berdnikau --- .../subsonic/SubsonicApiCreatePlaylistTest.kt | 54 +++++++++++++++++++ .../api/subsonic/SubsonicAPIDefinition.kt | 5 ++ 2 files changed, 59 insertions(+) create mode 100644 subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiCreatePlaylistTest.kt diff --git a/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiCreatePlaylistTest.kt b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiCreatePlaylistTest.kt new file mode 100644 index 00000000..f7450c6c --- /dev/null +++ b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiCreatePlaylistTest.kt @@ -0,0 +1,54 @@ +package org.moire.ultrasonic.api.subsonic + +import org.junit.Test + +/** + * Integration test for [SubsonicAPIClient] for createPlaylist call. + */ +class SubsonicApiCreatePlaylistTest : SubsonicAPIClientTest() { + @Test + fun `Should handle error response`() { + checkErrorCallParsed(mockWebServerRule) { + client.api.createPlaylist().execute() + } + } + + @Test + fun `Should hanlde ok response`() { + mockWebServerRule.enqueueResponse("ping_ok.json") + + val response = client.api.createPlaylist().execute() + + assertResponseSuccessful(response) + } + + @Test + fun `Should pass id param in request`() { + val id = 56L + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "playlistId=$id") { + client.api.createPlaylist(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.createPlaylist(name = name).execute() + } + } + + @Test + fun `Should pass song id param in request`() { + val songId = listOf(4410L, 852L) + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "songId=${songId[0]}&songId=${songId[1]}") { + client.api.createPlaylist(songIds = songId).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 409dff08..98123943 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 @@ -91,4 +91,9 @@ interface SubsonicAPIDefinition { @GET("getPlaylists.view") fun getPlaylists(@Query("username") username: String? = null): Call + + @GET("createPlaylist.view") + fun createPlaylist(@Query("playlistId") id: Long? = null, + @Query("name") name: String? = null, + @Query("songId") songIds: List? = null): Call }