@@ -290,4 +290,127 @@ mod mock {
290
290
assert!( body[ "audio_length_sec" ] . as_i64( ) . unwrap( ) > 0 ) ;
291
291
} ) ;
292
292
}
293
+
294
+ #[ test]
295
+ fn fetch_recommendations_for_podcast ( ) {
296
+ b ! ( async {
297
+ let response = client( )
298
+ . fetch_recommendations_for_podcast( "adfsddf" , & json!( { } ) )
299
+ . await
300
+ . unwrap( ) ;
301
+ // Request
302
+ assert_eq!( response. request. method( ) , http:: Method :: GET ) ;
303
+ assert_eq!(
304
+ response. request. url( ) . path( ) ,
305
+ "/api/v2/podcasts/adfsddf/recommendations"
306
+ ) ;
307
+ let p = response. request. url( ) . query_pairs( ) ;
308
+ assert_eq!( p. count( ) , 0 ) ;
309
+ // Response
310
+ let body = response. json( ) . await . unwrap( ) ;
311
+ assert!( body. is_object( ) ) ;
312
+ assert!( body[ "recommendations" ] . as_array( ) . unwrap( ) . len( ) > 0 ) ;
313
+ } ) ;
314
+ }
315
+
316
+ #[ test]
317
+ fn fetch_recommendations_for_episode ( ) {
318
+ b ! ( async {
319
+ let response = client( )
320
+ . fetch_recommendations_for_episode( "asdfasdf" , & json!( { } ) )
321
+ . await
322
+ . unwrap( ) ;
323
+ // Request
324
+ assert_eq!( response. request. method( ) , http:: Method :: GET ) ;
325
+ assert_eq!(
326
+ response. request. url( ) . path( ) ,
327
+ "/api/v2/episodes/asdfasdf/recommendations"
328
+ ) ;
329
+ let p = response. request. url( ) . query_pairs( ) ;
330
+ assert_eq!( p. count( ) , 0 ) ;
331
+ // Response
332
+ let body = response. json( ) . await . unwrap( ) ;
333
+ assert!( body. is_object( ) ) ;
334
+ assert!( body[ "recommendations" ] . as_array( ) . unwrap( ) . len( ) > 0 ) ;
335
+ } ) ;
336
+ }
337
+
338
+ #[ test]
339
+ fn fetch_playlist_by_id ( ) {
340
+ b ! ( async {
341
+ let response = client( ) . fetch_playlist_by_id( "fdsafdsa" , & json!( { } ) ) . await . unwrap( ) ;
342
+ // Request
343
+ assert_eq!( response. request. method( ) , http:: Method :: GET ) ;
344
+ assert_eq!( response. request. url( ) . path( ) , "/api/v2/playlists/fdsafdsa" ) ;
345
+ let p = response. request. url( ) . query_pairs( ) ;
346
+ assert_eq!( p. count( ) , 0 ) ;
347
+ // Response
348
+ let body = response. json( ) . await . unwrap( ) ;
349
+ assert!( body. is_object( ) ) ;
350
+ assert!( body[ "items" ] . as_array( ) . unwrap( ) . len( ) > 0 ) ;
351
+ } ) ;
352
+ }
353
+
354
+ #[ test]
355
+ fn fetch_my_playlists ( ) {
356
+ b ! ( async {
357
+ let response = client( )
358
+ . fetch_my_playlists( & json!( {
359
+ "page" : 2
360
+ } ) )
361
+ . await
362
+ . unwrap( ) ;
363
+ // Request
364
+ assert_eq!( response. request. method( ) , http:: Method :: GET ) ;
365
+ assert_eq!( response. request. url( ) . path( ) , "/api/v2/playlists" ) ;
366
+ let mut p = response. request. url( ) . query_pairs( ) ;
367
+ assert_eq!( p. count( ) , 1 ) ;
368
+ assert_eq!( p. next( ) , Some ( ( Cow :: Borrowed ( "page" ) , Cow :: Borrowed ( "2" ) ) ) ) ;
369
+ // Response
370
+ let body = response. json( ) . await . unwrap( ) ;
371
+ assert!( body. is_object( ) ) ;
372
+ assert!( body[ "playlists" ] . as_array( ) . unwrap( ) . len( ) > 0 ) ;
373
+ } ) ;
374
+ }
375
+
376
+ #[ test]
377
+ fn submit_podcast ( ) {
378
+ b ! ( async {
379
+ let response = client( )
380
+ . submit_podcast( & json!( {
381
+ "rss" : "http://myrss.com/rss"
382
+ } ) )
383
+ . await
384
+ . unwrap( ) ;
385
+ // Request
386
+ assert_eq!( response. request. method( ) , http:: Method :: POST ) ;
387
+ assert_eq!( response. request. url( ) . path( ) , "/api/v2/podcasts/submit" ) ;
388
+ let mut p = form_urlencoded:: parse( response. request. body( ) . unwrap( ) . as_bytes( ) . unwrap( ) ) ;
389
+ assert_eq!( p. count( ) , 1 ) ;
390
+ assert_eq!(
391
+ p. next( ) ,
392
+ Some ( ( Cow :: Borrowed ( "rss" ) , Cow :: Borrowed ( "http://myrss.com/rss" ) ) )
393
+ ) ;
394
+ // Response
395
+ let body = response. json( ) . await . unwrap( ) ;
396
+ assert!( body. is_object( ) ) ;
397
+ assert!( body[ "status" ] . as_str( ) . unwrap( ) . len( ) > 0 ) ;
398
+ } ) ;
399
+ }
400
+
401
+ #[ test]
402
+ fn delete_podcast ( ) {
403
+ b ! ( async {
404
+ let response = client( ) . delete_podcast( "asdfasdfdf" , & json!( { } ) ) . await . unwrap( ) ;
405
+ // Request
406
+ assert_eq!( response. request. method( ) , http:: Method :: DELETE ) ;
407
+ assert_eq!( response. request. url( ) . path( ) , "/api/v2/podcasts/asdfasdfdf" ) ;
408
+ let p = response. request. url( ) . query_pairs( ) ;
409
+ assert_eq!( p. count( ) , 0 ) ;
410
+ // Response
411
+ let body = response. json( ) . await . unwrap( ) ;
412
+ assert!( body. is_object( ) ) ;
413
+ assert!( body[ "status" ] . as_str( ) . unwrap( ) . len( ) > 0 ) ;
414
+ } ) ;
415
+ }
293
416
}
0 commit comments