Skip to content

Commit

Permalink
Nice failing tests when data is missing - Multiple data in one test
Browse files Browse the repository at this point in the history
  • Loading branch information
ICavlek committed Sep 27, 2023
1 parent ca6714b commit 1747885
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/health_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,29 @@ async fn subscribe_returns_a_200_for_valid_form_data() {
.expect("Failed to execute reques");
assert_eq!(200, response.status().as_u16());
}

#[tokio::test]
async fn subscribe_returns_a_400_when_data_is_missing() {
let app_address = spawn_app();
let client = reqwest::Client::new();
let test_cases = vec![
("name=le%20guin", "missing the email"),
("email=ursula_le_guin%40gmail.com", "missing the name"),
("", "missing both name and email"),
];
for (invalid_body, error_message) in test_cases {
let response = client
.post(&format!("{}/subscriptions", &app_address))
.header("Content-Type", "application/x-www-form-urlencoded")
.body(invalid_body)
.send()
.await
.expect("Failed to execute request");
assert_eq!(
400,
response.status().as_u16(),
"The API did not fail with 400 Bad Request when the payload was {}.",
error_message
);
}
}

0 comments on commit 1747885

Please sign in to comment.