@@ -141,6 +141,136 @@ func TestGetPlaylistTracks(t *testing.T) {
141141 }
142142}
143143
144+ func TestGetPlaylistItemsEpisodes (t * testing.T ) {
145+ client , server := testClientFile (http .StatusOK , "test_data/playlist_items_episodes.json" )
146+ defer server .Close ()
147+
148+ tracks , err := client .GetPlaylistItems (context .Background (), "playlistID" )
149+ if err != nil {
150+ t .Error (err )
151+ }
152+ if tracks .Total != 4 {
153+ t .Errorf ("Got %d tracks, expected 47\n " , tracks .Total )
154+ }
155+ if len (tracks .Items ) == 0 {
156+ t .Fatal ("No tracks returned" )
157+ }
158+ expected := "112: Dirty Coms"
159+ actual := tracks .Items [0 ].Track .Episode .Name
160+ if expected != actual {
161+ t .Errorf ("Got '%s', expected '%s'\n " , actual , expected )
162+ }
163+ added := tracks .Items [0 ].AddedAt
164+ tm , err := time .Parse (TimestampLayout , added )
165+ if err != nil {
166+ t .Error (err )
167+ }
168+ if f := tm .Format (DateLayout ); f != "2022-05-20" {
169+ t .Errorf ("Expected added at 2014-11-25, got %s\n " , f )
170+ }
171+ }
172+
173+ func TestGetPlaylistItemsTracks (t * testing.T ) {
174+ client , server := testClientFile (http .StatusOK , "test_data/playlist_items_tracks.json" )
175+ defer server .Close ()
176+
177+ tracks , err := client .GetPlaylistItems (context .Background (), "playlistID" )
178+ if err != nil {
179+ t .Error (err )
180+ }
181+ if tracks .Total != 2 {
182+ t .Errorf ("Got %d tracks, expected 47\n " , tracks .Total )
183+ }
184+ if len (tracks .Items ) == 0 {
185+ t .Fatal ("No tracks returned" )
186+ }
187+ expected := "Typhoons"
188+ actual := tracks .Items [0 ].Track .Track .Name
189+ if expected != actual {
190+ t .Errorf ("Got '%s', expected '%s'\n " , actual , expected )
191+ }
192+ added := tracks .Items [0 ].AddedAt
193+ tm , err := time .Parse (TimestampLayout , added )
194+ if err != nil {
195+ t .Error (err )
196+ }
197+ if f := tm .Format (DateLayout ); f != "2022-05-20" {
198+ t .Errorf ("Expected added at 2014-11-25, got %s\n " , f )
199+ }
200+ }
201+
202+ func TestGetPlaylistItemsTracksAndEpisodes (t * testing.T ) {
203+ client , server := testClientFile (http .StatusOK , "test_data/playlist_items_episodes_and_tracks.json" )
204+ defer server .Close ()
205+
206+ tracks , err := client .GetPlaylistItems (context .Background (), "playlistID" )
207+ if err != nil {
208+ t .Error (err )
209+ }
210+ if tracks .Total != 4 {
211+ t .Errorf ("Got %d tracks, expected 47\n " , tracks .Total )
212+ }
213+ if len (tracks .Items ) == 0 {
214+ t .Fatal ("No tracks returned" )
215+ }
216+
217+ expected := "491- The Missing Middle"
218+ actual := tracks .Items [0 ].Track .Episode .Name
219+ if expected != actual {
220+ t .Errorf ("Got '%s', expected '%s'\n " , actual , expected )
221+ }
222+ added := tracks .Items [0 ].AddedAt
223+ tm , err := time .Parse (TimestampLayout , added )
224+ if err != nil {
225+ t .Error (err )
226+ }
227+ if f := tm .Format (DateLayout ); f != "2022-05-20" {
228+ t .Errorf ("Expected added at 2014-11-25, got %s\n " , f )
229+ }
230+
231+ expected = "Typhoons"
232+ actual = tracks .Items [2 ].Track .Track .Name
233+ if expected != actual {
234+ t .Errorf ("Got '%s', expected '%s'\n " , actual , expected )
235+ }
236+ added = tracks .Items [0 ].AddedAt
237+ tm , err = time .Parse (TimestampLayout , added )
238+ if err != nil {
239+ t .Error (err )
240+ }
241+ if f := tm .Format (DateLayout ); f != "2022-05-20" {
242+ t .Errorf ("Expected added at 2014-11-25, got %s\n " , f )
243+ }
244+ }
245+
246+ func TestGetPlaylistItemsOverride (t * testing.T ) {
247+ var types string
248+ client , server := testClientString (http .StatusForbidden , "" , func (r * http.Request ) {
249+ types = r .URL .Query ().Get ("additional_types" )
250+ })
251+ defer server .Close ()
252+
253+ _ , _ = client .GetPlaylistItems (context .Background (), "playlistID" , AdditionalTypes (EpisodeAdditionalType ))
254+
255+ if types != "episode" {
256+ t .Errorf ("Expected additional type episode, got %s\n " , types )
257+ }
258+ }
259+
260+ func TestGetPlaylistItemsDefault (t * testing.T ) {
261+ var types string
262+ client , server := testClientString (http .StatusForbidden , "" , func (r * http.Request ) {
263+ types = r .URL .Query ().Get ("additional_types" )
264+ })
265+ defer server .Close ()
266+
267+ _ , _ = client .GetPlaylistItems (context .Background (), "playlistID" )
268+
269+ if types != "episode,track" {
270+ t .Errorf ("Expected additional type episode, got %s\n " , types )
271+ }
272+ }
273+
144274func TestUserFollowsPlaylist (t * testing.T ) {
145275 client , server := testClientString (http .StatusOK , `[ true, false ]` )
146276 defer server .Close ()
@@ -160,7 +290,7 @@ var newPlaylist = `
160290"collaborative": %t,
161291"description": "Test Description",
162292"external_urls": {
163- "spotify": "http://open.spotify.com/user/thelinmichael/playlist/7d2D2S200NyUE5KYs80PwO"
293+ "spotify": "api. http://open.spotify.com/user/thelinmichael/playlist/7d2D2S200NyUE5KYs80PwO"
164294},
165295"followers": {
166296 "href": null,
@@ -172,7 +302,7 @@ var newPlaylist = `
172302"name": "A New Playlist",
173303"owner": {
174304 "external_urls": {
175- "spotify": "http://open.spotify.com/user/thelinmichael"
305+ "spotify": "api. http://open.spotify.com/user/thelinmichael"
176306 },
177307 "href": "https://api.spotify.com/v1/users/thelinmichael",
178308 "id": "thelinmichael",
0 commit comments