Skip to content

Commit eca1d97

Browse files
authored
Merge pull request #247 from adamint/dev
Make CursorBasedPagingObject cursor nullable
2 parents e2dce0a + 6181884 commit eca1d97

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

src/commonMain/kotlin/com.adamratzman.spotify/models/PagingObjects.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ public abstract class AbstractPagingObject<T : Any, Z : AbstractPagingObject<T,
244244
* @param limit The maximum number of items in the response (as set in the query or by default).
245245
* @param next URL to the next page of items. ( null if none)
246246
* @param total The maximum number of items available to return.
247-
* @param cursor The cursors used to find the next set of items..
247+
* @param cursor The cursors used to find the next set of items. If [items] is empty, cursor may be null.
248248
*/
249249
@Serializable
250250
public data class CursorBasedPagingObject<T : Any>(
251251
override val href: String,
252252
override val items: List<T>,
253253
override val limit: Int,
254254
override val next: String? = null,
255-
@SerialName("cursors") public val cursor: Cursor,
255+
@SerialName("cursors") public val cursor: Cursor? = null,
256256
override val total: Int = 0,
257257
override val offset: Int = 0,
258258
override val previous: String? = null

src/commonTest/kotlin/com.adamratzman/spotify/pub/BrowseApiTest.kt

+1-9
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,7 @@ class BrowseApiTest {
114114
assertFailsWithSuspend<SpotifyException.BadRequestException> {
115115
api.browse.getTrackRecommendations(seedArtists = listOf("abc"))
116116
}
117-
assertTrue(api.browse.getTrackRecommendations(seedArtists = listOf("2C2sVVXanbOpymYBMpsi89")).tracks.isNotEmpty())
118-
assertTrue(
119-
api.browse.getTrackRecommendations(
120-
seedArtists = listOf(
121-
"2C2sVVXanbOpymYBMpsi89",
122-
"7lMgpN1tEBQKpRoUMKB8iw"
123-
)
124-
).tracks.isNotEmpty()
125-
)
117+
assertTrue(api.browse.getTrackRecommendations(seedArtists = listOf("1kNQXvepPjaPgUfeDAF2h6")).tracks.isNotEmpty())
126118

127119
assertFailsWithSuspend<SpotifyException.BadRequestException> {
128120
api.browse.getTrackRecommendations(seedTracks = listOf("abc"))

src/commonTest/kotlin/com.adamratzman/spotify/utilities/JsonTests.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class JsonTests {
112112
assertEquals(emptyList(), pagingObject.items)
113113
assertEquals(50, pagingObject.limit)
114114
assertEquals("nextHref", pagingObject.next)
115-
assertEquals("afterHref", pagingObject.cursor.after)
115+
assertEquals("afterHref", pagingObject.cursor?.after)
116116
assertEquals(5, pagingObject.total)
117117
}
118118
}

0 commit comments

Comments
 (0)