@@ -1666,6 +1666,29 @@ describe('Spotify Web API', () => {
1666
1666
} ) ;
1667
1667
} ) ;
1668
1668
1669
+ test ( "should get user\'s currently playing track" , done => {
1670
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
1671
+ method ,
1672
+ options ,
1673
+ uri ,
1674
+ callback
1675
+ ) {
1676
+ expect ( method ) . toBe ( superagent . get ) ;
1677
+ expect ( uri ) . toBe ( 'https://api.spotify.com/v1/me/player/currently-playing' ) ;
1678
+ expect ( options . query ) . toStrictEqual ( { market : 'NO' } ) ;
1679
+ expect ( options . headers ) . toEqual ( { Authorization : 'Bearer someAccessToken' } ) ;
1680
+ callback ( null , { } ) ;
1681
+ } ) ;
1682
+
1683
+ var api = new SpotifyWebApi ( {
1684
+ accessToken : 'someAccessToken'
1685
+ } ) ;
1686
+
1687
+ api . getMyCurrentPlayingTrack ( { market : 'NO' } ) . then ( function ( data , err ) {
1688
+ done ( err ) ;
1689
+ } ) ;
1690
+ } ) ;
1691
+
1669
1692
test ( "should get user's recently played tracks:" , done => {
1670
1693
sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
1671
1694
method ,
@@ -2050,7 +2073,74 @@ describe('Spotify Web API', () => {
2050
2073
) ;
2051
2074
} ) ;
2052
2075
2053
- test ( "should set the user's playback shuffle mode" , done => {
2076
+ test ( "should set the user's playback repeat mode without given device" , done => {
2077
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
2078
+ method ,
2079
+ options ,
2080
+ uri ,
2081
+ callback
2082
+ ) {
2083
+ expect ( method ) . toBe ( superagent . put ) ;
2084
+ expect ( uri ) . toBe ( 'https://api.spotify.com/v1/me/player/repeat' ) ;
2085
+ expect ( options . query ) . toBeTruthy ( ) ;
2086
+ expect ( options . query . state ) . toEqual ( 'context' ) ;
2087
+ expect ( options . query . device_id ) . toBeFalsy ( ) ;
2088
+ expect ( options . body ) . toBeFalsy ( ) ;
2089
+ expect ( options . headers . Authorization ) . toBe ( 'Bearer myAccessToken' ) ;
2090
+ expect ( options . headers [ 'Content-Type' ] ) . toBeFalsy ( ) ;
2091
+ callback ( ) ;
2092
+ } ) ;
2093
+
2094
+ var accessToken = 'myAccessToken' ;
2095
+
2096
+ var api = new SpotifyWebApi ( {
2097
+ accessToken : accessToken
2098
+ } ) ;
2099
+
2100
+ api . setRepeat ( 'context' , { } ) . then (
2101
+ function ( data ) {
2102
+ done ( ) ;
2103
+ } ,
2104
+ function ( err ) {
2105
+ console . log ( err ) ;
2106
+ done ( err ) ;
2107
+ }
2108
+ ) ;
2109
+ } ) ;
2110
+
2111
+ test ( "should set the user's playback shuffle mode with device" , done => {
2112
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
2113
+ method ,
2114
+ options ,
2115
+ uri ,
2116
+ callback
2117
+ ) {
2118
+ expect ( method ) . toBe ( superagent . put ) ;
2119
+ expect ( uri ) . toBe ( 'https://api.spotify.com/v1/me/player/shuffle' ) ;
2120
+ expect ( options . query ) . toBeTruthy ( ) ;
2121
+ expect ( options . query . state ) . toEqual ( true )
2122
+ expect ( options . query . device_id ) . toEqual ( 'my-device' ) ;
2123
+ expect ( options . body ) . toBeFalsy ( ) ;
2124
+ callback ( ) ;
2125
+ } ) ;
2126
+
2127
+ var accessToken = 'myAccessToken' ;
2128
+
2129
+ var api = new SpotifyWebApi ( {
2130
+ accessToken : accessToken
2131
+ } ) ;
2132
+
2133
+ api . setShuffle ( true , { device_id : 'my-device' } ) . then (
2134
+ function ( data ) {
2135
+ done ( ) ;
2136
+ } ,
2137
+ function ( err ) {
2138
+ done ( err ) ;
2139
+ }
2140
+ ) ;
2141
+ } ) ;
2142
+
2143
+ test ( "should set the user's playback shuffle mode without device id" , done => {
2054
2144
sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
2055
2145
method ,
2056
2146
options ,
@@ -2082,6 +2172,39 @@ describe('Spotify Web API', () => {
2082
2172
) ;
2083
2173
} ) ;
2084
2174
2175
+ test ( "should set the user's playback volume without device id" , done => {
2176
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
2177
+ method ,
2178
+ options ,
2179
+ uri ,
2180
+ callback
2181
+ ) {
2182
+ expect ( method ) . toBe ( superagent . put ) ;
2183
+ expect ( uri ) . toBe ( 'https://api.spotify.com/v1/me/player/volume' ) ;
2184
+ expect ( options . query ) . toEqual ( {
2185
+ volume_percent : 75
2186
+ } ) ;
2187
+ expect ( options . body ) . toBeFalsy ( ) ;
2188
+ callback ( ) ;
2189
+ } ) ;
2190
+
2191
+ var accessToken = 'myAccessToken' ;
2192
+
2193
+ var api = new SpotifyWebApi ( {
2194
+ accessToken : accessToken
2195
+ } ) ;
2196
+
2197
+ api . setVolume ( 75 ) . then (
2198
+ function ( data ) {
2199
+ done ( ) ;
2200
+ } ,
2201
+ function ( err ) {
2202
+ console . log ( err ) ;
2203
+ done ( err ) ;
2204
+ }
2205
+ ) ;
2206
+ } ) ;
2207
+
2085
2208
test ( "should set the user's playback volume" , done => {
2086
2209
sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
2087
2210
method ,
@@ -2215,6 +2338,76 @@ describe('Spotify Web API', () => {
2215
2338
) ;
2216
2339
} ) ;
2217
2340
2341
+ /* Get My Saved Tracks */
2342
+ test ( 'should get tracks in the user\' library' , done => {
2343
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
2344
+ method ,
2345
+ options ,
2346
+ uri ,
2347
+ callback
2348
+ ) {
2349
+ expect ( method ) . toBe ( superagent . get ) ;
2350
+ expect ( options . data ) . toBeFalsy ( ) ;
2351
+ expect ( uri ) . toBe ( 'https://api.spotify.com/v1/me/tracks' ) ;
2352
+ expect ( options . query . limit ) . toBe ( 1 ) ;
2353
+ expect ( options . query . offset ) . toBe ( 3 ) ;
2354
+ expect ( options . query . market ) . toBe ( 'SE' ) ;
2355
+ expect ( options . headers [ 'Content-Type' ] ) . toBeFalsy ( ) ;
2356
+ expect ( options . headers . Authorization ) . toBe ( 'Bearer myAccessToken' ) ;
2357
+ callback ( ) ;
2358
+ } ) ;
2359
+
2360
+ var accessToken = 'myAccessToken' ;
2361
+
2362
+ var api = new SpotifyWebApi ( {
2363
+ accessToken : accessToken
2364
+ } ) ;
2365
+
2366
+ api . getMySavedTracks ( { market : 'SE' , limit : 1 , offset : 3 } ) . then (
2367
+ function ( data ) {
2368
+ done ( ) ;
2369
+ } ,
2370
+ function ( err ) {
2371
+ console . log ( err ) ;
2372
+ done ( err ) ;
2373
+ }
2374
+ ) ;
2375
+ } ) ;
2376
+
2377
+ /* Check if Track is in User\'s Saved Tracks */
2378
+ test ( 'should check if track is in user\'s library' , done => {
2379
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
2380
+ method ,
2381
+ options ,
2382
+ uri ,
2383
+ callback
2384
+ ) {
2385
+ expect ( method ) . toBe ( superagent . get ) ;
2386
+ expect ( uri ) . toBe ( 'https://api.spotify.com/v1/me/tracks/contains' ) ;
2387
+ expect ( options . data ) . toBeFalsy ( ) ;
2388
+ expect ( options . query . ids ) . toBe ( '27cZdqrQiKt3IT00338dws,37cZdqrQiKt3IT00338dzs' )
2389
+ expect ( options . headers [ 'Content-Type' ] ) . toBeFalsy ( ) ;
2390
+ expect ( options . headers . Authorization ) . toBe ( 'Bearer myAccessToken' ) ;
2391
+ callback ( ) ;
2392
+ } ) ;
2393
+
2394
+ var accessToken = 'myAccessToken' ;
2395
+
2396
+ var api = new SpotifyWebApi ( {
2397
+ accessToken : accessToken
2398
+ } ) ;
2399
+
2400
+ api . containsMySavedTracks ( [ '27cZdqrQiKt3IT00338dws' , '37cZdqrQiKt3IT00338dzs' ] ) . then (
2401
+ function ( data ) {
2402
+ done ( ) ;
2403
+ } ,
2404
+ function ( err ) {
2405
+ console . log ( err ) ;
2406
+ done ( err ) ;
2407
+ }
2408
+ ) ;
2409
+ } ) ;
2410
+
2218
2411
test ( 'should remove albums in the users library' , done => {
2219
2412
sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
2220
2413
method ,
@@ -3926,6 +4119,105 @@ describe('Spotify Web API', () => {
3926
4119
) ;
3927
4120
} ) ;
3928
4121
4122
+ /* Remove from user\'s saved shows. */
4123
+ test ( 'should remove from user\'s saved shows' , done => {
4124
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
4125
+ method ,
4126
+ options ,
4127
+ uri ,
4128
+ callback
4129
+ ) {
4130
+ expect ( method ) . toBe ( superagent . del ) ;
4131
+ expect ( uri ) . toBe (
4132
+ 'https://api.spotify.com/v1/me/shows'
4133
+ ) ;
4134
+ expect ( JSON . parse ( options . data ) ) . toStrictEqual ( [ "1" , "2" , "3" ] ) ;
4135
+ expect ( options . query ) . toBeFalsy ( ) ;
4136
+ expect ( options . headers . Authorization ) . toEqual ( 'Bearer longtoken' ) ;
4137
+ expect ( options . headers [ 'Content-Type' ] ) . toEqual ( 'application/json' ) ;
4138
+ callback ( null , { } )
4139
+ } ) ;
4140
+
4141
+ var api = new SpotifyWebApi ( ) ;
4142
+ api . setAccessToken ( 'longtoken' ) ;
4143
+
4144
+ api . removeFromMySavedShows ( [ '1' , '2' , '3' ] ) . then (
4145
+ function ( data ) {
4146
+ done ( ) ;
4147
+ } ,
4148
+ function ( err ) {
4149
+ done ( err ) ;
4150
+ }
4151
+ ) ;
4152
+ } ) ;
4153
+
4154
+ /* Add to user\'s saved shows. */
4155
+ test ( 'should remove from user\'s saved shows' , done => {
4156
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
4157
+ method ,
4158
+ options ,
4159
+ uri ,
4160
+ callback
4161
+ ) {
4162
+ expect ( method ) . toBe ( superagent . put ) ;
4163
+ expect ( uri ) . toBe (
4164
+ 'https://api.spotify.com/v1/me/shows'
4165
+ ) ;
4166
+ expect ( JSON . parse ( options . data ) ) . toStrictEqual ( [ "1" , "2" , "3" ] ) ;
4167
+ expect ( options . query ) . toBeFalsy ( ) ;
4168
+ expect ( options . headers . Authorization ) . toEqual ( 'Bearer longtoken' ) ;
4169
+ expect ( options . headers [ 'Content-Type' ] ) . toEqual ( 'application/json' ) ;
4170
+ callback ( null , { } )
4171
+ } ) ;
4172
+
4173
+ var api = new SpotifyWebApi ( ) ;
4174
+ api . setAccessToken ( 'longtoken' ) ;
4175
+
4176
+ api . addToMySavedShows ( [ '1' , '2' , '3' ] ) . then (
4177
+ function ( data ) {
4178
+ done ( ) ;
4179
+ } ,
4180
+ function ( err ) {
4181
+ done ( err ) ;
4182
+ }
4183
+ ) ;
4184
+ } ) ;
4185
+
4186
+ /* Get user\'s saved shows. */
4187
+ test ( 'should remove from user\'s saved shows' , done => {
4188
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
4189
+ method ,
4190
+ options ,
4191
+ uri ,
4192
+ callback
4193
+ ) {
4194
+ expect ( method ) . toBe ( superagent . get ) ;
4195
+ expect ( uri ) . toBe (
4196
+ 'https://api.spotify.com/v1/me/shows'
4197
+ ) ;
4198
+ expect ( options . data ) . toBeFalsy ( ) ;
4199
+ expect ( options . query . limit ) . toBe ( 1 ) ;
4200
+ expect ( options . query . offset ) . toBe ( 2 ) ;
4201
+ expect ( options . query . market ) . toBe ( 'DK' ) ;
4202
+ expect ( options . headers . Authorization ) . toEqual ( 'Bearer longtoken' ) ;
4203
+ expect ( options . headers [ 'Content-Type' ] ) . toBeFalsy ( ) ;
4204
+ callback ( null , { } )
4205
+ } ) ;
4206
+
4207
+ var api = new SpotifyWebApi ( ) ;
4208
+ api . setAccessToken ( 'longtoken' ) ;
4209
+
4210
+ api . getMySavedShows ( { market : 'DK' , limit : 1 , offset : 2 } ) . then (
4211
+ function ( data ) {
4212
+ done ( ) ;
4213
+ } ,
4214
+ function ( err ) {
4215
+ done ( err ) ;
4216
+ }
4217
+ ) ;
4218
+ } ) ;
4219
+
4220
+
3929
4221
/* Get the episodes of an show. */
3930
4222
test ( 'should retrieve the episodes of a show' , done => {
3931
4223
sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
0 commit comments