fix(tests): fix ocr endpoint tests due to our endpoint change

This commit is contained in:
perf3ct 2025-06-28 23:43:04 +00:00
parent 52b2cd6d88
commit 9e09bc019e
1 changed files with 35 additions and 41 deletions

View File

@ -172,12 +172,12 @@ async fn test_zero_failures_display_correctly() {
assert_eq!(result["statistics"]["total_failed"], 0); assert_eq!(result["statistics"]["total_failed"], 0);
assert!(result["documents"].is_array()); assert!(result["documents"].is_array());
assert_eq!(result["documents"].as_array().unwrap().len(), 0); assert_eq!(result["documents"].as_array().unwrap().len(), 0);
assert!(result["statistics"]["failure_categories"].is_array()); assert!(result["statistics"]["by_reason"].is_object());
assert_eq!(result["statistics"]["failure_categories"].as_array().unwrap().len(), 0); assert_eq!(result["statistics"]["by_reason"].as_object().unwrap().len(), 0);
// Verify pagination shows zero // Verify pagination shows zero
assert_eq!(result["pagination"]["total"], 0); assert_eq!(result["pagination"]["total"], 0);
assert_eq!(result["pagination"]["has_more"], false); assert_eq!(result["pagination"]["total_pages"], 0);
println!("✅ Zero failures are displayed correctly"); println!("✅ Zero failures are displayed correctly");
} }
@ -195,27 +195,21 @@ async fn test_failure_categories_structure() {
}; };
let result = client.get_failed_ocr_documents().await.unwrap(); let result = client.get_failed_ocr_documents().await.unwrap();
let failure_categories = &result["statistics"]["failure_categories"]; let by_reason = &result["statistics"]["by_reason"];
// Verify failure categories is an array // Verify by_reason is an object
assert!(failure_categories.is_array()); assert!(by_reason.is_object());
// Check structure of any failure categories that exist // Check structure of any failure reasons that exist
if let Some(categories) = failure_categories.as_array() { if let Some(reasons) = by_reason.as_object() {
for category in categories { for (reason, count) in reasons {
// Each category should have these fields // Each entry should have a non-empty reason and numeric count
assert!(category.get("reason").is_some(), "Category should have 'reason' field"); assert!(!reason.is_empty(), "Reason should not be empty");
assert!(category.get("display_name").is_some(), "Category should have 'display_name' field"); assert!(count.is_number(), "Count should be a number");
assert!(category.get("count").is_some(), "Category should have 'count' field");
// Verify data types
assert!(category["reason"].is_string(), "'reason' should be a string");
assert!(category["display_name"].is_string(), "'display_name' should be a string");
assert!(category["count"].is_number(), "'count' should be a number");
// Count should be non-negative // Count should be non-negative
let count = category["count"].as_i64().unwrap(); let count_val = count.as_i64().unwrap();
assert!(count >= 0, "Failure count should be non-negative"); assert!(count_val >= 0, "Failure count should be non-negative");
} }
} }
@ -274,17 +268,17 @@ async fn test_failure_category_counts_sum_to_total() {
let result = client.get_failed_ocr_documents().await.unwrap(); let result = client.get_failed_ocr_documents().await.unwrap();
let total_failed = result["statistics"]["total_failed"].as_i64().unwrap(); let total_failed = result["statistics"]["total_failed"].as_i64().unwrap();
let failure_categories = result["statistics"]["failure_categories"].as_array().unwrap(); let by_reason = result["statistics"]["by_reason"].as_object().unwrap();
// Sum up all category counts // Sum up all reason counts
let category_sum: i64 = failure_categories let reason_sum: i64 = by_reason
.iter() .values()
.map(|cat| cat["count"].as_i64().unwrap()) .map(|count| count.as_i64().unwrap())
.sum(); .sum();
// Category counts should sum to total failed // Reason counts should sum to total failed
assert_eq!(category_sum, total_failed, assert_eq!(reason_sum, total_failed,
"Sum of category counts should equal total failed count"); "Sum of reason counts should equal total failed count");
println!("✅ Failure category counts sum to total failed count"); println!("✅ Failure category counts sum to total failed count");
} }
@ -302,23 +296,23 @@ async fn test_failure_reason_classification() {
}; };
let result = client.get_failed_ocr_documents().await.unwrap(); let result = client.get_failed_ocr_documents().await.unwrap();
let failure_categories = result["statistics"]["failure_categories"].as_array().unwrap(); let by_reason = result["statistics"]["by_reason"].as_object().unwrap();
// Check that known failure reasons are properly categorized // Check that known failure reasons are properly categorized
let valid_display_names = vec![ let valid_reason_keys = vec![
"PDF Font Issues", "low_ocr_confidence",
"PDF Corruption", "ocr_timeout",
"Timeout", "ocr_memory_limit",
"Memory Limit", "pdf_parsing_error",
"PDF Parsing Error", "file_corrupted",
"Unknown Error", "unsupported_format",
"Other" "access_denied",
"other"
]; ];
for category in failure_categories { for (reason_key, _count) in by_reason {
let display_name = category["display_name"].as_str().unwrap(); assert!(valid_reason_keys.contains(&reason_key.as_str()),
assert!(valid_display_names.contains(&display_name), "Reason key '{}' should be one of the valid failure reasons", reason_key);
"Display name '{}' should be one of the valid categories", display_name);
} }
println!("✅ Failure reasons are properly classified"); println!("✅ Failure reasons are properly classified");