|
|
|
|
@ -548,10 +548,10 @@ struct SyncDataAccessTests { |
|
|
|
|
let matchColA: SyncedCollection<Match> = await tourStoreA.asyncLoadingSynchronizedCollection() |
|
|
|
|
let teamScoreColA: SyncedCollection<TeamScore> = await tourStoreA.asyncLoadingSynchronizedCollection() |
|
|
|
|
|
|
|
|
|
let tr1 = TeamRegistration() |
|
|
|
|
let tr1 = TeamRegistration(tournament: tournament.id) |
|
|
|
|
let pr11 = PlayerRegistration(teamRegistration: tr1.id, firstName: "f1", lastName: "l1") |
|
|
|
|
let pr12 = PlayerRegistration(teamRegistration: tr1.id, firstName: "f2", lastName: "l2") |
|
|
|
|
let tr2 = TeamRegistration() |
|
|
|
|
let tr2 = TeamRegistration(tournament: tournament.id) |
|
|
|
|
let pr21 = PlayerRegistration(teamRegistration: tr2.id, firstName: "f21", lastName: "l21") |
|
|
|
|
let pr22 = PlayerRegistration(teamRegistration: tr2.id, firstName: "f22", lastName: "l22") |
|
|
|
|
|
|
|
|
|
@ -569,7 +569,11 @@ struct SyncDataAccessTests { |
|
|
|
|
|
|
|
|
|
try await StoreCenter.main.setAuthorizedUsersAsync(for: tournament, users: [userId2]) |
|
|
|
|
|
|
|
|
|
let _ = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
let data = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
let syncData = try SyncData(data: data, storeCenter: self.storeCenterB) |
|
|
|
|
|
|
|
|
|
#expect(syncData.shared.count == 1) |
|
|
|
|
|
|
|
|
|
let tournamentColB: SyncedCollection<Tournament> = await self.storeCenterB.mainStore.asyncLoadingSynchronizedCollection() |
|
|
|
|
|
|
|
|
|
#expect(tournamentColB.count == 1) |
|
|
|
|
@ -588,6 +592,82 @@ struct SyncDataAccessTests { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test func testMatchSharingThenTournamentDelete() async throws { |
|
|
|
|
guard let userId1 = StoreCenter.main.userId else { |
|
|
|
|
throw TestError.notAuthenticated |
|
|
|
|
} |
|
|
|
|
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") |
|
|
|
|
tournament.relatedUser = userId1 |
|
|
|
|
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(tournament: tournament.id) |
|
|
|
|
let pr11 = PlayerRegistration(teamRegistration: tr1.id, firstName: "f1", lastName: "l1") |
|
|
|
|
let pr12 = PlayerRegistration(teamRegistration: tr1.id, firstName: "f2", lastName: "l2") |
|
|
|
|
let tr2 = TeamRegistration(tournament: tournament.id) |
|
|
|
|
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: match, users: [userId2]) |
|
|
|
|
|
|
|
|
|
let data = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
let syncData = try SyncData(data: data, storeCenter: self.storeCenterB) |
|
|
|
|
|
|
|
|
|
#expect(syncData.shared.count == 1) |
|
|
|
|
|
|
|
|
|
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 playerRegColB: SyncedCollection<PlayerRegistration> = await tourStoreB.asyncLoadingSynchronizedCollection() |
|
|
|
|
let teamRegColB: SyncedCollection<TeamRegistration> = await tourStoreB.asyncLoadingSynchronizedCollection() |
|
|
|
|
|
|
|
|
|
#expect(matchColB.count == 1) |
|
|
|
|
#expect(playerRegColB.count == 4) |
|
|
|
|
#expect(teamRegColB.count == 2) |
|
|
|
|
|
|
|
|
|
try await tournamentColA.deleteAsync(instance: tournament) |
|
|
|
|
|
|
|
|
|
#expect(tournamentColA.count == 0) |
|
|
|
|
|
|
|
|
|
let data2 = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
let syncData2 = try SyncData(data: data2, storeCenter: self.storeCenterB) |
|
|
|
|
|
|
|
|
|
#expect(syncData2.deletions.count > 0) |
|
|
|
|
|
|
|
|
|
#expect(matchColB.count == 0) |
|
|
|
|
#expect(playerRegColB.count == 0) |
|
|
|
|
#expect(teamRegColB.count == 0) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// needs to run on a postgreSQL, otherwise fails because of sqlite database locks |
|
|
|
|
@Test func testDataAccessForChildren() async throws { |
|
|
|
|
|
|
|
|
|
|