From 9a13378b915787c1e8b3f3a0dcc9851f220ed6d0 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 10 Jun 2025 14:33:25 +0200 Subject: [PATCH] adds test --- PadelClubDataTests/SyncDataAccessTests.swift | 60 ++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/PadelClubDataTests/SyncDataAccessTests.swift b/PadelClubDataTests/SyncDataAccessTests.swift index 8d87e83..957ce81 100644 --- a/PadelClubDataTests/SyncDataAccessTests.swift +++ b/PadelClubDataTests/SyncDataAccessTests.swift @@ -597,6 +597,64 @@ struct SyncDataAccessTests { } + @Test func testTournamentSharingTeamScoreIssue() async throws { + guard let userId2 = self.storeCenterB.userId else { + throw TestError.notAuthenticated + } + + // Setup tournament + let tournamentColA: SyncedCollection = await StoreCenter.main.mainStore.asyncLoadingSynchronizedCollection() + + let tournament = Tournament(name: "test_data_access_children") + try await tournamentColA.addOrUpdateAsync(instance: tournament) + + let tourStoreA = try StoreCenter.main.store(identifier: tournament.id) + let teamRegColA: SyncedCollection = await tourStoreA.asyncLoadingSynchronizedCollection() + let playerRegColA: SyncedCollection = await tourStoreA.asyncLoadingSynchronizedCollection() + let roundColA: SyncedCollection = await tourStoreA.asyncLoadingSynchronizedCollection() + let matchColA: SyncedCollection = await tourStoreA.asyncLoadingSynchronizedCollection() + let teamScoreColA: SyncedCollection = await tourStoreA.asyncLoadingSynchronizedCollection() + + let tr1 = TeamRegistration() + let pr11 = PlayerRegistration(teamRegistration: tr1.id, firstName: "f1", lastName: "l1") + let pr12 = PlayerRegistration(teamRegistration: tr1.id, firstName: "f2", lastName: "l2") + let tr2 = TeamRegistration() + let pr21 = PlayerRegistration(teamRegistration: tr2.id, firstName: "f21", lastName: "l21") + let pr22 = PlayerRegistration(teamRegistration: tr2.id, firstName: "f22", lastName: "l22") + + try await teamRegColA.addOrUpdateAsync(contentOfs: [tr1, tr2]) + try await playerRegColA.addOrUpdateAsync(contentOfs: [pr11, pr12, pr21, pr22]) + + let round = Round(tournament: tournament.id) + let match = Match(round: round.id) + let ts1 = TeamScore(match: match.id, team: tr1) + let ts2 = TeamScore(match: match.id, team: tr2) + + try await roundColA.addOrUpdateAsync(instance: round) + try await matchColA.addOrUpdateAsync(instance: match) + try await teamScoreColA.addOrUpdateAsync(contentOfs: [ts1, ts2]) + + try await StoreCenter.main.setAuthorizedUsersAsync(for: tournament, users: [userId2]) + + let _ = try await self.storeCenterB.testSynchronizeOnceAsync() + let tournamentColB: SyncedCollection = await self.storeCenterB.mainStore.asyncLoadingSynchronizedCollection() + + #expect(tournamentColB.count == 1) + + let tourStoreB = try self.storeCenterB.store(identifier: tournament.id) + let matchColB: SyncedCollection = await tourStoreB.asyncLoadingSynchronizedCollection() + let teamScoreColB: SyncedCollection = await tourStoreB.asyncLoadingSynchronizedCollection() + + #expect(teamScoreColB.count == 2) + + let matchB = matchColB.first! + matchB.courtIndex = 2 + try await matchColB.addOrUpdateAsync(instance: matchB) + + #expect(teamScoreColB.count == 2) + + } + } @@ -778,4 +836,6 @@ extension Round { try await round.buildLoserBracketAsync() } } + + }