This refactor fixes the achievement system by using stable canonical string IDs (e.g., "stadium_mlb_fenway_park") instead of random UUIDs. This ensures stadium mappings for achievements are consistent across app launches and CloudKit sync operations. Changes: - Stadium, Team, Game: id property changed from UUID to String - Trip, TripStop, TripPreferences: updated to use String IDs for games/stadiums - CKModels: removed UUID parsing, use canonical IDs directly - AchievementEngine: now matches against canonical stadium IDs - All test files updated to use String IDs instead of UUID() Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
84 lines
2.7 KiB
Swift
84 lines
2.7 KiB
Swift
//
|
|
// SportsTimeTests.swift
|
|
// SportsTimeTests
|
|
//
|
|
// Created by Trey Tartt on 1/6/26.
|
|
//
|
|
|
|
import Testing
|
|
@testable import SportsTime
|
|
import Foundation
|
|
|
|
// MARK: - DayCard Tests (Removed)
|
|
// DayCard and DayConflictInfo types were removed during refactor.
|
|
// Tests for TripDetailView conflict detection are in TripDetailViewTests.swift if needed.
|
|
|
|
// MARK: - Duplicate Game ID Regression Tests
|
|
|
|
/// Tests for handling duplicate game IDs without crashing (regression test for fatal error)
|
|
struct DuplicateGameIdTests {
|
|
|
|
private func makeStadium(sport: Sport = .mlb) -> Stadium {
|
|
Stadium(
|
|
id: "stadium_test_\(UUID().uuidString)",
|
|
name: "Test Stadium",
|
|
city: "Test City",
|
|
state: "TS",
|
|
latitude: 40.0,
|
|
longitude: -100.0,
|
|
capacity: 40000,
|
|
sport: sport
|
|
)
|
|
}
|
|
|
|
private func makeTeam(sport: Sport = .mlb, stadiumId: String) -> Team {
|
|
Team(
|
|
id: "team_test_\(UUID().uuidString)",
|
|
name: "Test Team",
|
|
abbreviation: "TST",
|
|
sport: sport,
|
|
city: "Test City",
|
|
stadiumId: stadiumId
|
|
)
|
|
}
|
|
|
|
private func makeGame(id: String, homeTeamId: String, awayTeamId: String, stadiumId: String, dateTime: Date) -> Game {
|
|
Game(
|
|
id: id,
|
|
homeTeamId: homeTeamId,
|
|
awayTeamId: awayTeamId,
|
|
stadiumId: stadiumId,
|
|
dateTime: dateTime,
|
|
sport: .mlb,
|
|
season: "2026"
|
|
)
|
|
}
|
|
|
|
// Note: GameCandidate test removed - type no longer exists after planning engine refactor
|
|
|
|
@Test("Duplicate games are deduplicated at load time")
|
|
func gamesArray_DeduplicatesById() {
|
|
// Simulate the deduplication logic used in StubDataProvider
|
|
let gameId = "game_test_\(UUID().uuidString)"
|
|
let dateTime = Date()
|
|
|
|
let game1 = makeGame(id: gameId, homeTeamId: "team_home_\(UUID().uuidString)", awayTeamId: "team_away_\(UUID().uuidString)", stadiumId: "stadium_test_\(UUID().uuidString)", dateTime: dateTime)
|
|
let game2 = makeGame(id: gameId, homeTeamId: "team_home_\(UUID().uuidString)", awayTeamId: "team_away_\(UUID().uuidString)", stadiumId: "stadium_test_\(UUID().uuidString)", dateTime: dateTime.addingTimeInterval(3600))
|
|
|
|
let games = [game1, game2]
|
|
|
|
// Deduplication logic from StubDataProvider
|
|
var seenIds = Set<String>()
|
|
let uniqueGames = games.filter { game in
|
|
if seenIds.contains(game.id) {
|
|
return false
|
|
}
|
|
seenIds.insert(game.id)
|
|
return true
|
|
}
|
|
|
|
#expect(uniqueGames.count == 1)
|
|
#expect(uniqueGames.first?.dateTime == game1.dateTime, "First occurrence should be kept")
|
|
}
|
|
}
|