//! Tests for `read_story_name`.
//!
//! Stage-transition notification tests have moved to `tests_transition.rs`
//! which uses `spawn_stage_notification_subscriber` and real CRDT transitions.

use super::read_story_name;

// ── read_story_name ──────────────────────────────────────────────────────────

#[test]
fn read_story_name_reads_from_front_matter() {
    crate::db::ensure_content_store();
    crate::db::write_item_with_content(
        "9942_story_my_feature",
        "2_current",
        "---\nname: My Cool Feature\n---\n# Story\n",
        crate::db::ItemMeta::named("My Cool Feature"),
    );

    let tmp = tempfile::tempdir().unwrap();
    let name = read_story_name(tmp.path(), "2_current", "9942_story_my_feature");
    assert_eq!(name, "My Cool Feature");
}

#[test]
fn read_story_name_returns_none_for_missing_file() {
    crate::db::ensure_content_store();
    let tmp = tempfile::tempdir().unwrap();
    let name = read_story_name(tmp.path(), "2_current", "99_story_missing_notif_test");
    assert!(name.is_empty());
}

#[test]
fn read_story_name_returns_none_for_missing_name_field() {
    crate::db::ensure_content_store();
    crate::db::write_item_with_content(
        "9943_story_no_name",
        "2_current",
        "---\ncoverage_baseline: 50%\n---\n# Story\n",
        crate::db::ItemMeta::default(),
    );

    let tmp = tempfile::tempdir().unwrap();
    let name = read_story_name(tmp.path(), "2_current", "9943_story_no_name");
    assert!(name.is_empty());
}
