Files
furumi-web/src/podcasts/tests.rs
T
sanapachandClaude Opus 5.5 7f07cb206a Add a PostgreSQL podcast store with relay import
PodcastStore implements the music_dht::podcast contract per account:
catalog, feed aliases, episodes with a derived season view, the
subscription, share and progress registers, listening sessions and the
local-only fetch state. Received operations, snapshot records and local
actions share one apply path (materializers plus merge functions) under
a per-account advisory lock. Local actions append their operation to the
device-sync log with the next stamp of the web device and apply exactly
that operation in the same transaction.

Migration m_0056 creates the tables; m_0057 imports the registers that
0.13 kept in furumusic__fed_podcast_relay and the catalog rows of the
episode references in the operation log. The relay table is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:12:38 +02:00

82 lines
2.7 KiB
Rust

//! Pure unit tests of the podcast store helpers (no database).
use music_dht::podcast::ProgressStatus;
use super::*;
#[test]
fn search_text_never_matches_across_title_and_description() {
let norm = episode_search_norm("Hello, World!", Some("WORLD peace"));
assert_eq!(norm, "hello world\nworld peace");
// A needle is itself normalized, so it never contains the separator.
let needle = music_dht::normalize_name("world world");
assert!(!norm.contains(&needle));
assert!(norm.contains(&music_dht::normalize_name("WORLD PEACE")));
assert_eq!(episode_search_norm("Only", None), "only\n");
}
#[test]
fn progress_status_round_trips_through_sql() {
for status in [
ProgressStatus::NotStarted,
ProgressStatus::InProgress,
ProgressStatus::Completed,
] {
assert_eq!(status_from_sql(status_to_sql(status)), status);
}
// The CHECK constraint admits exactly these values.
for sql in schema::CREATE_PODCAST_STORE {
if sql.contains("CREATE TABLE IF NOT EXISTS furumusic__podcast_progress (") {
for value in ["not_started", "in_progress", "completed"] {
assert!(sql.contains(&format!("'{value}'")));
}
}
}
}
#[test]
fn generations_beyond_bigint_are_rejected() {
assert_eq!(generation_to_sql(0).unwrap(), 0);
assert_eq!(generation_to_sql(i64::MAX as u64).unwrap(), i64::MAX);
assert!(matches!(
generation_to_sql(i64::MAX as u64 + 1),
Err(PodcastStoreError::Invalid(_))
));
assert_eq!(generation_from_sql(-1), 0);
}
#[test]
fn contract_numbers_outside_u32_are_dropped() {
assert_eq!(u32_from_sql(Some(7)), Some(7));
assert_eq!(u32_from_sql(Some(-1)), None);
assert_eq!(u32_from_sql(Some(i64::from(u32::MAX) + 1)), None);
assert_eq!(u32_from_sql(None), None);
}
#[test]
fn progress_columns_are_prefixed() {
assert_eq!(
progress_columns("g", "g_"),
"g.episode_id AS g_episode_id, g.podcast_id AS g_podcast_id, \
g.position_ms AS g_position_ms, g.status AS g_status, \
g.generation AS g_generation, g.session_id AS g_session_id, \
g.hlc_ms AS g_hlc_ms, g.device_id AS g_device_id, g.op_id AS g_op_id"
);
}
#[test]
fn queries_sort_undated_and_unnumbered_episodes_last() {
for sort in [
EpisodeSort::NewestFirst,
EpisodeSort::OldestFirst,
EpisodeSort::EpisodeNumber,
EpisodeSort::EpisodeNumberDesc,
] {
let order = queries::order_by_for_tests(sort);
assert!(
order.starts_with("e.published_at_ms IS NULL") || order.starts_with("e.season IS NULL")
);
assert!(order.ends_with("e.episode_id"), "{order}");
}
}