|
|
|
|
@ -42,6 +42,10 @@ struct SyncDataAccessTests { |
|
|
|
|
try StoreCenter.main.deviceKeychain.add(value: UUID().uuidString) |
|
|
|
|
StoreCenter.main.classProject = "PadelClubData" |
|
|
|
|
|
|
|
|
|
// if conf.inMemory { |
|
|
|
|
// try await self._createUsers() |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
let token = try? StoreCenter.main.rawTokenShouldNotBeUsed() |
|
|
|
|
if token == nil { |
|
|
|
|
try await self.login(storeCenter: StoreCenter.main, username: self.username1, password: self.password1) |
|
|
|
|
@ -74,6 +78,17 @@ struct SyncDataAccessTests { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _createUsers() async throws { |
|
|
|
|
|
|
|
|
|
let user1 = CustomUser(username: self.username1) |
|
|
|
|
let form1 = UserCreationForm(user: user1, username: self.username1, password: self.password1, firstName: "f", lastName: "l", email: "test1@lolomo.net", phone: "", country: "") |
|
|
|
|
let _: CustomUser = try await StoreCenter.main.service().createAccount(user: form1) |
|
|
|
|
|
|
|
|
|
let user2 = CustomUser(username: self.username2) |
|
|
|
|
let form2 = UserCreationForm(user: user2, username: self.username2, password: self.password2, firstName: "f2", lastName: "l2", email: "test2@lolomo.net", phone: "", country: "") |
|
|
|
|
let _: CustomUser = try await StoreCenter.main.service().createAccount(user: form2) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mutating func login(storeCenter: StoreCenter, username: String, password: String) async throws { |
|
|
|
|
let _: CustomUser = try await storeCenter.service().login(username: username, password: password) |
|
|
|
|
} |
|
|
|
|
@ -602,8 +617,12 @@ struct SyncDataAccessTests { |
|
|
|
|
|
|
|
|
|
// Setup tournament |
|
|
|
|
let tournamentColA: SyncedCollection<Tournament> = await StoreCenter.main.mainStore.asyncLoadingSynchronizedCollection() |
|
|
|
|
let eventColA: SyncedCollection<Event> = await StoreCenter.main.mainStore.asyncLoadingSynchronizedCollection() |
|
|
|
|
|
|
|
|
|
let tournament = Tournament(name: "test_data_access_children") |
|
|
|
|
let event = Event(creator: userId1) |
|
|
|
|
try await eventColA.addOrUpdateAsync(instance: event) |
|
|
|
|
|
|
|
|
|
let tournament = Tournament(event: event.id, name: "test_data_access_children") |
|
|
|
|
tournament.relatedUser = userId1 |
|
|
|
|
try await tournamentColA.addOrUpdateAsync(instance: tournament) |
|
|
|
|
|
|
|
|
|
@ -654,12 +673,16 @@ struct SyncDataAccessTests { |
|
|
|
|
#expect(teamRegColB.count == 2) |
|
|
|
|
|
|
|
|
|
try await tournamentColA.deleteAsync(instance: tournament) |
|
|
|
|
let tournaments: [Tournament] = try await StoreCenter.main.service().get() |
|
|
|
|
#expect(tournaments.count == 0) |
|
|
|
|
|
|
|
|
|
#expect(tournamentColA.count == 0) |
|
|
|
|
|
|
|
|
|
let data2 = try await self.storeCenterB.testSynchronizeOnceAsync() |
|
|
|
|
let syncData2 = try SyncData(data: data2, storeCenter: self.storeCenterB) |
|
|
|
|
|
|
|
|
|
#expect(tournamentColB.count == 0) |
|
|
|
|
|
|
|
|
|
#expect(syncData2.deletions.count > 0) |
|
|
|
|
|
|
|
|
|
#expect(matchColB.count == 0) |
|
|
|
|
|