sync3
Laurent 5 months ago
parent d7e63d0193
commit 9a13378b91
  1. 60
      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<Tournament> = 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<TeamRegistration> = await tourStoreA.asyncLoadingSynchronizedCollection()
let playerRegColA: SyncedCollection<PlayerRegistration> = await tourStoreA.asyncLoadingSynchronizedCollection()
let roundColA: SyncedCollection<Round> = await tourStoreA.asyncLoadingSynchronizedCollection()
let matchColA: SyncedCollection<Match> = await tourStoreA.asyncLoadingSynchronizedCollection()
let teamScoreColA: SyncedCollection<TeamScore> = 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<Tournament> = await self.storeCenterB.mainStore.asyncLoadingSynchronizedCollection()
#expect(tournamentColB.count == 1)
let tourStoreB = try self.storeCenterB.store(identifier: tournament.id)
let matchColB: SyncedCollection<Match> = await tourStoreB.asyncLoadingSynchronizedCollection()
let teamScoreColB: SyncedCollection<TeamScore> = 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()
}
}
}

Loading…
Cancel
Save