2980a3beb4
continuous-integration/drone/push Build is passing
- Renamed the test function to `TestBuildRecommendedTenderListResponsesPreservesOrderWithoutStorage` for clarity and updated its logic to reflect changes in the recommendation response building process. - Removed unnecessary sleep in the test to enhance performance. - Refactored the `buildRecommendedTenderResponsesParallel` method to `buildRecommendedTenderListResponses`, simplifying the response building without relying on MinIO translation lookups. - Updated the repository's `mapProcedureReferencesToTenders` function to improve efficiency by grouping candidates by their contract folder IDs, enhancing the mapping process. This update streamlines the recommendation response handling and enhances the test suite for better maintainability and performance.
89 lines
2.4 KiB
Go
89 lines
2.4 KiB
Go
package tender
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"sync/atomic"
|
|
"testing"
|
|
|
|
"go.mongodb.org/mongo-driver/v2/bson"
|
|
|
|
"tm/pkg/ai_summarizer"
|
|
)
|
|
|
|
type countingTranslationStorage struct {
|
|
calls atomic.Int32
|
|
}
|
|
|
|
func (s *countingTranslationStorage) GetSummaryFromStorage(context.Context, string, string) (string, error) {
|
|
return "", ai_summarizer.ErrSummaryNotReady
|
|
}
|
|
|
|
func (s *countingTranslationStorage) GetDocumentSummariesFromStorage(context.Context, string, string) ([]ai_summarizer.DocumentSummary, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (s *countingTranslationStorage) GetTranslationFromStorage(context.Context, string, string, string) (ai_summarizer.StoredTranslation, error) {
|
|
s.calls.Add(1)
|
|
return ai_summarizer.StoredTranslation{
|
|
Title: "Translated title",
|
|
Description: "Translated description",
|
|
}, nil
|
|
}
|
|
|
|
func (s *countingTranslationStorage) ListDocuments(context.Context, string, string) ([]ai_summarizer.StoredDocument, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (s *countingTranslationStorage) DownloadDocument(context.Context, string) (io.ReadCloser, error) {
|
|
return nil, ai_summarizer.ErrObjectNotFound
|
|
}
|
|
|
|
func TestBuildRecommendedTenderListResponsesPreservesOrderWithoutStorage(t *testing.T) {
|
|
storage := &countingTranslationStorage{}
|
|
service := &tenderService{
|
|
aiSummarizerStorage: storage,
|
|
defaultLanguage: "en",
|
|
logger: noopTenderTestLogger{},
|
|
}
|
|
|
|
items := make([]rankedRecommendedTender, 0, 4)
|
|
ids := []string{
|
|
"507f1f77bcf86cd799439011",
|
|
"507f1f77bcf86cd799439012",
|
|
"507f1f77bcf86cd799439013",
|
|
"507f1f77bcf86cd799439014",
|
|
}
|
|
for i, idHex := range ids {
|
|
tender := Tender{
|
|
ContractFolderID: "folder",
|
|
NoticePublicationID: "notice",
|
|
Title: "Original",
|
|
}
|
|
tender.ID, _ = bson.ObjectIDFromHex(idHex)
|
|
items = append(items, rankedRecommendedTender{
|
|
tender: tender,
|
|
rank: i + 1,
|
|
analysis: "fit",
|
|
tenderRef: "PROC_folder/notice",
|
|
})
|
|
}
|
|
|
|
got := service.buildRecommendedTenderListResponses(items, "fr")
|
|
if len(got) != len(items) {
|
|
t.Fatalf("len = %d, want %d", len(got), len(items))
|
|
}
|
|
for i, resp := range got {
|
|
wantRank := i + 1
|
|
if resp.Rank != wantRank {
|
|
t.Fatalf("got[%d].Rank = %d, want %d", i, resp.Rank, wantRank)
|
|
}
|
|
if resp.Title != "Original" {
|
|
t.Fatalf("got[%d].Title = %q, want MongoDB title without MinIO lookup", i, resp.Title)
|
|
}
|
|
}
|
|
if storage.calls.Load() != 0 {
|
|
t.Fatalf("translation lookups = %d, want 0", storage.calls.Load())
|
|
}
|
|
}
|