From df94010d212c3c49e18d672e499466c9372d64bb Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 19 Dec 2025 14:20:51 -0500 Subject: [PATCH] Fix tests and improve memories date error log --- src/auth.rs | 1 - src/files.rs | 12 ++++++++++-- src/geo.rs | 1 + src/lib.rs | 2 ++ src/memories.rs | 15 +++++++++++---- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index 9012e4f..9ee09bf 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -64,7 +64,6 @@ pub async fn login( #[cfg(test)] mod tests { - use super::*; use crate::testhelpers::{BodyReader, TestUserDao}; diff --git a/src/files.rs b/src/files.rs index b566b76..bf51abd 100644 --- a/src/files.rs +++ b/src/files.rs @@ -819,12 +819,12 @@ impl Handler for StreamActor { #[cfg(test)] mod tests { + use super::*; + use crate::database::DbError; use std::collections::HashMap; use std::env; use std::fs::File; - use super::*; - struct FakeFileSystem { files: HashMap>, err: bool, @@ -955,6 +955,14 @@ mod tests { fn get_camera_makes(&mut self) -> Result, crate::database::DbError> { Ok(Vec::new()) } + + fn update_file_path(&mut self, old_path: &str, new_path: &str) -> Result<(), DbError> { + Ok(()) + } + + fn get_all_file_paths(&mut self) -> Result, DbError> { + Ok(Vec::new()) + } } mod api { diff --git a/src/geo.rs b/src/geo.rs index eea7e0a..46cc1dc 100644 --- a/src/geo.rs +++ b/src/geo.rs @@ -12,6 +12,7 @@ use std::f64; /// /// # Example /// ``` +/// use image_api::geo::haversine_distance; /// let distance = haversine_distance(37.7749, -122.4194, 34.0522, -118.2437); /// // Distance between San Francisco and Los Angeles (~559 km) /// ``` diff --git a/src/lib.rs b/src/lib.rs index 6933068..7729d98 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,8 @@ pub mod service; pub mod state; pub mod tags; pub mod video; +#[cfg(test)] +pub mod testhelpers; // Re-export commonly used types pub use data::{Claims, ThumbnailRequest}; diff --git a/src/memories.rs b/src/memories.rs index e723200..d941cd2 100644 --- a/src/memories.rs +++ b/src/memories.rs @@ -379,7 +379,7 @@ fn collect_exif_memories( let file_date = timestamp_to_naive_date(*date_taken_ts, client_timezone)?; // Check if matches memory criteria - if !is_memories_match(file_date, now, span_mode, years_back) { + if !is_memories_match(file_path, file_date, now, span_mode, years_back) { return None; } @@ -438,7 +438,13 @@ fn collect_filesystem_memories( // Use existing get_file_date_info() for filename/metadata fallback let (file_date, created, modified) = get_file_date_info(entry.path(), client_timezone)?; - if is_memories_match(file_date, now, span_mode, years_back) { + if is_memories_match( + entry.path().to_str().unwrap_or("Unknown"), + file_date, + now, + span_mode, + years_back, + ) { let path_relative = entry.path().strip_prefix(base).ok()?.to_str()?.to_string(); Some(( @@ -575,6 +581,7 @@ pub async fn list_memories( } fn is_memories_match( + file_path: &str, file_date: NaiveDate, today: NaiveDate, span: MemoriesSpan, @@ -586,8 +593,8 @@ fn is_memories_match( let years_diff = (today.year() - file_date.year()).unsigned_abs(); if years_diff > years_back { warn!( - "File date is too far in the past: {:?} vs {:?}", - file_date, today + "File ({}) date is too far in the past: {:?} vs {:?}", + file_path, file_date, today ); return false; }