55 lines
1.4 KiB
Rust
55 lines
1.4 KiB
Rust
|
use axum::{routing::{get, post}, Json, Router};
|
||
|
|
||
|
use crate::{
|
||
|
core::Core,
|
||
|
handlers::{check_password, healthcheck, AuthRequest},
|
||
|
};
|
||
|
|
||
|
pub fn routes(core: Core) -> Router {
|
||
|
Router::new()
|
||
|
.route(
|
||
|
"/api/v1/health",
|
||
|
get({
|
||
|
let core = core.clone();
|
||
|
move || healthcheck(core)
|
||
|
}),
|
||
|
)
|
||
|
.route(
|
||
|
"/api/v1/auth",
|
||
|
post({
|
||
|
let core = core.clone();
|
||
|
move |req: Json<AuthRequest>| check_password(core, req)
|
||
|
}),
|
||
|
)
|
||
|
}
|
||
|
|
||
|
#[cfg(test)]
|
||
|
mod test {
|
||
|
use std::path::PathBuf;
|
||
|
|
||
|
use axum_test::TestServer;
|
||
|
|
||
|
use crate::{asset_db::FsAssets, core::Core, database::DbConn};
|
||
|
use super::*;
|
||
|
|
||
|
fn setup() -> (Core, TestServer) {
|
||
|
let memory_db: Option<PathBuf> = None;
|
||
|
let conn = DbConn::new(memory_db);
|
||
|
let core = Core::new(FsAssets::new(PathBuf::from("/home/savanni/Pictures")), conn);
|
||
|
let app = routes(core.clone());
|
||
|
let server = TestServer::new(app).unwrap();
|
||
|
(core, server)
|
||
|
}
|
||
|
|
||
|
#[tokio::test]
|
||
|
async fn it_returns_a_healthcheck() {
|
||
|
let (_core, server) = setup();
|
||
|
let response = server.get("/api/v1/health").await;
|
||
|
response.assert_status_ok();
|
||
|
|
||
|
let b: crate::handlers::HealthCheck = response.json();
|
||
|
|
||
|
assert_eq!(b, crate::handlers::HealthCheck { ok: false });
|
||
|
}
|
||
|
}
|