use super::debug_contracts::LoggingSchemaDebugReport;
use super::debug_service_error::LoggingSchemaDebugReportError;
use super::debug_service_result_from_stage_output_assembly::build_logging_schema_debug_report_service_result_from_stage_output_assembly;
use super::debug_service_result_stage_input_assembly::build_debug_service_result_stage_input_assembly;
use super::debug_service_result_stage_input_contracts::LoggingSchemaDebugReportServiceResultStageInput;
use super::debug_service_result_stage_output_assembly::build_debug_service_result_stage_output_assembly;
use super::debug_snapshot_error::LoggingSchemaSnapshotError;
pub(super) fn build_logging_schema_debug_report_service_result(
report_result: Result<LoggingSchemaDebugReport, LoggingSchemaSnapshotError>,
) -> Result<LoggingSchemaDebugReport, LoggingSchemaDebugReportError> {
let stage_input: LoggingSchemaDebugReportServiceResultStageInput =
build_debug_service_result_stage_input_assembly(report_result);
let stage = build_debug_service_result_stage_output_assembly(stage_input);
build_logging_schema_debug_report_service_result_from_stage_output_assembly(stage)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::api::schema::debug_report_test_fixtures::build_empty_logging_schema_debug_report_for_tests;
use crate::api::schema::debug_service_result_test_helpers::{
assert_fetch_snapshot_relations_service_error_for_tests,
assert_successful_service_report_result_for_tests,
};
#[test]
fn service_result_assembly_preserves_successful_report() {
let report = build_empty_logging_schema_debug_report_for_tests();
let result = build_logging_schema_debug_report_service_result(Ok(report));
assert_successful_service_report_result_for_tests(result, "service result assembly");
}
#[test]
fn service_result_assembly_maps_snapshot_error_to_service_error() {
let result = build_logging_schema_debug_report_service_result(Err(
LoggingSchemaSnapshotError::FetchRelations(sqlx::Error::Protocol(
"relation query failed".to_string(),
)),
));
assert_fetch_snapshot_relations_service_error_for_tests(
result,
None,
"service result assembly",
);
}
}