test(readarr): add shared network test factories

This commit is contained in:
Dark-Alex-17 committed 2026-08-26 14:23:15 -06:00
1 parent 84eba9beac
commit 817fe4d135
4 files changed
+72 -40

No files matched your search

@@ -4,8 +4,11 @@ mod tests {
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 crate::network::readarr_network::readarr_network_test_utils::test_utils::{
AUTHOR_JSON, stale_author,
};
use pretty_assertions::assert_eq;
use serde_json::json;
use serde_json::{Value, json};
#[tokio::test]
async fn test_handle_list_authors_event() {
@@ -74,20 +77,7 @@ mod tests {
#[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 authors_json = json!([serde_json::from_str::<Value>(AUTHOR_JSON).unwrap()]);
let (mock, app, _server) = MockServarrApi::get()
.returns(authors_json)
.build_for(ReadarrEvent::ListAuthors)
@@ -111,21 +101,7 @@ mod tests {
#[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 stale_authors = vec![stale_author()];
let (mock, app, _server) = MockServarrApi::get()
.returns(json!({}))
.status(500)
+4
View File
@@ -15,6 +15,10 @@ mod system;
#[path = "readarr_network_tests.rs"]
mod readarr_network_tests;
#[cfg(test)]
#[path = "readarr_network_test_utils.rs"]
pub mod readarr_network_test_utils;
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum ReadarrEvent {
AddRootFolder(AddReadarrRootFolderBody),
@@ -0,0 +1,61 @@
#[cfg(test)]
#[allow(dead_code)]
pub mod test_utils {
use crate::models::readarr_models::{Author, AuthorStatus, NewItemMonitorType};
use crate::models::servarr_models::RootFolder;
pub const AUTHOR_JSON: &str = r#"{
"id": 1,
"authorName": "Test Author",
"foreignAuthorId": "test-foreign-id",
"status": "continuing",
"overview": "some interesting description of the author",
"authorType": "Person",
"disambiguation": "American novelist",
"path": "/nfs/books/Test Author",
"rootFolderPath": "/nfs/books/",
"qualityProfileId": 1,
"metadataProfileId": 1,
"monitored": true,
"monitorNewItems": "all",
"genres": ["science fiction"],
"tags": [1],
"ratings": { "votes": 15, "value": 8.4, "popularity": 1.2 },
"statistics": {
"bookCount": 3,
"bookFileCount": 2,
"totalBookCount": 3,
"availableBookCount": 2,
"sizeOnDisk": 12345,
"percentOfBooks": 66.6
}
}"#;
pub fn stale_author() -> Author {
Author {
id: 99,
author_name: "Stale Author".into(),
foreign_author_id: "foreign-author-99".to_owned(),
status: AuthorStatus::Continuing,
path: "/nfs/books/Stale Author".to_owned(),
root_folder_path: Some("/nfs/books/".to_owned()),
quality_profile_id: 1,
metadata_profile_id: 1,
monitored: true,
monitor_new_items: NewItemMonitorType::All,
genres: vec![],
tags: vec![],
..Author::default()
}
}
pub fn stale_root_folder() -> RootFolder {
RootFolder {
id: 99,
path: "/stale".to_owned(),
accessible: false,
free_space: 1,
unmapped_folders: None,
}
}
}
@@ -6,20 +6,11 @@ mod tests {
use crate::models::servarr_models::RootFolder;
use crate::network::network_tests::test_utils::{MockServarrApi, test_network};
use crate::network::readarr_network::ReadarrEvent;
use crate::network::readarr_network::readarr_network_test_utils::test_utils::stale_root_folder;
use bimap::BiMap;
use pretty_assertions::assert_eq;
use serde_json::json;
fn stale_root_folder() -> RootFolder {
RootFolder {
id: 99,
path: "/stale".to_owned(),
accessible: false,
free_space: 1,
unmapped_folders: None,
}
}
#[tokio::test]
async fn test_handle_add_readarr_root_folder_event() {
let expected_add_root_folder_body = AddReadarrRootFolderBody {