use axum::{ body::Body, http::{Method, Request, StatusCode}, }; use tower::ServiceExt; fn build_app() -> axum::Router { app_operation_system::build_router(app_operation_system::app::test_state()) } #[tokio::test] async fn operation_system_router_exposes_health_endpoint() { let response = build_app() .oneshot( Request::builder() .method(Method::GET) .uri("/api/health") .body(Body::empty()) .expect("request should build"), ) .await .expect("router should answer request"); assert_eq!(response.status(), StatusCode::OK); } /// Verify the station collection route is registered (DELETE on the collection /// isn't a real method, so axum should answer METHOD_NOT_ALLOWED, not 404). #[tokio::test] async fn operation_system_router_exposes_station_collection() { let response = build_app() .oneshot( Request::builder() .method(Method::DELETE) .uri("/api/station") .body(Body::empty()) .expect("request should build"), ) .await .expect("router should answer request"); assert_eq!(response.status(), StatusCode::METHOD_NOT_ALLOWED); } #[tokio::test] async fn operation_system_router_exposes_segment_collection() { let response = build_app() .oneshot( Request::builder() .method(Method::DELETE) .uri("/api/segment") .body(Body::empty()) .expect("request should build"), ) .await .expect("router should answer request"); assert_eq!(response.status(), StatusCode::METHOD_NOT_ALLOWED); } /// Runtime overview is GET-only; a POST should be METHOD_NOT_ALLOWED rather /// than 404 — proving the route is registered. #[tokio::test] async fn operation_system_router_exposes_runtime_overview() { let response = build_app() .oneshot( Request::builder() .method(Method::POST) .uri("/api/runtime/overview") .body(Body::empty()) .expect("request should build"), ) .await .expect("router should answer request"); assert_eq!(response.status(), StatusCode::METHOD_NOT_ALLOWED); } /// Control endpoints are POST-only; GETting one should be METHOD_NOT_ALLOWED. #[tokio::test] async fn operation_system_router_exposes_control_batch_routes() { let response = build_app() .oneshot( Request::builder() .method(Method::GET) .uri("/api/control/segment/batch-start-auto") .body(Body::empty()) .expect("request should build"), ) .await .expect("router should answer request"); assert_eq!(response.status(), StatusCode::METHOD_NOT_ALLOWED); } /// Event timeline endpoint is GET-only — POST should be METHOD_NOT_ALLOWED. #[tokio::test] async fn operation_system_router_exposes_event_timeline() { let response = build_app() .oneshot( Request::builder() .method(Method::POST) .uri("/api/event") .body(Body::empty()) .expect("request should build"), ) .await .expect("router should answer request"); assert_eq!(response.status(), StatusCode::METHOD_NOT_ALLOWED); }