feat(readarr): toggle Readarr author monitoring and expose the command on the CLI

This commit is contained in:
Dark-Alex-17 committed 2026-08-27 10:09:04 -06:00
1 parent ac8a11233f
commit f896b65fd9
6 files changed
+221 -2

No files matched your search

+18
View File
@@ -70,6 +70,17 @@ pub enum ReadarrCommand {
)]
task_name: ReadarrTaskName,
},
#[command(
about = "Toggle monitoring for the specified author corresponding to the given author ID"
)]
ToggleAuthorMonitoring {
#[arg(
long,
help = "The Readarr ID of the author to toggle monitoring on",
required = true
)]
author_id: i64,
},
}
impl From<ReadarrCommand> for Command {
@@ -138,6 +149,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrCommand> for ReadarrCliHandler<'a,
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrCommand::ToggleAuthorMonitoring { author_id } => {
let resp = self
.network
.handle_network_event(ReadarrEvent::ToggleAuthorMonitoring(author_id).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
};
Ok(result)
+54
View File
@@ -76,6 +76,31 @@ mod tests {
assert_ok!(&result);
}
#[test]
fn test_toggle_author_monitoring_requires_author_id() {
let result =
Cli::command().try_get_matches_from(["managarr", "readarr", "toggle-author-monitoring"]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_toggle_author_monitoring_requirements_satisfied() {
let result = Cli::command().try_get_matches_from([
"managarr",
"readarr",
"toggle-author-monitoring",
"--author-id",
"1",
]);
assert_ok!(&result);
}
}
mod handler {
@@ -149,5 +174,34 @@ mod tests {
assert_ok!(&result);
}
#[tokio::test]
async fn test_toggle_author_monitoring_command() {
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
ReadarrEvent::ToggleAuthorMonitoring(1).into(),
))
.times(1)
.returning(|_| {
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::test_default()));
let toggle_author_monitoring_command =
ReadarrCommand::ToggleAuthorMonitoring { author_id: 1 };
let result = ReadarrCliHandler::with(
&app_arc,
toggle_author_monitoring_command,
&mut mock_network,
)
.handle()
.await;
assert_ok!(&result);
}
}
}