fix(tests): resolve tests checking `id` instead of `document_id`
This commit is contained in:
parent
bf2162ad89
commit
0e3418a35a
|
|
@ -11,6 +11,7 @@ use std::time::Duration;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use readur::models::{DocumentResponse, CreateUser, LoginRequest, LoginResponse, UserRole};
|
use readur::models::{DocumentResponse, CreateUser, LoginRequest, LoginResponse, UserRole};
|
||||||
|
use readur::routes::documents::types::DocumentUploadResponse;
|
||||||
|
|
||||||
fn get_base_url() -> String {
|
fn get_base_url() -> String {
|
||||||
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_string())
|
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_string())
|
||||||
|
|
@ -100,7 +101,7 @@ impl DocumentDeletionTestClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Upload a test document
|
/// 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 token = self.token.as_ref().ok_or("Not authenticated")?;
|
||||||
|
|
||||||
let form = multipart::Form::new()
|
let form = multipart::Form::new()
|
||||||
|
|
@ -120,7 +121,7 @@ impl DocumentDeletionTestClient {
|
||||||
return Err(format!("Document upload failed: {}", response.text().await?).into());
|
return Err(format!("Document upload failed: {}", response.text().await?).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let document: DocumentResponse = response.json().await?;
|
let document: DocumentUploadResponse = response.json().await?;
|
||||||
Ok(document)
|
Ok(document)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -317,24 +318,24 @@ async fn test_single_document_deletion_success() {
|
||||||
let document = client.upload_document(test_content, "test_deletion.txt")
|
let document = client.upload_document(test_content, "test_deletion.txt")
|
||||||
.await.expect("Failed to upload document");
|
.await.expect("Failed to upload document");
|
||||||
|
|
||||||
println!("Uploaded document: {}", document.id);
|
println!("Uploaded document: {}", document.document_id);
|
||||||
|
|
||||||
// Verify document exists
|
// 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");
|
.await.expect("Failed to get document");
|
||||||
assert!(retrieved_doc.is_some(), "Document should exist before deletion");
|
assert!(retrieved_doc.is_some(), "Document should exist before deletion");
|
||||||
|
|
||||||
// Delete the document
|
// 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");
|
.await.expect("Failed to delete document");
|
||||||
|
|
||||||
// Verify deletion response
|
// Verify deletion response
|
||||||
assert_eq!(delete_result["success"], true);
|
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);
|
assert_eq!(delete_result["filename"], document.filename);
|
||||||
|
|
||||||
// Verify document no longer exists
|
// 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");
|
.await.expect("Failed to check document existence");
|
||||||
assert!(retrieved_doc_after.is_none(), "Document should not exist after deletion");
|
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 test_content = format!("This is test document number {}", i);
|
||||||
let document = client.upload_document(test_content.as_bytes(), &format!("test_bulk_{}.txt", i))
|
let document = client.upload_document(test_content.as_bytes(), &format!("test_bulk_{}.txt", i))
|
||||||
.await.expect("Failed to upload document");
|
.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());
|
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
|
// Create a list with real and fake IDs
|
||||||
let fake_id = Uuid::new_v4().to_string();
|
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
|
// Perform bulk deletion
|
||||||
let delete_result = client.bulk_delete_documents(&mixed_ids)
|
let delete_result = client.bulk_delete_documents(&mixed_ids)
|
||||||
|
|
@ -492,10 +493,10 @@ async fn test_bulk_delete_mixed_existing_nonexistent() {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
assert_eq!(deleted_ids.len(), 1);
|
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
|
// 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");
|
.await.expect("Failed to check document existence");
|
||||||
assert!(retrieved_doc.is_none(), "Real document should be deleted");
|
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");
|
.await.expect("Failed to upload document as user 1");
|
||||||
|
|
||||||
// User 2 tries to delete user 1's document
|
// 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)
|
// Should return 404 (document not found for user 2)
|
||||||
assert!(delete_result.is_err(), "Cross-user deletion should fail");
|
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");
|
assert!(error_msg.contains("404"), "Should return 404 for document not owned by user");
|
||||||
|
|
||||||
// Verify user 1's document still exists
|
// 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");
|
.await.expect("Failed to check document existence");
|
||||||
assert!(retrieved_doc.is_some(), "User 1's document should still exist after failed cross-user deletion");
|
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");
|
.await.expect("Failed to upload document as user");
|
||||||
|
|
||||||
// Admin deletes user's document
|
// 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");
|
.await.expect("Admin should be able to delete any document");
|
||||||
|
|
||||||
// Verify deletion response
|
// Verify deletion response
|
||||||
assert_eq!(delete_result["success"], true);
|
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
|
// 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");
|
.await.expect("Failed to check document existence");
|
||||||
assert!(retrieved_doc.is_none(), "Document should be deleted by admin");
|
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 test_content = format!("Test document {}", i);
|
||||||
let document = client.upload_document(test_content.as_bytes(), &format!("count_test_{}.txt", i))
|
let document = client.upload_document(test_content.as_bytes(), &format!("count_test_{}.txt", i))
|
||||||
.await.expect("Failed to upload document");
|
.await.expect("Failed to upload document");
|
||||||
document_ids.push(document.id.to_string());
|
document_ids.push(document.document_id.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify count increased
|
// Verify count increased
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@ use std::time::{Duration, Instant};
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
use uuid::Uuid;
|
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 {
|
fn get_base_url() -> String {
|
||||||
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_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
|
/// 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);
|
println!("🔍 DEBUG: Uploading file: {} with MIME type: {}", filename, mime_type);
|
||||||
let token = self.token.as_ref().ok_or("Not authenticated")?;
|
let token = self.token.as_ref().ok_or("Not authenticated")?;
|
||||||
|
|
||||||
|
|
@ -164,13 +165,13 @@ impl FileProcessingTestClient {
|
||||||
let response_text = response.text().await?;
|
let response_text = response.text().await?;
|
||||||
println!("🟢 DEBUG: Upload response: {}", response_text);
|
println!("🟢 DEBUG: Upload response: {}", response_text);
|
||||||
|
|
||||||
let document: DocumentResponse = serde_json::from_str(&response_text)?;
|
let document: DocumentUploadResponse = serde_json::from_str(&response_text)?;
|
||||||
println!("✅ DEBUG: Successfully parsed document: {}", document.id);
|
println!("✅ DEBUG: Successfully parsed document: {}", document.document_id);
|
||||||
Ok(document)
|
Ok(document)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Upload binary file content
|
/// 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 token = self.token.as_ref().ok_or("Not authenticated")?;
|
||||||
|
|
||||||
let part = reqwest::multipart::Part::bytes(content)
|
let part = reqwest::multipart::Part::bytes(content)
|
||||||
|
|
@ -196,8 +197,8 @@ impl FileProcessingTestClient {
|
||||||
let response_text = response.text().await?;
|
let response_text = response.text().await?;
|
||||||
println!("🟢 DEBUG: Binary upload response: {}", response_text);
|
println!("🟢 DEBUG: Binary upload response: {}", response_text);
|
||||||
|
|
||||||
let document: DocumentResponse = serde_json::from_str(&response_text)?;
|
let document: DocumentUploadResponse = serde_json::from_str(&response_text)?;
|
||||||
println!("✅ DEBUG: Successfully parsed binary document: {}", document.id);
|
println!("✅ DEBUG: Successfully parsed binary document: {}", document.document_id);
|
||||||
Ok(document)
|
Ok(document)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -369,7 +370,7 @@ End of test document."#;
|
||||||
let document = client.upload_file(text_content, "test_pipeline.txt", "text/plain").await
|
let document = client.upload_file(text_content, "test_pipeline.txt", "text/plain").await
|
||||||
.expect("Failed to upload text file");
|
.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);
|
println!("✅ Text file uploaded: {}", document_id);
|
||||||
|
|
||||||
// Validate initial document properties
|
// 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;
|
let empty_result = client.upload_file("", "empty.txt", "text/plain").await;
|
||||||
match empty_result {
|
match empty_result {
|
||||||
Ok(document) => {
|
Ok(document) => {
|
||||||
println!("✅ Empty file uploaded: {}", document.id);
|
println!("✅ Empty file uploaded: {}", document.document_id);
|
||||||
|
|
||||||
// Try to process empty file
|
// 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) => {
|
Ok(processed) => {
|
||||||
println!("✅ Empty file processing completed: {:?}", processed.ocr_status);
|
println!("✅ Empty file processing completed: {:?}", processed.ocr_status);
|
||||||
}
|
}
|
||||||
|
|
@ -742,10 +743,10 @@ async fn test_processing_error_recovery() {
|
||||||
|
|
||||||
match corrupted_result {
|
match corrupted_result {
|
||||||
Ok(document) => {
|
Ok(document) => {
|
||||||
println!("✅ Corrupted file uploaded: {}", document.id);
|
println!("✅ Corrupted file uploaded: {}", document.document_id);
|
||||||
|
|
||||||
// Processing should handle the mismatch gracefully
|
// 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) => {
|
Ok(processed) => {
|
||||||
println!("✅ Corrupted file processed: {:?}", processed.ocr_status);
|
println!("✅ Corrupted file processed: {:?}", processed.ocr_status);
|
||||||
}
|
}
|
||||||
|
|
@ -767,10 +768,10 @@ async fn test_processing_error_recovery() {
|
||||||
|
|
||||||
match special_result {
|
match special_result {
|
||||||
Ok(document) => {
|
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);
|
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"),
|
Ok(_) => println!("✅ Special filename file processed successfully"),
|
||||||
Err(e) => println!("⚠️ Special filename file processing failed: {}", e),
|
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);
|
println!("✅ {} uploaded in {:?}", filename, upload_time);
|
||||||
|
|
||||||
// Wait for processing and measure 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) => {
|
Ok(processed_doc) => {
|
||||||
let total_processing_time = processing_start.elapsed();
|
let total_processing_time = processing_start.elapsed();
|
||||||
|
|
||||||
// Get OCR results to check reported processing time
|
// 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"]
|
let reported_time = ocr_results["ocr_processing_time_ms"]
|
||||||
.as_i64()
|
.as_i64()
|
||||||
.map(|ms| Duration::from_millis(ms as u64));
|
.map(|ms| Duration::from_millis(ms as u64));
|
||||||
|
|
@ -948,8 +949,8 @@ async fn test_concurrent_file_processing() {
|
||||||
if response.status().is_success() {
|
if response.status().is_success() {
|
||||||
let response_text = response.text().await
|
let response_text = response.text().await
|
||||||
.expect("Should get response text");
|
.expect("Should get response text");
|
||||||
let document: DocumentResponse = serde_json::from_str(&response_text)
|
let document: DocumentUploadResponse = serde_json::from_str(&response_text)
|
||||||
.expect("Should parse document response");
|
.expect("Should parse document upload response");
|
||||||
Ok((i, document, upload_time))
|
Ok((i, document, upload_time))
|
||||||
} else {
|
} else {
|
||||||
Err((i, response.text().await.unwrap_or_default()))
|
Err((i, response.text().await.unwrap_or_default()))
|
||||||
|
|
@ -964,7 +965,7 @@ async fn test_concurrent_file_processing() {
|
||||||
for handle in upload_handles {
|
for handle in upload_handles {
|
||||||
match handle.await.expect("Upload task should complete") {
|
match handle.await.expect("Upload task should complete") {
|
||||||
Ok((index, document, upload_time)) => {
|
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);
|
uploaded_documents.push(document);
|
||||||
}
|
}
|
||||||
Err((index, error)) => {
|
Err((index, error)) => {
|
||||||
|
|
@ -1138,11 +1139,11 @@ async fn test_real_test_images_processing() {
|
||||||
};
|
};
|
||||||
|
|
||||||
let upload_time = upload_start.elapsed();
|
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
|
// Wait for OCR processing
|
||||||
let processing_start = std::time::Instant::now();
|
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) => {
|
Ok(processed_doc) => {
|
||||||
let processing_time = processing_start.elapsed();
|
let processing_time = processing_start.elapsed();
|
||||||
println!("✅ {} processed in {:?}: status = {:?}",
|
println!("✅ {} processed in {:?}: status = {:?}",
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ use serde_json::{json, Value};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use tokio::time::sleep;
|
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 {
|
fn get_base_url() -> String {
|
||||||
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_string())
|
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_string())
|
||||||
|
|
@ -95,7 +96,7 @@ impl TestClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Upload a test document
|
/// 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 token = self.token.as_ref().ok_or("Not authenticated")?;
|
||||||
|
|
||||||
let part = reqwest::multipart::Part::text(content.to_string())
|
let part = reqwest::multipart::Part::text(content.to_string())
|
||||||
|
|
@ -115,7 +116,7 @@ impl TestClient {
|
||||||
return Err(format!("Upload failed: {}", response.text().await?).into());
|
return Err(format!("Upload failed: {}", response.text().await?).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let document: DocumentResponse = response.json().await?;
|
let document: DocumentUploadResponse = response.json().await?;
|
||||||
Ok(document)
|
Ok(document)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,7 +213,7 @@ Technology: Rust + Axum + SQLx"#;
|
||||||
let document = client.upload_document(test_content, "rust_test.txt").await
|
let document = client.upload_document(test_content, "rust_test.txt").await
|
||||||
.expect("Failed to upload document");
|
.expect("Failed to upload document");
|
||||||
|
|
||||||
println!("✅ Document uploaded: {}", document.id);
|
println!("✅ Document uploaded: {}", document.document_id);
|
||||||
|
|
||||||
// Validate document response structure using our types
|
// Validate document response structure using our types
|
||||||
assert!(!document.filename.is_empty());
|
assert!(!document.filename.is_empty());
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ use std::time::{Duration, Instant};
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
use uuid::Uuid;
|
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 {
|
fn get_base_url() -> String {
|
||||||
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_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());
|
return Err(format!("Upload failed: {}", response.text().await?).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let document: DocumentResponse = response.json().await?;
|
let document: DocumentUploadResponse = response.json().await?;
|
||||||
Ok((document.id, content.to_string()))
|
Ok((document.document_id, content.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get document details including OCR status
|
/// Get document details including OCR status
|
||||||
|
|
@ -195,8 +196,8 @@ impl OcrTestClient {
|
||||||
return Err(format!("Upload failed: {}", response.text().await?).into());
|
return Err(format!("Upload failed: {}", response.text().await?).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let document: DocumentResponse = response.json().await?;
|
let document: DocumentUploadResponse = response.json().await?;
|
||||||
Ok::<(Uuid, String), Box<dyn std::error::Error>>((document.id, content_owned))
|
Ok::<(Uuid, String), Box<dyn std::error::Error>>((document.document_id, content_owned))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ use std::time::{Duration, Instant};
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
use uuid::Uuid;
|
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 {
|
fn get_base_url() -> String {
|
||||||
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_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
|
/// 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 token = self.token.as_ref().ok_or("Not authenticated")?;
|
||||||
|
|
||||||
let part = reqwest::multipart::Part::text(content.to_string())
|
let part = reqwest::multipart::Part::text(content.to_string())
|
||||||
|
|
@ -178,14 +179,14 @@ impl OCRQueueTestClient {
|
||||||
return Err(format!("Upload failed: {}", text).into());
|
return Err(format!("Upload failed: {}", text).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let document: DocumentResponse = response.json().await?;
|
let document: DocumentUploadResponse = response.json().await?;
|
||||||
println!("📄 Document uploaded: {} (filename: {}, has_ocr_text: {}, ocr_status: {:?})",
|
println!("📄 Document uploaded: {} (filename: {}, size: {})",
|
||||||
document.id, filename, document.has_ocr_text, document.ocr_status);
|
document.document_id, filename, document.file_size);
|
||||||
Ok(document)
|
Ok(document)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Upload multiple documents concurrently
|
/// 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();
|
let mut handles = Vec::new();
|
||||||
|
|
||||||
for i in 0..count {
|
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
|
let document = client.upload_document("Test document for queue monitoring", "queue_test.txt").await
|
||||||
.expect("Failed to upload document");
|
.expect("Failed to upload document");
|
||||||
|
|
||||||
println!("✅ Document uploaded: {}", document.id);
|
println!("✅ Document uploaded: {}", document.document_id);
|
||||||
|
|
||||||
// Wait a moment for queue to update
|
// Wait a moment for queue to update
|
||||||
sleep(Duration::from_secs(2)).await;
|
sleep(Duration::from_secs(2)).await;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ use tokio::time::sleep;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use chrono;
|
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 {
|
fn get_base_url() -> String {
|
||||||
std::env::var("API_URL").unwrap_or_else(|_| "http://localhost:8000".to_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
|
/// 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 start = Instant::now();
|
||||||
let token = self.token.as_ref().ok_or("Not authenticated")?;
|
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());
|
return Err(format!("Upload failed: {}", response.text().await?).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let document: DocumentResponse = response.json().await?;
|
let document: DocumentUploadResponse = response.json().await?;
|
||||||
Ok((document, elapsed))
|
Ok((document, elapsed))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform a timed document list request
|
/// 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 start = Instant::now();
|
||||||
let token = self.token.as_ref().ok_or("Not authenticated")?;
|
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 response_json: serde_json::Value = response.json().await?;
|
||||||
let documents: Vec<DocumentResponse> = serde_json::from_value(
|
let documents = response_json["documents"].as_array()
|
||||||
response_json["documents"].clone()
|
.ok_or("Invalid response format: missing documents array")?
|
||||||
)?;
|
.clone();
|
||||||
Ok((documents, elapsed))
|
Ok((documents, elapsed))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -319,7 +320,7 @@ async fn test_high_volume_document_uploads() {
|
||||||
let result = client_clone.timed_upload(&content, &filename).await;
|
let result = client_clone.timed_upload(&content, &filename).await;
|
||||||
|
|
||||||
match result {
|
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),
|
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 content = format!("Stability test document {}", operation_counter);
|
||||||
let filename = format!("stability_{}.txt", operation_counter);
|
let filename = format!("stability_{}.txt", operation_counter);
|
||||||
client.timed_upload(&content, &filename).await
|
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
|
// Search operation
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue