feat(readarr): fetch Readarr author details and expose them on the CLI

This commit is contained in:
Dark-Alex-17 committed 2026-08-26 14:35:46 -06:00
1 parent 817fe4d135
commit 5042dbdb3a
6 files changed
+158 -2

No files matched your search

+16
View File
@@ -18,6 +18,15 @@ mod get_command_handler_tests;
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)] #[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum ReadarrGetCommand { pub enum ReadarrGetCommand {
#[command(about = "Get detailed information for the author with the given ID")]
AuthorDetails {
#[arg(
long,
help = "The Readarr ID of the author whose details you wish to fetch",
required = true
)]
author_id: i64,
},
#[command(about = "Fetch the host config for your Readarr instance")] #[command(about = "Fetch the host config for your Readarr instance")]
HostConfig, HostConfig,
#[command(about = "Fetch the security config for your Readarr instance")] #[command(about = "Fetch the security config for your Readarr instance")]
@@ -53,6 +62,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrGetCommand> for ReadarrGetCommandH
async fn handle(self) -> Result<String> { async fn handle(self) -> Result<String> {
let result = match self.command { let result = match self.command {
ReadarrGetCommand::AuthorDetails { author_id } => {
let resp = self
.network
.handle_network_event(ReadarrEvent::GetAuthorDetails(author_id).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrGetCommand::HostConfig => { ReadarrGetCommand::HostConfig => {
let resp = self let resp = self
.network .network
+56 -1
View File
@@ -18,9 +18,38 @@ mod tests {
} }
mod cli { mod cli {
use super::*; use clap::error::ErrorKind;
use pretty_assertions::assert_eq;
use rstest::rstest; use rstest::rstest;
use super::*;
#[test]
fn test_author_details_requires_author_id() {
let result =
Cli::command().try_get_matches_from(["managarr", "readarr", "get", "author-details"]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_author_details_requirements_satisfied() {
let result = Cli::command().try_get_matches_from([
"managarr",
"readarr",
"get",
"author-details",
"--author-id",
"1",
]);
assert_ok!(&result);
}
#[rstest] #[rstest]
fn test_get_commands_have_no_arg_requirements( fn test_get_commands_have_no_arg_requirements(
#[values("host-config", "security-config", "system-status")] subcommand: &str, #[values("host-config", "security-config", "system-status")] subcommand: &str,
@@ -48,6 +77,32 @@ mod tests {
network::{MockNetworkTrait, NetworkEvent, readarr_network::ReadarrEvent}, network::{MockNetworkTrait, NetworkEvent, readarr_network::ReadarrEvent},
}; };
#[tokio::test]
async fn test_handle_get_author_details_command() {
let expected_author_id = 1;
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
ReadarrEvent::GetAuthorDetails(expected_author_id).into(),
))
.times(1)
.returning(|_| {
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::test_default()));
let get_author_details_command = ReadarrGetCommand::AuthorDetails { author_id: 1 };
let result =
ReadarrGetCommandHandler::with(&app_arc, get_author_details_command, &mut mock_network)
.handle()
.await;
assert_ok!(&result);
}
#[tokio::test] #[tokio::test]
async fn test_handle_get_host_config_command() { async fn test_handle_get_host_config_command() {
let mut mock_network = MockNetworkTrait::new(); let mut mock_network = MockNetworkTrait::new();
@@ -12,6 +12,28 @@ use crate::network::{Network, RequestMethod};
mod readarr_authors_network_tests; mod readarr_authors_network_tests;
impl Network<'_, '_> { impl Network<'_, '_> {
pub(in crate::network::readarr_network) async fn get_author_details(
&mut self,
author_id: i64,
) -> Result<Author> {
info!("Fetching details for Readarr author with ID: {author_id}");
let event = ReadarrEvent::GetAuthorDetails(author_id);
let request_props = self
.request_props_from(
event,
RequestMethod::Get,
None::<()>,
Some(format!("/{author_id}")),
None,
)
.await;
self
.handle_request::<(), Author>(request_props, |_, _| ())
.await
}
pub(in crate::network::readarr_network) async fn list_authors(&mut self) -> Result<Vec<Author>> { pub(in crate::network::readarr_network) async fn list_authors(&mut self) -> Result<Vec<Author>> {
info!("Fetching Readarr authors"); info!("Fetching Readarr authors");
let event = ReadarrEvent::ListAuthors; let event = ReadarrEvent::ListAuthors;
@@ -10,6 +10,63 @@ mod tests {
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use serde_json::{Value, json}; use serde_json::{Value, json};
#[tokio::test]
async fn test_handle_get_author_details_event() {
let expected_author: Author = serde_json::from_str(AUTHOR_JSON).unwrap();
let stale_authors = vec![stale_author()];
let (mock, app, _server) = MockServarrApi::get()
.returns(serde_json::from_str(AUTHOR_JSON).unwrap())
.path("/1")
.build_for(ReadarrEvent::GetAuthorDetails(1))
.await;
{
let mut app = app.lock().await;
app.server_tabs.set_index(3);
app
.data
.readarr_data
.authors
.set_items(stale_authors.clone());
}
let mut network = test_network(&app);
let result = network
.handle_readarr_event(ReadarrEvent::GetAuthorDetails(1))
.await;
mock.assert_async().await;
let ReadarrSerdeable::Author(author) = result.unwrap() else {
panic!("Expected Author")
};
assert_eq!(author, expected_author);
assert_eq!(
app.lock().await.data.readarr_data.authors.items,
stale_authors
);
}
#[tokio::test]
async fn test_handle_get_author_details_event_failure() {
let (mock, app, _server) = MockServarrApi::get()
.returns(serde_json::from_str(AUTHOR_JSON).unwrap())
.status(500)
.path("/1")
.build_for(ReadarrEvent::GetAuthorDetails(1))
.await;
app.lock().await.server_tabs.set_index(3);
let mut network = test_network(&app);
let result = network
.handle_readarr_event(ReadarrEvent::GetAuthorDetails(1))
.await;
mock.assert_async().await;
assert_err!(result);
}
#[tokio::test] #[tokio::test]
async fn test_handle_list_authors_event() { async fn test_handle_list_authors_event() {
let authors_json = json!([ let authors_json = json!([
+6 -1
View File
@@ -25,6 +25,7 @@ pub enum ReadarrEvent {
AddTag(String), AddTag(String),
DeleteRootFolder(i64), DeleteRootFolder(i64),
DeleteTag(i64), DeleteTag(i64),
GetAuthorDetails(i64),
GetDiskSpace, GetDiskSpace,
GetHostConfig, GetHostConfig,
GetLogs(u64), GetLogs(u64),
@@ -45,7 +46,7 @@ pub enum ReadarrEvent {
impl NetworkResource for ReadarrEvent { impl NetworkResource for ReadarrEvent {
fn resource(&self) -> &'static str { fn resource(&self) -> &'static str {
match &self { match &self {
ReadarrEvent::ListAuthors => "/author", ReadarrEvent::GetAuthorDetails(_) | ReadarrEvent::ListAuthors => "/author",
ReadarrEvent::GetQueuedEvents | ReadarrEvent::StartTask(_) => "/command", ReadarrEvent::GetQueuedEvents | ReadarrEvent::StartTask(_) => "/command",
ReadarrEvent::GetHostConfig | ReadarrEvent::GetSecurityConfig => "/config/host", ReadarrEvent::GetHostConfig | ReadarrEvent::GetSecurityConfig => "/config/host",
ReadarrEvent::GetDiskSpace => "/diskspace", ReadarrEvent::GetDiskSpace => "/diskspace",
@@ -89,6 +90,10 @@ impl Network<'_, '_> {
.delete_readarr_tag(tag_id) .delete_readarr_tag(tag_id)
.await .await
.map(ReadarrSerdeable::from), .map(ReadarrSerdeable::from),
ReadarrEvent::GetAuthorDetails(author_id) => self
.get_author_details(author_id)
.await
.map(ReadarrSerdeable::from),
ReadarrEvent::GetDiskSpace => self ReadarrEvent::GetDiskSpace => self
.get_readarr_diskspace() .get_readarr_diskspace()
.await .await
@@ -13,6 +13,7 @@ mod tests {
use tokio::sync::Mutex; use tokio::sync::Mutex;
#[rstest] #[rstest]
#[case(ReadarrEvent::GetAuthorDetails(1), "/author")]
#[case(ReadarrEvent::ListAuthors, "/author")] #[case(ReadarrEvent::ListAuthors, "/author")]
#[case(ReadarrEvent::GetQueuedEvents, "/command")] #[case(ReadarrEvent::GetQueuedEvents, "/command")]
#[case(ReadarrEvent::StartTask(Default::default()), "/command")] #[case(ReadarrEvent::StartTask(Default::default()), "/command")]