package espn import ( "testing" "github.com/humdrum-tiv/sportsball/internal/model" ) // mapScheduleGame must decode the object-shaped score, assign home/away, and // carry winner + state for a completed game. func TestMapScheduleGameObjectScore(t *testing.T) { ev := schedEvent{ ID: "401", Date: "2026-04-12T20:15Z", Competitions: []schedComp{{ Status: status{Type: statusType{State: "post", Detail: "Final"}}, Competitors: []schedCompetitor{ {HomeAway: "home", Winner: true, Score: scoreObj{Value: 5, DisplayValue: "5"}, Team: teamJSON{ID: "22", Abbreviation: "PHI", ShortDisplayName: "Phillies"}}, {HomeAway: "away", Winner: false, Score: scoreObj{Value: 3, DisplayValue: "3"}, Team: teamJSON{ID: "13", Abbreviation: "TEX", ShortDisplayName: "Rangers"}}, }, }}, } g, ok := mapScheduleGame(model.MLB, ev) if !ok { t.Fatal("mapScheduleGame returned ok=false") } if g.State != model.StateFinal { t.Errorf("state = %v, want Final", g.State) } if g.Home.Abbr != "PHI" || g.Home.Score != 5 || !g.Home.Winner { t.Errorf("home = %+v", g.Home) } if g.Away.Abbr != "TEX" || g.Away.Score != 3 || g.Away.Winner { t.Errorf("away = %+v", g.Away) } } // A bye-week / placeholder event with no competition is dropped, not panicked. func TestMapScheduleGameNoCompetition(t *testing.T) { if _, ok := mapScheduleGame(model.NFL, schedEvent{ID: "x"}); ok { t.Error("event with no competitions should be skipped") } }