fix(tests): resolve tests checking id instead of document_id

This commit is contained in:
perf3ct
2025-07-07 20:47:36 +00:00
parent a4b9626616
commit 22c890356d
6 changed files with 69 additions and 63 deletions

View File

@@ -11,6 +11,7 @@ use std::time::Duration;
use uuid::Uuid;
use readur::models::{DocumentResponse, CreateUser, LoginRequest, LoginResponse, UserRole};
use readur::routes::documents::types::DocumentUploadResponse;
fn get_base_url() -> String {
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_string())
@@ -100,7 +101,7 @@ impl DocumentDeletionTestClient {
}
/// Upload a test document
async fn upload_document(&self, content: &[u8], filename: &str) -> Result<DocumentResponse, Box<dyn std::error::Error>> {
async fn upload_document(&self, content: &[u8], filename: &str) -> Result<DocumentUploadResponse, Box<dyn std::error::Error>> {
let token = self.token.as_ref().ok_or("Not authenticated")?;
let form = multipart::Form::new()
@@ -120,7 +121,7 @@ impl DocumentDeletionTestClient {
return Err(format!("Document upload failed: {}", response.text().await?).into());
}
let document: DocumentResponse = response.json().await?;
let document: DocumentUploadResponse = response.json().await?;
Ok(document)
}
@@ -317,24 +318,24 @@ async fn test_single_document_deletion_success() {
let document = client.upload_document(test_content, "test_deletion.txt")
.await.expect("Failed to upload document");
println!("Uploaded document: {}", document.id);
println!("Uploaded document: {}", document.document_id);
// Verify document exists
let retrieved_doc = client.get_document(&document.id.to_string())
let retrieved_doc = client.get_document(&document.document_id.to_string())
.await.expect("Failed to get document");
assert!(retrieved_doc.is_some(), "Document should exist before deletion");
// Delete the document
let delete_result = client.delete_document(&document.id.to_string())
let delete_result = client.delete_document(&document.document_id.to_string())
.await.expect("Failed to delete document");
// Verify deletion response
assert_eq!(delete_result["success"], true);
assert_eq!(delete_result["document_id"], document.id.to_string());
assert_eq!(delete_result["document_id"], document.document_id.to_string());
assert_eq!(delete_result["filename"], document.filename);
// Verify document no longer exists
let retrieved_doc_after = client.get_document(&document.id.to_string())
let retrieved_doc_after = client.get_document(&document.document_id.to_string())
.await.expect("Failed to check document existence");
assert!(retrieved_doc_after.is_none(), "Document should not exist after deletion");
@@ -360,7 +361,7 @@ async fn test_bulk_document_deletion_success() {
let test_content = format!("This is test document number {}", i);
let document = client.upload_document(test_content.as_bytes(), &format!("test_bulk_{}.txt", i))
.await.expect("Failed to upload document");
document_ids.push(document.id.to_string());
document_ids.push(document.document_id.to_string());
}
println!("Uploaded {} documents for bulk deletion", document_ids.len());
@@ -473,7 +474,7 @@ async fn test_bulk_delete_mixed_existing_nonexistent() {
// Create a list with real and fake IDs
let fake_id = Uuid::new_v4().to_string();
let mixed_ids = vec![real_document.id.to_string(), fake_id];
let mixed_ids = vec![real_document.document_id.to_string(), fake_id];
// Perform bulk deletion
let delete_result = client.bulk_delete_documents(&mixed_ids)
@@ -492,10 +493,10 @@ async fn test_bulk_delete_mixed_existing_nonexistent() {
.collect();
assert_eq!(deleted_ids.len(), 1);
assert_eq!(deleted_ids[0], real_document.id.to_string());
assert_eq!(deleted_ids[0], real_document.document_id.to_string());
// Verify real document was deleted
let retrieved_doc = client.get_document(&real_document.id.to_string())
let retrieved_doc = client.get_document(&real_document.document_id.to_string())
.await.expect("Failed to check document existence");
assert!(retrieved_doc.is_none(), "Real document should be deleted");
@@ -551,7 +552,7 @@ async fn test_cross_user_deletion_protection() {
.await.expect("Failed to upload document as user 1");
// User 2 tries to delete user 1's document
let delete_result = client2.delete_document(&user1_document.id.to_string()).await;
let delete_result = client2.delete_document(&user1_document.document_id.to_string()).await;
// Should return 404 (document not found for user 2)
assert!(delete_result.is_err(), "Cross-user deletion should fail");
@@ -559,7 +560,7 @@ async fn test_cross_user_deletion_protection() {
assert!(error_msg.contains("404"), "Should return 404 for document not owned by user");
// Verify user 1's document still exists
let retrieved_doc = client1.get_document(&user1_document.id.to_string())
let retrieved_doc = client1.get_document(&user1_document.document_id.to_string())
.await.expect("Failed to check document existence");
assert!(retrieved_doc.is_some(), "User 1's document should still exist after failed cross-user deletion");
@@ -597,15 +598,15 @@ async fn test_admin_can_delete_any_document() {
.await.expect("Failed to upload document as user");
// Admin deletes user's document
let delete_result = admin_client.delete_document(&user_document.id.to_string())
let delete_result = admin_client.delete_document(&user_document.document_id.to_string())
.await.expect("Admin should be able to delete any document");
// Verify deletion response
assert_eq!(delete_result["success"], true);
assert_eq!(delete_result["document_id"], user_document.id.to_string());
assert_eq!(delete_result["document_id"], user_document.document_id.to_string());
// Verify document no longer exists
let retrieved_doc = user_client.get_document(&user_document.id.to_string())
let retrieved_doc = user_client.get_document(&user_document.document_id.to_string())
.await.expect("Failed to check document existence");
assert!(retrieved_doc.is_none(), "Document should be deleted by admin");
@@ -636,7 +637,7 @@ async fn test_document_count_updates_after_deletion() {
let test_content = format!("Test document {}", i);
let document = client.upload_document(test_content.as_bytes(), &format!("count_test_{}.txt", i))
.await.expect("Failed to upload document");
document_ids.push(document.id.to_string());
document_ids.push(document.document_id.to_string());
}
// Verify count increased

View File

@@ -19,7 +19,8 @@ use std::time::{Duration, Instant};
use tokio::time::sleep;
use uuid::Uuid;
use readur::models::{CreateUser, LoginRequest, LoginResponse, UserRole, DocumentResponse};
use readur::models::{CreateUser, LoginRequest, LoginResponse, UserRole};
use readur::routes::documents::types::DocumentUploadResponse;
fn get_base_url() -> String {
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_string())
@@ -137,7 +138,7 @@ impl FileProcessingTestClient {
}
/// Upload a file with specific content and MIME type
async fn upload_file(&self, content: &str, filename: &str, mime_type: &str) -> Result<DocumentResponse, Box<dyn std::error::Error>> {
async fn upload_file(&self, content: &str, filename: &str, mime_type: &str) -> Result<DocumentUploadResponse, Box<dyn std::error::Error>> {
println!("🔍 DEBUG: Uploading file: {} with MIME type: {}", filename, mime_type);
let token = self.token.as_ref().ok_or("Not authenticated")?;
@@ -164,13 +165,13 @@ impl FileProcessingTestClient {
let response_text = response.text().await?;
println!("🟢 DEBUG: Upload response: {}", response_text);
let document: DocumentResponse = serde_json::from_str(&response_text)?;
println!("✅ DEBUG: Successfully parsed document: {}", document.id);
let document: DocumentUploadResponse = serde_json::from_str(&response_text)?;
println!("✅ DEBUG: Successfully parsed document: {}", document.document_id);
Ok(document)
}
/// Upload binary file content
async fn upload_binary_file(&self, content: Vec<u8>, filename: &str, mime_type: &str) -> Result<DocumentResponse, Box<dyn std::error::Error>> {
async fn upload_binary_file(&self, content: Vec<u8>, filename: &str, mime_type: &str) -> Result<DocumentUploadResponse, Box<dyn std::error::Error>> {
let token = self.token.as_ref().ok_or("Not authenticated")?;
let part = reqwest::multipart::Part::bytes(content)
@@ -196,8 +197,8 @@ impl FileProcessingTestClient {
let response_text = response.text().await?;
println!("🟢 DEBUG: Binary upload response: {}", response_text);
let document: DocumentResponse = serde_json::from_str(&response_text)?;
println!("✅ DEBUG: Successfully parsed binary document: {}", document.id);
let document: DocumentUploadResponse = serde_json::from_str(&response_text)?;
println!("✅ DEBUG: Successfully parsed binary document: {}", document.document_id);
Ok(document)
}
@@ -369,7 +370,7 @@ End of test document."#;
let document = client.upload_file(text_content, "test_pipeline.txt", "text/plain").await
.expect("Failed to upload text file");
let document_id = document.id.to_string();
let document_id = document.document_id.to_string();
println!("✅ Text file uploaded: {}", document_id);
// Validate initial document properties
@@ -663,10 +664,10 @@ async fn test_processing_error_recovery() {
let empty_result = client.upload_file("", "empty.txt", "text/plain").await;
match empty_result {
Ok(document) => {
println!("✅ Empty file uploaded: {}", document.id);
println!("✅ Empty file uploaded: {}", document.document_id);
// Try to process empty file
match client.wait_for_processing(&document.id.to_string()).await {
match client.wait_for_processing(&document.document_id.to_string()).await {
Ok(processed) => {
println!("✅ Empty file processing completed: {:?}", processed.ocr_status);
}
@@ -742,10 +743,10 @@ async fn test_processing_error_recovery() {
match corrupted_result {
Ok(document) => {
println!("✅ Corrupted file uploaded: {}", document.id);
println!("✅ Corrupted file uploaded: {}", document.document_id);
// Processing should handle the mismatch gracefully
match client.wait_for_processing(&document.id.to_string()).await {
match client.wait_for_processing(&document.document_id.to_string()).await {
Ok(processed) => {
println!("✅ Corrupted file processed: {:?}", processed.ocr_status);
}
@@ -767,10 +768,10 @@ async fn test_processing_error_recovery() {
match special_result {
Ok(document) => {
println!("✅ File with special characters uploaded: {}", document.id);
println!("✅ File with special characters uploaded: {}", document.document_id);
println!("✅ Original filename preserved: {}", document.original_filename);
match client.wait_for_processing(&document.id.to_string()).await {
match client.wait_for_processing(&document.document_id.to_string()).await {
Ok(_) => println!("✅ Special filename file processed successfully"),
Err(e) => println!("⚠️ Special filename file processing failed: {}", e),
}
@@ -816,12 +817,12 @@ async fn test_pipeline_performance_monitoring() {
println!("{} uploaded in {:?}", filename, upload_time);
// Wait for processing and measure time
match client.wait_for_processing(&document.id.to_string()).await {
match client.wait_for_processing(&document.document_id.to_string()).await {
Ok(processed_doc) => {
let total_processing_time = processing_start.elapsed();
// Get OCR results to check reported processing time
if let Ok(ocr_results) = client.get_ocr_results(&document.id.to_string()).await {
if let Ok(ocr_results) = client.get_ocr_results(&document.document_id.to_string()).await {
let reported_time = ocr_results["ocr_processing_time_ms"]
.as_i64()
.map(|ms| Duration::from_millis(ms as u64));
@@ -948,8 +949,8 @@ async fn test_concurrent_file_processing() {
if response.status().is_success() {
let response_text = response.text().await
.expect("Should get response text");
let document: DocumentResponse = serde_json::from_str(&response_text)
.expect("Should parse document response");
let document: DocumentUploadResponse = serde_json::from_str(&response_text)
.expect("Should parse document upload response");
Ok((i, document, upload_time))
} else {
Err((i, response.text().await.unwrap_or_default()))
@@ -964,7 +965,7 @@ async fn test_concurrent_file_processing() {
for handle in upload_handles {
match handle.await.expect("Upload task should complete") {
Ok((index, document, upload_time)) => {
println!("✅ Document {} uploaded in {:?}: {}", index + 1, upload_time, document.id);
println!("✅ Document {} uploaded in {:?}: {}", index + 1, upload_time, document.document_id);
uploaded_documents.push(document);
}
Err((index, error)) => {
@@ -1138,11 +1139,11 @@ async fn test_real_test_images_processing() {
};
let upload_time = upload_start.elapsed();
println!("{} uploaded in {:?}: {}", test_image.filename, upload_time, document.id);
println!("{} uploaded in {:?}: {}", test_image.filename, upload_time, document.document_id);
// Wait for OCR processing
let processing_start = std::time::Instant::now();
match client.wait_for_processing(&document.id.to_string()).await {
match client.wait_for_processing(&document.document_id.to_string()).await {
Ok(processed_doc) => {
let processing_time = processing_start.elapsed();
println!("{} processed in {:?}: status = {:?}",

View File

@@ -10,7 +10,8 @@ use serde_json::{json, Value};
use std::time::{Duration, Instant};
use tokio::time::sleep;
use readur::models::{DocumentResponse, CreateUser, LoginRequest, LoginResponse};
use readur::models::{CreateUser, LoginRequest, LoginResponse};
use readur::routes::documents::types::DocumentUploadResponse;
fn get_base_url() -> String {
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_string())
@@ -95,7 +96,7 @@ impl TestClient {
}
/// Upload a test document
async fn upload_document(&self, content: &str, filename: &str) -> Result<DocumentResponse, Box<dyn std::error::Error>> {
async fn upload_document(&self, content: &str, filename: &str) -> Result<DocumentUploadResponse, Box<dyn std::error::Error>> {
let token = self.token.as_ref().ok_or("Not authenticated")?;
let part = reqwest::multipart::Part::text(content.to_string())
@@ -115,7 +116,7 @@ impl TestClient {
return Err(format!("Upload failed: {}", response.text().await?).into());
}
let document: DocumentResponse = response.json().await?;
let document: DocumentUploadResponse = response.json().await?;
Ok(document)
}
@@ -212,7 +213,7 @@ Technology: Rust + Axum + SQLx"#;
let document = client.upload_document(test_content, "rust_test.txt").await
.expect("Failed to upload document");
println!("✅ Document uploaded: {}", document.id);
println!("✅ Document uploaded: {}", document.document_id);
// Validate document response structure using our types
assert!(!document.filename.is_empty());

View File

@@ -11,7 +11,8 @@ use std::time::{Duration, Instant};
use tokio::time::sleep;
use uuid::Uuid;
use readur::models::{DocumentResponse, CreateUser, LoginRequest, LoginResponse};
use readur::models::{CreateUser, LoginRequest, LoginResponse};
use readur::routes::documents::types::DocumentUploadResponse;
fn get_base_url() -> String {
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_string())
@@ -108,8 +109,8 @@ impl OcrTestClient {
return Err(format!("Upload failed: {}", response.text().await?).into());
}
let document: DocumentResponse = response.json().await?;
Ok((document.id, content.to_string()))
let document: DocumentUploadResponse = response.json().await?;
Ok((document.document_id, content.to_string()))
}
/// Get document details including OCR status
@@ -195,8 +196,8 @@ impl OcrTestClient {
return Err(format!("Upload failed: {}", response.text().await?).into());
}
let document: DocumentResponse = response.json().await?;
Ok::<(Uuid, String), Box<dyn std::error::Error>>((document.id, content_owned))
let document: DocumentUploadResponse = response.json().await?;
Ok::<(Uuid, String), Box<dyn std::error::Error>>((document.document_id, content_owned))
}
})
.collect();

View File

@@ -16,7 +16,8 @@ use std::time::{Duration, Instant};
use tokio::time::sleep;
use uuid::Uuid;
use readur::models::{CreateUser, LoginRequest, LoginResponse, UserRole, DocumentResponse};
use readur::models::{CreateUser, LoginRequest, LoginResponse, UserRole};
use readur::routes::documents::types::DocumentUploadResponse;
fn get_base_url() -> String {
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_string())
@@ -155,7 +156,7 @@ impl OCRQueueTestClient {
}
/// Upload a document for OCR processing
async fn upload_document(&self, content: &str, filename: &str) -> Result<DocumentResponse, Box<dyn std::error::Error + Send + Sync>> {
async fn upload_document(&self, content: &str, filename: &str) -> Result<DocumentUploadResponse, Box<dyn std::error::Error + Send + Sync>> {
let token = self.token.as_ref().ok_or("Not authenticated")?;
let part = reqwest::multipart::Part::text(content.to_string())
@@ -178,14 +179,14 @@ impl OCRQueueTestClient {
return Err(format!("Upload failed: {}", text).into());
}
let document: DocumentResponse = response.json().await?;
println!("📄 Document uploaded: {} (filename: {}, has_ocr_text: {}, ocr_status: {:?})",
document.id, filename, document.has_ocr_text, document.ocr_status);
let document: DocumentUploadResponse = response.json().await?;
println!("📄 Document uploaded: {} (filename: {}, size: {})",
document.document_id, filename, document.file_size);
Ok(document)
}
/// Upload multiple documents concurrently
async fn upload_multiple_documents(&self, count: usize, base_content: &str) -> Result<Vec<DocumentResponse>, Box<dyn std::error::Error + Send + Sync>> {
async fn upload_multiple_documents(&self, count: usize, base_content: &str) -> Result<Vec<DocumentUploadResponse>, Box<dyn std::error::Error + Send + Sync>> {
let mut handles = Vec::new();
for i in 0..count {
@@ -327,7 +328,7 @@ async fn test_queue_stats_monitoring() {
let document = client.upload_document("Test document for queue monitoring", "queue_test.txt").await
.expect("Failed to upload document");
println!("✅ Document uploaded: {}", document.id);
println!("✅ Document uploaded: {}", document.document_id);
// Wait a moment for queue to update
sleep(Duration::from_secs(2)).await;

View File

@@ -21,7 +21,8 @@ use tokio::time::sleep;
use uuid::Uuid;
use chrono;
use readur::models::{CreateUser, LoginRequest, LoginResponse, UserRole, DocumentResponse};
use readur::models::{CreateUser, LoginRequest, LoginResponse, UserRole};
use readur::routes::documents::types::DocumentUploadResponse;
fn get_base_url() -> String {
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_string())
@@ -194,7 +195,7 @@ impl LoadTestClient {
}
/// Perform a timed document upload
async fn timed_upload(&self, content: &str, filename: &str) -> Result<(DocumentResponse, Duration), Box<dyn std::error::Error + Send + Sync>> {
async fn timed_upload(&self, content: &str, filename: &str) -> Result<(DocumentUploadResponse, Duration), Box<dyn std::error::Error + Send + Sync>> {
let start = Instant::now();
let token = self.token.as_ref().ok_or("Not authenticated")?;
@@ -217,12 +218,12 @@ impl LoadTestClient {
return Err(format!("Upload failed: {}", response.text().await?).into());
}
let document: DocumentResponse = response.json().await?;
let document: DocumentUploadResponse = response.json().await?;
Ok((document, elapsed))
}
/// Perform a timed document list request
async fn timed_list_documents(&self) -> Result<(Vec<DocumentResponse>, Duration), Box<dyn std::error::Error + Send + Sync>> {
async fn timed_list_documents(&self) -> Result<(Vec<Value>, Duration), Box<dyn std::error::Error + Send + Sync>> {
let start = Instant::now();
let token = self.token.as_ref().ok_or("Not authenticated")?;
@@ -239,9 +240,9 @@ impl LoadTestClient {
}
let response_json: serde_json::Value = response.json().await?;
let documents: Vec<DocumentResponse> = serde_json::from_value(
response_json["documents"].clone()
)?;
let documents = response_json["documents"].as_array()
.ok_or("Invalid response format: missing documents array")?
.clone();
Ok((documents, elapsed))
}
@@ -319,7 +320,7 @@ async fn test_high_volume_document_uploads() {
let result = client_clone.timed_upload(&content, &filename).await;
match result {
Ok((document, duration)) => (i, true, duration, Some(document.id.to_string())),
Ok((document, duration)) => (i, true, duration, Some(document.document_id.to_string())),
Err(_) => (i, false, Duration::ZERO, None),
}
});
@@ -694,7 +695,7 @@ async fn test_system_stability_under_sustained_load() {
let content = format!("Stability test document {}", operation_counter);
let filename = format!("stability_{}.txt", operation_counter);
client.timed_upload(&content, &filename).await
.map(|(doc, duration)| (format!("upload({})", doc.id), duration))
.map(|(doc, duration)| (format!("upload({})", doc.document_id), duration))
}
_ => {
// Search operation