summaryrefslogtreecommitdiffstats
path: root/src/server/routes.rs
blob: 85cc100c0f0e2c015884d5138ce65e9e388646c0 (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
32
33
34
35
36
37
38
39
pub(super) mod users;
use axum::response::IntoResponse;

pub async fn health_check() -> impl IntoResponse {
    let name = env!("CARGO_PKG_NAME");
    let ver = env!("CARGO_PKG_VERSION");

    format!("{name} v{ver} is live")
}

#[cfg(test)]
mod tests {
    use axum::{
        body::Body,
        http::{Request, StatusCode},
    };
    use sqlx::PgPool;
    use stack_up::Services;
    use tower::ServiceExt;

    use crate::{
        server::{self, test_config},
        state::AppState,
    };

    #[sqlx::test]
    async fn health_check(pool: PgPool) {
        let services = Services { postgres: pool };
        let state = AppState::new(services, &test_config()).await.unwrap();
        let app = server::router(state);

        let response = app
            .oneshot(Request::builder().uri("/").body(Body::empty()).unwrap())
            .await
            .unwrap();

        assert_eq!(response.status(), StatusCode::OK);
    }
}