fix(sonarr): Pass the download ID alongside all DeleteDownload events published to the networking channel
This commit is contained in:
@@ -101,7 +101,7 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrDeleteCommand> for SonarrDeleteComm
|
||||
SonarrDeleteCommand::Download { download_id } => {
|
||||
let resp = self
|
||||
.network
|
||||
.handle_network_event(SonarrEvent::DeleteDownload(Some(download_id)).into())
|
||||
.handle_network_event(SonarrEvent::DeleteDownload(download_id).into())
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ mod tests {
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(
|
||||
SonarrEvent::DeleteDownload(Some(expected_download_id)).into(),
|
||||
SonarrEvent::DeleteDownload(expected_download_id).into(),
|
||||
))
|
||||
.times(1)
|
||||
.returning(|_| {
|
||||
|
||||
@@ -512,19 +512,20 @@ mod tests {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_extract_blocklist_item_id() {
|
||||
let mut app = App::default();
|
||||
app.data.sonarr_data.blocklist.set_items(blocklist_vec());
|
||||
|
||||
|
||||
let blocklist_item_id = BlocklistHandler::with(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Blocklist,
|
||||
None,
|
||||
).extract_blocklist_item_id();
|
||||
|
||||
)
|
||||
.extract_blocklist_item_id();
|
||||
|
||||
assert_eq!(blocklist_item_id, 3);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,15 +28,9 @@ impl<'a, 'b> BlocklistHandler<'a, 'b> {
|
||||
self.app.data.sonarr_data.blocklist,
|
||||
BlocklistItem
|
||||
);
|
||||
|
||||
|
||||
fn extract_blocklist_item_id(&self) -> i64 {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.blocklist
|
||||
.current_selection()
|
||||
.id
|
||||
self.app.data.sonarr_data.blocklist.current_selection().id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,8 +102,9 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a,
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::DeleteBlocklistItemPrompt => {
|
||||
if self.app.data.sonarr_data.prompt_confirm {
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::DeleteBlocklistItem(self.extract_blocklist_item_id()));
|
||||
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteBlocklistItem(
|
||||
self.extract_blocklist_item_id(),
|
||||
));
|
||||
}
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
@@ -161,8 +156,9 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a,
|
||||
ActiveSonarrBlock::DeleteBlocklistItemPrompt => {
|
||||
if key == DEFAULT_KEYBINDINGS.confirm.key {
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::DeleteBlocklistItem(self.extract_blocklist_item_id()));
|
||||
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteBlocklistItem(
|
||||
self.extract_blocklist_item_id(),
|
||||
));
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::sonarr_handlers::downloads::DownloadsHandler;
|
||||
use crate::handlers::sonarr_handlers::sonarr_handler_test_utils::utils::download_record;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, DOWNLOADS_BLOCKS};
|
||||
use crate::models::sonarr_models::DownloadRecord;
|
||||
@@ -138,7 +140,7 @@ mod tests {
|
||||
#[case(
|
||||
ActiveSonarrBlock::Downloads,
|
||||
ActiveSonarrBlock::DeleteDownloadPrompt,
|
||||
SonarrEvent::DeleteDownload(None)
|
||||
SonarrEvent::DeleteDownload(1)
|
||||
)]
|
||||
#[case(
|
||||
ActiveSonarrBlock::Downloads,
|
||||
@@ -155,7 +157,7 @@ mod tests {
|
||||
.data
|
||||
.sonarr_data
|
||||
.downloads
|
||||
.set_items(vec![DownloadRecord::default()]);
|
||||
.set_items(vec![download_record()]);
|
||||
app.data.sonarr_data.prompt_confirm = true;
|
||||
app.push_navigation_stack(base_route.into());
|
||||
app.push_navigation_stack(prompt_block.into());
|
||||
@@ -338,7 +340,7 @@ mod tests {
|
||||
#[case(
|
||||
ActiveSonarrBlock::Downloads,
|
||||
ActiveSonarrBlock::DeleteDownloadPrompt,
|
||||
SonarrEvent::DeleteDownload(None)
|
||||
SonarrEvent::DeleteDownload(1)
|
||||
)]
|
||||
#[case(
|
||||
ActiveSonarrBlock::Downloads,
|
||||
@@ -355,7 +357,7 @@ mod tests {
|
||||
.data
|
||||
.sonarr_data
|
||||
.downloads
|
||||
.set_items(vec![DownloadRecord::default()]);
|
||||
.set_items(vec![download_record()]);
|
||||
app.push_navigation_stack(base_route.into());
|
||||
app.push_navigation_stack(prompt_block.into());
|
||||
|
||||
@@ -387,6 +389,26 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_download_id() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.downloads
|
||||
.set_items(vec![download_record()]);
|
||||
|
||||
let download_id = DownloadsHandler::with(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Downloads,
|
||||
None,
|
||||
)
|
||||
.extract_download_id();
|
||||
|
||||
assert_eq!(download_id, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_downloads_handler_not_ready_when_loading() {
|
||||
let mut app = App::default();
|
||||
|
||||
@@ -27,6 +27,10 @@ impl<'a, 'b> DownloadsHandler<'a, 'b> {
|
||||
self.app.data.sonarr_data.downloads,
|
||||
DownloadRecord
|
||||
);
|
||||
|
||||
fn extract_download_id(&self) -> i64 {
|
||||
self.app.data.sonarr_data.downloads.current_selection().id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DownloadsHandler<'a, 'b> {
|
||||
@@ -95,7 +99,8 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DownloadsHandler<'a,
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::DeleteDownloadPrompt => {
|
||||
if self.app.data.sonarr_data.prompt_confirm {
|
||||
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteDownload(None));
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::DeleteDownload(self.extract_download_id()));
|
||||
}
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
@@ -138,7 +143,8 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DownloadsHandler<'a,
|
||||
ActiveSonarrBlock::DeleteDownloadPrompt => {
|
||||
if key == DEFAULT_KEYBINDINGS.confirm.key {
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteDownload(None));
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::DeleteDownload(self.extract_download_id()));
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user