Skip to content

Commit

Permalink
test: generalize API tests (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo authored Sep 19, 2024
1 parent 91aeb2f commit a593457
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 716 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ struct_excessive_bools = "allow" # due to Telegram API
# TODO: remove and fix (or allow explicitly on the specific problem)
missing_errors_doc = "allow"
option_if_let_else = "allow"
significant_drop_tightening = "allow"
single_match_else = "allow"
unreadable_literal = "allow"

[[example]]
Expand Down
11 changes: 9 additions & 2 deletions src/client_reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ mod async_tests {
.text("Hello!")
.build();
let mut server = mockito::Server::new_async().await;
let _m = server
let mock = server
.mock("POST", "/sendMessage")
.with_status(200)
.with_body(response_string)
Expand All @@ -166,6 +166,9 @@ mod async_tests {
let api = AsyncApi::new_url(server.url());

let response = api.send_message(&params).await.unwrap();
mock.assert();
drop(server);

json::assert_str(&response, response_string);
}

Expand All @@ -178,14 +181,18 @@ mod async_tests {
.text("Hello!")
.build();
let mut server = mockito::Server::new_async().await;
let _m = server
let mock = server
.mock("POST", "/sendMessage")
.with_status(400)
.with_body(response_string)
.create_async()
.await;
let api = AsyncApi::new_url(server.url());

let error = api.send_message(&params).await.unwrap_err().unwrap_api();
mock.assert();
drop(server);

assert_eq!(error.description, "Bad Request: chat not found");
assert_eq!(error.error_code, 400);
assert_eq!(error.parameters, None);
Expand Down
Loading

0 comments on commit a593457

Please sign in to comment.