-
Notifications
You must be signed in to change notification settings - Fork 3
Add Link Header Tests #120
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
Conversation
wp_api/Cargo.toml
Outdated
|
||
[dev-dependencies] | ||
chrono = { version = "0.4" } | ||
claim = "0.5" |
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.
It's probably not worth adding a dependency just for assert_none
which can be done with .is_none()
.
wp_api/src/request.rs
Outdated
#[test] | ||
fn test_link_header_can_be_parsed_for_first_page() { | ||
let response = WPNetworkResponse{ body: Vec::with_capacity(0), status_code: 200, header_map: Some(HashMap::from([("Link".to_string(), "<http://localhost/wp-json/wp/v2/posts?page=2>; rel=\"next\"".to_string())])) }; | ||
assert_eq!(response.get_link_header("next").unwrap(), Url::parse("http://localhost/wp-json/wp/v2/posts?page=2").unwrap()); | ||
assert_none!(response.get_link_header("prev")); | ||
} | ||
|
||
#[test] | ||
fn test_link_header_can_be_parsed_for_intermediate_pages() { | ||
let response = WPNetworkResponse{ body: Vec::with_capacity(0), status_code: 200, header_map: Some(HashMap::from([("Link".to_string(), "<http://localhost/wp-json/wp/v2/posts?page=1>; rel=\"prev\", <http://localhost/wp-json/wp/v2/posts?page=3>; rel=\"next\"".to_string())])) }; | ||
assert_eq!(response.get_link_header("prev").unwrap(), Url::parse("http://localhost/wp-json/wp/v2/posts?page=1").unwrap()); | ||
assert_eq!(response.get_link_header("next").unwrap(), Url::parse("http://localhost/wp-json/wp/v2/posts?page=3").unwrap()); | ||
} | ||
|
||
#[test] | ||
fn test_link_header_can_be_parsed_for_last_page() { | ||
let response = WPNetworkResponse{ body: Vec::with_capacity(0), status_code: 200, header_map: Some(HashMap::from([("Link".to_string(), "<http://localhost/wp-json/wp/v2/posts?page=5>; rel=\"prev\"".to_string())])) }; | ||
assert_none!(response.get_link_header("next")); | ||
assert_eq!(response.get_link_header("prev").unwrap(), Url::parse("http://localhost/wp-json/wp/v2/posts?page=5").unwrap()); | ||
} |
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 think these tests can be written in a much nicer way with rstest
that'll allow us to add more cases without having to copy/paste the implementation.
Since there were some syntax suggestions as well, I combined all of them into a suggestion commit: 53e7072. Let me know what you think!
141b035
to
81d80cb
Compare
81d80cb
to
f50c3eb
Compare
Adds tests for #119 – the code works correctly, and this does overlap with what the Link Header Parser's test suite should do, but now that we're re-mapping the output in a more efficient way I figure it'd be nice to be able to quickly ensure that it's working.
To Test: