feat(cli): Support for triggering an automatic series search in Sonarr

This commit is contained in:
2024-11-22 18:22:33 -07:00
parent a11bce603d
commit 74e9ea17ac
2 changed files with 74 additions and 0 deletions
+16
View File
@@ -99,6 +99,15 @@ pub enum SonarrCommand {
},
#[command(about = "Test all Radarr indexers")]
TestAllIndexers,
#[command(about = "Trigger an automatic search for the series with the specified ID")]
TriggerAutomaticSeriesSearch {
#[arg(
long,
help = "The ID of the series you want to trigger an automatic search for",
required = true
)]
series_id: i64,
},
}
impl From<SonarrCommand> for Command {
@@ -209,6 +218,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrCommand> for SonarrCliHandler<'a, '
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrCommand::TriggerAutomaticSeriesSearch { series_id } => {
let resp = self
.network
.handle_network_event(SonarrEvent::TriggerAutomaticSeriesSearch(Some(series_id)).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
};
Ok(result)
+58
View File
@@ -190,6 +190,34 @@ mod tests {
assert!(result.is_ok());
}
#[rstest]
fn test_trigger_automatic_series_search_requires_series_id() {
let result = Cli::command().try_get_matches_from([
"managarr",
"sonarr",
"trigger-automatic-series-search",
]);
assert!(result.is_err());
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_trigger_automatic_series_search_requirements_satisfied() {
let result = Cli::command().try_get_matches_from([
"managarr",
"sonarr",
"trigger-automatic-series-search",
"--series-id",
"1",
]);
assert!(result.is_ok());
}
}
mod handler {
@@ -510,5 +538,35 @@ mod tests {
assert!(result.is_ok());
}
#[tokio::test]
async fn test_trigger_automatic_series_search_command() {
let expected_series_id = 1;
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
SonarrEvent::TriggerAutomaticSeriesSearch(Some(expected_series_id)).into(),
))
.times(1)
.returning(|_| {
Ok(Serdeable::Sonarr(SonarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::default()));
let trigger_automatic_series_search_command =
SonarrCommand::TriggerAutomaticSeriesSearch { series_id: 1 };
let result = SonarrCliHandler::with(
&app_arc,
trigger_automatic_series_search_command,
&mut mock_network,
)
.handle()
.await;
assert!(result.is_ok());
}
}
}