feat(cli): Sonarr CLI support for fetching all episodes for a given series
This commit is contained in:
@@ -80,8 +80,8 @@ mod tests {
|
|||||||
|
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
||||||
if let Some(Command::Radarr(RadarrCommand::List(refresh_command))) = result.unwrap().command {
|
if let Some(Command::Radarr(RadarrCommand::List(credits_command))) = result.unwrap().command {
|
||||||
assert_eq!(refresh_command, expected_args);
|
assert_eq!(credits_command, expected_args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,15 @@ mod list_command_handler_tests;
|
|||||||
pub enum SonarrListCommand {
|
pub enum SonarrListCommand {
|
||||||
#[command(about = "List all items in the Sonarr blocklist")]
|
#[command(about = "List all items in the Sonarr blocklist")]
|
||||||
Blocklist,
|
Blocklist,
|
||||||
|
#[command(about = "List the episodes for the series with the given ID")]
|
||||||
|
Episodes {
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
help = "The Sonarr ID of the series whose episodes you wish to fetch",
|
||||||
|
required = true
|
||||||
|
)]
|
||||||
|
series_id: i64,
|
||||||
|
},
|
||||||
#[command(about = "Fetch Sonarr logs")]
|
#[command(about = "Fetch Sonarr logs")]
|
||||||
Logs {
|
Logs {
|
||||||
#[arg(long, help = "How many log events to fetch", default_value_t = 500)]
|
#[arg(long, help = "How many log events to fetch", default_value_t = 500)]
|
||||||
@@ -65,6 +74,9 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrListCommand> for SonarrListCommandH
|
|||||||
SonarrListCommand::Blocklist => {
|
SonarrListCommand::Blocklist => {
|
||||||
execute_network_event!(self, SonarrEvent::GetBlocklist);
|
execute_network_event!(self, SonarrEvent::GetBlocklist);
|
||||||
}
|
}
|
||||||
|
SonarrListCommand::Episodes { series_id } => {
|
||||||
|
execute_network_event!(self, SonarrEvent::GetEpisodes(Some(series_id)));
|
||||||
|
}
|
||||||
SonarrListCommand::Logs {
|
SonarrListCommand::Logs {
|
||||||
events,
|
events,
|
||||||
output_in_log_format,
|
output_in_log_format,
|
||||||
|
|||||||
@@ -31,6 +31,17 @@ mod tests {
|
|||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_list_episodes_requires_series_id() {
|
||||||
|
let result = Cli::command().try_get_matches_from(["managarr", "sonarr", "list", "episodes"]);
|
||||||
|
|
||||||
|
assert!(result.is_err());
|
||||||
|
assert_eq!(
|
||||||
|
result.unwrap_err().kind(),
|
||||||
|
ErrorKind::MissingRequiredArgument
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_list_logs_events_flag_requires_arguments() {
|
fn test_list_logs_events_flag_requires_arguments() {
|
||||||
let result =
|
let result =
|
||||||
@@ -54,6 +65,20 @@ mod tests {
|
|||||||
assert_eq!(refresh_command, expected_args);
|
assert_eq!(refresh_command, expected_args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_list_episodes_success() {
|
||||||
|
let expected_args = SonarrListCommand::Episodes { series_id: 1 };
|
||||||
|
let result =
|
||||||
|
Cli::try_parse_from(["managarr", "sonarr", "list", "episodes", "--series-id", "1"]);
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
|
||||||
|
if let Some(Command::Sonarr(SonarrCommand::List(episodes_command))) = result.unwrap().command
|
||||||
|
{
|
||||||
|
assert_eq!(episodes_command, expected_args);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod handler {
|
mod handler {
|
||||||
@@ -102,6 +127,32 @@ mod tests {
|
|||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_list_episodes_command() {
|
||||||
|
let expected_series_id = 1;
|
||||||
|
let mut mock_network = MockNetworkTrait::new();
|
||||||
|
mock_network
|
||||||
|
.expect_handle_network_event()
|
||||||
|
.with(eq::<NetworkEvent>(
|
||||||
|
SonarrEvent::GetEpisodes(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 list_episodes_command = SonarrListCommand::Episodes { series_id: 1 };
|
||||||
|
|
||||||
|
let result =
|
||||||
|
SonarrListCommandHandler::with(&app_arc, list_episodes_command, &mut mock_network)
|
||||||
|
.handle()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_handle_list_logs_command() {
|
async fn test_handle_list_logs_command() {
|
||||||
let expected_events = 1000;
|
let expected_events = 1000;
|
||||||
|
|||||||
+3
-7
@@ -21,6 +21,7 @@ use crossterm::execute;
|
|||||||
use crossterm::terminal::{
|
use crossterm::terminal::{
|
||||||
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
|
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
|
||||||
};
|
};
|
||||||
|
use human_panic::metadata;
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use network::NetworkTrait;
|
use network::NetworkTrait;
|
||||||
use ratatui::backend::CrosstermBackend;
|
use ratatui::backend::CrosstermBackend;
|
||||||
@@ -287,14 +288,9 @@ fn create_cert(cert_path: &String, servarr_name: &str) -> Certificate {
|
|||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
fn panic_hook(info: &PanicHookInfo<'_>) {
|
fn panic_hook(info: &PanicHookInfo<'_>) {
|
||||||
use human_panic::{handle_dump, print_msg, Metadata};
|
use human_panic::{handle_dump, print_msg};
|
||||||
|
|
||||||
let meta = Metadata {
|
let meta = metadata!();
|
||||||
version: env!("CARGO_PKG_VERSION").into(),
|
|
||||||
name: env!("CARGO_PKG_NAME").into(),
|
|
||||||
authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(),
|
|
||||||
homepage: env!("CARGO_PKG_HOMEPAGE").into(),
|
|
||||||
};
|
|
||||||
let file_path = handle_dump(&meta, info);
|
let file_path = handle_dump(&meta, info);
|
||||||
disable_raw_mode().unwrap();
|
disable_raw_mode().unwrap();
|
||||||
execute!(io::stdout(), LeaveAlternateScreen).unwrap();
|
execute!(io::stdout(), LeaveAlternateScreen).unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user