diff --git a/PadelClubDataTests/DeletionTests.swift b/PadelClubDataTests/DeletionTests.swift index 3b39b66..9641dfa 100644 --- a/PadelClubDataTests/DeletionTests.swift +++ b/PadelClubDataTests/DeletionTests.swift @@ -50,6 +50,28 @@ struct DeletionTests { let _: CustomUser = try await storeCenter.service().login(username: username, password: password) } + @Test func testDeleteDependencies() async throws { + + let teamRegCol: SyncedCollection = await StoreCenter.main.mainStore.asyncLoadingSynchronizedCollection() + let playerRegCol: SyncedCollection = await StoreCenter.main.mainStore.asyncLoadingSynchronizedCollection() + + let tr1 = TeamRegistration(tournament: "1") + let pr11 = PlayerRegistration(teamRegistration: tr1.id, firstName: "a1", lastName: "b1") + let pr12 = PlayerRegistration(teamRegistration: tr1.id, firstName: "a1", lastName: "b2") + let tr2 = TeamRegistration(tournament: "1") + let pr21 = PlayerRegistration(teamRegistration: tr2.id, firstName: "a2", lastName: "b1") + let pr22 = PlayerRegistration(teamRegistration: tr2.id, firstName: "a2", lastName: "b2") + + try await teamRegCol.addOrUpdateAsync(contentOfs: [tr1, tr2]) + try await playerRegCol.addOrUpdateAsync(contentOfs: [pr11, pr12, pr21, pr22]) + + try await teamRegCol.deleteAsync(instance: tr1) + + #expect(teamRegCol.count == 1) + #expect(playerRegCol.count == 2) + + } + /// This test creates a hierarchy of objects and deletes to see if everything has been properly deleted @Test func testDeleteEventWithDependencies() async throws {