//go:build integration package integration import ( "context" "testing" "time" "github.com/google/uuid" "github.com/missionworkforce/missionmatch/internal/modules/commandcenter" ) // TestRevenueAtRiskValueSourceRoundTrip proves the W2 value_source column round trips through the real // RLS scoped Command Center read and drives the representative logic: a sam sourced opportunity value // produces a non representative dollar with the counted basis and a modeled impact, end to end. func TestRevenueAtRiskValueSourceRoundTrip(t *testing.T) { ctx := context.Background() org := seedOrg(t) // A real (sam) sourced priced opportunity, and a requirement needing 2 people with NO candidates in // the org, so the requirement is fully unmet and a staffing gap appears. opp := uuid.New() if _, err := migrator.Exec(ctx, `INSERT INTO opportunities (id, organization_id, name, status, value, value_source) VALUES ($1,$2,'RAR Opp','open',2000000,'sam')`, opp, org); err != nil { t.Fatalf("seed opportunity: %v", err) } if _, err := migrator.Exec(ctx, `INSERT INTO requirements (organization_id, opportunity_id, title, labor_category, quantity, required_level, required_poly) VALUES ($1,$2,'Cyber Engineer','Cyber Engineer',2,'secret','none')`, org, opp); err != nil { t.Fatalf("seed requirement: %v", err) } v, err := commandcenter.NewService(appDB).CommandCenter(ctxOrg(org), time.Now()) if err != nil { t.Fatalf("command center: %v", err) } var g *commandcenter.Gap for i := range v.StaffingGaps { if v.StaffingGaps[i].LaborCategory == "Cyber Engineer" { g = &v.StaffingGaps[i] } } if g == nil { t.Fatal("expected a Cyber Engineer staffing gap") } if g.ValueAtRisk == nil || *g.ValueAtRisk != "2000000.00" { t.Fatalf("value at risk: got %v want 2000000.00", g.ValueAtRisk) } if g.ValueRepresentative { t.Error("a sam sourced value must not be representative") } if g.PricedOpportunities != 1 || g.UnpricedOpportunities != 0 || g.TotalOpportunities != 1 { t.Fatalf("counts: priced=%d unpriced=%d total=%d want 1/0/1", g.PricedOpportunities, g.UnpricedOpportunities, g.TotalOpportunities) } if g.ImpactModeledPct == "" || g.ImpactModeledPct == "0.00" { t.Fatalf("expected a positive modeled impact, got %q", g.ImpactModeledPct) } }