fix: deliver validated AI insight responses
This commit is contained in:
49
internal/growthreport/adapter_test.go
Normal file
49
internal/growthreport/adapter_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package growthreport
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/growth"
|
||||
)
|
||||
|
||||
func TestUpcomingEventsKeepsFiveChronologicalEligibleCandidates(t *testing.T) {
|
||||
t.Parallel()
|
||||
start := time.Date(2026, time.August, 22, 0, 0, 0, 0, time.UTC)
|
||||
catalog := []growth.Event{
|
||||
{ID: "past", TitleFA: "رویداد گذشته", StartDate: start.AddDate(0, 0, -1)},
|
||||
{ID: "one", TitleFA: "رویداد اول", StartDate: start},
|
||||
{ID: "two", TitleFA: "رویداد دوم", StartDate: start.AddDate(0, 0, 40)},
|
||||
{ID: "three", TitleFA: "رویداد سوم", StartDate: start.AddDate(0, 0, 100)},
|
||||
{ID: "four", TitleFA: "رویداد چهارم", StartDate: start.AddDate(0, 0, 190)},
|
||||
{ID: "five", TitleFA: "رویداد پنجم", StartDate: start.AddDate(0, 0, 280), OfficialHoliday: true},
|
||||
{ID: "six", TitleFA: "رویداد ششم", StartDate: start.AddDate(0, 0, 320)},
|
||||
}
|
||||
|
||||
got := upcomingEvents(catalog, start, 5)
|
||||
if len(got) != 5 {
|
||||
t.Fatalf("upcomingEvents() returned %d events, want 5", len(got))
|
||||
}
|
||||
for index, want := range []string{"event:one", "event:two", "event:three", "event:four", "event:five"} {
|
||||
if got[index].EvidenceID != want {
|
||||
t.Fatalf("upcomingEvents()[%d] = %q, want %q", index, got[index].EvidenceID, want)
|
||||
}
|
||||
}
|
||||
if !got[4].OfficialHoliday {
|
||||
t.Fatal("eligible official holiday was removed from the candidate set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFallbackEventRecommendationsUseTheFirstThreeCandidates(t *testing.T) {
|
||||
t.Parallel()
|
||||
events := []UpcomingEvent{{EvidenceID: "event:first"}, {EvidenceID: "event:second"}, {EvidenceID: "event:third"}, {EvidenceID: "event:fourth"}}
|
||||
got := fallbackEventRecommendations(events)
|
||||
if len(got) != 3 || got[0].EvidenceID != "event:first" || got[2].EvidenceID != "event:third" {
|
||||
t.Fatalf("fallbackEventRecommendations() = %+v", got)
|
||||
}
|
||||
for _, item := range got {
|
||||
if item.RelevanceReason == "" {
|
||||
t.Fatal("fallback recommendation lacks a relevance reason")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user