use super::*;
use crate::cli::clap::render_help;
use crate::cli::common::OutputFormat;
fn leaf_command(name: &str) -> ClapCommand {
command()
.find_subcommand_mut(name)
.expect("reward operation")
.clone()
}
fn options(args: &[&str]) -> RewardCommand {
let matches = crate::cli::parse_test_args(command(), args).expect("valid options");
parsed_options(&matches)
}
#[test]
fn help_discloses_authority_bounds_and_page_overlap() {
let family = render_help(command());
let list = render_help(leaf_command("list"));
let history = render_help(leaf_command("history"));
assert!(family.contains("Usage: reward [COMMAND]"));
assert!(family.contains("history"));
assert!(family.contains("info"));
assert!(family.contains("list"));
assert!(list.contains("Adjacent upstream offset pages can overlap"));
assert!(list.contains("--max-reward-index"));
assert!(history.contains("capped at 1000 requested observations"));
}
#[test]
fn options_preserve_explicit_bounds_and_raw_format() {
let RewardCommand::List(options) = options(&[
"list",
"--limit",
"25",
"--offset",
"50",
"--max-reward-index",
"6470",
"--json",
]) else {
panic!("expected reward list")
};
let (format, list) = list_request(options, 1_780_531_200);
assert_eq!(list.query.limit, 25);
assert_eq!(list.query.offset, 50);
assert_eq!(list.query.max_reward_index, Some(6_470));
assert_eq!(format, OutputFormat::Json);
let RewardCommand::History(options) = self::options(&[
"history",
"--start",
"1752537600",
"--end",
"1784073600",
"--step",
"86400",
]) else {
panic!("expected reward history")
};
let (_, history) = history_request(options, 1_780_531_200);
assert_eq!(history.query.start_unix_secs, 1_752_537_600);
assert_eq!(history.query.end_unix_secs, 1_784_073_600);
assert_eq!(history.query.step_secs, 86_400);
}
#[test]
fn info_preserves_exact_id_source_and_collection_clock() {
let RewardCommand::Info(options) = options(&[
"info",
"7562",
"--source-endpoint",
"https://dashboard.example/api/v3",
"--json",
]) else {
panic!("expected reward info")
};
let (format, request) = info_request(options, 1_780_531_200);
assert_eq!(request.reward_id, 7_562);
assert_eq!(
request.dashboard.source_endpoint,
"https://dashboard.example/api/v3"
);
assert_eq!(request.dashboard.now_unix_secs, 1_780_531_200);
assert_eq!(format, OutputFormat::Json);
}