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

This commit is contained in:
perf3ct 2025-06-28 23:11:47 +00:00
parent 2797cb4367
commit fa7fd86622
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232
2 changed files with 25 additions and 19 deletions

View File

@ -84,11 +84,12 @@ interface FailedOcrResponse {
total: number; total: number;
limit: number; limit: number;
offset: number; offset: number;
has_more: boolean; total_pages: number;
}; };
statistics: { statistics: {
total_failed: number; total_failed: number;
failure_categories: FailureCategory[]; by_reason: Record<string, number>;
by_stage: Record<string, number>;
}; };
} }
@ -615,15 +616,15 @@ const FailedOcrPage: React.FC = () => {
Failure Categories Failure Categories
</Typography> </Typography>
<Box display="flex" flexWrap="wrap" gap={1}> <Box display="flex" flexWrap="wrap" gap={1}>
{statistics?.failure_categories?.map((category) => ( {statistics?.by_reason ? Object.entries(statistics.by_reason).map(([reason, count]) => (
<Chip <Chip
key={category.reason} key={reason}
label={`${category.display_name}: ${category.count}`} label={`${reason}: ${count}`}
color={getFailureCategoryColor(category.display_name)} color={getFailureCategoryColor(reason)}
variant="outlined" variant="outlined"
size="small" size="small"
/> />
)) || ( )) : (
<Typography variant="body2" color="text.secondary"> <Typography variant="body2" color="text.secondary">
No failure data available No failure data available
</Typography> </Typography>

View File

@ -250,12 +250,12 @@ async fn test_failed_ocr_endpoint_structure() {
assert!(pagination.get("total").is_some()); assert!(pagination.get("total").is_some());
assert!(pagination.get("limit").is_some()); assert!(pagination.get("limit").is_some());
assert!(pagination.get("offset").is_some()); assert!(pagination.get("offset").is_some());
assert!(pagination.get("has_more").is_some()); assert!(pagination.get("total_pages").is_some());
// Verify statistics structure // Verify statistics structure
let statistics = &failed_docs["statistics"]; let statistics = &failed_docs["statistics"];
assert!(statistics.get("total_failed").is_some()); assert!(statistics.get("total_failed").is_some());
assert!(statistics.get("failure_categories").is_some()); assert!(statistics.get("by_reason").is_some());
println!("✅ Failed OCR endpoint returns proper structure"); println!("✅ Failed OCR endpoint returns proper structure");
} }
@ -302,15 +302,20 @@ async fn test_failed_ocr_statistics_format() {
// Verify statistics format // Verify statistics format
assert!(statistics["total_failed"].is_number()); assert!(statistics["total_failed"].is_number());
assert!(statistics["failure_categories"].is_array()); assert!(statistics["by_reason"].is_object());
// Verify failure categories structure // Verify failure reasons structure
let categories = statistics["failure_categories"].as_array().unwrap(); let by_reason = statistics["by_reason"].as_object().unwrap();
for category in categories { for (reason, count) in by_reason {
assert!(category.get("reason").is_some()); assert!(!reason.is_empty());
assert!(category.get("display_name").is_some()); assert!(count.is_number());
assert!(category.get("count").is_some()); }
assert!(category["count"].is_number());
// Verify failure stages structure
let by_stage = statistics["by_stage"].as_object().unwrap();
for (stage, count) in by_stage {
assert!(!stage.is_empty());
assert!(count.is_number());
} }
println!("✅ Failed OCR statistics have correct format"); println!("✅ Failed OCR statistics have correct format");
@ -451,7 +456,7 @@ async fn test_failed_ocr_empty_response_structure() {
// Structure should be consistent regardless of document count // Structure should be consistent regardless of document count
assert!(failed_docs["documents"].is_array()); assert!(failed_docs["documents"].is_array());
assert!(failed_docs["statistics"]["total_failed"].is_number()); assert!(failed_docs["statistics"]["total_failed"].is_number());
assert!(failed_docs["statistics"]["failure_categories"].is_array()); assert!(failed_docs["statistics"]["by_reason"].is_object());
// The key test is structure consistency // The key test is structure consistency
let documents = failed_docs["documents"].as_array().unwrap(); let documents = failed_docs["documents"].as_array().unwrap();
@ -463,7 +468,7 @@ async fn test_failed_ocr_empty_response_structure() {
// Also test pagination values for empty result // Also test pagination values for empty result
assert_eq!(failed_docs["pagination"]["total"], 0); assert_eq!(failed_docs["pagination"]["total"], 0);
assert_eq!(failed_docs["pagination"]["has_more"], false); assert_eq!(failed_docs["pagination"]["total_pages"], 0);
println!("✅ Failed OCR endpoint returns consistent empty structure for new user"); println!("✅ Failed OCR endpoint returns consistent empty structure for new user");
} }