use axum::Router;
use event_service::{
api::rest::{create_router, AppState},
config::Config,
db,
matching::ProbabilisticMatcher,
search::SearchEngine,
};
pub async fn create_test_app_state() -> AppState {
let config = Config::from_env().expect("Failed to load test config");
let db = db::create_connection(&config.database)
.await
.expect("Failed to connect to database");
let tmp = tempfile::tempdir().expect("tempdir for search index");
let search_engine =
SearchEngine::new(tmp.path()).expect("Failed to create search engine");
let matcher = ProbabilisticMatcher::new(config.matching.clone());
std::mem::forget(tmp);
AppState::new(db, search_engine, matcher, config)
}
pub async fn create_test_router() -> Router {
let state = create_test_app_state().await;
create_router(state)
}
pub fn unique_event_name(suffix: &str) -> String {
use chrono::Utc;
let ts = Utc::now().timestamp_micros();
format!("TestEvent_{suffix}_{ts}")
}