-
Notifications
You must be signed in to change notification settings - Fork 1
Finish first 7 endpoints + unit tests + crate docs #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5299ea0
ad961fb
0aec839
f63c418
0600308
fc1be97
23a011e
94fa566
ba2c5f1
863c4a6
98bc939
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,23 @@ | ||
| # podcast-api-rust | ||
| Rust library for the Listen Notes Podcast API | ||
|
|
||
| ## Check | ||
| - formatting: `cargo fmt -- --check` | ||
| - valid code: `cargo check` | ||
| - linting: `cargo clippy` | ||
|
|
||
| ## Open Docs | ||
| `cargo doc --open` | ||
|
|
||
| ## Build | ||
| `cargo build` | ||
|
|
||
| ## Test | ||
| `cargo test` | ||
|
|
||
| ## Usage | ||
| Add this to your `Cargo.toml`: | ||
| ```toml | ||
| [dependencies] | ||
| podcast-api = "0.1" | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| macro_rules! b { | ||
| ($e:expr) => { | ||
| tokio_test::block_on($e) | ||
| }; | ||
| } | ||
|
|
||
| mod mock { | ||
| use serde_json::json; | ||
|
|
||
| fn client<'a>() -> podcast_api::Client<'a> { | ||
| podcast_api::Client::new(reqwest::Client::new(), None) | ||
| } | ||
|
|
||
| #[test] | ||
| fn search() { | ||
| let response = b!(client().search(&json!({ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's test 4 things for each client function: 1, see if the endpoint url is correct (sometimes we copy & paste to make a function hit the wrong url) 2, see if the http method is correct. For this function, it should be GET; for some other functions, it should be POST or DELETE 3, see if parameters are passed okay. For GET functions, check if query strings contain the expected parameters. 4, see if the response json is good, which you already did. Example: https://github.com/ListenNotes/podcast-api-python/blob/main/tests/test_client.py#L16
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this would be a bit awkward to add to the existing tests as I don't like any of the solutions for making that information user facing but I could test those items separately with a module mocking your API expecting those properties from the client.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's make a new Response struct similar to the one in our swift sdk: We need users to be able to access stats returned from response headers and maybe the raw request object. |
||
| "q": "dummy", | ||
| "sort_by_date": 1 | ||
| }))) | ||
| .unwrap(); | ||
| assert!(response.is_object()); | ||
| assert!(response["results"].as_array().unwrap().len() > 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn typeahead() { | ||
| let response = b!(client().typeahead(&json!({ | ||
| "q": "dummy", | ||
| "show_podcasts": 1 | ||
| }))) | ||
| .unwrap(); | ||
| assert!(response.is_object()); | ||
| assert!(response["terms"].as_array().unwrap().len() > 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn fetch_best_podcasts() { | ||
| let response = b!(client().fetch_best_podcasts(&json!({ | ||
| "genre_id": 23, | ||
| }))) | ||
| .unwrap(); | ||
| assert!(response.is_object()); | ||
| assert!(response["total"].as_i64().unwrap() > 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn fetch_podcast_by_id() { | ||
| let response = b!(client().fetch_podcast_by_id("dummy_id", &json!({}))).unwrap(); | ||
| assert!(response.is_object()); | ||
| assert!(response["episodes"].as_array().unwrap().len() > 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn batch_fetch_podcasts() { | ||
| let response = b!(client().batch_fetch_podcasts(&json!({ | ||
| "ids": "996,777,888,1000" | ||
| }))) | ||
| .unwrap(); | ||
| assert!(response.is_object()); | ||
| assert!(response["podcasts"].as_array().unwrap().len() > 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn fetch_episode_by_id() { | ||
| let response = b!(client().fetch_episode_by_id("dummy_id", &json!({}))).unwrap(); | ||
| assert!(response.is_object()); | ||
| assert!( | ||
| response["podcast"].as_object().unwrap()["rss"] | ||
| .as_str() | ||
| .unwrap() | ||
| .len() | ||
| > 0 | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn batch_fetch_episodes() { | ||
| let response = b!(client().batch_fetch_episodes(&json!({ | ||
| "ids": "996,777,888,1000" | ||
| }))) | ||
| .unwrap(); | ||
| assert!(response.is_object()); | ||
| assert!(response["episodes"].as_array().unwrap().len() > 0); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a test_* prefix to each unit test name? Making this
test_search()not sure if it's conventional to have both unit test & the tested function have the same name.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't say there's widespread consensus on this but this way of doing it isn't uncommon since it's already in a test file and you don't need to worry about name/symbol collision. This is how I normally do it but it's largely personal opinion so I'll leave it up to you if you want these as
Xortest_X. Happy to change them if you want