refactor: change domain model IDs from UUID to String canonical IDs
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>
This commit is contained in:
@@ -31,7 +31,7 @@ struct ScenarioAPlannerTests {
|
||||
|
||||
/// Creates a stadium at a known location
|
||||
private func makeStadium(
|
||||
id: UUID = UUID(),
|
||||
id: String = "stadium_test_\(UUID().uuidString)",
|
||||
city: String,
|
||||
lat: Double,
|
||||
lon: Double,
|
||||
@@ -51,10 +51,10 @@ struct ScenarioAPlannerTests {
|
||||
|
||||
/// Creates a game at a stadium
|
||||
private func makeGame(
|
||||
id: UUID = UUID(),
|
||||
stadiumId: UUID,
|
||||
homeTeamId: UUID = UUID(),
|
||||
awayTeamId: UUID = UUID(),
|
||||
id: String = "game_test_\(UUID().uuidString)",
|
||||
stadiumId: String,
|
||||
homeTeamId: String = "team_test_\(UUID().uuidString)",
|
||||
awayTeamId: String = "team_test_\(UUID().uuidString)",
|
||||
dateTime: Date,
|
||||
sport: Sport = .mlb
|
||||
) -> Game {
|
||||
@@ -74,8 +74,8 @@ struct ScenarioAPlannerTests {
|
||||
startDate: Date,
|
||||
endDate: Date,
|
||||
games: [Game],
|
||||
stadiums: [UUID: Stadium],
|
||||
teams: [UUID: Team] = [:],
|
||||
stadiums: [String: Stadium],
|
||||
teams: [String: Team] = [:],
|
||||
allowRepeatCities: Bool = true,
|
||||
numberOfDrivers: Int = 1,
|
||||
maxDrivingHoursPerDriver: Double = 8.0,
|
||||
@@ -106,9 +106,9 @@ struct ScenarioAPlannerTests {
|
||||
@Test("4.1 - Valid date range returns games in range")
|
||||
func test_planByDates_ValidDateRange_ReturnsGamesInRange() {
|
||||
// Setup: 3 games across nearby cities over 5 days
|
||||
let chicagoId = UUID()
|
||||
let milwaukeeId = UUID()
|
||||
let detroitId = UUID()
|
||||
let chicagoId = "stadium_chicago_\(UUID().uuidString)"
|
||||
let milwaukeeId = "stadium_milwaukee_\(UUID().uuidString)"
|
||||
let detroitId = "stadium_detroit_\(UUID().uuidString)"
|
||||
|
||||
let chicago = makeStadium(id: chicagoId, city: "Chicago", lat: 41.8781, lon: -87.6298)
|
||||
let milwaukee = makeStadium(id: milwaukeeId, city: "Milwaukee", lat: 43.0389, lon: -87.9065)
|
||||
@@ -144,7 +144,7 @@ struct ScenarioAPlannerTests {
|
||||
@Test("4.2 - Single day range returns games on that day")
|
||||
func test_planByDates_SingleDayRange_ReturnsGamesOnThatDay() {
|
||||
// Setup: Multiple games on a single day at the same stadium
|
||||
let stadiumId = UUID()
|
||||
let stadiumId = "stadium_test_\(UUID().uuidString)"
|
||||
let stadium = makeStadium(id: stadiumId, city: "Chicago", lat: 41.8781, lon: -87.6298)
|
||||
let stadiums = [stadiumId: stadium]
|
||||
|
||||
@@ -182,10 +182,10 @@ struct ScenarioAPlannerTests {
|
||||
@Test("4.3 - Multi-week range returns multiple games")
|
||||
func test_planByDates_MultiWeekRange_ReturnsMultipleGames() {
|
||||
// Setup: Games spread across 3 weeks in nearby cities
|
||||
let chicagoId = UUID()
|
||||
let milwaukeeId = UUID()
|
||||
let detroitId = UUID()
|
||||
let clevelandId = UUID()
|
||||
let chicagoId = "stadium_chicago_\(UUID().uuidString)"
|
||||
let milwaukeeId = "stadium_milwaukee_\(UUID().uuidString)"
|
||||
let detroitId = "stadium_detroit_\(UUID().uuidString)"
|
||||
let clevelandId = "stadium_cleveland_\(UUID().uuidString)"
|
||||
|
||||
let chicago = makeStadium(id: chicagoId, city: "Chicago", lat: 41.8781, lon: -87.6298)
|
||||
let milwaukee = makeStadium(id: milwaukeeId, city: "Milwaukee", lat: 43.0389, lon: -87.9065)
|
||||
@@ -230,7 +230,7 @@ struct ScenarioAPlannerTests {
|
||||
@Test("4.4 - No games in range returns failure")
|
||||
func test_planByDates_NoGamesInRange_ThrowsError() {
|
||||
// Setup: Games outside the requested date range
|
||||
let stadiumId = UUID()
|
||||
let stadiumId = "stadium_test_\(UUID().uuidString)"
|
||||
let stadium = makeStadium(id: stadiumId, city: "Chicago", lat: 41.8781, lon: -87.6298)
|
||||
let stadiums = [stadiumId: stadium]
|
||||
|
||||
@@ -257,7 +257,7 @@ struct ScenarioAPlannerTests {
|
||||
@Test("4.5 - End date before start date returns failure")
|
||||
func test_planByDates_EndDateBeforeStartDate_ThrowsError() {
|
||||
// Setup: Invalid date range where end < start
|
||||
let stadiumId = UUID()
|
||||
let stadiumId = "stadium_test_\(UUID().uuidString)"
|
||||
let stadium = makeStadium(id: stadiumId, city: "Chicago", lat: 41.8781, lon: -87.6298)
|
||||
let stadiums = [stadiumId: stadium]
|
||||
|
||||
@@ -283,7 +283,7 @@ struct ScenarioAPlannerTests {
|
||||
@Test("4.6 - Single game in range returns single game route")
|
||||
func test_planByDates_SingleGameInRange_ReturnsSingleGameRoute() {
|
||||
// Setup: Only one game in the date range
|
||||
let stadiumId = UUID()
|
||||
let stadiumId = "stadium_test_\(UUID().uuidString)"
|
||||
let stadium = makeStadium(id: stadiumId, city: "Chicago", lat: 41.8781, lon: -87.6298)
|
||||
let stadiums = [stadiumId: stadium]
|
||||
|
||||
@@ -354,9 +354,9 @@ struct ScenarioAPlannerTests {
|
||||
func test_planByDates_UsesDAGRouterForRouting() {
|
||||
// Setup: Games that require DAG routing logic
|
||||
// Create games in multiple cities with feasible transitions
|
||||
let chicagoId = UUID()
|
||||
let milwaukeeId = UUID()
|
||||
let detroitId = UUID()
|
||||
let chicagoId = "stadium_chicago_\(UUID().uuidString)"
|
||||
let milwaukeeId = "stadium_milwaukee_\(UUID().uuidString)"
|
||||
let detroitId = "stadium_detroit_\(UUID().uuidString)"
|
||||
|
||||
let chicago = makeStadium(id: chicagoId, city: "Chicago", lat: 41.8781, lon: -87.6298)
|
||||
let milwaukee = makeStadium(id: milwaukeeId, city: "Milwaukee", lat: 43.0389, lon: -87.9065)
|
||||
@@ -403,8 +403,8 @@ struct ScenarioAPlannerTests {
|
||||
@Test("4.9 - Respects driver constraints")
|
||||
func test_planByDates_RespectsDriverConstraints() {
|
||||
// Setup: Games that would require excessive daily driving if constraints are loose
|
||||
let nycId = UUID()
|
||||
let chicagoId = UUID()
|
||||
let nycId = "stadium_nyc_\(UUID().uuidString)"
|
||||
let chicagoId = "stadium_chicago_\(UUID().uuidString)"
|
||||
|
||||
// NYC to Chicago is ~790 miles (~13 hours of driving)
|
||||
let nyc = makeStadium(id: nycId, city: "New York", lat: 40.7128, lon: -73.9352)
|
||||
@@ -474,9 +474,9 @@ struct ScenarioAPlannerTests {
|
||||
func test_planByDates_MustStop_FiltersToGamesInCity() {
|
||||
// Setup: Games in Chicago, Milwaukee, Detroit
|
||||
// Must-stop = Chicago → should only return Chicago games
|
||||
let chicagoId = UUID()
|
||||
let milwaukeeId = UUID()
|
||||
let detroitId = UUID()
|
||||
let chicagoId = "stadium_chicago_\(UUID().uuidString)"
|
||||
let milwaukeeId = "stadium_milwaukee_\(UUID().uuidString)"
|
||||
let detroitId = "stadium_detroit_\(UUID().uuidString)"
|
||||
|
||||
let chicago = makeStadium(id: chicagoId, city: "Chicago", lat: 41.8781, lon: -87.6298)
|
||||
let milwaukee = makeStadium(id: milwaukeeId, city: "Milwaukee", lat: 43.0389, lon: -87.9065)
|
||||
@@ -518,8 +518,8 @@ struct ScenarioAPlannerTests {
|
||||
func test_planByDates_MustStop_NoMatchingGames_ReturnsFailure() {
|
||||
// Setup: Games only in Milwaukee and Detroit
|
||||
// Must-stop = Chicago → no games there, should fail
|
||||
let milwaukeeId = UUID()
|
||||
let detroitId = UUID()
|
||||
let milwaukeeId = "stadium_milwaukee_\(UUID().uuidString)"
|
||||
let detroitId = "stadium_detroit_\(UUID().uuidString)"
|
||||
|
||||
let milwaukee = makeStadium(id: milwaukeeId, city: "Milwaukee", lat: 43.0389, lon: -87.9065)
|
||||
let detroit = makeStadium(id: detroitId, city: "Detroit", lat: 42.3314, lon: -83.0458)
|
||||
@@ -553,10 +553,10 @@ struct ScenarioAPlannerTests {
|
||||
// Setup: Cubs home game in Chicago + Cubs away game in Milwaukee (playing at Milwaukee)
|
||||
// Must-stop = Chicago → should ONLY return the Chicago home game
|
||||
// This tests Issue #8: "Must stop needs to be home team"
|
||||
let chicagoStadiumId = UUID()
|
||||
let milwaukeeStadiumId = UUID()
|
||||
let cubsTeamId = UUID()
|
||||
let brewersTeamId = UUID()
|
||||
let chicagoStadiumId = "stadium_chicago_\(UUID().uuidString)"
|
||||
let milwaukeeStadiumId = "stadium_milwaukee_\(UUID().uuidString)"
|
||||
let cubsTeamId = "team_cubs_\(UUID().uuidString)"
|
||||
let brewersTeamId = "team_brewers_\(UUID().uuidString)"
|
||||
|
||||
let wrigleyField = makeStadium(id: chicagoStadiumId, city: "Chicago", lat: 41.9484, lon: -87.6553)
|
||||
let millerPark = makeStadium(id: milwaukeeStadiumId, city: "Milwaukee", lat: 43.0280, lon: -87.9712)
|
||||
@@ -608,7 +608,7 @@ struct ScenarioAPlannerTests {
|
||||
func test_planByDates_MustStop_PartialCityMatch_Works() {
|
||||
// Setup: User types "Chicago" but stadium city is "Chicago, IL"
|
||||
// Should still match via contains
|
||||
let chicagoId = UUID()
|
||||
let chicagoId = "stadium_chicago_\(UUID().uuidString)"
|
||||
let chicago = makeStadium(id: chicagoId, city: "Chicago", lat: 41.8781, lon: -87.6298)
|
||||
let stadiums = [chicagoId: chicago]
|
||||
|
||||
@@ -636,7 +636,7 @@ struct ScenarioAPlannerTests {
|
||||
@Test("4.14 - Must-stop case insensitive")
|
||||
func test_planByDates_MustStop_CaseInsensitive() {
|
||||
// Setup: Must-stop = "CHICAGO" (uppercase) should match "Chicago"
|
||||
let chicagoId = UUID()
|
||||
let chicagoId = "stadium_chicago_\(UUID().uuidString)"
|
||||
let chicago = makeStadium(id: chicagoId, city: "Chicago", lat: 41.8781, lon: -87.6298)
|
||||
let stadiums = [chicagoId: chicago]
|
||||
|
||||
@@ -662,7 +662,7 @@ struct ScenarioAPlannerTests {
|
||||
@Test("4.15 - Multiple games in must-stop city all included")
|
||||
func test_planByDates_MustStop_MultipleGamesInCity_AllIncluded() {
|
||||
// Setup: Multiple games in Chicago on different days
|
||||
let chicagoId = UUID()
|
||||
let chicagoId = "stadium_chicago_\(UUID().uuidString)"
|
||||
let chicago = makeStadium(id: chicagoId, city: "Chicago", lat: 41.8781, lon: -87.6298)
|
||||
let stadiums = [chicagoId: chicago]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user