feat(readarr): fetch releases for an author and expose them on the CLI

This commit is contained in:
Dark-Alex-17 committed 2026-08-28 14:15:28 -06:00
1 parent 666084a30f
commit 999a22a37f
6 files changed
+203 -4

No files matched your search

+17
View File
@@ -26,6 +26,15 @@ pub enum ReadarrListCommand {
)]
author_id: i64,
},
#[command(about = "Trigger a manual search for releases of the author with the given ID")]
AuthorReleases {
#[arg(
long,
help = "The Readarr ID of the author whose releases you wish to search for",
required = true
)]
author_id: i64,
},
#[command(about = "List all authors in your Readarr library")]
Authors,
#[command(about = "List all editions for the book with the given ID")]
@@ -151,6 +160,14 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrListCommand> for ReadarrListComman
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrListCommand::AuthorReleases { author_id } => {
println!("Searching for author releases. This may take a minute...");
let resp = self
.network
.handle_network_event(ReadarrEvent::GetAuthorReleases(author_id).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrListCommand::Authors => {
let resp = self
.network
@@ -252,6 +252,40 @@ mod tests {
);
}
#[test]
fn test_list_author_releases_requires_author_id() {
let result =
Cli::command().try_get_matches_from(["managarr", "readarr", "list", "author-releases"]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_list_author_releases_success() {
let expected_args = ReadarrListCommand::AuthorReleases { author_id: 3 };
let result = Cli::try_parse_from([
"managarr",
"readarr",
"list",
"author-releases",
"--author-id",
"3",
]);
assert_ok!(&result);
let Some(Command::Readarr(ReadarrCommand::List(author_releases_command))) =
result.unwrap().command
else {
panic!("Unexpected command type");
};
assert_eq!(author_releases_command, expected_args);
}
#[test]
fn test_list_releases_success() {
let expected_args = ReadarrListCommand::Releases { book_id: 7 };
@@ -757,6 +791,32 @@ mod tests {
assert_ok!(&result);
}
#[tokio::test]
async fn test_handle_list_author_releases_command() {
let expected_author_id = 3;
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
ReadarrEvent::GetAuthorReleases(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_author_releases_command = ReadarrListCommand::AuthorReleases { author_id: 3 };
let result =
ReadarrListCommandHandler::with(&app_arc, list_author_releases_command, &mut mock_network)
.handle()
.await;
assert_ok!(&result);
}
#[tokio::test]
async fn test_handle_list_root_folders_command() {
let mut mock_network = MockNetworkTrait::new();