Skip to content

Commit 0aec839

Browse files
committed
Unit tests for first 7 endpoints
1 parent ad961fb commit 0aec839

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ edition = "2018"
1010
serde = { version = "1", features = ["derive"] }
1111
serde_json = "1"
1212
tokio = { version = "1", features = ["full"] }
13+
tokio-test = "0.4"
1314
reqwest = { version = "0.11", features = ["json"] }

tests/client_tests.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

Comments
 (0)