Add parsing shortcuts info.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-08-12 21:19:46 +02:00
parent b02df33b9c
commit 13cf2cd8bf
5 changed files with 21 additions and 10 deletions

View File

@ -30,7 +30,7 @@ import java.util.TimeZone
/** /**
* Integration test for [SubsonicAPIClient] class. * Integration test for [SubsonicAPIClient] class.
*/ */
@Suppress("TooManyFunctions") @Suppress("TooManyFunctions", "LargeClass")
class SubsonicAPIClientTest { class SubsonicAPIClientTest {
companion object { companion object {
const val USERNAME = "some-user" const val USERNAME = "some-user"
@ -154,7 +154,6 @@ class SubsonicAPIClientTest {
@Test @Test
fun `Should parse get indexes ok response`() { fun `Should parse get indexes ok response`() {
// check for shortcut parsing
enqueueResponse("get_indexes_ok.json") enqueueResponse("get_indexes_ok.json")
val response = client.api.getIndexes(null, null).execute() val response = client.api.getIndexes(null, null).execute()
@ -164,7 +163,10 @@ class SubsonicAPIClientTest {
with(response.body().indexes) { with(response.body().indexes) {
lastModified `should equal` 1491069027523 lastModified `should equal` 1491069027523
ignoredArticles `should equal` "The El La Los Las Le Les" ignoredArticles `should equal` "The El La Los Las Le Les"
shortcuts `should be` emptyList<Index>() shortcutList `should equal` listOf(
Artist(889L, "podcasts", null),
Artist(890L, "audiobooks", null)
)
indexList `should equal` mutableListOf( indexList `should equal` mutableListOf(
Index("A", listOf( Index("A", listOf(
Artist(50L, "Ace Of Base", parseDate("2017-04-02T20:16:29.815Z")), Artist(50L, "Ace Of Base", parseDate("2017-04-02T20:16:29.815Z")),
@ -225,7 +227,7 @@ class SubsonicAPIClientTest {
lastModified `should equal to` 0 lastModified `should equal to` 0
ignoredArticles `should equal to` "" ignoredArticles `should equal to` ""
indexList.size `should equal to` 0 indexList.size `should equal to` 0
shortcuts.size `should equal to` 0 shortcutList.size `should equal to` 0
} }
} }

View File

@ -5,6 +5,14 @@
"indexes" : { "indexes" : {
"lastModified" : 1491069027523, "lastModified" : 1491069027523,
"ignoredArticles" : "The El La Los Las Le Les", "ignoredArticles" : "The El La Los Las Le Les",
"shortcut" : [ {
"id" : "889",
"name" : "podcasts"
},
{
"id" : "890",
"name" : "audiobooks"
} ],
"index" : [ { "index" : [ {
"name" : "A", "name" : "A",
"artist" : [ { "artist" : [ {

View File

@ -6,4 +6,5 @@ data class Indexes(val lastModified: Long = 0,
val ignoredArticles: String = "", val ignoredArticles: String = "",
@JsonProperty("index") @JsonProperty("index")
val indexList: List<Index> = emptyList(), val indexList: List<Index> = emptyList(),
val shortcuts: List<Index> = emptyList()) @JsonProperty("shortcut")
val shortcutList: List<Artist> = emptyList())

View File

@ -16,7 +16,7 @@ fun List<APIMusicFolder>.toDomainEntityList(): List<MusicFolder>
= this.map { it.toDomainEntity() } = this.map { it.toDomainEntity() }
fun APIIndexes.toDomainEntity(): Indexes = Indexes(this.lastModified, this.ignoredArticles, fun APIIndexes.toDomainEntity(): Indexes = Indexes(this.lastModified, this.ignoredArticles,
this.shortcuts.foldIndexToArtistList(), this.indexList.foldIndexToArtistList()) this.shortcutList.map { it.toDomainEntity() }, this.indexList.foldIndexToArtistList())
private fun List<Index>.foldIndexToArtistList(): List<Artist> = this.fold(listOf(), { private fun List<Index>.foldIndexToArtistList(): List<Artist> = this.fold(listOf(), {
acc, index -> acc + index.artists.map { it.toDomainEntity() } acc, index -> acc + index.artists.map { it.toDomainEntity() }

View File

@ -64,7 +64,7 @@ class APIConverterTest {
val entity = createIndexes(154, "Le Tre Ze", listOf( val entity = createIndexes(154, "Le Tre Ze", listOf(
createIndex("A", artistsA), createIndex("A", artistsA),
createIndex("T", artistsT) createIndex("T", artistsT)
), emptyList()) ), artistsA)
val convertedEntity = entity.toDomainEntity() val convertedEntity = entity.toDomainEntity()
@ -74,7 +74,7 @@ class APIConverterTest {
ignoredArticles `should equal to` entity.ignoredArticles ignoredArticles `should equal to` entity.ignoredArticles
artists.size `should equal to` expectedArtists.size artists.size `should equal to` expectedArtists.size
artists `should equal` expectedArtists artists `should equal` expectedArtists
shortcuts `should equal` emptyList() shortcuts `should equal` artistsA.map { it.toDomainEntity() }.toMutableList()
} }
} }
@ -91,6 +91,6 @@ class APIConverterTest {
lastModified: Long = 0, lastModified: Long = 0,
ignoredArticles: String, ignoredArticles: String,
indexList: List<Index> = emptyList(), indexList: List<Index> = emptyList(),
shortcuts: List<Index> = emptyList()): Indexes shortcuts: List<Artist> = emptyList()): Indexes
= Indexes(lastModified, ignoredArticles, indexList, shortcuts) = Indexes(lastModified, ignoredArticles, indexList, shortcuts)
} }