Files
Sportstime/SportsTimeTests/Export/MapSnapshotServiceTests.swift
Trey t 8162b4a029 refactor(tests): TDD rewrite of all unit tests with spec documentation
Complete rewrite of unit test suite using TDD methodology:

Planning Engine Tests:
- GameDAGRouterTests: Beam search, anchor games, transitions
- ItineraryBuilderTests: Stop connection, validators, EV enrichment
- RouteFiltersTests: Region, time window, scoring filters
- ScenarioA/B/C/D PlannerTests: All planning scenarios
- TravelEstimatorTests: Distance, duration, travel days
- TripPlanningEngineTests: Orchestration, caching, preferences

Domain Model Tests:
- AchievementDefinitionsTests, AnySportTests, DivisionTests
- GameTests, ProgressTests, RegionTests, StadiumTests
- TeamTests, TravelSegmentTests, TripTests, TripPollTests
- TripPreferencesTests, TripStopTests, SportTests

Service Tests:
- FreeScoreAPITests, RouteDescriptionGeneratorTests
- SuggestedTripsGeneratorTests

Export Tests:
- ShareableContentTests (card types, themes, dimensions)

Bug fixes discovered through TDD:
- ShareCardDimensions: mapSnapshotSize exceeded available width (960x480)
- ScenarioBPlanner: Added anchor game validation filter

All tests include:
- Specification tests (expected behavior)
- Invariant tests (properties that must always hold)
- Edge case tests (boundary conditions)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 14:07:41 -06:00

68 lines
2.4 KiB
Swift

//
// MapSnapshotServiceTests.swift
// SportsTimeTests
//
// TDD specification tests for MapSnapshotService types.
//
import Testing
import Foundation
@testable import SportsTime
// MARK: - MapSnapshotError Tests
@Suite("MapSnapshotError")
struct MapSnapshotErrorTests {
// MARK: - Specification Tests: errorDescription
/// - Expected Behavior: noStops explains no stops provided
@Test("errorDescription: noStops mentions stops")
func errorDescription_noStops() {
let error = MapSnapshotService.MapSnapshotError.noStops
#expect(error.errorDescription != nil)
#expect(error.errorDescription!.lowercased().contains("stop") || error.errorDescription!.lowercased().contains("no"))
}
/// - Expected Behavior: snapshotFailed includes the reason
@Test("errorDescription: snapshotFailed includes reason")
func errorDescription_snapshotFailed() {
let error = MapSnapshotService.MapSnapshotError.snapshotFailed("Test reason")
#expect(error.errorDescription != nil)
#expect(error.errorDescription!.contains("Test reason") || error.errorDescription!.lowercased().contains("snapshot"))
}
/// - Expected Behavior: invalidCoordinates explains the issue
@Test("errorDescription: invalidCoordinates mentions coordinates")
func errorDescription_invalidCoordinates() {
let error = MapSnapshotService.MapSnapshotError.invalidCoordinates
#expect(error.errorDescription != nil)
#expect(error.errorDescription!.lowercased().contains("coordinate") || error.errorDescription!.lowercased().contains("invalid"))
}
// MARK: - Invariant Tests
/// - Invariant: All errors have non-empty descriptions
@Test("Invariant: all errors have descriptions")
func invariant_allHaveDescriptions() {
let errors: [MapSnapshotService.MapSnapshotError] = [
.noStops,
.snapshotFailed("test"),
.invalidCoordinates
]
for error in errors {
#expect(error.errorDescription != nil)
#expect(!error.errorDescription!.isEmpty)
}
}
/// - Invariant: snapshotFailed preserves the reason message
@Test("Invariant: snapshotFailed preserves reason")
func invariant_snapshotFailedPreservesReason() {
let testReason = "Network timeout 12345"
let error = MapSnapshotService.MapSnapshotError.snapshotFailed(testReason)
#expect(error.errorDescription!.contains(testReason))
}
}