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

This commit is contained in:
Dark-Alex-17 committed 2026-08-27 14:38:51 -06:00
1 parent 8752a85db5
commit 41830cc072
8 files changed
+264 -2

No files matched your search

+16
View File
@@ -28,6 +28,15 @@ pub enum ReadarrListCommand {
},
#[command(about = "List all authors in your Readarr library")]
Authors,
#[command(about = "List all books for the author with the given ID")]
Books {
#[arg(
long,
help = "The Readarr ID of the author whose books you want to list",
required = true
)]
author_id: i64,
},
#[command(about = "List disk space details for all provisioned root folders in Readarr")]
DiskSpace,
#[command(about = "Fetch Readarr logs")]
@@ -97,6 +106,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrListCommand> for ReadarrListComman
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrListCommand::Books { author_id } => {
let resp = self
.network
.handle_network_event(ReadarrEvent::GetBooks(author_id).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrListCommand::DiskSpace => {
let resp = self
.network
@@ -85,6 +85,32 @@ mod tests {
assert_eq!(author_command, expected_args);
}
#[test]
fn test_list_books_requires_author_id() {
let result = Cli::command().try_get_matches_from(["managarr", "readarr", "list", "books"]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_list_books_success() {
let expected_args = ReadarrListCommand::Books { author_id: 1 };
let result =
Cli::try_parse_from(["managarr", "readarr", "list", "books", "--author-id", "1"]);
assert_ok!(&result);
let Some(Command::Readarr(ReadarrCommand::List(books_command))) = result.unwrap().command
else {
panic!("Unexpected command type");
};
assert_eq!(books_command, expected_args);
}
#[test]
fn test_list_logs_default_values() {
let expected_args = ReadarrListCommand::Logs {
@@ -170,6 +196,31 @@ mod tests {
assert_ok!(&result);
}
#[tokio::test]
async fn test_handle_list_books_command() {
let expected_author_id = 1;
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
ReadarrEvent::GetBooks(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 list_books_command = ReadarrListCommand::Books { author_id: 1 };
let result = ReadarrListCommandHandler::with(&app_arc, list_books_command, &mut mock_network)
.handle()
.await;
assert_ok!(&result);
}
#[tokio::test]
async fn test_handle_list_disk_space_command() {
let mut mock_network = MockNetworkTrait::new();