feat(readarr): fetch Readarr author details and expose them on the CLI
This commit is contained in:
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!([
|
||||
|
||||
@@ -25,6 +25,7 @@ pub enum ReadarrEvent {
|
||||
AddTag(String),
|
||||
DeleteRootFolder(i64),
|
||||
DeleteTag(i64),
|
||||
GetAuthorDetails(i64),
|
||||
GetDiskSpace,
|
||||
GetHostConfig,
|
||||
GetLogs(u64),
|
||||
@@ -45,7 +46,7 @@ pub enum ReadarrEvent {
|
||||
impl NetworkResource for ReadarrEvent {
|
||||
fn resource(&self) -> &'static str {
|
||||
match &self {
|
||||
ReadarrEvent::ListAuthors => "/author",
|
||||
ReadarrEvent::GetAuthorDetails(_) | ReadarrEvent::ListAuthors => "/author",
|
||||
ReadarrEvent::GetQueuedEvents | ReadarrEvent::StartTask(_) => "/command",
|
||||
ReadarrEvent::GetHostConfig | ReadarrEvent::GetSecurityConfig => "/config/host",
|
||||
ReadarrEvent::GetDiskSpace => "/diskspace",
|
||||
@@ -89,6 +90,10 @@ impl Network<'_, '_> {
|
||||
.delete_readarr_tag(tag_id)
|
||||
.await
|
||||
.map(ReadarrSerdeable::from),
|
||||
ReadarrEvent::GetAuthorDetails(author_id) => self
|
||||
.get_author_details(author_id)
|
||||
.await
|
||||
.map(ReadarrSerdeable::from),
|
||||
ReadarrEvent::GetDiskSpace => self
|
||||
.get_readarr_diskspace()
|
||||
.await
|
||||
|
||||
@@ -13,6 +13,7 @@ mod tests {
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
#[rstest]
|
||||
#[case(ReadarrEvent::GetAuthorDetails(1), "/author")]
|
||||
#[case(ReadarrEvent::ListAuthors, "/author")]
|
||||
#[case(ReadarrEvent::GetQueuedEvents, "/command")]
|
||||
#[case(ReadarrEvent::StartTask(Default::default()), "/command")]
|
||||
|
||||
Reference in new issue
Block a user