diff --git a/src/cli/sonarr/mod.rs b/src/cli/sonarr/mod.rs index 0b8e438..693ae01 100644 --- a/src/cli/sonarr/mod.rs +++ b/src/cli/sonarr/mod.rs @@ -42,6 +42,15 @@ pub enum SonarrCommand { List(SonarrListCommand), #[command(about = "Clear the blocklist")] ClearBlocklist, + #[command(about = "Trigger a manual search of releases for the episode with the given ID")] + ManualEpisodeSearch { + #[arg( + long, + help = "The Sonarr ID of the episode whose releases you wish to fetch and list", + required = true + )] + episode_id: i64, + }, #[command( about = "Trigger a manual search of releases for the given season corresponding to the series with the given ID" )] @@ -106,6 +115,10 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrCommand> for SonarrCliHandler<'a, ' .await?; execute_network_event!(self, SonarrEvent::ClearBlocklist); } + SonarrCommand::ManualEpisodeSearch { episode_id } => { + println!("Searching for episode releases. This may take a minute..."); + execute_network_event!(self, SonarrEvent::GetEpisodeReleases(Some(episode_id))); + } SonarrCommand::ManualSeasonSearch { series_id, season_number, diff --git a/src/cli/sonarr/sonarr_command_tests.rs b/src/cli/sonarr/sonarr_command_tests.rs index d61b749..cf22b4b 100644 --- a/src/cli/sonarr/sonarr_command_tests.rs +++ b/src/cli/sonarr/sonarr_command_tests.rs @@ -76,6 +76,31 @@ mod tests { assert!(result.is_ok()); } + + #[rstest] + fn test_manual_episode_search_requires_episode_id() { + let result = + Cli::command().try_get_matches_from(["managarr", "sonarr", "manual-episode-search"]); + + assert!(result.is_err()); + assert_eq!( + result.unwrap_err().kind(), + ErrorKind::MissingRequiredArgument + ); + } + + #[test] + fn test_manual_episode_search_requirements_satisfied() { + let result = Cli::command().try_get_matches_from([ + "managarr", + "sonarr", + "manual-episode-search", + "--episode-id", + "1", + ]); + + assert!(result.is_ok()); + } } mod handler { @@ -134,6 +159,32 @@ mod tests { assert!(result.is_ok()); } + #[tokio::test] + async fn test_manual_episode_search_command() { + let expected_episode_id = 1; + let mut mock_network = MockNetworkTrait::new(); + mock_network + .expect_handle_network_event() + .with(eq::( + SonarrEvent::GetEpisodeReleases(Some(expected_episode_id)).into(), + )) + .times(1) + .returning(|_| { + Ok(Serdeable::Sonarr(SonarrSerdeable::Value( + json!({"testResponse": "response"}), + ))) + }); + let app_arc = Arc::new(Mutex::new(App::default())); + let manual_episode_search_command = SonarrCommand::ManualEpisodeSearch { episode_id: 1 }; + + let result = + SonarrCliHandler::with(&app_arc, manual_episode_search_command, &mut mock_network) + .handle() + .await; + + assert!(result.is_ok()); + } + #[tokio::test] async fn test_manual_season_search_command() { let expected_series_id = 1;