feat: enhance error handling and user follow functionality, update tests for user context

This commit is contained in:
2025-09-05 21:44:46 +02:00
parent decf81e535
commit 0e6c072387
13 changed files with 172 additions and 81 deletions

View File

@@ -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()
}