Merged in feature/fix_test_timeouts (pull request #194)
text extractions tests * increase timeout for slow ci/cd systems * add tests
This commit is contained in:
@@ -251,7 +251,7 @@ func verifyFolderMetrics(t *testing.T, net test.Network, clientID string) {
|
||||
t.Helper()
|
||||
|
||||
// List all folders for the client using the new endpoint
|
||||
foldersRes, err := net.Client.ListClientFoldersWithResponse(t.Context(), queryapi.ClientID(clientID))
|
||||
foldersRes, err := net.Client.ListClientFoldersWithResponse(t.Context(), queryapi.ClientID(clientID), nil)
|
||||
require.NoError(t, err, "Failed to list client folders")
|
||||
if foldersRes.JSON200 == nil {
|
||||
t.Logf("Response status: %d, body: %s", foldersRes.StatusCode(), string(foldersRes.Body))
|
||||
@@ -873,7 +873,7 @@ func TestFolderAPI(t *testing.T) {
|
||||
|
||||
// Get the root folder and verify its metrics separately
|
||||
fmt.Println("\n=== Testing root folder metrics ===")
|
||||
foldersRes, err := net.Client.ListClientFoldersWithResponse(t.Context(), queryapi.ClientID(clientID))
|
||||
foldersRes, err := net.Client.ListClientFoldersWithResponse(t.Context(), queryapi.ClientID(clientID), nil)
|
||||
require.NoError(t, err, "Failed to list client folders")
|
||||
require.NotNil(t, foldersRes.JSON200, "Expected 200 for folder list")
|
||||
|
||||
@@ -912,5 +912,506 @@ func ptr(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
// ptrFloat64 returns a pointer to a float64 value.
|
||||
func ptrFloat64(f float64) *float64 {
|
||||
return &f
|
||||
}
|
||||
|
||||
// ptrBool returns a pointer to a bool value.
|
||||
func ptrBool(b bool) *bool {
|
||||
return &b
|
||||
}
|
||||
|
||||
// TestDeepFolderHierarchy tests folder creation with 10+ levels of nesting
|
||||
// (Phase 10 - Scenario 4: Folder hierarchy with recursive queries).
|
||||
func TestDeepFolderHierarchy(t *testing.T) {
|
||||
cfg := &TextExtractionConfig{}
|
||||
|
||||
// Create full network
|
||||
net, cleanup := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||
defer cleanup()
|
||||
|
||||
// Create test client
|
||||
clientName := fmt.Sprintf("DeepFolderTestClient_%d", time.Now().UnixNano())
|
||||
clientExternalID := fmt.Sprintf("deep-fld-%d", time.Now().Unix())
|
||||
createRes, err := net.Client.CreateClientWithResponse(t.Context(), queryapi.ClientCreate{
|
||||
Name: clientName,
|
||||
Id: clientExternalID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, createRes.JSON201, "Expected 201 response for client creation, got status %d", createRes.StatusCode())
|
||||
clientID := createRes.JSON201.Id
|
||||
fmt.Printf("Created client: %s\n", clientID)
|
||||
|
||||
// Enable sync
|
||||
canSync := true
|
||||
_, err = net.Client.UpdateClientWithResponse(t.Context(), clientID, queryapi.ClientUpdate{
|
||||
CanSync: &canSync,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create 12 levels of nested folders
|
||||
fmt.Println("\n=== Creating 12 levels of nested folders ===")
|
||||
const folderDepth = 12
|
||||
var parentID *openapi_types.UUID
|
||||
var folderIDs []openapi_types.UUID
|
||||
var currentPath string
|
||||
|
||||
for i := 1; i <= folderDepth; i++ {
|
||||
currentPath = fmt.Sprintf("%s/level%d", currentPath, i)
|
||||
createFolderReq := queryapi.CreateFolderJSONRequestBody{
|
||||
Path: currentPath,
|
||||
ClientId: clientID,
|
||||
CreatedBy: "test@example.com",
|
||||
}
|
||||
if parentID != nil {
|
||||
createFolderReq.ParentId = parentID
|
||||
}
|
||||
|
||||
folderRes, err := net.Client.CreateFolderWithResponse(t.Context(), createFolderReq)
|
||||
require.NoError(t, err, "Failed to create folder at level %d", i)
|
||||
require.NotNil(t, folderRes.JSON201, "Expected 201 for folder at level %d, got %d with body: %s",
|
||||
i, folderRes.StatusCode(), string(folderRes.Body))
|
||||
|
||||
folderID := folderRes.JSON201.Id
|
||||
folderIDs = append(folderIDs, folderID)
|
||||
parentID = &folderID
|
||||
fmt.Printf(" Level %d: ID=%s, Path=%s\n", i, folderID, currentPath)
|
||||
}
|
||||
|
||||
assert.Len(t, folderIDs, folderDepth, "Should have created %d folders", folderDepth)
|
||||
|
||||
// List all folders and verify count
|
||||
fmt.Println("\n=== Listing all folders for client ===")
|
||||
foldersRes, err := net.Client.ListClientFoldersWithResponse(t.Context(), queryapi.ClientID(clientID), nil)
|
||||
require.NoError(t, err, "Failed to list client folders")
|
||||
require.NotNil(t, foldersRes.JSON200, "Expected 200 response for folder list")
|
||||
|
||||
// Should have at least 12 folders (plus root if created)
|
||||
fmt.Printf(" Total folders found: %d\n", len(foldersRes.JSON200.Folders))
|
||||
assert.GreaterOrEqual(t, len(foldersRes.JSON200.Folders), folderDepth,
|
||||
"Expected at least %d folders", folderDepth)
|
||||
|
||||
// Verify we can get metrics for the deepest folder
|
||||
fmt.Println("\n=== Testing metrics for deepest folder (level 12) ===")
|
||||
deepestFolderID := folderIDs[len(folderIDs)-1]
|
||||
metricsRes, err := net.Client.GetFolderMetricsWithResponse(t.Context(), deepestFolderID)
|
||||
require.NoError(t, err, "Failed to get metrics for deepest folder")
|
||||
require.NotNil(t, metricsRes.JSON200, "Expected 200 for deepest folder metrics")
|
||||
fmt.Printf(" Deepest folder metrics: folderId=%s, totalDocuments=%d\n",
|
||||
metricsRes.JSON200.FolderId, metricsRes.JSON200.TotalDocuments)
|
||||
assert.Equal(t, deepestFolderID, metricsRes.JSON200.FolderId,
|
||||
"Metrics should be for the requested folder")
|
||||
|
||||
// Verify we can get documents for the deepest folder (should be empty)
|
||||
fmt.Println("\n=== Testing documents for deepest folder ===")
|
||||
docsRes, err := net.Client.GetFolderDocumentsWithResponse(t.Context(), deepestFolderID)
|
||||
require.NoError(t, err, "Failed to get documents for deepest folder")
|
||||
require.NotNil(t, docsRes.JSON200, "Expected 200 for folder documents")
|
||||
docCount := 0
|
||||
if docsRes.JSON200.Documents != nil {
|
||||
docCount = len(*docsRes.JSON200.Documents)
|
||||
}
|
||||
fmt.Printf(" Documents in deepest folder: %d\n", docCount)
|
||||
|
||||
fmt.Println("\n=== Deep folder hierarchy test complete ===")
|
||||
}
|
||||
|
||||
// TestLargeArrayFieldExtraction tests field extraction creation with large array sizes (N=100)
|
||||
// (Phase 10 - Performance test: Large array sizes).
|
||||
func TestLargeArrayFieldExtraction(t *testing.T) {
|
||||
cfg := &TextExtractionConfig{}
|
||||
|
||||
// Create full network
|
||||
net, cleanup := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||
defer cleanup()
|
||||
|
||||
// Create test client
|
||||
clientName := fmt.Sprintf("LargeArrayTestClient_%d", time.Now().UnixNano())
|
||||
clientExternalID := fmt.Sprintf("lg-array-%d", time.Now().Unix())
|
||||
createRes, err := net.Client.CreateClientWithResponse(t.Context(), queryapi.ClientCreate{
|
||||
Name: clientName,
|
||||
Id: clientExternalID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, createRes.JSON201, "Expected 201 response for client creation")
|
||||
clientID := createRes.JSON201.Id
|
||||
fmt.Printf("Created client: %s\n", clientID)
|
||||
|
||||
// Enable sync
|
||||
canSync := true
|
||||
_, err = net.Client.UpdateClientWithResponse(t.Context(), clientID, queryapi.ClientUpdate{
|
||||
CanSync: &canSync,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Upload a single document
|
||||
fmt.Println("\n=== Uploading document ===")
|
||||
uploadSingleDocument(t, net.Client, clientID, "large_array_test.pdf")
|
||||
|
||||
// Wait for document to appear
|
||||
var documents []queryapi.DocumentSummary
|
||||
waitForDocumentCount(t, net.Client, clientID, 1, &documents)
|
||||
require.Len(t, documents, 1, "Expected 1 document")
|
||||
docID := documents[0].Id
|
||||
fmt.Printf(" Document uploaded: ID=%s\n", docID)
|
||||
|
||||
// Create field extraction with 100 array field items
|
||||
fmt.Println("\n=== Creating field extraction with 100 array items ===")
|
||||
const arraySize = 100
|
||||
arrayFields := make([]queryapi.ArrayFieldItem, arraySize)
|
||||
for i := 0; i < arraySize; i++ {
|
||||
arrayFields[i] = queryapi.ArrayFieldItem{
|
||||
ExhibitTitle: ptr(fmt.Sprintf("Exhibit %d", i+1)),
|
||||
ExhibitPage: ptr(fmt.Sprintf("%d", i+1)),
|
||||
ReimbProvTin: ptr(fmt.Sprintf("%09d", i+100000000)),
|
||||
ReimbProvNpi: ptr(fmt.Sprintf("%010d", i+1000000000)),
|
||||
ReimbProvName: ptr(fmt.Sprintf("Provider %d", i+1)),
|
||||
AareteDerivedClaimTypeCd: ptr("INPATIENT"),
|
||||
ReimbPctRate: ptrFloat64(float64(80+i%20) + float64(i%100)/100.0),
|
||||
ReimbFeeRate: ptrFloat64(float64(100 + i*10)),
|
||||
CarveoutInd: ptrBool(i%2 == 0),
|
||||
DefaultInd: ptrBool(i == 0),
|
||||
}
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
createFieldExtRes, err := net.Client.CreateFieldExtractionWithResponse(t.Context(), queryapi.CreateFieldExtractionJSONRequestBody{
|
||||
DocumentId: docID,
|
||||
SingleFields: queryapi.SingleFields{
|
||||
FileName: ptr("large_array_test.pdf"),
|
||||
ContractTitle: ptr("Large Array Performance Test Contract"),
|
||||
ClientName: ptr("Performance Test Client"),
|
||||
},
|
||||
ArrayFields: arrayFields,
|
||||
CreatedBy: openapi_types.Email("test@example.com"),
|
||||
})
|
||||
createDuration := time.Since(startTime)
|
||||
require.NoError(t, err, "Failed to create field extraction")
|
||||
|
||||
if createFieldExtRes.JSON400 != nil {
|
||||
t.Fatalf("Got 400 error creating field extraction: %s", createFieldExtRes.JSON400.Message)
|
||||
}
|
||||
require.NotNil(t, createFieldExtRes.JSON201, "Expected 201 for field extraction, got %d with body: %s",
|
||||
createFieldExtRes.StatusCode(), string(createFieldExtRes.Body))
|
||||
|
||||
fmt.Printf(" Field extraction created in %v\n", createDuration)
|
||||
fmt.Printf(" Version: %d\n", createFieldExtRes.JSON201.Version)
|
||||
|
||||
// Verify the current field extraction
|
||||
fmt.Println("\n=== Verifying current field extraction ===")
|
||||
getFieldExtRes, err := net.Client.GetCurrentFieldExtractionWithResponse(t.Context(), &queryapi.GetCurrentFieldExtractionParams{
|
||||
DocumentId: docID,
|
||||
})
|
||||
require.NoError(t, err, "Failed to get current field extraction")
|
||||
require.NotNil(t, getFieldExtRes.JSON200, "Expected 200 for get field extraction")
|
||||
|
||||
// Verify array field count
|
||||
actualArraySize := len(getFieldExtRes.JSON200.ArrayFields)
|
||||
fmt.Printf(" Array fields returned: %d\n", actualArraySize)
|
||||
assert.Equal(t, arraySize, actualArraySize, "Expected %d array fields", arraySize)
|
||||
|
||||
// Verify single fields
|
||||
assert.NotNil(t, getFieldExtRes.JSON200.SingleFields.ContractTitle)
|
||||
if getFieldExtRes.JSON200.SingleFields.ContractTitle != nil {
|
||||
assert.Equal(t, "Large Array Performance Test Contract", *getFieldExtRes.JSON200.SingleFields.ContractTitle)
|
||||
}
|
||||
|
||||
// Performance assertion: should complete reasonably quickly (under 30 seconds)
|
||||
assert.Less(t, createDuration, 30*time.Second,
|
||||
"Field extraction with 100 array items should complete in under 30 seconds")
|
||||
|
||||
fmt.Println("\n=== Large array field extraction test complete ===")
|
||||
}
|
||||
|
||||
// TestLabelReapplicationHistory tests applying the same label multiple times to track history
|
||||
// (Phase 10 - Performance test: Many labels per document history).
|
||||
func TestLabelReapplicationHistory(t *testing.T) {
|
||||
cfg := &TextExtractionConfig{}
|
||||
|
||||
// Create full network
|
||||
net, cleanup := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||
defer cleanup()
|
||||
|
||||
// Create test client
|
||||
clientName := fmt.Sprintf("LabelHistoryTestClient_%d", time.Now().UnixNano())
|
||||
clientExternalID := fmt.Sprintf("lbl-hist-%d", time.Now().Unix())
|
||||
createRes, err := net.Client.CreateClientWithResponse(t.Context(), queryapi.ClientCreate{
|
||||
Name: clientName,
|
||||
Id: clientExternalID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, createRes.JSON201, "Expected 201 response for client creation")
|
||||
clientID := createRes.JSON201.Id
|
||||
fmt.Printf("Created client: %s\n", clientID)
|
||||
|
||||
// Enable sync
|
||||
canSync := true
|
||||
_, err = net.Client.UpdateClientWithResponse(t.Context(), clientID, queryapi.ClientUpdate{
|
||||
CanSync: &canSync,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Upload a single document
|
||||
fmt.Println("\n=== Uploading document ===")
|
||||
uploadSingleDocument(t, net.Client, clientID, "label_history_test.pdf")
|
||||
|
||||
// Wait for document to appear
|
||||
var documents []queryapi.DocumentSummary
|
||||
waitForDocumentCount(t, net.Client, clientID, 1, &documents)
|
||||
require.Len(t, documents, 1, "Expected 1 document")
|
||||
docID := documents[0].Id
|
||||
fmt.Printf(" Document uploaded: ID=%s\n", docID)
|
||||
|
||||
// Apply each of the 5 available labels multiple times to build history
|
||||
// Note: The system has 5 predefined labels: Ingested, OCR_Processed, GenAI_Processed, Doczy_AI_Completed, Dashboard_Ready
|
||||
labels := []string{"Ingested", "OCR_Processed", "GenAI_Processed", "Doczy_AI_Completed", "Dashboard_Ready"}
|
||||
const applicationsPerLabel = 4
|
||||
|
||||
fmt.Printf("\n=== Applying each label %d times (total %d label applications) ===\n",
|
||||
applicationsPerLabel, len(labels)*applicationsPerLabel)
|
||||
|
||||
totalApplications := 0
|
||||
for round := 1; round <= applicationsPerLabel; round++ {
|
||||
for _, label := range labels {
|
||||
applyLabelRes, err := net.Client.ApplyLabelWithResponse(t.Context(), docID, queryapi.ApplyLabelJSONRequestBody{
|
||||
Label: label,
|
||||
AppliedBy: openapi_types.Email(fmt.Sprintf("user%d@example.com", round)),
|
||||
})
|
||||
require.NoError(t, err, "Failed to apply label %s in round %d", label, round)
|
||||
|
||||
if applyLabelRes.JSON201 != nil {
|
||||
totalApplications++
|
||||
if round == 1 || round == applicationsPerLabel {
|
||||
fmt.Printf(" Round %d: Applied '%s'\n", round, label)
|
||||
}
|
||||
} else if applyLabelRes.JSON400 != nil {
|
||||
// This might happen if re-application isn't allowed - that's informative
|
||||
t.Logf(" Round %d: Label '%s' returned 400: %s", round, label, applyLabelRes.JSON400.Message)
|
||||
}
|
||||
}
|
||||
if round == 1 {
|
||||
fmt.Println(" ...")
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf(" Total successful label applications: %d\n", totalApplications)
|
||||
|
||||
// Get all labels for the document and verify history
|
||||
fmt.Println("\n=== Verifying label history ===")
|
||||
getLabelsRes, err := net.Client.GetDocumentLabelsWithResponse(t.Context(), docID)
|
||||
require.NoError(t, err, "Failed to get document labels")
|
||||
require.NotNil(t, getLabelsRes.JSON200, "Expected 200 for get labels")
|
||||
|
||||
labelCount := 0
|
||||
if getLabelsRes.JSON200.Labels != nil {
|
||||
labelCount = len(*getLabelsRes.JSON200.Labels)
|
||||
}
|
||||
fmt.Printf(" Total label entries in history: %d\n", labelCount)
|
||||
|
||||
// If re-application is allowed, we should have multiple entries
|
||||
// If not, we should have exactly 5 (one per unique label)
|
||||
if labelCount == len(labels) {
|
||||
fmt.Println(" Note: System appears to keep only most recent application per label")
|
||||
} else if labelCount == totalApplications {
|
||||
fmt.Println(" Note: System preserves full history of all label applications")
|
||||
}
|
||||
|
||||
// The key test: verify we have at least one entry per label
|
||||
assert.GreaterOrEqual(t, labelCount, len(labels),
|
||||
"Should have at least one entry per label type")
|
||||
|
||||
// Verify we can query documents by each label
|
||||
fmt.Println("\n=== Verifying query by label ===")
|
||||
for _, label := range labels {
|
||||
getDocsByLabelRes, err := net.Client.GetDocumentsByLabelWithResponse(t.Context(), label, &queryapi.GetDocumentsByLabelParams{
|
||||
ClientId: queryapi.ClientID(clientID),
|
||||
})
|
||||
require.NoError(t, err, "Failed to get documents by label %s", label)
|
||||
require.NotNil(t, getDocsByLabelRes.JSON200, "Expected 200 for get documents by label %s", label)
|
||||
|
||||
docCount := 0
|
||||
if getDocsByLabelRes.JSON200.Documents != nil {
|
||||
docCount = len(*getDocsByLabelRes.JSON200.Documents)
|
||||
}
|
||||
assert.Equal(t, 1, docCount, "Expected 1 document with label '%s'", label)
|
||||
}
|
||||
fmt.Println(" All labels return the document correctly")
|
||||
|
||||
fmt.Println("\n=== Label reapplication history test complete ===")
|
||||
}
|
||||
|
||||
// TestFieldExtractionByFolderAndLabel tests Scenario 2: Query field extractions by folder and label
|
||||
// (Phase 10 - Scenario 2: Cross-feature integration).
|
||||
// This test uses a simpler approach - single document upload to test cross-feature integration.
|
||||
func TestFieldExtractionByFolderAndLabel(t *testing.T) {
|
||||
cfg := &TextExtractionConfig{}
|
||||
|
||||
// Create full network
|
||||
net, cleanup := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||
defer cleanup()
|
||||
|
||||
// Create test client
|
||||
clientName := fmt.Sprintf("FolderLabelFETestClient_%d", time.Now().UnixNano())
|
||||
clientExternalID := fmt.Sprintf("fld-lbl-fe-%d", time.Now().Unix())
|
||||
createRes, err := net.Client.CreateClientWithResponse(t.Context(), queryapi.ClientCreate{
|
||||
Name: clientName,
|
||||
Id: clientExternalID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, createRes.JSON201, "Expected 201 response for client creation, got status: %d, body: %s",
|
||||
createRes.StatusCode(), string(createRes.Body))
|
||||
clientID := createRes.JSON201.Id
|
||||
fmt.Printf("Created client: %s\n", clientID)
|
||||
|
||||
// Enable sync
|
||||
canSync := true
|
||||
_, err = net.Client.UpdateClientWithResponse(t.Context(), clientID, queryapi.ClientUpdate{
|
||||
CanSync: &canSync,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create two folders
|
||||
fmt.Println("\n=== Creating folders ===")
|
||||
folder1Res, err := net.Client.CreateFolderWithResponse(t.Context(), queryapi.CreateFolderJSONRequestBody{
|
||||
Path: "/contracts",
|
||||
ClientId: clientID,
|
||||
CreatedBy: "test@example.com",
|
||||
})
|
||||
require.NoError(t, err, "Failed to create folder1")
|
||||
require.NotNil(t, folder1Res.JSON201, "Expected 201 for folder1")
|
||||
folder1ID := folder1Res.JSON201.Id
|
||||
fmt.Printf(" Created /contracts folder: ID=%s\n", folder1ID)
|
||||
|
||||
folder2Res, err := net.Client.CreateFolderWithResponse(t.Context(), queryapi.CreateFolderJSONRequestBody{
|
||||
Path: "/invoices",
|
||||
ClientId: clientID,
|
||||
CreatedBy: "test@example.com",
|
||||
})
|
||||
require.NoError(t, err, "Failed to create folder2")
|
||||
require.NotNil(t, folder2Res.JSON201, "Expected 201 for folder2")
|
||||
folder2ID := folder2Res.JSON201.Id
|
||||
fmt.Printf(" Created /invoices folder: ID=%s\n", folder2ID)
|
||||
|
||||
// Upload single document and wait for it
|
||||
fmt.Println("\n=== Uploading document ===")
|
||||
uploadSingleDocument(t, net.Client, clientID, "contract_doc.pdf")
|
||||
|
||||
var documents []queryapi.DocumentSummary
|
||||
waitForDocumentCount(t, net.Client, clientID, 1, &documents)
|
||||
require.Len(t, documents, 1, "Expected 1 document")
|
||||
docID := documents[0].Id
|
||||
fmt.Printf(" Uploaded document: ID=%s\n", docID)
|
||||
|
||||
// Apply labels to document
|
||||
fmt.Println("\n=== Applying labels ===")
|
||||
for _, label := range []string{"Ingested", "OCR_Processed", "Dashboard_Ready"} {
|
||||
_, err := net.Client.ApplyLabelWithResponse(t.Context(), docID, queryapi.ApplyLabelJSONRequestBody{
|
||||
Label: label,
|
||||
AppliedBy: openapi_types.Email("test@example.com"),
|
||||
})
|
||||
require.NoError(t, err, "Failed to apply label %s", label)
|
||||
}
|
||||
fmt.Printf(" Applied Ingested, OCR_Processed, Dashboard_Ready\n")
|
||||
|
||||
// Create field extraction
|
||||
fmt.Println("\n=== Creating field extraction ===")
|
||||
feRes, err := net.Client.CreateFieldExtractionWithResponse(t.Context(), queryapi.CreateFieldExtractionJSONRequestBody{
|
||||
DocumentId: docID,
|
||||
SingleFields: queryapi.SingleFields{
|
||||
FileName: ptr("contract_doc.pdf"),
|
||||
ContractTitle: ptr("Service Agreement"),
|
||||
ClientName: ptr("Test Client"),
|
||||
},
|
||||
ArrayFields: []queryapi.ArrayFieldItem{
|
||||
{
|
||||
ExhibitTitle: ptr("Exhibit A"),
|
||||
ReimbPctRate: ptrFloat64(85.0),
|
||||
ReimbFeeRate: ptrFloat64(150.0),
|
||||
},
|
||||
},
|
||||
CreatedBy: openapi_types.Email("test@example.com"),
|
||||
})
|
||||
require.NoError(t, err, "Failed to create field extraction")
|
||||
require.NotNil(t, feRes.JSON201, "Expected 201 for field extraction")
|
||||
fmt.Printf(" Field extraction created: version=%d\n", feRes.JSON201.Version)
|
||||
|
||||
// Query by label and verify field extraction exists
|
||||
fmt.Println("\n=== Querying documents by label and verifying field extractions ===")
|
||||
|
||||
// Get documents with Dashboard_Ready label
|
||||
dashboardReadyDocsRes, err := net.Client.GetDocumentsByLabelWithResponse(t.Context(), "Dashboard_Ready", &queryapi.GetDocumentsByLabelParams{
|
||||
ClientId: queryapi.ClientID(clientID),
|
||||
})
|
||||
require.NoError(t, err, "Failed to get documents by Dashboard_Ready label")
|
||||
require.NotNil(t, dashboardReadyDocsRes.JSON200, "Expected 200 for get documents by label")
|
||||
|
||||
dashboardReadyDocs := dashboardReadyDocsRes.JSON200.Documents
|
||||
require.NotNil(t, dashboardReadyDocs, "Expected documents list")
|
||||
assert.Len(t, *dashboardReadyDocs, 1, "Expected 1 document with Dashboard_Ready label")
|
||||
fmt.Printf(" Documents with Dashboard_Ready: %d\n", len(*dashboardReadyDocs))
|
||||
|
||||
// Verify that document has a field extraction
|
||||
for _, doc := range *dashboardReadyDocs {
|
||||
feGetRes, err := net.Client.GetCurrentFieldExtractionWithResponse(t.Context(), &queryapi.GetCurrentFieldExtractionParams{
|
||||
DocumentId: doc.Id,
|
||||
})
|
||||
require.NoError(t, err, "Failed to get field extraction for document %s", doc.Id)
|
||||
require.NotNil(t, feGetRes.JSON200, "Expected field extraction for Dashboard_Ready document")
|
||||
assert.NotNil(t, feGetRes.JSON200.SingleFields.ContractTitle, "Expected contract title")
|
||||
fmt.Printf(" Document %s has field extraction with title: %s\n",
|
||||
doc.Id, *feGetRes.JSON200.SingleFields.ContractTitle)
|
||||
}
|
||||
|
||||
// Get documents with OCR_Processed label
|
||||
ocrDocsRes, err := net.Client.GetDocumentsByLabelWithResponse(t.Context(), "OCR_Processed", &queryapi.GetDocumentsByLabelParams{
|
||||
ClientId: queryapi.ClientID(clientID),
|
||||
})
|
||||
require.NoError(t, err, "Failed to get documents by OCR_Processed label")
|
||||
require.NotNil(t, ocrDocsRes.JSON200, "Expected 200 for get documents by label")
|
||||
|
||||
ocrDocs := ocrDocsRes.JSON200.Documents
|
||||
require.NotNil(t, ocrDocs, "Expected documents list")
|
||||
assert.Len(t, *ocrDocs, 1, "Expected 1 document with OCR_Processed label")
|
||||
fmt.Printf(" Documents with OCR_Processed: %d\n", len(*ocrDocs))
|
||||
|
||||
// Verify folder metrics
|
||||
fmt.Println("\n=== Verifying folder metrics ===")
|
||||
metrics1Res, err := net.Client.GetFolderMetricsWithResponse(t.Context(), folder1ID)
|
||||
require.NoError(t, err, "Failed to get folder1 metrics")
|
||||
require.NotNil(t, metrics1Res.JSON200, "Expected 200 for folder1 metrics")
|
||||
fmt.Printf(" /contracts folder metrics: totalDocs=%d\n", metrics1Res.JSON200.TotalDocuments)
|
||||
|
||||
metrics2Res, err := net.Client.GetFolderMetricsWithResponse(t.Context(), folder2ID)
|
||||
require.NoError(t, err, "Failed to get folder2 metrics")
|
||||
require.NotNil(t, metrics2Res.JSON200, "Expected 200 for folder2 metrics")
|
||||
fmt.Printf(" /invoices folder metrics: totalDocs=%d\n", metrics2Res.JSON200.TotalDocuments)
|
||||
|
||||
// Test: Get all documents with Ingested label
|
||||
fmt.Println("\n=== Verifying Ingested documents ===")
|
||||
allIngestedRes, err := net.Client.GetDocumentsByLabelWithResponse(t.Context(), "Ingested", &queryapi.GetDocumentsByLabelParams{
|
||||
ClientId: queryapi.ClientID(clientID),
|
||||
})
|
||||
require.NoError(t, err, "Failed to get documents by Ingested label")
|
||||
require.NotNil(t, allIngestedRes.JSON200, "Expected 200 for get documents by label")
|
||||
ingestedDocs := allIngestedRes.JSON200.Documents
|
||||
require.NotNil(t, ingestedDocs, "Expected documents list")
|
||||
assert.Len(t, *ingestedDocs, 1, "Expected 1 document with Ingested label")
|
||||
fmt.Printf(" Documents with Ingested label: %d\n", len(*ingestedDocs))
|
||||
|
||||
// Verify field extraction on the ingested document
|
||||
fmt.Println("\n=== Checking field extraction on Ingested document ===")
|
||||
for _, doc := range *ingestedDocs {
|
||||
feGetRes, err := net.Client.GetCurrentFieldExtractionWithResponse(t.Context(), &queryapi.GetCurrentFieldExtractionParams{
|
||||
DocumentId: doc.Id,
|
||||
})
|
||||
require.NoError(t, err, "Failed to query field extraction for document %s", doc.Id)
|
||||
require.NotNil(t, feGetRes.JSON200, "Expected field extraction for Ingested document")
|
||||
fmt.Printf(" Document %s has field extraction\n", doc.Id)
|
||||
}
|
||||
|
||||
fmt.Println("\n=== Field extraction by folder and label test complete ===")
|
||||
}
|
||||
|
||||
// Ensure io import is used
|
||||
var _ = io.EOF
|
||||
|
||||
Reference in New Issue
Block a user