#![allow(
clippy::unwrap_used,
clippy::expect_used,
reason = "test code — panics are acceptable failures"
)]
mod support;
use axum::http::StatusCode;
#[tokio::test]
async fn test_openapi_json_returns_200() {
let state = support::build_test_state().await;
let app = support::test_router(state).await;
let resp = support::oneshot_get(app, "/openapi.json").await;
assert_eq!(resp.status(), StatusCode::OK);
}
#[tokio::test]
async fn test_openapi_has_security_schemes() {
let state = support::build_test_state().await;
let app = support::test_router(state).await;
let resp = support::oneshot_get(app, "/openapi.json").await;
let body = support::body_json(resp).await;
let schemes = &body["components"]["securitySchemes"];
assert!(
schemes["BearerAuth"].is_object(),
"BearerAuth security scheme missing: {body}"
);
assert!(
schemes["ApiKeyAuth"].is_object(),
"ApiKeyAuth security scheme missing: {body}"
);
}
#[tokio::test]
async fn test_openapi_info() {
let state = support::build_test_state().await;
let app = support::test_router(state).await;
let resp = support::oneshot_get(app, "/openapi.json").await;
let body = support::body_json(resp).await;
assert_eq!(body["info"]["title"], "Cognee API");
assert_eq!(body["info"]["version"], "1.0.0");
}
#[tokio::test]
async fn test_openapi_advertises_p5_paths() {
let state = support::build_test_state().await;
let app = support::test_router(state).await;
let resp = support::oneshot_get(app, "/openapi.json").await;
let body = support::body_json(resp).await;
let paths = body["paths"]
.as_object()
.expect("openapi document must have a `paths` object");
let required = "/api/v1/settings";
assert!(
paths.contains_key(required),
"openapi `paths` must advertise `{required}`; only saw: {:?}",
paths.keys().collect::<Vec<_>>()
);
}