fix(tests): expected 303 response
This commit is contained in:
parent
a0101bbc7b
commit
67fd253bea
|
|
@ -338,35 +338,46 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
|
|
||||||
.await
|
if status != StatusCode::SEE_OTHER {
|
||||||
.unwrap();
|
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
|
||||||
|
.await
|
||||||
if status != StatusCode::OK {
|
.unwrap();
|
||||||
let error_text = String::from_utf8_lossy(&body);
|
let error_text = String::from_utf8_lossy(&body);
|
||||||
eprintln!("Response status: {}", status);
|
eprintln!("Response status: {}", status);
|
||||||
eprintln!("Response body: {}", error_text);
|
eprintln!("Response body: {}", error_text);
|
||||||
|
|
||||||
// Also check if we made the expected API calls to the mock server
|
// Also check if we made the expected API calls to the mock server
|
||||||
eprintln!("Mock server received calls:");
|
eprintln!("Mock server received calls:");
|
||||||
let received_requests = mock_server.received_requests().await.unwrap();
|
let received_requests = mock_server.received_requests().await.unwrap();
|
||||||
for req in received_requests {
|
for req in received_requests {
|
||||||
eprintln!(" {} {} - {}", req.method, req.url.path(), String::from_utf8_lossy(&req.body));
|
eprintln!(" {} {} - {}", req.method, req.url.path(), String::from_utf8_lossy(&req.body));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to parse as JSON to see if there's a more detailed error message
|
// Try to parse as JSON to see if there's a more detailed error message
|
||||||
if let Ok(error_json) = serde_json::from_slice::<serde_json::Value>(&body) {
|
if let Ok(error_json) = serde_json::from_slice::<serde_json::Value>(&body) {
|
||||||
eprintln!("Error JSON: {:#}", error_json);
|
eprintln!("Error JSON: {:#}", error_json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
assert!(login_response["token"].is_string());
|
let location = response.headers().get("location").unwrap().to_str().unwrap();
|
||||||
assert_eq!(login_response["user"]["username"], test_username);
|
assert!(location.contains("/auth/callback?token="));
|
||||||
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]
|
#[tokio::test]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue