feat(cli): Support for deleting a Sonarr indexer

This commit is contained in:
2024-11-21 16:22:30 -07:00
parent 72cb334b6a
commit f4c647342b
2 changed files with 70 additions and 0 deletions
+12
View File
@@ -32,6 +32,11 @@ pub enum SonarrDeleteCommand {
#[arg(long, help = "The ID of the download to delete", required = true)]
download_id: i64,
},
#[command(about = "Delete the indexer with the given ID")]
Indexer {
#[arg(long, help = "The ID of the indexer to delete", required = true)]
indexer_id: i64,
},
}
impl From<SonarrDeleteCommand> for Command {
@@ -75,6 +80,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrDeleteCommand> for SonarrDeleteComm
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrDeleteCommand::Indexer { indexer_id } => {
let resp = self
.network
.handle_network_event((SonarrEvent::DeleteIndexer(Some(indexer_id))).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
};
Ok(resp)
@@ -91,6 +91,38 @@ mod tests {
assert_eq!(delete_command, expected_args);
}
}
#[test]
fn test_delete_indexer_requires_arguments() {
let result = Cli::command().try_get_matches_from(["managarr", "sonarr", "delete", "indexer"]);
assert!(result.is_err());
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_delete_indexer_success() {
let expected_args = SonarrDeleteCommand::Indexer { indexer_id: 1 };
let result = Cli::try_parse_from([
"managarr",
"sonarr",
"delete",
"indexer",
"--indexer-id",
"1",
]);
assert!(result.is_ok());
if let Some(Command::Sonarr(SonarrCommand::Delete(delete_command))) = result.unwrap().command
{
assert_eq!(delete_command, expected_args);
}
}
}
mod handler {
@@ -166,5 +198,31 @@ mod tests {
assert!(result.is_ok());
}
#[tokio::test]
async fn test_handle_delete_indexer_command() {
let expected_indexer_id = 1;
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
SonarrEvent::DeleteIndexer(Some(expected_indexer_id)).into(),
))
.times(1)
.returning(|_| {
Ok(Serdeable::Sonarr(SonarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::default()));
let delete_indexer_command = SonarrDeleteCommand::Indexer { indexer_id: 1 };
let result =
SonarrDeleteCommandHandler::with(&app_arc, delete_indexer_command, &mut mock_network)
.handle()
.await;
assert!(result.is_ok());
}
}
}