feat(readarr): search for new Readarr authors and expose the command on the CLI
This commit is contained in:
7 files changed
+244
-4
No files matched your search
@@ -44,6 +44,15 @@ pub enum ReadarrCommand {
|
||||
about = "Commands to list attributes from your Readarr instance"
|
||||
)]
|
||||
List(ReadarrListCommand),
|
||||
#[command(about = "Search for a new author to add to Readarr")]
|
||||
SearchNewAuthor {
|
||||
#[arg(
|
||||
long,
|
||||
help = "The name of the author you want to search for",
|
||||
required = true
|
||||
)]
|
||||
query: String,
|
||||
},
|
||||
#[command(about = "Start the specified Readarr task")]
|
||||
StartTask {
|
||||
#[arg(
|
||||
@@ -103,6 +112,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrCommand> for ReadarrCliHandler<'a,
|
||||
.handle()
|
||||
.await?
|
||||
}
|
||||
ReadarrCommand::SearchNewAuthor { query } => {
|
||||
let resp = self
|
||||
.network
|
||||
.handle_network_event(ReadarrEvent::SearchNewAuthor(query).into())
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
ReadarrCommand::StartTask { task_name } => {
|
||||
let resp = self
|
||||
.network
|
||||
|
||||
@@ -14,6 +14,31 @@ mod tests {
|
||||
assert_err!(&result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_search_new_author_requires_query() {
|
||||
let result =
|
||||
Cli::command().try_get_matches_from(["managarr", "readarr", "search-new-author"]);
|
||||
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_search_new_author_requirements_satisfied() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"readarr",
|
||||
"search-new-author",
|
||||
"--query",
|
||||
"test query",
|
||||
]);
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_start_task_requires_task_name() {
|
||||
let result = Cli::command().try_get_matches_from(["managarr", "readarr", "start-task"]);
|
||||
@@ -71,6 +96,33 @@ mod tests {
|
||||
network::{MockNetworkTrait, NetworkEvent, readarr_network::ReadarrEvent},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_search_new_author_command() {
|
||||
let expected_query = "test author".to_owned();
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(
|
||||
ReadarrEvent::SearchNewAuthor(expected_query.clone()).into(),
|
||||
))
|
||||
.times(1)
|
||||
.returning(|_| {
|
||||
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
|
||||
json!({"testResponse": "response"}),
|
||||
)))
|
||||
});
|
||||
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
||||
let search_new_author_command = ReadarrCommand::SearchNewAuthor {
|
||||
query: expected_query,
|
||||
};
|
||||
|
||||
let result = ReadarrCliHandler::with(&app_arc, search_new_author_command, &mut mock_network)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_start_task_command() {
|
||||
let expected_task_name = ReadarrTaskName::CheckHealth;
|
||||
|
||||
Reference in new issue
Block a user