Lines
97.44 %
Functions
100 %
Branches
use super::tests::parse;
use super::*;
fn from_template(args: &[&str]) -> anyhow::Result<(Uuid, FormValues)> {
match parse(args)? {
TransactionCmd::CreateFromTemplate {
template,
overrides,
} => Ok((template, overrides)),
other => anyhow::bail!("expected create from template, got {other:?}"),
}
#[test]
fn template_names_the_draft_to_start_from() -> anyhow::Result<()> {
let id = Uuid::new_v4();
let (template, overrides) = from_template(&["create", "--template", &id.to_string()])?;
assert_eq!(template, id);
assert_eq!(overrides, FormValues::default());
Ok(())
fn the_other_flags_override_the_draft() -> anyhow::Result<()> {
let (_, overrides) = from_template(&[
"create",
"--template",
&id.to_string(),
"--note",
"Dinner",
"--date",
"2026-07-01",
"--row",
"from=Cash,to=Food,from-commodity=USD,value=1",
])?;
assert_eq!(overrides.text("note"), Some("Dinner"));
assert_eq!(overrides.text("date"), Some("2026-07-01"));
assert_eq!(overrides.rows("splits").map(<[_]>::len), Some(1));
fn without_a_template_the_date_still_defaults_to_now() -> anyhow::Result<()> {
assert!(matches!(
parse(&["create", "--note", "x"])?,
TransactionCmd::Create(values) if values.text("date").is_some()
));
fn a_template_that_is_not_an_id_is_a_usage_error() {
assert!(parse(&["create", "--template", "lunch"]).is_err());