feat(readarr): fetch Readarr book history and expose it on the CLI
This commit is contained in:
6 files changed
+435
-4
No files matched your search
@@ -46,6 +46,21 @@ pub enum ReadarrListCommand {
|
||||
)]
|
||||
book_id: i64,
|
||||
},
|
||||
#[command(about = "Fetch all history events for the book with the given ID")]
|
||||
BookHistory {
|
||||
#[arg(
|
||||
long,
|
||||
help = "The Readarr ID of the author who wrote the book whose history you wish to fetch",
|
||||
required = true
|
||||
)]
|
||||
author_id: i64,
|
||||
#[arg(
|
||||
long,
|
||||
help = "The Readarr ID of the book whose history you wish to fetch",
|
||||
required = true
|
||||
)]
|
||||
book_id: i64,
|
||||
},
|
||||
#[command(about = "List all books for the author with the given ID")]
|
||||
Books {
|
||||
#[arg(
|
||||
@@ -138,6 +153,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrListCommand> for ReadarrListComman
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
ReadarrListCommand::BookHistory { author_id, book_id } => {
|
||||
let resp = self
|
||||
.network
|
||||
.handle_network_event(ReadarrEvent::GetBookHistory(author_id, book_id).into())
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
ReadarrListCommand::Books { author_id } => {
|
||||
let resp = self
|
||||
.network
|
||||
|
||||
@@ -164,6 +164,45 @@ mod tests {
|
||||
assert_eq!(book_files_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_book_history_requires_author_id_and_book_id() {
|
||||
let result =
|
||||
Cli::command().try_get_matches_from(["managarr", "readarr", "list", "book-history"]);
|
||||
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_book_history_success() {
|
||||
let expected_args = ReadarrListCommand::BookHistory {
|
||||
author_id: 1,
|
||||
book_id: 2,
|
||||
};
|
||||
let result = Cli::try_parse_from([
|
||||
"managarr",
|
||||
"readarr",
|
||||
"list",
|
||||
"book-history",
|
||||
"--author-id",
|
||||
"1",
|
||||
"--book-id",
|
||||
"2",
|
||||
]);
|
||||
|
||||
assert_ok!(&result);
|
||||
|
||||
let Some(Command::Readarr(ReadarrCommand::List(book_history_command))) =
|
||||
result.unwrap().command
|
||||
else {
|
||||
panic!("Unexpected command type");
|
||||
};
|
||||
assert_eq!(book_history_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_books_success() {
|
||||
let expected_args = ReadarrListCommand::Books { author_id: 1 };
|
||||
@@ -341,6 +380,36 @@ mod tests {
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_list_book_history_command() {
|
||||
let expected_author_id = 1;
|
||||
let expected_book_id = 2;
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(
|
||||
ReadarrEvent::GetBookHistory(expected_author_id, 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 list_book_history_command = ReadarrListCommand::BookHistory {
|
||||
author_id: 1,
|
||||
book_id: 2,
|
||||
};
|
||||
|
||||
let result =
|
||||
ReadarrListCommandHandler::with(&app_arc, list_book_history_command, &mut mock_network)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_list_disk_space_command() {
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
|
||||
Reference in new issue
Block a user