Skip to content

Commit 52bcdbf

Browse files
committed
add another test
1 parent 589d7ca commit 52bcdbf

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

Tests/SQLiteDataTests/CloudKitTests/MockCloudDatabaseTests.swift

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,85 @@
433433
}
434434
#expect(error?.code == .permissionFailure)
435435
}
436+
437+
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
438+
@Test func deletingShareDeletesSharedRecords() async throws {
439+
let externalZone = CKRecordZone(
440+
zoneID: CKRecordZone.ID(zoneName: "external.zone", ownerName: "external.owner")
441+
)
442+
_ = try syncEngine.shared.database.modifyRecordZones(saving: [externalZone])
443+
444+
let recordA = CKRecord(
445+
recordType: "A",
446+
recordID: CKRecord.ID(recordName: "A1", zoneID: externalZone.zoneID)
447+
)
448+
let recordB = CKRecord(
449+
recordType: "B",
450+
recordID: CKRecord.ID(recordName: "B1", zoneID: externalZone.zoneID)
451+
)
452+
recordB.parent = CKRecord.Reference(recordID: recordA.recordID, action: .none)
453+
let share = CKShare(
454+
rootRecord: recordA,
455+
shareID: CKRecord.ID(recordName: "share", zoneID: externalZone.zoneID
456+
)
457+
)
458+
let (saveResults, _) = try syncEngine.shared.database.modifyRecords(
459+
saving: [share, recordA, recordB]
460+
)
461+
462+
print(saveResults)
463+
464+
assertInlineSnapshot(of: container, as: .customDump) {
465+
"""
466+
MockCloudContainer(
467+
privateCloudDatabase: MockCloudDatabase(
468+
databaseScope: .private,
469+
storage: []
470+
),
471+
sharedCloudDatabase: MockCloudDatabase(
472+
databaseScope: .shared,
473+
storage: [
474+
[0]: CKRecord(
475+
recordID: CKRecord.ID(A1/external.zone/external.owner),
476+
recordType: "A",
477+
parent: nil,
478+
share: CKReference(recordID: CKRecord.ID(share/external.zone/external.owner))
479+
),
480+
[1]: CKRecord(
481+
recordID: CKRecord.ID(B1/external.zone/external.owner),
482+
recordType: "B",
483+
parent: CKReference(recordID: CKRecord.ID(A1/external.zone/external.owner)),
484+
share: nil
485+
),
486+
[2]: CKRecord(
487+
recordID: CKRecord.ID(share/external.zone/external.owner),
488+
recordType: "cloudkit.share",
489+
parent: nil,
490+
share: nil
491+
)
492+
]
493+
)
494+
)
495+
"""
496+
}
497+
498+
_ = try syncEngine.shared.database.modifyRecords(deleting: [share.recordID])
499+
500+
assertInlineSnapshot(of: container, as: .customDump) {
501+
"""
502+
MockCloudContainer(
503+
privateCloudDatabase: MockCloudDatabase(
504+
databaseScope: .private,
505+
storage: []
506+
),
507+
sharedCloudDatabase: MockCloudDatabase(
508+
databaseScope: .shared,
509+
storage: []
510+
)
511+
)
512+
"""
513+
}
514+
}
436515
}
437516
}
438517
#endif

0 commit comments

Comments
 (0)