feat(cli): Added support for manually searching for season releases for Sonarr
This commit is contained in:
@@ -86,7 +86,7 @@ pub enum RadarrCommand {
|
||||
ManualSearch {
|
||||
#[arg(
|
||||
long,
|
||||
help = "The Radarr ID of the movie whose releases you wish to fetch and list",
|
||||
help = "The Radarr ID of the movie whose releases you wish to fetch",
|
||||
required = true
|
||||
)]
|
||||
movie_id: i64,
|
||||
|
||||
@@ -42,6 +42,19 @@ pub enum SonarrCommand {
|
||||
List(SonarrListCommand),
|
||||
#[command(about = "Clear the blocklist")]
|
||||
ClearBlocklist,
|
||||
#[command(
|
||||
about = "Trigger a manual search of releases for the given season corresponding to the series with the given ID"
|
||||
)]
|
||||
ManualSeasonSearch {
|
||||
#[arg(
|
||||
long,
|
||||
help = "The Sonarr ID of the series whose releases you wish to fetch and list",
|
||||
required = true
|
||||
)]
|
||||
series_id: i64,
|
||||
#[arg(long, help = "The season number to search for", required = true)]
|
||||
season_number: i64,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<SonarrCommand> for Command {
|
||||
@@ -93,6 +106,16 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrCommand> for SonarrCliHandler<'a, '
|
||||
.await?;
|
||||
execute_network_event!(self, SonarrEvent::ClearBlocklist);
|
||||
}
|
||||
SonarrCommand::ManualSeasonSearch {
|
||||
series_id,
|
||||
season_number,
|
||||
} => {
|
||||
println!("Searching for season releases. This may take a minute...");
|
||||
execute_network_event!(
|
||||
self,
|
||||
SonarrEvent::GetSeasonReleases(Some((series_id, season_number)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -18,6 +18,7 @@ mod tests {
|
||||
|
||||
mod cli {
|
||||
use super::*;
|
||||
use clap::error::ErrorKind;
|
||||
use rstest::rstest;
|
||||
|
||||
#[rstest]
|
||||
@@ -26,6 +27,55 @@ mod tests {
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_manual_season_search_requires_series_id() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"sonarr",
|
||||
"manual-season-search",
|
||||
"--season-number",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_manual_season_search_requires_season_number() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"sonarr",
|
||||
"manual-season-search",
|
||||
"--series-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_manual_season_search_requirements_satisfied() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"sonarr",
|
||||
"manual-season-search",
|
||||
"--series-id",
|
||||
"1",
|
||||
"--season-number",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
mod handler {
|
||||
@@ -84,6 +134,36 @@ mod tests {
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_manual_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::<NetworkEvent>(
|
||||
SonarrEvent::GetSeasonReleases(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 manual_season_search_command = SonarrCommand::ManualSeasonSearch {
|
||||
series_id: 1,
|
||||
season_number: 1,
|
||||
};
|
||||
|
||||
let result =
|
||||
SonarrCliHandler::with(&app_arc, manual_season_search_command, &mut mock_network)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_sonarr_cli_handler_delegates_delete_commands_to_the_delete_command_handler() {
|
||||
let expected_blocklist_item_id = 1;
|
||||
|
||||
Reference in New Issue
Block a user