Skip to content

nbascore: Switch to ESPN API, add tests, improve UX - #2151

Open
Seanstoppable wants to merge 3 commits into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-nbascore-test-coverage
Open

nbascore: Switch to ESPN API, add tests, improve UX#2151
Seanstoppable wants to merge 3 commits into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-nbascore-test-coverage

Conversation

@Seanstoppable

Copy link
Copy Markdown
Collaborator

Summary

The nbascore module was broken because the data.nba.net API has been shut down (returns 400). This PR switches to ESPN free public scoreboard API, adds comprehensive unit tests, and improves the user experience during the offseason.

Changes

Switch to ESPN API

  • The old data.nba.net API is dead; cdn.nba.com blocks non-browser clients
  • ESPN API is free, requires no authentication, and works reliably
  • Uses typed structs for JSON parsing instead of fragile map[string]interface{}
  • Supports date-based queries via ?dates=YYYYMMDD for prev/next day navigation

Add unit tests (0 to 74% coverage)

  • Table-driven tests using net/http/httptest to mock API responses

Improve offseason UX

  • Show No games scheduled message when there are no events
  • Display the next game date from ESPN API when available

Bug fix

  • Fixed nil pointer dereference in the non-200 status code path

- Add widget_test.go with table-driven tests using net/http/httptest
- Test successful response parsing, empty games, non-200 status, invalid JSON,
  unreachable server, date offset formatting, score color formatting,
  active/inactive game highlighting, multiple games, request headers,
  settings defaults, and ConfigText
- Extract nbaBaseURL to package-level var for test server injection
- Fix nil pointer dereference bug in non-200 status code path
  (err was nil when checking response.StatusCode != 200)
The old data.nba.net API returns 400 and cdn.nba.com blocks non-browser
requests. Switch to ESPN's free public scoreboard API which requires no
authentication and works reliably.

- Use structured types instead of map[string]interface{} for JSON parsing
- Parse ESPN response format (events/competitions/competitors)
- Support date-based queries via ?dates= query parameter
- Use WTFUtil user agent string
- Add 10s HTTP client timeout
- Update tests to match new ESPN response structure
When the ESPN API returns no events (e.g. offseason), display
'No games scheduled' with the next game date if available from
the API's day.date field.
@Seanstoppable
Seanstoppable force-pushed the seanstoppable-nbascore-test-coverage branch from d1deffb to 7b2ef3b Compare July 26, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant