|
| 1 | +macro_rules! b { |
| 2 | + ($e:expr) => { |
| 3 | + tokio_test::block_on($e) |
| 4 | + }; |
| 5 | +} |
| 6 | + |
| 7 | +mod mock { |
| 8 | + use serde_json::json; |
| 9 | + |
| 10 | + fn client<'a>() -> podcast_api::Client<'a> { |
| 11 | + podcast_api::Client::new(reqwest::Client::new(), None) |
| 12 | + } |
| 13 | + |
| 14 | + #[test] |
| 15 | + fn search() { |
| 16 | + let response = b!(client().search(&json!({ |
| 17 | + "q": "dummy", |
| 18 | + "sort_by_date": 1 |
| 19 | + }))) |
| 20 | + .unwrap(); |
| 21 | + assert!(response.is_object()); |
| 22 | + assert!(response["results"].as_array().unwrap().len() > 0); |
| 23 | + } |
| 24 | + |
| 25 | + #[test] |
| 26 | + fn typeahead() { |
| 27 | + let response = b!(client().typeahead(&json!({ |
| 28 | + "q": "dummy", |
| 29 | + "show_podcasts": 1 |
| 30 | + }))) |
| 31 | + .unwrap(); |
| 32 | + assert!(response.is_object()); |
| 33 | + assert!(response["terms"].as_array().unwrap().len() > 0); |
| 34 | + } |
| 35 | + |
| 36 | + #[test] |
| 37 | + fn best_podcasts() { |
| 38 | + let response = b!(client().best_podcasts(&json!({ |
| 39 | + "genre_id": 23, |
| 40 | + }))) |
| 41 | + .unwrap(); |
| 42 | + assert!(response.is_object()); |
| 43 | + assert!(response["total"].as_i64().unwrap() > 0); |
| 44 | + } |
| 45 | + |
| 46 | + #[test] |
| 47 | + fn podcast() { |
| 48 | + let response = b!(client().podcast("dummy_id", &json!({}))).unwrap(); |
| 49 | + assert!(response.is_object()); |
| 50 | + assert!(response["episodes"].as_array().unwrap().len() > 0); |
| 51 | + } |
| 52 | + |
| 53 | + #[test] |
| 54 | + fn podcasts() { |
| 55 | + let response = b!(client().podcasts(&json!({ |
| 56 | + "ids": "996,777,888,1000" |
| 57 | + }))) |
| 58 | + .unwrap(); |
| 59 | + assert!(response.is_object()); |
| 60 | + assert!(response["podcasts"].as_array().unwrap().len() > 0); |
| 61 | + } |
| 62 | + |
| 63 | + #[test] |
| 64 | + fn episode() { |
| 65 | + let response = b!(client().episode("dummy_id", &json!({}))).unwrap(); |
| 66 | + assert!(response.is_object()); |
| 67 | + assert!( |
| 68 | + response["podcast"].as_object().unwrap()["rss"] |
| 69 | + .as_str() |
| 70 | + .unwrap() |
| 71 | + .len() |
| 72 | + > 0 |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + #[test] |
| 77 | + fn episodes() { |
| 78 | + let response = b!(client().episodes(&json!({ |
| 79 | + "ids": "996,777,888,1000" |
| 80 | + }))) |
| 81 | + .unwrap(); |
| 82 | + assert!(response.is_object()); |
| 83 | + assert!(response["episodes"].as_array().unwrap().len() > 0); |
| 84 | + } |
| 85 | +} |
0 commit comments