Parse data from incoming request

This commit is contained in:
Alphonse Paix
2025-08-23 11:13:57 +02:00
parent d0c146328a
commit 6a25c43ce4
9 changed files with 405 additions and 14 deletions

View File

@@ -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);