From 50ce8cb96b2b218751c2fc2a6b19372f51846acc Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Mon, 14 Jul 2025 19:34:59 +0300 Subject: feat: rewrite in rust --- src/lib.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/lib.rs (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..f51483b --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,31 @@ +use axum::{Router, routing::get}; + +pub fn app() -> Router { + Router::new() + .route("/health", get(crate::health::health_handler)) +} + +pub mod users; +pub mod locations; +pub mod weather_thresholds; +pub mod notifications; +pub mod weather_poller; +pub mod health; + +#[cfg(test)] +mod tests { + use super::*; + use axum::body::Body; + use axum::http::{Request, StatusCode}; + use tower::ServiceExt; // for `oneshot` + use axum::body::to_bytes; + + #[tokio::test] + async fn test_health_endpoint() { + let app = app(); + let response = app.oneshot(Request::builder().uri("/health").body(Body::empty()).unwrap()).await.unwrap(); + assert_eq!(response.status(), StatusCode::OK); + let body = to_bytes(response.into_body(), 1024).await.unwrap(); + assert_eq!(&body[..], b"{\"status\":\"ok\"}"); + } +} -- cgit v1.2.3