feat(readarr): fetch Readarr book details and expose them on the CLI
This commit is contained in:
6 files changed
+147
-1
No files matched your search
@@ -27,6 +27,15 @@ pub enum ReadarrGetCommand {
|
|||||||
)]
|
)]
|
||||||
author_id: i64,
|
author_id: i64,
|
||||||
},
|
},
|
||||||
|
#[command(about = "Get detailed information for the book with the given ID")]
|
||||||
|
BookDetails {
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
help = "The Readarr ID of the book whose details you wish to fetch",
|
||||||
|
required = true
|
||||||
|
)]
|
||||||
|
book_id: i64,
|
||||||
|
},
|
||||||
#[command(about = "Fetch the host config for your Readarr instance")]
|
#[command(about = "Fetch the host config for your Readarr instance")]
|
||||||
HostConfig,
|
HostConfig,
|
||||||
#[command(about = "Fetch the security config for your Readarr instance")]
|
#[command(about = "Fetch the security config for your Readarr instance")]
|
||||||
@@ -69,6 +78,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrGetCommand> for ReadarrGetCommandH
|
|||||||
.await?;
|
.await?;
|
||||||
serde_json::to_string_pretty(&resp)?
|
serde_json::to_string_pretty(&resp)?
|
||||||
}
|
}
|
||||||
|
ReadarrGetCommand::BookDetails { book_id } => {
|
||||||
|
let resp = self
|
||||||
|
.network
|
||||||
|
.handle_network_event(ReadarrEvent::GetBookDetails(book_id).into())
|
||||||
|
.await?;
|
||||||
|
serde_json::to_string_pretty(&resp)?
|
||||||
|
}
|
||||||
ReadarrGetCommand::HostConfig => {
|
ReadarrGetCommand::HostConfig => {
|
||||||
let resp = self
|
let resp = self
|
||||||
.network
|
.network
|
||||||
|
|||||||
@@ -50,6 +50,32 @@ mod tests {
|
|||||||
assert_ok!(&result);
|
assert_ok!(&result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_book_details_requires_book_id() {
|
||||||
|
let result =
|
||||||
|
Cli::command().try_get_matches_from(["managarr", "readarr", "get", "book-details"]);
|
||||||
|
|
||||||
|
assert_err!(&result);
|
||||||
|
assert_eq!(
|
||||||
|
result.unwrap_err().kind(),
|
||||||
|
ErrorKind::MissingRequiredArgument
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_book_details_requirements_satisfied() {
|
||||||
|
let result = Cli::command().try_get_matches_from([
|
||||||
|
"managarr",
|
||||||
|
"readarr",
|
||||||
|
"get",
|
||||||
|
"book-details",
|
||||||
|
"--book-id",
|
||||||
|
"1",
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert_ok!(&result);
|
||||||
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn test_get_commands_have_no_arg_requirements(
|
fn test_get_commands_have_no_arg_requirements(
|
||||||
#[values("host-config", "security-config", "system-status")] subcommand: &str,
|
#[values("host-config", "security-config", "system-status")] subcommand: &str,
|
||||||
@@ -103,6 +129,32 @@ mod tests {
|
|||||||
assert_ok!(&result);
|
assert_ok!(&result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_get_book_details_command() {
|
||||||
|
let expected_book_id = 1;
|
||||||
|
let mut mock_network = MockNetworkTrait::new();
|
||||||
|
mock_network
|
||||||
|
.expect_handle_network_event()
|
||||||
|
.with(eq::<NetworkEvent>(
|
||||||
|
ReadarrEvent::GetBookDetails(expected_book_id).into(),
|
||||||
|
))
|
||||||
|
.times(1)
|
||||||
|
.returning(|_| {
|
||||||
|
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
|
||||||
|
json!({"testResponse": "response"}),
|
||||||
|
)))
|
||||||
|
});
|
||||||
|
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
||||||
|
let get_book_details_command = ReadarrGetCommand::BookDetails { book_id: 1 };
|
||||||
|
|
||||||
|
let result =
|
||||||
|
ReadarrGetCommandHandler::with(&app_arc, get_book_details_command, &mut mock_network)
|
||||||
|
.handle()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
assert_ok!(&result);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_handle_get_host_config_command() {
|
async fn test_handle_get_host_config_command() {
|
||||||
let mut mock_network = MockNetworkTrait::new();
|
let mut mock_network = MockNetworkTrait::new();
|
||||||
|
|||||||
@@ -10,6 +10,28 @@ use crate::network::{Network, RequestMethod};
|
|||||||
mod readarr_books_network_tests;
|
mod readarr_books_network_tests;
|
||||||
|
|
||||||
impl Network<'_, '_> {
|
impl Network<'_, '_> {
|
||||||
|
pub(in crate::network::readarr_network) async fn get_book_details(
|
||||||
|
&mut self,
|
||||||
|
book_id: i64,
|
||||||
|
) -> Result<Book> {
|
||||||
|
info!("Fetching details for Readarr book with ID: {book_id}");
|
||||||
|
let event = ReadarrEvent::GetBookDetails(book_id);
|
||||||
|
|
||||||
|
let request_props = self
|
||||||
|
.request_props_from(
|
||||||
|
event,
|
||||||
|
RequestMethod::Get,
|
||||||
|
None::<()>,
|
||||||
|
Some(format!("/{book_id}")),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
self
|
||||||
|
.handle_request::<(), Book>(request_props, |_, _| ())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
pub(in crate::network::readarr_network) async fn get_books(
|
pub(in crate::network::readarr_network) async fn get_books(
|
||||||
&mut self,
|
&mut self,
|
||||||
author_id: i64,
|
author_id: i64,
|
||||||
|
|||||||
@@ -9,6 +9,56 @@ mod tests {
|
|||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use serde_json::{Value, json};
|
use serde_json::{Value, json};
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_get_book_details_event() {
|
||||||
|
let expected_book: Book = serde_json::from_str(BOOK_JSON).unwrap();
|
||||||
|
let stale_books = vec![stale_book()];
|
||||||
|
let (mock, app, _server) = MockServarrApi::get()
|
||||||
|
.returns(serde_json::from_str(BOOK_JSON).unwrap())
|
||||||
|
.path("/1")
|
||||||
|
.build_for(ReadarrEvent::GetBookDetails(1))
|
||||||
|
.await;
|
||||||
|
{
|
||||||
|
let mut app = app.lock().await;
|
||||||
|
app.server_tabs.set_index(3);
|
||||||
|
app.data.readarr_data.books.set_items(stale_books.clone());
|
||||||
|
}
|
||||||
|
let mut network = test_network(&app);
|
||||||
|
|
||||||
|
let result = network
|
||||||
|
.handle_readarr_event(ReadarrEvent::GetBookDetails(1))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
mock.assert_async().await;
|
||||||
|
|
||||||
|
let ReadarrSerdeable::Book(book) = result.unwrap() else {
|
||||||
|
panic!("Expected Book")
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(book, expected_book);
|
||||||
|
assert_eq!(app.lock().await.data.readarr_data.books.items, stale_books);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_get_book_details_event_failure() {
|
||||||
|
let (mock, app, _server) = MockServarrApi::get()
|
||||||
|
.returns(serde_json::from_str(BOOK_JSON).unwrap())
|
||||||
|
.status(500)
|
||||||
|
.path("/1")
|
||||||
|
.build_for(ReadarrEvent::GetBookDetails(1))
|
||||||
|
.await;
|
||||||
|
app.lock().await.server_tabs.set_index(3);
|
||||||
|
let mut network = test_network(&app);
|
||||||
|
|
||||||
|
let result = network
|
||||||
|
.handle_readarr_event(ReadarrEvent::GetBookDetails(1))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
mock.assert_async().await;
|
||||||
|
|
||||||
|
assert_err!(result);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_handle_get_books_event() {
|
async fn test_handle_get_books_event() {
|
||||||
let books_json = json!([
|
let books_json = json!([
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ pub enum ReadarrEvent {
|
|||||||
EditAuthor(EditAuthorParams),
|
EditAuthor(EditAuthorParams),
|
||||||
GetAuthorDetails(i64),
|
GetAuthorDetails(i64),
|
||||||
GetAuthorHistory(i64),
|
GetAuthorHistory(i64),
|
||||||
|
GetBookDetails(i64),
|
||||||
GetBooks(i64),
|
GetBooks(i64),
|
||||||
GetDiskSpace,
|
GetDiskSpace,
|
||||||
GetHostConfig,
|
GetHostConfig,
|
||||||
@@ -66,7 +67,7 @@ impl NetworkResource for ReadarrEvent {
|
|||||||
| ReadarrEvent::ListAuthors
|
| ReadarrEvent::ListAuthors
|
||||||
| ReadarrEvent::ToggleAuthorMonitoring(_) => "/author",
|
| ReadarrEvent::ToggleAuthorMonitoring(_) => "/author",
|
||||||
ReadarrEvent::SearchNewAuthor(_) => "/author/lookup",
|
ReadarrEvent::SearchNewAuthor(_) => "/author/lookup",
|
||||||
ReadarrEvent::GetBooks(_) => "/book",
|
ReadarrEvent::GetBookDetails(_) | ReadarrEvent::GetBooks(_) => "/book",
|
||||||
ReadarrEvent::GetQueuedEvents
|
ReadarrEvent::GetQueuedEvents
|
||||||
| ReadarrEvent::StartTask(_)
|
| ReadarrEvent::StartTask(_)
|
||||||
| ReadarrEvent::TriggerAutomaticAuthorSearch(_)
|
| ReadarrEvent::TriggerAutomaticAuthorSearch(_)
|
||||||
@@ -132,6 +133,10 @@ impl Network<'_, '_> {
|
|||||||
.get_readarr_author_history(author_id)
|
.get_readarr_author_history(author_id)
|
||||||
.await
|
.await
|
||||||
.map(ReadarrSerdeable::from),
|
.map(ReadarrSerdeable::from),
|
||||||
|
ReadarrEvent::GetBookDetails(book_id) => self
|
||||||
|
.get_book_details(book_id)
|
||||||
|
.await
|
||||||
|
.map(ReadarrSerdeable::from),
|
||||||
ReadarrEvent::GetBooks(author_id) => {
|
ReadarrEvent::GetBooks(author_id) => {
|
||||||
self.get_books(author_id).await.map(ReadarrSerdeable::from)
|
self.get_books(author_id).await.map(ReadarrSerdeable::from)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ mod tests {
|
|||||||
#[case(ReadarrEvent::ListAuthors, "/author")]
|
#[case(ReadarrEvent::ListAuthors, "/author")]
|
||||||
#[case(ReadarrEvent::ToggleAuthorMonitoring(1), "/author")]
|
#[case(ReadarrEvent::ToggleAuthorMonitoring(1), "/author")]
|
||||||
#[case(ReadarrEvent::SearchNewAuthor(String::new()), "/author/lookup")]
|
#[case(ReadarrEvent::SearchNewAuthor(String::new()), "/author/lookup")]
|
||||||
|
#[case(ReadarrEvent::GetBookDetails(1), "/book")]
|
||||||
#[case(ReadarrEvent::GetBooks(1), "/book")]
|
#[case(ReadarrEvent::GetBooks(1), "/book")]
|
||||||
#[case(ReadarrEvent::GetQueuedEvents, "/command")]
|
#[case(ReadarrEvent::GetQueuedEvents, "/command")]
|
||||||
#[case(ReadarrEvent::StartTask(Default::default()), "/command")]
|
#[case(ReadarrEvent::StartTask(Default::default()), "/command")]
|
||||||
|
|||||||
Reference in new issue
Block a user