feat(readarr): delete Readarr authors and expose the command on the CLI

This commit is contained in:
Dark-Alex-17 committed 2026-08-27 09:54:38 -06:00
1 parent fcfc29894e
commit ac8a11233f
7 files changed
+249 -6

No files matched your search

+115 -1
View File
@@ -24,6 +24,86 @@ mod tests {
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn test_delete_author_requires_arguments() {
let result = Cli::command().try_get_matches_from(["managarr", "readarr", "delete", "author"]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_delete_author_author_id_requires_a_number() {
let result = Cli::command().try_get_matches_from([
"managarr",
"readarr",
"delete",
"author",
"--author-id",
"not_a_number",
]);
assert_err!(&result);
assert_eq!(result.unwrap_err().kind(), ErrorKind::ValueValidation);
}
#[test]
fn test_delete_author_defaults() {
let expected_args = ReadarrDeleteCommand::Author {
author_id: 1,
delete_files_from_disk: false,
add_list_exclusion: false,
};
let result = Cli::try_parse_from([
"managarr",
"readarr",
"delete",
"author",
"--author-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_author_all_args_defined() {
let expected_args = ReadarrDeleteCommand::Author {
author_id: 1,
delete_files_from_disk: true,
add_list_exclusion: true,
};
let result = Cli::try_parse_from([
"managarr",
"readarr",
"delete",
"author",
"--author-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 =
@@ -127,13 +207,47 @@ mod tests {
ReadarrDeleteCommand, ReadarrDeleteCommandHandler,
};
use crate::models::Serdeable;
use crate::models::readarr_models::ReadarrSerdeable;
use crate::models::readarr_models::{DeleteParams, ReadarrSerdeable};
use crate::network::readarr_network::ReadarrEvent;
use crate::{
app::App,
network::{MockNetworkTrait, NetworkEvent},
};
#[tokio::test]
async fn test_handle_delete_author_command() {
let expected_delete_author_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::DeleteAuthor(expected_delete_author_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_author_command = ReadarrDeleteCommand::Author {
author_id: 1,
delete_files_from_disk: true,
add_list_exclusion: false,
};
let result =
ReadarrDeleteCommandHandler::with(&app_arc, delete_author_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();