Skip to content

Commit 23c8c74

Browse files
committed
update client player tests to reflect queue functionality
Signed-off-by: Adam Ratzman <[email protected]>
1 parent ee8cc2e commit 23c8c74

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/commonMain/kotlin/com.adamratzman.spotify/endpoints/client/ClientPlayerApi.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ public class ClientPlayerApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
677677

678678
/**
679679
* Add an item to the end of the user’s current playback queue.
680+
* Please note that all items in the queue will be played before resuming the current playlist/album playing, if there is one.
680681
*
681682
* This method is provided **AS-IS** until Spotify
682683
* exposes device queue. Please consider managing the player queue within your application.

src/commonTest/kotlin/com.adamratzman/spotify/priv/ClientPlayerApiTest.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ import com.adamratzman.spotify.models.CurrentlyPlayingType
88
import com.adamratzman.spotify.models.PlayableUri
99
import com.adamratzman.spotify.models.SpotifyContextType
1010
import com.adamratzman.spotify.models.SpotifyTrackUri
11+
import com.adamratzman.spotify.models.Track
1112
import com.adamratzman.spotify.models.toAlbumUri
1213
import com.adamratzman.spotify.models.toArtistUri
1314
import com.adamratzman.spotify.models.toPlaylistUri
1415
import com.adamratzman.spotify.models.toShowUri
1516
import com.adamratzman.spotify.models.toTrackUri
1617
import com.adamratzman.spotify.runBlockingTest
18+
import kotlinx.coroutines.delay
1719
import kotlin.test.Test
1820
import kotlin.test.assertEquals
1921
import kotlin.test.assertNotNull
2022
import kotlin.test.assertTrue
2123
import kotlin.time.ExperimentalTime
2224
import kotlin.time.measureTime
23-
import kotlinx.coroutines.delay
2425

2526
@ExperimentalTime
2627
class ClientPlayerApiTest {
@@ -114,15 +115,20 @@ class ClientPlayerApiTest {
114115
runBlockingTest {
115116
if (!testPrereq()) return@runBlockingTest else api!!
116117
val device = api!!.player.getDevices().first()
117-
api!!.player.startPlayback(playlistId = "098OivbzwUNzzDShgF6U4A") // two tracks
118+
val playlist = api!!.playlists.getPlaylist("098OivbzwUNzzDShgF6U4A")!!
119+
api!!.player.startPlayback(playlistId = playlist.id) // two tracks
118120
val trackId = "7lPN2DXiMsVn7XUKtOW1CS"
119121
api!!.player.addItemToEndOfQueue(trackId.toTrackUri(), device.id)
120-
122+
delay(1000)
121123
api!!.player.skipForward() // skip first
124+
delay(2000)
125+
// we have nothing in the queue so the next in queue gets played before resuming playlist
126+
assertEquals(trackId, api!!.player.getCurrentlyPlaying()?.track?.uri?.id)
122127
api!!.player.skipForward() // skip second
123128
delay(2000)
124-
// we should now be at track
125-
assertEquals(trackId, api!!.player.getCurrentlyPlaying()?.context?.uri?.id)
129+
// now we're back in the playlist
130+
assertEquals(playlist.tracks[1].track!!.asTrack!!.id, api!!.player.getCurrentlyPlaying()?.track?.uri?.id)
131+
api!!.player.skipForward() // skip second
126132
}
127133
}
128134

@@ -235,12 +241,13 @@ class ClientPlayerApiTest {
235241
assertEquals(trackUris[offsetIndex + 1].id, api!!.player.getCurrentlyPlaying()?.track?.id)
236242

237243
// play playlist with offset track
244+
val playlistTracks = api!!.playlists.getPlaylist(playlistUri.id)!!.tracks.map { it?.track as Track }
238245
api!!.player.startPlayback(contextUri = playlistUri, offsetIndex = offsetIndex)
239-
delay(1000)
240-
assertEquals(trackUris[offsetIndex].id, api!!.player.getCurrentlyPlaying()?.track?.id)
246+
delay(2500)
247+
assertEquals(playlistTracks[offsetIndex].id, api!!.player.getCurrentlyPlaying()?.track?.id)
241248
api!!.player.skipForward()
242-
delay(1000)
243-
assertEquals(trackUris[offsetIndex + 1].id, api!!.player.getCurrentlyPlaying()?.track?.id)
249+
delay(2000)
250+
assertEquals(playlistTracks[offsetIndex + 1].id, api!!.player.getCurrentlyPlaying()?.track?.id)
244251
}
245252
}
246253

0 commit comments

Comments
 (0)