▍ humdrum codex / sportsball
license AGPL-3.0
1.4 KB raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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")
	}
}