feat(readarr): fetch releases for a book and expose them on the CLI

This commit is contained in:
Dark-Alex-17 committed 2026-08-28 14:07:15 -06:00
1 parent 1edceba056
commit 666084a30f
7 files changed
+333 -4

No files matched your search

+17
View File
@@ -98,6 +98,15 @@ pub enum ReadarrListCommand {
QualityProfiles,
#[command(about = "List all queued events")]
QueuedEvents,
#[command(about = "Trigger a manual search for releases of the book with the given ID")]
Releases {
#[arg(
long,
help = "The Readarr ID of the book whose releases you wish to search for",
required = true
)]
book_id: i64,
},
#[command(about = "List all root folders in Readarr")]
RootFolders,
#[command(about = "List all Readarr tags")]
@@ -236,6 +245,14 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrListCommand> for ReadarrListComman
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrListCommand::Releases { book_id } => {
println!("Searching for book releases. This may take a minute...");
let resp = self
.network
.handle_network_event(ReadarrEvent::GetBookReleases(book_id).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrListCommand::RootFolders => {
let resp = self
.network
@@ -241,6 +241,32 @@ mod tests {
assert_eq!(books_command, expected_args);
}
#[test]
fn test_list_releases_requires_book_id() {
let result = Cli::command().try_get_matches_from(["managarr", "readarr", "list", "releases"]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_list_releases_success() {
let expected_args = ReadarrListCommand::Releases { book_id: 7 };
let result =
Cli::try_parse_from(["managarr", "readarr", "list", "releases", "--book-id", "7"]);
assert_ok!(&result);
let Some(Command::Readarr(ReadarrCommand::List(releases_command))) = result.unwrap().command
else {
panic!("Unexpected command type");
};
assert_eq!(releases_command, expected_args);
}
#[test]
fn test_list_logs_default_values() {
let expected_args = ReadarrListCommand::Logs {
@@ -705,6 +731,32 @@ mod tests {
assert_ok!(&result);
}
#[tokio::test]
async fn test_handle_list_releases_command() {
let expected_book_id = 7;
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
ReadarrEvent::GetBookReleases(expected_book_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_releases_command = ReadarrListCommand::Releases { book_id: 7 };
let result =
ReadarrListCommandHandler::with(&app_arc, list_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();