feat(cli): Added CLI support for fetching series details in Sonarr
This commit is contained in:
@@ -34,6 +34,15 @@ pub enum SonarrGetCommand {
|
|||||||
HostConfig,
|
HostConfig,
|
||||||
#[command(about = "Fetch the security config for your Sonarr instance")]
|
#[command(about = "Fetch the security config for your Sonarr instance")]
|
||||||
SecurityConfig,
|
SecurityConfig,
|
||||||
|
#[command(about = "Get detailed information for the series with the given ID")]
|
||||||
|
SeriesDetails {
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
help = "The Sonarr ID of the series whose details you wish to fetch",
|
||||||
|
required = true
|
||||||
|
)]
|
||||||
|
series_id: i64,
|
||||||
|
},
|
||||||
#[command(about = "Get the system status")]
|
#[command(about = "Get the system status")]
|
||||||
SystemStatus,
|
SystemStatus,
|
||||||
}
|
}
|
||||||
@@ -77,6 +86,9 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrGetCommand> for SonarrGetCommandHan
|
|||||||
SonarrGetCommand::SecurityConfig => {
|
SonarrGetCommand::SecurityConfig => {
|
||||||
execute_network_event!(self, SonarrEvent::GetSecurityConfig);
|
execute_network_event!(self, SonarrEvent::GetSecurityConfig);
|
||||||
}
|
}
|
||||||
|
SonarrGetCommand::SeriesDetails { series_id } => {
|
||||||
|
execute_network_event!(self, SonarrEvent::GetSeriesDetails(Some(series_id)));
|
||||||
|
}
|
||||||
SonarrGetCommand::SystemStatus => {
|
SonarrGetCommand::SystemStatus => {
|
||||||
execute_network_event!(self, SonarrEvent::GetStatus);
|
execute_network_event!(self, SonarrEvent::GetStatus);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,32 @@ mod tests {
|
|||||||
|
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_series_details_requires_series_id() {
|
||||||
|
let result =
|
||||||
|
Cli::command().try_get_matches_from(["managarr", "sonarr", "get", "series-details"]);
|
||||||
|
|
||||||
|
assert!(result.is_err());
|
||||||
|
assert_eq!(
|
||||||
|
result.unwrap_err().kind(),
|
||||||
|
ErrorKind::MissingRequiredArgument
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_series_details_requirements_satisfied() {
|
||||||
|
let result = Cli::command().try_get_matches_from([
|
||||||
|
"managarr",
|
||||||
|
"sonarr",
|
||||||
|
"get",
|
||||||
|
"series-details",
|
||||||
|
"--series-id",
|
||||||
|
"1",
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod handler {
|
mod handler {
|
||||||
@@ -197,6 +223,32 @@ mod tests {
|
|||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_get_series_details_command() {
|
||||||
|
let expected_series_id = 1;
|
||||||
|
let mut mock_network = MockNetworkTrait::new();
|
||||||
|
mock_network
|
||||||
|
.expect_handle_network_event()
|
||||||
|
.with(eq::<NetworkEvent>(
|
||||||
|
SonarrEvent::GetSeriesDetails(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 get_series_details_command = SonarrGetCommand::SeriesDetails { series_id: 1 };
|
||||||
|
|
||||||
|
let result =
|
||||||
|
SonarrGetCommandHandler::with(&app_arc, get_series_details_command, &mut mock_network)
|
||||||
|
.handle()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_handle_get_system_status_command() {
|
async fn test_handle_get_system_status_command() {
|
||||||
let mut mock_network = MockNetworkTrait::new();
|
let mut mock_network = MockNetworkTrait::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user