|
|
|
|
@ -905,6 +905,69 @@ struct SyncDataAccessTests { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// In this test: |
|
|
|
|
/// - first user shares an event with a linked club to the second user |
|
|
|
|
/// - first user creates an event with the same club to the second user |
|
|
|
|
/// We test that the second event does not have linked data accesses |
|
|
|
|
@Test func testDataAccessIssue() async throws { |
|
|
|
|
|
|
|
|
|
guard let userId1 = self.storeCenterA.userId else { |
|
|
|
|
throw TestError.notAuthenticated |
|
|
|
|
} |
|
|
|
|
guard let userId2 = self.storeCenterB.userId else { |
|
|
|
|
throw TestError.notAuthenticated |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Setup |
|
|
|
|
let eventColA: SyncedCollection<Event> = await self.storeCenterA.mainStore.asyncLoadingSynchronizedCollection() |
|
|
|
|
let clubColA: SyncedCollection<Club> = await self.storeCenterA.mainStore.asyncLoadingSynchronizedCollection() |
|
|
|
|
let eventColB: SyncedCollection<Event> = await self.storeCenterB.mainStore.asyncLoadingSynchronizedCollection() |
|
|
|
|
let clubColB: SyncedCollection<Club> = await self.storeCenterB.mainStore.asyncLoadingSynchronizedCollection() |
|
|
|
|
|
|
|
|
|
if let dataAccessCollection = self.storeCenterA.dataAccessCollection { |
|
|
|
|
try await dataAccessCollection.deleteAsync(contentOfs: Array(dataAccessCollection)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try await eventColA.deleteAsync(contentOfs: Array(eventColA)) |
|
|
|
|
try await clubColA.deleteAsync(contentOfs: Array(clubColA)) |
|
|
|
|
|
|
|
|
|
let _ = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
|
|
|
|
|
#expect(eventColB.count == 0) |
|
|
|
|
#expect(clubColB.count == 0) |
|
|
|
|
|
|
|
|
|
// Create |
|
|
|
|
let clubA = Club(creator: userId1, name: "Club A", acronym: "CA") |
|
|
|
|
try await clubColA.addOrUpdateAsync(instance: clubA) |
|
|
|
|
|
|
|
|
|
let event1A = Event(creator: userId1, club: clubA.id, name: "event 1") |
|
|
|
|
try await eventColA.addOrUpdateAsync(contentOfs: [event1A]) |
|
|
|
|
|
|
|
|
|
// Share with user2 |
|
|
|
|
try await self.storeCenterA.setAuthorizedUsersAsync(for: event1A, users: [userId2]) |
|
|
|
|
// try await self.storeCenterA.setAuthorizedUsersAsync(for: event2A, users: [userId2]) |
|
|
|
|
|
|
|
|
|
var dataB = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
var syncDataB = try SyncData(data: dataB, storeCenter: self.storeCenterB) |
|
|
|
|
|
|
|
|
|
let event2A = Event(creator: userId1, club: clubA.id, name: "event 2") |
|
|
|
|
try await eventColA.addOrUpdateAsync(contentOfs: [event2A]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove sharing from user2 |
|
|
|
|
// try await self.storeCenterA.setAuthorizedUsersAsync(for: event1A, users: []) |
|
|
|
|
// |
|
|
|
|
// dataB = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
// syncDataB = try SyncData(data: dataB, storeCenter: self.storeCenterB) |
|
|
|
|
// #expect(syncDataB.revocations.count == 1) |
|
|
|
|
// #expect(syncDataB.revocationParents.count == 1) |
|
|
|
|
// |
|
|
|
|
// #expect(eventColB.count == 1) |
|
|
|
|
// #expect(clubColB.count == 1) // club remains because used in event2A |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|