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:
7 files changed
+402
-6
No files matched your search
@@ -17,6 +17,15 @@ mod list_command_handler_tests;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
|
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
|
||||||
pub enum ReadarrListCommand {
|
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")]
|
#[command(about = "List all authors in your Readarr library")]
|
||||||
Authors,
|
Authors,
|
||||||
#[command(about = "List disk space details for all provisioned root folders in Readarr")]
|
#[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> {
|
async fn handle(self) -> Result<String> {
|
||||||
let result = match self.command {
|
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 => {
|
ReadarrListCommand::Authors => {
|
||||||
let resp = self
|
let resp = self
|
||||||
.network
|
.network
|
||||||
|
|||||||
@@ -52,6 +52,39 @@ mod tests {
|
|||||||
assert_eq!(result.unwrap_err().kind(), ErrorKind::InvalidValue);
|
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]
|
#[test]
|
||||||
fn test_list_logs_default_values() {
|
fn test_list_logs_default_values() {
|
||||||
let expected_args = ReadarrListCommand::Logs {
|
let expected_args = ReadarrListCommand::Logs {
|
||||||
@@ -111,6 +144,32 @@ mod tests {
|
|||||||
assert_ok!(&result);
|
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]
|
#[tokio::test]
|
||||||
async fn test_handle_list_disk_space_command() {
|
async fn test_handle_list_disk_space_command() {
|
||||||
let mut mock_network = MockNetworkTrait::new();
|
let mut mock_network = MockNetworkTrait::new();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use serde_json::{Value, json};
|
|||||||
use crate::models::Route;
|
use crate::models::Route;
|
||||||
use crate::models::readarr_models::{
|
use crate::models::readarr_models::{
|
||||||
AddAuthorBody, AddAuthorSearchResult, Author, DeleteParams, EditAuthorParams, ReadarrCommandBody,
|
AddAuthorBody, AddAuthorSearchResult, Author, DeleteParams, EditAuthorParams, ReadarrCommandBody,
|
||||||
|
ReadarrHistoryItem,
|
||||||
};
|
};
|
||||||
use crate::models::servarr_data::readarr::readarr_data::ActiveReadarrBlock;
|
use crate::models::servarr_data::readarr::readarr_data::ActiveReadarrBlock;
|
||||||
use crate::models::stateful_table::StatefulTable;
|
use crate::models::stateful_table::StatefulTable;
|
||||||
@@ -216,6 +217,41 @@ impl Network<'_, '_> {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(in crate::network::readarr_network) async fn get_readarr_author_history(
|
||||||
|
&mut self,
|
||||||
|
author_id: i64,
|
||||||
|
) -> Result<Vec<ReadarrHistoryItem>> {
|
||||||
|
info!("Fetching Readarr author history for author with ID: {author_id}");
|
||||||
|
let event = ReadarrEvent::GetAuthorHistory(author_id);
|
||||||
|
|
||||||
|
let request_props = self
|
||||||
|
.request_props_from(
|
||||||
|
event,
|
||||||
|
RequestMethod::Get,
|
||||||
|
None::<()>,
|
||||||
|
None,
|
||||||
|
Some(format!("authorId={author_id}")),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
self
|
||||||
|
.handle_request::<(), Vec<ReadarrHistoryItem>>(request_props, |mut history_vec, mut app| {
|
||||||
|
let is_sorting = matches!(
|
||||||
|
app.get_current_route(),
|
||||||
|
Route::Readarr(ActiveReadarrBlock::AuthorHistorySortPrompt, _)
|
||||||
|
);
|
||||||
|
|
||||||
|
let author_history = &mut app.data.readarr_data.author_history;
|
||||||
|
|
||||||
|
if !is_sorting {
|
||||||
|
history_vec.sort_by_key(|a| a.id);
|
||||||
|
author_history.set_items(history_vec);
|
||||||
|
author_history.apply_sorting_toggle(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
pub(in crate::network::readarr_network) async fn list_authors(&mut self) -> Result<Vec<Author>> {
|
pub(in crate::network::readarr_network) async fn list_authors(&mut self) -> Result<Vec<Author>> {
|
||||||
info!("Fetching Readarr authors");
|
info!("Fetching Readarr authors");
|
||||||
let event = ReadarrEvent::ListAuthors;
|
let event = ReadarrEvent::ListAuthors;
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
mod tests {
|
mod tests {
|
||||||
use crate::models::readarr_models::{
|
use crate::models::readarr_models::{
|
||||||
AddAuthorBody, AddAuthorSearchResult, Author, DeleteParams, EditAuthorParams,
|
AddAuthorBody, AddAuthorSearchResult, Author, DeleteParams, EditAuthorParams,
|
||||||
NewItemMonitorType, ReadarrSerdeable,
|
NewItemMonitorType, ReadarrHistoryItem, ReadarrSerdeable,
|
||||||
};
|
};
|
||||||
use crate::models::servarr_data::readarr::readarr_data::ActiveReadarrBlock;
|
use crate::models::servarr_data::readarr::readarr_data::ActiveReadarrBlock;
|
||||||
use crate::models::stateful_table::StatefulTable;
|
use crate::models::stateful_table::{SortOption, StatefulTable};
|
||||||
use crate::network::NetworkResource;
|
use crate::network::NetworkResource;
|
||||||
use crate::network::network_tests::test_utils::{MockServarrApi, test_network};
|
use crate::network::network_tests::test_utils::{MockServarrApi, test_network};
|
||||||
use crate::network::readarr_network::ReadarrEvent;
|
use crate::network::readarr_network::ReadarrEvent;
|
||||||
use crate::network::readarr_network::readarr_network_test_utils::test_utils::{
|
use crate::network::readarr_network::readarr_network_test_utils::test_utils::{
|
||||||
ADD_AUTHOR_SEARCH_RESULT_JSON, AUTHOR_JSON, add_author_body, stale_add_author_search_result,
|
ADD_AUTHOR_SEARCH_RESULT_JSON, AUTHOR_JSON, add_author_body, readarr_history_item,
|
||||||
stale_author,
|
stale_add_author_search_result, stale_author, stale_readarr_history_item,
|
||||||
};
|
};
|
||||||
use bimap::BiMap;
|
use bimap::BiMap;
|
||||||
use mockito::Matcher;
|
use mockito::Matcher;
|
||||||
@@ -76,6 +76,244 @@ mod tests {
|
|||||||
assert_err!(result);
|
assert_err!(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_get_readarr_author_history_event(
|
||||||
|
#[values(true, false)] use_custom_sorting: bool,
|
||||||
|
) {
|
||||||
|
let history_json = json!([{
|
||||||
|
"id": 456,
|
||||||
|
"authorId": 2001,
|
||||||
|
"bookId": 2001,
|
||||||
|
"sourceTitle": "An Anthology",
|
||||||
|
"quality": { "quality": { "name": "AZW3" } },
|
||||||
|
"date": "2023-01-01T00:00:00Z",
|
||||||
|
"eventType": "grabbed",
|
||||||
|
"data": {
|
||||||
|
"droppedPath": "/nfs/nzbget/completed/books/Something/cool.azw3",
|
||||||
|
"importedPath": "/nfs/books/Test Author/Book 1/Cool.azw3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 123,
|
||||||
|
"authorId": 1007,
|
||||||
|
"bookId": 1007,
|
||||||
|
"sourceTitle": "z book",
|
||||||
|
"quality": { "quality": { "name": "AZW3" } },
|
||||||
|
"date": "2023-01-01T00:00:00Z",
|
||||||
|
"eventType": "grabbed",
|
||||||
|
"data": {
|
||||||
|
"droppedPath": "/nfs/nzbget/completed/books/Something/cool.azw3",
|
||||||
|
"importedPath": "/nfs/books/Test Author/Book 1/Cool.azw3"
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
let response: Vec<ReadarrHistoryItem> = serde_json::from_value(history_json.clone()).unwrap();
|
||||||
|
let mut expected_history_items = vec![
|
||||||
|
ReadarrHistoryItem {
|
||||||
|
id: 123,
|
||||||
|
author_id: 1007,
|
||||||
|
book_id: 1007,
|
||||||
|
source_title: "z book".into(),
|
||||||
|
..readarr_history_item()
|
||||||
|
},
|
||||||
|
ReadarrHistoryItem {
|
||||||
|
id: 456,
|
||||||
|
author_id: 2001,
|
||||||
|
book_id: 2001,
|
||||||
|
source_title: "An Anthology".into(),
|
||||||
|
..readarr_history_item()
|
||||||
|
},
|
||||||
|
];
|
||||||
|
let (mock, app, _server) = MockServarrApi::get()
|
||||||
|
.returns(history_json)
|
||||||
|
.query("authorId=1")
|
||||||
|
.build_for(ReadarrEvent::GetAuthorHistory(1))
|
||||||
|
.await;
|
||||||
|
if use_custom_sorting {
|
||||||
|
let cmp_fn = |a: &ReadarrHistoryItem, b: &ReadarrHistoryItem| {
|
||||||
|
a.source_title
|
||||||
|
.text
|
||||||
|
.to_lowercase()
|
||||||
|
.cmp(&b.source_title.text.to_lowercase())
|
||||||
|
};
|
||||||
|
expected_history_items.sort_by(cmp_fn);
|
||||||
|
|
||||||
|
let history_sort_option = SortOption {
|
||||||
|
name: "Source Title",
|
||||||
|
cmp_fn: Some(cmp_fn),
|
||||||
|
};
|
||||||
|
app
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.data
|
||||||
|
.readarr_data
|
||||||
|
.author_history
|
||||||
|
.sorting(vec![history_sort_option]);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let mut app = app.lock().await;
|
||||||
|
app.server_tabs.set_index(3);
|
||||||
|
app.data.readarr_data.author_history.sort_asc = true;
|
||||||
|
}
|
||||||
|
let mut network = test_network(&app);
|
||||||
|
|
||||||
|
let result = network
|
||||||
|
.handle_readarr_event(ReadarrEvent::GetAuthorHistory(1))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
mock.assert_async().await;
|
||||||
|
|
||||||
|
let ReadarrSerdeable::ReadarrHistoryItems(history_items) = result.unwrap() else {
|
||||||
|
panic!("Expected ReadarrHistoryItems")
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(history_items, response);
|
||||||
|
let app = app.lock().await;
|
||||||
|
assert_eq!(
|
||||||
|
app.data.readarr_data.author_history.items,
|
||||||
|
expected_history_items
|
||||||
|
);
|
||||||
|
assert!(app.data.readarr_data.author_history.sort_asc);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_get_readarr_author_history_event_no_op_when_user_is_selecting_sort_options()
|
||||||
|
{
|
||||||
|
let history_json = json!([{
|
||||||
|
"id": 456,
|
||||||
|
"authorId": 2001,
|
||||||
|
"bookId": 2001,
|
||||||
|
"sourceTitle": "An Anthology",
|
||||||
|
"quality": { "quality": { "name": "AZW3" } },
|
||||||
|
"date": "2023-01-01T00:00:00Z",
|
||||||
|
"eventType": "grabbed",
|
||||||
|
"data": {
|
||||||
|
"droppedPath": "/nfs/nzbget/completed/books/Something/cool.azw3",
|
||||||
|
"importedPath": "/nfs/books/Test Author/Book 1/Cool.azw3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 123,
|
||||||
|
"authorId": 1007,
|
||||||
|
"bookId": 1007,
|
||||||
|
"sourceTitle": "z book",
|
||||||
|
"quality": { "quality": { "name": "AZW3" } },
|
||||||
|
"date": "2023-01-01T00:00:00Z",
|
||||||
|
"eventType": "grabbed",
|
||||||
|
"data": {
|
||||||
|
"droppedPath": "/nfs/nzbget/completed/books/Something/cool.azw3",
|
||||||
|
"importedPath": "/nfs/books/Test Author/Book 1/Cool.azw3"
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
let response: Vec<ReadarrHistoryItem> = serde_json::from_value(history_json.clone()).unwrap();
|
||||||
|
let (mock, app, _server) = MockServarrApi::get()
|
||||||
|
.returns(history_json)
|
||||||
|
.query("authorId=1")
|
||||||
|
.build_for(ReadarrEvent::GetAuthorHistory(1))
|
||||||
|
.await;
|
||||||
|
{
|
||||||
|
let mut app = app.lock().await;
|
||||||
|
app.server_tabs.set_index(3);
|
||||||
|
app.data.readarr_data.author_history.sort_asc = true;
|
||||||
|
app.push_navigation_stack(ActiveReadarrBlock::AuthorHistorySortPrompt.into());
|
||||||
|
}
|
||||||
|
let mut network = test_network(&app);
|
||||||
|
|
||||||
|
let result = network
|
||||||
|
.handle_readarr_event(ReadarrEvent::GetAuthorHistory(1))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
mock.assert_async().await;
|
||||||
|
|
||||||
|
let ReadarrSerdeable::ReadarrHistoryItems(history_items) = result.unwrap() else {
|
||||||
|
panic!("Expected ReadarrHistoryItems")
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(history_items, response);
|
||||||
|
let app = app.lock().await;
|
||||||
|
assert_is_empty!(app.data.readarr_data.author_history);
|
||||||
|
assert!(app.data.readarr_data.author_history.sort_asc);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_get_readarr_author_history_event_empty_response() {
|
||||||
|
let stale_history_items = vec![stale_readarr_history_item()];
|
||||||
|
let (mock, app, _server) = MockServarrApi::get()
|
||||||
|
.returns(json!([]))
|
||||||
|
.query("authorId=1")
|
||||||
|
.build_for(ReadarrEvent::GetAuthorHistory(1))
|
||||||
|
.await;
|
||||||
|
{
|
||||||
|
let mut app = app.lock().await;
|
||||||
|
app.server_tabs.set_index(3);
|
||||||
|
app
|
||||||
|
.data
|
||||||
|
.readarr_data
|
||||||
|
.author_history
|
||||||
|
.set_items(stale_history_items.clone());
|
||||||
|
}
|
||||||
|
let mut network = test_network(&app);
|
||||||
|
|
||||||
|
let result = network
|
||||||
|
.handle_readarr_event(ReadarrEvent::GetAuthorHistory(1))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
mock.assert_async().await;
|
||||||
|
|
||||||
|
let ReadarrSerdeable::ReadarrHistoryItems(history_items) = result.unwrap() else {
|
||||||
|
panic!("Expected ReadarrHistoryItems")
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_is_empty!(history_items);
|
||||||
|
assert_is_empty!(app.lock().await.data.readarr_data.author_history);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_get_readarr_author_history_event_failure() {
|
||||||
|
let history_json = json!([{
|
||||||
|
"id": 123,
|
||||||
|
"authorId": 1007,
|
||||||
|
"bookId": 1007,
|
||||||
|
"sourceTitle": "z book",
|
||||||
|
"quality": { "quality": { "name": "AZW3" } },
|
||||||
|
"date": "2023-01-01T00:00:00Z",
|
||||||
|
"eventType": "grabbed",
|
||||||
|
"data": {
|
||||||
|
"droppedPath": "/nfs/nzbget/completed/books/Something/cool.azw3",
|
||||||
|
"importedPath": "/nfs/books/Test Author/Book 1/Cool.azw3"
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
let stale_history_items = vec![stale_readarr_history_item()];
|
||||||
|
let (mock, app, _server) = MockServarrApi::get()
|
||||||
|
.returns(history_json)
|
||||||
|
.status(500)
|
||||||
|
.query("authorId=1")
|
||||||
|
.build_for(ReadarrEvent::GetAuthorHistory(1))
|
||||||
|
.await;
|
||||||
|
{
|
||||||
|
let mut app = app.lock().await;
|
||||||
|
app.server_tabs.set_index(3);
|
||||||
|
app
|
||||||
|
.data
|
||||||
|
.readarr_data
|
||||||
|
.author_history
|
||||||
|
.set_items(stale_history_items.clone());
|
||||||
|
}
|
||||||
|
let mut network = test_network(&app);
|
||||||
|
|
||||||
|
let result = network
|
||||||
|
.handle_readarr_event(ReadarrEvent::GetAuthorHistory(1))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
mock.assert_async().await;
|
||||||
|
|
||||||
|
assert_err!(result);
|
||||||
|
assert_eq!(
|
||||||
|
app.lock().await.data.readarr_data.author_history.items,
|
||||||
|
stale_history_items
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_handle_list_authors_event() {
|
async fn test_handle_list_authors_event() {
|
||||||
let authors_json = json!([
|
let authors_json = json!([
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ pub enum ReadarrEvent {
|
|||||||
DeleteTag(i64),
|
DeleteTag(i64),
|
||||||
EditAuthor(EditAuthorParams),
|
EditAuthor(EditAuthorParams),
|
||||||
GetAuthorDetails(i64),
|
GetAuthorDetails(i64),
|
||||||
|
GetAuthorHistory(i64),
|
||||||
GetDiskSpace,
|
GetDiskSpace,
|
||||||
GetHostConfig,
|
GetHostConfig,
|
||||||
GetLogs(u64),
|
GetLogs(u64),
|
||||||
@@ -72,6 +73,7 @@ impl NetworkResource for ReadarrEvent {
|
|||||||
ReadarrEvent::GetHostConfig | ReadarrEvent::GetSecurityConfig => "/config/host",
|
ReadarrEvent::GetHostConfig | ReadarrEvent::GetSecurityConfig => "/config/host",
|
||||||
ReadarrEvent::GetDiskSpace => "/diskspace",
|
ReadarrEvent::GetDiskSpace => "/diskspace",
|
||||||
ReadarrEvent::HealthCheck => "/health",
|
ReadarrEvent::HealthCheck => "/health",
|
||||||
|
ReadarrEvent::GetAuthorHistory(_) => "/history/author",
|
||||||
ReadarrEvent::GetLogs(_) => "/log",
|
ReadarrEvent::GetLogs(_) => "/log",
|
||||||
ReadarrEvent::GetMetadataProfiles => "/metadataprofile",
|
ReadarrEvent::GetMetadataProfiles => "/metadataprofile",
|
||||||
ReadarrEvent::GetQualityProfiles => "/qualityprofile",
|
ReadarrEvent::GetQualityProfiles => "/qualityprofile",
|
||||||
@@ -124,6 +126,10 @@ impl Network<'_, '_> {
|
|||||||
.get_author_details(author_id)
|
.get_author_details(author_id)
|
||||||
.await
|
.await
|
||||||
.map(ReadarrSerdeable::from),
|
.map(ReadarrSerdeable::from),
|
||||||
|
ReadarrEvent::GetAuthorHistory(author_id) => self
|
||||||
|
.get_readarr_author_history(author_id)
|
||||||
|
.await
|
||||||
|
.map(ReadarrSerdeable::from),
|
||||||
ReadarrEvent::GetDiskSpace => self
|
ReadarrEvent::GetDiskSpace => self
|
||||||
.get_readarr_diskspace()
|
.get_readarr_diskspace()
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
pub mod test_utils {
|
pub mod test_utils {
|
||||||
use crate::models::readarr_models::{
|
use crate::models::readarr_models::{
|
||||||
AddAuthorBody, AddAuthorOptions, AddAuthorSearchResult, Author, AuthorStatus, MonitorType,
|
AddAuthorBody, AddAuthorOptions, AddAuthorSearchResult, Author, AuthorStatus, MonitorType,
|
||||||
NewItemMonitorType,
|
NewItemMonitorType, ReadarrHistoryData, ReadarrHistoryEventType, ReadarrHistoryItem,
|
||||||
};
|
};
|
||||||
use crate::models::servarr_models::RootFolder;
|
use crate::models::servarr_models::{Quality, QualityWrapper, RootFolder};
|
||||||
|
use chrono::DateTime;
|
||||||
|
|
||||||
pub const AUTHOR_JSON: &str = r#"{
|
pub const AUTHOR_JSON: &str = r#"{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
@@ -83,6 +84,45 @@ pub mod test_utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn stale_readarr_history_item() -> ReadarrHistoryItem {
|
||||||
|
ReadarrHistoryItem {
|
||||||
|
id: 99,
|
||||||
|
source_title: "Stale source title".into(),
|
||||||
|
..ReadarrHistoryItem::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn quality_wrapper() -> QualityWrapper {
|
||||||
|
QualityWrapper { quality: quality() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn quality() -> Quality {
|
||||||
|
Quality {
|
||||||
|
name: "AZW3".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn readarr_history_item() -> ReadarrHistoryItem {
|
||||||
|
ReadarrHistoryItem {
|
||||||
|
id: 1,
|
||||||
|
author_id: 1,
|
||||||
|
book_id: 1,
|
||||||
|
source_title: "Test source title".into(),
|
||||||
|
quality: quality_wrapper(),
|
||||||
|
date: DateTime::from(DateTime::parse_from_rfc3339("2023-01-01T00:00:00Z").unwrap()),
|
||||||
|
event_type: ReadarrHistoryEventType::Grabbed,
|
||||||
|
data: readarr_history_data(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn readarr_history_data() -> ReadarrHistoryData {
|
||||||
|
ReadarrHistoryData {
|
||||||
|
dropped_path: Some("/nfs/nzbget/completed/books/Something/cool.azw3".to_owned()),
|
||||||
|
imported_path: Some("/nfs/books/Test Author/Book 1/Cool.azw3".to_owned()),
|
||||||
|
..ReadarrHistoryData::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_author_body() -> AddAuthorBody {
|
pub fn add_author_body() -> AddAuthorBody {
|
||||||
AddAuthorBody {
|
AddAuthorBody {
|
||||||
foreign_author_id: "test-foreign-id".to_owned(),
|
foreign_author_id: "test-foreign-id".to_owned(),
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ mod tests {
|
|||||||
#[case(ReadarrEvent::GetSecurityConfig, "/config/host")]
|
#[case(ReadarrEvent::GetSecurityConfig, "/config/host")]
|
||||||
#[case(ReadarrEvent::GetDiskSpace, "/diskspace")]
|
#[case(ReadarrEvent::GetDiskSpace, "/diskspace")]
|
||||||
#[case(ReadarrEvent::HealthCheck, "/health")]
|
#[case(ReadarrEvent::HealthCheck, "/health")]
|
||||||
|
#[case(ReadarrEvent::GetAuthorHistory(1), "/history/author")]
|
||||||
#[case(ReadarrEvent::GetLogs(500), "/log")]
|
#[case(ReadarrEvent::GetLogs(500), "/log")]
|
||||||
#[case(ReadarrEvent::GetMetadataProfiles, "/metadataprofile")]
|
#[case(ReadarrEvent::GetMetadataProfiles, "/metadataprofile")]
|
||||||
#[case(ReadarrEvent::GetQualityProfiles, "/qualityprofile")]
|
#[case(ReadarrEvent::GetQualityProfiles, "/qualityprofile")]
|
||||||
|
|||||||
Reference in new issue
Block a user