feat: enhance error handling and user follow functionality, update tests for user context
This commit is contained in:
@@ -13,7 +13,7 @@ async fn test_feed_and_user_thoughts() {
|
||||
|
||||
// As user1, post a thought
|
||||
let body = json!({ "content": "A thought from user1" }).to_string();
|
||||
make_post_request(app.router.clone(), "/thoughts", body).await;
|
||||
make_post_request(app.router.clone(), "/thoughts", body, Some(1)).await;
|
||||
|
||||
// As a different "user", create thoughts for user2 and user3 (we cheat here since auth is hardcoded)
|
||||
app::persistence::thought::create_thought(
|
||||
@@ -36,7 +36,7 @@ async fn test_feed_and_user_thoughts() {
|
||||
.unwrap();
|
||||
|
||||
// 1. Get thoughts for user2 - should only see their thought
|
||||
let response = make_get_request(app.router.clone(), "/users/user2/thoughts").await;
|
||||
let response = make_get_request(app.router.clone(), "/users/user2/thoughts", Some(2)).await;
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||
let v: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
||||
@@ -44,17 +44,23 @@ async fn test_feed_and_user_thoughts() {
|
||||
assert_eq!(v["thoughts"][0]["content"], "user2 was here");
|
||||
|
||||
// 2. user1's feed is initially empty
|
||||
let response = make_get_request(app.router.clone(), "/feed").await;
|
||||
let response = make_get_request(app.router.clone(), "/feed", Some(1)).await;
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||
let v: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
||||
assert!(v["thoughts"].as_array().unwrap().is_empty());
|
||||
|
||||
// 3. user1 follows user2
|
||||
make_post_request(app.router.clone(), "/users/user2/follow", "".to_string()).await;
|
||||
make_post_request(
|
||||
app.router.clone(),
|
||||
"/users/user2/follow",
|
||||
"".to_string(),
|
||||
Some(1),
|
||||
)
|
||||
.await;
|
||||
|
||||
// 4. user1's feed now has user2's thought
|
||||
let response = make_get_request(app.router.clone(), "/feed").await;
|
||||
let response = make_get_request(app.router.clone(), "/feed", Some(1)).await;
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||
let v: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
||||
|
Reference in New Issue
Block a user