athena_rs 3.18.0

Hyper performant polyglot Database driver
Documentation
//! `/debug/schema` response orchestration helpers.
//!
//! This module keeps route response flow thin by delegating report-result
//! stage-input assembly to `debug_response_stage_input_assembly`, stage-output
//! assembly to `debug_response_stage_output_assembly` and final
//! stage-output handoff to the stable facade in
//! `debug_response_from_stage_output_assembly`, which delegates to
//! `debug_response_stage_output_handoff_assembly`.

use actix_web::HttpResponse;

use crate::AppState;

use super::debug_response_from_stage_output_assembly::build_debug_response_from_stage_output_assembly;
use super::debug_response_stage_input_assembly::build_debug_response_stage_input_assembly;
use super::debug_response_stage_output_assembly::build_debug_response_stage_output_assembly;
use super::debug_service::load_logging_schema_debug_report;

/// Builds the route response for `/debug/schema` after auth has succeeded.
pub(super) async fn debug_schema_response(app_state: &AppState) -> HttpResponse {
    let stage_input = build_debug_response_stage_input_assembly(
        load_logging_schema_debug_report(app_state).await,
    );
    let stage = build_debug_response_stage_output_assembly(stage_input);
    build_debug_response_from_stage_output_assembly(stage)
}

#[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 response orchestration returns a stable envelope when logging is not configured.
    async fn debug_schema_response_returns_service_unavailable_when_logging_client_missing() {
        let app_state = AppState::default();

        let response = debug_schema_response(&app_state).await;
        assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE);
        let body = response_json_for_tests(response, "debug-response missing logging").await;

        assert_error_payload_for_tests(
            &body,
            "Logging store unavailable",
            &["No athena logging client is configured."],
            "debug-response missing logging",
        );
    }

    #[actix_web::test]
    /// Ensures response orchestration returns a stable envelope when logging is configured but disconnected.
    async fn debug_schema_response_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 = debug_schema_response(&app_state).await;
        assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE);
        let body = response_json_for_tests(response, "debug-response disconnected logging").await;

        assert_error_payload_for_tests(
            &body,
            "Logging store unavailable",
            &["Logging client 'athena_logging' is not connected."],
            "debug-response disconnected logging",
        );
    }
}