feat(network): Support for marking a Sonarr history item as failed
This commit is contained in:
@@ -114,8 +114,8 @@ pub enum ActiveSonarrBlock {
|
||||
ManualSeasonSearch,
|
||||
ManualSeasonSearchConfirmPrompt,
|
||||
ManualSeasonSearchSortPrompt,
|
||||
MarkHistoryItemAsFailureConfirmPrompt,
|
||||
MarkHistoryItemAsFailurePrompt,
|
||||
MarkHistoryItemAsFailedConfirmPrompt,
|
||||
MarkHistoryItemAsFailedPrompt,
|
||||
RootFolders,
|
||||
SearchEpisodes,
|
||||
SearchEpisodesError,
|
||||
|
||||
@@ -62,6 +62,7 @@ pub enum SonarrEvent {
|
||||
GetTags,
|
||||
HealthCheck,
|
||||
ListSeries,
|
||||
MarkHistoryItemAsFailed(i64),
|
||||
}
|
||||
|
||||
impl NetworkResource for SonarrEvent {
|
||||
@@ -89,6 +90,7 @@ impl NetworkResource for SonarrEvent {
|
||||
SonarrEvent::GetStatus => "/system/status",
|
||||
SonarrEvent::HealthCheck => "/health",
|
||||
SonarrEvent::ListSeries | SonarrEvent::GetSeriesDetails(_) => "/series",
|
||||
SonarrEvent::MarkHistoryItemAsFailed(_) => "/history/failed",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,6 +207,10 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.await
|
||||
.map(SonarrSerdeable::from),
|
||||
SonarrEvent::ListSeries => self.list_series().await.map(SonarrSerdeable::from),
|
||||
SonarrEvent::MarkHistoryItemAsFailed(history_item_id) => self
|
||||
.mark_sonarr_history_item_as_failed(history_item_id)
|
||||
.await
|
||||
.map(SonarrSerdeable::from),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1150,6 +1156,25 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn mark_sonarr_history_item_as_failed(&mut self, history_item_id: i64) -> Result<Value> {
|
||||
info!("Marking the Sonarr history item with ID: {history_item_id} as 'failed'");
|
||||
let event = SonarrEvent::MarkHistoryItemAsFailed(history_item_id);
|
||||
|
||||
let request_props = self
|
||||
.request_props_from(
|
||||
event,
|
||||
RequestMethod::Post,
|
||||
None,
|
||||
Some(format!("/{history_item_id}")),
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
|
||||
self
|
||||
.handle_request::<(), Value>(request_props, |_, _| ())
|
||||
.await
|
||||
}
|
||||
|
||||
async fn extract_series_id(&mut self, series_id: Option<i64>) -> (i64, String) {
|
||||
let series_id = if let Some(id) = series_id {
|
||||
id
|
||||
|
||||
@@ -217,6 +217,7 @@ mod test {
|
||||
#[case(SonarrEvent::GetLogs(Some(500)), "/log")]
|
||||
#[case(SonarrEvent::GetQualityProfiles, "/qualityprofile")]
|
||||
#[case(SonarrEvent::GetStatus, "/system/status")]
|
||||
#[case(SonarrEvent::MarkHistoryItemAsFailed(0), "/history/failed")]
|
||||
fn test_resource(#[case] event: SonarrEvent, #[case] expected_uri: String) {
|
||||
assert_str_eq!(event.resource(), expected_uri);
|
||||
}
|
||||
@@ -3674,6 +3675,30 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_mark_sonarr_history_item_as_failed_event() {
|
||||
let expected_history_item_id = 1;
|
||||
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||
RequestMethod::Post,
|
||||
None,
|
||||
Some(json!({})),
|
||||
None,
|
||||
SonarrEvent::MarkHistoryItemAsFailed(expected_history_item_id),
|
||||
Some("/1"),
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert!(network
|
||||
.handle_sonarr_event(SonarrEvent::MarkHistoryItemAsFailed(
|
||||
expected_history_item_id
|
||||
))
|
||||
.await
|
||||
.is_ok());
|
||||
async_server.assert_async().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_series_id() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
|
||||
Reference in New Issue
Block a user