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

This commit is contained in:
Dark-Alex-17 committed 2026-08-26 10:38:58 -06:00
1 parent 3475660eb2
commit e1be1df68a
6 files changed
+150 -1

No files matched your search

+12
View File
@@ -17,6 +17,11 @@ mod delete_command_handler_tests;
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum ReadarrDeleteCommand {
#[command(about = "Delete the root folder with the given ID")]
RootFolder {
#[arg(long, help = "The ID of the root folder to delete", required = true)]
root_folder_id: i64,
},
#[command(about = "Delete the tag with the specified ID")]
Tag {
#[arg(long, help = "The ID of the tag to delete", required = true)]
@@ -53,6 +58,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrDeleteCommand>
async fn handle(self) -> Result<String> {
let result = match self.command {
ReadarrDeleteCommand::RootFolder { root_folder_id } => {
let resp = self
.network
.handle_network_event(ReadarrEvent::DeleteRootFolder(root_folder_id).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrDeleteCommand::Tag { tag_id } => {
let resp = self
.network
@@ -24,6 +24,55 @@ mod tests {
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn test_delete_root_folder_requires_arguments() {
let result =
Cli::command().try_get_matches_from(["managarr", "readarr", "delete", "root-folder"]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_delete_root_folder_root_folder_id_requires_a_number() {
let result = Cli::command().try_get_matches_from([
"managarr",
"readarr",
"delete",
"root-folder",
"--root-folder-id",
"not_a_number",
]);
assert_err!(&result);
assert_eq!(result.unwrap_err().kind(), ErrorKind::ValueValidation);
}
#[test]
fn test_delete_root_folder_success() {
let expected_args = ReadarrDeleteCommand::RootFolder { root_folder_id: 1 };
let result = Cli::try_parse_from([
"managarr",
"readarr",
"delete",
"root-folder",
"--root-folder-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_tag_requires_arguments() {
let result = Cli::command().try_get_matches_from(["managarr", "readarr", "delete", "tag"]);
@@ -85,6 +134,29 @@ mod tests {
network::{MockNetworkTrait, NetworkEvent},
};
#[tokio::test]
async fn test_handle_delete_root_folder_command() {
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(ReadarrEvent::DeleteRootFolder(1).into()))
.times(1)
.returning(|_| {
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::test_default()));
let delete_root_folder_command = ReadarrDeleteCommand::RootFolder { root_folder_id: 1 };
let result =
ReadarrDeleteCommandHandler::with(&app_arc, delete_root_folder_command, &mut mock_network)
.handle()
.await;
assert_ok!(&result);
}
#[tokio::test]
async fn test_handle_delete_tag_command() {
let mut mock_network = MockNetworkTrait::new();