use crate::cli::{CliArgType, CliCommandRegistration, CliHandlerRegistration};
use crate::prelude::ApiError;
use sdforge_macros::service_api;
#[service_api(
name = "test_cli_macro_cmd",
version = "v1",
description = "Test CLI macro command",
path = "/users/:id",
cli = true
)]
async fn test_cli_macro_cmd(id: u64) -> Result<String, ApiError> {
Ok(format!("id={}", id))
}
#[service_api(name = "test_cli_macro_noargs", version = "v2", cli = true)]
async fn test_cli_macro_noargs() -> Result<String, ApiError> {
Ok("ok".to_string())
}
#[test]
fn test_service_api_with_cli_generates_command_registration() {
let cmd = inventory::iter::<CliCommandRegistration>()
.find(|c| c.name == "test_cli_macro_cmd")
.expect("CliCommandRegistration for test_cli_macro_cmd must be registered");
assert_eq!(cmd.version, "v1");
assert_eq!(cmd.description, "Test CLI macro command");
assert_eq!(cmd.handler_fn_name, "test_cli_macro_cmd");
assert_eq!(
cmd.args.len(),
1,
"expected exactly one CLI arg for test_cli_macro_cmd"
);
assert_eq!(cmd.args[0].name, "id");
assert_eq!(cmd.args[0].arg_type, CliArgType::Path);
assert!(cmd.args[0].required);
}
#[test]
fn test_service_api_with_cli_generates_handler_registration() {
let handler = inventory::iter::<CliHandlerRegistration>()
.find(|h| h.name == "test_cli_macro_cmd")
.expect("CliHandlerRegistration for test_cli_macro_cmd must be registered");
let _ = handler.handler;
}
#[test]
fn test_service_api_with_cli_no_args_registers() {
let cmd = inventory::iter::<CliCommandRegistration>()
.find(|c| c.name == "test_cli_macro_noargs")
.expect("CliCommandRegistration for test_cli_macro_noargs must be registered");
assert_eq!(cmd.version, "v2");
assert!(cmd.args.is_empty(), "expected no args for noargs fixture");
let handler = inventory::iter::<CliHandlerRegistration>()
.find(|h| h.name == "test_cli_macro_noargs")
.expect("CliHandlerRegistration for test_cli_macro_noargs must be registered");
let _ = handler.handler;
}