|
|
|
@ -847,6 +847,64 @@ struct SyncDataAccessTests { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// In this test, the first user: |
|
|
|
|
|
|
|
/// - creates an event |
|
|
|
|
|
|
|
/// - shares the event with a second user |
|
|
|
|
|
|
|
/// - the second user creates a tournament on that event |
|
|
|
|
|
|
|
/// We test that the tournament related_user is the second user |
|
|
|
|
|
|
|
@Test func testRelatedUsers() async throws { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
guard let userId1 = StoreCenter.main.userId else { |
|
|
|
|
|
|
|
throw TestError.notAuthenticated |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
guard let userId2 = self.storeCenterB.userId else { |
|
|
|
|
|
|
|
throw TestError.notAuthenticated |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Setup |
|
|
|
|
|
|
|
let eventColA: SyncedCollection<Event> = await StoreCenter.main.mainStore.asyncLoadingSynchronizedCollection() |
|
|
|
|
|
|
|
let tournamentColA: SyncedCollection<Tournament> = await StoreCenter.main.mainStore.asyncLoadingSynchronizedCollection() |
|
|
|
|
|
|
|
let eventColB: SyncedCollection<Event> = await self.storeCenterB.mainStore.asyncLoadingSynchronizedCollection() |
|
|
|
|
|
|
|
let tournamentColB: SyncedCollection<Tournament> = await self.storeCenterB.mainStore.asyncLoadingSynchronizedCollection() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let dataAccessCollection = StoreCenter.main.dataAccessCollection { |
|
|
|
|
|
|
|
try await dataAccessCollection.deleteAsync(contentOfs: Array(dataAccessCollection)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try await eventColA.deleteAsync(contentOfs: Array(eventColA)) |
|
|
|
|
|
|
|
try await tournamentColA.deleteAsync(contentOfs: Array(tournamentColA)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let _ = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#expect(eventColB.count == 0) |
|
|
|
|
|
|
|
#expect(tournamentColB.count == 0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create |
|
|
|
|
|
|
|
let eventA = Event(creator: userId1) |
|
|
|
|
|
|
|
try await eventColA.addOrUpdateAsync(instance: eventA) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Share with user2 |
|
|
|
|
|
|
|
try await StoreCenter.main.setAuthorizedUsersAsync(for: eventA, users: [userId2]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let dataB = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
|
|
|
var syncDataB = try SyncData(data: dataB, storeCenter: self.storeCenterB) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#expect(syncDataB.shared.count == 1) |
|
|
|
|
|
|
|
#expect(eventColB.count == 1) |
|
|
|
|
|
|
|
#expect(eventColB.first?.relatedUser == userId1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let tournamentB = Tournament(event: eventA.id, name: "P100") |
|
|
|
|
|
|
|
try await tournamentColB.addOrUpdateAsync(instance: tournamentB) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let tournaments: [Tournament] = try await self.storeCenterA.service().get() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let tournamentServerCopy = tournaments.first(where: { $0.id == tournamentB.id }) { |
|
|
|
|
|
|
|
#expect(tournamentServerCopy.relatedUser == userId2) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
throw TestError.missingTournament |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|