fix(sonarr): Pass the download ID alongside all DeleteDownload events published to the networking channel

This commit is contained in:
2024-12-17 22:27:08 -07:00
parent 906e093152
commit 6c5a73f78f
8 changed files with 57 additions and 68 deletions
+5 -19
View File
@@ -43,7 +43,7 @@ pub enum SonarrEvent {
AddTag(String),
ClearBlocklist,
DeleteBlocklistItem(i64),
DeleteDownload(Option<i64>),
DeleteDownload(i64),
DeleteEpisodeFile(Option<i64>),
DeleteIndexer(Option<i64>),
DeleteRootFolder(Option<i64>),
@@ -514,30 +514,16 @@ impl<'a, 'b> Network<'a, 'b> {
.await
}
async fn delete_sonarr_download(&mut self, download_id: Option<i64>) -> Result<()> {
let event = SonarrEvent::DeleteDownload(None);
let id = if let Some(dl_id) = download_id {
dl_id
} else {
self
.app
.lock()
.await
.data
.sonarr_data
.downloads
.current_selection()
.id
};
info!("Deleting Sonarr download for download with id: {id}");
async fn delete_sonarr_download(&mut self, download_id: i64) -> Result<()> {
let event = SonarrEvent::DeleteDownload(download_id);
info!("Deleting Sonarr download for download with id: {download_id}");
let request_props = self
.request_props_from(
event,
RequestMethod::Delete,
None::<()>,
Some(format!("/{id}")),
Some(format!("/{download_id}")),
None,
)
.await;
+3 -25
View File
@@ -240,7 +240,7 @@ mod test {
#[rstest]
fn test_resource_queue(
#[values(SonarrEvent::GetDownloads, SonarrEvent::DeleteDownload(None))] event: SonarrEvent,
#[values(SonarrEvent::GetDownloads, SonarrEvent::DeleteDownload(0))] event: SonarrEvent,
) {
assert_str_eq!(event.resource(), "/queue");
}
@@ -646,7 +646,7 @@ mod test {
None,
None,
None,
SonarrEvent::DeleteDownload(None),
SonarrEvent::DeleteDownload(1),
Some("/1"),
None,
)
@@ -661,29 +661,7 @@ mod test {
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
assert!(network
.handle_sonarr_event(SonarrEvent::DeleteDownload(None))
.await
.is_ok());
async_server.assert_async().await;
}
#[tokio::test]
async fn test_handle_delete_sonarr_download_event_uses_provided_id() {
let (async_server, app_arc, _server) = mock_servarr_api(
RequestMethod::Delete,
None,
None,
None,
SonarrEvent::DeleteDownload(None),
Some("/1"),
None,
)
.await;
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
assert!(network
.handle_sonarr_event(SonarrEvent::DeleteDownload(Some(1)))
.handle_sonarr_event(SonarrEvent::DeleteDownload(1))
.await
.is_ok());