package adapters import ( "testing" "time" "github.com/shopspring/decimal" oppintel "github.com/missionworkforce/missionmatch/internal/modules/opportunity_intelligence" "github.com/missionworkforce/missionmatch/internal/platform/forecast" ) func TestFromForecast(t *testing.T) { award := time.Date(2026, 4, 1, 0, 0, 0, 0, time.UTC) val := decimal.RequireFromString("5000000") r := forecast.Record{ SourceID: "FC-1", Title: "Cyber support", Agency: "DEPT OF DEFENSE", Organization: "Air Force", NAICS: "541512", PlaceState: "HI", SetAside: "8(a) Set Aside", ContractType: "FFP", EstimatedValue: &val, EstimatedAward: &award, Raw: map[string]string{"Title": "Cyber support"}, } rec := fromForecast("GSA Forecast", r, time.Now()) if rec.Kind != oppintel.KindForecast { t.Fatalf("kind = %s", rec.Kind) } if !rec.IsPlanning { t.Fatal("a forecast must be marked as planning data") } if rec.SourceName != "GSA Forecast" || rec.SourceRecordID != "FC-1" { t.Fatalf("provenance: %+v", rec) } if rec.SubAgency != "Air Force" || rec.Place.State != "HI" || rec.ContractVehicle != "FFP" { t.Fatalf("fields: %+v", rec) } if rec.EstimatedValue == nil || !rec.EstimatedValue.Equal(val) || rec.ValueSource != "forecast" { t.Fatalf("value = %v source = %q", rec.EstimatedValue, rec.ValueSource) } if rec.EstimatedAwardDate == nil || !rec.EstimatedAwardDate.Equal(award) { t.Fatalf("estimated award date = %v", rec.EstimatedAwardDate) } } func TestFromForecastDerivesStableIDWhenAbsent(t *testing.T) { r := forecast.Record{Title: "Job A", Agency: "GSA", NAICS: "541512", PlaceState: "VA"} rec1 := fromForecast("GSA Forecast", r, time.Now()) rec2 := fromForecast("GSA Forecast", r, time.Now().Add(time.Hour)) if rec1.SourceRecordID == "" { t.Fatal("an export without an id must get a derived id") } if rec1.SourceRecordID != rec2.SourceRecordID { t.Fatalf("the derived id must be stable for the same row, got %q and %q", rec1.SourceRecordID, rec2.SourceRecordID) } } func TestFromForecastNoValueNoSource(t *testing.T) { rec := fromForecast("GSA Forecast", forecast.Record{SourceID: "X", Title: "Y"}, time.Now()) if rec.EstimatedValue != nil || rec.ValueSource != "" { t.Fatal("no value means no value source, never a fabricated zero") } }