feat(cli): Support for refreshing all Sonarr series data
This commit is contained in:
@@ -18,7 +18,7 @@ mod refresh_command_handler_tests;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
|
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
|
||||||
pub enum RadarrRefreshCommand {
|
pub enum RadarrRefreshCommand {
|
||||||
#[command(about = "Refresh all movie data for all movies in your library")]
|
#[command(about = "Refresh all movie data for all movies in your Radarr library")]
|
||||||
AllMovies,
|
AllMovies,
|
||||||
#[command(about = "Refresh movie data and scan disk for the movie with the given ID")]
|
#[command(about = "Refresh movie data and scan disk for the movie with the given ID")]
|
||||||
Movie {
|
Movie {
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ mod tests {
|
|||||||
#[case(RadarrRefreshCommand::Collections, RadarrEvent::UpdateCollections)]
|
#[case(RadarrRefreshCommand::Collections, RadarrEvent::UpdateCollections)]
|
||||||
#[case(RadarrRefreshCommand::Downloads, RadarrEvent::UpdateDownloads)]
|
#[case(RadarrRefreshCommand::Downloads, RadarrEvent::UpdateDownloads)]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_handle_list_blocklist_command(
|
async fn test_handle_refresh_command(
|
||||||
#[case] refresh_command: RadarrRefreshCommand,
|
#[case] refresh_command: RadarrRefreshCommand,
|
||||||
#[case] expected_radarr_event: RadarrEvent,
|
#[case] expected_radarr_event: RadarrEvent,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use clap::Subcommand;
|
|||||||
use delete_command_handler::{SonarrDeleteCommand, SonarrDeleteCommandHandler};
|
use delete_command_handler::{SonarrDeleteCommand, SonarrDeleteCommandHandler};
|
||||||
use get_command_handler::{SonarrGetCommand, SonarrGetCommandHandler};
|
use get_command_handler::{SonarrGetCommand, SonarrGetCommandHandler};
|
||||||
use list_command_handler::{SonarrListCommand, SonarrListCommandHandler};
|
use list_command_handler::{SonarrListCommand, SonarrListCommandHandler};
|
||||||
|
use refresh_command_handler::{SonarrRefreshCommand, SonarrRefreshCommandHandler};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -20,6 +21,7 @@ mod add_command_handler;
|
|||||||
mod delete_command_handler;
|
mod delete_command_handler;
|
||||||
mod get_command_handler;
|
mod get_command_handler;
|
||||||
mod list_command_handler;
|
mod list_command_handler;
|
||||||
|
mod refresh_command_handler;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[path = "sonarr_command_tests.rs"]
|
#[path = "sonarr_command_tests.rs"]
|
||||||
@@ -47,6 +49,11 @@ pub enum SonarrCommand {
|
|||||||
about = "Commands to list attributes from your Sonarr instance"
|
about = "Commands to list attributes from your Sonarr instance"
|
||||||
)]
|
)]
|
||||||
List(SonarrListCommand),
|
List(SonarrListCommand),
|
||||||
|
#[command(
|
||||||
|
subcommand,
|
||||||
|
about = "Commands to refresh the data in your Sonarr instance"
|
||||||
|
)]
|
||||||
|
Refresh(SonarrRefreshCommand),
|
||||||
#[command(about = "Clear the blocklist")]
|
#[command(about = "Clear the blocklist")]
|
||||||
ClearBlocklist,
|
ClearBlocklist,
|
||||||
#[command(about = "Mark the Sonarr history item with the given ID as 'failed'")]
|
#[command(about = "Mark the Sonarr history item with the given ID as 'failed'")]
|
||||||
@@ -179,6 +186,11 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrCommand> for SonarrCliHandler<'a, '
|
|||||||
.handle()
|
.handle()
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
|
SonarrCommand::Refresh(update_command) => {
|
||||||
|
SonarrRefreshCommandHandler::with(self.app, update_command, self.network)
|
||||||
|
.handle()
|
||||||
|
.await?
|
||||||
|
}
|
||||||
SonarrCommand::ClearBlocklist => {
|
SonarrCommand::ClearBlocklist => {
|
||||||
self
|
self
|
||||||
.network
|
.network
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use clap::Subcommand;
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
app::App,
|
||||||
|
cli::{CliCommandHandler, Command},
|
||||||
|
network::{sonarr_network::SonarrEvent, NetworkTrait},
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::SonarrCommand;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[path = "refresh_command_handler_tests.rs"]
|
||||||
|
mod refresh_command_handler_tests;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
|
||||||
|
pub enum SonarrRefreshCommand {
|
||||||
|
#[command(about = "Refresh all series data for all series in your Sonarr library")]
|
||||||
|
AllSeries,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SonarrRefreshCommand> for Command {
|
||||||
|
fn from(value: SonarrRefreshCommand) -> Self {
|
||||||
|
Command::Sonarr(SonarrCommand::Refresh(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) struct SonarrRefreshCommandHandler<'a, 'b> {
|
||||||
|
_app: &'a Arc<Mutex<App<'b>>>,
|
||||||
|
command: SonarrRefreshCommand,
|
||||||
|
network: &'a mut dyn NetworkTrait,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrRefreshCommand>
|
||||||
|
for SonarrRefreshCommandHandler<'a, 'b>
|
||||||
|
{
|
||||||
|
fn with(
|
||||||
|
_app: &'a Arc<Mutex<App<'b>>>,
|
||||||
|
command: SonarrRefreshCommand,
|
||||||
|
network: &'a mut dyn NetworkTrait,
|
||||||
|
) -> Self {
|
||||||
|
SonarrRefreshCommandHandler {
|
||||||
|
_app,
|
||||||
|
command,
|
||||||
|
network,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle(self) -> anyhow::Result<String> {
|
||||||
|
let result = match self.command {
|
||||||
|
SonarrRefreshCommand::AllSeries => {
|
||||||
|
let resp = self
|
||||||
|
.network
|
||||||
|
.handle_network_event(SonarrEvent::UpdateAllSeries.into())
|
||||||
|
.await?;
|
||||||
|
serde_json::to_string_pretty(&resp)?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
|
use crate::cli::{
|
||||||
|
sonarr::{refresh_command_handler::SonarrRefreshCommand, SonarrCommand},
|
||||||
|
Command,
|
||||||
|
};
|
||||||
|
use crate::Cli;
|
||||||
|
use clap::CommandFactory;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_sonarr_refresh_command_from() {
|
||||||
|
let command = SonarrRefreshCommand::AllSeries;
|
||||||
|
|
||||||
|
let result = Command::from(command.clone());
|
||||||
|
|
||||||
|
assert_eq!(result, Command::Sonarr(SonarrCommand::Refresh(command)));
|
||||||
|
}
|
||||||
|
|
||||||
|
mod cli {
|
||||||
|
use super::*;
|
||||||
|
use clap::Parser;
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
|
use rstest::rstest;
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
fn test_refresh_commands_have_no_arg_requirements(#[values("all-series")] subcommand: &str) {
|
||||||
|
let result =
|
||||||
|
Cli::command().try_get_matches_from(["managarr", "sonarr", "refresh", subcommand]);
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod handler {
|
||||||
|
use rstest::rstest;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use mockall::predicate::eq;
|
||||||
|
use serde_json::json;
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
cli::{sonarr::refresh_command_handler::SonarrRefreshCommand, CliCommandHandler},
|
||||||
|
network::sonarr_network::SonarrEvent,
|
||||||
|
};
|
||||||
|
use crate::{
|
||||||
|
models::{sonarr_models::SonarrSerdeable, Serdeable},
|
||||||
|
network::{MockNetworkTrait, NetworkEvent},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
#[case(SonarrRefreshCommand::AllSeries, SonarrEvent::UpdateAllSeries)]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_refresh_command(
|
||||||
|
#[case] refresh_command: SonarrRefreshCommand,
|
||||||
|
#[case] expected_sonarr_event: SonarrEvent,
|
||||||
|
) {
|
||||||
|
use crate::{app::App, cli::sonarr::refresh_command_handler::SonarrRefreshCommandHandler};
|
||||||
|
|
||||||
|
let mut mock_network = MockNetworkTrait::new();
|
||||||
|
mock_network
|
||||||
|
.expect_handle_network_event()
|
||||||
|
.with(eq::<NetworkEvent>(expected_sonarr_event.into()))
|
||||||
|
.times(1)
|
||||||
|
.returning(|_| {
|
||||||
|
Ok(Serdeable::Sonarr(SonarrSerdeable::Value(
|
||||||
|
json!({"testResponse": "response"}),
|
||||||
|
)))
|
||||||
|
});
|
||||||
|
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||||
|
|
||||||
|
let result = SonarrRefreshCommandHandler::with(&app_arc, refresh_command, &mut mock_network)
|
||||||
|
.handle()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -544,6 +544,32 @@ mod tests {
|
|||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #[tokio::test]
|
||||||
|
// async fn test_sonarr_cli_handler_delegates_refresh_commands_to_the_refresh_command_handler() {
|
||||||
|
// let expected_series_id = 1;
|
||||||
|
// let mut mock_network = MockNetworkTrait::new();
|
||||||
|
// mock_network
|
||||||
|
// .expect_handle_network_event()
|
||||||
|
// .with(eq::<NetworkEvent>(
|
||||||
|
// SonarrEvent::UpdateAndScan(Some(expected_movie_id)).into(),
|
||||||
|
// ))
|
||||||
|
// .times(1)
|
||||||
|
// .returning(|_| {
|
||||||
|
// Ok(Serdeable::Sonarr(SonarrSerdeable::Value(
|
||||||
|
// json!({"testResponse": "response"}),
|
||||||
|
// )))
|
||||||
|
// });
|
||||||
|
// let app_arc = Arc::new(Mutex::new(App::default()));
|
||||||
|
// let refresh_all_series_command =
|
||||||
|
// SonarrCommand::Refresh(SonarrRefreshCommand::Movie { movie_id: 1 });
|
||||||
|
|
||||||
|
// let result = SonarrCliHandler::with(&app_arc, refresh_movie_command, &mut mock_network)
|
||||||
|
// .handle()
|
||||||
|
// .await;
|
||||||
|
|
||||||
|
// assert!(result.is_ok());
|
||||||
|
// }
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_start_task_command() {
|
async fn test_start_task_command() {
|
||||||
let expected_task_name = SonarrTaskName::ApplicationUpdateCheck;
|
let expected_task_name = SonarrTaskName::ApplicationUpdateCheck;
|
||||||
|
|||||||
Reference in New Issue
Block a user