//! Only meaningful with `--features embed-web` and a built `web/dist`. Compiled only
//! under that feature.
#![cfg(feature = "embed-web")]

use axum::body::Body;
use axum::http::{Request, StatusCode};
use http_body_util::BodyExt;
use tower::ServiceExt;

#[tokio::test]
async fn serves_index_at_root_and_spa_fallback() {
    let app = server::test_support::web_router();

    let root = app
        .clone()
        .oneshot(Request::builder().uri("/").body(Body::empty()).unwrap())
        .await
        .unwrap();

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

    let body = root.into_body().collect().await.unwrap().to_bytes();

    assert!(String::from_utf8_lossy(&body).contains("<div id=\"root\">"));

    let deep = app
        .oneshot(
            Request::builder()
                .uri("/objects/123")
                .body(Body::empty())
                .unwrap(),
        )
        .await
        .unwrap();

    assert_eq!(deep.status(), StatusCode::OK);
}
