Lines
100 %
Functions
Branches
//! Integration tests for the `nomisync` automation CLI. These exercise
//! the clap parser and help/error pathways without needing a running
//! database. Actual command dispatch against the server is covered by
//! `cli-core`'s tests and the per-command tests inside the server crate.
use assert_cmd::Command;
use predicates::prelude::*;
fn cli() -> Command {
Command::cargo_bin("cli").expect("cli binary should build")
}
#[test]
fn top_level_help_mentions_every_subcommand() {
cli()
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("version"))
.stdout(predicate::str::contains("account"))
.stdout(predicate::str::contains("transaction"))
.stdout(predicate::str::contains("commodity"))
.stdout(predicate::str::contains("config"))
.stdout(predicate::str::contains("sql"))
.stdout(predicate::str::contains("reports"))
.stdout(predicate::str::contains("ssh-key"));
fn ssh_key_help_lists_subcommands() {
.args(["ssh-key", "--help"])
.stdout(predicate::str::contains("add"))
.stdout(predicate::str::contains("list"))
.stdout(predicate::str::contains("remove"));
fn ssh_key_add_requires_key_source() {
let uuid = uuid::Uuid::new_v4();
.args(["--userid", &uuid.to_string(), "ssh-key", "add"])
.failure()
.stderr(predicate::str::contains("required"));
fn ssh_key_add_rejects_both_key_sources() {
.args([
"--userid",
&uuid.to_string(),
"ssh-key",
"add",
"--key-file",
"/tmp/foo",
"--public-key",
"ssh-ed25519 AAAA",
])
.failure();
fn ssh_key_remove_requires_fingerprint() {
.args(["--userid", &uuid.to_string(), "ssh-key", "remove"])
.stderr(predicate::str::contains("fingerprint"));
fn reports_help_lists_subcommands() {
.args(["reports", "--help"])
.stdout(predicate::str::contains("balance"))
.stdout(predicate::str::contains("activity"))
.stdout(predicate::str::contains("breakdown"));
fn account_help_lists_subcommands() {
.args(["account", "--help"])
.stdout(predicate::str::contains("create"));
fn missing_userid_exits_non_zero() {
.arg("version")
.stderr(predicate::str::contains("userid"));
fn unknown_subcommand_exits_non_zero() {
.args(["--userid", &uuid.to_string(), "bogus"])
fn reports_balance_help_documents_chart_flag() {
.args(["reports", "balance", "--help"])
.stdout(predicate::str::contains("chart"))
.stdout(predicate::str::contains("from"))
.stdout(predicate::str::contains("to"));
fn transaction_create_rejects_malformed_value() {
let dummy = uuid::Uuid::new_v4();
"transaction",
"create",
"--from",
&dummy.to_string(),
"--to",
"--from-currency",
"--to-currency",
"--value",
"not-a-number",