Lines
100 %
Functions
Branches
use super::form_invalid;
use axum::{body::to_bytes, http::StatusCode};
use forms::{Form, TRANSACTION_CREATE};
#[tokio::test]
async fn answers_422_retargeting_the_form() {
let response = form_invalid(&TRANSACTION_CREATE, "<form></form>".into());
assert_eq!(response.status(), StatusCode::UNPROCESSABLE_ENTITY);
assert_eq!(response.headers()["hx-retarget"], "#nf-transaction-create");
assert_eq!(response.headers()["hx-reswap"], "outerHTML");
assert!(
response.headers()["content-type"]
.to_str()
.is_ok_and(|v| v.starts_with("text/html"))
);
let body = to_bytes(response.into_body(), usize::MAX).await;
assert_eq!(body.as_deref().ok(), Some(&b"<form></form>"[..]));
}
#[test]
fn invalid_header_name_is_a_500() {
let bad = Form {
name: "bad\nname",
..TRANSACTION_CREATE
};
let response = form_invalid(&bad, String::new());
assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR);