package adapters import ( "encoding/json" "testing" "time" "github.com/shopspring/decimal" oppintel "github.com/missionworkforce/missionmatch/internal/modules/opportunity_intelligence" "github.com/missionworkforce/missionmatch/internal/platform/marketintel" "github.com/missionworkforce/missionmatch/internal/platform/samgov" ) func TestFromSAM(t *testing.T) { posted := time.Date(2026, 6, 1, 0, 0, 0, 0, time.UTC) deadline := time.Date(2026, 7, 1, 12, 0, 0, 0, time.UTC) n := samgov.Normalized{ NoticeID: "N123", Title: "Cyber support", SolicitationNumber: "FA8773 26 R 0001", Department: "DEPT OF DEFENSE", SubAgency: "AIR FORCE", NaicsCode: "541512", PSCCode: "D310", SetAside: "8(a) Set Aside", SetAsideCode: "8A", POPCity: "Honolulu", POPState: "HI", POPZip: "96853", PostedDate: &posted, ResponseDeadline: &deadline, UILink: "https://sam.gov/x", Source: "SAM.gov", Raw: json.RawMessage(`{"noticeId":"N123"}`), } at := time.Date(2026, 6, 26, 0, 0, 0, 0, time.UTC) r := fromSAM(n, at) if r.SourceName != "SAM.gov" || r.SourceRecordID != "N123" { t.Fatalf("provenance wrong: %+v", r) } if r.Kind != oppintel.KindActiveSolicitation { t.Fatalf("kind = %s", r.Kind) } if r.EstimatedValue != nil { t.Fatal("SAM opportunities must carry no dollar value") } if r.DedupeKey != "FA877326R0001" { t.Fatalf("dedupe = %q", r.DedupeKey) } if r.Place.State != "HI" || r.NAICS != "541512" || r.SubAgency != "AIR FORCE" { t.Fatalf("fields wrong: %+v", r) } if !r.FetchedAt.Equal(at) { t.Fatalf("fetchedAt = %v", r.FetchedAt) } if r.IsPlanning { t.Fatal("solicitations are not planning data") } } func TestFromAward(t *testing.T) { amt := decimal.RequireFromString("1250000.50") start := time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC) a := marketintel.Award{ GeneratedInternalID: "CONT_AWD_1", AwardID: "FA8773-26-R-0001", RecipientName: "Acme Corp", RecipientUEI: "ABC123", AwardAmount: &amt, AwardingAgency: "Department of Defense", AwardingSubAgency: "Department of the Air Force", NAICSCode: "541512", Description: "IT services", POPStart: &start, Raw: json.RawMessage(`{"id":1}`), } r := fromAward(a, start) if r.Kind != oppintel.KindContractAward { t.Fatalf("kind = %s", r.Kind) } if r.EstimatedValue == nil || !r.EstimatedValue.Equal(amt) { t.Fatalf("value = %v", r.EstimatedValue) } if r.ValueSource != "usaspending" { t.Fatalf("value source = %q", r.ValueSource) } if r.IncumbentName != "Acme Corp" || r.IncumbentUEI != "ABC123" { t.Fatalf("incumbent wrong: %+v", r) } // The award PIID and the SAM solicitation above reduce to the same dedupe key. if r.DedupeKey != "FA877326R0001" { t.Fatalf("dedupe = %q", r.DedupeKey) } } func TestFromAwardNilAmountKeepsNoValue(t *testing.T) { a := marketintel.Award{GeneratedInternalID: "X", AwardID: "Y"} r := fromAward(a, time.Now()) if r.EstimatedValue != nil { t.Fatal("a nil award amount must stay nil, never a fabricated zero") } if r.ValueSource != "" { t.Fatal("no value source without a value") } }