feat(readarr): fetch Readarr author details and expose them on the CLI

This commit is contained in:
Dark-Alex-17 committed 2026-08-26 14:35:46 -06:00
1 parent 817fe4d135
commit 5042dbdb3a
6 files changed
+158 -2

No files matched your search

@@ -12,6 +12,28 @@ use crate::network::{Network, RequestMethod};
mod readarr_authors_network_tests;
impl Network<'_, '_> {
pub(in crate::network::readarr_network) async fn get_author_details(
&mut self,
author_id: i64,
) -> Result<Author> {
info!("Fetching details for Readarr author with ID: {author_id}");
let event = ReadarrEvent::GetAuthorDetails(author_id);
let request_props = self
.request_props_from(
event,
RequestMethod::Get,
None::<()>,
Some(format!("/{author_id}")),
None,
)
.await;
self
.handle_request::<(), Author>(request_props, |_, _| ())
.await
}
pub(in crate::network::readarr_network) async fn list_authors(&mut self) -> Result<Vec<Author>> {
info!("Fetching Readarr authors");
let event = ReadarrEvent::ListAuthors;
@@ -10,6 +10,63 @@ mod tests {
use pretty_assertions::assert_eq;
use serde_json::{Value, json};
#[tokio::test]
async fn test_handle_get_author_details_event() {
let expected_author: Author = serde_json::from_str(AUTHOR_JSON).unwrap();
let stale_authors = vec![stale_author()];
let (mock, app, _server) = MockServarrApi::get()
.returns(serde_json::from_str(AUTHOR_JSON).unwrap())
.path("/1")
.build_for(ReadarrEvent::GetAuthorDetails(1))
.await;
{
let mut app = app.lock().await;
app.server_tabs.set_index(3);
app
.data
.readarr_data
.authors
.set_items(stale_authors.clone());
}
let mut network = test_network(&app);
let result = network
.handle_readarr_event(ReadarrEvent::GetAuthorDetails(1))
.await;
mock.assert_async().await;
let ReadarrSerdeable::Author(author) = result.unwrap() else {
panic!("Expected Author")
};
assert_eq!(author, expected_author);
assert_eq!(
app.lock().await.data.readarr_data.authors.items,
stale_authors
);
}
#[tokio::test]
async fn test_handle_get_author_details_event_failure() {
let (mock, app, _server) = MockServarrApi::get()
.returns(serde_json::from_str(AUTHOR_JSON).unwrap())
.status(500)
.path("/1")
.build_for(ReadarrEvent::GetAuthorDetails(1))
.await;
app.lock().await.server_tabs.set_index(3);
let mut network = test_network(&app);
let result = network
.handle_readarr_event(ReadarrEvent::GetAuthorDetails(1))
.await;
mock.assert_async().await;
assert_err!(result);
}
#[tokio::test]
async fn test_handle_list_authors_event() {
let authors_json = json!([