Refactor dashboard repository to integrate ProcedureDocumentsLister
- Introduced the ProcedureDocumentsLister interface to list contract folders with scraped documents, enhancing the accuracy of document-scrape statistics. - Updated the dashboard repository to accept ProcedureDocumentsLister as a dependency, allowing for improved data retrieval. - Implemented tests for the new functionality, ensuring proper handling of scraped document folder IDs and error propagation. This update enhances the dashboard's capability to manage and report on scraped documents, improving overall system efficiency and data integrity.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"tm/pkg/ai_summarizer"
|
||||
)
|
||||
|
||||
type mockProcedureDocumentsLister struct {
|
||||
procedures []ai_summarizer.ProcedureDocumentsSummary
|
||||
err error
|
||||
}
|
||||
|
||||
func (m *mockProcedureDocumentsLister) ListProceduresWithDocuments(context.Context) ([]ai_summarizer.ProcedureDocumentsSummary, error) {
|
||||
if m.err != nil {
|
||||
return nil, m.err
|
||||
}
|
||||
return m.procedures, nil
|
||||
}
|
||||
|
||||
func TestScrapedDocumentsFolderIDsUsesMinIOProcedures(t *testing.T) {
|
||||
repo := &repository{
|
||||
procedureLister: &mockProcedureDocumentsLister{
|
||||
procedures: []ai_summarizer.ProcedureDocumentsSummary{
|
||||
{ContractFolderID: "PROC-1", DocumentCount: 3},
|
||||
{ContractFolderID: "PROC-2", DocumentCount: 0},
|
||||
{ContractFolderID: " PROC-3 ", DocumentCount: 1},
|
||||
{ContractFolderID: "PROC-1", DocumentCount: 2},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
got, err := repo.scrapedDocumentsFolderIDs(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
want := []string{"PROC-1", "PROC-3"}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("expected %d folder IDs, got %d: %v", len(want), len(got), got)
|
||||
}
|
||||
for i, id := range want {
|
||||
if got[i] != id {
|
||||
t.Fatalf("expected folder ID %q at index %d, got %q", id, i, got[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestScrapedDocumentsFolderIDsWithoutLister(t *testing.T) {
|
||||
repo := &repository{}
|
||||
|
||||
got, err := repo.scrapedDocumentsFolderIDs(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if got != nil {
|
||||
t.Fatalf("expected nil folder IDs without lister, got %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScrapedDocumentsFolderIDsPropagatesError(t *testing.T) {
|
||||
repo := &repository{
|
||||
procedureLister: &mockProcedureDocumentsLister{
|
||||
err: errors.New("minio unavailable"),
|
||||
},
|
||||
}
|
||||
|
||||
_, err := repo.scrapedDocumentsFolderIDs(context.Background())
|
||||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user