Testing Guide

Testing Guide

Comprehensive guide for testing your Sports Stack integration and data syncs.

Overview

This guide covers testing strategies for:

  • Data provider syncs
  • API endpoints
  • Webhook integrations
  • Data validation

Testing Data Syncs

Browser-Based Testing

Recommended: Use the CMS UI for testing syncs

Step 1: Navigate to Provider

http://localhost:4001/integrations/data_providers/{provider}?tab=Sync+Data&league={league}

Examples:

  • NFL: http://localhost:4001/integrations/data_providers/sportradar?tab=Sync+Data&league=nfl
  • NBA: http://localhost:4001/integrations/data_providers/sportradar?tab=Sync+Data&league=nba

Step 2: Trigger Sync

  1. Find the route you want to test (e.g., "Teams", "League Hierarchy")
  2. Click "Sync now" button
  3. Wait 3-10 seconds for processing
  4. Check Recent API Calls for status

Step 3: Validate Results

# Validate league sync
mix run validate_league_sync.exs {league}

# Example
mix run validate_league_sync.exs nfl

Systematic League Testing

Test multiple leagues at once:

# Test all leagues
mix run test_all_leagues.exs

# Test specific league
mix run validate_league_sync.exs nfl

Expected Results by League

NFL:

  • Seasons: ~10-15 (PRE, REG, POST)
  • Active Teams: 32
  • All teams have colors and metadata

NBA:

  • Seasons: ~5-10
  • Active Teams: 30
  • All teams have colors and metadata

NHL:

  • Seasons: ~5-10
  • Active Teams: 32
  • All teams have colors and metadata

Testing API Endpoints

Using cURL

# Get teams
curl -X GET "https://api.sportsstack.io/api/v1/teams?league_id=nfl" \
  -H "Authorization: Bearer YOUR_API_KEY"

# Get events
curl -X GET "https://api.sportsstack.io/api/v1/events?league_id=nfl&season_year=2024" \
  -H "Authorization: Bearer YOUR_API_KEY"

Using Postman

  1. Import OpenAPI spec: openapi.json
  2. Set up environment variables:
    • base_url: https://api.sportsstack.io
    • api_key: Your API key
  3. Test endpoints from collection

Using Browser Developer Tools

  1. Open Developer Tools (F12)
  2. Navigate to Network tab
  3. Use CMS UI (makes API calls automatically)
  4. Inspect API requests/responses

Testing Webhooks

Using Webhook Tester

  1. Navigate to Admin → Webhook Tester
  2. Select your tenant
  3. Copy the generated test URL
  4. Configure destination with test URL
  5. Trigger a data change
  6. Inspect payload in tester interface

Using ngrok (Local Testing)

  1. Install ngrok: brew install ngrok
  2. Start your local server
  3. Expose with ngrok: ngrok http 8000
  4. Copy HTTPS URL
  5. Configure webhook with ngrok URL
  6. Test webhook delivery

Signature Verification Testing

import hmac
import hashlib

def test_signature_verification():
    payload = '{"test": "data"}'
    secret = "test-secret"

    # Generate expected signature
    expected = hmac.new(
        secret.encode('utf-8'),
        payload.encode('utf-8'),
        hashlib.sha256
    ).hexdigest()

    # Verify signature matches
    assert verify_webhook_signature(payload, expected, secret)

Testing Filters

Season Type Filtering

  1. Navigate to Explore → Seasons
  2. Test filters:
    • Regular: Shows only REG seasons
    • Preseason: Shows only PRE seasons
    • Postseason: Shows only PST seasons
    • All: Shows all seasons

Team Status Filtering

  1. Navigate to Explore → Teams
  2. Test filters:
    • ACTIVE: Shows active teams (default)
    • INACTIVE: Shows inactive teams
    • Verify counts match expectations

Event Status Filtering

  1. Navigate to Explore → Events
  2. Test filters:
    • scheduled: Upcoming events
    • in_progress: Live events
    • completed: Finished events
    • cancelled: Cancelled events

Integration Testing

Using Integration Test Framework

# Show available tests
elixir integration_tests/integration_test_runner.exs

# Test SportRadar NBA teams
elixir integration_tests/integration_test_runner.exs sportradar_nba_teams

# Test SportRadar NFL events
elixir integration_tests/integration_test_runner.exs sportradar_nfl_events

Manual Integration Testing

# In IEx
iex> Code.eval_file("integration_tests/integration_test.exs")

# Run specific test
iex> IntegrationTest.run("SportRadar", "nba", "teams", %{})

# Use helper functions
iex> IntegrationTest.Helpers.test_sportradar_nba_teams()

Validation Scripts

League Sync Validation

# Validate specific league
mix run validate_league_sync.exs nfl

# Checks:
# - Season counts
# - Team counts (active/inactive)
# - Team colors
# - Team metadata (division/conference)

Browser Sync Validation

# Validate browser-triggered sync
mix run browser_sync_validation.exs {provider} {league} {model}

# Example
mix run browser_sync_validation.exs sportradar nfl teams

Test Checklist

Before Testing

  • Services running: docker compose up -d
  • Database migrated: mix ecto.migrate
  • Server running: mix phx.server
  • Provider configured with valid API key

Data Sync Testing

  • League Hierarchy sync completes
  • Teams created with correct counts
  • Teams have colors and metadata
  • Seasons created correctly
  • Events sync successfully
  • Statistics sync correctly

API Testing

  • Authentication works
  • Rate limits respected
  • Filters work correctly
  • Pagination works
  • Error handling works

Webhook Testing

  • Webhook configuration works
  • Payloads received correctly
  • Signature verification works
  • Idempotency implemented
  • Error handling works

Common Test Scenarios

Scenario 1: Initial League Setup

  1. Sync League Hierarchy
  2. Sync Seasons
  3. Sync Teams
  4. Sync Events
  5. Validate all entities created

Scenario 2: Daily Updates

  1. Sync Events (scheduled)
  2. Sync Statistics (after games)
  3. Validate updates applied

Scenario 3: Webhook Integration

  1. Configure webhook destination
  2. Trigger data change
  3. Verify webhook received
  4. Verify signature
  5. Process webhook

Troubleshooting Tests

Sync Tests Failing

  1. Check Provider Configuration:

    • Verify API key is valid
    • Check provider is active
    • Verify league is selected
  2. Check Trace Logs:

    • Review API call logs
    • Check conversion errors
    • Verify processor matching

API Tests Failing

  1. Check Authentication:

    • Verify API key is correct
    • Check Authorization header
    • Verify key hasn't expired
  2. Check Rate Limits:

    • Verify not exceeding limits
    • Check rate limit headers
    • Wait for reset if needed

Webhook Tests Failing

  1. Check Configuration:

    • Verify webhook URL is correct
    • Check shared secret matches
    • Verify entity filters
  2. Check Delivery:

    • Review Recent API Calls
    • Check webhook tester
    • Verify endpoint is accessible

Related Documentation

Support

For testing issues:

  1. Check Recent API Calls for errors
  2. Review Trace Logs for details
  3. Run Validation Scripts to verify data
  4. Contact support with test results