feat(readarr): fetch Readarr author history and expose it on the CLI

Add the GetAuthorHistory event, backed by GET /history/author?authorId=N,
which returns a flat array of history records for a single author. The
fetcher mirrors the artist-history equivalent, sorting by id and carrying
the sort-prompt route guard so a refresh landing while the sort prompt is
open cannot clobber an in-progress sort selection.

Expose it as `readarr list author-history --author-id N`.
This commit is contained in:
Dark-Alex-17 committed 2026-08-27 11:11:24 -06:00
1 parent 9572b68f97
commit 8752a85db5
7 files changed
+402 -6

No files matched your search

+16
View File
@@ -17,6 +17,15 @@ mod list_command_handler_tests;
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum ReadarrListCommand {
#[command(about = "Fetch all history events for the author with the given ID")]
AuthorHistory {
#[arg(
long,
help = "The Readarr ID of the author whose history you wish to fetch",
required = true
)]
author_id: i64,
},
#[command(about = "List all authors in your Readarr library")]
Authors,
#[command(about = "List disk space details for all provisioned root folders in Readarr")]
@@ -74,6 +83,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrListCommand> for ReadarrListComman
async fn handle(self) -> Result<String> {
let result = match self.command {
ReadarrListCommand::AuthorHistory { author_id } => {
let resp = self
.network
.handle_network_event(ReadarrEvent::GetAuthorHistory(author_id).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrListCommand::Authors => {
let resp = self
.network
@@ -52,6 +52,39 @@ mod tests {
assert_eq!(result.unwrap_err().kind(), ErrorKind::InvalidValue);
}
#[test]
fn test_list_author_history_requires_author_id() {
let result =
Cli::command().try_get_matches_from(["managarr", "readarr", "list", "author-history"]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_list_author_history_success() {
let expected_args = ReadarrListCommand::AuthorHistory { author_id: 1 };
let result = Cli::try_parse_from([
"managarr",
"readarr",
"list",
"author-history",
"--author-id",
"1",
]);
assert_ok!(&result);
let Some(Command::Readarr(ReadarrCommand::List(author_command))) = result.unwrap().command
else {
panic!("Unexpected command type");
};
assert_eq!(author_command, expected_args);
}
#[test]
fn test_list_logs_default_values() {
let expected_args = ReadarrListCommand::Logs {
@@ -111,6 +144,32 @@ mod tests {
assert_ok!(&result);
}
#[tokio::test]
async fn test_handle_list_author_history_command() {
let expected_author_id = 1;
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
ReadarrEvent::GetAuthorHistory(expected_author_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_author_history_command = ReadarrListCommand::AuthorHistory { author_id: 1 };
let result =
ReadarrListCommandHandler::with(&app_arc, list_author_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();