fix(sonarr): Pass the blocklist item ID alongside the DeleteBlocklistItem event when publishing to the networking channel

This commit is contained in:
2024-12-17 22:22:32 -07:00
parent 478b4ae3c0
commit 906e093152
7 changed files with 40 additions and 29 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrDeleteCommand> for SonarrDeleteComm
SonarrDeleteCommand::BlocklistItem { blocklist_item_id } => { SonarrDeleteCommand::BlocklistItem { blocklist_item_id } => {
let resp = self let resp = self
.network .network
.handle_network_event(SonarrEvent::DeleteBlocklistItem(Some(blocklist_item_id)).into()) .handle_network_event(SonarrEvent::DeleteBlocklistItem(blocklist_item_id).into())
.await?; .await?;
serde_json::to_string_pretty(&resp)? serde_json::to_string_pretty(&resp)?
} }
@@ -301,7 +301,7 @@ mod tests {
mock_network mock_network
.expect_handle_network_event() .expect_handle_network_event()
.with(eq::<NetworkEvent>( .with(eq::<NetworkEvent>(
SonarrEvent::DeleteBlocklistItem(Some(expected_blocklist_item_id)).into(), SonarrEvent::DeleteBlocklistItem(expected_blocklist_item_id).into(),
)) ))
.times(1) .times(1)
.returning(|_| { .returning(|_| {
+1 -1
View File
@@ -346,7 +346,7 @@ mod tests {
mock_network mock_network
.expect_handle_network_event() .expect_handle_network_event()
.with(eq::<NetworkEvent>( .with(eq::<NetworkEvent>(
SonarrEvent::DeleteBlocklistItem(Some(expected_blocklist_item_id)).into(), SonarrEvent::DeleteBlocklistItem(expected_blocklist_item_id).into(),
)) ))
.times(1) .times(1)
.returning(|_| { .returning(|_| {
@@ -161,7 +161,7 @@ mod tests {
#[case( #[case(
ActiveSonarrBlock::Blocklist, ActiveSonarrBlock::Blocklist,
ActiveSonarrBlock::DeleteBlocklistItemPrompt, ActiveSonarrBlock::DeleteBlocklistItemPrompt,
SonarrEvent::DeleteBlocklistItem(None) SonarrEvent::DeleteBlocklistItem(3)
)] )]
#[case( #[case(
ActiveSonarrBlock::Blocklist, ActiveSonarrBlock::Blocklist,
@@ -361,7 +361,7 @@ mod tests {
#[case( #[case(
ActiveSonarrBlock::Blocklist, ActiveSonarrBlock::Blocklist,
ActiveSonarrBlock::DeleteBlocklistItemPrompt, ActiveSonarrBlock::DeleteBlocklistItemPrompt,
SonarrEvent::DeleteBlocklistItem(None) SonarrEvent::DeleteBlocklistItem(3)
)] )]
#[case( #[case(
ActiveSonarrBlock::Blocklist, ActiveSonarrBlock::Blocklist,
@@ -513,6 +513,21 @@ 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();
assert_eq!(blocklist_item_id, 3);
}
#[test] #[test]
fn test_blocklist_handler_not_ready_when_loading() { fn test_blocklist_handler_not_ready_when_loading() {
let mut app = App::default(); let mut app = App::default();
+12 -2
View File
@@ -28,6 +28,16 @@ impl<'a, 'b> BlocklistHandler<'a, 'b> {
self.app.data.sonarr_data.blocklist, self.app.data.sonarr_data.blocklist,
BlocklistItem BlocklistItem
); );
fn extract_blocklist_item_id(&self) -> i64 {
self
.app
.data
.sonarr_data
.blocklist
.current_selection()
.id
}
} }
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a, 'b> { impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a, 'b> {
@@ -99,7 +109,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a,
ActiveSonarrBlock::DeleteBlocklistItemPrompt => { ActiveSonarrBlock::DeleteBlocklistItemPrompt => {
if self.app.data.sonarr_data.prompt_confirm { if self.app.data.sonarr_data.prompt_confirm {
self.app.data.sonarr_data.prompt_confirm_action = self.app.data.sonarr_data.prompt_confirm_action =
Some(SonarrEvent::DeleteBlocklistItem(None)); Some(SonarrEvent::DeleteBlocklistItem(self.extract_blocklist_item_id()));
} }
self.app.pop_navigation_stack(); self.app.pop_navigation_stack();
@@ -152,7 +162,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a,
if key == DEFAULT_KEYBINDINGS.confirm.key { if key == DEFAULT_KEYBINDINGS.confirm.key {
self.app.data.sonarr_data.prompt_confirm = true; self.app.data.sonarr_data.prompt_confirm = true;
self.app.data.sonarr_data.prompt_confirm_action = self.app.data.sonarr_data.prompt_confirm_action =
Some(SonarrEvent::DeleteBlocklistItem(None)); Some(SonarrEvent::DeleteBlocklistItem(self.extract_blocklist_item_id()));
self.app.pop_navigation_stack(); self.app.pop_navigation_stack();
} }
+5 -19
View File
@@ -42,7 +42,7 @@ pub enum SonarrEvent {
AddSeries(AddSeriesBody), AddSeries(AddSeriesBody),
AddTag(String), AddTag(String),
ClearBlocklist, ClearBlocklist,
DeleteBlocklistItem(Option<i64>), DeleteBlocklistItem(i64),
DeleteDownload(Option<i64>), DeleteDownload(Option<i64>),
DeleteEpisodeFile(Option<i64>), DeleteEpisodeFile(Option<i64>),
DeleteIndexer(Option<i64>), DeleteIndexer(Option<i64>),
@@ -459,30 +459,16 @@ impl<'a, 'b> Network<'a, 'b> {
.await .await
} }
async fn delete_sonarr_blocklist_item(&mut self, blocklist_item_id: Option<i64>) -> Result<()> { async fn delete_sonarr_blocklist_item(&mut self, blocklist_item_id: i64) -> Result<()> {
let event = SonarrEvent::DeleteBlocklistItem(None); let event = SonarrEvent::DeleteBlocklistItem(blocklist_item_id);
let id = if let Some(b_id) = blocklist_item_id { info!("Deleting Sonarr blocklist item for item with id: {blocklist_item_id}");
b_id
} else {
self
.app
.lock()
.await
.data
.sonarr_data
.blocklist
.current_selection()
.id
};
info!("Deleting Sonarr blocklist item for item with id: {id}");
let request_props = self let request_props = self
.request_props_from( .request_props_from(
event, event,
RequestMethod::Delete, RequestMethod::Delete,
None::<()>, None::<()>,
Some(format!("/{id}")), Some(format!("/{blocklist_item_id}")),
None, None,
) )
.await; .await;
+3 -3
View File
@@ -281,7 +281,7 @@ mod test {
#[rstest] #[rstest]
#[case(SonarrEvent::ClearBlocklist, "/blocklist/bulk")] #[case(SonarrEvent::ClearBlocklist, "/blocklist/bulk")]
#[case(SonarrEvent::DeleteBlocklistItem(None), "/blocklist")] #[case(SonarrEvent::DeleteBlocklistItem(0), "/blocklist")]
#[case(SonarrEvent::HealthCheck, "/health")] #[case(SonarrEvent::HealthCheck, "/health")]
#[case(SonarrEvent::GetBlocklist, "/blocklist?page=1&pageSize=10000")] #[case(SonarrEvent::GetBlocklist, "/blocklist?page=1&pageSize=10000")]
#[case(SonarrEvent::GetDiskSpace, "/diskspace")] #[case(SonarrEvent::GetDiskSpace, "/diskspace")]
@@ -540,7 +540,7 @@ mod test {
None, None,
None, None,
None, None,
SonarrEvent::DeleteBlocklistItem(None), SonarrEvent::DeleteBlocklistItem(1),
Some("/1"), Some("/1"),
None, None,
) )
@@ -555,7 +555,7 @@ mod test {
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new()); let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
assert!(network assert!(network
.handle_sonarr_event(SonarrEvent::DeleteBlocklistItem(None)) .handle_sonarr_event(SonarrEvent::DeleteBlocklistItem(1))
.await .await
.is_ok()); .is_ok());