47 lines
1.4 KiB
Rust
47 lines
1.4 KiB
Rust
use axum::{body::{to_bytes, Body}, http::{Request, StatusCode}};
|
|
use hermes_backend::{app_state::AppState, build_router, config::AppConfig};
|
|
use tower::ServiceExt;
|
|
|
|
#[tokio::test]
|
|
async fn health_returns_ok() {
|
|
let app = build_router(AppState::new(AppConfig::default(), None, None));
|
|
|
|
let response = app
|
|
.oneshot(Request::builder().uri("/health").body(Body::empty()).unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(response.status(), StatusCode::OK);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn session_start_and_me_work() {
|
|
let app = build_router(AppState::new(AppConfig::default(), None, None));
|
|
|
|
let response = app
|
|
.clone()
|
|
.oneshot(
|
|
Request::builder()
|
|
.method("POST")
|
|
.uri("/api/v1/session/start")
|
|
.header("content-type", "application/json")
|
|
.body(Body::from("{}"))
|
|
.unwrap(),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(response.status(), StatusCode::CREATED);
|
|
|
|
let body = to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
let json: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
|
assert_eq!(json["locale_code"], "en");
|
|
|
|
let response = app
|
|
.oneshot(Request::builder().uri("/api/v1/session/me").body(Body::empty()).unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(response.status(), StatusCode::OK);
|
|
}
|