64 lines
1.6 KiB
Rust
64 lines
1.6 KiB
Rust
use axum::{
|
|
body::Body,
|
|
http::{Request, StatusCode},
|
|
};
|
|
use http_body_util::BodyExt; // for `collect`
|
|
use tower::ServiceExt; // for `oneshot`
|
|
|
|
#[tokio::test]
|
|
async fn healthcheck_returns_healthy() {
|
|
let (app, _) = nuchat::app();
|
|
|
|
let response = app
|
|
.oneshot(
|
|
Request::builder()
|
|
.uri("/api/healthcheck")
|
|
.body(Body::empty())
|
|
.unwrap(),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(response.status(), StatusCode::OK);
|
|
|
|
let body = response.into_body().collect().await.unwrap().to_bytes();
|
|
assert_eq!(&body[..], br#"{"healthy":true}"#);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn root_returns_spa() {
|
|
let (app, _) = nuchat::app();
|
|
|
|
let response = app
|
|
.oneshot(Request::builder().uri("/").body(Body::empty()).unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(response.status(), StatusCode::OK);
|
|
|
|
let body = response.into_body().collect().await.unwrap().to_bytes();
|
|
let body = String::from_utf8(body.into_iter().collect()).unwrap();
|
|
assert!(body.starts_with("<!DOCTYPE html>"));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn unkown_fallsback_to_spa() {
|
|
let (app, _) = nuchat::app();
|
|
|
|
let response = app
|
|
.oneshot(
|
|
Request::builder()
|
|
.uri("/asdfasdfa") // unknown url
|
|
.body(Body::empty())
|
|
.unwrap(),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
|
|
|
let body = response.into_body().collect().await.unwrap().to_bytes();
|
|
let body = String::from_utf8(body.into_iter().collect()).unwrap();
|
|
assert!(body.starts_with("<!DOCTYPE html>"));
|
|
}
|