Added api post.
This commit is contained in:
parent
38af08eb14
commit
ce10c73eae
22
src/main.rs
22
src/main.rs
@ -3,7 +3,7 @@ use axum::{
|
||||
extract::{Extension, FromRequestParts, State},
|
||||
http::request::Parts,
|
||||
response::IntoResponse,
|
||||
routing::get,
|
||||
routing::{get, post},
|
||||
RequestPartsExt, Router,
|
||||
};
|
||||
use clap::Parser;
|
||||
@ -45,6 +45,7 @@ async fn main() {
|
||||
async fn create_app(state: MoreThanText) -> Router {
|
||||
Router::new()
|
||||
.route("/", get(mtt_conn))
|
||||
.route("/api/:document", post(mtt_conn))
|
||||
.layer(CookieManagerLayer::new())
|
||||
.layer(Extension(state.clone()))
|
||||
.with_state(state)
|
||||
@ -96,6 +97,7 @@ mod servers {
|
||||
body::Body,
|
||||
http::{
|
||||
header::{COOKIE, SET_COOKIE},
|
||||
Method,
|
||||
Request, StatusCode,
|
||||
},
|
||||
};
|
||||
@ -170,4 +172,22 @@ mod servers {
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn add_new_page() {
|
||||
let base = "/something";
|
||||
let api = "/api".to_owned() + base;
|
||||
let app = create_app(MoreThanText::new()).await;
|
||||
let response = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method(Method::POST)
|
||||
.uri(&api)
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK, "failed to post ro {:?}", api);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user