//! Shared test utilities: helpers to insert fake sample rows for use in unit tests. use crate::db::Database; use crate::error::unix_now; use crate::id_types::{NodeId, VfsId}; /// Insert a fake sample row for testing (no actual file on disk). pub fn insert_fake_sample(db: &Database, hash: &str) { let now = unix_now(); db.conn() .execute( "INSERT OR IGNORE INTO samples (hash, original_name, file_extension, file_size, import_date, last_modified) VALUES (?1, ?2, 'wav', 100, ?3, ?4)", rusqlite::params![hash, format!("{hash}.wav"), now, now], ) .unwrap(); } /// Insert a fake sample with analysis data and a VFS link in one call. /// /// Combines `insert_fake_sample`, `save_analysis`, and `create_sample_link` for /// tests that need samples with BPM/key/duration/classification populated. #[allow(clippy::too_many_arguments)] pub fn insert_sample_with_analysis( db: &Database, hash: &str, name: &str, vfs_id: VfsId, bpm: Option, key: Option<&str>, duration: Option, classification: Option<&str>, ) -> NodeId { insert_fake_sample(db, hash); let result = crate::analysis::AnalysisResult { hash: hash.to_string(), duration: duration.unwrap_or(1.0), sample_rate: 44100, channels: 1, peak_db: Some(-3.0), rms_db: None, lufs: None, bpm, musical_key: key.map(String::from), is_loop: None, spectral_centroid: None, spectral_flatness: None, spectral_rolloff: None, zero_crossing_rate: None, onset_strength: None, classification: classification.map(|c| c.parse().unwrap()), fingerprint: None, spectral_bandwidth: None, centroid_variance: None, crest_factor: None, attack_time: None, classification_confidence: None, }; crate::analysis::save_analysis(db, &result).unwrap(); crate::vfs::create_sample_link(db, vfs_id, None, name, hash).unwrap() }