feat(cli): Support for toggling monitoring for a specific season in Sonarr
This commit is contained in:
@@ -120,6 +120,23 @@ pub enum SonarrCommand {
|
|||||||
},
|
},
|
||||||
#[command(about = "Test all Sonarr indexers")]
|
#[command(about = "Test all Sonarr indexers")]
|
||||||
TestAllIndexers,
|
TestAllIndexers,
|
||||||
|
#[command(
|
||||||
|
about = "Toggle monitoring for the specified season that corresponds to the specified series ID"
|
||||||
|
)]
|
||||||
|
ToggleSeasonMonitoring {
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
help = "The Sonarr ID of the series that the season belongs to",
|
||||||
|
required = true
|
||||||
|
)]
|
||||||
|
series_id: i64,
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
help = "The season number to toggle monitoring for",
|
||||||
|
required = true
|
||||||
|
)]
|
||||||
|
season_number: i64,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SonarrCommand> for Command {
|
impl From<SonarrCommand> for Command {
|
||||||
@@ -245,6 +262,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrCommand> for SonarrCliHandler<'a, '
|
|||||||
.await?;
|
.await?;
|
||||||
serde_json::to_string_pretty(&resp)?
|
serde_json::to_string_pretty(&resp)?
|
||||||
}
|
}
|
||||||
|
SonarrCommand::ToggleSeasonMonitoring {series_id, season_number } => {
|
||||||
|
let resp = self
|
||||||
|
.network
|
||||||
|
.handle_network_event(SonarrEvent::ToggleSeasonMonitoring(Some((series_id, season_number))).into())
|
||||||
|
.await?;
|
||||||
|
serde_json::to_string_pretty(&resp)?
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
|||||||
@@ -142,6 +142,55 @@ mod tests {
|
|||||||
|
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_toggle_season_monitoring_requires_series_id() {
|
||||||
|
let result = Cli::command().try_get_matches_from([
|
||||||
|
"managarr",
|
||||||
|
"sonarr",
|
||||||
|
"toggle-season-monitoring",
|
||||||
|
"--season-number",
|
||||||
|
"1",
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert!(result.is_err());
|
||||||
|
assert_eq!(
|
||||||
|
result.unwrap_err().kind(),
|
||||||
|
ErrorKind::MissingRequiredArgument
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_toggle_season_monitoring_requires_season_number() {
|
||||||
|
let result = Cli::command().try_get_matches_from([
|
||||||
|
"managarr",
|
||||||
|
"sonarr",
|
||||||
|
"toggle-season-monitoring",
|
||||||
|
"--series-id",
|
||||||
|
"1",
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert!(result.is_err());
|
||||||
|
assert_eq!(
|
||||||
|
result.unwrap_err().kind(),
|
||||||
|
ErrorKind::MissingRequiredArgument
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_toggle_season_monitoring_requirements_satisfied() {
|
||||||
|
let result = Cli::command().try_get_matches_from([
|
||||||
|
"managarr",
|
||||||
|
"sonarr",
|
||||||
|
"toggle-season-monitoring",
|
||||||
|
"--series-id",
|
||||||
|
"1",
|
||||||
|
"--season-number",
|
||||||
|
"1",
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod handler {
|
mod handler {
|
||||||
@@ -616,5 +665,35 @@ mod tests {
|
|||||||
|
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_list_toggle_season_monitoring_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::ToggleSeasonMonitoring(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 toggle_season_monitoring_command = SonarrCommand::ToggleSeasonMonitoring {
|
||||||
|
series_id: 1,
|
||||||
|
season_number: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
let result =
|
||||||
|
SonarrCliHandler::with(&app_arc, toggle_season_monitoring_command, &mut mock_network)
|
||||||
|
.handle()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user