feat(readarr): trigger an automatic book search and expose the command on the CLI

This commit is contained in:
Dark-Alex-17 committed 2026-08-27 15:52:44 -06:00
1 parent b48ce5db2e
commit f2787560d6
6 files changed
+159 -1

No files matched your search

@@ -27,6 +27,15 @@ pub enum ReadarrTriggerAutomaticSearchCommand {
)]
author_id: i64,
},
#[command(about = "Trigger an automatic search for the book with the specified ID")]
Book {
#[arg(
long,
help = "The ID of the book you want to trigger an automatic search for",
required = true
)]
book_id: i64,
},
}
impl From<ReadarrTriggerAutomaticSearchCommand> for Command {
@@ -65,6 +74,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrTriggerAutomaticSearchCommand>
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrTriggerAutomaticSearchCommand::Book { book_id } => {
let resp = self
.network
.handle_network_event(ReadarrEvent::TriggerAutomaticBookSearch(book_id).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
};
Ok(result)
@@ -68,6 +68,45 @@ mod tests {
};
assert_eq!(trigger_automatic_search_command, expected_args);
}
#[test]
fn test_trigger_automatic_book_search_requires_book_id() {
let result = Cli::command().try_get_matches_from([
"managarr",
"readarr",
"trigger-automatic-search",
"book",
]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_trigger_automatic_book_search_with_book_id() {
let expected_args = ReadarrTriggerAutomaticSearchCommand::Book { book_id: 1 };
let result = Cli::try_parse_from([
"managarr",
"readarr",
"trigger-automatic-search",
"book",
"--book-id",
"1",
]);
assert_ok!(&result);
let Some(Command::Readarr(ReadarrCommand::TriggerAutomaticSearch(
trigger_automatic_search_command,
))) = result.unwrap().command
else {
panic!("Unexpected command type");
};
assert_eq!(trigger_automatic_search_command, expected_args);
}
}
mod handler {
@@ -114,5 +153,34 @@ mod tests {
assert_ok!(&result);
}
#[tokio::test]
async fn test_handle_trigger_automatic_book_search_command() {
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
ReadarrEvent::TriggerAutomaticBookSearch(1).into(),
))
.times(1)
.returning(|_| {
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::test_default()));
let trigger_automatic_search_command =
ReadarrTriggerAutomaticSearchCommand::Book { book_id: 1 };
let result = ReadarrTriggerAutomaticSearchCommandHandler::with(
&app_arc,
trigger_automatic_search_command,
&mut mock_network,
)
.handle()
.await;
assert_ok!(&result);
}
}
}