feat(readarr): mark a history item as failed and expose the command on the CLI
This commit is contained in:
6 files changed
+146
No files matched your search
@@ -8,6 +8,7 @@ use edit_command_handler::{ReadarrEditCommand, ReadarrEditCommandHandler};
|
|||||||
use get_command_handler::{ReadarrGetCommand, ReadarrGetCommandHandler};
|
use get_command_handler::{ReadarrGetCommand, ReadarrGetCommandHandler};
|
||||||
use list_command_handler::{ReadarrListCommand, ReadarrListCommandHandler};
|
use list_command_handler::{ReadarrListCommand, ReadarrListCommandHandler};
|
||||||
use refresh_command_handler::{ReadarrRefreshCommand, ReadarrRefreshCommandHandler};
|
use refresh_command_handler::{ReadarrRefreshCommand, ReadarrRefreshCommandHandler};
|
||||||
|
use serde_json::json;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use trigger_automatic_search_command_handler::{
|
use trigger_automatic_search_command_handler::{
|
||||||
ReadarrTriggerAutomaticSearchCommand, ReadarrTriggerAutomaticSearchCommandHandler,
|
ReadarrTriggerAutomaticSearchCommand, ReadarrTriggerAutomaticSearchCommandHandler,
|
||||||
@@ -67,6 +68,15 @@ pub enum ReadarrCommand {
|
|||||||
about = "Commands to trigger automatic searches for releases of different resources in your Readarr instance"
|
about = "Commands to trigger automatic searches for releases of different resources in your Readarr instance"
|
||||||
)]
|
)]
|
||||||
TriggerAutomaticSearch(ReadarrTriggerAutomaticSearchCommand),
|
TriggerAutomaticSearch(ReadarrTriggerAutomaticSearchCommand),
|
||||||
|
#[command(about = "Mark the Readarr history item with the given ID as 'failed'")]
|
||||||
|
MarkHistoryItemAsFailed {
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
help = "The Readarr ID of the history item you wish to mark as 'failed'",
|
||||||
|
required = true
|
||||||
|
)]
|
||||||
|
history_item_id: i64,
|
||||||
|
},
|
||||||
#[command(about = "Search for a new author to add to Readarr")]
|
#[command(about = "Search for a new author to add to Readarr")]
|
||||||
SearchNewAuthor {
|
SearchNewAuthor {
|
||||||
#[arg(
|
#[arg(
|
||||||
@@ -174,6 +184,15 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrCommand> for ReadarrCliHandler<'a,
|
|||||||
.handle()
|
.handle()
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
|
ReadarrCommand::MarkHistoryItemAsFailed { history_item_id } => {
|
||||||
|
let _ = self
|
||||||
|
.network
|
||||||
|
.handle_network_event(ReadarrEvent::MarkHistoryItemAsFailed(history_item_id).into())
|
||||||
|
.await?;
|
||||||
|
serde_json::to_string_pretty(
|
||||||
|
&json!({"message": "Readarr history item marked as 'failed'"}),
|
||||||
|
)?
|
||||||
|
}
|
||||||
ReadarrCommand::SearchNewAuthor { query } => {
|
ReadarrCommand::SearchNewAuthor { query } => {
|
||||||
let resp = self
|
let resp = self
|
||||||
.network
|
.network
|
||||||
|
|||||||
@@ -14,6 +14,31 @@ mod tests {
|
|||||||
assert_err!(&result);
|
assert_err!(&result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_mark_history_item_as_failed_requires_history_item_id() {
|
||||||
|
let result =
|
||||||
|
Cli::command().try_get_matches_from(["managarr", "readarr", "mark-history-item-as-failed"]);
|
||||||
|
|
||||||
|
assert_err!(&result);
|
||||||
|
assert_eq!(
|
||||||
|
result.unwrap_err().kind(),
|
||||||
|
ErrorKind::MissingRequiredArgument
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_mark_history_item_as_failed_requirements_satisfied() {
|
||||||
|
let result = Cli::command().try_get_matches_from([
|
||||||
|
"managarr",
|
||||||
|
"readarr",
|
||||||
|
"mark-history-item-as-failed",
|
||||||
|
"--history-item-id",
|
||||||
|
"1234",
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert_ok!(&result);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_search_new_author_requires_query() {
|
fn test_search_new_author_requires_query() {
|
||||||
let result =
|
let result =
|
||||||
@@ -146,6 +171,37 @@ mod tests {
|
|||||||
network::{MockNetworkTrait, NetworkEvent, readarr_network::ReadarrEvent},
|
network::{MockNetworkTrait, NetworkEvent, readarr_network::ReadarrEvent},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_mark_history_item_as_failed_command() {
|
||||||
|
let expected_history_item_id = 1234i64;
|
||||||
|
let mut mock_network = MockNetworkTrait::new();
|
||||||
|
mock_network
|
||||||
|
.expect_handle_network_event()
|
||||||
|
.with(eq::<NetworkEvent>(
|
||||||
|
ReadarrEvent::MarkHistoryItemAsFailed(expected_history_item_id).into(),
|
||||||
|
))
|
||||||
|
.times(1)
|
||||||
|
.returning(|_| {
|
||||||
|
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
|
||||||
|
json!({"testResponse": "response"}),
|
||||||
|
)))
|
||||||
|
});
|
||||||
|
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
||||||
|
let mark_history_item_as_failed_command = ReadarrCommand::MarkHistoryItemAsFailed {
|
||||||
|
history_item_id: expected_history_item_id,
|
||||||
|
};
|
||||||
|
|
||||||
|
let result = ReadarrCliHandler::with(
|
||||||
|
&app_arc,
|
||||||
|
mark_history_item_as_failed_command,
|
||||||
|
&mut mock_network,
|
||||||
|
)
|
||||||
|
.handle()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
assert_ok!(&result);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_search_new_author_command() {
|
async fn test_search_new_author_command() {
|
||||||
let expected_query = "test author".to_owned();
|
let expected_query = "test author".to_owned();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
use crate::models::Route;
|
use crate::models::Route;
|
||||||
use crate::models::readarr_models::ReadarrHistoryWrapper;
|
use crate::models::readarr_models::ReadarrHistoryWrapper;
|
||||||
@@ -38,4 +39,26 @@ impl Network<'_, '_> {
|
|||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(in crate::network::readarr_network) async fn mark_readarr_history_item_as_failed(
|
||||||
|
&mut self,
|
||||||
|
history_item_id: i64,
|
||||||
|
) -> Result<Value> {
|
||||||
|
info!("Marking the Readarr history item with ID: {history_item_id} as 'failed'");
|
||||||
|
let event = ReadarrEvent::MarkHistoryItemAsFailed(history_item_id);
|
||||||
|
|
||||||
|
let request_props = self
|
||||||
|
.request_props_from(
|
||||||
|
event,
|
||||||
|
RequestMethod::Post,
|
||||||
|
None,
|
||||||
|
Some(format!("/{history_item_id}")),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
self
|
||||||
|
.handle_request::<(), Value>(request_props, |_, _| ())
|
||||||
|
.await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -263,4 +263,45 @@ mod tests {
|
|||||||
stale_history_items
|
stale_history_items
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_mark_readarr_history_item_as_failed_event() {
|
||||||
|
let history_item_id = 1234i64;
|
||||||
|
let (mock, app, _server) = MockServarrApi::post()
|
||||||
|
.returns(json!({}))
|
||||||
|
.path("/1234")
|
||||||
|
.build_for(ReadarrEvent::MarkHistoryItemAsFailed(history_item_id))
|
||||||
|
.await;
|
||||||
|
app.lock().await.server_tabs.set_index(3);
|
||||||
|
let mut network = test_network(&app);
|
||||||
|
|
||||||
|
let result = network
|
||||||
|
.handle_readarr_event(ReadarrEvent::MarkHistoryItemAsFailed(history_item_id))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
mock.assert_async().await;
|
||||||
|
|
||||||
|
assert_ok!(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_mark_readarr_history_item_as_failed_event_failure() {
|
||||||
|
let history_item_id = 1234i64;
|
||||||
|
let (mock, app, _server) = MockServarrApi::post()
|
||||||
|
.returns(json!({}))
|
||||||
|
.status(500)
|
||||||
|
.path("/1234")
|
||||||
|
.build_for(ReadarrEvent::MarkHistoryItemAsFailed(history_item_id))
|
||||||
|
.await;
|
||||||
|
app.lock().await.server_tabs.set_index(3);
|
||||||
|
let mut network = test_network(&app);
|
||||||
|
|
||||||
|
let result = network
|
||||||
|
.handle_readarr_event(ReadarrEvent::MarkHistoryItemAsFailed(history_item_id))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
mock.assert_async().await;
|
||||||
|
|
||||||
|
assert_err!(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,7 @@ pub enum ReadarrEvent {
|
|||||||
GetUpdates,
|
GetUpdates,
|
||||||
HealthCheck,
|
HealthCheck,
|
||||||
ListAuthors,
|
ListAuthors,
|
||||||
|
MarkHistoryItemAsFailed(i64),
|
||||||
SearchNewAuthor(String),
|
SearchNewAuthor(String),
|
||||||
StartTask(ReadarrTaskName),
|
StartTask(ReadarrTaskName),
|
||||||
ToggleAuthorMonitoring(i64),
|
ToggleAuthorMonitoring(i64),
|
||||||
@@ -98,6 +99,7 @@ impl NetworkResource for ReadarrEvent {
|
|||||||
ReadarrEvent::HealthCheck => "/health",
|
ReadarrEvent::HealthCheck => "/health",
|
||||||
ReadarrEvent::GetHistory(_) => "/history",
|
ReadarrEvent::GetHistory(_) => "/history",
|
||||||
ReadarrEvent::GetAuthorHistory(_) | ReadarrEvent::GetBookHistory(_, _) => "/history/author",
|
ReadarrEvent::GetAuthorHistory(_) | ReadarrEvent::GetBookHistory(_, _) => "/history/author",
|
||||||
|
ReadarrEvent::MarkHistoryItemAsFailed(_) => "/history/failed",
|
||||||
ReadarrEvent::GetLogs(_) => "/log",
|
ReadarrEvent::GetLogs(_) => "/log",
|
||||||
ReadarrEvent::GetMetadataProfiles => "/metadataprofile",
|
ReadarrEvent::GetMetadataProfiles => "/metadataprofile",
|
||||||
ReadarrEvent::GetQualityProfiles => "/qualityprofile",
|
ReadarrEvent::GetQualityProfiles => "/qualityprofile",
|
||||||
@@ -235,6 +237,10 @@ impl Network<'_, '_> {
|
|||||||
.await
|
.await
|
||||||
.map(ReadarrSerdeable::from),
|
.map(ReadarrSerdeable::from),
|
||||||
ReadarrEvent::ListAuthors => self.list_authors().await.map(ReadarrSerdeable::from),
|
ReadarrEvent::ListAuthors => self.list_authors().await.map(ReadarrSerdeable::from),
|
||||||
|
ReadarrEvent::MarkHistoryItemAsFailed(history_item_id) => self
|
||||||
|
.mark_readarr_history_item_as_failed(history_item_id)
|
||||||
|
.await
|
||||||
|
.map(ReadarrSerdeable::from),
|
||||||
ReadarrEvent::SearchNewAuthor(query) => {
|
ReadarrEvent::SearchNewAuthor(query) => {
|
||||||
self.search_author(query).await.map(ReadarrSerdeable::from)
|
self.search_author(query).await.map(ReadarrSerdeable::from)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ mod tests {
|
|||||||
#[case(ReadarrEvent::GetHistory(500), "/history")]
|
#[case(ReadarrEvent::GetHistory(500), "/history")]
|
||||||
#[case(ReadarrEvent::GetAuthorHistory(1), "/history/author")]
|
#[case(ReadarrEvent::GetAuthorHistory(1), "/history/author")]
|
||||||
#[case(ReadarrEvent::GetBookHistory(1, 2), "/history/author")]
|
#[case(ReadarrEvent::GetBookHistory(1, 2), "/history/author")]
|
||||||
|
#[case(ReadarrEvent::MarkHistoryItemAsFailed(1), "/history/failed")]
|
||||||
#[case(ReadarrEvent::GetLogs(500), "/log")]
|
#[case(ReadarrEvent::GetLogs(500), "/log")]
|
||||||
#[case(ReadarrEvent::GetMetadataProfiles, "/metadataprofile")]
|
#[case(ReadarrEvent::GetMetadataProfiles, "/metadataprofile")]
|
||||||
#[case(ReadarrEvent::GetQualityProfiles, "/qualityprofile")]
|
#[case(ReadarrEvent::GetQualityProfiles, "/qualityprofile")]
|
||||||
|
|||||||
Reference in new issue
Block a user