feat(cli): Added support for manually searching for episode releases in Sonarr
This commit is contained in:
@@ -42,6 +42,15 @@ pub enum SonarrCommand {
|
|||||||
List(SonarrListCommand),
|
List(SonarrListCommand),
|
||||||
#[command(about = "Clear the blocklist")]
|
#[command(about = "Clear the blocklist")]
|
||||||
ClearBlocklist,
|
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(
|
#[command(
|
||||||
about = "Trigger a manual search of releases for the given season corresponding to the series with the given ID"
|
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?;
|
.await?;
|
||||||
execute_network_event!(self, SonarrEvent::ClearBlocklist);
|
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 {
|
SonarrCommand::ManualSeasonSearch {
|
||||||
series_id,
|
series_id,
|
||||||
season_number,
|
season_number,
|
||||||
|
|||||||
@@ -76,6 +76,31 @@ mod tests {
|
|||||||
|
|
||||||
assert!(result.is_ok());
|
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 {
|
mod handler {
|
||||||
@@ -134,6 +159,32 @@ mod tests {
|
|||||||
assert!(result.is_ok());
|
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::<NetworkEvent>(
|
||||||
|
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]
|
#[tokio::test]
|
||||||
async fn test_manual_season_search_command() {
|
async fn test_manual_season_search_command() {
|
||||||
let expected_series_id = 1;
|
let expected_series_id = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user