mod support;
use axum::http::StatusCode;
use support::TestServer;
#[tokio::test]
async fn the_api_wins_over_the_single_page_app() {
let Some(server) = TestServer::start().await else { return };
let (status, body) = server.get_with_cookie("/api/v1/privacy", None).await;
assert_eq!(status, StatusCode::UNAUTHORIZED);
assert!(body["error"].is_string(), "an API path must answer JSON, got {body}");
}
#[tokio::test]
async fn an_unknown_api_path_does_not_fall_through_to_the_app() {
let Some(server) = TestServer::start().await else { return };
let (status, body) = server.get_with_cookie("/api/v1/no-such-endpoint", None).await;
assert_eq!(status, StatusCode::NOT_FOUND, "an unknown API path must not be answered by the web UI");
assert_eq!(body["error"], "no such endpoint", "{body}");
let (status, body) = server.get_with_cookie("/api/privacy", None).await;
assert_eq!(status, StatusCode::NOT_FOUND);
assert_eq!(body["error"], "no such endpoint", "{body}");
}
#[tokio::test]
async fn health_is_still_answered_by_the_server() {
let Some(server) = TestServer::start().await else { return };
let (status, body) = server.get_with_cookie("/health", None).await;
assert_eq!(status, StatusCode::OK);
assert_eq!(body["status"], "ok", "{body}");
}