1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-25 01:51:23 +02:00

Private serde fork (#390)

* Fork serde_urlencoded

* Apply enum PR https://github.com/nox/serde_urlencoded/pull/30

* Add test to verify enum in query

* Docs are updated to show example of how to use enum.
This commit is contained in:
Douman
2018-07-13 09:59:09 +03:00
committed by GitHub
parent 4395add1c7
commit 7d753eeb8c
11 changed files with 1595 additions and 8 deletions

View File

@ -91,6 +91,48 @@ fn test_query_extractor() {
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
}
#[derive(Deserialize, Debug)]
pub enum ResponseType {
Token,
Code
}
#[derive(Debug, Deserialize)]
pub struct AuthRequest {
id: u64,
response_type: ResponseType,
}
#[test]
fn test_query_enum_extractor() {
let mut srv = test::TestServer::new(|app| {
app.resource("/index.html", |r| {
r.with(|p: Query<AuthRequest>| format!("{:?}", p.into_inner()))
});
});
// client request
let request = srv
.get()
.uri(srv.url("/index.html?id=64&response_type=Code"))
.finish()
.unwrap();
let response = srv.execute(request.send()).unwrap();
assert!(response.status().is_success());
// read response
let bytes = srv.execute(response.body()).unwrap();
assert_eq!(bytes, Bytes::from_static(b"AuthRequest { id: 64, response_type: Code }"));
let request = srv.get().uri(srv.url("/index.html?id=64&response_type=Co")).finish().unwrap();
let response = srv.execute(request.send()).unwrap();
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
let request = srv.get().uri(srv.url("/index.html?response_type=Code")).finish().unwrap();
let response = srv.execute(request.send()).unwrap();
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
}
#[test]
fn test_async_extractor_async() {
let mut srv = test::TestServer::new(|app| {