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>
This commit is contained in:
Trey T
2026-04-04 23:00:46 -05:00
parent 9b622f8bbb
commit a6f538dfed
23 changed files with 265 additions and 109 deletions

View File

@@ -32,21 +32,19 @@ struct GameTests {
@Test("gameDate returns start of day for dateTime")
func gameDate_returnsStartOfDay() {
let calendar = TestClock.calendar
// Game at 7:05 PM
let dateTime = calendar.date(from: DateComponents(
year: 2026, month: 6, day: 15,
hour: 19, minute: 5, second: 0
))!
// Use TestFixtures.date which creates dates at 7:05 PM EST safely same
// calendar day in any US timezone when interpreted by Calendar.current.
let dateTime = TestFixtures.date(year: 2026, month: 6, day: 15, hour: 19, minute: 5)
let game = makeGame(dateTime: dateTime)
let expectedStart = calendar.startOfDay(for: dateTime)
// Production gameDate uses Calendar.current, so assert with the same calendar
let systemCalendar = Calendar.current
let expectedStart = systemCalendar.startOfDay(for: dateTime)
#expect(game.gameDate == expectedStart)
// Verify it's at midnight
let components = calendar.dateComponents([.hour, .minute, .second], from: game.gameDate)
// Verify it's at midnight in the system calendar
let components = systemCalendar.dateComponents([.hour, .minute, .second], from: game.gameDate)
#expect(components.hour == 0)
#expect(components.minute == 0)
#expect(components.second == 0)
@@ -166,16 +164,17 @@ struct GameTests {
@Test("Invariant: gameDate is always at midnight")
func invariant_gameDateAtMidnight() {
let calendar = TestClock.calendar
// Test various times throughout the day
let times = [0, 6, 12, 18, 23].map { hour in
calendar.date(from: DateComponents(year: 2026, month: 6, day: 15, hour: hour))!
// Production gameDate uses Calendar.current, so create dates and assert
// with Calendar.current to avoid cross-timezone mismatches.
// Use TestFixtures.date (7pm EST default) to ensure same calendar day in any US tz.
let times = [8, 12, 15, 19, 22].map { hour in
TestFixtures.date(year: 2026, month: 6, day: 15, hour: hour)
}
let systemCalendar = Calendar.current
for time in times {
let game = makeGame(dateTime: time)
let components = calendar.dateComponents([.hour, .minute, .second], from: game.gameDate)
let components = systemCalendar.dateComponents([.hour, .minute, .second], from: game.gameDate)
#expect(components.hour == 0, "gameDate hour should be 0")
#expect(components.minute == 0, "gameDate minute should be 0")
#expect(components.second == 0, "gameDate second should be 0")

View File

@@ -124,22 +124,24 @@ struct SportTests {
@Test("isInSeason boundary: first and last day of season month")
func isInSeason_boundaryDays() {
let calendar = TestClock.calendar
// Production isInSeason uses Calendar.current to extract month.
// Use noon (hour: 12) so the date stays in the correct calendar day
// regardless of system timezone across the US.
// MLB: First day of March (in season)
let marchFirst = calendar.date(from: DateComponents(year: 2026, month: 3, day: 1))!
let marchFirst = TestFixtures.date(year: 2026, month: 3, day: 1, hour: 12)
#expect(Sport.mlb.isInSeason(for: marchFirst))
// MLB: Last day of October (in season)
let octLast = calendar.date(from: DateComponents(year: 2026, month: 10, day: 31))!
let octLast = TestFixtures.date(year: 2026, month: 10, day: 31, hour: 12)
#expect(Sport.mlb.isInSeason(for: octLast))
// MLB: First day of November (out of season)
let novFirst = calendar.date(from: DateComponents(year: 2026, month: 11, day: 1))!
let novFirst = TestFixtures.date(year: 2026, month: 11, day: 1, hour: 12)
#expect(!Sport.mlb.isInSeason(for: novFirst))
// MLB: Last day of February (out of season)
let febLast = calendar.date(from: DateComponents(year: 2026, month: 2, day: 28))!
let febLast = TestFixtures.date(year: 2026, month: 2, day: 28, hour: 12)
#expect(!Sport.mlb.isInSeason(for: febLast))
}

View File

@@ -97,8 +97,9 @@ struct TripStopTests {
@Test("formattedDateRange: single date for 1-day stay")
func formattedDateRange_singleDay() {
let calendar = TestClock.calendar
let date = calendar.date(from: DateComponents(year: 2026, month: 6, day: 15))!
// formattedDateRange uses DateFormatter with system timezone, so create dates
// at noon to ensure the calendar day is stable across US timezones.
let date = TestFixtures.date(year: 2026, month: 6, day: 15, hour: 12)
let stop = makeStop(arrivalDate: date, departureDate: date)
@@ -108,9 +109,10 @@ struct TripStopTests {
@Test("formattedDateRange: range for multi-day stay")
func formattedDateRange_multiDay() {
let calendar = TestClock.calendar
let arrival = calendar.date(from: DateComponents(year: 2026, month: 6, day: 15))!
let departure = calendar.date(from: DateComponents(year: 2026, month: 6, day: 18))!
// formattedDateRange uses DateFormatter with system timezone, so create dates
// at noon to ensure the calendar day is stable across US timezones.
let arrival = TestFixtures.date(year: 2026, month: 6, day: 15, hour: 12)
let departure = TestFixtures.date(year: 2026, month: 6, day: 18, hour: 12)
let stop = makeStop(arrivalDate: arrival, departureDate: departure)