2024-10-26 21:35:28 +02:00
|
|
|
use cuddle_actions_sdk::AddActionOptions;
|
2024-08-26 09:05:58 +02:00
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_can_schema_no_actions() -> anyhow::Result<()> {
|
2024-10-26 21:35:28 +02:00
|
|
|
let output = cuddle_actions_sdk::CuddleActions::default().get_pretty_actions()?;
|
2024-08-26 09:05:58 +02:00
|
|
|
|
|
|
|
assert_eq!("[]", &output);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_can_schema_simple_action() -> anyhow::Result<()> {
|
2024-10-26 21:35:28 +02:00
|
|
|
let output = cuddle_actions_sdk::CuddleActions::default()
|
2024-08-26 22:02:50 +02:00
|
|
|
.add_action("something", || Ok(()), &AddActionOptions::default())
|
|
|
|
.get_pretty_actions()?;
|
2024-08-26 09:05:58 +02:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
r#"[
|
|
|
|
{
|
|
|
|
"name": "something",
|
|
|
|
"description": null
|
|
|
|
}
|
|
|
|
]"#,
|
|
|
|
&output
|
|
|
|
);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2024-08-26 22:02:50 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_can_call_simple_action() -> anyhow::Result<()> {
|
2024-10-26 21:35:28 +02:00
|
|
|
cuddle_actions_sdk::CuddleActions::default()
|
2024-08-26 22:02:50 +02:00
|
|
|
.add_action("something", || Ok(()), &AddActionOptions::default())
|
|
|
|
.execute_from(vec!["cuddle-actions", "do", "something"])?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_can_fail_on_unknown_command() -> anyhow::Result<()> {
|
2024-10-26 21:35:28 +02:00
|
|
|
let res = cuddle_actions_sdk::CuddleActions::default().execute_from(vec![
|
2024-08-26 22:02:50 +02:00
|
|
|
"cuddle-actions",
|
|
|
|
"do",
|
|
|
|
"something",
|
|
|
|
]);
|
|
|
|
|
|
|
|
assert!(res.is_err());
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_can_cmd_can_fail() -> anyhow::Result<()> {
|
2024-10-26 21:35:28 +02:00
|
|
|
let res = cuddle_actions_sdk::CuddleActions::default()
|
2024-08-26 22:02:50 +02:00
|
|
|
.add_action(
|
|
|
|
"something",
|
|
|
|
|| anyhow::bail!("failed to run cmd"),
|
|
|
|
&AddActionOptions::default(),
|
|
|
|
)
|
|
|
|
.execute_from(vec!["cuddle-actions", "do", "something"]);
|
|
|
|
|
|
|
|
assert!(res.is_err());
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|