From d0289a298fc89fd373372e544be31e96787afa5d Mon Sep 17 00:00:00 2001 From: Levi McDonough Date: Fri, 16 Oct 2026 10:54:14 -0400 Subject: [PATCH] test(search): cover title edge cases in session title resolution Adds mock tests for resolve_session_titles covering a whitespace-only session title (falls back to the date), a title with surrounding spaces (returned trimmed), a mixed batch of titled, untitled and unknown ids in one call, and duplicate ids in the input. Refs #431. Generated with Claude Code Co-Authored-By: Claude --- .../src/search/session_title_mock_tests.rs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/entity_api/src/search/session_title_mock_tests.rs b/entity_api/src/search/session_title_mock_tests.rs index 31ff5dd3..93dc0298 100644 --- a/entity_api/src/search/session_title_mock_tests.rs +++ b/entity_api/src/search/session_title_mock_tests.rs @@ -84,3 +84,67 @@ async fn no_ids_issue_no_query() { assert!(titles.is_empty()); } + +#[tokio::test] +async fn a_whitespace_only_session_title_falls_back_to_the_date() { + // Trimmed to empty, so compose_display_title is None and the date fallback applies. + let s = session(Some(" \t\n "), NaiveDate::from_ymd_opt(2026, 3, 9).unwrap()); + let id = s.id; + let db = db_with(vec![s]); + + let titles = resolve_session_titles(&db, &[id]).await.unwrap(); + + assert_eq!( + titles.get(&id).map(String::as_str), + Some("Coaching session — 2026-03-09") + ); +} + +#[tokio::test] +async fn a_title_with_surrounding_spaces_is_returned_trimmed() { + let s = session( + Some(" Kickoff "), + NaiveDate::from_ymd_opt(2026, 3, 9).unwrap(), + ); + let id = s.id; + let db = db_with(vec![s]); + + let titles = resolve_session_titles(&db, &[id]).await.unwrap(); + + assert_eq!(titles.get(&id).map(String::as_str), Some("Kickoff")); +} + +#[tokio::test] +async fn a_mixed_batch_resolves_known_ids_and_omits_the_unknown() { + // One call: titled session, untitled session, and an id never inserted. + let titled = session(Some("Intro"), NaiveDate::from_ymd_opt(2026, 3, 9).unwrap()); + let untitled = session(None, NaiveDate::from_ymd_opt(2026, 4, 1).unwrap()); + let unknown_id = Id::new_v4(); + let titled_id = titled.id; + let untitled_id = untitled.id; + let db = db_with(vec![titled, untitled]); + + let titles = resolve_session_titles(&db, &[titled_id, untitled_id, unknown_id]) + .await + .unwrap(); + + assert_eq!( + titles, + HashMap::from([ + (titled_id, "Intro".to_string()), + (untitled_id, "Coaching session — 2026-04-01".to_string()), + ]) + ); +} + +#[tokio::test] +async fn duplicate_ids_in_the_input_resolve_to_one_map_entry() { + // Same id twice: must not panic and must collapse to a single entry. + let s = session(Some("Intro"), NaiveDate::from_ymd_opt(2026, 3, 9).unwrap()); + let id = s.id; + let db = db_with(vec![s]); + + let titles = resolve_session_titles(&db, &[id, id]).await.unwrap(); + + assert_eq!(titles, HashMap::from([(id, "Intro".to_string())])); +}