package tender import ( "context" "io" "testing" "tm/pkg/ai_summarizer" "tm/pkg/logger" ) type noopTenderTestLogger struct{} func (noopTenderTestLogger) Debug(string, map[string]interface{}) {} func (noopTenderTestLogger) Info(string, map[string]interface{}) {} func (noopTenderTestLogger) Warn(string, map[string]interface{}) {} func (noopTenderTestLogger) Error(string, map[string]interface{}) {} func (noopTenderTestLogger) Fatal(string, map[string]interface{}) {} func (l noopTenderTestLogger) WithFields(map[string]interface{}) logger.Logger { return l } func (noopTenderTestLogger) Sync() error { return nil } type stubRecommendationTranslationStorage struct { translations map[string]ai_summarizer.StoredTranslation } func (s stubRecommendationTranslationStorage) GetSummaryFromStorage(context.Context, string, string) (string, error) { return "", ai_summarizer.ErrSummaryNotReady } func (s stubRecommendationTranslationStorage) GetDocumentSummariesFromStorage(context.Context, string, string) ([]ai_summarizer.DocumentSummary, error) { return nil, nil } func (s stubRecommendationTranslationStorage) GetTranslationFromStorage(_ context.Context, contractFolderID, noticePublicationID, language string) (ai_summarizer.StoredTranslation, error) { key := contractFolderID + "|" + noticePublicationID + "|" + language if translation, ok := s.translations[key]; ok { return translation, nil } return ai_summarizer.StoredTranslation{}, ai_summarizer.ErrTranslationNotReady } func (s stubRecommendationTranslationStorage) ListDocuments(context.Context, string, string) ([]ai_summarizer.StoredDocument, error) { return nil, nil } func (s stubRecommendationTranslationStorage) DownloadDocument(context.Context, string) (io.ReadCloser, error) { return nil, ai_summarizer.ErrObjectNotFound } func TestBuildRecommendedTenderResponseAppliesStoredTranslation(t *testing.T) { service := &tenderService{ aiSummarizerStorage: stubRecommendationTranslationStorage{ translations: map[string]ai_summarizer.StoredTranslation{ "folder-1|00123456-2026|fr": { Title: "Titre traduit", Description: "Description traduite", }, }, }, defaultLanguage: "en", logger: noopTenderTestLogger{}, } tender := Tender{ ContractFolderID: "folder-1", NoticePublicationID: "00123456-2026", Title: "Original title", Description: "Original description", } resp := service.buildRecommendedTenderResponse( context.Background(), tender, 3, "Strong fit", "PROC_folder-1/00123456-2026", "fr", nil, ) if resp.Title != "Titre traduit" { t.Fatalf("expected translated title, got %q", resp.Title) } if resp.Description != "Description traduite" { t.Fatalf("expected translated description, got %q", resp.Description) } if resp.Language != "fr" { t.Fatalf("expected response language fr, got %q", resp.Language) } if resp.Rank != 3 { t.Fatalf("expected rank 3, got %d", resp.Rank) } if resp.Analysis != "Strong fit" { t.Fatalf("expected analysis to be preserved, got %q", resp.Analysis) } if resp.ProcedureRef != "PROC_folder-1/00123456-2026" { t.Fatalf("expected procedure ref to be preserved, got %q", resp.ProcedureRef) } } func TestBuildRecommendedTenderResponseKeepsOriginalTextWithoutStoredTranslation(t *testing.T) { service := &tenderService{ aiSummarizerStorage: stubRecommendationTranslationStorage{}, defaultLanguage: "en", logger: noopTenderTestLogger{}, } tender := Tender{ ContractFolderID: "folder-1", NoticePublicationID: "00123456-2026", Title: "Original title", Description: "Original description", } resp := service.buildRecommendedTenderResponse( context.Background(), tender, 1, "Fallback", "PROC_folder-1/00123456-2026", "fr", nil, ) if resp.Title != "Original title" { t.Fatalf("expected original title, got %q", resp.Title) } if resp.Description != "Original description" { t.Fatalf("expected original description, got %q", resp.Description) } if resp.Language != "" { t.Fatalf("expected empty language when no translation exists, got %q", resp.Language) } }