athena_rs 3.22.1

Hyper performant polyglot Database driver
Documentation
//! `/debug/schema` handler output-handoff assembly helpers.
//!
//! This module owns handing authorized debug-schema requests into route
//! response orchestration.

use actix_web::HttpResponse;

use crate::AppState;

use super::debug_response::debug_schema_response;

/// Builds one `/debug/schema` handler response after authorization succeeds.
pub(super) async fn build_debug_schema_handler_response(app_state: &AppState) -> HttpResponse {
    debug_schema_response(app_state).await
}

#[cfg(test)]
mod tests {
    use actix_web::http::StatusCode;

    use super::*;
    use crate::api::schema::debug_response_test_helpers::{
        assert_error_payload_for_tests, response_json_for_tests,
    };

    #[actix_web::test]
    /// Ensures authorized handler handoff reports missing logging-store configuration consistently.
    async fn handler_output_handoff_returns_service_unavailable_when_logging_client_missing() {
        let app_state = AppState::default();

        let response = build_debug_schema_handler_response(&app_state).await;
        assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE);
        let body =
            response_json_for_tests(response, "handler output handoff missing logging client")
                .await;

        assert_error_payload_for_tests(
            &body,
            "Logging store unavailable",
            &["No athena logging client is configured."],
            "handler output handoff missing logging client",
        );
    }

    #[actix_web::test]
    /// Ensures authorized handler handoff reports disconnected logging-store clients consistently.
    async fn handler_output_handoff_returns_service_unavailable_when_logging_client_disconnected() {
        let mut app_state = AppState::default();
        app_state.logging_client_name = Some("athena_logging".to_string());

        let response = build_debug_schema_handler_response(&app_state).await;
        assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE);
        let body = response_json_for_tests(
            response,
            "handler output handoff disconnected logging client",
        )
        .await;

        assert_error_payload_for_tests(
            &body,
            "Logging store unavailable",
            &["Logging client 'athena_logging' is not connected."],
            "handler output handoff disconnected logging client",
        );
    }
}