use std::sync::Arc; use axum::body::Body; use axum::http::{Request, StatusCode}; use tower::util::ServiceExt; use doctate_server::config::Config; fn test_config() -> Arc { Arc::new(Config { data_path: "/tmp/doctate-test".into(), log_path: "/tmp/doctate-test/logs".into(), ..Config::test_default() }) } #[tokio::test] async fn health_returns_ok() { let app = doctate_server::create_router(test_config()); let response = app .oneshot( Request::builder() .uri("/api/health") .body(Body::empty()) .unwrap(), ) .await .unwrap(); assert_eq!(response.status(), StatusCode::OK); } #[tokio::test] async fn health_returns_json_with_status() { let app = doctate_server::create_router(test_config()); let response = app .oneshot( Request::builder() .uri("/api/health") .body(Body::empty()) .unwrap(), ) .await .unwrap(); let body = axum::body::to_bytes(response.into_body(), usize::MAX) .await .unwrap(); let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); assert_eq!(json["status"], "ok"); assert_eq!(json["port"], 3000); }