feat(cli): Support for fetching all Sonarr history events
This commit is contained in:
@@ -32,6 +32,11 @@ pub enum SonarrListCommand {
|
|||||||
)]
|
)]
|
||||||
series_id: i64,
|
series_id: i64,
|
||||||
},
|
},
|
||||||
|
#[command(about = "Fetch all Sonarr history events")]
|
||||||
|
History {
|
||||||
|
#[arg(long, help = "How many history events to fetch", default_value_t = 500)]
|
||||||
|
events: u64,
|
||||||
|
},
|
||||||
#[command(about = "List all Sonarr indexers")]
|
#[command(about = "List all Sonarr indexers")]
|
||||||
Indexers,
|
Indexers,
|
||||||
#[command(about = "Fetch Sonarr logs")]
|
#[command(about = "Fetch Sonarr logs")]
|
||||||
@@ -88,6 +93,9 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrListCommand> for SonarrListCommandH
|
|||||||
SonarrListCommand::Episodes { series_id } => {
|
SonarrListCommand::Episodes { series_id } => {
|
||||||
execute_network_event!(self, SonarrEvent::GetEpisodes(Some(series_id)));
|
execute_network_event!(self, SonarrEvent::GetEpisodes(Some(series_id)));
|
||||||
}
|
}
|
||||||
|
SonarrListCommand::History { events: items } => {
|
||||||
|
execute_network_event!(self, SonarrEvent::GetHistory(Some(items)));
|
||||||
|
}
|
||||||
SonarrListCommand::Indexers => {
|
SonarrListCommand::Indexers => {
|
||||||
execute_network_event!(self, SonarrEvent::GetIndexers);
|
execute_network_event!(self, SonarrEvent::GetIndexers);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,27 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_list_history_events_flag_requires_arguments() {
|
||||||
|
let result =
|
||||||
|
Cli::command().try_get_matches_from(["managarr", "sonarr", "list", "history", "--events"]);
|
||||||
|
|
||||||
|
assert!(result.is_err());
|
||||||
|
assert_eq!(result.unwrap_err().kind(), ErrorKind::InvalidValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_list_history_default_values() {
|
||||||
|
let expected_args = SonarrListCommand::History { events: 500 };
|
||||||
|
let result = Cli::try_parse_from(["managarr", "sonarr", "list", "history"]);
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
|
||||||
|
if let Some(Command::Sonarr(SonarrCommand::List(history_command))) = result.unwrap().command {
|
||||||
|
assert_eq!(history_command, expected_args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_list_logs_events_flag_requires_arguments() {
|
fn test_list_logs_events_flag_requires_arguments() {
|
||||||
let result =
|
let result =
|
||||||
@@ -69,8 +90,8 @@ mod tests {
|
|||||||
|
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
||||||
if let Some(Command::Sonarr(SonarrCommand::List(refresh_command))) = result.unwrap().command {
|
if let Some(Command::Sonarr(SonarrCommand::List(logs_command))) = result.unwrap().command {
|
||||||
assert_eq!(refresh_command, expected_args);
|
assert_eq!(logs_command, expected_args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +186,32 @@ mod tests {
|
|||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_list_history_command() {
|
||||||
|
let expected_events = 1000;
|
||||||
|
let mut mock_network = MockNetworkTrait::new();
|
||||||
|
mock_network
|
||||||
|
.expect_handle_network_event()
|
||||||
|
.with(eq::<NetworkEvent>(
|
||||||
|
SonarrEvent::GetHistory(Some(expected_events)).into(),
|
||||||
|
))
|
||||||
|
.times(1)
|
||||||
|
.returning(|_| {
|
||||||
|
Ok(Serdeable::Sonarr(SonarrSerdeable::Value(
|
||||||
|
json!({"testResponse": "response"}),
|
||||||
|
)))
|
||||||
|
});
|
||||||
|
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||||
|
let list_history_command = SonarrListCommand::History { events: 1000 };
|
||||||
|
|
||||||
|
let result =
|
||||||
|
SonarrListCommandHandler::with(&app_arc, list_history_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;
|
||||||
|
|||||||
@@ -108,8 +108,8 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.get_episode_details(episode_id)
|
.get_episode_details(episode_id)
|
||||||
.await
|
.await
|
||||||
.map(SonarrSerdeable::from),
|
.map(SonarrSerdeable::from),
|
||||||
SonarrEvent::GetHistory(items) => self
|
SonarrEvent::GetHistory(events) => self
|
||||||
.get_sonarr_history(items)
|
.get_sonarr_history(events)
|
||||||
.await
|
.await
|
||||||
.map(SonarrSerdeable::from),
|
.map(SonarrSerdeable::from),
|
||||||
SonarrEvent::GetHostConfig => self
|
SonarrEvent::GetHostConfig => self
|
||||||
@@ -467,13 +467,13 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_sonarr_history(&mut self, items: Option<u64>) -> Result<SonarrHistoryWrapper> {
|
async fn get_sonarr_history(&mut self, events: Option<u64>) -> Result<SonarrHistoryWrapper> {
|
||||||
info!("Fetching all Sonarr history events");
|
info!("Fetching all Sonarr history events");
|
||||||
let event = SonarrEvent::GetHistory(items);
|
let event = SonarrEvent::GetHistory(events);
|
||||||
|
|
||||||
let params = format!(
|
let params = format!(
|
||||||
"pageSize={}&sortDirection=descending&sortKey=time",
|
"pageSize={}&sortDirection=descending&sortKey=time",
|
||||||
items.unwrap_or(500)
|
events.unwrap_or(500)
|
||||||
);
|
);
|
||||||
let request_props = self
|
let request_props = self
|
||||||
.request_props_from(event, RequestMethod::Get, None::<()>, None, Some(params))
|
.request_props_from(event, RequestMethod::Get, None::<()>, None, Some(params))
|
||||||
|
|||||||
Reference in New Issue
Block a user