Files
doctate/server/tests/health_test.rs
T
Brummel 5435b60b80 Refactor config to use test_default
Introduced a `test_default` method to `Config` to provide sane defaults
for integration tests. This refactors several test files to use this new
method, reducing boilerplate and improving maintainability.

Added `LLM_TIMEOUT_SECONDS` to the environment variables and `Config`
struct.
2026-04-15 19:07:58 +02:00

56 lines
1.3 KiB
Rust

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<Config> {
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);
}