use super::{build_router, init_app_state, AuthState, CorsConfig};
use axum::body::Body;
use axum::http::{Request, StatusCode};
use tower::ServiceExt;
fn test_router() -> axum::Router {
let dir = tempfile::tempdir().expect("test: temp dir");
let state = init_app_state(
dir.path().to_str().expect("test: utf-8 path"),
velesdb_core::config::VelesConfig::default(),
)
.expect("test: init app state");
build_router(state, AuthState::new(Vec::new()), 0, &CorsConfig::default())
.expect("test: build router")
}
#[tokio::test]
async fn swagger_ui_index_serves_html() {
let app = test_router();
let response = app
.oneshot(
Request::builder()
.uri("/swagger-ui/")
.body(Body::empty())
.expect("test: build request"),
)
.await
.expect("test: request failed");
assert_eq!(response.status(), StatusCode::OK);
let content_type = response
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or_default();
assert!(
content_type.contains("text/html"),
"expected text/html, got {content_type}"
);
}
#[tokio::test]
async fn swagger_ui_serves_the_openapi_document_it_points_at() {
let app = test_router();
let response = app
.oneshot(
Request::builder()
.uri("/api-docs/openapi.json")
.body(Body::empty())
.expect("test: build request"),
)
.await
.expect("test: request failed");
assert_eq!(response.status(), StatusCode::OK);
}