feat(cli): Support for toggling monitoring on a specific episode in Sonarr
This commit is contained in:
@@ -120,6 +120,17 @@ pub enum SonarrCommand {
|
|||||||
},
|
},
|
||||||
#[command(about = "Test all Sonarr indexers")]
|
#[command(about = "Test all Sonarr indexers")]
|
||||||
TestAllIndexers,
|
TestAllIndexers,
|
||||||
|
#[command(
|
||||||
|
about = "Toggle monitoring for the specified episode"
|
||||||
|
)]
|
||||||
|
ToggleEpisodeMonitoring {
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
help = "The Sonarr ID of the episode to toggle monitoring on",
|
||||||
|
required = true
|
||||||
|
)]
|
||||||
|
episode_id: i64,
|
||||||
|
},
|
||||||
#[command(
|
#[command(
|
||||||
about = "Toggle monitoring for the specified season that corresponds to the specified series ID"
|
about = "Toggle monitoring for the specified season that corresponds to the specified series ID"
|
||||||
)]
|
)]
|
||||||
@@ -262,6 +273,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::ToggleEpisodeMonitoring { episode_id } => {
|
||||||
|
let resp = self
|
||||||
|
.network
|
||||||
|
.handle_network_event(SonarrEvent::ToggleEpisodeMonitoring(Some(episode_id)).into())
|
||||||
|
.await?;
|
||||||
|
serde_json::to_string_pretty(&resp)?
|
||||||
|
}
|
||||||
SonarrCommand::ToggleSeasonMonitoring {series_id, season_number } => {
|
SonarrCommand::ToggleSeasonMonitoring {series_id, season_number } => {
|
||||||
let resp = self
|
let resp = self
|
||||||
.network
|
.network
|
||||||
|
|||||||
@@ -143,6 +143,34 @@ mod tests {
|
|||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_toggle_episode_monitoring_requires_episode_id() {
|
||||||
|
let result = Cli::command().try_get_matches_from([
|
||||||
|
"managarr",
|
||||||
|
"sonarr",
|
||||||
|
"toggle-episode-monitoring",
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert!(result.is_err());
|
||||||
|
assert_eq!(
|
||||||
|
result.unwrap_err().kind(),
|
||||||
|
ErrorKind::MissingRequiredArgument
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_toggle_episode_monitoring_requirements_satisfied() {
|
||||||
|
let result = Cli::command().try_get_matches_from([
|
||||||
|
"managarr",
|
||||||
|
"sonarr",
|
||||||
|
"toggle-episode-monitoring",
|
||||||
|
"--episode-id",
|
||||||
|
"1",
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_toggle_season_monitoring_requires_series_id() {
|
fn test_toggle_season_monitoring_requires_series_id() {
|
||||||
let result = Cli::command().try_get_matches_from([
|
let result = Cli::command().try_get_matches_from([
|
||||||
@@ -666,6 +694,34 @@ mod tests {
|
|||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_list_toggle_episode_monitoring_command() {
|
||||||
|
let expected_episode_id = 1;
|
||||||
|
let mut mock_network = MockNetworkTrait::new();
|
||||||
|
mock_network
|
||||||
|
.expect_handle_network_event()
|
||||||
|
.with(eq::<NetworkEvent>(
|
||||||
|
SonarrEvent::ToggleEpisodeMonitoring(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 toggle_episode_monitoring_command = SonarrCommand::ToggleEpisodeMonitoring {
|
||||||
|
episode_id: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
let result =
|
||||||
|
SonarrCliHandler::with(&app_arc, toggle_episode_monitoring_command, &mut mock_network)
|
||||||
|
.handle()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_list_toggle_season_monitoring_command() {
|
async fn test_list_toggle_season_monitoring_command() {
|
||||||
let expected_series_id = 1;
|
let expected_series_id = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user