summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: f51483b1fcb50986bcf8ea6748b7c0c4c8cf9937 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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\"}");
    }
}