//! Shared test utilities for chat handler tests.
//!
//! Import with `use crate::chat::test_helpers::write_story_file;`

use std::path::Path;

/// Write a work-item into the content store and CRDT for testing.
///
/// Also creates the filesystem directory structure and file so that tests
/// which still verify filesystem state (e.g. assign tests that check the
/// physical file) continue to work.
///
/// Uses `write_item_with_content` to populate both the in-memory content
/// store and the CRDT, matching the production write path.
pub(crate) fn write_story_file(root: &Path, stage: &str, filename: &str, content: &str) {
    let dir = root.join(".huskies/work").join(stage);
    std::fs::create_dir_all(&dir).unwrap();
    std::fs::write(dir.join(filename), content).unwrap();

    let story_id = filename.trim_end_matches(".md");
    crate::db::ensure_content_store();
    crate::db::write_item_with_content(story_id, stage, content);
}
