diff --git a/src/cli/radarr/add_command_handler_tests.rs b/src/cli/radarr/add_command_handler_tests.rs index 8974454..59c9e29 100644 --- a/src/cli/radarr/add_command_handler_tests.rs +++ b/src/cli/radarr/add_command_handler_tests.rs @@ -10,6 +10,7 @@ mod tests { models::radarr_models::{MinimumAvailability, Monitor}, Cli, }; + use pretty_assertions::assert_eq; #[test] fn test_radarr_add_command_from() { diff --git a/src/cli/radarr/delete_command_handler_tests.rs b/src/cli/radarr/delete_command_handler_tests.rs index 7e20597..d8971f7 100644 --- a/src/cli/radarr/delete_command_handler_tests.rs +++ b/src/cli/radarr/delete_command_handler_tests.rs @@ -8,6 +8,7 @@ mod tests { Cli, }; use clap::{error::ErrorKind, CommandFactory, Parser}; + use pretty_assertions::assert_eq; #[test] fn test_radarr_delete_command_from() { diff --git a/src/cli/radarr/edit_command_handler_tests.rs b/src/cli/radarr/edit_command_handler_tests.rs index 3f77649..a960954 100644 --- a/src/cli/radarr/edit_command_handler_tests.rs +++ b/src/cli/radarr/edit_command_handler_tests.rs @@ -8,6 +8,7 @@ mod tests { Cli, }; use clap::{error::ErrorKind, CommandFactory, Parser}; + use pretty_assertions::assert_eq; #[test] fn test_radarr_edit_command_from() { diff --git a/src/cli/radarr/get_command_handler_tests.rs b/src/cli/radarr/get_command_handler_tests.rs index 0bc629f..e70db37 100644 --- a/src/cli/radarr/get_command_handler_tests.rs +++ b/src/cli/radarr/get_command_handler_tests.rs @@ -7,6 +7,7 @@ mod tests { use crate::cli::radarr::RadarrCommand; use crate::cli::Command; use crate::Cli; + use pretty_assertions::assert_eq; #[test] fn test_radarr_get_command_from() { diff --git a/src/cli/radarr/list_command_handler_tests.rs b/src/cli/radarr/list_command_handler_tests.rs index 080e0df..ca9aa0f 100644 --- a/src/cli/radarr/list_command_handler_tests.rs +++ b/src/cli/radarr/list_command_handler_tests.rs @@ -7,6 +7,7 @@ mod tests { use crate::cli::radarr::RadarrCommand; use crate::cli::Command; use crate::Cli; + use pretty_assertions::assert_eq; #[test] fn test_radarr_list_command_from() { diff --git a/src/cli/radarr/refresh_command_handler_tests.rs b/src/cli/radarr/refresh_command_handler_tests.rs index 2f8352a..30be57b 100644 --- a/src/cli/radarr/refresh_command_handler_tests.rs +++ b/src/cli/radarr/refresh_command_handler_tests.rs @@ -7,6 +7,7 @@ mod tests { use crate::cli::radarr::RadarrCommand; use crate::cli::Command; use crate::Cli; + use pretty_assertions::assert_eq; #[test] fn test_radarr_refresh_command_from() { diff --git a/src/cli/sonarr/add_command_handler_tests.rs b/src/cli/sonarr/add_command_handler_tests.rs index 25c244c..9a6f251 100644 --- a/src/cli/sonarr/add_command_handler_tests.rs +++ b/src/cli/sonarr/add_command_handler_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use clap::{error::ErrorKind, CommandFactory, Parser}; + use pretty_assertions::assert_eq; use crate::{ cli::{ diff --git a/src/cli/sonarr/delete_command_handler_tests.rs b/src/cli/sonarr/delete_command_handler_tests.rs index 8c66a4e..4400a90 100644 --- a/src/cli/sonarr/delete_command_handler_tests.rs +++ b/src/cli/sonarr/delete_command_handler_tests.rs @@ -8,6 +8,7 @@ mod tests { Cli, }; use clap::{error::ErrorKind, CommandFactory, Parser}; + use pretty_assertions::assert_eq; #[test] fn test_sonarr_delete_command_from() { diff --git a/src/cli/sonarr/get_command_handler_tests.rs b/src/cli/sonarr/get_command_handler_tests.rs index 714cc67..12a6225 100644 --- a/src/cli/sonarr/get_command_handler_tests.rs +++ b/src/cli/sonarr/get_command_handler_tests.rs @@ -6,6 +6,7 @@ mod tests { }; use crate::Cli; use clap::CommandFactory; + use pretty_assertions::assert_eq; #[test] fn test_sonarr_get_command_from() { @@ -18,6 +19,7 @@ mod tests { mod cli { use clap::error::ErrorKind; + use pretty_assertions::assert_eq; use super::*; diff --git a/src/cli/sonarr/list_command_handler_tests.rs b/src/cli/sonarr/list_command_handler_tests.rs index 886750e..0382f60 100644 --- a/src/cli/sonarr/list_command_handler_tests.rs +++ b/src/cli/sonarr/list_command_handler_tests.rs @@ -6,6 +6,7 @@ mod tests { }; use crate::Cli; use clap::CommandFactory; + use pretty_assertions::assert_eq; #[test] fn test_sonarr_list_command_from() { diff --git a/src/cli/sonarr/mod.rs b/src/cli/sonarr/mod.rs index 54d651c..81cfa48 100644 --- a/src/cli/sonarr/mod.rs +++ b/src/cli/sonarr/mod.rs @@ -108,6 +108,19 @@ pub enum SonarrCommand { )] series_id: i64, }, + #[command( + about = "Trigger an automatic search for the given season corresponding to the series with the given ID" + )] + TriggerAutomaticSeasonSearch { + #[arg( + long, + help = "The Sonarr ID of the series whose season you wish to trigger an automatic search for", + required = true + )] + series_id: i64, + #[arg(long, help = "The season number to search for", required = true)] + season_number: i64, + }, } impl From for Command { @@ -225,6 +238,18 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrCommand> for SonarrCliHandler<'a, ' .await?; serde_json::to_string_pretty(&resp)? } + SonarrCommand::TriggerAutomaticSeasonSearch { + series_id, + season_number, + } => { + let resp = self + .network + .handle_network_event( + SonarrEvent::TriggerAutomaticSeasonSearch(Some((series_id, season_number))).into(), + ) + .await?; + serde_json::to_string_pretty(&resp)? + } }; Ok(result) diff --git a/src/cli/sonarr/sonarr_command_tests.rs b/src/cli/sonarr/sonarr_command_tests.rs index 0ce54d0..b906ef8 100644 --- a/src/cli/sonarr/sonarr_command_tests.rs +++ b/src/cli/sonarr/sonarr_command_tests.rs @@ -6,6 +6,7 @@ mod tests { }; use crate::Cli; use clap::CommandFactory; + use pretty_assertions::assert_eq; #[test] fn test_sonarr_command_from() { @@ -19,6 +20,7 @@ mod tests { mod cli { use super::*; use clap::error::ErrorKind; + use pretty_assertions::assert_eq; use rstest::rstest; #[rstest] @@ -218,6 +220,55 @@ mod tests { assert!(result.is_ok()); } + + #[rstest] + fn test_trigger_automatic_season_search_requires_series_id() { + let result = Cli::command().try_get_matches_from([ + "managarr", + "sonarr", + "trigger-automatic-season-search", + "--season-number", + "1", + ]); + + assert!(result.is_err()); + assert_eq!( + result.unwrap_err().kind(), + ErrorKind::MissingRequiredArgument + ); + } + + #[rstest] + fn test_trigger_automatic_season_search_requires_season_number() { + let result = Cli::command().try_get_matches_from([ + "managarr", + "sonarr", + "trigger-automatic-season-search", + "--series-id", + "1", + ]); + + assert!(result.is_err()); + assert_eq!( + result.unwrap_err().kind(), + ErrorKind::MissingRequiredArgument + ); + } + + #[test] + fn test_trigger_automatic_season_search_requirements_satisfied() { + let result = Cli::command().try_get_matches_from([ + "managarr", + "sonarr", + "trigger-automatic-season-search", + "--series-id", + "1", + "--season-number", + "1", + ]); + + assert!(result.is_ok()); + } } mod handler { @@ -568,5 +619,42 @@ mod tests { assert!(result.is_ok()); } + + #[tokio::test] + async fn test_trigger_automatic_season_search_command() { + let expected_series_id = 1; + let expected_season_number = 1; + let mut mock_network = MockNetworkTrait::new(); + mock_network + .expect_handle_network_event() + .with(eq::( + SonarrEvent::TriggerAutomaticSeasonSearch(Some(( + expected_series_id, + expected_season_number, + ))) + .into(), + )) + .times(1) + .returning(|_| { + Ok(Serdeable::Sonarr(SonarrSerdeable::Value( + json!({"testResponse": "response"}), + ))) + }); + let app_arc = Arc::new(Mutex::new(App::default())); + let trigger_automatic_season_search_command = SonarrCommand::TriggerAutomaticSeasonSearch { + series_id: 1, + season_number: 1, + }; + + let result = SonarrCliHandler::with( + &app_arc, + trigger_automatic_season_search_command, + &mut mock_network, + ) + .handle() + .await; + + assert!(result.is_ok()); + } } }