Lines
100 %
Functions
Branches
//! The create submit over the shared forms (plan 0016 W5): plain
//! address-named fields in, `rpc::forms::submit` behind.
use axum::http::StatusCode;
use crate::common::new_page::{
Ids, created_id, input_value, post_form, seeded_ids, seeded_user, snapshot, textarea,
};
const DATE: &str = "2026-10-27T09:15:42.123456Z";
fn entry<'a>(ids: &'a Ids, from: &'a str, note: &'a str) -> Vec<(&'a str, &'a str)> {
vec![
("date", DATE),
("note", note),
("tags", ""),
("tags.0.name", "trip"),
("tags.0.value", "japan"),
("tags.0.description", "spring"),
("splits", ""),
("splits.0.key", "n1"),
("splits.0.from", from),
("splits.0.to", &ids.food),
("splits.0.from-commodity", &ids.usd),
("splits.0.value", "50"),
("splits.0.hidden", ""),
("split-tags", ""),
("split-tags.0.row", "n1"),
("split-tags.0.name", "memo"),
("split-tags.0.value", "lunch"),
]
}
fn has(facts: &[String], prefix: &str) -> bool {
facts.iter().any(|fact| fact.starts_with(prefix))
#[supp_macro::shared_runtime_test]
async fn a_valid_create_stores_tags_and_split_tags() {
let user = seeded_user().await;
let ids = seeded_ids(&user).await;
let reply = post_form(&user, &entry(&ids, &ids.checking, "lunch")).await;
let id = created_id(&reply);
let facts = snapshot(&user, id).await;
assert_eq!(reply.status, StatusCode::OK, "{}", reply.body);
assert!(
reply.body.contains("New transaction created with ID"),
"{}",
reply.body
);
has(&facts, "date 2026-10-27 09:15:42.123456+00"),
"{facts:?}"
assert!(has(&facts, "tag trip japan spring"), "{facts:?}");
assert!(has(&facts, "tag note lunch"), "{facts:?}");
let split_tags = facts.iter().filter(|f| f.starts_with("split-tag ")).count();
assert_eq!(split_tags, 2, "{facts:?}");
assert!(facts.iter().all(|f| !f.starts_with("price ")), "{facts:?}");
async fn an_invalid_create_rerenders_and_a_corrected_resubmit_succeeds() {
let invalid = post_form(&user, &entry(&ids, "Nowhere", "multi\r\nline")).await;
let corrected = post_form(&user, &entry(&ids, &ids.checking, "multi\r\nline")).await;
let id = created_id(&corrected);
assert_eq!(
invalid.status,
StatusCode::UNPROCESSABLE_ENTITY,
invalid.body
invalid.headers.get("hx-retarget").map(|v| v.as_bytes()),
Some(&b"#nf-transaction-create"[..])
invalid.headers.get("hx-reswap").map(|v| v.as_bytes()),
Some(&b"outerHTML"[..])
let html = &invalid.body;
assert!(html.starts_with("<form"), "{html}");
assert!(html.contains("field invalid"), "{html}");
assert_eq!(input_value(html, "splits.0.from"), Some("Nowhere"));
assert_eq!(input_value(html, "splits.0.key"), Some("n1"));
assert_eq!(input_value(html, "splits.0.hidden"), Some(""));
assert_eq!(input_value(html, "tags.0.name"), Some("trip"));
assert_eq!(textarea(html, "tags.0.description"), Some("spring"));
assert_eq!(input_value(html, "split-tags.0.row"), Some("n1"));
assert_eq!(input_value(html, "split-tags.0.value"), Some("lunch"));
assert_eq!(input_value(html, "date"), Some(DATE));
assert_eq!(textarea(html, "note"), Some("multi\nline"));
assert_eq!(corrected.status, StatusCode::OK, "{}", corrected.body);
assert!(has(&facts, "tag note multi\nline"), "{facts:?}");
assert!(has(&facts, "tag trip japan"), "{facts:?}");
/// A new row posts its hidden cell empty: that is no hidden data, the same
/// create as one without the cell.
async fn an_empty_hidden_cell_means_no_hidden_data() {
let with = post_form(&user, &entry(&ids, &ids.checking, "n")).await;
let without: Vec<_> = entry(&ids, &ids.checking, "n")
.into_iter()
.filter(|(name, _)| *name != "splits.0.hidden")
.collect();
let without = post_form(&user, &without).await;
let (with, without) = (
snapshot(&user, created_id(&with)).await,
snapshot(&user, created_id(&without)).await,
let stable = |facts: Vec<String>| -> Vec<String> {
facts
.filter(|fact| !fact.starts_with("date "))
.collect()
assert_eq!(stable(with), stable(without));
async fn a_whitespace_only_note_is_dropped() {
let reply = post_form(&user, &entry(&ids, &ids.checking, " \t ")).await;
let facts = snapshot(&user, created_id(&reply)).await;
assert!(!has(&facts, "tag note"), "{facts:?}");
async fn an_absent_date_is_not_filled_in() {
let undated: Vec<_> = entry(&ids, &ids.checking, "n")
.filter(|(name, _)| *name != "date")
let reply = post_form(&user, &undated).await;
reply.status,
assert!(reply.body.contains("is required"), "{}", reply.body);
async fn an_undecodable_body_is_refused_whole() {
let mut gap = entry(&ids, &ids.checking, "n");
gap.push(("splits.2.value", "1"));
let reply = post_form(&user, &gap).await;
assert!(reply.headers.get("hx-retarget").is_none());
assert!(!reply.body.contains("<form"), "{}", reply.body);
async fn an_old_clients_name_is_a_field_error_at_its_cell() {
let reply = post_form(&user, &entry(&ids, "Assets:Checking", "lunch")).await;
assert!(reply.body.contains("unknown account"), "{}", reply.body);
input_value(&reply.body, "splits.0.from"),
Some("Assets:Checking")