fix(sonarr): Pass the indexer ID alongside all DeleteIndexer events when publishing to the networking channel
This commit is contained in:
@@ -115,7 +115,7 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrDeleteCommand> for SonarrDeleteComm
|
||||
SonarrDeleteCommand::Indexer { indexer_id } => {
|
||||
let resp = self
|
||||
.network
|
||||
.handle_network_event(SonarrEvent::DeleteIndexer(Some(indexer_id)).into())
|
||||
.handle_network_event(SonarrEvent::DeleteIndexer(indexer_id).into())
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
|
||||
@@ -367,17 +367,12 @@ mod tests {
|
||||
)))
|
||||
});
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
let delete_episode_file_command = SonarrDeleteCommand::EpisodeFile {
|
||||
episode_file_id: 1,
|
||||
};
|
||||
let delete_episode_file_command = SonarrDeleteCommand::EpisodeFile { episode_file_id: 1 };
|
||||
|
||||
let result = SonarrDeleteCommandHandler::with(
|
||||
&app_arc,
|
||||
delete_episode_file_command,
|
||||
&mut mock_network,
|
||||
)
|
||||
.handle()
|
||||
.await;
|
||||
let result =
|
||||
SonarrDeleteCommandHandler::with(&app_arc, delete_episode_file_command, &mut mock_network)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
@@ -389,7 +384,7 @@ mod tests {
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(
|
||||
SonarrEvent::DeleteIndexer(Some(expected_indexer_id)).into(),
|
||||
SonarrEvent::DeleteIndexer(expected_indexer_id).into(),
|
||||
))
|
||||
.times(1)
|
||||
.returning(|_| {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
@@ -7,6 +8,7 @@ mod tests {
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::sonarr_handlers::indexers::IndexersHandler;
|
||||
use crate::handlers::sonarr_handlers::sonarr_handler_test_utils::utils::indexer;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||
ActiveSonarrBlock, EDIT_INDEXER_BLOCKS, INDEXERS_BLOCKS, INDEXER_SETTINGS_BLOCKS,
|
||||
@@ -245,11 +247,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_delete_indexer_prompt_confirm_submit() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexers
|
||||
.set_items(vec![Indexer::default()]);
|
||||
app.data.sonarr_data.indexers.set_items(vec![indexer()]);
|
||||
app.data.sonarr_data.prompt_confirm = true;
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Indexers.into());
|
||||
app.push_navigation_stack(ActiveSonarrBlock::DeleteIndexerPrompt.into());
|
||||
@@ -265,7 +263,7 @@ mod tests {
|
||||
assert!(app.data.sonarr_data.prompt_confirm);
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.prompt_confirm_action,
|
||||
Some(SonarrEvent::DeleteIndexer(None))
|
||||
Some(SonarrEvent::DeleteIndexer(1))
|
||||
);
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Indexers.into());
|
||||
}
|
||||
@@ -556,11 +554,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_delete_indexer_prompt_confirm() {
|
||||
let mut app = App::default();
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexers
|
||||
.set_items(vec![Indexer::default()]);
|
||||
app.data.sonarr_data.indexers.set_items(vec![indexer()]);
|
||||
app.push_navigation_stack(ActiveSonarrBlock::Indexers.into());
|
||||
app.push_navigation_stack(ActiveSonarrBlock::DeleteIndexerPrompt.into());
|
||||
|
||||
@@ -575,7 +569,7 @@ mod tests {
|
||||
assert!(app.data.sonarr_data.prompt_confirm);
|
||||
assert_eq!(
|
||||
app.data.sonarr_data.prompt_confirm_action,
|
||||
Some(SonarrEvent::DeleteIndexer(None))
|
||||
Some(SonarrEvent::DeleteIndexer(1))
|
||||
);
|
||||
assert_eq!(app.get_current_route(), ActiveSonarrBlock::Indexers.into());
|
||||
}
|
||||
@@ -649,6 +643,22 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_indexer_id() {
|
||||
let mut app = App::default();
|
||||
app.data.sonarr_data.indexers.set_items(vec![indexer()]);
|
||||
|
||||
let indexer_id = IndexersHandler::with(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::Indexers,
|
||||
None,
|
||||
)
|
||||
.extract_indexer_id();
|
||||
|
||||
assert_eq!(indexer_id, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_indexers_handler_not_ready_when_loading() {
|
||||
let mut app = App::default();
|
||||
|
||||
@@ -33,6 +33,10 @@ pub(super) struct IndexersHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> IndexersHandler<'a, 'b> {
|
||||
handle_table_events!(self, indexers, self.app.data.sonarr_data.indexers, Indexer);
|
||||
|
||||
fn extract_indexer_id(&self) -> i64 {
|
||||
self.app.data.sonarr_data.indexers.current_selection().id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for IndexersHandler<'a, 'b> {
|
||||
@@ -115,9 +119,9 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for IndexersHandler<'a,
|
||||
fn handle_submit(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::DeleteIndexerPrompt => {
|
||||
let sonarr_data = &mut self.app.data.sonarr_data;
|
||||
if sonarr_data.prompt_confirm {
|
||||
sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteIndexer(None));
|
||||
if self.app.data.sonarr_data.prompt_confirm {
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::DeleteIndexer(self.extract_indexer_id()));
|
||||
}
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
@@ -189,7 +193,8 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for IndexersHandler<'a,
|
||||
ActiveSonarrBlock::DeleteIndexerPrompt => {
|
||||
if key == DEFAULT_KEYBINDINGS.confirm.key {
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteIndexer(None));
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::DeleteIndexer(self.extract_indexer_id()));
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ impl<'a, 'b> SeasonDetailsHandler<'a, 'b> {
|
||||
.season_releases,
|
||||
SonarrRelease
|
||||
);
|
||||
|
||||
|
||||
fn extract_episode_file_id(&self) -> i64 {
|
||||
self
|
||||
.app
|
||||
@@ -246,8 +246,9 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeasonDetailsHandler
|
||||
.push_navigation_stack(ActiveSonarrBlock::SeasonHistoryDetails.into()),
|
||||
ActiveSonarrBlock::DeleteEpisodeFilePrompt => {
|
||||
if self.app.data.sonarr_data.prompt_confirm {
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::DeleteEpisodeFile(self.extract_episode_file_id()));
|
||||
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteEpisodeFile(
|
||||
self.extract_episode_file_id(),
|
||||
));
|
||||
}
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
@@ -386,8 +387,9 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeasonDetailsHandler
|
||||
}
|
||||
ActiveSonarrBlock::DeleteEpisodeFilePrompt if key == DEFAULT_KEYBINDINGS.confirm.key => {
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::DeleteEpisodeFile(self.extract_episode_file_id()));
|
||||
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::DeleteEpisodeFile(
|
||||
self.extract_episode_file_id(),
|
||||
));
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ mod tests {
|
||||
use crate::models::servarr_models::{Language, Quality, QualityWrapper};
|
||||
use crate::models::sonarr_models::{SonarrRelease, SonarrReleaseDownloadBody};
|
||||
use crate::models::HorizontallyScrollableText;
|
||||
use pretty_assertions::{assert_str_eq, assert_eq};
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
use rstest::rstest;
|
||||
use serde_json::Number;
|
||||
use std::cmp::Ordering;
|
||||
@@ -782,19 +782,20 @@ mod tests {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_extract_episode_file_id() {
|
||||
let mut app = App::default();
|
||||
app.data.sonarr_data = create_test_sonarr_data();
|
||||
|
||||
|
||||
let episode_file_id = SeasonDetailsHandler::with(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::SeasonDetails,
|
||||
None,
|
||||
).extract_episode_file_id();
|
||||
|
||||
)
|
||||
.extract_episode_file_id();
|
||||
|
||||
assert_eq!(episode_file_id, 0);
|
||||
}
|
||||
|
||||
@@ -803,12 +804,13 @@ mod tests {
|
||||
fn test_extract_episode_file_id_empty_season_details_modal_panics() {
|
||||
let mut app = App::default();
|
||||
|
||||
let episode_file_id = SeasonDetailsHandler::with(
|
||||
SeasonDetailsHandler::with(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
&mut app,
|
||||
ActiveSonarrBlock::SeasonDetails,
|
||||
None,
|
||||
).extract_episode_file_id();
|
||||
)
|
||||
.extract_episode_file_id();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -45,7 +45,7 @@ pub enum SonarrEvent {
|
||||
DeleteBlocklistItem(i64),
|
||||
DeleteDownload(i64),
|
||||
DeleteEpisodeFile(i64),
|
||||
DeleteIndexer(Option<i64>),
|
||||
DeleteIndexer(i64),
|
||||
DeleteRootFolder(Option<i64>),
|
||||
DeleteSeries(Option<DeleteSeriesParams>),
|
||||
DeleteTag(i64),
|
||||
@@ -516,30 +516,16 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn delete_sonarr_indexer(&mut self, indexer_id: Option<i64>) -> Result<()> {
|
||||
let event = SonarrEvent::DeleteIndexer(None);
|
||||
let id = if let Some(i_id) = indexer_id {
|
||||
i_id
|
||||
} else {
|
||||
self
|
||||
.app
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexers
|
||||
.current_selection()
|
||||
.id
|
||||
};
|
||||
|
||||
info!("Deleting Sonarr indexer for indexer with id: {id}");
|
||||
async fn delete_sonarr_indexer(&mut self, indexer_id: i64) -> Result<()> {
|
||||
let event = SonarrEvent::DeleteIndexer(indexer_id);
|
||||
info!("Deleting Sonarr indexer for indexer with id: {indexer_id}");
|
||||
|
||||
let request_props = self
|
||||
.request_props_from(
|
||||
event,
|
||||
RequestMethod::Delete,
|
||||
None::<()>,
|
||||
Some(format!("/{id}")),
|
||||
Some(format!("/{indexer_id}")),
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -211,7 +211,7 @@ mod test {
|
||||
fn test_resource_indexer(
|
||||
#[values(
|
||||
SonarrEvent::GetIndexers,
|
||||
SonarrEvent::DeleteIndexer(None),
|
||||
SonarrEvent::DeleteIndexer(0),
|
||||
SonarrEvent::EditIndexer(None)
|
||||
)]
|
||||
event: SonarrEvent,
|
||||
@@ -270,10 +270,7 @@ mod test {
|
||||
|
||||
#[rstest]
|
||||
fn test_resource_episode_file(
|
||||
#[values(
|
||||
SonarrEvent::GetEpisodeFiles(None),
|
||||
SonarrEvent::DeleteEpisodeFile(0)
|
||||
)]
|
||||
#[values(SonarrEvent::GetEpisodeFiles(None), SonarrEvent::DeleteEpisodeFile(0))]
|
||||
event: SonarrEvent,
|
||||
) {
|
||||
assert_str_eq!(event.resource(), "/episodefile");
|
||||
@@ -622,7 +619,7 @@ mod test {
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
SonarrEvent::DeleteIndexer(None),
|
||||
SonarrEvent::DeleteIndexer(1),
|
||||
Some("/1"),
|
||||
None,
|
||||
)
|
||||
@@ -637,29 +634,7 @@ mod test {
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert!(network
|
||||
.handle_sonarr_event(SonarrEvent::DeleteIndexer(None))
|
||||
.await
|
||||
.is_ok());
|
||||
|
||||
async_server.assert_async().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_delete_sonarr_indexer_event_uses_provided_id() {
|
||||
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||
RequestMethod::Delete,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
SonarrEvent::DeleteIndexer(None),
|
||||
Some("/1"),
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert!(network
|
||||
.handle_sonarr_event(SonarrEvent::DeleteIndexer(Some(1)))
|
||||
.handle_sonarr_event(SonarrEvent::DeleteIndexer(1))
|
||||
.await
|
||||
.is_ok());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user