diff options
| author | Cyril Plisko <cyril.plisko@mountall.com> | 2025-03-04 20:01:35 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-04 12:01:35 -0600 | 
| commit | 776843be76e58c2045e2f80e75a72bfd9cac9d83 (patch) | |
| tree | be8526f16b62c5902b5c0279448f899b5560dbf9 /tests | |
| parent | 8ce597c207144faaeb47f3c53657ffa9b50f08ba (diff) | |
Add axum::OptionalQsQuery (#102)
Addresses #101
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_axum.rs | 42 | 
1 files changed, 41 insertions, 1 deletions
diff --git a/tests/test_axum.rs b/tests/test_axum.rs index 16449b9..dd86a9e 100644 --- a/tests/test_axum.rs +++ b/tests/test_axum.rs @@ -8,7 +8,7 @@ extern crate axum_framework as axum;  extern crate serde_qs as qs;  use axum::{extract::FromRequestParts, http::StatusCode, response::IntoResponse}; -use qs::axum::{QsQuery, QsQueryConfig, QsQueryRejection}; +use qs::axum::{OptionalQsQuery, QsQuery, QsQueryConfig, QsQueryRejection};  use serde::de::Error;  fn from_str<'de, D, S>(deserializer: D) -> Result<S, D::Error> @@ -132,3 +132,43 @@ fn test_custom_qs_config() {          assert!(s.common.remaining);      })  } + +#[test] +fn test_optional_query_none() { +    futures::executor::block_on(async { +        let req = axum::http::Request::builder() +            .uri("/test") +            .body(()) +            .unwrap(); +        let (mut req_parts, _) = req.into_parts(); + +        let OptionalQsQuery(s) = OptionalQsQuery::<Query>::from_request_parts(&mut req_parts, &()) +            .await +            .unwrap(); + +        assert!(s.is_none()); +    }) +} + +#[test] +fn test_optional_query_some() { +    futures::executor::block_on(async { +        let req = axum::http::Request::builder() +            .uri("/test?foo=1&bars%5B%5D=3&limit=100&offset=50&remaining=true") +            .extension(QsQueryConfig::new(5, false)) +            .body(()) +            .unwrap(); + +        let (mut req_parts, _) = req.into_parts(); +        let OptionalQsQuery(s) = OptionalQsQuery::<Query>::from_request_parts(&mut req_parts, &()) +            .await +            .unwrap(); + +        let query = s.unwrap(); +        assert_eq!(query.foo, 1); +        assert_eq!(query.bars, vec![3]); +        assert_eq!(query.common.limit, 100); +        assert_eq!(query.common.offset, 50); +        assert!(query.common.remaining); +    }) +}  | 
