fix(sonarr): Pass the episode file ID alongside all DeleteEpisodeFile events when publishing to the networking channel

This commit is contained in:
2024-12-17 22:33:10 -07:00
parent 6c5a73f78f
commit aece20af47
6 changed files with 86 additions and 84 deletions
+5 -22
View File
@@ -44,7 +44,7 @@ pub enum SonarrEvent {
ClearBlocklist,
DeleteBlocklistItem(i64),
DeleteDownload(i64),
DeleteEpisodeFile(Option<i64>),
DeleteEpisodeFile(i64),
DeleteIndexer(Option<i64>),
DeleteRootFolder(Option<i64>),
DeleteSeries(Option<DeleteSeriesParams>),
@@ -478,33 +478,16 @@ impl<'a, 'b> Network<'a, 'b> {
.await
}
async fn delete_sonarr_episode_file(&mut self, episode_file_id: Option<i64>) -> Result<()> {
let event = SonarrEvent::DeleteEpisodeFile(None);
let id = if let Some(ep_id) = episode_file_id {
ep_id
} else {
self
.app
.lock()
.await
.data
.sonarr_data
.season_details_modal
.as_ref()
.expect("Season details have not been loaded")
.episodes
.current_selection()
.episode_file_id
};
info!("Deleting Sonarr episode file for episode file with id: {id}");
async fn delete_sonarr_episode_file(&mut self, episode_file_id: i64) -> Result<()> {
let event = SonarrEvent::DeleteEpisodeFile(episode_file_id);
info!("Deleting Sonarr episode file for episode file with id: {episode_file_id}");
let request_props = self
.request_props_from(
event,
RequestMethod::Delete,
None::<()>,
Some(format!("/{id}")),
Some(format!("/{episode_file_id}")),
None,
)
.await;
+3 -56
View File
@@ -272,7 +272,7 @@ mod test {
fn test_resource_episode_file(
#[values(
SonarrEvent::GetEpisodeFiles(None),
SonarrEvent::DeleteEpisodeFile(None)
SonarrEvent::DeleteEpisodeFile(0)
)]
event: SonarrEvent,
) {
@@ -569,76 +569,23 @@ mod test {
None,
None,
None,
SonarrEvent::DeleteEpisodeFile(None),
SonarrEvent::DeleteEpisodeFile(1),
Some("/1"),
None,
)
.await;
app_arc.lock().await.data.sonarr_data.season_details_modal =
Some(SeasonDetailsModal::default());
app_arc
.lock()
.await
.data
.sonarr_data
.season_details_modal
.as_mut()
.unwrap()
.episodes
.set_items(vec![episode()]);
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
assert!(network
.handle_sonarr_event(SonarrEvent::DeleteEpisodeFile(None))
.handle_sonarr_event(SonarrEvent::DeleteEpisodeFile(1))
.await
.is_ok());
async_server.assert_async().await;
}
#[tokio::test]
async fn test_handle_delete_sonarr_episode_file_event_uses_provided_id() {
let (async_server, app_arc, _server) = mock_servarr_api(
RequestMethod::Delete,
None,
None,
None,
SonarrEvent::DeleteEpisodeFile(None),
Some("/1"),
None,
)
.await;
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
assert!(network
.handle_sonarr_event(SonarrEvent::DeleteEpisodeFile(Some(1)))
.await
.is_ok());
async_server.assert_async().await;
}
#[tokio::test]
#[should_panic(expected = "Season details have not been loaded")]
async fn test_handle_delete_sonarr_episode_file_event_empty_season_details_modal_panics() {
let (_async_server, app_arc, _server) = mock_servarr_api(
RequestMethod::Delete,
None,
None,
None,
SonarrEvent::DeleteEpisodeFile(None),
Some("/1"),
None,
)
.await;
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
network
.handle_sonarr_event(SonarrEvent::DeleteEpisodeFile(None))
.await
.unwrap();
}
#[tokio::test]
async fn test_handle_delete_sonarr_download_event() {
let (async_server, app_arc, _server) = mock_servarr_api(