|
|
|
|
@ -29,6 +29,7 @@ struct SyncDataAccessTests { |
|
|
|
|
let dirB = "storageB" |
|
|
|
|
|
|
|
|
|
FileManager.default.deleteDirectoryInDocuments(directoryName: dir) |
|
|
|
|
FileManager.default.deleteDirectoryInDocuments(directoryName: dirA) |
|
|
|
|
FileManager.default.deleteDirectoryInDocuments(directoryName: dirB) |
|
|
|
|
|
|
|
|
|
self.storeCenterA = StoreCenter(directoryName: dirA) |
|
|
|
|
@ -279,13 +280,16 @@ struct SyncDataAccessTests { |
|
|
|
|
// Change the club |
|
|
|
|
eventA.club = club2A.id |
|
|
|
|
try await eventColA.addOrUpdateAsync(instance: eventA) |
|
|
|
|
|
|
|
|
|
let dataB = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
|
|
|
|
|
let syncDataB = try SyncData(data: dataB, storeCenter: self.storeCenterB) |
|
|
|
|
|
|
|
|
|
#expect(syncDataB.updates.count == 1) // event update |
|
|
|
|
#expect(syncDataB.sharedRelationshipSets.count == 1) |
|
|
|
|
#expect(syncDataB.sharedRelationshipRemovals.count == 1) |
|
|
|
|
|
|
|
|
|
print("club1A = \(club1A.id)") |
|
|
|
|
#expect(eventColB.first?.club == club2A.id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -418,7 +422,7 @@ struct SyncDataAccessTests { |
|
|
|
|
|
|
|
|
|
// Sync with 2nd store |
|
|
|
|
let data = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
let syncData = try SyncData(data: data, storeCenter: self.storeCenterB) |
|
|
|
|
let _ = try SyncData(data: data, storeCenter: self.storeCenterB) |
|
|
|
|
|
|
|
|
|
#expect(gsColB.count == 2) |
|
|
|
|
#expect(roundColB.count == 15) |
|
|
|
|
@ -426,6 +430,74 @@ struct SyncDataAccessTests { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// needs to run on a postgreSQL, otherwise fails because of sqlite database locks |
|
|
|
|
@Test func testDataAccessForChildren() async throws { |
|
|
|
|
|
|
|
|
|
guard let userId2 = self.storeCenterB.userId else { |
|
|
|
|
throw TestError.notAuthenticated |
|
|
|
|
} |
|
|
|
|
// Setup tournament |
|
|
|
|
let tournamentColA: SyncedCollection<Tournament> = await StoreCenter.main.mainStore.asyncLoadingSynchronizedCollection() |
|
|
|
|
let tournamentColB: SyncedCollection<Tournament> = await self.storeCenterB.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() |
|
|
|
|
|
|
|
|
|
// cleanup sync residues |
|
|
|
|
let _ = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
|
|
|
|
|
try await StoreCenter.main.setAuthorizedUsersAsync(for: tournament, users: [userId2]) |
|
|
|
|
|
|
|
|
|
var teamRegistrations: [TeamRegistration] = [] |
|
|
|
|
var playerRegistrations: [PlayerRegistration] = [] |
|
|
|
|
|
|
|
|
|
let count = 5 |
|
|
|
|
for i in (0..<count) { |
|
|
|
|
let tr = TeamRegistration(tournament: tournament.id, name: "Team \(i)") |
|
|
|
|
let pr1 = PlayerRegistration(teamRegistration: tr.id, firstName: "f1\(i)", lastName: "l1\(i)") |
|
|
|
|
let pr2 = PlayerRegistration(teamRegistration: tr.id, firstName: "f2\(i)", lastName: "l2\(i)") |
|
|
|
|
teamRegistrations.append(tr) |
|
|
|
|
playerRegistrations.append(contentsOf: [pr1, pr2]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try await teamRegColA.addOrUpdateAsync(contentOfs: teamRegistrations) |
|
|
|
|
try await playerRegColA.addOrUpdateAsync(contentOfs: playerRegistrations) |
|
|
|
|
|
|
|
|
|
let _ = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
|
|
|
|
|
let tourStoreB = try self.storeCenterB.store(identifier: tournament.id) |
|
|
|
|
let teamRegColB: SyncedCollection<TeamRegistration> = await tourStoreB.asyncLoadingSynchronizedCollection() |
|
|
|
|
let playerRegColB: SyncedCollection<PlayerRegistration> = await tourStoreB.asyncLoadingSynchronizedCollection() |
|
|
|
|
|
|
|
|
|
#expect(tournamentColB.count == 1) |
|
|
|
|
#expect(teamRegColB.count == count) |
|
|
|
|
#expect(playerRegColB.count == count * 2) |
|
|
|
|
|
|
|
|
|
for team in teamRegistrations { |
|
|
|
|
try await teamRegColA.deleteAsync(instance: team) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try await Task.sleep(for: .milliseconds(100)) // without this, it looks like the sync date is smaller than the ModelLogs, so we don't get them all |
|
|
|
|
|
|
|
|
|
let data = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
let syncData = try SyncData(data: data, storeCenter: self.storeCenterB) |
|
|
|
|
|
|
|
|
|
#expect(syncData.deletions.count == 2) |
|
|
|
|
|
|
|
|
|
let teamRegDeletions = syncData.deletions.first(where: { $0.type == TeamRegistration.self }) |
|
|
|
|
#expect(teamRegDeletions?.items.count == 5) |
|
|
|
|
let playerRegDeletions = syncData.deletions.first(where: { $0.type == PlayerRegistration.self }) |
|
|
|
|
#expect(playerRegDeletions?.items.count == 10) |
|
|
|
|
|
|
|
|
|
#expect(teamRegColB.count == 0) |
|
|
|
|
#expect(playerRegColB.count == 0) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -468,7 +540,7 @@ extension Tournament { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func buildGroupStagesAsync() async throws { |
|
|
|
|
guard groupStages().isEmpty, let tournamentStore = self.tournamentStore else { |
|
|
|
|
guard groupStages().isEmpty, let _ = self.tournamentStore else { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -555,13 +627,13 @@ extension GroupStage { |
|
|
|
|
_removeMatches() |
|
|
|
|
|
|
|
|
|
for i in 0..<_numberOfMatchesToBuild() { |
|
|
|
|
let newMatch = self._createMatch(index: i) |
|
|
|
|
let newMatch = self.createMatch(index: i) |
|
|
|
|
// let newMatch = Match(groupStage: self.id, index: i, matchFormat: self.matchFormat, name: localizedMatchUpLabel(for: i)) |
|
|
|
|
teamScores.append(contentsOf: newMatch.createTeamScores()) |
|
|
|
|
matches.append(newMatch) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
for match in matches() { |
|
|
|
|
for match in self.matches() { |
|
|
|
|
match.resetTeamScores(outsideOf: []) |
|
|
|
|
teamScores.append(contentsOf: match.createTeamScores()) |
|
|
|
|
} |
|
|
|
|
|