domain crate code quality cleanup
strip all comments, extract tests to tests/ dirs, remove #[allow(clippy::...)], extract magic numbers to constants, refactor schedule engine private methods to use param structs, add Default impls, clippy.toml for persistence constructors
This commit is contained in:
122
crates/domain/src/models/tests/library.rs
Normal file
122
crates/domain/src/models/tests/library.rs
Normal file
@@ -0,0 +1,122 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn library_item_new_generates_composite_id() {
|
||||
let item = LibraryItem::new("jellyfin", "abc123", "Test Movie", ContentType::Movie, 7200, "2026-03-19T00:00:00Z");
|
||||
assert_eq!(item.id(), "jellyfin::abc123");
|
||||
assert_eq!(item.provider_id(), "jellyfin");
|
||||
assert_eq!(item.external_id(), "abc123");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn library_item_new_defaults_optional_fields() {
|
||||
let item = LibraryItem::new("jf", "1", "Movie", ContentType::Movie, 3600, "2026-01-01");
|
||||
assert!(item.series_name().is_none());
|
||||
assert!(item.season_number().is_none());
|
||||
assert!(item.genres().is_empty());
|
||||
assert!(item.tags().is_empty());
|
||||
assert!(item.collection_id().is_none());
|
||||
assert!(item.thumbnail_url().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn library_item_from_persistence_all_fields() {
|
||||
let item = LibraryItem::from_persistence(
|
||||
"jf::abc".into(),
|
||||
"jf".into(),
|
||||
"abc".into(),
|
||||
"Breaking Bad S01E01".into(),
|
||||
ContentType::Episode,
|
||||
2700,
|
||||
Some("Breaking Bad".into()),
|
||||
Some(1),
|
||||
Some(1),
|
||||
Some(2008),
|
||||
vec!["Drama".into()],
|
||||
vec!["tv".into()],
|
||||
Some("col-1".into()),
|
||||
Some("TV Shows".into()),
|
||||
Some("tvshows".into()),
|
||||
Some("http://thumb.jpg".into()),
|
||||
"2026-03-19T00:00:00Z".into(),
|
||||
);
|
||||
assert_eq!(item.series_name(), Some("Breaking Bad"));
|
||||
assert_eq!(item.season_number(), Some(1));
|
||||
assert_eq!(item.year(), Some(2008));
|
||||
assert_eq!(item.collection_name(), Some("TV Shows"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn library_collection_new_and_getters() {
|
||||
let col = LibraryCollection::new("col-1", "Movies");
|
||||
assert_eq!(col.id(), "col-1");
|
||||
assert_eq!(col.name(), "Movies");
|
||||
assert!(col.collection_type().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn library_collection_from_persistence() {
|
||||
let col = LibraryCollection::from_persistence(
|
||||
"col-2".into(),
|
||||
"TV Shows".into(),
|
||||
Some("tvshows".into()),
|
||||
);
|
||||
assert_eq!(col.collection_type(), Some("tvshows"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync_result_success() {
|
||||
let r = LibrarySyncResult::new("jellyfin", 150, 1200);
|
||||
assert_eq!(r.provider_id(), "jellyfin");
|
||||
assert_eq!(r.items_found(), 150);
|
||||
assert_eq!(r.duration_ms(), 1200);
|
||||
assert!(r.error().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync_result_with_error() {
|
||||
let r = LibrarySyncResult::with_error("jellyfin", 500, "connection refused");
|
||||
assert_eq!(r.items_found(), 0);
|
||||
assert_eq!(r.error(), Some("connection refused"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync_log_entry_new_defaults() {
|
||||
let entry = LibrarySyncLogEntry::new(1, "jellyfin", "2026-03-19T00:00:00Z");
|
||||
assert_eq!(entry.id(), 1);
|
||||
assert_eq!(entry.status(), SYNC_STATUS_RUNNING);
|
||||
assert_eq!(entry.items_found(), 0);
|
||||
assert!(entry.finished_at().is_none());
|
||||
assert!(entry.error_msg().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_summary_getters() {
|
||||
let show = ShowSummary::from_persistence(
|
||||
"Breaking Bad".into(),
|
||||
62,
|
||||
5,
|
||||
Some("http://thumb.jpg".into()),
|
||||
vec!["Drama".into(), "Crime".into()],
|
||||
);
|
||||
assert_eq!(show.series_name(), "Breaking Bad");
|
||||
assert_eq!(show.episode_count(), 62);
|
||||
assert_eq!(show.season_count(), 5);
|
||||
assert_eq!(show.genres().len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn season_summary_getters() {
|
||||
let season = SeasonSummary::from_persistence(1, 7, Some("http://s1.jpg".into()));
|
||||
assert_eq!(season.season_number(), 1);
|
||||
assert_eq!(season.episode_count(), 7);
|
||||
assert_eq!(season.thumbnail_url(), Some("http://s1.jpg"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn season_summary_new_defaults() {
|
||||
let season = SeasonSummary::new(3, 13);
|
||||
assert_eq!(season.season_number(), 3);
|
||||
assert_eq!(season.episode_count(), 13);
|
||||
assert!(season.thumbnail_url().is_none());
|
||||
}
|
||||
Reference in New Issue
Block a user