Parse data from incoming request
This commit is contained in:
@@ -88,6 +88,34 @@ async fn subscribe_returns_a_422_when_data_is_missing() {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn subscribe_returns_a_400_when_fields_are_present_but_invalid() {
|
||||
let app = spawn_app().await;
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
let test_cases = [
|
||||
("name=&email=alphonse.paix%40outlook.com", "empty name"),
|
||||
("name=Alphonse&email=", "empty email"),
|
||||
("name=Alphonse&email=not-an-email", "invalid email"),
|
||||
];
|
||||
for (body, description) in test_cases {
|
||||
let response = client
|
||||
.post(format!("http://{}/subscriptions", app.address))
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.body(body)
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
400,
|
||||
response.status().as_u16(),
|
||||
"the API did not return a 400 Bad Request when the payload had an {}.",
|
||||
description
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async fn spawn_app() -> TestApp {
|
||||
Lazy::force(&TRACING);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user