fix(tests): expected 303 response

This commit is contained in:
aaldebs99 2025-10-12 03:20:03 +00:00
parent a0101bbc7b
commit 67fd253bea
1 changed files with 26 additions and 15 deletions

View File

@ -338,11 +338,11 @@ mod tests {
.unwrap();
let status = response.status();
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
.await
.unwrap();
if status != StatusCode::OK {
if status != StatusCode::SEE_OTHER {
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
.await
.unwrap();
let error_text = String::from_utf8_lossy(&body);
eprintln!("Response status: {}", status);
eprintln!("Response body: {}", error_text);
@ -360,13 +360,24 @@ mod tests {
}
}
assert_eq!(status, StatusCode::OK);
// Expect a redirect (303 See Other) instead of JSON response
assert_eq!(status, StatusCode::SEE_OTHER);
let login_response: serde_json::Value = serde_json::from_slice(&body).unwrap();
// Extract the token from the Location header
let location = response.headers().get("location").unwrap().to_str().unwrap();
assert!(location.contains("/auth/callback?token="));
assert!(login_response["token"].is_string());
assert_eq!(login_response["user"]["username"], test_username);
assert_eq!(login_response["user"]["email"], test_email);
// Extract token from URL
let token_start = location.find("token=").unwrap() + 6;
let token = urlencoding::decode(&location[token_start..]).unwrap();
// Verify token is not empty
assert!(!token.is_empty());
// Verify user was created by checking database
let user = db.get_user_by_username(&test_username).await.unwrap().unwrap();
assert_eq!(user.username, test_username);
assert_eq!(user.email, test_email);
}
#[tokio::test]