feat(readarr): delete a book and expose the command on the CLI

The delete flags travel as query parameters rather than a request body,
and Readarr spells the exclusion key addImportListExclusion, not the
addImportExclusion that Radarr uses.
This commit is contained in:
Dark-Alex-17 committed 2026-08-27 16:19:49 -06:00
1 parent e30d4dbd0c
commit fbfd64eb2a
6 files changed
+228 -3

No files matched your search

@@ -104,6 +104,79 @@ mod tests {
assert_eq!(delete_command, expected_args);
}
#[test]
fn test_delete_book_requires_arguments() {
let result = Cli::command().try_get_matches_from(["managarr", "readarr", "delete", "book"]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_delete_book_book_id_requires_a_number() {
let result = Cli::command().try_get_matches_from([
"managarr",
"readarr",
"delete",
"book",
"--book-id",
"not_a_number",
]);
assert_err!(&result);
assert_eq!(result.unwrap_err().kind(), ErrorKind::ValueValidation);
}
#[test]
fn test_delete_book_defaults() {
let expected_args = ReadarrDeleteCommand::Book {
book_id: 1,
delete_files_from_disk: false,
add_list_exclusion: false,
};
let result = Cli::try_parse_from(["managarr", "readarr", "delete", "book", "--book-id", "1"]);
assert_ok!(&result);
let Some(Command::Readarr(ReadarrCommand::Delete(delete_command))) = result.unwrap().command
else {
panic!("Unexpected command type");
};
assert_eq!(delete_command, expected_args);
}
#[test]
fn test_delete_book_all_args_defined() {
let expected_args = ReadarrDeleteCommand::Book {
book_id: 1,
delete_files_from_disk: true,
add_list_exclusion: true,
};
let result = Cli::try_parse_from([
"managarr",
"readarr",
"delete",
"book",
"--book-id",
"1",
"--delete-files-from-disk",
"--add-list-exclusion",
]);
assert_ok!(&result);
let Some(Command::Readarr(ReadarrCommand::Delete(delete_command))) = result.unwrap().command
else {
panic!("Unexpected command type");
};
assert_eq!(delete_command, expected_args);
}
#[test]
fn test_delete_root_folder_requires_arguments() {
let result =
@@ -248,6 +321,40 @@ mod tests {
assert_ok!(&result);
}
#[tokio::test]
async fn test_handle_delete_book_command() {
let expected_delete_book_params = DeleteParams {
id: 1,
delete_files: true,
add_import_list_exclusion: false,
};
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
ReadarrEvent::DeleteBook(expected_delete_book_params).into(),
))
.times(1)
.returning(|_| {
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::test_default()));
let delete_book_command = ReadarrDeleteCommand::Book {
book_id: 1,
delete_files_from_disk: true,
add_list_exclusion: false,
};
let result =
ReadarrDeleteCommandHandler::with(&app_arc, delete_book_command, &mut mock_network)
.handle()
.await;
assert_ok!(&result);
}
#[tokio::test]
async fn test_handle_delete_root_folder_command() {
let mut mock_network = MockNetworkTrait::new();