Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions entity_api/src/search/session_title_mock_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())]));
}
Loading