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

Add ReadarrEvent::ListAuthors, mapping to GET /author, and wire it up as
`managarr readarr list authors`.

This is the first Readarr event that touches the library rather than
configuration, so it creates the library/authors module tree mirroring
Lidarr's library/artists layout.

list_authors mirrors Lidarr's list_artists, including the sort-prompt
route guard: a response landing while the user has the sort prompt open
must not clobber their in-progress sort selection. Both directions of
that guard are covered by tests.
This commit is contained in:
Dark-Alex-17 committed 2026-08-26 11:41:42 -06:00
1 parent e1be1df68a
commit 84eba9beac
7 files changed
+232

No files matched your search

@@ -0,0 +1,36 @@
use anyhow::Result;
use log::info;
use crate::models::Route;
use crate::models::readarr_models::Author;
use crate::models::servarr_data::readarr::readarr_data::ActiveReadarrBlock;
use crate::network::readarr_network::ReadarrEvent;
use crate::network::{Network, RequestMethod};
#[cfg(test)]
#[path = "readarr_authors_network_tests.rs"]
mod readarr_authors_network_tests;
impl Network<'_, '_> {
pub(in crate::network::readarr_network) async fn list_authors(&mut self) -> Result<Vec<Author>> {
info!("Fetching Readarr authors");
let event = ReadarrEvent::ListAuthors;
let request_props = self
.request_props_from(event, RequestMethod::Get, None::<()>, None, None)
.await;
self
.handle_request::<(), Vec<Author>>(request_props, |mut authors_vec, mut app| {
if !matches!(
app.get_current_route(),
Route::Readarr(ActiveReadarrBlock::AuthorsSortPrompt, _)
) {
authors_vec.sort_by_key(|a| a.id);
app.data.readarr_data.authors.set_items(authors_vec);
app.data.readarr_data.authors.apply_sorting_toggle(false);
}
})
.await
}
}
@@ -0,0 +1,157 @@
#[cfg(test)]
mod tests {
use crate::models::readarr_models::{Author, ReadarrSerdeable};
use crate::models::servarr_data::readarr::readarr_data::ActiveReadarrBlock;
use crate::network::network_tests::test_utils::{MockServarrApi, test_network};
use crate::network::readarr_network::ReadarrEvent;
use pretty_assertions::assert_eq;
use serde_json::json;
#[tokio::test]
async fn test_handle_list_authors_event() {
let authors_json = json!([
{
"id": 2,
"authorName": "Zeta Author",
"foreignAuthorId": "foreign-author-2",
"status": "continuing",
"overview": "An overview of Zeta Author",
"path": "/nfs/books/Zeta Author",
"rootFolderPath": "/nfs/books/",
"qualityProfileId": 1,
"metadataProfileId": 1,
"monitored": true,
"monitorNewItems": "all",
"genres": ["Fantasy"],
"tags": [1]
},
{
"id": 1,
"authorName": "Alpha Author",
"foreignAuthorId": "foreign-author-1",
"status": "continuing",
"overview": "An overview of Alpha Author",
"path": "/nfs/books/Alpha Author",
"rootFolderPath": "/nfs/books/",
"qualityProfileId": 1,
"metadataProfileId": 1,
"monitored": true,
"monitorNewItems": "all",
"genres": ["Fantasy"],
"tags": [1]
}
]);
let response: Vec<Author> = serde_json::from_value(authors_json.clone()).unwrap();
let mut sorted_authors = response.clone();
sorted_authors.sort_by_key(|author| author.id);
let (mock, app, _server) = MockServarrApi::get()
.returns(authors_json)
.build_for(ReadarrEvent::ListAuthors)
.await;
{
let mut app = app.lock().await;
app.server_tabs.set_index(3);
app.push_navigation_stack(ActiveReadarrBlock::Authors.into());
}
let mut network = test_network(&app);
let result = network
.handle_readarr_event(ReadarrEvent::ListAuthors)
.await;
mock.assert_async().await;
let ReadarrSerdeable::Authors(authors) = result.unwrap() else {
panic!("Expected Authors")
};
assert_eq!(authors, response);
assert_eq!(
app.lock().await.data.readarr_data.authors.items,
sorted_authors
);
}
#[tokio::test]
async fn test_handle_list_authors_event_no_op_when_user_is_selecting_sort_options() {
let authors_json = json!([{
"id": 1,
"authorName": "Alpha Author",
"foreignAuthorId": "foreign-author-1",
"status": "continuing",
"path": "/nfs/books/Alpha Author",
"rootFolderPath": "/nfs/books/",
"qualityProfileId": 1,
"metadataProfileId": 1,
"monitored": true,
"monitorNewItems": "all",
"genres": [],
"tags": []
}]);
let (mock, app, _server) = MockServarrApi::get()
.returns(authors_json)
.build_for(ReadarrEvent::ListAuthors)
.await;
{
let mut app = app.lock().await;
app.server_tabs.set_index(3);
app.push_navigation_stack(ActiveReadarrBlock::AuthorsSortPrompt.into());
}
let mut network = test_network(&app);
let result = network
.handle_readarr_event(ReadarrEvent::ListAuthors)
.await;
mock.assert_async().await;
assert_ok!(result);
assert_is_empty!(app.lock().await.data.readarr_data.authors);
}
#[tokio::test]
async fn test_handle_list_authors_event_failure() {
let stale_authors: Vec<Author> = serde_json::from_value(json!([{
"id": 99,
"authorName": "Stale Author",
"foreignAuthorId": "foreign-author-99",
"status": "continuing",
"path": "/nfs/books/Stale Author",
"rootFolderPath": "/nfs/books/",
"qualityProfileId": 1,
"metadataProfileId": 1,
"monitored": true,
"monitorNewItems": "all",
"genres": [],
"tags": []
}]))
.unwrap();
let (mock, app, _server) = MockServarrApi::get()
.returns(json!({}))
.status(500)
.build_for(ReadarrEvent::ListAuthors)
.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::ListAuthors)
.await;
mock.assert_async().await;
assert_err!(result);
assert_eq!(
app.lock().await.data.readarr_data.authors.items,
stale_authors
);
}
}
@@ -0,0 +1 @@
mod authors;
+4
View File
@@ -7,6 +7,7 @@ use crate::models::readarr_models::{AddReadarrRootFolderBody, ReadarrSerdeable,
use crate::models::servarr_models::{MetadataProfile, QualityProfile, Tag};
use crate::network::{Network, RequestMethod};
mod library;
mod root_folders;
mod system;
@@ -33,12 +34,14 @@ pub enum ReadarrEvent {
GetTasks,
GetUpdates,
HealthCheck,
ListAuthors,
StartTask(ReadarrTaskName),
}
impl NetworkResource for ReadarrEvent {
fn resource(&self) -> &'static str {
match &self {
ReadarrEvent::ListAuthors => "/author",
ReadarrEvent::GetQueuedEvents | ReadarrEvent::StartTask(_) => "/command",
ReadarrEvent::GetHostConfig | ReadarrEvent::GetSecurityConfig => "/config/host",
ReadarrEvent::GetDiskSpace => "/diskspace",
@@ -122,6 +125,7 @@ impl Network<'_, '_> {
.get_readarr_healthcheck()
.await
.map(ReadarrSerdeable::from),
ReadarrEvent::ListAuthors => self.list_authors().await.map(ReadarrSerdeable::from),
ReadarrEvent::StartTask(task_name) => self
.start_readarr_task(task_name)
.await
@@ -13,6 +13,7 @@ mod tests {
use tokio::sync::Mutex;
#[rstest]
#[case(ReadarrEvent::ListAuthors, "/author")]
#[case(ReadarrEvent::GetQueuedEvents, "/command")]
#[case(ReadarrEvent::StartTask(Default::default()), "/command")]
#[case(ReadarrEvent::GetHostConfig, "/config/host")]