use super::TestHttpRequestBuilder;
#[derive(Clone)]
pub struct TestHttpApp {
router: axum::Router,
}
impl TestHttpApp {
#[must_use]
pub fn new(router: axum::Router) -> Self {
Self { router }
}
pub async fn request(
&self,
request: axum::http::Request<axum::body::Body>,
) -> axum::response::Response {
use tower::ServiceExt;
self.router
.clone()
.oneshot(request)
.await
.expect("test HTTP request should complete")
}
pub async fn get(&self, uri: impl Into<String>) -> axum::response::Response {
self.request(TestHttpRequestBuilder::get(uri).build()).await
}
pub async fn post_json(
&self,
uri: impl Into<String>,
value: &serde_json::Value,
) -> axum::response::Response {
self.request(TestHttpRequestBuilder::post(uri).json_body(value).build())
.await
}
}