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;
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]
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]
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",
);
}
}