@@ -4189,7 +4189,7 @@ describe('Spotify Web API', () => {
4189
4189
* Shows
4190
4190
*/
4191
4191
4192
- /* Get a Show */
4192
+ /* Get a Show */
4193
4193
test ( 'should get a show' , done => {
4194
4194
sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
4195
4195
method ,
@@ -4204,19 +4204,6 @@ describe('Spotify Web API', () => {
4204
4204
expect ( options . query . market ) . toBe ( 'SE' ) ;
4205
4205
4206
4206
callback ( null , {
4207
- body : {
4208
- total_episodes : 3 ,
4209
- type : "show" ,
4210
- name : "The API show" ,
4211
- episodes : [ {
4212
- items : [
4213
- {
4214
- "audio_preview_url" : "https://p.scdn.co/mp3-preview/7a785904a33e34b0b2bd382c82fca16be7060c36" ,
4215
- "duration_ms" : 2677448
4216
- }
4217
- ]
4218
- } ]
4219
- } ,
4220
4207
statusCode : 200
4221
4208
} )
4222
4209
} ) ;
@@ -4225,13 +4212,142 @@ describe('Spotify Web API', () => {
4225
4212
4226
4213
api . getShow ( '123' , { market : 'SE' } ) . then (
4227
4214
function ( data ) {
4228
- expect ( data . body . total_episodes ) . toBe ( 3 ) ;
4229
- expect ( data . body . episodes [ 0 ] . items [ 0 ] . duration_ms ) . toBe ( 2677448 ) ;
4230
4215
done ( ) ;
4231
4216
} ,
4232
4217
function ( err ) {
4233
4218
done ( err ) ;
4234
4219
}
4235
4220
) ;
4236
4221
} ) ;
4222
+
4223
+ /* Look up several shows */
4224
+ test ( 'should get several shows' , done => {
4225
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
4226
+ method ,
4227
+ options ,
4228
+ uri ,
4229
+ callback
4230
+ ) {
4231
+ expect ( method ) . toBe ( superagent . get ) ;
4232
+ expect ( uri ) . toBe (
4233
+ 'https://api.spotify.com/v1/shows'
4234
+ ) ;
4235
+ expect ( options . query . market ) . toBe ( 'SE' ) ;
4236
+ expect ( options . query . ids ) . toBe ( '1,2,3' ) ;
4237
+ callback ( null , {
4238
+ statusCode : 200
4239
+ } )
4240
+ } ) ;
4241
+
4242
+ var api = new SpotifyWebApi ( ) ;
4243
+
4244
+ api . getShows ( [ '1' , '2' , '3' ] , { market : 'SE' } ) . then (
4245
+ function ( data ) {
4246
+ done ( ) ;
4247
+ } ,
4248
+ function ( err ) {
4249
+ done ( err ) ;
4250
+ }
4251
+ ) ;
4252
+ } ) ;
4253
+
4254
+ /* Check if one or more shows is already saved in the current Spotify user’s “Your Music” library. */
4255
+ test ( 'should see that show is already saved by user' , done => {
4256
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
4257
+ method ,
4258
+ options ,
4259
+ uri ,
4260
+ callback
4261
+ ) {
4262
+ expect ( method ) . toBe ( superagent . get ) ;
4263
+ expect ( uri ) . toBe (
4264
+ 'https://api.spotify.com/v1/me/shows/contains'
4265
+ ) ;
4266
+ expect ( options . query . ids ) . toBe ( '1,2,3' ) ;
4267
+ callback ( null , {
4268
+ body : [ true , false , false ] ,
4269
+ statusCode : 200
4270
+ } )
4271
+ } ) ;
4272
+
4273
+ var api = new SpotifyWebApi ( ) ;
4274
+
4275
+ api . containsMySavedShows ( [ '1' , '2' , '3' ] ) . then (
4276
+ function ( data ) {
4277
+ done ( ) ;
4278
+ } ,
4279
+ function ( err ) {
4280
+ done ( err ) ;
4281
+ }
4282
+ ) ;
4283
+ } ) ;
4284
+
4285
+ /* Get the episodes of an show. */
4286
+ test ( 'should retrieve the episodes of a show' , done => {
4287
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
4288
+ method ,
4289
+ options ,
4290
+ uri ,
4291
+ callback
4292
+ ) {
4293
+ expect ( method ) . toBe ( superagent . get ) ;
4294
+ expect ( uri ) . toBe (
4295
+ 'https://api.spotify.com/v1/shows/123/episodes'
4296
+ ) ;
4297
+ expect ( options . query . market ) . toBe ( 'SE' ) ;
4298
+ expect ( options . query . limit ) . toBe ( 1 ) ;
4299
+ expect ( options . query . offset ) . toBe ( 2 ) ;
4300
+ callback ( null , {
4301
+ body : { } ,
4302
+ statusCode : 200
4303
+ } )
4304
+ } ) ;
4305
+
4306
+ var api = new SpotifyWebApi ( ) ;
4307
+
4308
+ api . getShowEpisodes ( '123' , { 'market' : 'SE' , 'limit' : 1 , 'offset' : 2 } ) . then (
4309
+ function ( data ) {
4310
+ done ( ) ;
4311
+ } ,
4312
+ function ( err ) {
4313
+ done ( err ) ;
4314
+ }
4315
+ ) ;
4316
+ } ) ;
4317
+
4318
+ /* Search for a show. */
4319
+ test ( 'should search for a show' , done => {
4320
+ sinon . stub ( HttpManager , '_makeRequest' ) . callsFake ( function (
4321
+ method ,
4322
+ options ,
4323
+ uri ,
4324
+ callback
4325
+ ) {
4326
+ expect ( method ) . toBe ( superagent . get ) ;
4327
+ expect ( uri ) . toBe (
4328
+ 'https://api.spotify.com/v1/search/'
4329
+ ) ;
4330
+ expect ( options . query . q ) . toBe ( 'kvartal' ) ;
4331
+ expect ( options . query . type ) . toBe ( 'show' ) ;
4332
+ expect ( options . query . market ) . toBe ( 'SE' ) ;
4333
+ expect ( options . query . limit ) . toBe ( 3 ) ;
4334
+ expect ( options . query . offset ) . toBe ( 1 ) ;
4335
+ callback ( null , {
4336
+ body : { } ,
4337
+ statusCode : 200
4338
+ } )
4339
+ } ) ;
4340
+
4341
+ var api = new SpotifyWebApi ( ) ;
4342
+
4343
+ api . searchShows ( 'kvartal' , { 'market' : 'SE' , 'limit' : 3 , 'offset' : 1 } ) . then (
4344
+ function ( data ) {
4345
+ done ( ) ;
4346
+ } ,
4347
+ function ( err ) {
4348
+ done ( err ) ;
4349
+ }
4350
+ ) ;
4351
+ } ) ;
4352
+
4237
4353
} ) ;
0 commit comments