feat: enhance error handling and user follow functionality, update tests for user context
This commit is contained in:
@@ -1,33 +1,51 @@
|
||||
use axum::{body::Body, http::Request, response::Response, Router};
|
||||
use tower::ServiceExt;
|
||||
|
||||
pub async fn make_get_request(app: Router, url: &str) -> Response {
|
||||
app.oneshot(Request::builder().uri(url).body(Body::empty()).unwrap())
|
||||
pub async fn make_get_request(app: Router, url: &str, user_id: Option<i32>) -> Response {
|
||||
let mut builder = Request::builder()
|
||||
.uri(url)
|
||||
.header("Content-Type", "application/json");
|
||||
|
||||
if let Some(user_id) = user_id {
|
||||
builder = builder.header("x-test-user-id", user_id.to_string());
|
||||
}
|
||||
|
||||
app.oneshot(builder.body(Body::empty()).unwrap())
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn make_post_request(app: Router, url: &str, body: String) -> Response {
|
||||
app.oneshot(
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri(url)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(Body::from(body))
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
pub async fn make_post_request(
|
||||
app: Router,
|
||||
url: &str,
|
||||
body: String,
|
||||
user_id: Option<i32>,
|
||||
) -> Response {
|
||||
let mut builder = Request::builder()
|
||||
.method("POST")
|
||||
.uri(url)
|
||||
.header("Content-Type", "application/json");
|
||||
|
||||
if let Some(user_id) = user_id {
|
||||
builder = builder.header("x-test-user-id", user_id.to_string());
|
||||
}
|
||||
|
||||
app.oneshot(builder.body(Body::from(body)).unwrap())
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn make_delete_request(app: Router, url: &str) -> Response {
|
||||
app.oneshot(
|
||||
Request::builder()
|
||||
.method("DELETE")
|
||||
.uri(url)
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
pub async fn make_delete_request(app: Router, url: &str, user_id: Option<i32>) -> Response {
|
||||
let mut builder = Request::builder()
|
||||
.method("DELETE")
|
||||
.uri(url)
|
||||
.header("Content-Type", "application/json");
|
||||
|
||||
if let Some(user_id) = user_id {
|
||||
builder = builder.header("x-test-user-id", user_id.to_string());
|
||||
}
|
||||
|
||||
app.oneshot(builder.body(Body::empty()).unwrap())
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
Reference in New Issue
Block a user