diff --git a/src/cli/sonarr/get_command_handler.rs b/src/cli/sonarr/get_command_handler.rs index 7e42ca9..c0356ce 100644 --- a/src/cli/sonarr/get_command_handler.rs +++ b/src/cli/sonarr/get_command_handler.rs @@ -28,6 +28,10 @@ pub enum SonarrGetCommand { )] episode_id: i64, }, + #[command(about = "Fetch the host config for your Sonarr instance")] + HostConfig, + #[command(about = "Fetch the security config for your Sonarr instance")] + SecurityConfig, #[command(about = "Get the system status")] SystemStatus, } @@ -62,6 +66,12 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrGetCommand> for SonarrGetCommandHan SonarrGetCommand::EpisodeDetails { episode_id } => { execute_network_event!(self, SonarrEvent::GetEpisodeDetails(Some(episode_id))); } + SonarrGetCommand::HostConfig => { + execute_network_event!(self, SonarrEvent::GetHostConfig); + } + SonarrGetCommand::SecurityConfig => { + execute_network_event!(self, SonarrEvent::GetSecurityConfig); + } SonarrGetCommand::SystemStatus => { execute_network_event!(self, SonarrEvent::GetStatus); } diff --git a/src/cli/sonarr/get_command_handler_tests.rs b/src/cli/sonarr/get_command_handler_tests.rs index 3f6a513..00e7a38 100644 --- a/src/cli/sonarr/get_command_handler_tests.rs +++ b/src/cli/sonarr/get_command_handler_tests.rs @@ -54,6 +54,22 @@ mod tests { assert!(result.is_ok()); } + + #[test] + fn test_get_host_config_has_no_arg_requirements() { + let result = + Cli::command().try_get_matches_from(["managarr", "sonarr", "get", "host-config"]); + + assert!(result.is_ok()); + } + + #[test] + fn test_get_security_config_has_no_arg_requirements() { + let result = + Cli::command().try_get_matches_from(["managarr", "sonarr", "get", "security-config"]); + + assert!(result.is_ok()); + } } mod handler { @@ -99,6 +115,52 @@ mod tests { assert!(result.is_ok()); } + #[tokio::test] + async fn test_handle_get_host_config_command() { + let mut mock_network = MockNetworkTrait::new(); + mock_network + .expect_handle_network_event() + .with(eq::(SonarrEvent::GetHostConfig.into())) + .times(1) + .returning(|_| { + Ok(Serdeable::Sonarr(SonarrSerdeable::Value( + json!({"testResponse": "response"}), + ))) + }); + let app_arc = Arc::new(Mutex::new(App::default())); + let get_host_config_command = SonarrGetCommand::HostConfig; + + let result = + SonarrGetCommandHandler::with(&app_arc, get_host_config_command, &mut mock_network) + .handle() + .await; + + assert!(result.is_ok()); + } + + #[tokio::test] + async fn test_handle_get_security_config_command() { + let mut mock_network = MockNetworkTrait::new(); + mock_network + .expect_handle_network_event() + .with(eq::(SonarrEvent::GetSecurityConfig.into())) + .times(1) + .returning(|_| { + Ok(Serdeable::Sonarr(SonarrSerdeable::Value( + json!({"testResponse": "response"}), + ))) + }); + let app_arc = Arc::new(Mutex::new(App::default())); + let get_security_config_command = SonarrGetCommand::SecurityConfig; + + let result = + SonarrGetCommandHandler::with(&app_arc, get_security_config_command, &mut mock_network) + .handle() + .await; + + assert!(result.is_ok()); + } + #[tokio::test] async fn test_handle_get_system_status_command() { let mut mock_network = MockNetworkTrait::new(); diff --git a/src/models/servarr_models.rs b/src/models/servarr_models.rs index 8dca55b..0944b74 100644 --- a/src/models/servarr_models.rs +++ b/src/models/servarr_models.rs @@ -117,8 +117,11 @@ pub struct IndexerField { #[serde(rename_all = "camelCase")] pub struct SecurityConfig { pub authentication_method: AuthenticationMethod, - pub authentication_required: AuthenticationRequired, - pub username: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub authentication_required: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub username: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub password: Option, pub api_key: String, pub certificate_validation: CertificateValidation, diff --git a/src/network/sonarr_network_tests.rs b/src/network/sonarr_network_tests.rs index 9a0e819..5fe5d46 100644 --- a/src/network/sonarr_network_tests.rs +++ b/src/network/sonarr_network_tests.rs @@ -964,7 +964,7 @@ mod test { async fn test_handle_get_sonarr_logs_event() { let expected_logs = vec![ HorizontallyScrollableText::from( - "2023-05-20 21:29:16 UTC|FATAL|RadarrError|Some.Big.Bad.Exception|test exception", + "2023-05-20 21:29:16 UTC|FATAL|SonarrError|Some.Big.Bad.Exception|test exception", ), HorizontallyScrollableText::from("2023-05-20 21:29:16 UTC|INFO|TestLogger|test message"), ]; @@ -985,7 +985,7 @@ mod test { { "time": "2023-05-20T21:29:16Z", "level": "fatal", - "logger": "RadarrError", + "logger": "SonarrError", "exception": "test exception", "exceptionType": "Some.Big.Bad.Exception", "id": 2 @@ -1032,7 +1032,7 @@ mod test { async fn test_handle_get_sonarr_logs_event_uses_provided_events() { let expected_logs = vec![ HorizontallyScrollableText::from( - "2023-05-20 21:29:16 UTC|FATAL|RadarrError|Some.Big.Bad.Exception|test exception", + "2023-05-20 21:29:16 UTC|FATAL|SonarrError|Some.Big.Bad.Exception|test exception", ), HorizontallyScrollableText::from("2023-05-20 21:29:16 UTC|INFO|TestLogger|test message"), ]; @@ -1053,7 +1053,7 @@ mod test { { "time": "2023-05-20T21:29:16Z", "level": "fatal", - "logger": "RadarrError", + "logger": "SonarrError", "exception": "test exception", "exceptionType": "Some.Big.Bad.Exception", "id": 2