Files
Sportstime/SportsTimeTests/Helpers/TestClock.swift
Trey T a6f538dfed Audit and fix 52 test correctness issues across 22 files
Systematic audit of 1,191 tests found tests written to pass rather than
verify correctness. Key fixes:

Infrastructure:
- TestClock: fixed timezone from .current to America/New_York (deterministic)
- TestFixtures: added 1.3x road routing factor to match production
- ItineraryTestHelpers: real per-city coordinates instead of hardcoded (40,-80)

Planning tests:
- Added missing Scenario E factory dispatch tests
- Tightened 12 loose assertions (>= 1 → == 8.0, > 0 → range checks)
- Fixed 4 no-op tests that accepted both success and failure
- Fixed wrong repeat-city invariant (was checking same-day, not different-day)
- Fixed tautological assertion in missing-stadium edge case

Services/Domain/Export tests:
- Replaced 4 placeholder tests (#expect(true)) with real assertions
- Fixed tautological assertions in POISearchServiceTests
- Fixed Chicago coordinate in RegionMapSelectorTests (-89 → -87.6553)
- Added sort order verification to ItineraryRowFlatteningTests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 23:00:46 -05:00

49 lines
1.3 KiB
Swift

//
// TestClock.swift
// SportsTimeTests
//
// Centralized time utilities for deterministic tests.
//
import Foundation
enum TestClock {
static let timeZone = TimeZone(identifier: "America/New_York")!
static let locale = Locale(identifier: "en_US_POSIX")
static let calendar: Calendar = {
var calendar = Calendar.current
calendar.timeZone = timeZone
calendar.locale = locale
return calendar
}()
static let baseDate: Date = {
let components = DateComponents(
calendar: calendar,
timeZone: timeZone,
year: 2026,
month: 1,
day: 15,
hour: 12,
minute: 0,
second: 0
)
return calendar.date(from: components) ?? Date(timeIntervalSince1970: 0)
}()
static var now: Date { baseDate }
static func startOfDay(for date: Date = baseDate) -> Date {
calendar.startOfDay(for: date)
}
static func addingDays(_ days: Int, to date: Date = baseDate) -> Date {
calendar.date(byAdding: .day, value: days, to: date) ?? date
}
static func addingHours(_ hours: Int, to date: Date = baseDate) -> Date {
calendar.date(byAdding: .hour, value: hours, to: date) ?? date
}
}