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

This commit is contained in:
2024-11-22 18:32:35 -07:00
parent 74e9ea17ac
commit 40bb22ef7c
12 changed files with 124 additions and 0 deletions
@@ -10,6 +10,7 @@ mod tests {
models::radarr_models::{MinimumAvailability, Monitor},
Cli,
};
use pretty_assertions::assert_eq;
#[test]
fn test_radarr_add_command_from() {
@@ -8,6 +8,7 @@ mod tests {
Cli,
};
use clap::{error::ErrorKind, CommandFactory, Parser};
use pretty_assertions::assert_eq;
#[test]
fn test_radarr_delete_command_from() {
@@ -8,6 +8,7 @@ mod tests {
Cli,
};
use clap::{error::ErrorKind, CommandFactory, Parser};
use pretty_assertions::assert_eq;
#[test]
fn test_radarr_edit_command_from() {
@@ -7,6 +7,7 @@ mod tests {
use crate::cli::radarr::RadarrCommand;
use crate::cli::Command;
use crate::Cli;
use pretty_assertions::assert_eq;
#[test]
fn test_radarr_get_command_from() {
@@ -7,6 +7,7 @@ mod tests {
use crate::cli::radarr::RadarrCommand;
use crate::cli::Command;
use crate::Cli;
use pretty_assertions::assert_eq;
#[test]
fn test_radarr_list_command_from() {
@@ -7,6 +7,7 @@ mod tests {
use crate::cli::radarr::RadarrCommand;
use crate::cli::Command;
use crate::Cli;
use pretty_assertions::assert_eq;
#[test]
fn test_radarr_refresh_command_from() {
@@ -1,6 +1,7 @@
#[cfg(test)]
mod tests {
use clap::{error::ErrorKind, CommandFactory, Parser};
use pretty_assertions::assert_eq;
use crate::{
cli::{
@@ -8,6 +8,7 @@ mod tests {
Cli,
};
use clap::{error::ErrorKind, CommandFactory, Parser};
use pretty_assertions::assert_eq;
#[test]
fn test_sonarr_delete_command_from() {
@@ -6,6 +6,7 @@ mod tests {
};
use crate::Cli;
use clap::CommandFactory;
use pretty_assertions::assert_eq;
#[test]
fn test_sonarr_get_command_from() {
@@ -18,6 +19,7 @@ mod tests {
mod cli {
use clap::error::ErrorKind;
use pretty_assertions::assert_eq;
use super::*;
@@ -6,6 +6,7 @@ mod tests {
};
use crate::Cli;
use clap::CommandFactory;
use pretty_assertions::assert_eq;
#[test]
fn test_sonarr_list_command_from() {
+25
View File
@@ -108,6 +108,19 @@ pub enum SonarrCommand {
)]
series_id: i64,
},
#[command(
about = "Trigger an automatic search for the given season corresponding to the series with the given ID"
)]
TriggerAutomaticSeasonSearch {
#[arg(
long,
help = "The Sonarr ID of the series whose season you wish to trigger an automatic search for",
required = true
)]
series_id: i64,
#[arg(long, help = "The season number to search for", required = true)]
season_number: i64,
},
}
impl From<SonarrCommand> for Command {
@@ -225,6 +238,18 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrCommand> for SonarrCliHandler<'a, '
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrCommand::TriggerAutomaticSeasonSearch {
series_id,
season_number,
} => {
let resp = self
.network
.handle_network_event(
SonarrEvent::TriggerAutomaticSeasonSearch(Some((series_id, season_number))).into(),
)
.await?;
serde_json::to_string_pretty(&resp)?
}
};
Ok(result)
+88
View File
@@ -6,6 +6,7 @@ mod tests {
};
use crate::Cli;
use clap::CommandFactory;
use pretty_assertions::assert_eq;
#[test]
fn test_sonarr_command_from() {
@@ -19,6 +20,7 @@ mod tests {
mod cli {
use super::*;
use clap::error::ErrorKind;
use pretty_assertions::assert_eq;
use rstest::rstest;
#[rstest]
@@ -218,6 +220,55 @@ mod tests {
assert!(result.is_ok());
}
#[rstest]
fn test_trigger_automatic_season_search_requires_series_id() {
let result = Cli::command().try_get_matches_from([
"managarr",
"sonarr",
"trigger-automatic-season-search",
"--season-number",
"1",
]);
assert!(result.is_err());
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[rstest]
fn test_trigger_automatic_season_search_requires_season_number() {
let result = Cli::command().try_get_matches_from([
"managarr",
"sonarr",
"trigger-automatic-season-search",
"--series-id",
"1",
]);
assert!(result.is_err());
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_trigger_automatic_season_search_requirements_satisfied() {
let result = Cli::command().try_get_matches_from([
"managarr",
"sonarr",
"trigger-automatic-season-search",
"--series-id",
"1",
"--season-number",
"1",
]);
assert!(result.is_ok());
}
}
mod handler {
@@ -568,5 +619,42 @@ mod tests {
assert!(result.is_ok());
}
#[tokio::test]
async fn test_trigger_automatic_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::TriggerAutomaticSeasonSearch(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 trigger_automatic_season_search_command = SonarrCommand::TriggerAutomaticSeasonSearch {
series_id: 1,
season_number: 1,
};
let result = SonarrCliHandler::with(
&app_arc,
trigger_automatic_season_search_command,
&mut mock_network,
)
.handle()
.await;
assert!(result.is_ok());
}
}
}