Refactor send_request in client.rs (#13701)

Closes #13687
Closes #13686

# Description
Light refactoring of `send_request `in `client.rs`. In the end there are
more lines but now the logic is more concise and facilitates adding new
conditions in the future. Unit tests ran fine and I tested a few cases
manually.
Cool project btw, I'll be using nushell from now on.
This commit is contained in:
xonas
2024-09-04 18:05:39 -03:00
committed by GitHub
parent 63b94dbd28
commit 4792328d0e
3 changed files with 203 additions and 123 deletions

View File

@ -133,6 +133,36 @@ fn http_post_json_list_is_success() {
assert!(actual.out.is_empty())
}
#[test]
fn http_post_json_int_is_success() {
let mut server = Server::new();
let mock = server.mock("POST", "/").match_body(r#"50"#).create();
let actual = nu!(format!(
r#"http post -t 'application/json' {url} 50"#,
url = server.url()
));
mock.assert();
assert!(actual.out.is_empty())
}
#[test]
fn http_post_json_string_is_success() {
let mut server = Server::new();
let mock = server.mock("POST", "/").match_body(r#""test""#).create();
let actual = nu!(format!(
r#"http post -t 'application/json' {url} "test""#,
url = server.url()
));
mock.assert();
assert!(actual.out.is_empty())
}
#[test]
fn http_post_follows_redirect() {
let mut server = Server::new();