fix: Blocklist Item ID passed in the DeleteBlocklistItem event when sent to the networking channel

This commit is contained in:
2024-12-17 15:03:06 -07:00
parent 1d1e42aeb1
commit a308b8fe95
7 changed files with 42 additions and 59 deletions
+1 -1
View File
@@ -89,7 +89,7 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, RadarrDeleteCommand> for RadarrDeleteComm
RadarrDeleteCommand::BlocklistItem { blocklist_item_id } => {
let resp = self
.network
.handle_network_event(RadarrEvent::DeleteBlocklistItem(Some(blocklist_item_id)).into())
.handle_network_event(RadarrEvent::DeleteBlocklistItem(blocklist_item_id).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
@@ -268,7 +268,7 @@ mod tests {
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
RadarrEvent::DeleteBlocklistItem(Some(expected_blocklist_item_id)).into(),
RadarrEvent::DeleteBlocklistItem(expected_blocklist_item_id).into(),
))
.times(1)
.returning(|_| {
+3 -3
View File
@@ -293,9 +293,9 @@ mod tests {
)))
});
let app_arc = Arc::new(Mutex::new(App::default()));
let claer_blocklist_command = RadarrCommand::ClearBlocklist;
let clear_blocklist_command = RadarrCommand::ClearBlocklist;
let result = RadarrCliHandler::with(&app_arc, claer_blocklist_command, &mut mock_network)
let result = RadarrCliHandler::with(&app_arc, clear_blocklist_command, &mut mock_network)
.handle()
.await;
@@ -524,7 +524,7 @@ mod tests {
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
RadarrEvent::DeleteBlocklistItem(Some(expected_blocklist_item_id)).into(),
RadarrEvent::DeleteBlocklistItem(expected_blocklist_item_id).into(),
))
.times(1)
.returning(|_| {
@@ -160,7 +160,7 @@ mod tests {
#[case(
ActiveRadarrBlock::Blocklist,
ActiveRadarrBlock::DeleteBlocklistItemPrompt,
RadarrEvent::DeleteBlocklistItem(None)
RadarrEvent::DeleteBlocklistItem(3)
)]
#[case(
ActiveRadarrBlock::Blocklist,
@@ -361,7 +361,7 @@ mod tests {
#[case(
ActiveRadarrBlock::Blocklist,
ActiveRadarrBlock::DeleteBlocklistItemPrompt,
RadarrEvent::DeleteBlocklistItem(None)
RadarrEvent::DeleteBlocklistItem(3)
)]
#[case(
ActiveRadarrBlock::Blocklist,
@@ -540,6 +540,21 @@ mod tests {
}
})
}
#[test]
fn test_extract_blocklist_item_id() {
let mut app = App::default();
app.data.radarr_data.blocklist.set_items(blocklist_vec());
let blocklist_item_id = BlocklistHandler::with(
DEFAULT_KEYBINDINGS.esc.key,
&mut app,
ActiveRadarrBlock::Blocklist,
None,
).extract_blocklist_item_id();
assert_eq!(blocklist_item_id, 3);
}
#[test]
fn test_blocklist_handler_not_ready_when_loading() {
+12 -2
View File
@@ -28,6 +28,16 @@ impl<'a, 'b> BlocklistHandler<'a, 'b> {
self.app.data.radarr_data.blocklist,
BlocklistItem
);
fn extract_blocklist_item_id(&self) -> i64 {
self
.app
.data
.radarr_data
.blocklist
.current_selection()
.id
}
}
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for BlocklistHandler<'a, 'b> {
@@ -99,7 +109,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for BlocklistHandler<'a,
ActiveRadarrBlock::DeleteBlocklistItemPrompt => {
if self.app.data.radarr_data.prompt_confirm {
self.app.data.radarr_data.prompt_confirm_action =
Some(RadarrEvent::DeleteBlocklistItem(None));
Some(RadarrEvent::DeleteBlocklistItem(self.extract_blocklist_item_id()));
}
self.app.pop_navigation_stack();
@@ -152,7 +162,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for BlocklistHandler<'a,
if key == DEFAULT_KEYBINDINGS.confirm.key {
self.app.data.radarr_data.prompt_confirm = true;
self.app.data.radarr_data.prompt_confirm_action =
Some(RadarrEvent::DeleteBlocklistItem(None));
Some(RadarrEvent::DeleteBlocklistItem(self.extract_blocklist_item_id()));
self.app.pop_navigation_stack();
}
+5 -18
View File
@@ -39,7 +39,7 @@ pub enum RadarrEvent {
AddRootFolder(AddRootFolderBody),
AddTag(String),
ClearBlocklist,
DeleteBlocklistItem(Option<i64>),
DeleteBlocklistItem(i64),
DeleteDownload(Option<i64>),
DeleteIndexer(Option<i64>),
DeleteMovie(Option<DeleteMovieParams>),
@@ -387,30 +387,17 @@ impl<'a, 'b> Network<'a, 'b> {
.await
}
async fn delete_radarr_blocklist_item(&mut self, blocklist_item_id: Option<i64>) -> Result<()> {
let event = RadarrEvent::DeleteBlocklistItem(None);
let id = if let Some(b_id) = blocklist_item_id {
b_id
} else {
self
.app
.lock()
.await
.data
.radarr_data
.blocklist
.current_selection()
.id
};
async fn delete_radarr_blocklist_item(&mut self, blocklist_item_id: i64) -> Result<()> {
let event = RadarrEvent::DeleteBlocklistItem(blocklist_item_id);
info!("Deleting Radarr blocklist item for item with id: {id}");
info!("Deleting Radarr blocklist item for item with id: {blocklist_item_id}");
let request_props = self
.request_props_from(
event,
RequestMethod::Delete,
None::<()>,
Some(format!("/{id}")),
Some(format!("/{blocklist_item_id}")),
None,
)
.await;
+3 -32
View File
@@ -217,7 +217,7 @@ mod test {
#[rstest]
#[case(RadarrEvent::ClearBlocklist, "/blocklist/bulk")]
#[case(RadarrEvent::DeleteBlocklistItem(None), "/blocklist")]
#[case(RadarrEvent::DeleteBlocklistItem(1), "/blocklist")]
#[case(RadarrEvent::GetBlocklist, "/blocklist?page=1&pageSize=10000")]
#[case(RadarrEvent::GetLogs(Some(500)), "/log")]
#[case(RadarrEvent::SearchNewMovie(None), "/movie/lookup")]
@@ -3199,36 +3199,7 @@ mod test {
None,
None,
None,
RadarrEvent::DeleteBlocklistItem(None),
Some("/1"),
None,
)
.await;
app_arc
.lock()
.await
.data
.radarr_data
.blocklist
.set_items(vec![blocklist_item()]);
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
assert!(network
.handle_radarr_event(RadarrEvent::DeleteBlocklistItem(None))
.await
.is_ok());
async_server.assert_async().await;
}
#[tokio::test]
async fn test_handle_delete_blocklist_item_event_uses_provided_id() {
let (async_server, app_arc, _server) = mock_servarr_api(
RequestMethod::Delete,
None,
None,
None,
RadarrEvent::DeleteBlocklistItem(None),
RadarrEvent::DeleteBlocklistItem(1),
Some("/1"),
None,
)
@@ -3236,7 +3207,7 @@ mod test {
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
assert!(network
.handle_radarr_event(RadarrEvent::DeleteBlocklistItem(Some(1)))
.handle_radarr_event(RadarrEvent::DeleteBlocklistItem(1))
.await
.is_ok());