summaryrefslogtreecommitdiffstats
path: root/src/api.rs
blob: f74e33a7661de0b8b89dd1f13640f9ecaaebbbde (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
40
41
42
43
44
45
46
use axum::{response::IntoResponse, routing::get};

use crate::state::AppState;

mod users;
pub mod error;

pub fn router(state: AppState) -> axum::Router {
    axum::Router::new()
        .merge(users::router())
        .route("/healthcheck", get(healthcheck))
        .with_state(state)
}

pub async fn healthcheck() -> impl IntoResponse {
    "success"
}

#[cfg(test)]
mod tests {
    use crate::tests::{setup_test_env, TestResult};

    use super::*;

    use axum::{
        body::Body,
        http::{Request, StatusCode},
    };
    use sqlx::PgPool;
    use tower::ServiceExt;

    #[sqlx::test]
    async fn test_healthcheck_ok(pool: PgPool) -> TestResult {
        setup_test_env();

        let router = router(AppState { pool });

        let request = Request::builder().uri("/healthcheck").body(Body::empty())?;

        let response = router.oneshot(request).await?;

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

        Ok(())
    }
}