test: cover resolve_library_param and per-library ExifDao filter
Adds 9 unit tests around the library plumbing: - resolve_library_param branches (absent, empty/whitespace, numeric id, name, unknown id, unknown name) - Library::resolve symmetry with strip_root - ExifDao::get_all_with_date_taken in union and scoped modes Introduces SqliteExifDao::from_connection test constructor mirroring the existing preview_dao pattern so DAO tests can drive an in-memory SQLite. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -198,4 +198,85 @@ mod tests {
|
||||
let outside = lib.strip_root(Path::new("/etc/passwd"));
|
||||
assert!(outside.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn library_resolve_joins_under_root() {
|
||||
let lib = Library {
|
||||
id: 1,
|
||||
name: "main".into(),
|
||||
root_path: "/tmp/media".into(),
|
||||
};
|
||||
let abs = lib.resolve("2024/photo.jpg");
|
||||
assert_eq!(abs, PathBuf::from("/tmp/media/2024/photo.jpg"));
|
||||
}
|
||||
|
||||
fn state_with_libraries(libs: Vec<Library>) -> AppState {
|
||||
let mut state = AppState::test_state();
|
||||
state.libraries = libs;
|
||||
state
|
||||
}
|
||||
|
||||
fn sample_libraries() -> Vec<Library> {
|
||||
vec![
|
||||
Library {
|
||||
id: 1,
|
||||
name: "main".into(),
|
||||
root_path: "/tmp/main".into(),
|
||||
},
|
||||
Library {
|
||||
id: 7,
|
||||
name: "archive".into(),
|
||||
root_path: "/tmp/archive".into(),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn resolve_library_param_absent_is_union() {
|
||||
let state = state_with_libraries(sample_libraries());
|
||||
assert!(matches!(resolve_library_param(&state, None), Ok(None)));
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn resolve_library_param_empty_or_whitespace_is_union() {
|
||||
let state = state_with_libraries(sample_libraries());
|
||||
assert!(matches!(resolve_library_param(&state, Some("")), Ok(None)));
|
||||
assert!(matches!(
|
||||
resolve_library_param(&state, Some(" ")),
|
||||
Ok(None)
|
||||
));
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn resolve_library_param_numeric_id_matches() {
|
||||
let state = state_with_libraries(sample_libraries());
|
||||
let lib = resolve_library_param(&state, Some("7"))
|
||||
.expect("valid id")
|
||||
.expect("some library");
|
||||
assert_eq!(lib.id, 7);
|
||||
assert_eq!(lib.name, "archive");
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn resolve_library_param_name_matches() {
|
||||
let state = state_with_libraries(sample_libraries());
|
||||
let lib = resolve_library_param(&state, Some("main"))
|
||||
.expect("valid name")
|
||||
.expect("some library");
|
||||
assert_eq!(lib.id, 1);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn resolve_library_param_unknown_id_errs() {
|
||||
let state = state_with_libraries(sample_libraries());
|
||||
let err = resolve_library_param(&state, Some("999")).unwrap_err();
|
||||
assert!(err.contains("unknown library id"));
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn resolve_library_param_unknown_name_errs() {
|
||||
let state = state_with_libraries(sample_libraries());
|
||||
let err = resolve_library_param(&state, Some("missing")).unwrap_err();
|
||||
assert!(err.contains("unknown library name"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user