From bad5cf5a9a22b17d6acbb5014dd39b5d9ca20a2b Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Sat, 16 Sep 2017 22:19:17 +0200 Subject: [PATCH] Add getStarred call. Signed-off-by: Yahor Berdnikau --- .../api/subsonic/SubsonicApiGetStarredTest.kt | 47 +++++++++++++++++++ .../resources/get_starred_ok.json | 13 +++++ .../api/subsonic/SubsonicAPIDefinition.kt | 4 ++ .../subsonic/response/GetStarredResponse.kt | 11 +++++ 4 files changed, 75 insertions(+) create mode 100644 subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiGetStarredTest.kt create mode 100644 subsonic-api/src/integrationTest/resources/get_starred_ok.json create mode 100644 subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetStarredResponse.kt diff --git a/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiGetStarredTest.kt b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiGetStarredTest.kt new file mode 100644 index 00000000..589f0fff --- /dev/null +++ b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiGetStarredTest.kt @@ -0,0 +1,47 @@ +package org.moire.ultrasonic.api.subsonic + +import org.amshove.kluent.`should equal to` +import org.amshove.kluent.`should equal` +import org.junit.Test +import org.moire.ultrasonic.api.subsonic.models.Artist +import org.moire.ultrasonic.api.subsonic.models.SearchTwoResult + +/** + * Integration test for [SubsonicAPIClient] for getStarred call. + */ +class SubsonicApiGetStarredTest : SubsonicAPIClientTest() { + @Test + fun `Should handle error response`() { + val response = checkErrorCallParsed(mockWebServerRule) { + client.api.getStarred().execute() + } + + response.starred `should equal` SearchTwoResult() + } + + @Test + fun `Should handle ok reponse`() { + mockWebServerRule.enqueueResponse("get_starred_ok.json") + + val response = client.api.getStarred().execute() + + assertResponseSuccessful(response) + with(response.body().starred) { + albumList `should equal` emptyList() + artistList.size `should equal to` 1 + artistList[0] `should equal` Artist(id = 364, name = "Parov Stelar", + starred = parseDate("2017-08-12T18:32:58.768Z")) + songList `should equal` emptyList() + } + } + + @Test + fun `Should pass music folder id in request param`() { + val musicFolderId = 441L + + mockWebServerRule.assertRequestParam(responseResourceName = "get_starred_ok.json", + expectedParam = "musicFolderId=$musicFolderId") { + client.api.getStarred(musicFolderId = musicFolderId).execute() + } + } +} diff --git a/subsonic-api/src/integrationTest/resources/get_starred_ok.json b/subsonic-api/src/integrationTest/resources/get_starred_ok.json new file mode 100644 index 00000000..4adab54d --- /dev/null +++ b/subsonic-api/src/integrationTest/resources/get_starred_ok.json @@ -0,0 +1,13 @@ +{ + "subsonic-response" : { + "status" : "ok", + "version" : "1.15.0", + "starred" : { + "artist" : [ { + "id" : "364", + "name" : "Parov Stelar", + "starred" : "2017-08-12T18:32:58.768Z" + } ] + } + } +} \ No newline at end of file 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 6be4263b..a9edabf3 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 @@ -13,6 +13,7 @@ import org.moire.ultrasonic.api.subsonic.response.GetPlaylistResponse import org.moire.ultrasonic.api.subsonic.response.GetPlaylistsResponse import org.moire.ultrasonic.api.subsonic.response.GetPodcastsResponse import org.moire.ultrasonic.api.subsonic.response.GetRandomSongsResponse +import org.moire.ultrasonic.api.subsonic.response.GetStarredResponse import org.moire.ultrasonic.api.subsonic.response.LicenseResponse import org.moire.ultrasonic.api.subsonic.response.MusicFoldersResponse import org.moire.ultrasonic.api.subsonic.response.SearchResponse @@ -152,4 +153,7 @@ interface SubsonicAPIDefinition { @Query("fromYear") fromYear: Int? = null, @Query("toYear") toYear: Int? = null, @Query("musicFolderId") musicFolderId: Long? = null): Call + + @GET("getStarred.view") + fun getStarred(@Query("musicFolderId") musicFolderId: Long? = null): Call } diff --git a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetStarredResponse.kt b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetStarredResponse.kt new file mode 100644 index 00000000..dc4e59eb --- /dev/null +++ b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetStarredResponse.kt @@ -0,0 +1,11 @@ +package org.moire.ultrasonic.api.subsonic.response + +import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions +import org.moire.ultrasonic.api.subsonic.SubsonicError +import org.moire.ultrasonic.api.subsonic.models.SearchTwoResult + +class GetStarredResponse(status: Status, + version: SubsonicAPIVersions, + error: SubsonicError?, + val starred: SearchTwoResult = SearchTwoResult()) + : SubsonicResponse(status, version, error)